当前位置: 首页>>代码示例>>C#>>正文


C# NamedPipeServerStream.RunAsClient方法代码示例

本文整理汇总了C#中System.IO.Pipes.NamedPipeServerStream.RunAsClient方法的典型用法代码示例。如果您正苦于以下问题:C# NamedPipeServerStream.RunAsClient方法的具体用法?C# NamedPipeServerStream.RunAsClient怎么用?C# NamedPipeServerStream.RunAsClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.Pipes.NamedPipeServerStream的用法示例。


在下文中一共展示了NamedPipeServerStream.RunAsClient方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ServerThread

    private static void ServerThread(object data)
    {
        NamedPipeServerStream pipeServer =
            new NamedPipeServerStream("testpipe", PipeDirection.InOut, numThreads);

        int threadId = Thread.CurrentThread.ManagedThreadId;

        // Wait for a client to connect
        pipeServer.WaitForConnection();

        Console.WriteLine("Client connected on thread[{0}].", threadId);
        try
        {
            // Read the request from the client. Once the client has
            // written to the pipe its security token will be available.

            StreamString ss = new StreamString(pipeServer);

            // Verify our identity to the connected client using a
            // string that the client anticipates.

            ss.WriteString("I am the one true server!");
            string filename = ss.ReadString();

            // Read in the contents of the file while impersonating the client.
            ReadFileToStream fileReader = new ReadFileToStream(ss, filename);

            // Display the name of the user we are impersonating.
            Console.WriteLine("Reading file: {0} on thread[{1}] as user: {2}.",
                filename, threadId, pipeServer.GetImpersonationUserName());
            pipeServer.RunAsClient(fileReader.Start);
        }
        // Catch the IOException that is raised if the pipe is broken
        // or disconnected.
        catch (IOException e)
        {
            Console.WriteLine("ERROR: {0}", e.Message);
        }
        pipeServer.Close();
    }
开发者ID:retracy,项目名称:pipes,代码行数:40,代码来源:Program.cs

示例2: ServerThread

    private static void ServerThread(object data)
    {
        NamedPipeServerStream pipeServer =
            new NamedPipeServerStream("testpipe", PipeDirection.InOut, numThreads);
        int threadId = Thread.CurrentThread.ManagedThreadId;

        //wait for client to connect
        pipeServer.WaitForConnection();

        Console.WriteLine("Client connected on thread[{0}].", threadId);
        try
        {
            //Read the request from the client. Once the client has
            //written to the pipe its security token will be available.
            //We might not need this security token ? 
            //We need interprocess communication on the same computer
            StreamString ss = new StreamString(pipeServer);

            //Verify our identity to the connected client using a 
            //string that the client anticipates

            ss.WriteString("I am the one true server!");
            string filename = ss.ReadString();

            //Read in the contents of the file while impersonating the client.
            ReadFileToStream fileReader = new ReadFileToStream(ss, filename);

            //Display the name of the user we are impersonating. //Impersonating ? 
            Console.WriteLine("Reading file: {0} on thread{1} as user: {2}.",
                filename, threadId, pipeServer.GetImpersonationUserName()); //So impersonation is nothing but name of client at the other end ? Cool!
            pipeServer.RunAsClient(fileReader.Start);
        }
        catch(IOException e)
        {
            Console.WriteLine("ERROR: {0}", e.Message);
        }
        pipeServer.Close();
    }
开发者ID:eaglespy21,项目名称:NamedPipeServer,代码行数:38,代码来源:Program.cs

示例3: ServerThread

        private static void ServerThread(object data)
        {
            var pipeServer = new NamedPipeServerStream("testpipe", PipeDirection.InOut, numThreads);
            int threadId = Thread.CurrentThread.ManagedThreadId;

            pipeServer.WaitForConnection();

            Console.WriteLine("Client connected on thread[{0}].", threadId);
            try
            {
                StreamString ss = new StreamString(pipeServer);
                ss.WriteString("I am the one true server!");
                string filename = ss.ReadString();
                ReadFileToStream fileReader = new ReadFileToStream(ss, filename);
                Console.WriteLine("Reading file: {0} on thread[{1}] as user: {2}.",
                    filename, threadId, pipeServer.GetImpersonationUserName());
                pipeServer.RunAsClient(fileReader.Start);
            }
            catch (IOException e)
            {
                Console.WriteLine("ERROR: {0}", e.Message);
            }
            pipeServer.Close();
        }
开发者ID:JianchengZh,项目名称:kasicass,代码行数:24,代码来源:PipeServer.cs

