Beispiel #1
0
        private void OnMenuFitSymbolsToDefaultContextMenuCommand(object sender, EventArgs e)
        {
            var command  = sender as MenuCommand;
            var store    = this.CurrentDocData.Store;
            var simbolos = store.ElementDirectory.FindElements <Simbolo>();

            if (simbolos.Count == 0)
            {
                return;
            }

            using (var transaction = store.TransactionManager.BeginTransaction("AjustarAoPadrao"))
            {
                try
                {
                    foreach (var simbolo in simbolos)
                    {
                        CompartmentHelper.AjustarAoPadrao(simbolo);
                    }

                    transaction.Commit(); // Don't forget this!
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    System.Windows.Forms
                    .MessageBox.Show("Não foi possível ajustar o tamanho dos Símbolos. Desculpe por isso :("
                                     , "FALHA AO AJUSTAR TAMANHO"
                                     , System.Windows.Forms.MessageBoxButtons.OK
                                     , System.Windows.Forms.MessageBoxIcon.Error);
                }
            }
        }
        /// <summary>
        /// Manage open compartment by requested object and based on locker configuration.
        /// </summary>
        /// <returns>
        ///  The compartment object mapped from locker configuration.
        /// </returns>
        public static Locker CompartmentOpen(DataObjects.Models.Compartment model, AppSettings lockerConfiguration)
        {
            var odbModuleList = new List <string> {
            };                                        // Find  object detection module id list by input list of compartment
            List <CompartmentConfiguration> compartments = lockerConfiguration.Locker.Compartments;

            if (model.CompartmentIds.Any(CompartmentId => CompartmentId == "All"))
            {
                model.CompartmentIds = lockerConfiguration.Locker.Compartments.Select(compartment => compartment.CompartmentId).ToArray();
            }
            foreach (var compartmentId in model.CompartmentIds)
            {
                var compartment = compartments.Find(c => c.CompartmentId == compartmentId);
                if (!odbModuleList.Contains(compartment.CompartmentCode.Odbmod)) // Get object detection module id
                {
                    odbModuleList.Add(compartment.CompartmentCode.Odbmod);
                }
            }

            // Update object detection status of selected modules
            var objectdetectStatusAry = new Dictionary <string, Dictionary <string, byte> > {
            };

            foreach (string moduleNo in odbModuleList)
            {
                objectdetectStatusAry[moduleNo] = CompartmentHelper.GetStatusByModuleId(CommandType.ItemDetection, moduleNo, lockerConfiguration);
                Log.Debug("[HCM][Compartment Manager][Compartment Open]" + "[Module No : " + moduleNo + "]" + "[Object Detection Status Array : " + objectdetectStatusAry[moduleNo] + "]");
            }


            var  result = new Locker();
            bool compartmentDoorStatusAlert = false;

            foreach (var compartmentId in model.CompartmentIds)
            {
                var targetCompartment = CompartmentService.CompartmentOpen(compartmentId, lockerConfiguration);

                // Update objectdetection status
                CompartmentConfiguration  targetCompartmentConfig = CompartmentHelper.MapCompartment(compartmentId, lockerConfiguration);
                Dictionary <string, byte> objectdetectStatus      = objectdetectStatusAry[targetCompartmentConfig.CompartmentCode.Odbmod];
                targetCompartment.ObjectDetected = objectdetectStatus[targetCompartmentConfig.CompartmentCode.Odbid] == 1 ? true : false;
                result.Compartments.Add(targetCompartment);
                compartmentDoorStatusAlert |= targetCompartment.CompartmentDoorOpen;
            }
            result.TransactionId = model.TransactionId;

            // Set alert timer
            if (compartmentDoorStatusAlert)
            {
                Log.Information("[HCM][Compartment Manager][Compartment Open]" + "[Set Door Open Timer]");
                CompartmentHelper.SetDoorOpenTimer(lockerConfiguration);
                //CompartmentHelper.EndDoorOpenTimer();
            }

            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// Prepare compartment status object by communicating command to communication port service.
        /// </summary>
        /// <returns>
        ///  Compartment status actual result including real hardware status.
        /// </returns>
        public static List <Compartment> CompartmentStatus(DataObjects.Models.Compartment model, AppSettings lockerConfiguration)
        {
            // Find locker controller board module id and object detection module id list
            var lcbModuleList = new List <string> {
            };
            var odbModuleList = new List <string> {
            };
            List <CompartmentConfiguration> compartments = lockerConfiguration.Locker.Compartments;

            if (model.CompartmentIds.Any(CompartmentId => CompartmentId == "All"))
            {
                model.CompartmentIds = lockerConfiguration.Locker.Compartments.Select(compartment => compartment.CompartmentId).ToArray();
            }

            foreach (var compartmentId in model.CompartmentIds)
            {
                var compartment = compartments.Find(c => c.CompartmentId == compartmentId);
                if (!odbModuleList.Contains(compartment.CompartmentCode.Odbmod)) // Get object detection module id
                {
                    odbModuleList.Add(compartment.CompartmentCode.Odbmod);
                }

                // Get locker controller module id
                if (!lcbModuleList.Contains(compartment.CompartmentCode.Lcbmod))
                {
                    lcbModuleList.Add(compartment.CompartmentCode.Lcbmod);
                }
            }

            // Get all module update
            List <Compartment> compartmentList = new List <Compartment>();
            var opendoorStatusAry = new Dictionary <string, Dictionary <string, byte> > {
            };

            foreach (string moduleNo in lcbModuleList)
            {
                opendoorStatusAry[moduleNo] = CompartmentHelper.GetStatusByModuleId(CommandType.DoorStatus, moduleNo, lockerConfiguration);
            }
            var objectdetectStatusAry = new Dictionary <string, Dictionary <string, byte> > {
            };

            foreach (string moduleNo in odbModuleList)
            {
                objectdetectStatusAry[moduleNo] = CompartmentHelper.GetStatusByModuleId(CommandType.ItemDetection, moduleNo, lockerConfiguration);
            }

            foreach (var compatmentId in model.CompartmentIds)
            {
                var compartment = compartments.Find(c => c.CompartmentId == compatmentId);

                Dictionary <string, byte> opendoorStatus     = opendoorStatusAry[compartment.CompartmentCode.Lcbmod];     //[compatment.CompartmentCode.Lcbid];
                Dictionary <string, byte> objectdetectStatus = objectdetectStatusAry[compartment.CompartmentCode.Odbmod]; //[compatment.CompartmentCode.Odbid];
                Compartment compartmentResult = new Compartment(lockerConfiguration.Locker.LockerId,
                                                                compartment.CompartmentId,
                                                                compartment.CompartmentSize,
                                                                opendoorStatus[compartment.CompartmentCode.Lcbid] == 0 ? true : false,
                                                                opendoorStatus[compartment.CompartmentCode.Lcbid] == 0 ? false : true,
                                                                objectdetectStatus[compartment.CompartmentCode.Odbid] == 1 ? true : false,
                                                                opendoorStatus[compartment.CompartmentCode.Lcbid] == 0 ? "ON" : "OFF");

                Log.Debug("[HCM][Compartment Service][Compartment Status]" + "[Compartment ID : " + compartmentResult.CompartmentId.ToString() + "]"
                          + "[Open Door status: " + compartmentResult.CompartmentDoorOpen.ToString() + "]"
                          + "[Door Available status: " + compartmentResult.CompartmentDoorAvailable.ToString() + "]"
                          + "[Object Detection status: " + compartmentResult.ObjectDetected.ToString() + "]"
                          + "[LED status: " + compartmentResult.StatusLed.ToString() + "]"
                          );
                compartmentList.Add(compartmentResult);
            }

            return(compartmentList);
        }
Beispiel #4
0
        /// <summary>
        /// Prepare open compartment object by communicating command to communication port service.
        /// </summary>
        /// <returns>
        ///  Open compartment actual result with status.
        /// </returns>
        public static Compartment CompartmentOpen(string compartmentId, AppSettings lockerConfiguration)
        {
            // Find the target compartment
            var target_compartment = lockerConfiguration.Locker.Compartments.Find(compartment => compartment.CompartmentId.Contains(compartmentId));

            // Commanding
            var DoorOpenResult = CommunicationPortControlService.SendCommand(CommandType.DoorOpen, CompartmentHelper.MapModuleId(target_compartment), lockerConfiguration);

            Compartment compartmentResult = new Compartment(lockerConfiguration.Locker.LockerId,
                                                            target_compartment.CompartmentId,
                                                            target_compartment.CompartmentSize,
                                                            Convert.ToBoolean(DoorOpenResult["DoorOpen"]),
                                                            !Convert.ToBoolean(DoorOpenResult["DoorOpen"]),
                                                            false,
                                                            Convert.ToBoolean(DoorOpenResult["DoorOpen"]) ? "ON" : "OFF");

            return(compartmentResult);
        }