public GlobalValues.GATE_ENTRY_STATUS GetGateEntryStatus(EESData objEESData)
        {
            GlobalValues.GATE_ENTRY_STATUS gateStatus = GlobalValues.GATE_ENTRY_STATUS.NOT_READY;
            if (objEESDaoService == null)
            {
                objEESDaoService = new EESDaoImp();
            }
            if (!GetVehicleDetectorStatus(objEESData))
            {
                if (objEESDaoService.IsPSPuttingEES(objEESData.machineCode))
                {
                    gateStatus = GlobalValues.GATE_ENTRY_STATUS.FEEDING;
                }
                else if (objEESDaoService.IsLCMGettingEES(objEESData.machineCode))
                {
                    gateStatus = GlobalValues.GATE_ENTRY_STATUS.CLEARING;
                }
                else
                {
                    int state = GetEESState(objEESData);
                    if (state == (int)EES_STATUS.EES_READY_FOR_PALLET)
                    {
                        gateStatus = GlobalValues.GATE_ENTRY_STATUS.CLEARING;
                    }
                    else if (state == (int)EES_STATUS.EES_READY_FOR_ENTRY)
                    {
                        gateStatus = GlobalValues.GATE_ENTRY_STATUS.READY;
                    }
                }
            }

            return(gateStatus);
        }
        public void CheckGateEntryStatus(EESData objEESData)
        {
            if (objEESDaoService == null)
            {
                objEESDaoService = new EESDaoImp();
            }

            try
            {
                if (objEESDaoService.IsEESDisabled(objEESData.machineCode))
                {
                    return;
                }

                GlobalValues.GATE_ENTRY_STATUS status = GetGateEntryStatus(objEESData);
                objEESDaoService.UpdateGateEntryStatus(objEESData.machineCode, (short)status);
            }
            catch (Exception errMsg)
            {
                Console.WriteLine(errMsg.Message);
            }
            finally
            {
            }
        }
        public bool IsEESReadyForChangeMode(EESData objEESData)
        {
            bool isEESReady = false;

            objEESDaoService = new EESDaoImp();

            isEESReady = CheckEESHealthy(objEESData);

            isEESReady = isEESReady && !objEESDaoService.IsEESBlockedInDBForParking(objEESData.machineCode);
            isEESReady = isEESReady && !objEESDaoService.IsEESBlockedInDBForPMS(objEESData.machineCode);
            using (OpcOperationsService opcd = new OpcOperationsImp(OpcConnection.GetOPCServerConnection()))
            {
                isEESReady = isEESReady && opcd.ReadTag <bool>(objEESData.machineChannel, objEESData.machineCode, OpcTags.EES_L2_Change_Mode_OK);


                //    isEESReady = isEESReady && opcd.ReadTag<bool>(objEESData.machineChannel, objEESData.machineCode, OpcTags.EES_L2_Change_Mode_OK);
                //    //isEESReady = isEESReady && !opcd.ReadTag<bool>(objEESData.machineChannel, objEESData.machineCode, OpcTags.EES_Inner_Door_Close_Con);
                //    //isEESReady = isEESReady && !opcd.ReadTag<bool>(objEESData.machineChannel, objEESData.machineCode, OpcTags.EES_Inner_Door_Open_Con);
                //    //isEESReady = isEESReady && !opcd.ReadTag<bool>(objEESData.machineChannel, objEESData.machineCode, OpcTags.EES_Outer_Door_Close_Con);
                //    //isEESReady = isEESReady && !opcd.ReadTag<bool>(objEESData.machineChannel, objEESData.machineCode, OpcTags.EES_Outer_Door_Open_Con);
                //    //isEESReady = isEESReady && !opcd.ReadTag<bool>(objEESData.machineChannel, objEESData.machineCode, OpcTags.EES_LOCKED_BY_PS);
                //    //isEESReady = isEESReady && !opcd.ReadTag<bool>(objEESData.machineChannel, objEESData.machineCode, OpcTags.EES_LOCKED_BY_REM);
            }

            return(isEESReady);
        }
 public bool IsEESDisabled(string machineName)
 {
     if (objEESDaoService == null)
     {
         objEESDaoService = new EESDaoImp();
     }
     return(objEESDaoService.IsEESDisabled(machineName));
 }
 public bool IsEESBlockedInDBForPMS(string machineName)
 {
     if (objEESDaoService == null)
     {
         objEESDaoService = new EESDaoImp();
     }
     return(objEESDaoService.IsEESBlockedInDBForPMS(machineName));
 }
 public EESData GetEESDetails(EESData objEESData)
 {
     if (objEESDaoService == null)
     {
         objEESDaoService = new EESDaoImp();
     }
     return(objEESDaoService.GetEESDetails(objEESData));
 }
 public List <EESData> GetEESList()
 {
     if (objEESDaoService == null)
     {
         objEESDaoService = new EESDaoImp();
     }
     return(objEESDaoService.GetEESList());
 }
 public List <Model.EESData> GetEESListInRange(int minRange, int maxRange)
 {
     if (objEESDaoService == null)
     {
         objEESDaoService = new EESDaoImp();
     }
     return(objEESDaoService.GetEESListInRange(minRange, maxRange));
 }
        public bool ConfirmEESReadyForREMLock(string machineCode)
        {
            bool    isReady    = false;
            EESData objEESData = new EESData();

            objEESData.machineCode = machineCode;
            if (objEESDaoService == null)
            {
                objEESDaoService = new EESDaoImp();
            }
            objEESData = objEESDaoService.GetEESDetails(objEESData);
            isReady    = IsEESReadyForRem(objEESData);
            return(isReady);
        }
        public bool UpdateMachineValues()
        {
            objEESDaoService = new EESDaoImp();
            List <EESData> eesList;
            bool           result;
            int            dataValue;
            bool           dataValueInBool;



            try
            {
                eesList = objEESDaoService.GetEESList();
                using (OpcOperationsService opcd = new OpcOperationsImp(OpcConnection.GetOPCServerConnection()))
                {
                    foreach (EESData objEESData in eesList)
                    {
                        if (opcd.IsMachineHealthy(objEESData.machineChannel + "." + objEESData.machineCode + "." + OpcTags.EES_Auto_Mode) == true)
                        {
                            //dataValueInBool = false;
                            //dataValueInBool = opcd.ReadTag<bool>(objEESData.machineChannel, objEESData.machineCode, OpcTags.EES_Auto_Mode);
                            // UpdateEESBoolData(objEESData.machineCode, OpcTags.EES_Auto_Mode, dataValueInBool);

                            dataValueInBool = false;
                            dataValueInBool = opcd.ReadTag <bool>(objEESData.machineChannel, objEESData.machineCode, OpcTags.EES_Auto_Ready);
                            UpdateEESBoolData(objEESData.machineCode, OpcTags.EES_Auto_Ready, dataValueInBool);

                            dataValueInBool = false;
                            dataValueInBool = opcd.ReadTag <bool>(objEESData.machineChannel, objEESData.machineCode, OpcTags.EES_Car_Ready_At_Entry);
                            UpdateEESBoolData(objEESData.machineCode, OpcTags.EES_Car_Ready_At_Entry, dataValueInBool);

                            dataValueInBool = false;
                            dataValueInBool = opcd.ReadTag <bool>(objEESData.machineChannel, objEESData.machineCode, OpcTags.EES_Car_Ready_At_Exit);
                            UpdateEESBoolData(objEESData.machineCode, OpcTags.EES_Car_Ready_At_Exit, dataValueInBool);

                            dataValueInBool = false;
                            dataValueInBool = GetCarAtEESStatus(objEESData.machineChannel, objEESData.machineCode);
                            UpdateEESBoolData(objEESData.machineCode, OpcTags.EES_Car_At_EES, dataValueInBool);
                        }
                    }
                }
                result = true;
            }
            catch (Exception errMsg)
            {
                result = false;
                Console.WriteLine(errMsg.Message);
            }
            return(result);
        }
        public bool CheckEESHealthy(EESData objEESData)
        {
            bool isHealthy = false;

            objEESDaoService = new EESDaoImp();

            using (OpcOperationsService opcd = new OpcOperationsImp(OpcConnection.GetOPCServerConnection()))
            {
                if (opcd.IsMachineHealthy(objEESData.machineChannel + "." + objEESData.machineCode + "." + OpcTags.EES_Auto_Ready))
                {
                    isHealthy = opcd.ReadTag <bool>(objEESData.machineChannel, objEESData.machineCode, OpcTags.EES_Auto_Ready);

                    isHealthy = isHealthy && !objEESDaoService.IsEESDisabled(objEESData.machineCode);
                    // isHealthy = isHealthy && !objEESDaoService.IsEESSwitchOff(objEESData.machineCode);
                }
            }
            return(isHealthy);
        }
        public bool IsEESReadyForRem(EESData objEESData)
        {
            bool isReady = false;

            if (objEESDaoService == null)
            {
                objEESDaoService = new EESDaoImp();
            }

            using (OpcOperationsService opcd = new OpcOperationsImp(OpcConnection.GetOPCServerConnection()))
            {
                if (opcd.IsMachineHealthy(objEESData.machineChannel + "." + objEESData.machineCode + "." + OpcTags.EES_Auto_Ready))
                {
                    isReady = opcd.ReadTag <bool>(objEESData.machineChannel, objEESData.machineCode, OpcTags.EES_Ready_for_REM_Lock);
                    isReady = isReady && !opcd.ReadTag <bool>(objEESData.machineChannel, objEESData.machineCode, OpcTags.EES_Car_At_EES);
                    isReady = isReady && objEESDaoService.IsPSNotGettingFromEES(objEESData.machineCode);
                    isReady = isReady && !objEESDaoService.IsEESDisabled(objEESData.machineCode);
                }
            }
            return(isReady);
        }
 public bool UpdateMachineBlockStatusForPMS(string machine_code, bool blockStatus)
 {
     objEESDaoService = new EESDaoImp();
     return(objEESDaoService.UpdateMachineBlockStatusForPMS(machine_code, blockStatus));
 }
        public bool UpdateMachineTagValueToDBFromListener(string machineCode, string machineTag, object dataValue)
        {
            string field = "";
            bool   boolDataValue;
            Int16  intDataValue;
            string stringDataValue;

            if (objEESDaoService == null)
            {
                objEESDaoService = new EESDaoImp();
            }
            int  dataType = 0; //1:bool;2:number;3:string
            bool isRem    = false;


            switch (machineTag)
            {
            case OpcTags.EES_State_EES_HMI:

                int dataValueInt = int.Parse(dataValue.ToString());
                if (dataValueInt == (int)EES_STATUS.EES_READY_STATUS)
                {
                    objEESDaoService.SetEESReadyTime(machineCode, System.DateTime.Now);
                }
                else if (dataValueInt == (int)EES_STATUS.EES_CAR_ALIGNED_STATUS)
                {
                    objEESDaoService.SetCarAlignedTime(machineCode, System.DateTime.Now);
                }
                else if (dataValueInt == (int)EES_STATUS.EES_READY_TO_GET_STATUS)
                {
                    objEESDaoService.SetReadyToGetTime(machineCode, System.DateTime.Now);
                }
                break;

            case OpcTags.EES_Vehicle_Detector:
                if ((bool)dataValue)
                {
                    objEESDaoService.SetCarOutsideTime(machineCode, System.DateTime.Now);
                }
                break;

            default:
                GetDataTypeAndFieldOfTag(machineTag, out dataType, out field, out isRem);
                if (dataType == 1)
                {
                    boolDataValue = Convert.ToBoolean(dataValue);
                    objEESDaoService.UpdateBoolValueUsingMachineCode(machineCode, field, boolDataValue);
                }
                else if (dataType == 2)
                {
                    intDataValue = Convert.ToInt16(dataValue);

                    objEESDaoService.UpdateIntValueUsingMachineCode(machineCode, field, intDataValue);
                }
                else if (dataType == 3)
                {
                    stringDataValue = Convert.ToString(dataValue);
                    objEESDaoService.UpdateStringValueUsingMachineCode(machineCode, field, stringDataValue);
                }
                break;
            }


            return(true);
        }
 public bool IsEESEntryInCurrentModeInDB(string machineCode)
 {
     objEESDaoService = new EESDaoImp();
     return(objEESDaoService.IsEESEntryInCurrentModeInDB(machineCode));
 }
        public void DoResumeEngine()
        {
            List <QueueData> processingQList = null;

            if (objQueueDaoService == null)
            {
                objQueueDaoService = new QueueDaoImp();
            }
            if (objCMControllerService == null)
            {
                objCMControllerService = new CMControllerImp();
            }
            if (objVLCControllerService == null)
            {
                objVLCControllerService = new VLCControllerImp();
            }
            if (objEESDaoService == null)
            {
                objEESDaoService = new EESDaoImp();
            }
            //get all request in status 0 or 2
            processingQList = objQueueDaoService.GetAllProcessingQId();

            //take one request
            foreach (QueueData objQueueData in processingQList)
            {
                string carMachine = null;

                //get queue id
                //get all cms blocked by this queue id
                CMData objCMData = objCMControllerService.GetBlockedCMDetails(objQueueData.queuePkId);

                //get all vlcs blocked by this queue id
                VLCData objVLCData = objVLCControllerService.GetVLCDetails(objQueueData.queuePkId);

                EESData objEESData = objEESDaoService.GetBlockedEESDetails(objQueueData.queuePkId);

                if (objCMData != null && objVLCData != null)
                {
                    //check pallet present of blocked machine
                    GlobalValues.palletStatus palletStatus = objCMControllerService.GetPalletOnCMStatus(objCMData);
                    if (palletStatus == GlobalValues.palletStatus.present)
                    {
                        carMachine = objCMData.machineCode;
                    }
                    else
                    {
                        carMachine = objVLCData.machineCode;
                    }
                }
                else if (objCMData != null)
                {
                    carMachine = objCMData.machineCode;
                }
                else if (objCMData != null)
                {
                    carMachine = objVLCData.machineCode;
                }
                else if (objEESData != null)
                {
                    carMachine = objEESData.machineCode;
                }

                //call SetReallocateData with pallet present machine
                if (!string.IsNullOrEmpty(carMachine))
                {
                    SetReallocateData(objQueueData.queuePkId, carMachine, 3);
                }
                else
                {
                    SetReallocateData(objQueueData.queuePkId, "SLOT", 3);// entry or exit which had no initial path
                }
                UpdateAbortedStatus(objQueueData.queuePkId);
            }
        }
        public bool TakePhoto(Model.EESData objEESData)
        {
            Logger.WriteLogger(GlobalValues.PARKING_LOG, "Queue Id:" + objEESData.queueId + ":Entered TakePhoto");
            if (objEESDaoService == null)
            {
                objEESDaoService = new EESDaoImp();
            }
            if (objUtilityClass == null)
            {
                objUtilityClass = new UtilityClass();
            }

            try
            {
                //string northimg =null;
                //string southimg = null;
                string imagePath           = GlobalValues.IMG_DIR;
                string cameraConfigXmlName = "eft_config\\CameraNodes.xml";
                string cuurDate            = System.DateTime.Now.Date.Date.Day + "_" + System.DateTime.Now.Date.Date.Month + "_" + System.DateTime.Now.Date.Date.Year;
                string northimg            = objEESData.queueId + "_" + objEESData.customerPkId + "_" + cuurDate + "_" + "north.jpg";
                string southimg            = objEESData.queueId + "_" + objEESData.customerPkId + "_" + cuurDate + "_" + "south.jpg";
                string northFullPath       = null;
                string southFullPath       = null;
                if (objEESData.isEntry)
                {
                    northFullPath = imagePath + "\\" + northimg;
                    southFullPath = imagePath + "\\" + southimg;
                }
                else
                {
                    northFullPath = imagePath + "\\" + northimg;
                    southFullPath = imagePath + "\\" + southimg;
                }

                string northImgOPCMachine = objEESData.eesName + "_North";
                string southImgOPCMachine = objEESData.eesName + "_South";

                // Define a delegate that prints and returns the system tick count
                Func <object, bool> north = (object obj) =>
                {
                    //  using (OpcOperationsService opcd = new OpcOperationsImp(OpcConnection.GetCamOPCServerConnection()))
                    //   {

                    try
                    {
                        //  opcd.WriteTagToCamOpc<bool>(northImgOPCMachine + "." + OpcTags.EES_Cam_GetCmd, true);
                        //  northimg = opcd.ReadTagFromCamOpc<string>(northImgOPCMachine + "." + OpcTags.EES_Cam_ImgPath);

                        if (BasicConfig.GetXmlAttributeValueOfTag(cameraConfigXmlName, "Node", "Name", northImgOPCMachine, "Active").Equals("true"))
                        {
                            objUtilityClass.CaptureImage(BasicConfig.GetXmlAttributeValueOfTag(cameraConfigXmlName, "Node", "Name", northImgOPCMachine, "IP"), northFullPath);
                        }
                        //if (!string.IsNullOrEmpty(opcd.GetCamOpcError("EES" + eesNumber + "_North.Error")))
                        //break;
                    }
                    finally
                    {
                        //opcd.WriteTagToCamOpc<bool>(northImgOPCMachine + "." + OpcTags.EES_Cam_GetCmd, true);
                    }

                    // }
                    return(true);
                };

                // Define a delegate that prints and returns the system tick count
                Func <object, bool> south = (object obj) =>
                {
                    //using (OpcOperationsService opcd = new OpcOperationsImp(OpcConnection.GetCamOPCServerConnection()))
                    //{

                    try
                    {
                        //opcd.WriteTagToCamOpc<bool>(southImgOPCMachine + "." + OpcTags.EES_Cam_GetCmd, true);
                        //southimg = opcd.ReadTagFromCamOpc<string>(southImgOPCMachine + "." + OpcTags.EES_Cam_ImgPath);
                        if (BasicConfig.GetXmlAttributeValueOfTag(cameraConfigXmlName, "Node", "Name", southImgOPCMachine, "Active").Equals("true"))
                        {
                            objUtilityClass.CaptureImage(BasicConfig.GetXmlAttributeValueOfTag(cameraConfigXmlName, "Node", "Name", southImgOPCMachine, "IP"), southFullPath);
                        }
                        //if (!string.IsNullOrEmpty(opcd.GetCamOpcError("EES" + eesNumber + "_North.Error")))
                        //break;
                    }
                    finally
                    {
                        //opcd.WriteTagToCamOpc<bool>(southImgOPCMachine + "." + OpcTags.EES_Cam_GetCmd, false);
                    }

                    // }
                    return(true);
                };

                Task <bool>[] tasks = new Task <bool> [2];
                tasks[0] = Task <bool> .Factory.StartNew(north, 1);

                tasks[1] = Task <bool> .Factory.StartNew(south, 1);


                // Wait for all the tasks to finish.
                // Task.WaitAll(tasks);

                if (!string.IsNullOrEmpty(northimg))
                {
                    northimg = new FileInfo(northimg).Name;
                }

                if (!string.IsNullOrEmpty(southimg))
                {
                    southimg = new FileInfo(southimg).Name;
                }


                objEESDaoService.UpdatePhotoPathToCustomerTable(objEESData, southimg, northimg);
            }
            catch (Exception errMsg)
            {
                Logger.WriteLogger(GlobalValues.PARKING_LOG, "Queue Id:" + objEESData.queueId + ":Error in TakePhoto: " + errMsg.Message);
            }
            finally
            {
            }
            Logger.WriteLogger(GlobalValues.PARKING_LOG, "Queue Id:" + objEESData.queueId + ":Exitting  TakePhoto");
            return(true);
        }