Ejemplo n.º 1
0
        private void HandleConnection(IAsyncResult result)
        {
            String projectName = String.Empty;
            String projectPath = String.Empty;

            try
            {
                if (m_PipeStream != null)
                {
                    m_PipeStream.EndWaitForConnection(result);
                    if (m_PipeStream.IsConnected)
                    {
                        using (System.IO.StreamReader reader = new System.IO.StreamReader(m_PipeStream))
                        {
                            projectName = reader.ReadLine();
                            projectPath = reader.ReadLine();
                        }
                    }
                    // the pipe has been closed now!
                    CreatePipe();
                }
            }
            catch (Exception)
            {
                projectName = String.Empty;
                projectPath = String.Empty;
            }
            if (ProjectOpenAction != null && !String.IsNullOrEmpty(projectName) && !String.IsNullOrEmpty(projectPath))
            {
                ProjectOpenAction(projectName, projectPath);
            }
        }
Ejemplo n.º 2
0
        //============
        // クライアント接続後処理メソッド
        // 本サーバーにクライアントが接続してきたら、本メソッドの処理を
        // 実行します。具体的には、まず、クライアントに要求電文(命令)
        // を提出するよう通知します(すなわち、これは、サーバーに接続さ
        // れたことをクライアントに通知することを意味しています)。次に、
        // クライアントから要求電文が送られてくるのを待機します。
        // 第1引数: 非同期操作のステータス
        private void WaitForConnectionCallBack(IAsyncResult iar)
        {
            try
            {
                // パイプの取得
                System.IO.Pipes.NamedPipeServerStream pipe_Server = (System.IO.Pipes.NamedPipeServerStream)iar.AsyncState;


                //------------
                // 非同期操作完了
                //------------


                // クライアントが接続するのを待機する非同期操作を終了します。
                pipe_Server.EndWaitForConnection(iar);


                // 以下の処理は、本サーバーにクライアントが接続された後に実行されます。
                // (それまで待機中となり、実行が開始されない)


                //------------
                // クライアントへ接続通知を送信
                //------------


                // ストリームに対して、文字データーを読み書きするオブジェクトを生成
                AccessStream ss = new AccessStream(pipe_Server);


                // 送信データーを書き込み
                //  --- クライアントに要求電文(命令)を提出するよう通知します。
                //      具体的には、
                //      「サーバーはクライアントに命令を提出するよう要求している」
                //      と言う意味の英文メッセージを名前付きパイプに書き込む。
                ss.WriteString(
                    "A connection succeeded.",
                    "shift_jis");


                //------------
                // クライアントから要求電文を受信
                //------------


                // 要求電文受信待機
                ReceiveOrder(this);
            }
            // 名前付きパイプが壊れているなどの異常が発生した場合
            catch (System.IO.IOException ex)
            {
                // エラー処理
                System.Windows.Forms.MessageBox.Show(ex.Message, "エラー通知");
            }
        }
Ejemplo n.º 3
0
        public EditorWorkProgressShowerInConsole()
        {
#if UNITY_EDITOR_WIN
            var pipeName = System.DateTime.Now.ToString("yyMMddHHmmss");
            var pipeout  = new System.IO.Pipes.NamedPipeServerStream("ProgressShowerInConsole" + pipeName, System.IO.Pipes.PipeDirection.Out);
            var pipein   = new System.IO.Pipes.NamedPipeServerStream("ProgressShowerInConsoleControl" + pipeName, System.IO.Pipes.PipeDirection.In);
            var arout    = pipeout.BeginWaitForConnection(null, null);
            var arin     = pipein.BeginWaitForConnection(null, null);

            var dir     = Application.dataPath + "/../";
            var tooldir = CapsModEditor.GetPackageOrModRoot(CapsEditorUtils.__MOD__) + "/~Tools~/";
            System.Diagnostics.ProcessStartInfo si = new System.Diagnostics.ProcessStartInfo(tooldir + "ProgressShowerInConsole.exe", pipeName);
            si.WorkingDirectory = tooldir;
            _ExProc             = System.Diagnostics.Process.Start(si);

            var thd_Write = new System.Threading.Thread(() =>
            {
                try
                {
                    pipeout.EndWaitForConnection(arout);
                    var sw = new System.IO.StreamWriter(pipeout);
                    while (_MessageReady.WaitOne())
                    {
                        _MessageReady.Reset();
                        lock (_MessageQueue)
                        {
                            foreach (var line in _MessageQueue)
                            {
                                sw.WriteLine(line);
                            }
                            sw.Flush();
                            _MessageQueue.Clear();
                        }
                    }
                }
                finally
                {
                    pipeout.Dispose();
                }
            });
            thd_Write.Start();

            var thd_Read = new System.Threading.Thread(() =>
            {
                try
                {
                    pipein.EndWaitForConnection(arin);
                    var sr = new System.IO.StreamReader(pipein);
                    while (!_ExProc.HasExited)
                    {
                        var line = sr.ReadLine();
                        if (line != null)
                        {
                            if (line == "\uEE05Quit")
                            {
                                break;
                            }
                        }
                    }
                }
                finally
                {
                    _ShouldQuit = true;
                    thd_Write.Abort();
                    _MessageReady.Set();
                    pipein.Dispose();
                }
            });
            thd_Read.Start();
#endif
        }