示例#1
0
        private void Restart()
        {
            if (m_toRumps != null)
            {
                m_toRumps.Dispose();
            }

            var startinfo = new System.Diagnostics.ProcessStartInfo(RUMPS_PYTHON, string.Format("\"{0}\"", SCRIPT_PATH));

            startinfo.CreateNoWindow         = true;
            startinfo.UseShellExecute        = false;
            startinfo.RedirectStandardInput  = true;
            startinfo.RedirectStandardOutput = true;
            startinfo.RedirectStandardError  = true;

            m_rumpsProcess = System.Diagnostics.Process.Start(startinfo);
            var ch = ChannelManager.CreateChannel <string>();

            m_toRumps = ch.AsWriteOnly();

            WriteChannel(m_rumpsProcess.StandardInput, ch.AsReadOnly());
            #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            ReadChannel(m_rumpsProcess.StandardOutput);
            ReadChannel(m_rumpsProcess.StandardError);
            #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

            m_toRumps.WriteNoWait(JsonConvert.SerializeObject(new { Action = "background" }));
            //m_toRumps.WriteNoWait(JsonConvert.SerializeObject(new {Action = "setappicon", Image = GetIcon(m_lastIcon)}));

            if (m_menus != null)
            {
                ResetMenus();
                m_toRumps.WriteNoWait(JsonConvert.SerializeObject(new { Action = "seticon", Image = GetIcon(m_lastIcon) }));
            }
        }
示例#2
0
        private void Restart()
        {
            if (m_toRumps != null)
            {
                m_toRumps.Dispose();
            }

            var startinfo = new System.Diagnostics.ProcessStartInfo(RUMPS_PYTHON, string.Format("\"{0}\"", SCRIPT_PATH));

            startinfo.CreateNoWindow         = true;
            startinfo.UseShellExecute        = false;
            startinfo.RedirectStandardInput  = true;
            startinfo.RedirectStandardOutput = true;
            startinfo.RedirectStandardError  = true;

            m_rumpsProcess = System.Diagnostics.Process.Start(startinfo);
            var ch = ChannelManager.CreateChannel <string>();

            m_toRumps = ch.AsWriteOnly();

            WriteChannel(m_rumpsProcess.StandardInput, ch.AsReadOnly());
            var standardOutputTask = ReadChannel(m_rumpsProcess.StandardOutput);
            var standardErrorTask  = ReadChannel(m_rumpsProcess.StandardError);

            m_toRumps.WriteNoWait(JsonConvert.SerializeObject(new { Action = "background" }));
            //m_toRumps.WriteNoWait(JsonConvert.SerializeObject(new {Action = "setappicon", Image = GetIcon(m_lastIcon)}));

            if (m_menus != null)
            {
                ResetMenus();
                m_toRumps.WriteNoWait(JsonConvert.SerializeObject(new { Action = "seticon", Image = GetIcon(m_lastIcon) }));
            }
        }
示例#3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CoCoL.Network.LatencyHidingWriter&lt;T&gt;"/> class.
 /// </summary>
 /// <param name="parent">The channel where requests are made.</param>
 /// <param name="buffersize">The size of the buffer.</param>
 public LatencyHidingWriter(IWriteChannelEnd <T> parent, int buffersize)
 {
     if (buffersize <= 0)
     {
         throw new ArgumentOutOfRangeException("buffersize");
     }
     m_parent     = parent;
     m_buffersize = buffersize;
 }
示例#4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CoCoL.Network.NetworkClientConnector"/> class.
 /// </summary>
 /// <param name="hostname">The hostname for the nameserver.</param>
 /// <param name="port">The port for the nameserver.</param>
 public NetworkClientConnector(string hostname, int port)
 {
     using (new IsolatedChannelScope())
     {
         m_nameserverclient = new NameServerClient(hostname, port);
         var chan = ChannelManager.CreateChannel <PendingNetworkRequest>();
         m_requests = chan.AsReadOnly();
         Requests   = chan.AsWriteOnly();
     }
 }
示例#5
0
        protected override void Exit()
        {
            m_isQuitting = true;
            if (m_rumpsProcess != null && !m_rumpsProcess.HasExited)
            {
                if (m_toRumps != null)
                {
                    m_toRumps.WriteNoWait(JsonConvert.SerializeObject(new { Action = "shutdown" }));
                    m_toRumps.Dispose();
                    m_toRumps = null;
                }

                m_rumpsProcess.WaitForExit((int)TimeSpan.FromSeconds(5).TotalMilliseconds);
                m_rumpsProcess.Kill();
                m_rumpsProcess = null;
            }
        }
示例#6
0
        protected override void Exit()
        {
            m_isQuitting = true;
            if (m_rumpsProcess != null && !m_rumpsProcess.HasExited)
            {
                m_toRumps.WriteNoWait(JsonConvert.SerializeObject(new {Action = "shutdown"}));
                if (m_toRumps != null)
                {
                    m_toRumps.Dispose();
                    m_toRumps = null;
                }

                m_rumpsProcess.WaitForExit((int)TimeSpan.FromSeconds(5).TotalMilliseconds);
                m_rumpsProcess.Kill();
                m_rumpsProcess = null;
            }

        }
