Ejemplo n.º 1
0
 public override void UpdateState(bool success, MachineStates finishedState)
 {
     Debug.Log(finishedState);
     if (Vector2.Distance(transform.position, player.transform.position) > 5)
     {
         comedorPatrollingAction.StartAction();
         actualState = MachineStates.Patrolling;
     }
     else
     {
         if (actualState == MachineStates.MoveToPlayer && finishedState == MachineStates.MoveToPlayer && success)
         {
             comedorattackAction.StartAction();
             actualState = MachineStates.Attack;
         }
     }
     if (actualState == MachineStates.Attack && finishedState == MachineStates.Attack && success)
     {
         if (!reachedEva)
         {
             comedorMoveToPlayer.StartAction();
             actualState = MachineStates.MoveToPlayer;
         }
         else
         {
             comedorattackAction.StartAction();
             actualState = MachineStates.Attack;
         }
     }
 }
Ejemplo n.º 2
0
        public void updateState(MachineStates state, bool value)
        {
            Debug.WriteLine("Machine.updateState");

            if(state != MachineStates.UNDEFINED)
            {
                states[state] = value;
                mainPage.updateGUI();
                mainPage.logic.machineStateChange(state);
            }
        }
Ejemplo n.º 3
0
    public override void UpdateState(bool success, MachineStates thisState)
    {
        actualState = thisState;
        switch (nextState)
        {
        case 1:
            patrollingAction.StartAction();
            thisState = MachineStates.Patrolling;
            break;

        case 2:
            sleepAction.StartAction();
            thisState = MachineStates.Sleep;
            break;
        }
    }
Ejemplo n.º 4
0
        private void ChangeState(MachineStates newState, MachineStates nextState = MachineStates.Idle, int predictedNextChangeSeconds = 10)
        {
            //Copy last state
            StateData.PreviousState = StateData.CurrentState;

            //Set new state and changetimestamp (right now)
            StateData.CurrentState = newState;
            StateData.CurrentStateChangedTimestamp = DateTime.Now;

            //Set predicted state which this adapter will be going to and a predicted time when it will change.
            StateData.PredictedState           = nextState;
            StateData.PredictedStateChangeTime = DateTime.Now.AddSeconds(predictedNextChangeSeconds);

            //Publishes the state change and the orderId indicates the context of the state change.
            MachineStateDataChanged?.Invoke(StateData, OrderData.OrderId);
        }
 public void EmergencyStop()
 {
     try
     {
         activeColorMemory  = ActiveColor;
         conveyorOnMemory   = ConveyorOn;
         currentStateMemory = CurrentState;
         ActiveColor        = MachineColor.None;
         ConveyorOn         = false;
         CurrentState       = MachineStates.Stoped;
         paintInjectionStopWatch.Stop();
         batchProductionStopWatch.Stop();
     }
     catch (SocketException)
     {
         lock (connectedLock) { Connected = false; }
         throw;
     }
 }
