示例#1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //-- 启动一个服务器
            appServer = new AppServer();

            var serverConfig = new ServerConfig
            {
                Port = 2010, //set the listening port
                TextEncoding = "UTF-8",
            };

            //Setup the appServer
            if (!appServer.Setup(serverConfig))
            {
                System.Diagnostics.Debug.Write("创建App Server失败");
            }

            //Try to start the appServer
            if (!appServer.Start())
            {
                System.Diagnostics.Debug.Write("启动App Server失败");
            }

            var mainFrm = new MainForm();
            appServer.NewSessionConnected += mainFrm.appServerNewSessionConnected;
            appServer.SessionClosed += mainFrm.appServerSessionClosed;
            Application.Run(mainFrm);

            //Stop the appServer
            appServer.Stop();
        }
示例#2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Press any key to start the server!");

            Console.ReadKey();
            Console.WriteLine();

            var appServer = new AppServer();

            //Setup with config model, which provides more options
            var serverConfig = new ServerConfig
            {
                Port = 2012, //set the listening port
                //Other configuration options
                //Mode = SocketMode.Udp,
                //MaxConnectionNumber = 100,
                //...
            };

            //Setup the appServer
            if (!appServer.Setup(serverConfig))
            {
                Console.WriteLine("Failed to setup!");
                Console.ReadKey();
                return;
            }

            appServer.NewSessionConnected += new SessionHandler<AppSession>(appServer_NewSessionConnected);

            Console.WriteLine();

            //Try to start the appServer
            if (!appServer.Start())
            {
                Console.WriteLine("Failed to start!");
                Console.ReadKey();
                return;
            }

            Console.WriteLine("The server started successfully, press key 'q' to stop it!");

            while (Console.ReadKey().KeyChar != 'q')
            {
                Console.WriteLine();
                continue;
            }

            Console.WriteLine();
            //Stop the appServer
            appServer.Stop();
            
            Console.WriteLine("The server was stopped!");
        }
示例#3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Press any key to start the server!");

            Console.ReadKey();
            Console.WriteLine();

            var appServer = new AppServer<TelnetSession>();

            var serverConfig = new ServerConfig
            {
                Port = 2012 //set the listening port
            };

            //Setup the appServer
            if (!appServer.Setup(serverConfig))
            {
                Console.WriteLine("Failed to setup!");
                Console.ReadKey();
                return;
            }

            Console.WriteLine();

            //Try to start the appServer
            if (!appServer.Start())
            {
                Console.WriteLine("Failed to start!");
                Console.ReadKey();
                return;
            }

            Console.WriteLine("The server started successfully, press key 'q' to stop it!");

            while (Console.ReadKey().KeyChar != 'q')
            {
                Console.WriteLine();
                continue;
            }

            //Stop the appServer
            appServer.Stop();

            Console.WriteLine();
            Console.WriteLine("The server was stopped!");
            Console.ReadKey();
        }
示例#4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Press any key to start the server!");

            Console.ReadKey();
            Console.WriteLine();

            var appServer = new AppServer();

            //Setup the appServer
            if (!appServer.Setup("127.0.0.1", 2012)) //Setup with listening IP and port
            {
                Console.WriteLine("Failed to setup!");
                Console.ReadKey();
                return;
            }

            appServer.NewSessionConnected += new SessionHandler<AppSession>(appServer_NewSessionConnected);
            appServer.NewRequestReceived += new RequestHandler<AppSession, StringRequestInfo>(appServer_NewRequestReceived);

            Console.WriteLine();

            //Try to start the appServer
            if (!appServer.Start())
            {
                Console.WriteLine("Failed to start!");
                Console.ReadKey();
                return;
            }

            Console.WriteLine("The server started successfully, press key 'q' to stop it!");

            while (Console.ReadKey().KeyChar != 'q')
            {
                Console.WriteLine();
                continue;
            }

            //Stop the appServer
            appServer.Stop();

            Console.WriteLine();
            Console.WriteLine("The server was stopped!");
            Console.ReadKey();
        }
示例#5
0
        static void Main(string[] args)
        {
            Console.WriteLine("Press any key to start the server!");

            Console.ReadKey();
            Console.WriteLine();

            var appServer = new AppServer();
            appServer.NewSessionConnected += AppServer_NewSessionConnected;
            appServer.SessionClosed += AppServer_SessionClosed;
            appServer.NewRequestReceived += AppServer_NewRequestReceived;
            
            //Setup the appServer
            if (!appServer.Setup(55555)) //Setup with listening port
            {
                Console.WriteLine("Failed to setup!");
                Console.ReadKey();
                return;
            }

            Console.WriteLine();

            //Try to start the appServer
            if (!appServer.Start())
            {
                Console.WriteLine("Failed to start!");
                Console.ReadKey();
                return;
            }

            Console.WriteLine("The server started successfully, press key 'q' to stop it!");

            while (Console.ReadKey().KeyChar != 'q')
            {
                Console.WriteLine();
            }

            //Stop the appServer
            appServer.Stop();

            Console.WriteLine("The server was stopped!");
            Console.ReadKey();
        }
