Exemplo n.º 1
0
 /// <summary>
 /// 开启服务
 /// </summary>
 public void StartService()
 {
     if (_Status != EServiceStatus.Stopped)
     {
         return;
     }
     if (_TypeLists.Count == 0)
     {
         return;
     }
     _Status = EServiceStatus.Starting;
     if (_TcpChannel == null)
     {
         //_TcpChannel = new TcpChannel(_Port);
         _TcpChannel = new TcpServerChannel(Guid.NewGuid().ToString(), _Port);
     }
     else
     {
         try
         {
             _TcpChannel.StopListening(null);
             ChannelServices.UnregisterChannel(_TcpChannel);
         }
         catch (Exception ex)
         {
             _Status = EServiceStatus.Stopped;
             throw ex;
         }
         Thread.Sleep(2000);
         //_TcpChannel = new TcpChannel(_Port);
         _TcpChannel = new TcpServerChannel(Guid.NewGuid().ToString(), _Port);
     }
     try
     {
         ChannelServices.RegisterChannel(_TcpChannel, false);
     }
     catch (Exception ex)
     {
         _TcpChannel = null;
         _Status     = EServiceStatus.Stopped;
         throw ex;
     }
     foreach (Type type in _TypeLists)
     {
         RemotingConfiguration.RegisterWellKnownServiceType(type, _UriName + "/" + type.Name, WellKnownObjectMode.Singleton);
     }
     RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.On;
     RemotingConfiguration.CustomErrorsEnabled(false);
     _Status    = EServiceStatus.Started;
     _StartTime = DateTime.Now;
 }
Exemplo n.º 2
0
        public void Start()
        {
            try
            {
                // Register TCP Channel
                channel = new TcpServerChannel("Archiver", Constants.TCPListeningPort);
                System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(channel, false);

                // Register the SAO
                RemotingConfiguration.RegisterWellKnownServiceType(typeof(ArchiveServer),
                                                                   "ArchiveServer", WellKnownObjectMode.Singleton);

                string configFileName = System.Reflection.Assembly.GetEntryAssembly().Location + ".config";
                if (System.IO.File.Exists(configFileName))
                {
                    RemotingConfiguration.Configure(configFileName, false);
                }

                eventLog.WriteEntry(Strings.ArchiveServiceStarted, EventLogEntryType.Information,
                                    ArchiveServiceEventLog.ID.Information);
            }
            catch
            {
                if (channel != null)
                {
                    channel.StopListening(null);
                    ChannelServices.UnregisterChannel(channel);
                }
            }
        }
Exemplo n.º 3
0
 private void btnStopListeningService_Click(object sender, EventArgs e)
 {
     try
     {
         this.lblListeningStatus.Text = "停止中";
         foreach (IChannel channel in ChannelServices.RegisteredChannels)
         {
             if (channel.ChannelName == "ReportChannel")
             {
                 TcpServerChannel tcpServerChannel = channel as TcpServerChannel;
                 tcpServerChannel.StopListening(null);
                 ChannelServices.UnregisterChannel(tcpServerChannel);
             }
         }
         btnStopListeningService.Enabled  = false;
         btnStartListeningService.Enabled = true;
         this.lblListeningStatus.Text     = "已停止";
     }
     catch (Exception ex)
     {
         btnStopListeningService.Enabled  = true;
         btnStartListeningService.Enabled = false;
         this.lblListeningStatus.Text     = "已启动";
         CommonHelper.ShowErrorBox("停止监听服务失败。");
         CommonHelper.WriteLog("failed to stop service. " + ex.Message);
     }
 }
Exemplo n.º 4
0
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                Application.DoEvents();
                canal.StopListening(4001);
                ChannelServices.UnregisterChannel(canal);

                if (CONNECTION_PARAM.cnx.State == ConnectionState.Open)
                {
                    CONNECTION_PARAM.cnx.Close();
                }
                btn_demarrer.Enabled   = true;
                btn_demarrer.Visible   = true;
                button3.Visible        = false;
                pictureBox1.Visible    = true;
                pictureBox2.Visible    = false;
                label1.Text            = "Déconnecté";
                SERVER_IP_ADDRESS.Text = "";
            }
            catch (Exception er)
            {
                MessageBox.Show(er.Message);
            }

            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
