Esempio n. 1
0
        //--------------------------------------------------------------------------------------Queue----------------------------------------------------------------------------------

        public void AstroQueueUpdate(String jSon)
        {
            jSon = StringCompression.DecompressString(jSon);
            JObject obj = JObject.Parse(jSon);

            STATIONNAME stationName = TTCSHelper.StationStrConveter(obj["StationName"].ToString());
            String      Id          = obj["Id"].ToString();
            String      Event       = obj["Event"].ToString();
            DateTime    TimeStamp   = DateTime.Parse(obj["TimeStamp"].ToString());

            Console.WriteLine("[AstroQueueUpdate] " + obj["StationName"] + " : " + obj["Event"] + " --> " + Id);

            AstroQueueImpl astroQueue = DBQueueEngine.FindById(stationName, Id);

            if (Event == "RECEIVED")
            {
                QueueStatus queueStatus = new QueueStatus(QUEUE_STATUS.WAITINGSTATION, SENDING_STATUS.COMPLETED, TimeStamp);

                astroQueue.QueueStatus.Add(queueStatus);
                astroQueue.Save();
            }

            Task task = Task.Run(async() =>
            {
                await Task.Delay(100);

                StationHandler StationCommunication = AstroData.GetStationObject(stationName);
                StationCommunication.AckTarget(astroQueue, QUEUE_STATUS.WAITINGSTATION, SENDING_STATUS.COMPLETED);
            });
        }
Esempio n. 2
0
        public void AstroQueueUpdateExposure(String jSon)
        {
            jSon = StringCompression.DecompressString(jSon);
            JObject obj = JObject.Parse(jSon);

            STATIONNAME    stationName        = TTCSHelper.StationStrConveter(obj["StationName"].ToString());
            String         Id                 = obj["Id"].ToString();
            String         AstroQueueId       = obj["AstroQueueId"].ToString();
            ExposedHistory exposedHistoryRecv = (ExposedHistory)JsonConvert.DeserializeObject(obj["ExposedHistory"].ToString(), typeof(ExposedHistory));

            Console.WriteLine("[AstroQueueUpdateExposure] " + obj["StationName"] + " : " + exposedHistoryRecv.filterName + " --> " + Id);

            AstroQueueImpl astroQueue     = DBQueueEngine.FindById(stationName, AstroQueueId);
            ExposedHistory exposedHistory = astroQueue.Target.exposedHistory.Find(Item => Item.filterName == exposedHistoryRecv.filterName && Item.executedStatus == EXECUTESTATUS.WAIT);

            if (exposedHistory != null)
            {
                exposedHistory.executedStatus = exposedHistoryRecv.executedStatus;
                exposedHistory.executedDate   = exposedHistoryRecv.executedDate;

                astroQueue.Save();

                Task task = Task.Run(async() =>
                {
                    await Task.Delay(100);

                    StationHandler StationCommunication = AstroData.GetStationObject(stationName);
                    StationCommunication.AckExposure(Id, SENDING_STATUS.COMPLETED);
                });
            }
        }
Esempio n. 3
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            if (VerifyData())
            {
                List <String> PermissionArray = new List <String>();
                for (int i = 0; i < UserPermissionType.RowCount; i++)
                {
                    if (Convert.ToBoolean(UserPermissionType[0, i].Value))
                    {
                        PermissionArray.Add(UserPermissionType[1, i].Value.ToString());
                    }
                }

                List <String> StationArray = new List <String>();
                for (int i = 0; i < UserStationPermission.RowCount; i++)
                {
                    if (Convert.ToBoolean(UserStationPermission[0, i].Value))
                    {
                        StationArray.Add(UserStationPermission[1, i].Value.ToString());
                    }
                }

                if (UserID == null)
                {
                    UserID = TTCSHelper.GenNewID();
                    UserManagement.AddUser(UserID, UserName.Text, UserLoginName.Text, UserLoginPassword.Text, String.Join(",", PermissionArray), String.Join(",", StationArray));
                }
                else
                {
                    UserManagement.UpdateUser(UserID, UserName.Text, UserLoginName.Text, UserLoginPassword.Text, String.Join(",", PermissionArray), String.Join(",", StationArray));
                }

                this.Close();
            }
        }