示例#6
0
        private static ExitKind RunAppServer(AppServer.StartupParameters startupParameters)
        {
            ExitKind exitKind;

            using (
                var server =
                    new AppServer(maximumIdleTime: new TimeSpan(hours: 0, minutes: startupParameters.ServerMaxIdleTimeInMinutes, seconds: 0)))
            {
                exitKind = server.Run(startupParameters);
            }

            Exception telemetryShutdownException;

            if (AriaV2StaticState.TryShutDown(out telemetryShutdownException) == AriaV2StaticState.ShutDownResult.Failure)
            {
                exitKind = ExitKind.InfrastructureError;
            }

            return(exitKind);
        }
示例#7
0
        private void btnBind_Click(object sender, EventArgs e)
        {
            if (this.dbGridView_RK.Rows.Count == 0 || this.dbGridView_RK.SelectedCells.Count == 0)
            {
                return;
            }
            //
            DataTable dt    = null;
            var       model = new Ref_WS_STK.DataType_存货();

            model.ExAction = "IsBind";
            model.存货编码     = this.dbGridView_RK.Rows[this.dbGridView_RK.CurrentCell.RowIndex].Cells["存货编码"].Value.ToString();
            model.默认仓库编码   = (string)this.cbx仓库编码.SelectedValue;
            AppServer.UsingWcf(() =>
            {
                dt = AppServer.wcfClient.BAS_存货_List(model).Tables[0];
            });
            //
            if (dt.Rows.Count > 0)
            {
                if (!AppServer.DialogMsg(String.Format("存货“{0}”已经在货架“{1}”上了,是否更改存放货架?",
                                                       this.dbGridView_RK.Rows[this.dbGridView_RK.CurrentCell.RowIndex].Cells["存货名称"].Value,
                                                       dt.Rows[0]["仓库名称"].ToString())))
                {
                    return;
                }
            }
            //
            using (var Fm = new M01_基础设置.BAS_货架设置_Select())
            {
                Fm.Select_Mod((string)this.cbx仓库编码.SelectedValue);
                if (Fm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    foreach (DataGridViewCell Cell in this.dbGridView_RK.SelectedCells)
                    {
                        this.dbGridView_RK.Rows[Cell.RowIndex].Cells["存放货架"].Value = Fm.CKName;
                        this.dbGridView_RK.Rows[Cell.RowIndex].Cells["货架编码"].Value = Fm.CKCode;
                    }
                }
            }
        }
示例#8
0
        private void btnSetCnt_Click(object sender, EventArgs e)
        {
            if (this.dbGridView_RK.Rows.Count == 0 || this.dbGridView_RK.SelectedCells.Count == 0)
            {
                return;
            }
            //
            bool fg = false;

            foreach (DataGridViewCell Cell in this.dbGridView_RK.SelectedCells)
            {
                if (this.dbGridView_RK.Columns[Cell.ColumnIndex].HeaderText.Equals("入库单价") ||
                    this.dbGridView_RK.Columns[Cell.ColumnIndex].HeaderText.Equals("入库数量") ||
                    this.dbGridView_RK.Columns[Cell.ColumnIndex].HeaderText.Equals("金额"))
                {
                    fg = true;
                    break;
                }
            }
            if (!fg)
            {
                AppServer.ShowMsg_Warn("所选内容没有包含入库单价、入库数量和金额,请核对");
                return;
            }
            //
            using (var Fm = new STK_库存入库_SetCnt())
            {
                if (Fm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    foreach (DataGridViewCell Cell in this.dbGridView_RK.SelectedCells)
                    {
                        if (this.dbGridView_RK.Columns[Cell.ColumnIndex].HeaderText.Equals("入库单价") ||
                            this.dbGridView_RK.Columns[Cell.ColumnIndex].HeaderText.Equals("入库数量") ||
                            this.dbGridView_RK.Columns[Cell.ColumnIndex].HeaderText.Equals("金额"))
                        {
                            Cell.Value = Fm.Value;
                        }
                    }
                }
            }
        }
示例#9
0
        static void Main(string[] args)
        {
            Console.WriteLine("Press any key to start the server!");

            Console.ReadKey();
            Console.WriteLine();

            var appServer = new AppServer();

            //Setup the appServer
            if (!appServer.Setup(2012)) //Setup with listening port
            {
                Console.WriteLine("Failed to setup!");
                Console.ReadKey();
                return;
            }

            Console.WriteLine();

            //Try to start the appServer
            if (!appServer.Start())
            {
                Console.WriteLine("Failed to start!");
                Console.ReadKey();
                return;
            }

            Console.WriteLine("The server started successfully, press key 'q' to stop it!");

            while (Console.ReadKey().KeyChar != 'q')
            {
                Console.WriteLine();
                continue;
            }

            //Stop the appServer
            appServer.Stop();

            Console.WriteLine("The server was stopped!");
            Console.ReadKey();
        }
 private Boolean PostData()
 {
     if (this.txt类别名称.Text == "")
     {
         AppServer.ShowMsg("请输入类别名称");
         this.txt类别名称.Focus();
         return(false);
     }
     //
     try
     {
         var model = new Ref_WS_STK.DataType_存货_类别();
         model.ExAction = this.Tag.ToString();
         TY.Helper.FormHelper.DataBinding_DataSourceToModel(this, model);
         model.级编码           = this.txt上级类别名称.Tag.ToString();
         model.类别编码          = this.txt类别名称.Tag.ToString();
         model.类别状态          = this.cbx类别状态.SelectedValue.ToIntegerDef();
         model.LoginUserCode = AppServer.LoginUserCode;
         AppServer.UsingWcf(() =>
         {
             AppServer.wcfClient.BAS_存货_类别_Edit(ref model);
         });
         if (model.ExResult != 0)
         {
             AppServer.ShowMsg_SubmitError(model.ErrorMsg);
             return(false);
         }
         //
         this.NewSortName = this.txt类别名称.Text;
         if (this.OnAddNewNodeEvent != null)
         {
             this.OnAddNewNodeEvent(model.级编码, model.类别编码, model.类别名称);
         }
     }
     catch (Exception ex)
     {
         AppServer.ShowMsg_ExceptError(ex.Message);
         return(false);
     }
     return(true);
 }
