Пример #1
0
        private void BgwOnlineWatcher_DoWork(object sender, DoWorkEventArgs e)
        {
            bool result = false;

            while (true)
            {
                try
                {
                    if (curChannelState == CHANNELSTATE.UNINITIALISED)
                    {
                        RegisterClient();
                    }
                    else
                    {
                        result = channel.CheckAvaliable();
                    }
                }
                catch (Exception exc)
                {
                    ;
                }

                if (!result)
                {
                    curChannelState = CHANNELSTATE.DISCONNECTED;
                }
                else
                {
                    curChannelState = CHANNELSTATE.CONNECTED;
                }
                (sender as BackgroundWorker).ReportProgress(0);
                Thread.Sleep(5000);
            }
        }
Пример #2
0
        public MSG RegisterClient()
        {
            MSG result = new MSG()
            {
                Code = CODES.SUCCESS, Text = string.Empty, Obj = null
            };

            try
            {
                Msg msg = channel.RegisterClient(new Msg()
                {
                    ClientName = "Client_1", GUID = new Guid()
                });

                curChannelState = CHANNELSTATE.CONNECTED;
            }
            catch (Exception exc)
            {
                curChannelState = CHANNELSTATE.UNINITIALISED;

                result.Code = CODES.ERROR;
                result.Text = "Неудалось зарегистрироваться на сервере.";
                result.Obj  = exc;
            }

            bgwOnlineWatcher.RunWorkerAsync();

            return(result);
        }
Пример #3
0
        public ServiceChannel()
        {
            if (dualFactory == null)
            {
                curChannelState = CHANNELSTATE.UNINITIALISED;

                subscribers = new Dictionary <MSGTYPE, EventHandler>();

                endpoint = new EndpointAddress("http://192.168.1.222:584/BroadcastorService");
                bc       = new BroadcastorCallback();
                bc.SetHandler(this.HandleBroadcast);
                dualFactory = new DuplexChannelFactory <IBroadcastorService>(bc, new WSDualHttpBinding()
                {
                    CloseTimeout = new TimeSpan(0, 0, 10)
                }, endpoint);
                channel = dualFactory.CreateChannel();

                bgwOnlineWatcher = new BackgroundWorker();
                bgwOnlineWatcher.WorkerReportsProgress = true;
                bgwOnlineWatcher.DoWork          += BgwOnlineWatcher_DoWork;
                bgwOnlineWatcher.ProgressChanged += BgwOnlineWatcher_ProgressChanged;
            }
        }