Esempio n. 4
0
        public static void SendScriptToStation(ScriptTB CompletedScript)
        {
            STATIONNAME     DestinationStation = STATIONNAME.NULL;
            List <ScriptTB> ScriptArr          = ScriptDBBuffer.Values.Where(Item => Item.BlockID == CompletedScript.BlockID).ToList();

            ScriptStructure[] StructureArr = ConvertScriptTBToScriptStructure(ScriptArr);

            foreach (ScriptTB ThisScript in ScriptArr)
            {
                DestinationStation     = TTCSHelper.StationStrConveter(ThisScript.StationName);
                ThisScript.ScriptState = SCRIPTSTATE.WAITINGSERVER.ToString();

                UpdateScriptToMonitoring(ThisScript);
            }

            StationHandler ThisStation = AstroData.GetStationObject(DestinationStation);

            if (ThisStation.IsStationConnected)
            {
                StructureArr.OrderBy(Item => Item.ExecutionNumber);
                AstroData.ScriptHandler(DestinationStation, StructureArr);

                foreach (ScriptTB ThisScript in ScriptArr)
                {
                    ThisScript.ScriptState = SCRIPTSTATE.SENDINGTOSTATION.ToString();
                    UpdateScriptToMonitoring(ThisScript);
                }
            }
        }
Esempio n. 5
0
        public void GetScript()
        {
            STATIONNAME?StationName = TTCSHelper.StationConveter(StationSelection.Text);

            if (StationName != null)
            {
                ScriptEngine.RefreshScript(StationName.Value);
            }
        }
Esempio n. 6
0
 private static void initialConfig()
 {
     if (scriptConfigure != null)
     {
         foreach (ScriptConfigure config in scriptConfigure)
         {
             StationScript stationScript = new StationScript(TTCSHelper.StationStrConveter(config.config_name));
             stationScript.LastestScriptFileName = config.config_value;
             ScriptStation.Add(stationScript);
         }
     }
 }
Esempio n. 7
0
        private static ScriptStructure[] ConvertScriptTBToScriptStructure(List <ScriptTB> ScriptTBArr)
        {
            List <ScriptStructure> ScriptStructureList = new List <ScriptStructure>();

            foreach (ScriptTB ThisScript in ScriptTBArr)
            {
                ScriptStructure NewSturcture = new ScriptStructure();
                NewSturcture.TargetID           = ThisScript.TargetID;
                NewSturcture.BlockID            = ThisScript.BlockID;
                NewSturcture.BlockName          = ThisScript.BlockName;
                NewSturcture.CommandCounter     = ThisScript.CommandCounter.Value;
                NewSturcture.CommandName        = ThisScript.CommandName;
                NewSturcture.DelayTime          = ThisScript.DelayTime;
                NewSturcture.DeviceCategory     = TTCSHelper.DeviceCategoryStrConverter(ThisScript.DeviceCategory);
                NewSturcture.DeviceName         = TTCSHelper.DeviceNameStrConverter(ThisScript.DeviceName);
                NewSturcture.ExecutionNumber    = ThisScript.ExecutionNumber;
                NewSturcture.ExecutionTimeEnd   = ThisScript.ExecutionTimeEnd;
                NewSturcture.ExecutionTimeStart = ThisScript.ExecutionTimeStart;
                NewSturcture.Owner = ThisScript.Owner;

                NewSturcture.Parameter = new List <Object>();
                String[] ValueStr = ThisScript.Parameter.Split(new char[] { ',' });
                foreach (String ThisValue in ValueStr)
                {
                    NewSturcture.Parameter.Add(ThisValue);
                }
                ;

                NewSturcture.ScriptState = TTCSHelper.ScriptStateStrConverter(ThisScript.ScriptState);
                NewSturcture.StationName = TTCSHelper.StationStrConveter(ThisScript.StationName);

                ScriptStructureList.Add(NewSturcture);
            }

            return(ScriptStructureList.ToArray());
        }
Esempio n. 8
0
        public ReturnKnowType AstroSet(STATIONNAME StationName, DEVICENAME DeviceName, dynamic CommandName, Object[] Values, DateTime CommandDateTime)
        {
            DEVICECATEGORY DeviceCategory = TTCSHelper.ConvertDeviceNameToDeviceCategory(StationName, DeviceName);

            return(AstroData.SetCommandHandler(StationName, DeviceCategory, DeviceName, CommandName, Values, CommandDateTime));
        }
Esempio n. 9
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);
                }
            });
        }