Exemplo n.º 5
0
        public void Stop()
        {
            if (channel != null)
            {
                channel.StopListening(null);
                ChannelServices.UnregisterChannel(channel);
            }

            eventLog.WriteEntry("Archive Service stopped.", EventLogEntryType.Information, ArchiveServiceEventLog.ID.Information);
        }
Exemplo n.º 6
0
        protected override void OnStop()
        {
            refMgr.StopReflector();

            // Close the server channel.
            if (channel != null)
            {
                channel.StopListening(null);
                ChannelServices.UnregisterChannel(channel);
            }
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            //var a = EncryptHelp.Encrypt3Des(DateTime.Now.ToString("2021-09-18 11:15"));
            AppConfig.ServerInit();

            var tcpChannel = new TcpServerChannel(AppConfig.TcpPort);

            ChannelServices.RegisterChannel(tcpChannel, false);
            var httpChannel = new HttpChannel(AppConfig.HttpPort);

            ChannelServices.RegisterChannel(httpChannel, false);
            Assembly assembly = Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory + "\\Mzh.Public.BLL.dll");

            Type[] types = assembly.GetTypes();
            foreach (var type in types)
            {
                RemotingConfiguration.RegisterWellKnownServiceType(type, type.Name, WellKnownObjectMode.SingleCall);
            }

            Hello.InitAll();
            Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    Thread.Sleep(60000);
                    if (DateTime.Now > AppConfig.expiretime)
                    {
                        tcpChannel.StopListening(tcpChannel);
                        break;
                    }
                }
            });


            #region 启动定时任务
            StartJob();
            #endregion

            #region 启动socket服务
            StartWebSocket();
            #endregion

            Console.WriteLine("按任意键退出");
            Console.ReadKey();
        }
Exemplo n.º 8
0
 /// <summary>
 /// Starts the server.
 /// </summary>
 /// <exception cref="T:System.InvalidOperationException">Server is already running.</exception>
 public void Start()
 {
     if (this.smsSender == null)
     {
         IDictionary hashtables = new Hashtable();
         hashtables["port"] = this.networkPort;
         hashtables["name"] = string.Concat("SMSSenderTCPChannel", this.networkPort.ToString());
         if (this.isSecured)
         {
             hashtables["secure"] = "true";
             this.authModule      = new AuthorizationModule(this.allowAnonymous);
         }
         TcpServerChannel tcpServerChannel = new TcpServerChannel(hashtables, null, this.authModule);
         SmsSender        smsSender        = null;
         ObjRef           objRef           = null;
         try
         {
             ChannelServices.RegisterChannel(tcpServerChannel, this.isSecured);
             try
             {
                 smsSender = new SmsSender(this.portName, this.baudRate, this.timeout);
                 objRef    = RemotingServices.Marshal(smsSender, this.uri);
             }
             catch (Exception exception)
             {
                 ChannelServices.UnregisterChannel(tcpServerChannel);
                 throw;
             }
         }
         catch (Exception exception1)
         {
             tcpServerChannel.StopListening(null);
             throw;
         }
         this.channel         = tcpServerChannel;
         this.smsSender       = smsSender;
         this.objRefSmsSender = objRef;
         this.ConnectEvents();
         return;
     }
     else
     {
         throw new InvalidOperationException("Server is already running.");
     }
 }
Exemplo n.º 9
0
        private void button_Stop_Click(object sender, EventArgs e)
        {
            hours   = 0;
            minute  = 0;
            seconds = 0;

            Mem.Abort();
            Mem = null;

            Time.Abort();
            Time = null;

            label_Mem.Text     = "已停止";
            label_RunTime.Text = "已停止";

            button_Stop.Enabled       = false;
            button_Run.Enabled        = true;
            button_ClearCache.Enabled = false;

            listBox_Online.Items.Clear();
            listBox_Status.Items.Clear();

            Remotingserver.StopListening(null);

            if (Remotingserver.ChannelData == null)
            {
                AddListStatus("Remoting->通道已关闭!");
            }
            else
            {
                AddListStatus("Remoting->通道关闭失败!");
            }


            serverSocket.CloseServer();
            serverSocket = null;
            AddListStatus("Socket->通道已关闭!");


            DB_CaChe.Dispose();
        }