示例#11
0
        static void Main(string[] args)
        {
            // Insert Product Test -- there be dragons!
            //BackendDataHandling BDH = new BackendDataHandling();
            //Product testproduct = new Product("Test3", "TestBeschreibung", "TestCategory", "Y", 33, new byte[100], "image//jpg", "shirt.jpg", new DateTime(), "Sweet", 44, new DateTime(), new DateTime(), null, null);
            //BDH.AddProduct(testproduct);

            /* Update Product Test
             * BackendDataHandling BHD = new BackendDataHandling();
             * bool temp;
             * temp = BHD.UpdateProductFID(5, 56);
             */
            Console.WriteLine("Chocolate Costumizer Synchronizer\nPress Enter to end the application.\n");

            // Frontend Host Variante 1

            /*ServiceHost frontendServiceHost = new ServiceHost(typeof(RestServiceImpl));
             * Task.Factory.StartNew(frontendServiceHost.Open);
             * Console.WriteLine("Frontend Service Host startet");
             * frontendServiceHost.Close();*/

            // Frontend Host Variante 2
            WebServiceHost       frontendServiceHost = new WebServiceHost(typeof(RestServiceImpl), new Uri("http://localhost:8000"));
            ServiceEndpoint      ep  = frontendServiceHost.AddServiceEndpoint(typeof(IRestServiceImpl), new WebHttpBinding(), "");
            ServiceDebugBehavior stp = frontendServiceHost.Description.Behaviors.Find <ServiceDebugBehavior>();

            stp.HttpHelpPageEnabled = false;
            frontendServiceHost.Open();
            Console.WriteLine("Frontend Service is up and running");
            //Console.WriteLine("Please press enter to quit");


            AppServer appServer = new AppServer();

            Console.ReadLine();

            // Close Frontend Host
            frontendServiceHost.Close();

            //end server?
        }
示例#12
0
        static void Main(string[] args)
        {
            Console.WriteLine("Press any key to start the server!");

            Console.ReadKey();
            Console.WriteLine();

            var appServer = new AppServer();

            //Setup the appServer
            if (!appServer.Setup(2012)) //Setup with listening port
            {
                Console.WriteLine("Failed to setup!");
                Console.ReadKey();
                return;
            }

            Console.WriteLine();

            //Try to start the appServer
            if (!appServer.Start())
            {
                Console.WriteLine("Failed to start!");
                Console.ReadKey();
                return;
            }

            Console.WriteLine("The server started successfully, press key 'q' to stop it!");

            while (Console.ReadKey().KeyChar != 'q')
            {
                Console.WriteLine();
                continue;
            }

            //Stop the appServer
            appServer.Stop();

            Console.WriteLine("The server was stopped!");
            Console.ReadKey();
        }
示例#13
0
        private static void Main(string[] args)
        {
            Console.WriteLine("Press any key to start the server!");

            var appServer = new AppServer();

            //Setup the appServer
            if (!appServer.Setup(2020)) //Setup with listening port
            {
                Console.WriteLine("Failed to setup!");
                Console.ReadKey();
                return;
            }

            Console.WriteLine();

            appServer.NewSessionConnected += new SessionHandler <AppSession>(appServer_NewSessionConnected);
            appServer.NewRequestReceived  += new RequestHandler <AppSession, StringRequestInfo>(appServer_NewRequestReceived);

            //Try to start the appServer
            if (!appServer.Start())
            {
                Console.WriteLine("Failed to start!");
                Console.ReadKey();
                return;
            }

            Console.WriteLine("The server started successfully, press key 'q' to stop it!");

            while (Console.ReadKey().KeyChar != 'q')
            {
                Console.WriteLine();
                continue;
            }

            //Stop the appServer
            appServer.Stop();

            Console.WriteLine("The server was stopped!");
            Console.ReadKey();
        }
示例#14
0
        private void DataBinding_cbx仓库()
        {
            DataTable dt = null;

            //
            Ref_WS_STK.DataType_仓库 model = new Ref_WS_STK.DataType_仓库();
            model.ExAction = "ALLCK";
            AppServer.UsingWcf(() =>
            {
                dt = AppServer.wcfClient.BAS_仓库_List(model).Tables[0];
            });
            //
            this.cbx仓库编码.ValueMember   = "仓库编码";
            this.cbx仓库编码.DisplayMember = "仓库名称";
            this.cbx仓库编码.DataSource    = dt;
            //
            if (this.cbx仓库编码.Items.Count > 0)
            {
                this.cbx仓库编码.SelectedIndex = 0;
            }
        }