Esempio n. 10
0
        private static Boolean VerifyScript(STATIONNAME StationName, List <ScriptStructureNew> ScriptCollection, out String Message)
        {
            foreach (ScriptStructureNew ThisScript in ScriptCollection)
            {
                //DUMMY ONLY
                //ThisScript.TargetID = "XXXXXX";

                if (String.IsNullOrEmpty(ThisScript.ScriptID))
                {
                    Message = "Invalid ScriptID can't be null or empty value. Please check.";
                    return(false);
                }

                if (String.IsNullOrEmpty(ThisScript.BlockID))
                {
                    Message = "Invalid BlockID can't be null or empty value at Script ID : " + ThisScript.ScriptID + ". Please check.";
                    return(false);
                }

                STATIONNAME ScriptStationName = TTCSHelper.StationStrConveter(ThisScript.StationName);

                if (StationName == STATIONNAME.NULL)
                {
                    Message = "Invalid station same at script ID : " + ThisScript.BlockID + ". Please check spelling.";
                    return(false);
                }

                if (StationName != ScriptStationName)
                {
                    Message = "Invalid station name not match in folder at script ID : " + ThisScript.BlockID + ". Please check spelling.";
                    return(false);
                }

                DEVICENAME DeviceName = TTCSHelper.DeviceNameStrConverter(ThisScript.DeviceName);
                if (DeviceName == DEVICENAME.NULL)
                {
                    Message = "Invalid device name at script ID : " + ThisScript.BlockID + ". Please check spelling.";
                    return(false);
                }

                DEVICECATEGORY DeviceCategory = TTCSHelper.ConvertDeviceNameToDeviceCategory(StationName, DeviceName);
                if (DeviceCategory == DEVICECATEGORY.NULL)
                {
                    Message = "Invalid devicecategory at script ID : " + ThisScript.BlockID + ". Please check spelling.";
                    return(false);
                }

                Object CommandName = TTCSHelper.CommandNameConverter(DeviceCategory, ThisScript.CommandName);
                if (CommandName == null)
                {
                    Message = "Invalid command name at script ID : " + ThisScript.BlockID + ". Please check spelling.";
                    return(false);
                }

                Int64 StartDateLong = 0;
                if (!Int64.TryParse(ThisScript.ExecutionTimeStart, out StartDateLong))
                {
                    Message = "Invalid start datetime at script ID : " + ThisScript.BlockID + ". Please check spelling.";
                    return(false);
                }

                Int64 EndDateLong = 0;
                if (!Int64.TryParse(ThisScript.ExecutionTimeEnd, out EndDateLong))
                {
                    Message = "Invalid end datetime at script ID : " + ThisScript.BlockID + ". Please check spelling.";
                    return(false);
                }

                int Life = 0;
                if (!int.TryParse(ThisScript.Life, out Life))
                {
                    Message = "Invalid life time at " + ThisScript.BlockID + ". Please check spelling.";
                    return(false);
                }

                if (String.IsNullOrEmpty(ThisScript.TargetID))
                {
                    Message = "Invalid TargetID can't be null or empty value at Script ID : " + ThisScript.BlockID + ". Please check.";
                    return(false);
                }

                if (String.IsNullOrEmpty(ThisScript.Owner))
                {
                    Message = "Invalid Owner can't be null or empty value at Script ID : " + ThisScript.BlockID + ". Please check.";
                    return(false);
                }

                ReturnKnowType CommandResult = CommandDefinition.VerifyCommand(StationName, DeviceCategory, CommandName, ThisScript.Parameters.ToArray());
                if (CommandResult.ReturnType == ReturnStatus.FAILED)
                {
                    Message = "Invalid parameter at script ID : " + ThisScript.ScriptID + " at Command " + CommandName + ". With: " + CommandResult.ReturnMessage + ". Please check spelling.";
                    return(false);
                }
            }

            Message = "All script verified.";
            return(true);
        }
