Пример #1
0
        public void ProcessRequest(HttpContext context)
        {
            //设备ID和下载指令,tag格式,其中多个设备和指令需以"|"分割
            StreamReader reader = new StreamReader(context.Request.InputStream);
            string tag = reader.ReadToEnd();
            if (string.IsNullOrEmpty(tag))
                return;
            string cmd = basefun.valtag(tag, "指令");
            if ("设备同步黑白名单" == cmd)
            {
                SynDeviceParam syn = new SynDeviceParam();
                string msg = syn.downCardALL();
                bool success = true;
                if (!string.IsNullOrEmpty(msg))
                {
                    success = false;
                    msg = basefun.setvaltag("", "提示", msg);
                }
                msg = basefun.setvaltag(msg, "成功", success ? "true" : "false");
                context.Response.Write(msg);
            }
            Debug.WriteLine(DateTime.Now.ToString("HH:mm.ss.fff") + " 发出请求");
            string reqid = basefun.valtag(tag, "reqID");
            //已经在处理请求的返回结果信息
            if (reqlist.ContainsKey(reqid))
            {
                reqParam reqparam = reqlist[reqid];
                reqparam.dtreq = DateTime.Now;
                string[] devs = new string[0];
                if (!string.IsNullOrEmpty(reqparam.reqdev))
                    devs = reqparam.reqdev.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                if (reqparam.taglist.Count >= devs.Length)
                    reqlist.Remove(reqid);
                string msg = "";
                foreach (string t in reqparam.taglist)
                    msg += t + ";";
                Debug.WriteLine(DateTime.Now.ToString("HH:mm.ss.fff") + " 结果:" + msg);
                context.Response.Write(msg);
                return;
            }
            List<string> keys = new List<string>();
            foreach (string k in reqlist.Keys)
                keys.Add(k);
            DateTime dt = DateTime.Now.AddMinutes(-1);
            foreach (string k in keys)
            {
                if (reqlist[k].dtreq < dt)
                    reqlist.Remove(k);
            }
            string devid = basefun.valtag(tag, "设备ID");
            if (string.IsNullOrEmpty(reqid) || string.IsNullOrEmpty(devid) || string.IsNullOrEmpty(cmd))
                return;
            reqParam param = new reqParam();
            param.reqid = reqid;
            param.reqdev = devid;
            reqlist.Add(reqid, param);
            //对设备启动或停止监控, patrol持续巡检
            CommiManager mgr = CommiManager.GlobalManager;
            CommiTarget target = getService();
            NameValueCollection info = new NameValueCollection();

            string tagdev = basefun.setvaltag("", "reqID", reqid);
            tagdev = basefun.setvaltag(tagdev, "指令", cmd);
            string[] devids = devid.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < devids.Length; i++)
            {
                tagdev = basefun.setvaltag(tagdev, "设备ID", devids[i]);
                //暂停巡检
                info["device"] = devids[i];
                if (null != target)
                {
                    CmdFileTrans cmdtrans = new CmdFileTrans(false);
                    cmdtrans.ExtService(CmdSrvType.HaltDevice, info);
                    mgr.SendCommand(target, cmdtrans, true);
                }
                ThreadManager.QueueUserWorkItem(delegate(object obj) { syncommi(obj); }, tagdev);
            }
        }
Пример #2
0
 /// <summary>
 /// 保存
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnSave_Click(object sender, EventArgs e)
 {
     this.validateFeeTab();
     DataTable tabpark = this.ds.Tables["停车场管理"];
     DataTable tabfee = this.ds.Tables["收费标准"];
     DataTable tabdspan = this.ds.Tables["收费标准时段"];
     DataTable tabdtime = this.ds.Tables["收费标准时刻"];
     DataTable[] tablist ={ tabpark, tabfee, tabdspan, tabdtime };
     bool isSuccess = this.Query.BeginTransaction();
     string msg = "";
     if (!isSuccess)
         msg = "保存失败,无法打开事务!";
     else
     {
         foreach (DataTable tab in tablist)
         {
             NameObjectList[] psins = ParamManager.createParam(tab, DataRowState.Added);
             NameObjectList[] psupt = ParamManager.createParam(tab, DataRowState.Modified);
             NameObjectList[] psdel = ParamManager.createParam(tab, DataRowState.Deleted);
             isSuccess = this.Query.ExecuteNonQuery(tab.TableName, psins, psupt, psdel);
             if (!isSuccess)
             {
                 msg = "保存失败,请检查数据是否合法!";
                 break;
             }
         }
     }
     if (!isSuccess)
         this.Query.RollbackAndClose();
     else
     {
         this.Query.Commit();
         this.Query.Close();
         foreach (DataTable tab in tablist)
             tab.AcceptChanges();
         //发出通讯更新设备
         int port = 2010;
         string sport = DataAccRes.AppSettings("Granity文件服务");
         if (!string.IsNullOrEmpty(sport))
             try { port = Convert.ToInt32(sport); }
             catch { return; }
         string conn = DataAccRes.DefaultDataConnInfo.Value;
         Regex regIP = new Regex(@"server=([\w.\(\)]*)(;|\\)");
         string ipsrv = "127.0.0.1";
         if (regIP.IsMatch(conn))
         {
             Match mt = regIP.Match(conn);
             if (mt.Groups.Count > 1)
                 ipsrv = mt.Groups[1].Value.ToLower();
             if ("(local)" == ipsrv || "127.0.0.1" == ipsrv)
                 ipsrv = Dns.GetHostName();
             ipsrv = Dns.GetHostAddresses(ipsrv)[0].ToString();
         }
         CmdFileTrans cmd = new CmdFileTrans(false);
         cmd.ExtService(ServiceType.UpdatePmDevice, null);
         CommiTarget target = new CommiTarget(ipsrv, port, CommiType.TCP);
         CommiManager.GlobalManager.SendCommand(target, cmd);
     }
     if (!isSuccess)
         MessageBox.Show(msg, "保存提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     else
         MessageBox.Show("保存成功!", "保存提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
 }