Ejemplo n.º 6
0
        /// <inheritdoc />
        public override bool Equals(object obj)
        {
            var other = obj as OperationalState;

            if (other == null)
            {
                return(false);
            }
            if (!base.Equals(obj))
            {
                return(false);
            }
            if (!MachineStates.SequenceEqual(other.MachineStates))
            {
                return(false);
            }
            if (CurrentJobState != other.CurrentMachineState)
            {
                return(false);
            }
            if (!JobStates.SequenceEqual(other.JobStates))
            {
                return(false);
            }
            if (CurrentJobState != other.CurrentJobState)
            {
                return(false);
            }
            if (RunningTime != other.RunningTime)
            {
                return(false);
            }
            if (RemainingTime != other.RemainingTime)
            {
                return(false);
            }
            if (ProgressPercentage != other.ProgressPercentage)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 7
0
 public VmModel(
     int machineId,
     string machineName,
     DateTimeOffset lastPoll,
     MachineStates machineState,
     LCMStates?LCMState,
     decimal?machineCpuUtilizationPercent,
     int?machineMemmoryUtilizationBytes,
     string?machineIp,
     string?machineMac)
 {
     MachineId       = machineId;
     MachineName     = machineName;
     LastPoll        = lastPoll;
     MachineState    = machineState;
     MachineLCMState = LCMState;
     MachineCpuUtilizationPercent   = machineCpuUtilizationPercent;
     MachineMemmoryUtilizationBytes = machineMemmoryUtilizationBytes;
     MachineIp  = machineIp;
     MachineMac = machineMac;
 }
Ejemplo n.º 8
0
        public VmPoolInfoExtendedReturnContainer(object[] input)
        {
            //Console.WriteLine("VMPoolInfoExtendedReturnContainer creation started");
            if (input is null)
            {
                Console.WriteLine("Input was null for VmPoolInfoExtendedReturnContainer");
            }

            VmModelList = new List <VmModel>();
            //Console.WriteLine("VMPoolInfoExtendedReturnContainer: VM Model List Created in ");
            XmlDocument ResultDocument;

            ResultDocument = GetCleanXmlDocument(input);
            //Console.WriteLine("VMPoolInfoExtendedReturnContainer: Clean result document generated");

            XmlNodeList VmTemplateNodes = ResultDocument.GetElementsByTagName("VM");

            //Console.WriteLine("VMPoolInfoExtendedReturnContainer: VMTemplate Nodes recovered");

            foreach (XmlNode VmNode in VmTemplateNodes)
            {
                var result = true;

                var monitoringNode = VmNode.SelectSingleNode("MONITORING");
                if (monitoringNode == null)
                {
                    Console.WriteLine("Error getting Monitoring node trashing result");
                    continue;
                }

                result &= int.TryParse(VmNode.SelectSingleNode("ID")?.InnerText, out int machineId);

                if (!result)
                {
                    Console.WriteLine("Error getting ID Node trashing result");
                    continue;
                }

                var machineName = VmNode.SelectSingleNode("NAME")?.InnerText;
                result &= machineName != null;
                if (!result)
                {
                    Console.WriteLine("Error getting Name node trashing result");
                    continue;
                }

                result &= long.TryParse(VmNode.SelectSingleNode("LAST_POLL")?.InnerText, out long lastPollLong);
                var lastPoll = DateTimeOffset.FromUnixTimeSeconds(lastPollLong);
                if (!result)
                {
                    Console.WriteLine("Error getting Last poll trashing result");
                    continue;
                }

                result &= int.TryParse(VmNode.SelectSingleNode("STATE")?.InnerText, out int machineStateInt);
                MachineStates machineState = (MachineStates)machineStateInt;
                if (!result)
                {
                    Console.WriteLine("Error getting STATE node trashing result");
                    continue;
                }

                result &= int.TryParse(VmNode.SelectSingleNode("LCM_STATE")?.InnerText, out int lcmstateint);
                LCMStates lcmState = (LCMStates)lcmstateint;

                //if (!result)
                //{
                //    Console.WriteLine("Error getting LCMSTATE Node trashing result");
                //    continue;
                //}

                result &= decimal.TryParse(monitoringNode.SelectSingleNode("CPU")?.InnerText, out decimal machineCpuPercent);
                //if (!result)
                //{
                //    Console.WriteLine("Error getting CPU Node trashing result");
                //    continue;
                //}

                result &= int.TryParse(monitoringNode.SelectSingleNode("MEMORY")?.InnerText, out int machineMemmoryUtilizationBytes);
                //if (!result)
                //{
                //    Console.WriteLine("Error getting MEMORY Node trashing result");
                //    continue;
                //}

                var    machineIpNodeInnerText = monitoringNode.SelectSingleNode("GUEST_IP_ADDRESSES")?.InnerText ?? "";
                Match  machineIpMatch         = Regex.Match(machineIpNodeInnerText, @"(\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})");
                string machineIp;
                //Console.WriteLine($"machineIpNodeInnerText, {machineIpNodeInnerText}, node == null : {monitoringNode.SelectSingleNode("GUEST_IP_ADDRESSES") == null}");
                if (!machineIpMatch.Success)
                {
                    result    = false;
                    machineIp = "";
                }
                else
                {
                    machineIp = machineIpMatch.Value;
                }
                //if (!result)
                //{
                //    Console.WriteLine("Error getting IP trashing result");
                //    continue;
                //}

                var machineMac = VmNode.SelectSingleNode("TEMPLATE")?.SelectSingleNode("NIC")?.SelectSingleNode("MAC")?.InnerText;
                result &= machineMac != null;

                //if (!result)
                //{
                //    Console.WriteLine("Error getting MAC Node trashing result");
                //    continue;
                //}

                //if (!result)
                //{
                //    Console.WriteLine("VMPoolInfoExtendedReturnContainer: Error in result - Trashing result");
                //    continue;
                //}
                VmModelList.Add(new VmModel(
                                    machineId,
                                    machineName,
                                    lastPoll,
                                    machineState,
                                    lcmState,
                                    machineCpuPercent,
                                    machineMemmoryUtilizationBytes,
                                    machineIp,
                                    machineMac
                                    ));
            }
        }
Ejemplo n.º 9
0
 public abstract void UpdateState(bool success, MachineStates finishedState
                                  );
Ejemplo n.º 10
0
        public void machineStateChange(MachineStates state)
        {
            Debug.WriteLine("Logic.machineStateChange");

            switch (state)
            {
                case MachineStates.STARTUP:

                    // If neither STARTUP or MANUAL states are active, machine must be running in AUTO
                    if (!machine.getState(MachineStates.STARTUP) && !machine.getState(MachineStates.MANUAL))
                        machine.updateState(MachineStates.AUTO, true);
                    else
                        machine.updateState(MachineStates.AUTO, false);

                    break;

                case MachineStates.AUTO:

                    break;

                case MachineStates.MANUAL:
                    
                    // If neither STARTUP or MANUAL states are active, machine must be running in AUTO
                    if (!machine.getState(MachineStates.STARTUP) && !machine.getState(MachineStates.MANUAL))
                        machine.updateState(MachineStates.AUTO, true);
                    else
                        machine.updateState(MachineStates.AUTO, false);
                    break;

                case MachineStates.LATCH:

                    // If LATCH occours while machineState.AUTO is true and a Process is loaded, then hasLatched = true
                    if (machine.getState(MachineStates.LATCH) && machine.getState(MachineStates.AUTO) && process.isLoaded())
                        machine.hasLatched = true;
                    
                    break;

                case MachineStates.SPLIT:

                    if (machine.getState(MachineStates.SPLIT) && machine.getState(MachineStates.AUTO))
                    {
                        // If SPLIT occours while machineState.AUTO is true and process is loaded, then process should be changed accordingly.
                        if (process.isLoaded())
                        {
                            if (machine.hasLatched)
                            {
                                process.quantity++;
                                machine.hasLatched = false;
                            }
                            else
                                process.waste++;

                            if (process.stopped)
                                runEvent();

                            events[events.Count - 1].change = DateTime.Now;
                            process.change = DateTime.Now;
                            process.stopped = false;
                            order.change = DateTime.Now;
                            
                            // Restart timer
                            mainPage.hideProcessStopContentDialog();
                            splitTimer.Change(5000, 5000);
                        }
                    }

                    break;
            }
            
            mainPage.updateGUI();
        }
Ejemplo n.º 11
0
        public bool getState(MachineStates state)
        {
            //Debug.WriteLine("Machine.getState");

            return states[state];
        }
Ejemplo n.º 12
0
        public void addState(MachineStates state, bool value)
        {
            Debug.WriteLine("Machine.addState");

            states.Add(state, value);
        }