Ejemplo n.º 1
0
        public Box.State GetCurrentState(int code)
        {
            #region 调试用
            //return Box.State.Close;
            #endregion

            ELock eLock = ELocksManager.GetInstance().GetLock(code);;
            if (eLock == null || eLock.BoxCode == 0)
            {
                return(Box.State.Close);
            }

            string           loginUrl = string.Format("http://{0}/coils/{1}?ac={2}", eLock.Address, eLock.Value, eLock.Password);
            CookieCollection cookies  = new CookieCollection();//如何从response.Headers["Set-Cookie"];中获取并设置CookieCollection的代码略
            HttpWebResponse  response = HttpWebResponseUtility.CreateGetHttpResponse(loginUrl, null, null, cookies);
            if (response == null)
            {
                return(Box.State.Close);
            }
            string result = "";
            using (StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8))
            {
                result = reader.ReadToEnd();
            }

            if (result.Equals("{\"v\":1}"))
            {
                return(Box.State.Open);
            }
            else if (result.Equals("{\"v\":0}"))
            {
                return(Box.State.Close);
            }
            return(Box.State.Close);
        }
Ejemplo n.º 2
0
        public bool Close(int code)
        {
            #region 调试用
            //return true;
            #endregion

            ELock eLock = ELocksManager.GetInstance().GetLock(code);
            if (eLock == null || eLock.BoxCode == 0)
            {
                return(false);
            }

            string           loginUrl = string.Format("http://{0}/gpio/ts/{1}?ac={2}&delay={3}", eLock.Address, eLock.Value, eLock.Password, delayTime);
            CookieCollection cookies  = new CookieCollection();//如何从response.Headers["Set-Cookie"];中获取并设置CookieCollection的代码略
            HttpWebResponse  response = HttpWebResponseUtility.CreateGetHttpResponse(loginUrl, null, null, cookies);

            if (response == null)
            {
                return(false);
            }
            string result = "";
            using (StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8))
            {
                result = reader.ReadToEnd();
            }

            string targetResult = string.Format("{\"v\":{0}}", delayTime);

            if (result == targetResult)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 3
0
        public bool Open(int code)
        {
            bool  success = false;
            ELock eLock   = ELocksManager.GetInstance().GetLock(code);

            if (eLock == null)
            {
                CLog4net.LogError("根据柜号:" + code + " 寻找锁号失败:eLock==nulll");
                return(false);
            }
            if (eLock.BoxCode == 0)
            {
                CLog4net.LogError("根据柜号:" + code + " 寻找锁号失败:eLock.BoxCode == 0");
                return(false);
            }
            try
            {
                if (isDebug)
                {
                    return(true);
                }

                VCI_CAN_OBJ obj      = PDUProducter.CreateOpenCmd(Convert.ToUInt32(eLock.Address), Convert.ToUInt32(eLock.Password), Convert.ToInt32(eLock.Value), timeout);
                VCI_CAN_OBJ response = CanManager.GetInsatnce().SendPdu(obj);
                if (response.Data != null)
                {
                    bool parameterLegal = response.Data[0] == 1 ? true : false;
                    bool passwordPass   = response.Data[1] == 1 ? true : false;
                    bool isReceivedData = response.Data[2] == 1 ? true : false;


                    success = (isReceivedData & passwordPass & parameterLegal) == true ? true : false;

                    if (!success)
                    {
                        CLog4net.LogError("Can发送开箱 " + "parameterLegal:" + parameterLegal + " passwordPass" + passwordPass + " parameterLegal" + parameterLegal);
                    }
                }
                else
                {
                    CLog4net.LogError("Can发送开箱 " + "response.Data == null");
                }
            }
            catch (Exception e)
            {
                CLog4net.LogError("Can控制器OPEN异常: " + e.ToString());
                return(false);
            }
            return(success);
        }
Ejemplo n.º 4
0
        public int Load(BackgroundWorker bw)
        {
            #region 获取初始化基本信息
            bw.ReportProgress(stepNum += 1, "starting......");

            this.databaseService = ServicesFactory.GetInstance().GetDatabaseService();
            this.aboutConfig     = AboutConfig.GetInstance();
            this.elocksManager   = ELocksManager.GetInstance();
            this.boxManager      = BoxsManager.GetInstance();
            this.packageManager  = PackageManager.GetInstance();
            this.adManager       = ADManager.GetInstance();
            this.remoteOpenLogic = RemoteOpenLogic.GetInstance();

            this.SystemTimer = new Timer(new TimerCallback(this.SystemTimer_Elapsed), null, Timeout.Infinite, Timeout.Infinite);
            #endregion

            System.Threading.Thread.Sleep(delay);
            bw.ReportProgress(stepNum += 1, "aboutConfig loading......");
            this.aboutConfig.Load();
            System.Threading.Thread.Sleep(delay);
            bw.ReportProgress(stepNum += 1, "boxManager loading......");
            this.boxManager.Load();
            System.Threading.Thread.Sleep(delay);
            bw.ReportProgress(stepNum += 1, "elocksManager loading......");
            this.elocksManager.Load();
            System.Threading.Thread.Sleep(delay);
            bw.ReportProgress(stepNum += 1, "packageManager loading......");
            this.packageManager.Load();
            System.Threading.Thread.Sleep(delay);
            bw.ReportProgress(stepNum += 1, "remoteOpenLogic loading......");
            this.remoteOpenLogic.Load();
            System.Threading.Thread.Sleep(delay);
            bw.ReportProgress(stepNum += 1, "adManager loading......");
            this.adManager.Load();
            System.Threading.Thread.Sleep(delay);
            bw.ReportProgress(stepNum += 1, "packageEvent loading......");
            this.packageManager.PackageCreatedEvent += new PackageManager.PackageCreatedDelegate(packageManager_PackageCreatedEvent);
            this.packageManager.PackageTakedEvent   += new PackageManager.PackageTakedDelegate(packageManager_PackageTakedEvent);
            this.SystemTimer.Change(0, 600 * 1000);
            System.Threading.Thread.Sleep(delay);
            bw.ReportProgress(stepNum += 1, "over");

            return(stepNum);
        }