示例#15
0
        public static void StartNewServer(int port)
        {
            if (appServerDic.ContainsKey(port))
            {
                throw new Exception($"The server with port {port} has exist.");
            }

            AppServer appServer = new AppServer();

            if (appServer.Setup(port))
            {
                throw new Exception($"The server with port {port} setup failed.");
            }

            if (!appServer.Start())
            {
                throw new Exception($"The server with port {port} start failed.");
            }

            appServerDic.Add(port, appServer);
        }
 private void btnMod_Click(object sender, EventArgs e)
 {
     if (this.dbGridView.SelectedRows.Count == 0)
     {
         return;
     }
     if (!String.IsNullOrWhiteSpace(this.dbGridView.SelectedRows[0].Cells["审核时间"].Value.ToString()))
     {
         AppServer.ShowMsg_Warn("该出库单已被审核,不能再修改了!");
         return;
     }
     //
     using (var Fm = new STK_库存出库_Editor())
     {
         Fm.Editor_Mod(this.dbGridView.SelectedRows[0].Cells["单据编码"].Value.ToString());
         if (Fm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             this.DataBinding_dbGridView(this.dbGridView.CurrentRow.Index);
         }
     }
 }
示例#17
0
        public void Uninitialize()
        {
            try
            {
                BiuIoManager.Instance.RemoveHandler(NetDebugLogTransmissionManager.Handler_DebugN1);

                _server = null;

                _ashley.Dispose();
                _ashley = null;

                _securityProvider.Dispose();
                _securityProvider = null;

                TransmissionManager.CleanUpWSA();
            }
            catch
            {
                throw;
            }
        }
