Example #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);
            });
        }
Example #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);
                });
            }
        }
Example #3
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);
                }
            }
        }
Example #4
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);
         }
     }
 }
Example #5
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());
        }
Example #6
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);
        }
Example #7
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);
        }