Ejemplo n.º 1
0
        private void WaitForConnectionCallBack(IAsyncResult iar)
        {
            try
            {
                // Get the pipe
                NamedPipeServerStream pipeServer = (NamedPipeServerStream)iar.AsyncState;
                // End waiting for the connection
                pipeServer.EndWaitForConnection(iar);

                byte[] buffer = new byte[1024];

                // Read the incoming message
                pipeServer.Read(buffer, 0, 1024);

                // Convert byte buffer to string
                string jsonRequestMsg = Encoding.UTF8.GetString(buffer, 0, buffer.Length);

                IpcOperationType type = IpcMessageStore.getIpcOperationType(jsonRequestMsg);

                string jsonResponseMsg = null;
                if (type == IpcOperationType.AddIssueRequest)
                {
                    AddIssueResponse response = handleAddIssueRequest();
                    jsonResponseMsg = IpcMessageStore.savePayload(IpcOperationType.AddIssueResponse, response);
                }
                else if (type == IpcOperationType.OpenViewpointRequest)
                {
                    VisualizationInfo visInfo = IpcMessageStore.getPayload <VisualizationInfo>(jsonRequestMsg);
                    jsonResponseMsg = "{}";
                    doOpen3DView(visInfo);
                }
                else if (type == IpcOperationType.SelectElementsRequest)
                {
                    List <Component> components = IpcMessageStore.getPayload <List <Component> >(jsonRequestMsg);
                    jsonResponseMsg = "{}";
                    selectElements(components, true);
                }

                // Send response
                byte[] _buffer = Encoding.UTF8.GetBytes(jsonResponseMsg);
                pipeServer.Write(_buffer, 0, _buffer.Length);
                pipeServer.Flush();

                // Kill original sever and create new wait server
                pipeServer.Close();
                pipeServer = null;
                pipeServer = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);

                // Recursively wait for the connection again and again....
                pipeServer.BeginWaitForConnection(new AsyncCallback(WaitForConnectionCallBack), pipeServer);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Ejemplo n.º 2
0
        private void sendIpcRequest(IpcOperationType type, object data, Action <object> callback)
        {
            try
            {
                NamedPipeClientStream pipeStream = new NamedPipeClientStream(".", ipcPipeName, PipeDirection.InOut, PipeOptions.Asynchronous);

                // The connect function will indefinitely wait for the pipe to become available
                // If that is not acceptable specify a maximum waiting time (in ms)
                pipeStream.Connect(1000);

                string msg = IpcMessageStore.savePayload(type, data);

                byte[] _buffer = Encoding.UTF8.GetBytes(msg);
                pipeStream.BeginWrite(_buffer, 0, _buffer.Length, ipcAsyncCallback, new Tuple <NamedPipeClientStream, Action <object> >(pipeStream, callback));
            }
            catch (Exception ex)
            {
                MessageBox.Show("Arup Issue Tracker could not finish the operation due to the following error:\n" + ex.ToString());
            }
        }