示例#18
0
        private void btnEnter_Click(object sender, EventArgs e)
        {
            var model = new Ref_WS_STK.DataType_仓库();

            model.ExAction  = "Bind";
            model.MxDataXML = (this.dbGridView_CWX.DataSource as DataTable).ToXml("ar");
            AppServer.UsingWcf(() =>
            {
                AppServer.wcfClient.BAS_储物箱_Edit(ref model);
            });
            //
            if (model.ExResult != 0)
            {
                AppServer.ShowMsg_Error(model.ErrorMsg);
                return;
            }
            else
            {
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
        }
        public void View_CK(string CKCode, string CKName, string CHCode, string CHName, string GGXH, string KJQJ)
        {
            this.Text          = String.Format("查看出库信息一{0}", CHName);
            this.lblTitle.Text = "出库信息列表";
            this.lbl仓库名称.Text  = String.Format("查看仓库:{0}", CKName);
            this.lbl存货名称.Text  = String.Format("查看存货:{0}  {1}", CHName, GGXH);
            this.lbl会计期间.Text  = String.Format("会计期间:{0}", KJQJ);
            //
            AppServer.SetGridViewStyle(this.dbGridView);
            this.dbGridView.GridStr(AppServer.GetTableDef("STK_库存总账_出库明细"));
            //
            var model = new Ref_WS_STK.DataType_库存管理();

            model.ExAction = "CK_Dtl";
            model.仓库编码     = CKCode;
            model.存货编码     = CHCode;
            model.会计期间     = KJQJ;
            AppServer.UsingWcf(() =>
            {
                this.dbGridView.DataSource = AppServer.wcfClient.STK_库存总账_List(model).Tables[0];
            });
        }
示例#20
0
        /// <summary>
        /// Post send to client
        /// </summary>
        /// <param name="opCode"></param>
        /// <param name="data"></param>
        /// <param name="offset"></param>
        /// <param name="count"></param>
        /// <param name="callback"></param>
        private async System.Threading.Tasks.Task <bool> PostSend(sbyte opCode, byte[] data, int offset, int count, Action <SocketAsyncResult> callback)
        {
            if (!IsSocket)
            {
                TraceLog.WriteError("Session does not support the push message");
                return(false);
            }
            if (data == null || data.Length == 0)
            {
                return(false);
            }
            if (!IsRemote && ProxySid != Guid.Empty)
            {
                //return proxy data format.
                data   = CheckAdditionalHead(data, ProxySid);
                count += 16;
            }

            await AppServer.PostSend(_exSocket, opCode, data, offset, count, callback);

            return(true);
        }
 private void btn设置存放仓库_Click(object sender, EventArgs e)
 {
     if (this.dbGridView.SelectedRows.Count == 0)
     {
         return;
     }
     //
     using (var Fm = new BAS_存货设置_选择仓库())
     {
         Fm.Editor_Mod(this.dbGridView.SelectedRows[0].Cells["默认仓库编码"].Value.ToString());
         if (Fm.ShowDialog() == DialogResult.OK)
         {
             this.Cursor = Cursors.WaitCursor;
             //
             var model = new Ref_WS_STK.DataType_存货();
             model.ExAction = "Bind_MRCK";
             AppServer.UsingWcf(() =>
             {
                 foreach (DataGridViewRow Row in this.dbGridView.SelectedRows)
                 {
                     model.存货编码   = Row.Cells["存货编码"].Value.ToString();
                     model.默认仓库编码 = Fm.CKCodes;
                     AppServer.wcfClient.BAS_存货_Edit(ref model);
                     //
                     if (model.ExResult != 0)
                     {
                         AppServer.ShowMsg_Error(model.ErrorMsg);
                         break;
                     }
                     //
                     Row.Cells["默认仓库"].Value   = Fm.CKNames;
                     Row.Cells["默认仓库编码"].Value = Fm.CKCodes;
                 }
             });
             //
             this.Cursor = Cursors.Default;
         }
     }
 }
示例#22
0
        private void FrmMain_Load(object sender, EventArgs e)
        {
            var config = new ServerConfig()
            {
                Name                     = "AliPayServer",
                ClearIdleSession         = true,
                ClearIdleSessionInterval = 60,
                IdleSessionTimeOut       = 90,
                Ip   = "Any",
                Port = 10100,
                Mode = SuperSocket.SocketBase.SocketMode.Tcp,
                MaxConnectionNumber = 600,
                MaxRequestLength    = 1024 * 1024 * 20,
                Security            = "tls",
                LogCommand          = true,
                Certificate         = new CertificateConfig
                {
                    Password = "******",
                    FilePath = Application.StartupPath + @"\Certificates.pfx",
                }
            };

            appServer = new AppServer();
            appServer.NewSessionConnected += AppServer_NewSessionConnected;
            appServer.NewRequestReceived  += AppServer_NewRequestReceived;
            //appServer = new WebSocketServer();
            //appServer.NewSessionConnected += AppServer_NewSessionConnected1;
            //appServer.NewDataReceived += AppServer_NewDataReceived;
            if (appServer.Setup(1100))
            {
                if (appServer.Start())
                {
                    txtContent.Text = "服务器已启动";
                }
            }

            //var bootstrap = new DefaultBootstrap(new RootConfig(), new IWorkItem[] { appServer });
            //bootstrap.Start();
        }
示例#23
0
        static void Main(string[] args)
        {
            //// CommandBus
            //var dis = new Dispatcher();
            //StringRequestInfo cmd = new StringRequestInfo();
            //cmd.Key = "ADD";
            //dis.ExecuteCommand(null, cmd);

            // socket server
            var appServer = new AppServer();

            appServer.Setup(9527);
            appServer.NewRequestReceived += AppServer_NewRequestReceived;
            appServer.Start();
            while (Console.ReadKey().KeyChar != 'q')
            {
                Console.WriteLine();
                continue;
            }
            appServer.Stop();

            //// socket client
            //EasyClient client = new EasyClient();
            //var r = client.ConnectAsync("127.0.0.1", 9988);
            //client.NewRequestReceived += Client_NewRequestReceived;
            //var rst = r.Result;
            //Thread th = new Thread(() =>
            //  {
            //      int n = 0;
            //      while (true)
            //      {
            //          if (client.Send(BitConverter.GetBytes(n)))
            //              n++;
            //          Thread.Sleep(1000);
            //      }
            //  });
            //th.Start();
            Console.ReadLine();
        }
示例#24
0
 private void DataBinding_dbTreeView()
 {
     base.Cursor = Cursors.WaitCursor;
     try
     {
         var model = new Ref_WS_STK.DataType_存货_类别();
         model.ExAction = "Tree";
         model.类别状态     = 0;
         AppServer.UsingWcf(() =>
         {
             this.dbTreeView.DataSource = AppServer.wcfClient.BAS_存货_类别_List(model).Tables[0];
         });
         //
         this.dbTreeView.ClearTrees();
         this.dbTreeView.NodeID    = "类别编码";
         this.dbTreeView.NodePID   = "上级编码";
         this.dbTreeView.NodeTitle = "类别名称";
         this.dbTreeView.BuildTrees();
         //this.dbTreeView.Nodes[0].Expand();
         //this.dbTreeView.SelectedNode = (DBTreeNode)this.dbTreeView.Nodes[0];
         DBTreeNode PNode = (DBTreeNode)this.dbTreeView.Nodes[0];
         while (PNode.FirstNode != null)
         {
             PNode = (DBTreeNode)PNode.FirstNode;
         }
         //
         this.dbTreeView.SelectedNode = PNode;
     }
     catch (Exception ex)
     {
         AppServer.ShowMsg_ExceptError(ex.Message);
         return;
     }
     finally
     {
         AppServer.WcfService_Close();
         base.Cursor = Cursors.Arrow;
     }
 }
        internal void ConnectTarget(EndPoint remoteEndPoint, Action <ProxySession, TcpClientSession> connectedAction)
        {
            m_ConnectedAction = connectedAction;
            var targetSession = new AsyncTcpSession(remoteEndPoint);

            targetSession.ReceiveBufferSize = 2000000;
            targetSession.Connected        += targetSession_Connected;
            targetSession.Closed           += targetSession_Closed;
            targetSession.DataReceived     += targetSession_DataReceived;
            targetSession.Error            += targetSession_Error;

            var buffer = AppServer.RequestProxyBuffer();

            if (buffer.Array == null)
            {
                this.Close(CloseReason.ServerClosing);
                return;
            }

            m_BufferSegment = buffer;
            targetSession.Connect();
        }
示例#26
0
文件: Program.cs 项目: TTKLLL/Monitor
        static void Main(string[] args)
        {
            ServerConfig serverConfig = new ServerConfig()
            {
                Ip   = "192.168.168.96",
                Port = 8080,
                Mode = SocketMode.Tcp
            };

            AppServer server = new AppServer();

            if (!server.Setup(serverConfig))
            {
                Console.WriteLine("fail");
            }

            if (!server.Start())
            {
                Console.WriteLine("fail");
            }
            Console.WriteLine("success");
        }
示例#27
0
        public async Task H_AppServerReceivesNewRequestBeginEndMarkReceiver()
        {
            var filterFactory = new DefaultReceiveFilterFactory <TestBeginEndMarkReceiveFilter, StringRequestInfo>();

            AppServer appServer = new AppServer(filterFactory);

            Assert.IsTrue(appServer.Setup("127.0.0.1", 50060));

            Assert.IsTrue(appServer.Start());

            appServer.NewRequestReceived += (s, e) =>
            {
                Assert.AreEqual("Hola!", e.Key);
                byte[] data = Encoding.ASCII.GetBytes("|" + "Howdy!" + "||");
                s.Send(data, 0, data.Length);
            };

            EasyClient easyClient = new EasyClient();

            AutoResetEvent callbackEvent = new AutoResetEvent(false);

            easyClient.Initialize(new TestProtoBaseBeginEndMarkReceiverFilter(), (p) =>
            {
                Assert.AreEqual("Howdy!", p.OriginalRequest);
                callbackEvent.Set();
            });

            bool connected = easyClient.ConnectAsync(serverEndpoint).Result;

            Assert.IsTrue(connected);

            easyClient.Send(Encoding.ASCII.GetBytes("#Hola!##"));

            callbackEvent.WaitOne(timeout);

            await easyClient.Close();

            appServer.Stop();
        }
        private void btnDel_Click(object sender, EventArgs e)
        {
            if (this.dbTreeView.SelectedNode.Parent == null)
            {
                return;
            }
            if (this.dbTreeView.SelectedNode.Level == 0)
            {
                return;
            }
            if (this.dbTreeView.SelectedNode.Nodes.Count > 0)
            {
                AppServer.ShowMsg("请先删除当前类别下的子类别后再删除当前类别!");
                return;
            }
            if (!AppServer.DialogMsg("确认要删除当前类别吗?"))
            {
                return;
            }
            //
            var model = new Ref_WS_STK.DataType_存货_类别();

            model.ExAction = "Del";
            model.类别编码     = this.dbTreeView.SelectedNode.ID;
            AppServer.UsingWcf(() =>
            {
                AppServer.wcfClient.BAS_存货_类别_Edit(ref model);
            });
            //
            if (model.ExResult != 0)
            {
                AppServer.ShowMsg_SubmitError(model.ErrorMsg);
                return;
            }
            DBTreeNode pnode = (DBTreeNode)this.dbTreeView.SelectedNode.Parent;

            this.dbTreeView.SelectedNode.Remove();
            this.dbTreeView.SelectedNode = pnode;
        }
示例#29
0
        void ProcessPackageWithoutSessionID(Socket listenSocket, IPEndPoint remoteEndPoint, byte[] receivedData)
        {
            var sessionID  = remoteEndPoint.ToString();
            var appSession = AppServer.GetSessionByID(sessionID);

            if (appSession == null) //New session
            {
                appSession = CreateNewSession(listenSocket, remoteEndPoint, sessionID);

                //Failed to create a new session
                if (appSession == null)
                {
                    return;
                }

                appSession.ProcessRequest(receivedData, 0, receivedData.Length, false);
            }
            else //Existing session
            {
                appSession.ProcessRequest(receivedData, 0, receivedData.Length, false);
            }
        }
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        AppServer myScript = (AppServer)target;


        if (GUILayout.Button("Connect", GUILayout.Width(100)))
        {
            myScript.Start();
        }

        if (GUILayout.Button("Request", GUILayout.Width(100)))
        {
            myScript.GetPeriod("test/signalA", double.NaN, double.NaN, null);
        }

        if (GUILayout.Button("Publish", GUILayout.Width(100)))
        {
            myScript.Publish("~/test/publish", "Hello!");
        }
    }