Esempio n. 11
0
        private static Boolean ExtractScriptData(String FileName, STATIONNAME StationName, List <ScriptConfigure> scriptConfigures, bool checkSameScript)
        {
            Boolean IsScriptOK = false;
            //StationName = STATIONNAME.NULL;

            String FilePathStr = FileName;

            if (File.Exists(FilePathStr))
            {
                try
                {
                    using (FileStream fs = new FileStream(FilePathStr, FileMode.Open, FileAccess.Read, FileShare.None))
                    {
                        using (StreamReader r = new StreamReader(fs))
                        {
                            //Console.WriteLine("Reading... " + FilePathStr);
                            String jsonString = r.ReadToEnd();

                            if (jsonString.Length > 0)
                            {
                                try
                                {
                                    List <ScriptStructureNew> NewScriptCollection = JsonConvert.DeserializeObject <List <ScriptStructureNew> >(jsonString);

                                    if (NewScriptCollection.Count > 0)
                                    {
                                        String TempFileNameStr = FilePathStr.Split('\\').Last();
                                        TempFileNameStr = TempFileNameStr.Replace(".txt", "");

                                        FILESTATE FileState = IsTheSameScript(TempFileNameStr, NewScriptCollection, StationName, scriptConfigures);

                                        if (FileState != FILESTATE.SAME || !checkSameScript)
                                        {
                                            bool IsMustInsertToDB = true;

                                            Console.WriteLine("Extracting Script... : " + FilePathStr);

                                            StationScript scriptTemp = ScriptStation.FirstOrDefault(Item => Item.StationName == StationName);
                                            scriptTemp.LastestScriptFileName = TempFileNameStr;

                                            if (scriptConfigure == null)
                                            {
                                                scriptConfigure = new List <ScriptConfigure>();
                                                scriptConfigure.Add(new ScriptConfigure(StationName.ToString(), TempFileNameStr, false, true));
                                            }
                                            else if (scriptTemp == null)
                                            {
                                                scriptConfigure.Add(new ScriptConfigure(StationName.ToString(), TempFileNameStr, false, true));
                                            }
                                            else
                                            {
                                                ScriptConfigure tempScript = scriptConfigure.FirstOrDefault(Item => Item.config_name == StationName.ToString());

                                                if (tempScript != null)
                                                {
                                                    if (tempScript.config_isaddtodb == true)
                                                    {
                                                        IsMustInsertToDB = false;
                                                    }
                                                    else
                                                    {
                                                        tempScript.config_isaddtodb = true;
                                                    }

                                                    tempScript.config_value  = TempFileNameStr;
                                                    tempScript.config_status = false;
                                                }
                                                else
                                                {
                                                    scriptConfigure.Add(new ScriptConfigure(StationName.ToString(), TempFileNameStr, false, true));
                                                }
                                            }

                                            if (FileState == FILESTATE.NOTSAME)
                                            {
                                                IsMustInsertToDB = true;
                                            }

                                            //DBScheduleEngine.DropSchedule(StationName);
                                            //Console.WriteLine(IsMustInsertToDB);

                                            String Message = "";

                                            Console.WriteLine("Verifying Script... : " + FilePathStr);

                                            if (VerifyScript(StationName, NewScriptCollection, out Message))
                                            {
                                                Console.WriteLine("Clear Fail Script to Database... : " + FilePathStr);
                                                DBScheduleEngine.CancleFailSchedule(StationName);

                                                Console.WriteLine("Insert Script to Database... (DB: " + IsMustInsertToDB + ") : " + FilePathStr);
                                                foreach (ScriptStructureNew Script in NewScriptCollection)
                                                {
                                                    //DUMMY ONLY
                                                    //Script.TargetID = "XXXXXX";
                                                    if (IsMustInsertToDB)
                                                    {
                                                        String _id = DBScheduleEngine.InsertSchedule(Script);
                                                        if (_id != null)
                                                        {
                                                            Script._id = _id;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        String _id = DBScheduleEngine.GetId(Script);
                                                        Script._id = _id;
                                                        //Console.WriteLine("OLD ID: " + _id);
                                                    }

                                                    //if (Script.ScriptState != SCRIPTSTATE.CANCELED.ToString())
                                                    //{
                                                    //    Script.ScriptState = SCRIPTSTATE.WAITINGSERVER.ToString();
                                                    //}
                                                }

                                                Console.WriteLine("Add Script to Object... : " + FilePathStr);

                                                StationName = TTCSHelper.StationStrConveter(NewScriptCollection.FirstOrDefault().StationName);
                                                StationScript ThisStationTemp = GetStationScript(StationName);

                                                if (ThisStationTemp == null)
                                                {
                                                    ThisStationTemp = new StationScript(StationName);
                                                    ScriptStation.Add(ThisStationTemp);
                                                }
                                                else
                                                {
                                                    ThisStationTemp.RemoveAllScript();
                                                }

                                                ThisStationTemp.AddScript(NewScriptCollection);

                                                DisplayScript(Message, StationName);
                                                IsScriptOK = true;

                                                fs.Close();
                                            }
                                            else
                                            {
                                                fs.Close();

                                                DisplayScriptMessage(Message);

                                                Console.WriteLine("Verifying command failed, Deleted.");
                                                Console.WriteLine(Message);
                                                File.Delete(@FilePathStr);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        //Console.WriteLine("No Data Received, Deleted.");
                                    }
                                }
                                catch (JsonReaderException ex)
                                {
                                    fs.Close();

                                    try
                                    {
                                        Console.WriteLine("File isn't jSon, Deleted.");
                                        File.Delete(@FilePathStr);
                                    }
                                    catch (Exception x)
                                    {
                                        Console.WriteLine(x.Message);
                                    }
                                }
                                catch (Exception ex2)
                                {
                                    fs.Close();

                                    Console.WriteLine(ex2.Message);
                                    File.Delete(@FilePathStr);
                                }
                            }
                            else
                            {
                                fs.Close();

                                try
                                {
                                    Console.WriteLine("File size <= 0 byte, Deleted.");
                                    File.Delete(@FilePathStr);
                                }
                                catch (Exception x)
                                {
                                    Console.WriteLine(x);
                                }
                            }
                        }
                    }
                }
                catch (Exception z)
                {
                    Console.WriteLine(z);
                }
            }

            return(IsScriptOK);
        }