예제 #1
0
        /// <summary>
        /// c触发式上传
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public string ConfigTriggerDefine(Stream stream)
        {
            ConfigTriggerDefineTaskModel param = new ConfigTriggerDefineTaskModel();
            UploadResult result = new UploadResult();

            try
            {
                StreamReader sr = new StreamReader(stream);

                string content = sr.ReadToEnd();
                sr.Dispose();
                NameValueCollection nvc = HttpUtility.ParseQueryString(content);
                param = Json.Parse <ConfigTriggerDefineTaskModel>(nvc["content"]);


                if (iCMS.WG.AgentServer.Common.syncTools == null)
                {
                    Common.Init();
                }
                Common.asyncTools.AddCmd(param);
                result.Result = 0;
            }
            catch
            {
                result.Result = 1;
                result.Reason = "发生错误无法受理请求";
            }

            return(Json.Stringify(result));
        }
        public object doOperator()
        {
            try
            {
                ConfigTriggerDefineTaskModel model = (configModel as ConfigTriggerDefineTaskModel);
                foreach (SendTriggerDefine TriggerDefine in model.triggerDefineList)
                {
                    iMesh.tSetTrigParam setTriggerDefParam = new iMesh.tSetTrigParam();
                    iCMS.WG.Agent.Common.LogHelper.WriteLog(iCMS.WG.Agent.Common.Enum.EnumLogType.Agent2WS.ToString(), "开始下发WS的触发式配置 :" + TriggerDefine.MAC);
                    setTriggerDefParam.mac = new iMesh.tMAC(TriggerDefine.MAC);
                    switch (TriggerDefine.bEnable)
                    {
                    case 0:
                        setTriggerDefParam.Enable = iMesh.enEnableFun.eCloseFun;
                        iCMS.WG.Agent.Common.LogHelper.WriteLog(iCMS.WG.Agent.Common.Enum.EnumLogType.Agent2WS.ToString(), "关闭触发功能 " + TriggerDefine.MAC);
                        break;

                    case 1:
                        setTriggerDefParam.Enable = iMesh.enEnableFun.eOpenFun;
                        iCMS.WG.Agent.Common.LogHelper.WriteLog(iCMS.WG.Agent.Common.Enum.EnumLogType.Agent2WS.ToString(), "开启触发功能 " + TriggerDefine.MAC);
                        break;

                    default:
                        break;
                    }
                    setTriggerDefParam.Enable = (iMesh.enEnableFun)TriggerDefine.bEnable;
                    if (TriggerDefine.ACCEnable == 1)
                    {
                        setTriggerDefParam.AccMdf.MeasDefType    = iMesh.enMeasDefType.eAccWaveform;
                        setTriggerDefParam.AccMdf.bEnable        = true;
                        setTriggerDefParam.AccMdf.u8Flag         = TriggerDefine.ACCValue;
                        setTriggerDefParam.AccMdf.fCharRmsvalue  = TriggerDefine.ACCRmsThreshold;
                        setTriggerDefParam.AccMdf.fCharPKvalue   = TriggerDefine.ACCPKThreshold;
                        setTriggerDefParam.AccMdf.fCharPKPKvalue = TriggerDefine.ACCPKPKThreshold;
                    }
                    if (TriggerDefine.ACCEnvlEnable == 1)
                    {
                        setTriggerDefParam.AccEnvMdf.MeasDefType   = iMesh.enMeasDefType.eAccEnvelope;
                        setTriggerDefParam.AccEnvMdf.bEnable       = true;
                        setTriggerDefParam.AccEnvMdf.u8Flag        = TriggerDefine.ACCEnvlValue;
                        setTriggerDefParam.AccEnvMdf.fCharPKvalue  = TriggerDefine.ACCEnvlPKThreshold;
                        setTriggerDefParam.AccEnvMdf.fCharPKCvalue = TriggerDefine.ACCEnvlPKCThreshold;
                    }
                    if (TriggerDefine.VelEnable == 1)
                    {
                        setTriggerDefParam.VelMdf.MeasDefType    = iMesh.enMeasDefType.eVelWaveform;
                        setTriggerDefParam.VelMdf.bEnable        = true;
                        setTriggerDefParam.VelMdf.u8Flag         = TriggerDefine.VelValue;
                        setTriggerDefParam.VelMdf.fCharRmsvalue  = TriggerDefine.VelRmsThreshold;
                        setTriggerDefParam.VelMdf.fCharPKvalue   = TriggerDefine.VelPKThreshold;
                        setTriggerDefParam.VelMdf.fCharPKPKvalue = TriggerDefine.VelPKPKThreshold;
                    }
                    if (TriggerDefine.DispEnable == 1)
                    {
                        setTriggerDefParam.DspMdf.MeasDefType    = iMesh.enMeasDefType.eDspWaveform;
                        setTriggerDefParam.DspMdf.bEnable        = true;
                        setTriggerDefParam.DspMdf.u8Flag         = TriggerDefine.DispValue;
                        setTriggerDefParam.DspMdf.fCharRmsvalue  = TriggerDefine.DispRmsThreshold;
                        setTriggerDefParam.DspMdf.fCharPKvalue   = TriggerDefine.DispPKThreshold;
                        setTriggerDefParam.DspMdf.fCharPKPKvalue = TriggerDefine.DispPKPKThreshold;
                    }

                    //向底层发送信息
                    if (!iCMS.WG.Agent.ComFunction.Send2WS(setTriggerDefParam, Common.Enum.EnumRequestWSType.SetTrigger))
                    {
                        CommunicationWithServer communication2Server = new CommunicationWithServer();
                        communication2Server.UploadConfigResponse(TriggerDefine.MAC, Enum_ConfigType.ConfigType_MeasDefine, Convert.ToInt32(EnmuReceiveStatus.Unaccept), "网络正忙下发触发式配置失败,退出");
                        iCMS.WG.Agent.Common.LogHelper.WriteLog(iCMS.WG.Agent.Common.Enum.EnumLogType.Agent2WS.ToString(), TriggerDefine.MAC + ":网络正忙下发触发式配置失败,退出");
                    }
                    else
                    {
                        lock (iCMS.WG.Agent.ComFunction.sendTriggerDefineList)
                        {
                            System.Threading.Timer timer = new System.Threading.Timer(new System.Threading.TimerCallback(CheckSetTriggerDefTimeOut), TriggerDefine.MAC, 40000, -1);
                            TriggerDefine.time = timer;
                            iCMS.WG.Agent.ComFunction.sendTriggerDefineList.Add(TriggerDefine);
                        }
                    }

                    System.Threading.Thread.Sleep(100);
                }
            }
            catch (Exception ex)
            {
                iCMS.WG.Agent.Common.LogHelper.WriteLog(ex);
            }
            return("ConfigTriggerDefineOper");
        }