示例#31
0
        public void Do()
        {
            var appServer = new AppServer();

            //Setup the appServer
            if (!appServer.Setup(2012))             //Setup with listening port
            {
                Console.WriteLine("Failed to setup!");
                Console.ReadKey();
                return;
            }

            Console.WriteLine();

            //Try to start the appServer
            if (!appServer.Start())
            {
                Console.WriteLine("Failed to start!");
                Console.ReadKey();
                return;
            }

            Console.WriteLine("The server started successfully, press key 'q' to stop it!");

            appServer.NewSessionConnected += AppServer_NewSessionConnected;
            //appServer.NewRequestReceived += AppServer_NewRequestReceived;

            while (Console.ReadKey().KeyChar != 'q')
            {
                Console.WriteLine();
                continue;
            }

            //Stop the appServer
            appServer.Stop();

            Console.WriteLine("The server was stopped!");
            Console.ReadKey();
        }
示例#32
0
        void ProcessPackageWithoutSessionID(Socket listenSocket, IPEndPoint remoteEndPoint, ArraySegment <byte> receivedData)
        {
            var sessionID  = remoteEndPoint.ToString();
            var appSession = AppServer.GetSessionByID(sessionID);

            if (appSession == null) //New session
            {
                if (!DetectConnectionNumber(remoteEndPoint))
                {
                    return;
                }

                var socketSession = new UdpSocketSession(listenSocket, remoteEndPoint, sessionID);

                appSession = AppServer.CreateAppSession(socketSession);

                if (appSession == null)
                {
                    return;
                }

                if (!DetectConnectionNumber(remoteEndPoint))
                {
                    return;
                }

                if (!AppServer.RegisterSession(appSession))
                {
                    return;
                }

                Interlocked.Increment(ref m_ConnectionCount);
                socketSession.Closed += OnSocketSessionClosed;
                socketSession.Start();
            }

            ((UdpSocketSession)appSession.SocketSession).ProcessReceivedData(receivedData, null);
        }
