Beispiel #1
0
        public void UpdateOutput(Setting setting)
        {
            SetSetting(setting);
            CloseOutput();
            StartOutput();
            ChannelFactory <Service.IContractOut> myChannelFactory = new ChannelFactory <Service.IContractOut>(new BasicHttpBinding(), new EndpointAddress("http://localhost:8000/sparkOutput"));

            Service.IContractOut wcfInput = myChannelFactory.CreateChannel();
            ((IClientChannel)wcfInput).OperationTimeout = new TimeSpan(0, 1, 10);

            string[] data = new string[setting.Outputs.Count];
            for (int i = 0; i < setting.Outputs.Count; i++)
            {
                data[i] = JsonConvert.SerializeObject(setting.Outputs[i]);
            }
            int countConnect = 0;

            while (true)
            {
                try {
                    countConnect++;
                    wcfInput.UpdateOutputs(data);
                    break;
                } catch (Exception ex) {
                    System.Threading.Thread.Sleep(500);
                    if (countConnect > 5)
                    {
                        Service.Log.LogShow(EnvPath, "Не удается подключиться к модулю выходов", ex.ToString(), "Ошибка", Service.MessageViewMode.Error);
                        break;
                    }
                }
            }
        }
Beispiel #2
0
        private void TimerUpdateData_Elapsed(object sender, ElapsedEventArgs e)
        {
            ChannelFactory <Service.IContractOut> myChannelFactory = new ChannelFactory <Service.IContractOut>(new BasicHttpBinding(), new EndpointAddress("http://localhost:8000/sparkOutput"));

            Service.IContractOut wcfOutput = myChannelFactory.CreateChannel();
            ((IClientChannel)wcfOutput).OperationTimeout = new TimeSpan(0, 0, 3);
            foreach (Service.InputCommon output in setting.Outputs)
            {
                Service.PairDataParam[] pairs = new Service.PairDataParam[output.ListDataParamsOut.Count];
                for (int i = 0; i < output.ListDataParamsOut.Count; i++)
                {
                    pairs[i] = new Service.PairDataParam {
                        ID    = output.ListDataParamsOut[i].ID,
                        Value = setting.GetParamByID(output.ListDataParamsOut[i].ID).Value
                    };
                }
                try {
                    wcfOutput.UpdateDate(output.Title, pairs);
                } catch { }
            }
        }