示例4: StartListener

        /// <summary>
        ///   Starts the listener.
        /// </summary>
        /// <remarks>
        /// </remarks>
        private void StartListener()
        {
            if (_cancellationTokenSource.Token.IsCancellationRequested) {
                return;
            }

            try {
                if (IsRunning) {
                    Logger.Message("Starting New Listener {0}", listenerCount++);
                    var serverPipe = new NamedPipeServerStream(PipeName, PipeDirection.InOut, Instances, PipeTransmissionMode.Message, PipeOptions.Asynchronous,
                        BufferSize, BufferSize, _pipeSecurity);
                    var listenTask = Task.Factory.FromAsync(serverPipe.BeginWaitForConnection, serverPipe.EndWaitForConnection, serverPipe);

                    listenTask.ContinueWith(t => {
                        if (t.IsCanceled || _cancellationTokenSource.Token.IsCancellationRequested) {
                            return;
                        }

                        StartListener(); // spawn next one!

                        if (serverPipe.IsConnected) {
                            var serverInput = new byte[BufferSize];

                            serverPipe.ReadAsync(serverInput, 0, serverInput.Length).AutoManage().ContinueWith(antecedent => {
                                var rawMessage = Encoding.UTF8.GetString(serverInput, 0, antecedent.Result);
                                if (string.IsNullOrEmpty(rawMessage)) {
                                    return;
                                }

                                var requestMessage = new UrlEncodedMessage(rawMessage);

                                // first command must be "startsession"
                                if (!requestMessage.Command.Equals("StartSession", StringComparison.CurrentCultureIgnoreCase)) {
                                    return;
                                }

                                // verify that user is allowed to connect.
                                try {
                                    var hasAccess = false;
                                    serverPipe.RunAsClient(() => {
                                        hasAccess = PermissionPolicy.Connect.HasPermission;
                                    });
                                    if (!hasAccess) {
                                        return;
                                    }
                                } catch {
                                    return;
                                }

                                // check for the required parameters.
                                // close the session if they are not here.
                                if (string.IsNullOrEmpty(requestMessage["id"]) || string.IsNullOrEmpty(requestMessage["client"])) {
                                    return;
                                }
                                var isSync = requestMessage["async"].IsFalse();

                                if (isSync) {
                                    StartResponsePipeAndProcessMesages(requestMessage["client"], requestMessage["id"], serverPipe);
                                } else {
                                    Session.Start(requestMessage["client"], requestMessage["id"], serverPipe, serverPipe);
                                }
                            }).Wait();
                        }
                    }, _cancellationTokenSource.Token, TaskContinuationOptions.AttachedToParent, TaskScheduler.Current);
                }
            } catch /* (Exception e) */ {
                RequestStop();
            }
        }
开发者ID:virmitio,项目名称:coapp,代码行数:74,代码来源:Engine.cs

示例5: btnStartServer_Click

        private async void btnStartServer_Click(object sender, EventArgs e)
        {
            try
            {
                btnStartServer.Enabled = false;

                using (NamedPipeServerStream pipe = new NamedPipeServerStream(txtPipeName.Text,
                    PipeDirection.In, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous))
                {
                    await Task.Factory.FromAsync(pipe.BeginWaitForConnection,
                        pipe.EndWaitForConnection, null);

                    UserToken token = null;

                    if (pipe.IsConnected)
                    {
                        pipe.RunAsClient(() => token = TokenUtils.GetTokenFromThread());
                        pipe.Disconnect();
                    }

                    if (token != null)
                    {
                        TokenForm.OpenForm(token, false);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                btnStartServer.Enabled = true;
            }
        }
开发者ID:GabberBaby,项目名称:sandbox-attacksurface-analysis-tools,代码行数:35,代码来源:MainForm.cs

示例6: ClientAndOurIdentitiesMatch

            /// <summary>
            /// Does the client of "pipeStream" have the same identity and elevation as we do?
            /// </summary>
            private bool ClientAndOurIdentitiesMatch(NamedPipeServerStream pipeStream)
            {
                string ourUserName, clientUserName = null;
                bool ourElevation, clientElevation = false;

                // Get the identities of ourselves and our client.
                ourUserName = GetIdentity(false, out ourElevation);
                pipeStream.RunAsClient(delegate() { clientUserName = GetIdentity(true, out clientElevation); });

                Log("Server identity = '{0}', server elevation='{1}'.", ourUserName, ourElevation);
                Log("Client identity = '{0}', client elevation='{1}'.", clientUserName, clientElevation);
                return (ourUserName == clientUserName && ourElevation == clientElevation);
            }
开发者ID:riversky,项目名称:roslyn,代码行数:16,代码来源:ServerDispatcher.Connection.cs

示例7: ServerThread

        public void ServerThread()
        {
            NamedPipeServerStream pipeServer = new NamedPipeServerStream("FTPbox Server", PipeDirection.InOut, 5);
            int threadID = Thread.CurrentThread.ManagedThreadId;

            pipeServer.WaitForConnection();

            Log.Write(l.Client, "Client connected, id: {0}", threadID);

            try
            {
                StreamString ss = new StreamString(pipeServer);

                ss.WriteString("ftpbox");
                string args = ss.ReadString();

                ReadMessageSent fReader = new ReadMessageSent(ss, "All done!");

                Log.Write(l.Client, "Reading file: \n {0} \non thread [{1}] as user {2}.", args, threadID, pipeServer.GetImpersonationUserName());

                List<string> li = new List<string>();
                li = ReadCombinedParameters(args);

                CheckClientArgs(li.ToArray());

                pipeServer.RunAsClient(fReader.Start);
            }
            catch (IOException e)
            {
                Common.LogError(e);
            }
            pipeServer.Close();
        }
开发者ID:skopp,项目名称:FTPbox,代码行数:33,代码来源:fMain.cs

示例8: ClientAndOurIdentitiesMatch

        /// <summary>
        /// Does the client of "pipeStream" have the same identity and elevation as we do?
        /// </summary>
        private static bool ClientAndOurIdentitiesMatch(NamedPipeServerStream pipeStream)
        {
            var serverIdentity = GetIdentity(impersonating: false);

            Tuple<string, bool> clientIdentity = null;
            pipeStream.RunAsClient(() => { clientIdentity = GetIdentity(impersonating: true); });

            CompilerServerLogger.Log($"Server identity = '{serverIdentity.Item1}', server elevation='{serverIdentity.Item2}'.");
            CompilerServerLogger.Log($"Client identity = '{clientIdentity.Item1}', client elevation='{serverIdentity.Item2}'.");

            return
                StringComparer.OrdinalIgnoreCase.Equals(serverIdentity.Item1, clientIdentity.Item1) &&
                serverIdentity.Item2 == clientIdentity.Item2;
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:17,代码来源:NamedPipeClientConnection.cs


注:本文中的System.IO.Pipes.NamedPipeServerStream.RunAsClient方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。