示例#33
0
        /// <summary>
        /// 开启TCP监听
        /// </summary>
        /// <returns></returns>
        public bool Start(out string errMsg)
        {
            errMsg    = "";
            appServer = new AppServer();
            ServerConfig serverConfig = new ServerConfig()
            {
                Ip                       = ip,
                Port                     = port,
                TextEncoding             = "UTF-8",
                Mode                     = SocketMode.Tcp,
                MaxConnectionNumber      = 500,
                ClearIdleSession         = true,
                ClearIdleSessionInterval = 30,
                IdleSessionTimeOut       = 60,
            };

            // 检查端口是否空闲
            if (!IPTool.IsValidPort(serverConfig.Port))
            {
                errMsg = "命令服务器的监听端口被占用,请更换端口号";
                return(false);
            }
            if (!appServer.Setup(serverConfig)) // 设置监听的IP和端口,不设置传输层协议,采用框架默认的TCP协议
            {
                errMsg = "superSocket设置IP和端口失败";
                return(false);
            }
            if (!appServer.Start())
            {
                errMsg = "superSocket启动失败";
                return(false);
            }
            // 绑定事件
            appServer.NewRequestReceived  += new RequestHandler <AppSession, StringRequestInfo>(appServer_NewRequestReceived);
            appServer.NewSessionConnected += new SessionHandler <AppSession>(appServer_NewSessionConnected);
            appServer.SessionClosed       += new SessionHandler <AppSession, CloseReason>(appServer_SessionClosed);
            return(true);
        }
示例#34
0
        public async Task F_AppSerserReplyToEasyClientNewRequestReceived()
        {
            AppServer appServer = new AppServer();

            Assert.IsTrue(appServer.Setup("127.0.0.1", 50060));

            Assert.IsTrue(appServer.Start());

            appServer.NewRequestReceived += (s, e) =>
            {
                Assert.AreEqual("Hello!", e.Key);

                s.Send("Hi There!");
            };

            EasyClient easyClient = new EasyClient();

            AutoResetEvent callbackEvent = new AutoResetEvent(false);

            easyClient.Initialize(new TestProtoBaseDefaultTerminatorReceiverFilter(), (p) =>
            {
                Assert.AreEqual("Hi There!", p.Key);

                callbackEvent.Set();
            });

            bool connected = easyClient.ConnectAsync(serverEndpoint).Result;

            Assert.IsTrue(connected);

            easyClient.Send(Encoding.ASCII.GetBytes("Hello!" + Environment.NewLine));

            callbackEvent.WaitOne(timeout);

            await easyClient.Close();

            appServer.Stop();
        }
        private bool PostData()
        {
            if (String.IsNullOrWhiteSpace(this.txt存货名称.Text))
            {
                AppServer.ShowMsg("存货名称不能为空或是全部空格");
                return(false);
            }
            if (this.rdbtn自定义.Checked && String.IsNullOrEmpty(this.txt存货序号.Text))
            {
                AppServer.ShowMsg("您选择的插入顺序为自定义,但没有选择存货");
                return(false);
            }
            //
            var model = new Ref_WS_STK.DataType_存货();

            model.ExAction = this.Tag.ToString();
            model.存货编码     = this.txt存货名称.Tag.ToString();
            TY.Helper.FormHelper.DataBinding_DataSourceToModel(this, model);
            model.类别编码          = this.txt类别名称.Tag.ToString();
            model.计量单位          = this.cbx计量单位.Text;
            model.LoginUserCode = AppServer.LoginUserCode;
            model.一个序号          = this.rdbtn自定义.Checked ? this.txt存货序号.Tag.ToIntegerDef() : -1;
            AppServer.UsingWcf(() =>
            {
                AppServer.wcfClient.BAS_存货_Edit(ref model);
            });
            //
            if (model.ExResult != 0)
            {
                AppServer.ShowMsg_Error(model.ErrorMsg);
                return(false);
            }
            if (this.OnAddNewDataEvent != null)
            {
                this.OnAddNewDataEvent(this.txt类别名称.Tag.ToString(), model.类别序号);
            }
            return(true);
        }
示例#36
0
        public CommandInfo(TCommand command, IEnumerable <CommandFilterAttribute> globalFilters)
        {
            Command = command;

            var allFilters = new List <CommandFilterAttribute>();

            if (globalFilters != null && globalFilters.Any())
            {
                allFilters.AddRange(globalFilters);
            }

            var filters = AppServer.GetCommandFilterAttributes(command.GetType());

            if (filters.Any())
            {
                allFilters.AddRange(filters);
            }

            if (allFilters.Any())
            {
                Filters = allFilters.OrderBy(f => f.Order).ToArray();
            }
        }
示例#37
0
 public abstract void Execute(AppServer server, Player player, object msg);