示例#7
0
        private void Restart()
        {
            if (m_toRumps != null)
                m_toRumps.Dispose();
            
            var startinfo = new System.Diagnostics.ProcessStartInfo(RUMPS_PYTHON, string.Format("\"{0}\"", SCRIPT_PATH));
            startinfo.CreateNoWindow = true;
            startinfo.UseShellExecute = false;
            startinfo.RedirectStandardInput = true;
            startinfo.RedirectStandardOutput = true;
            startinfo.RedirectStandardError = true;

            m_rumpsProcess = System.Diagnostics.Process.Start(startinfo);
            var ch = ChannelManager.CreateChannel<string>();
            m_toRumps = ch.AsWriteOnly();

            WriteChannel(m_rumpsProcess.StandardInput, ch.AsReadOnly());
            ReadChannel(m_rumpsProcess.StandardOutput);
            ReadChannel(m_rumpsProcess.StandardError);

			m_toRumps.WriteNoWait(JsonConvert.SerializeObject(new {Action = "background"}));
			//m_toRumps.WriteNoWait(JsonConvert.SerializeObject(new {Action = "setappicon", Image = GetIcon(m_lastIcon)}));

            if (m_menus != null)
            {
                ResetMenus();
                m_toRumps.WriteNoWait(JsonConvert.SerializeObject(new {Action = "seticon", Image = GetIcon(m_lastIcon)}));
            }
        }
示例#8
0
        /// <summary>
        /// The process that reads data from the underlying stream and parses it into a <see cref="CoCoL.Network.PendingNetworkRequest" />.
        /// </summary>
        /// <returns>The awaitable task.</returns>
        /// <param name="client">The <see cref="System.Net.Sockets.TcpClient"/> to read data from.</param>
        /// <param name="stream">The stream to read data from.</param>
        /// <param name="channel">The channel to write requests to.</param>
        /// <param name="selfid">A string used to identify this process in logs</param>
        private static async Task ReaderProcess(TcpClient client, Stream stream, IWriteChannelEnd <PendingNetworkRequest> channel, string selfid)
        {
            try
            {
                var buffer = new byte[SMALL_MESSAGE_SIZE];
                var json   = new Newtonsoft.Json.JsonSerializer();

                using (client)
                    using (stream)
                        using (channel)
                        {
                            while (true)
                            {
                                LOG.DebugFormat("{0}: Waiting for data from stream", selfid);
                                await ForceReadAsync(stream, buffer, 0, 8);

                                LOG.DebugFormat("{0}: Not waiting for data from stream", selfid);

                                var streamlen = BitConverter.ToUInt64(buffer, 0);
                                if (streamlen > MAX_MESSAGE_SIZE)
                                {
                                    throw new Exception("Perhaps too big data?");
                                }

                                await ForceReadAsync(stream, buffer, 0, 2);

                                var headlen = BitConverter.ToUInt16(buffer, 0);
                                if (headlen > buffer.Length || headlen > streamlen)
                                {
                                    throw new Exception("Perhaps too big data?");
                                }

                                await ForceReadAsync(stream, buffer, 0, headlen);

                                RequestHeader header;
                                using (var ms = new MemoryStream(buffer, 0, headlen))
                                    using (var sr = new StreamReader(ms))
                                        using (var jr = new Newtonsoft.Json.JsonTextReader(sr))
                                            header = json.Deserialize <RequestHeader>(jr);

                                LOG.DebugFormat("{4}: Got {0} - {1} request with {2} bytes from {3}", header.RequestID, header.RequestType, streamlen, client.Client.RemoteEndPoint, selfid);

                                await ForceReadAsync(stream, buffer, 0, 8);

                                var payloadlen = BitConverter.ToUInt64(buffer, 0);
                                if (payloadlen > MAX_MESSAGE_SIZE || payloadlen > streamlen - headlen)
                                {
                                    throw new Exception("Perhaps too big data?");
                                }

                                object payload = null;
                                if (header.PayloadClassName != null)
                                {
                                    var bf = payloadlen <= (ulong)buffer.Length ? buffer : new byte[payloadlen];
                                    await ForceReadAsync(stream, bf, 0, (int)payloadlen);

                                    var objtype = Type.GetType(header.PayloadClassName);
                                    if (objtype == null)
                                    {
                                        throw new ArgumentException(string.Format("Unable to determine the target type to create for {0}", header.PayloadClassName));
                                    }

                                    using (var ms = new MemoryStream(bf, 0, (int)payloadlen))
                                        using (var sr = new StreamReader(ms))
                                            using (var jr = new Newtonsoft.Json.JsonTextReader(sr))
                                                payload = json.Deserialize(jr, objtype);
                                }

                                var pnrq = new PendingNetworkRequest(
                                    header.ChannelID,
                                    Type.GetType(header.ChannelDataType),
                                    header.RequestID,
                                    header.SourceID,
                                    header.Timeout,
                                    header.RequestType,
                                    payload,
                                    header.NoOffer
                                    );

                                LOG.DebugFormat("{2}: Forwarding {0} - {1} request", header.RequestID, header.RequestType, selfid);
                                await channel.WriteAsync(pnrq);

                                LOG.DebugFormat("{2}: Forwarded {0} - {1} request", header.RequestID, header.RequestType, selfid);
                            }
                        }
            }
            catch (Exception ex)
            {
                if (!ex.IsRetiredException())
                {
                    LOG.Error("Crashed network client reader side", ex);
                    throw;
                }
                else
                {
                    LOG.Info("Stopped network client reader");
                }
            }
        }