Esempio n. 1
0
 public void CloseDisplay()
 {
   Log.Debug("MatrixGX.MOGXDisplay.CloseDisplay() - called");
   try
   {
     lock (this.StopMutex)
     {
       Log.Debug("MatrixGX.MOGXDisplay.CloseDisplay() Stopping DisplayUpdate() Thread");
       Thread.Sleep(250);
       this.stopDisplayUpdateThread = true;
       goto Label_004E;
     }
     Label_0047:
     Thread.Sleep(100);
     Label_004E:
     if (this._displayThread.IsAlive)
     {
       goto Label_0047;
     }
     Log.Debug("MatrixGX.MOGXDisplay.CloseDisplay() DisplayUpdate() Thread stopped.");
     this._isClosing = true;
     lock (this.DWriteMutex)
     {
       this.GX_Graphics.Dispose();
       this.GX_Session.End();
       this.GX_Session = null;
       this.GX_Client.Disconnect();
       this.GX_Client = null;
       this._isOpen = false;
     }
     Log.Debug("MatrixGX.MOGXDisplay.CloseDisplay() - Display closed.");
   }
   catch (Exception exception)
   {
     Log.Debug("MatrixGX.MOGXDisplay.CloseDisplay() - caught exception on display close: {0}",
               new object[] {exception.ToString()});
     Log.Error(exception);
     this._isOpen = false;
   }
 }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Random r   = new Random();
            int    max = 0;
            Thread t1  = new Thread(() =>
            {
                DCClient client = DCClient.Instance("TESTPUB", "global");
                while (true)
                {
                    client.Pub("0x0309", make0EEE());
                    Console.WriteLine("--0x0309--" + DateTime.Now.Second + "." + DateTime.Now.Millisecond);
                    Thread.Sleep(10000);
                }
            }
                                    );

            t1.Start();

            //Thread t2 = new Thread(() =>
            //{
            //    DCClient client = DCClient.Instance("TESTPUB", "global");
            //    while (true)
            //    {
            //        List<string> list = new List<string>();
            //        Signal sig = new Signal { Freq = (UInt64)r.Next(), Bw = (UInt32)r.Next(), TimeMark = DateTime.Now, Halo = "最无需思考的方法就是", List = new List<string>(new string[] { "asdfte", "satewr", "阿布才" }) };
            //        client.Pub<Signal>(sig);
            //        Console.WriteLine("--Signal--" + DateTime.Now.Second + "." + DateTime.Now.Millisecond);
            //        Thread.Sleep(2000);
            //    }
            //}
            //);
            //t2.Start();

            //Thread t3 = new Thread(() =>
            //{
            //    DCClient client = DCClient.Instance("TESTPUB", "global");
            //    while (true)
            //    {
            //        List<string> list = new List<string>();
            //        Signal sig = new Signal { Freq = (UInt64)r.Next(), Bw = (UInt32)r.Next(), TimeMark = DateTime.Now, Halo = "最无需思考的方法就是", List = new List<string>(new string[] { "asdfte", "satewr", "阿布才" }) };
            //        client.Pub("testObj", sig);
            //        Console.WriteLine("--Signal--" + DateTime.Now.Second + "." + DateTime.Now.Millisecond);
            //        //Thread.Sleep(10);
            //    }
            //}
            //);
            //t3.Start();

            //Thread t2 = new Thread(() =>
            //{
            //    DCClient client = DCClient.Instance("TESTPUB", "global");
            //    while (true)
            //    {
            //        client.Pub("0x0304", make0EEE());
            //        Console.WriteLine("--0x0304--" + DateTime.Now.Second + "." + DateTime.Now.Millisecond);
            //        //Thread.Sleep(1);
            //    }
            //}
            //);
            //t2.Start();

            //Thread t3 = new Thread(() =>
            //{
            //    DCClient client = DCClient.Instance("Service1", "global");
            //    while (true)
            //    {
            //        client.Pub("20002", Encoding.Unicode.GetBytes("Status Service1, timestamp " + DateTime.Now.Second + "." + DateTime.Now.Millisecond));
            //        Thread.Sleep(r.Next(10, 1000));
            //    }
            //}
            //);
            //t3.Start();

            //Thread t4 = new Thread(() =>
            //{
            //    DCClient client = DCClient.Instance("Service2", "global");
            //    while (true)
            //    {
            //        client.Pub("20002", Encoding.Unicode.GetBytes("Status Service2, timestamp " + DateTime.Now.Second + "." + DateTime.Now.Millisecond));
            //        Thread.Sleep(r.Next(10, 1000));
            //    }
            //}
            //);
            //t4.Start();

            //Thread t5 = new Thread(() =>
            //{
            //    DCClient client = DCClient.Instance("Service3", "global");
            //    while (true)
            //    {
            //        client.Pub("20002", Encoding.Unicode.GetBytes("Status Service3, timestamp " + DateTime.Now.Second + "." + DateTime.Now.Millisecond));
            //        Thread.Sleep(r.Next(10, 1000));
            //    }
            //}
            //);
            //t5.Start();

            Console.ReadLine();
        }