示例#38
0
        static void Main(string[] args)
        {
            Console.WriteLine("Press any key to start the server!");

            Console.ReadKey();
            Console.WriteLine();
            AppServer a = new AppServer();

            var bootstrap = BootstrapFactory.CreateBootstrap();

            if (!bootstrap.Initialize())
            {
                Console.WriteLine("Failed to initialize!");
                Console.ReadKey();
                return;
            }

            var result = bootstrap.Start();
            var ws = bootstrap.GetServerByName("WSServer");
            PlayServer Server = (bootstrap.GetServerByName("PlayServer") as PlayServer);
            Server.DisplayServer = ws as WebSocketTest.WSServer;

            Console.WriteLine("Start result: {0}!", result);

            if (result == StartResult.Failed)
            {
                Console.WriteLine("Failed to start!");
                Console.ReadKey();
                return;
            }

            Console.WriteLine("Press key 'q' to stop it!");
            /*
            while (Console.ReadKey().KeyChar != 'q')
            {
                Console.WriteLine();
                continue;
            }
            */
            while (true)
            {
                string str = Console.ReadLine();
                str = str.Trim();
                if (str == "start")
                {
                    //PlayServer Server = (bootstrap.GetServerByName("PlayServer") as PlayServer);
                    if (Server.GameStarted)
                    {
                        Console.WriteLine("Game has started");
                    }
                    else
                    {
                        Server.GameStart();
                        Console.WriteLine("Game Start!");
                    }
                }
                if (str == "q") break;
                if (str == "end")
                {
                    //PlayServer Server = (bootstrap.GetServerByName("PlayServer") as PlayServer);
                    Server.GameEnd();
                }
            }
            Console.WriteLine();

            //Stop the appServer
            bootstrap.Stop();

            Console.WriteLine("The server was stopped!");
        }
示例#39
0
        /// <summary>
        /// This method stops the service. If the service is not running, no action is taken.
        /// </summary>
        public void Stop()
        {
            if (Status == AppServerStatus.Started)
            {
                try
                {
                    server.Stop();
                }
                catch (Exception ex)
                {

                }
                server = null;

                AppDomain.Unload(dom);
                dom = null;
            }

            Status = AppServerStatus.NotStarted;
            NotifyPropertyChanged("Status");

            ErrorDescription = "";
            NotifyPropertyChanged("ErrorDescription");

            CanEdit = true;
            NotifyPropertyChanged("CanEdit");
        }
示例#40
0
        /// <summary>
        /// This method starts the service.
        /// </summary>
        /// <exception cref="Ximura.Windows.ServiceStartException">This exception is thrown if the service generates an unhandled exception.</exception>
        public void Start()
        {
            bool throwError = false;

            CanEdit = false;
            ErrorInStart = false;
            NotifyPropertyChanged("CanEdit");
            NotifyPropertyChanged("ErrorInStart");

            if (!CanStart)
            {
                ErrorDescription = "Service Disabled";
                NotifyPropertyChanged("ErrorDescription");
                Status = AppServerStatus.Disabled;
                NotifyPropertyChanged("Status");
                return;
            }

            ErrorDescription = "Starting";
            NotifyPropertyChanged("ErrorDescription");

            Status = AppServerStatus.Starting;
            NotifyPropertyChanged("Status");

            try
            {
                dom = AppDomain.CreateDomain(Name);

                server = (AppServer)dom.CreateInstanceAndUnwrap(ServerType.Assembly.FullName, ServerType.FullName);

                server.Start();

                Status = AppServerStatus.Started;
                NotifyPropertyChanged("Status");
                ErrorDescription = "";
                NotifyPropertyChanged("ErrorDescription");
            }
            catch (Exception ex)
            {
                ErrorDescription = string.Format("Error: {0}",ex.Message);
                ErrorInStart = true;
                Status = AppServerStatus.Failed;

                if (dom != null)
                {
                    AppDomain.Unload(dom);
                    dom = null;
                }

                NotifyPropertyChanged("ErrorInStart");
                NotifyPropertyChanged("Status");
                NotifyPropertyChanged("ErrorDescription");

                if (RaiseMessage != null)
                {
                    throwError = RaiseMessage(this,
                        string.Format("Service '{0}' cannot start. Do you wish to continue?", Name),
                        "Start error.", MessageBoxButton.YesNoCancel) != MessageBoxResult.Yes;
                }
                else
                    throwError = true;
            }


            if (throwError)
                throw new ServiceStartException(ErrorDescription);
        }
示例#41
0
        public void SocketTest()
        {
			string portStr =  System.Console.ReadLine();
			int port = System.Convert.ToInt32(portStr);
            AppServer<TextMessage> appServer = new AppServer<TextMessage>(port);
            appServer.Connected += (x, y) => _logger.Debug("socket", y.ToString());
            appServer.Disconnected += (x, y) => _logger.Debug("socket", y.ToString());
            appServer.Received += (x, y) => _logger.Debug("socket", y.ToString());

            appServer.StartListener();

            while (true)
            {
                string readLine = System.Console.ReadLine();
                if(string.IsNullOrEmpty(readLine))
                {
                    break;
                }
                TextMessage textMessage = new TextMessage();
                textMessage.Message = readLine;
                appServer.SendMessage(textMessage);
            }

            System.Console.ReadKey(true);
            appServer.StopListener();
        }