Пример #1
0
        public static void UpdateScriptFromStation(String BlockID, String BlockName, String StationName, DateTime ExecutionTimeStart, DateTime ExecutionTimeEnd, int CommandCounter, int ExecutionNumber, String DeviceName, String DeviceCategory, String CommandName, String Owner, int DelayTime, String Parameter, String ScriptState)
        {
            ScriptTB ExistingScript = ScriptDBBuffer.FirstOrDefault(Item => Item.Value.BlockID == BlockID && Item.Value.ExecutionNumber == ExecutionNumber).Value;

            if (ExistingScript != null)
            {
                ExistingScript.ScriptState = ScriptState;
                UpdateScriptToMonitoring(ExistingScript);
                DatabaseSynchronization.ScriptSaveChange(false);
            }
        }
Пример #2
0
        private static void SetStationStateToWaitingStation(Object ScriptBlockID)
        {
            String BlockID = ScriptBlockID.ToString();
            List <KeyValuePair <String, ScriptTB> > ScriptList = ScriptDBBuffer.Where(Item => Item.Value.BlockID == BlockID).ToList();

            foreach (KeyValuePair <String, ScriptTB> ScriptNode in ScriptList)
            {
                ScriptNode.Value.ScriptState = SCRIPTSTATE.WAITINGSTATION.ToString();
                UpdateScriptToMonitoring(ScriptNode.Value);
            }

            DatabaseSynchronization.ScriptSaveChange(true);
        }
Пример #3
0
        public static Boolean RemoveScript(String BlockID, int ExecutionNumber)
        {
            try
            {
                ScriptTB ThisBuffer = ScriptDBBuffer.FirstOrDefault(Item => Item.Value.BlockID == BlockID && Item.Value.ExecutionNumber == ExecutionNumber).Value;
                ScriptDBBuffer.TryRemove(ThisBuffer.BlockID + ThisBuffer.ExecutionNumber, out ThisBuffer);
                DatabaseSynchronization.DeleteScript(ScriptDBBuffer.FirstOrDefault(Item => Item.Value.BlockID == BlockID && Item.Value.ExecutionNumber == ExecutionNumber).Value);
                DatabaseSynchronization.ScriptSaveChange(true);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Пример #4
0
        private static void UpdateExecutionState(STATIONNAME StationName, Object Value)
        {
            String[] ValueArr        = Value.ToString().Split(new char[] { ',' });
            String   BlockID         = ValueArr[0];
            int      ExecutionNumber = Convert.ToInt32(ValueArr[1]);
            String   ScriptState     = ValueArr[2];

            ScriptTB ScriptDB = ScriptDBBuffer.FirstOrDefault(Item => Item.Value.BlockID == BlockID && Item.Value.ExecutionNumber == ExecutionNumber).Value;

            if (ScriptDB == null)
            {
                return;
            }

            ScriptDB.ScriptState = ScriptState;
            DatabaseSynchronization.ScriptSaveChange(true);

            if (ScriptState == "ENDTIMEPASSED")
            {
                Console.WriteLine("ENDTIMEPASSED");
            }

            UpdateScriptToMonitoring(ScriptDB);
        }
Пример #5
0
        private static void ReadScriptFromBuffer()
        {
            Task TTCSTask = Task.Run(() =>
            {
                Boolean IsDatabaseUpdate = false;
                while (IsScriptActive)
                {
                    ScriptBuffer ThisBuffer = null;
                    if (NewScriptBuffer.TryDequeue(out ThisBuffer))
                    {
                        ScriptTB ExistingScript = ScriptDBBuffer.FirstOrDefault(Item => Item.Value.BlockName == ThisBuffer.Script.BlockName && Item.Value.ScriptState != "EXECUTED").Value;
                        if (ExistingScript == null)  //New block name
                        {
                            ThisBuffer.Script.TargetID    = TTCSHelper.GenNewID();
                            ThisBuffer.Script.BlockID     = ThisBuffer.Script.TargetID;
                            ThisBuffer.Script.ScriptState = "CREATED";
                            ScriptDBBuffer.TryAdd(ThisBuffer.Script.BlockID + ThisBuffer.Script.ExecutionNumber, ThisBuffer.Script);

                            DatabaseSynchronization.InsertScript(ThisBuffer.Script);
                            IsDatabaseUpdate = true;
                            AddScriptToMonitoring(ThisBuffer.Script);
                        }
                        else if (ExistingScript.ScriptState != "EXECUTING") //Existing block name
                        {
                            ScriptTB ExistingBlockScript = ScriptDBBuffer.FirstOrDefault(Item => Item.Value.BlockName == ThisBuffer.Script.BlockName && Item.Value.ExecutionNumber == ThisBuffer.Script.ExecutionNumber && Item.Value.ScriptState != "EXECUTED").Value;

                            if (ExistingBlockScript == null)  //Add new script to the same BlockName
                            {
                                ExistingBlockScript         = ThisBuffer.Script;
                                ExistingBlockScript.BlockID = ExistingScript.BlockID;
                                ScriptDBBuffer.TryAdd(ExistingBlockScript.BlockID + ExistingBlockScript.ExecutionNumber, ExistingBlockScript);

                                DatabaseSynchronization.InsertScript(ExistingBlockScript);
                                IsDatabaseUpdate = true;
                                AddScriptToMonitoring(ExistingBlockScript);
                            }
                            else
                            {
                                if (!IsEqualScript(ExistingBlockScript, ThisBuffer.Script))  //Update existing BlockName
                                {
                                    ExistingBlockScript.CommandCounter     = ThisBuffer.Script.CommandCounter;
                                    ExistingBlockScript.CommandName        = ThisBuffer.Script.CommandName;
                                    ExistingBlockScript.DelayTime          = ThisBuffer.Script.DelayTime;
                                    ExistingBlockScript.DeviceCategory     = ThisBuffer.Script.DeviceCategory;
                                    ExistingBlockScript.DeviceName         = ThisBuffer.Script.DeviceName;
                                    ExistingBlockScript.ExecutionTimeEnd   = ThisBuffer.Script.ExecutionTimeEnd;
                                    ExistingBlockScript.ExecutionTimeStart = ThisBuffer.Script.ExecutionTimeStart;
                                    ExistingBlockScript.Owner       = ThisBuffer.Script.Owner;
                                    ExistingBlockScript.Parameter   = ThisBuffer.Script.Parameter;
                                    ExistingBlockScript.ScriptState = "CREATED";
                                    ExistingBlockScript.StationName = ThisBuffer.Script.StationName;

                                    UpdateScriptToMonitoring(ExistingBlockScript);
                                }
                            }
                        }
                    }

                    ResponseToClient(ThisBuffer);
                    if (!IsDatabaseUpdate)
                    {
                        IsDatabaseUpdate = ResponseToStation(ThisBuffer);
                    }
                    else
                    {
                        ResponseToStation(ThisBuffer);
                    }

                    if (!IsDatabaseUpdate)
                    {
                        IsDatabaseUpdate = RemoveExpireScript();
                    }
                    else
                    {
                        RemoveExpireScript();
                    }

                    if (IsDatabaseUpdate)
                    {
                        IsDatabaseUpdate = !DatabaseSynchronization.ScriptSaveChange(true);
                    }

                    Thread.Sleep(10);
                }
            });
        }
Пример #6
0
 public static void RemoveAllScriptDB()
 {
     ScriptDBBuffer.Clear();
     DatabaseSynchronization.DeleteAllScript();
     DatabaseSynchronization.ScriptSaveChange(false);
 }