Example #1
0
        static void Main(string[] args)
        {
            IProcessorController proccontroller = ChannelFactory <IProcessorController> .CreateChannel(new WSDualHttpBinding(), new EndpointAddress(new Uri(string.Format("http://{0}:8001/ProcessorControllerWCF", "10.3.2.35"))));

            List <ProcessorData> ProcessorList = proccontroller.ListProcessors();

            ProcessorList.ForEach(x => Console.WriteLine(x.ToString()));
            Console.CancelKeyPress += delegate
            {
                Environment.Exit(0);
            };
            ProcessorList.ForEach(x => proccontroller.StopProcessor(x.Pid));
            System.Threading.Thread.CurrentThread.Join();
        }
        protected override void OnStart(string[] args)
        {
            this.ConfigurationServerHost    = ConfigurationManager.AppSettings["ConfigurationServerHost"] != null ? ConfigurationManager.AppSettings["ConfigurationServerHost"] : ProcessorManager.ConfigurationServerHostDefault;
            this.ConfigurationServerWCFPort = ConfigurationManager.AppSettings["ConfigurationServerWCFPort"] != null ? ConfigurationManager.AppSettings["ConfigurationServerWCFPort"] : ProcessorManager.ConfigurationServerWCFPortDefault;
            this.ProcessorControllerWCFPort = ConfigurationManager.AppSettings["ProcessorControllerWCFPort"] != null ? ConfigurationManager.AppSettings["ProcessorControllerWCFPort"] : ProcessorManager.ProcessorControllerWCFPortDefault;

            ThreadPool.QueueUserWorkItem(x =>
            {
                LocationDataDictionary prevlocations = new LocationDataDictionary();
                while (true)
                {
                    try
                    {
                        IConfigurationServer configserver    = ChannelFactory <IConfigurationServer> .CreateChannel(new NetTcpBinding(), new EndpointAddress(new Uri(string.Format("net.tcp://{0}:{1}/ConfigurationServerWCF", this.ConfigurationServerHost, this.ConfigurationServerWCFPort))));
                        LocationDataDictionary currlocations = configserver.GetLocations();
                        Console.WriteLine(currlocations.ToString());
                        foreach (string location in currlocations.Keys)
                        {
                            try
                            {
                                IProcessorController proccontroller            = ChannelFactory <IProcessorController> .CreateChannel(new NetTcpBinding(), new EndpointAddress(new Uri(string.Format("net.tcp://{0}:{1}/ProcessorControllerWCF", location, this.ProcessorControllerWCFPort))));
                                ProcessorManagement.Data.ProcessorDataList pdl = proccontroller.ListProcessors();

                                Console.WriteLine(pdl.ToString());
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }

                    Thread.Sleep(60000);
                }
            });
        }