Exemplo n.º 10
0
        protected override void OnStart(string[] args)
        {
            try
            {
                AppConfig.ServerInit();

                var tcpChannel = new TcpServerChannel(AppConfig.TcpPort);
                ChannelServices.RegisterChannel(tcpChannel, false);
                var httpChannel = new HttpChannel(AppConfig.HttpPort);
                ChannelServices.RegisterChannel(httpChannel, false);
                Assembly assembly = Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory + "\\Mzh.Public.BLL.dll");
                Type[]   types    = assembly.GetTypes();
                foreach (var type in types)
                {
                    RemotingConfiguration.RegisterWellKnownServiceType(type, type.Name, WellKnownObjectMode.SingleCall);
                }
                Hello.InitAll();
                Task.Factory.StartNew(() =>
                {
                    while (true)
                    {
                        Thread.Sleep(60000);
                        if (DateTime.Now > AppConfig.expiretime)
                        {
                            tcpChannel.StopListening(tcpChannel);
                            this.Stop();
                            break;
                        }
                    }
                });
                #region 启动定时任务
                StartJob();
                #endregion
            }
            catch (Exception ex)
            {
                File.AppendAllText(AppDomain.CurrentDomain.BaseDirectory + "\\log.txt", ex.ToString());
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// 停止此服务。
        /// </summary>
        protected void OnStop()
        {
            // TODO: 在此处添加代码以执行停止服务所需的关闭操作。
            try
            {
                if (ChannelServices.RegisteredChannels.Length > 0)
                {
                    IChannel[] channels = ChannelServices.RegisteredChannels;

                    //					现在改成TCP、HTTP的都能停
                    for (int i = 0; i < channels.Length; i++)
                    {
                        string sChannelName = channels[i].ChannelName;
                        if (sChannelName == "tcp")
                        {
                            TcpServerChannel channel = (TcpServerChannel)channels[i];
                            channel.StopListening(null);
                            ChannelServices.UnregisterChannel(channel);
                        }
                        else
                        {
                            HttpServerChannel channel = (HttpServerChannel)channels[i];
                            channel.StopListening(null);
                            ChannelServices.UnregisterChannel(channel);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                System.Windows.Forms.MessageBox.Show("连接数据库出错" + exception.ToString(), "操作提示");
            }
            finally
            {
            }
        }
 public void Dispose()
 {
     channel.StopListening(null);
     RemotingServices.Disconnect(factory);
     ChannelServices.UnregisterChannel(channel);
 }
Exemplo n.º 13
0
 public void Dispose()
 {
     _tcpChannel.StopListening(null);
 }
Exemplo n.º 14
0
        private void Receiver(object state)
        {
            var pipeline = new Pipeline();

            pipeline.Push(new NboFrameLengthSink(2)
            {
                IncludeHeaderLength = false, MaxFrameLength = 1024
            });
            pipeline.Push(
                new MessageFormatterSink(new Iso8583MessageFormatter((@"..\Formatters\Iso8583Bin1987.xml"))));
            var ts = new TupleSpace <ReceiveDescriptor>();

            var server = new TcpServerChannel(new Pipeline(), new ClonePipelineFactory(pipeline), ts,
                                              new FieldsMessagesIdentifier(new[] { 11, 41 }))
            {
                Port           = 8583,
                LocalInterface = (string)state,
                Name           = "ISO8583Server"
            };

            server.StartListening();

            while (!_stop)
            {
                ReceiveDescriptor rcvDesc = ts.Take(null, 100);
                if (rcvDesc == null)
                {
                    continue;
                }
                _requestsCnt++;
                var message = rcvDesc.ReceivedMessage as Iso8583Message;
                if (message == null)
                {
                    continue;
                }

                Iso8583Message response;
                if (message.IsAuthorization())
                {
                    Console.WriteLine("go to handle sale msg");
                    Sale auth = new Sale(message);
                    response = auth.GetMessage();
                }
                else if (message.IsNetworkManagement())
                {
                    Console.WriteLine("go to handle logon msg");
                    Logon logon = new Logon(message);
                    logon.BuildResponse();
                    response = logon.GetMessage();
                    Console.WriteLine(response.ToString());
                }
                else
                {
                    response = null;
                }

                //message.SetResponseMessageTypeIdentifier();
                //message.Fields.Add(Field39ResponseCode, "00");
                var addr = rcvDesc.ChannelAddress as ReferenceChannelAddress;
                if (addr == null)
                {
                    continue;
                }
                var child = addr.Channel as ISenderChannel;
                if (child != null)
                {
                    child.Send(response);
                }
            }

            // Stop listening and shutdown the connection with the sender.
            server.StopListening();
        }
Exemplo n.º 15
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                Application.DoEvents();
                canal = new TcpServerChannel(4001);

                ChannelServices.RegisterChannel(canal, false);

                RemotingConfiguration.RegisterWellKnownServiceType(typeof(CHM_GESTION_COM), "CHM_GESTION_COM", WellKnownObjectMode.SingleCall);

                CONNECTION_PARAM.charger_param();
                if (CONNECTION_PARAM.cnx.State == ConnectionState.Closed)
                {
                    CONNECTION_PARAM.cnx.Open();
                }
                NOM_MACHINE_SERVER.Text = CONNECTION_PARAM.cnx.WorkstationId.ToString();
                btn_demarrer.Enabled    = false;
                btn_demarrer.Visible    = false;
                button3.Visible         = true;
                pictureBox1.Visible     = false;
                pictureBox2.Visible     = true;
                label1.Text             = "Connecté";
                string[] IpAdress = GetIPaddresses(CONNECTION_PARAM.cnx.WorkstationId.ToString());
                int      i        = 0;
                while (IpAdress[i] != null)
                {
                    SERVER_IP_ADDRESS.Text = IpAdress[i];
                    i++;
                    break;
                }
            }
            catch (Exception er)
            {
                MessageBox.Show(er.Message);
            }

            finally
            {
                this.Cursor = Cursors.Default;
            }
            //gest = (CHM_GESTION_COMERCIALE.CHM_GESTION)Activator.GetObject(typeof(CHM_GESTION_COMERCIALE.CHM_GESTION), "tcp://LOCALHOST:4001/CHM_GESTION_COM");
            timer1.Enabled = false;
            License.License license = new License.License();



            if (license.license_type != "O")
            {
                dt = new CHM_GESTION_COM().P_FACTURE.SELECT_ALL_FACTURES(); //gest.P_FACTURE.SELECT_ALL_FACTURES();
                int n = license.nb - dt.Rows.Count;
                if (n <= 50 && n > 0)
                {
                    timer1.Enabled = false;
                    MessageBox.Show(" áÞÏ ÞÇÑÈÊ ÑÎÕÉ ÇÓÊÚãÇá ÇáãäÙæãÉ Úáì ÇáÅäÊåÇÁ.\n ÊÈÞì áßã ÅãßÇäíÉ ÅÏÎÇá " + n.ToString() + "ÝÇÊæÑÉ", "CHM Commercial Management Program");
                    timer1.Enabled = false;
                }

                if (dt.Rows.Count >= license.nb)
                {
                    this.Cursor = Cursors.WaitCursor;
                    Application.DoEvents();
                    canal.StopListening(4001);
                    ChannelServices.UnregisterChannel(canal);

                    if (CONNECTION_PARAM.cnx.State == ConnectionState.Open)
                    {
                        CONNECTION_PARAM.cnx.Close();
                    }
                    btn_demarrer.Enabled   = true;
                    btn_demarrer.Visible   = true;
                    button3.Visible        = false;
                    pictureBox1.Visible    = true;
                    pictureBox2.Visible    = false;
                    label1.Text            = "Déconnecté";
                    SERVER_IP_ADDRESS.Text = "";
                    MessageBox.Show(" áÞÏ ÇäÊåÊ ÑÎÕÉ ÇÓÊÚãÇá ÇáãäÙæãÉ.", "CHM Commercial Management Program");
                }
            }
        }