Esempio n. 3
0
 public bool OpenDisplay(AdvancedSettings UseSettings)
 {
   Log.Info("MatrixGX.MOGXDisplay.OpenDisplay() - called");
   this.AdvSettings = UseSettings;
   MiniDisplayHelper.InitEQ(ref this.EQSettings);
   MiniDisplayHelper.InitDisplayControl(ref this.DisplaySettings);
   this.ParseAdvancedSettings();
   try
   {
     using (Profile.Settings settings = new Profile.MPSettings())
     {
       this._AudioUseASIO = settings.GetValueAsBool("audioplayer", "asio", false);
     }
     this.GX_Client = new DCClient();
     if (!this.GX_Client.Connect())
     {
       Log.Info("MatrixGX.MOGXDisplay.OpenDisplay() - Could not connect to DriverCore service");
       this._isOpen = false;
     }
     else
     {
       Log.Info("MatrixGX.MOGXDisplay.OpenDisplay() - Connect to the DriverCore service");
       this.GX_Devices = this.GX_Client.Devices;
       if (this.GX_Devices.Count() > 0)
       {
         Log.Info("MatrixGX.MOGXDisplay.OpenDisplay() - Found a GX series device");
         this.GX_Session = this.GX_Devices[0].CreateSession("MediaPortal");
         this.GX_Session.CreateGraphics(out this.GX_Surface);
         this.GX_Graphics = Graphics.FromImage(this.GX_Surface);
         this._isOpen = true;
         this._isClosing = false;
         Log.Info("MatrixGX.MOGXDisplay.OpenDisplay() - Display Opened");
         this.BacklightOn();
         this.GX_Session.SetOptions(true, false);
         if (this.MOGX_Control.InvertDisplay)
         {
           this.GX_Session.SetOptions(true, true);
         }
         this.stopDisplayUpdateThread = false;
         this._displayThread = new Thread(new ThreadStart(this.DisplayUpdate));
         this._displayThread.IsBackground = true;
         this._displayThread.Priority = ThreadPriority.BelowNormal;
         this._displayThread.Name = "DisplayUpdateThread";
         this._displayThread.Start();
         if (this._displayThread.IsAlive)
         {
           Log.Info("MatrixGX.MOGXDisplay.DisplayUpdate() Thread Started");
         }
         else
         {
           Log.Info("MatrixGX.MOGXDisplay.DisplayUpdate() FAILED TO START");
           this.CloseDisplay();
         }
       }
       else
       {
         Log.Info("MatrixGX.MOGXDisplay.OpenDisplay() - No GX Series Display found");
         this._isOpen = false;
       }
     }
   }
   catch (Exception exception)
   {
     Log.Info("MatrixGX.MOGXDisplay.OpenDisplay() - Display not opened - caught exception {0}",
              new object[] {exception.ToString()});
     Log.Error(exception);
     this._isOpen = false;
   }
   Log.Info("MatrixGX.MOGXDisplay.OpenDisplay() - Completed");
   return this._isOpen;
 }
Esempio n. 4
0
        static void Main(string[] args)
        {
            DCClient client = DCClient.Instance("TESTSRV", "global");

            client.Srv("Add", Program.add);
        }
Esempio n. 5
0
 internal void Stop()
 {
     //db.Dispose();
     DCClient.Dispose(clt);
 }
Esempio n. 6
0
 public void Start()
 {
     clt = DCClient.Instance("BizSampleSrv", "global");
     //clt.Srv("/veginfo/list", veginfoList);
     clt.Srv("/test/helloworld", helloworld);
 }
Esempio n. 7
0
        //private string lsnrUrl = "http://+:8080/";
        //private string localMngPort = "8090";

        public void Start()
        {
            IConfigSource cs = new IniConfigSource(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ConnectorRest.ini"));

            //lsnrUrl = cs.Configs["init"].Get("ListenPoint");
            //localMngPort = cs.Configs["init"].Get("LocalManagePort");

            lsnrThrd = new Thread(new ThreadStart(delegate()
            {
                // 检查系统是否支持
                if (!HttpListener.IsSupported)
                {
                    DCLogger.LogError("软件运行需要 Windows XP SP2 或 Server 2003 以上系统.");
                }

                // 注意前缀必须以 / 正斜杠结尾
                string[] prefixes = cs.Configs["init"].Get("ListenPoint").Split(',');

                // 设置manifest UAC权限
                foreach (string lsnrUrl in prefixes)
                {
                    AddAddress(lsnrUrl);
                }

                // 创建监听器.
                HttpListener listener = new HttpListener();
                // 增加监听的前缀.
                foreach (string lsnrUrl in prefixes)
                {
                    listener.Prefixes.Add(lsnrUrl);
                }


                //开始监听
                try
                {
                    listener.Start();
                }
                catch (Exception ex)
                {
                    DCLogger.LogError(ex.Message);
                    throw ex;
                }

                foreach (string lsnrUrl in prefixes)
                {
                    DCLogger.LogInfo(string.Format("REST监听启动于:{0}", lsnrUrl));
                }
                DCClient client = DCClient.Instance("ConnectorRest", "global");
                long length     = 0;
                Stopwatch watch = new Stopwatch();
                watch.Start();
                while (true)
                {
                    try
                    {
                        // 注意: GetContext 方法将阻塞线程,直到请求到达
                        HttpListenerContext context = listener.GetContext();
                        // 取得请求对象
                        HttpListenerRequest request = context.Request;

                        length += 1;

                        if (watch.ElapsedMilliseconds > 10000)
                        {
                            DCLogger.LogInfo(string.Format("Connect Pressure:{0}requests/s\t{1}", length * 1000 / (watch.ElapsedMilliseconds), DateTime.Now));
                            length = 0;
                            watch.Reset();
                            watch.Start();
                        }

                        //if (request.RawUrl.Equals("/connector/stop"))
                        //    break;
                        if (request.RawUrl.Equals("/helloworld"))
                        {
                            // 取得回应对象
                            HttpListenerResponse response = context.Response;
                            byte[] ack = Encoding.UTF8.GetBytes("Hello World!");
                            response.ContentLength64 = ack.LongLength;
                            response.ContentType     = "text/plain; charset=UTF-8";
                            response.StatusCode      = 200;
                            // 输出回应内容
                            try
                            {
                                using (BinaryWriter writer = new System.IO.BinaryWriter(response.OutputStream))
                                {
                                    writer.Write(ack, 0, (int)response.ContentLength64);
                                }
                            }
                            catch (Exception ex)
                            {
                                DCLogger.LogError(ex.Message);
                            }
                            continue;
                        }

                        if (request.ContentLength64 < 0 || request.ContentLength64 > 20000000)
                        {
                            string resp = string.Format("超长的Rest请求内容,长度{0}", request.ContentLength64);
                            DCLogger.LogError(resp);

                            // 取得回应对象
                            HttpListenerResponse response = context.Response;

                            // 设置回应头部内容,长度,编码
                            response.ContentLength64 = resp.Length;
                            response.ContentType     = "text/plain; charset=UTF-8";
                            response.StatusCode      = 500;
                            // 输出回应内容
                            try
                            {
                                using (BinaryWriter writer = new BinaryWriter(response.OutputStream))
                                {
                                    writer.Write(Encoding.UTF8.GetBytes(resp));
                                }
                            }
                            catch (Exception ex)
                            {
                                DCLogger.LogError(ex.Message);
                            }
                            continue;
                        }

                        byte[] postData = getPostData(request);
                        if (request.ContentLength64 > 0 && request.ContentLength64 <= 256)
                        {
                            DCLogger.LogTrace(string.Format(
                                                  "{0}-->{1}:::{2}",
                                                  request.RemoteEndPoint,
                                                  request.RawUrl,
                                                  Global.Encoding.GetString(postData)
                                                  )
                                              );
                        }
                        else if (request.ContentLength64 > 256 && request.ContentLength64 <= 4096)
                        {
                            DCLogger.LogTrace(string.Format(
                                                  "{0}-->{1}:::{2}",
                                                  request.RemoteEndPoint,
                                                  request.RawUrl,
                                                  Global.Encoding.GetString(postData, 0, 256) + "..."
                                                  )
                                              );
                        }
                        else
                        {
                            DCLogger.LogTrace(string.Format(
                                                  "{0}-->{1}:::{2}",
                                                  request.RemoteEndPoint,
                                                  request.RawUrl,
                                                  string.Format("{0} bytes long content.", request.ContentLength64)
                                                  )
                                              );
                        }
                        //if (postData == null)
                        //{
                        //    HttpListenerResponse response = context.Response;
                        //    response.StatusCode = 404;
                        //    response.Close();
                        //}
                        //else
                        {
                            try
                            {
                                client.Act(request.RawUrl, postData, (rst) =>
                                {
                                    // 取得回应对象
                                    HttpListenerResponse response = context.Response;

                                    // 设置回应头部内容,长度,编码
                                    int httpHeadInfoLength    = BitConverter.ToInt32(rst.ResultData, 0);
                                    HttpHeadInfo httpHeadInfo = HttpHeadInfo.FromBytes(rst.ResultData, 4, httpHeadInfoLength);
                                    int rawBytesIndex         = httpHeadInfoLength + 4;
                                    response.ContentLength64  = rst.ResultData.LongLength - rawBytesIndex;
                                    response.ContentType      = httpHeadInfo.ContentType;
                                    response.StatusCode       = (int)httpHeadInfo.StatusCode;
                                    // 输出回应内容
                                    try
                                    {
                                        using (BinaryWriter writer = new System.IO.BinaryWriter(response.OutputStream))
                                        {
                                            writer.Write(rst.ResultData, rawBytesIndex, (int)response.ContentLength64);
                                        }

                                        if (response.ContentType.Equals(HttpContentType.Json))
                                        {
                                            if (response.ContentLength64 > 256)
                                            {
                                                DCLogger.LogTrace(string.Format(
                                                                      "{0}<--{1}:::{2}",
                                                                      request.RemoteEndPoint,
                                                                      request.RawUrl,
                                                                      Global.Encoding.GetString(rst.ResultData, rawBytesIndex, 256) + "..."
                                                                      )
                                                                  );
                                            }
                                            else
                                            {
                                                DCLogger.LogTrace(string.Format(
                                                                      "{0}<--{1}:::{2}",
                                                                      request.RemoteEndPoint,
                                                                      request.RawUrl,
                                                                      Global.Encoding.GetString(rst.ResultData, rawBytesIndex, (int)response.ContentLength64)
                                                                      )
                                                                  );
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        DCLogger.LogError(ex.Message);
                                    }
                                }
                                           );
                            }
                            catch (Exception ex)
                            {
                                DCLogger.LogError(ex.Message);

                                // 取得回应对象
                                HttpListenerResponse response = context.Response;

                                // 设置回应头部内容,长度,编码
                                response.ContentLength64 = ex.Message.Length;
                                response.ContentType     = "text/plain; charset=UTF-8";
                                response.StatusCode      = 500;
                                // 输出回应内容
                                try
                                {
                                    using (BinaryWriter writer = new BinaryWriter(response.OutputStream))
                                    {
                                        writer.Write(Encoding.UTF8.GetBytes(ex.Message));
                                    }
                                }
                                catch (Exception ex2)
                                {
                                    DCLogger.LogError(ex2.Message);
                                }

                                //response.Close();
                            }
                        }
                    }
                    catch (ThreadAbortException)
                    {
                        break;
                    }
                    catch
                    { }
                }

                // 关闭服务器
                listener.Stop();
                DCLogger.LogInfo(string.Format("REST监听关闭:{0}", prefixes));
                DCClient.Dispose(client);
            }
                                                  ));
            lsnrThrd.IsBackground = true;
            lsnrThrd.Start();
        }