Пример #1
0
        public Boolean ScheduleEvented(String ScriptsJSON)
        {
            String             jSonC  = StringCompression.DecompressString(ScriptsJSON);
            ScriptStructureNew Script = (ScriptStructureNew)Newtonsoft.Json.JsonConvert.DeserializeObject(jSonC, typeof(ScriptStructureNew));

            DBScheduleEngine.UpdateSchedule(Script);
            return(true);
        }
Пример #2
0
        public Boolean DelayScheduleEvented(String ScriptsJSON)
        {
            String jSonC = StringCompression.DecompressString(ScriptsJSON);

            ScriptStructureNew[] Scripts = (ScriptStructureNew[])Newtonsoft.Json.JsonConvert.DeserializeObject(jSonC, typeof(ScriptStructureNew[]));

            foreach (ScriptStructureNew Script in Scripts)
            {
                DBScheduleEngine.UpdateSchedule(Script);
            }

            Console.WriteLine("RECEIVED DelayScheduleEvented() = " + Scripts.Count());

            return(true);
        }
Пример #3
0
        private HttpResponseMessage GetSetCommandStructure(String StationNameStr, String TargetIDStr, String SessionID)
        {
            XmlDocument    myXml = new XmlDocument();
            XPathNavigator xNav  = myXml.CreateNavigator();

            if (UserSessionHandler.VerifyTimeout(SessionID))
            {
                STATIONNAME ThisStation = HostingHelper.ConvertStationNameStrToSTATIONNAME(StationNameStr);

                if (ThisStation == STATIONNAME.NULL)
                {
                    return(HostingHelper.ReturnError("Invalid station name. Please check.", myXml, xNav));
                }

                if (DBScheduleEngine.IsFoundScheduleByTargetID(StationNameStr, TargetIDStr))
                {
                    StationHandler StationHandle = AstroData.GetStationObject(ThisStation);
                    StationHandle.CancelScript(TargetIDStr);

                    return(HostingHelper.ReturnSuccess(ThisStation, "OK", myXml, xNav));
                }
                else
                {
                    return(HostingHelper.ReturnError("There are no TargetID in Database.", myXml, xNav));
                }

                /*
                 * TTCSCommandDisplay[] ListOfDisplayCommand = CommandDefinition.GetListCommandName(ThisStation, ThisDeviceCategory).ToArray();
                 * if (ListOfDisplayCommand != null)
                 * {
                 *  var json = new JavaScriptSerializer().Serialize(ListOfDisplayCommand);
                 *  return new HttpResponseMessage() { Content = new StringContent(json, Encoding.UTF8, "application/json") };
                 * }
                 * else
                 *  return HostingHelper.ReturnError("There are no set command avaliable on this stationName and DeviceName.", myXml, xNav);
                 */
            }
            else
            {
                return(HostingHelper.ReturnError("Session is timeout. Please login to the system.", myXml, xNav));
            }
        }
Пример #4
0
        public Boolean AddDelayDeviceData(STATIONNAME StationName, String ScriptsJSON)
        {
            Task DelayTask = Task.Run(() =>
            {
                if (ScriptsJSON == null)
                {
                    return;
                }

                if (ScriptsJSON[0] != '[' && ScriptsJSON['1'] != '{')
                {
                    ScriptsJSON = StringCompression.DecompressString(ScriptsJSON);
                }

                DataPacket[] Datas = (DataPacket[])Newtonsoft.Json.JsonConvert.DeserializeObject(ScriptsJSON, typeof(DataPacket[]));

                Console.WriteLine("AddDelayDeviceData - " + StationName.ToString() + " (" + Datas[0].DataId + ") - Packet: " + Datas.Count() + " Rows");

                StationHandler StationCommunication = AstroData.GetStationObject(StationName);

                //StationCommunication.ReceivedInformation(Datas, out Msg);

                foreach (DataPacket Data in Datas)
                {
                    if (Data.DeviceCategory == DEVICECATEGORY.CCTV)
                    {
                        if (Data.FieldName.ToString() != CCTV.CCTV_CONNECTED.ToString())
                        {
                            Data.Value = Convert.ToBase64String(((JArray)Data.Value).ToObject <byte[]>());
                        }
                    }
                    else if (Data.DeviceCategory == DEVICECATEGORY.ALLSKY)
                    {
                        //Console.WriteLine(Data.Value);

                        if (Data.FieldName.ToString() == ALLSKY.ALLSKY_IMAGE.ToString())
                        {
                            if (typeof(JArray).Equals(Data.Value.GetType()))
                            {
                                Data.Value = Convert.ToBase64String(((JArray)Data.Value).ToObject <byte[]>());
                            }
                            else if (Data.Value.ToString() == "System.Byte[]")
                            {
                                Data.Value = null;
                            }
                            else
                            {
                                Data.Value = Convert.ToBase64String((byte[])Data.Value);
                            }
                        }
                    }
                    else if (Data.DeviceCategory == DEVICECATEGORY.IMAGING)
                    {
                        //Console.WriteLine(Data.FieldName);

                        if (Data.FieldName.ToString() == IMAGING.IMAGING_CCD_DOWNLOAD_STATUS.ToString())
                        {
                            String[] TempValue = Data.Value.ToString().Split(';');

                            if (TempValue.Count() > 1)
                            {
                                if (TempValue[0] == "Completed")
                                {
                                    //   /files/AIRFORCE/FITS/maIeayp9iEO57G9LXZVPA_TakenFromClient.FITS

                                    String[] TmpFileName = TempValue[1].Split('/');
                                    String FileName      = TmpFileName[(TmpFileName.Count() - 1)];
                                    String[] TempBlockID = FileName.Split('_');
                                    String TargetID      = TempBlockID[0];
                                    String BlockID       = TempBlockID[1];

                                    DBScheduleEngine.InsertFITSData(TargetID, BlockID, StationName, FileName, Data.DateTimeUTC, DateTime.UtcNow.Ticks);
                                }
                            }
                        }
                    }

                    DBScheduleEngine.InsertData(Data.DataId, StationName, Data.DeviceCategory, Data.DeviceName, Data.FieldName, Data.Value, Data.DateTimeUTC);
                }
            });

            return(true);
        }
Пример #5
0
        public void AddDeviceData(STATIONNAME StationName, String ScriptsJSON, Boolean IsInsertDB = true, Boolean IsSentWebSocket = true)
        {
            //Console.WriteLine(StationName);
            Task DeviceTask = Task.Run(() =>
            {
                if (ScriptsJSON == null)
                {
                    return;
                }

                if (ScriptsJSON[0] != '[' && ScriptsJSON['1'] != '{')
                {
                    ScriptsJSON = StringCompression.DecompressString(ScriptsJSON);
                }

                if (ScriptsJSON == null)
                {
                    return;
                }


                //Console.WriteLine("AddDeviceData - " + StationName.ToString() + " (" + Datas[0].DataId + ") - Packet: " + Datas.Count() + " Rows");
                DataPacket[] Datas = (DataPacket[])Newtonsoft.Json.JsonConvert.DeserializeObject(ScriptsJSON, typeof(DataPacket[]));

                StationHandler StationCommunication = AstroData.GetStationObject(StationName);

                foreach (DataPacket Data in Datas)
                {
                    //if (Data.FieldName == "IMAGING_FILTER_FILTERPOSITION")
                    //{
                    //    Console.WriteLine(Data.Value);
                    //}

                    if (Data.DeviceCategory == DEVICECATEGORY.CCTV)
                    {
                        //Console.WriteLine(Data.Value);

                        if (Data.FieldName.ToString() == CCTV.CCTV_DEVICE1_IMAGE.ToString() || Data.FieldName.ToString() == CCTV.CCTV_DEVICE2_IMAGE.ToString())
                        {
                            Data.Value = Convert.ToBase64String(((JArray)Data.Value).ToObject <byte[]>());
                        }
                    }
                    else if (Data.DeviceCategory == DEVICECATEGORY.ALLSKY)
                    {
                        if (Data.FieldName.ToString() == ALLSKY.ALLSKY_IMAGE.ToString())
                        {
                            //Console.WriteLine("RECEIVED ALLSKY: " + IsSentWebSocket);

                            if (typeof(JArray).Equals(Data.Value.GetType()))
                            {
                                Data.Value = Convert.ToBase64String(((JArray)Data.Value).ToObject <byte[]>());
                            }
                        }
                    }
                    else if (Data.DeviceCategory == DEVICECATEGORY.IMAGING)
                    {
                        //Console.WriteLine(Data.FieldName);

                        if (Data.FieldName.ToString() == IMAGING.IMAGING_CCD_DOWNLOAD_STATUS.ToString())
                        {
                            String[] TempValue = Data.Value.ToString().Split(';');

                            if (TempValue.Count() > 1)
                            {
                                if (TempValue[0] == "Completed")
                                {
                                    //   BlockID#/files/AIRFORCE/FITS/maIeayp9iEO57G9LXZVPA_TakenFromClient.FITS
                                    String[] PreFileName = TempValue[1].Split('#');

                                    if (PreFileName.Count() > 1)
                                    {
                                        String BlockID = PreFileName[0];

                                        String[] TmpFileName  = PreFileName[1].Split('/');
                                        String FileName       = TmpFileName[(TmpFileName.Count() - 1)] + ".FITS";
                                        String[] TempTargetID = FileName.Split('_');
                                        String TargetID       = TempTargetID[0];

                                        DBScheduleEngine.InsertFITSData(TargetID, BlockID, StationName, FileName, Data.DateTimeUTC, DateTime.UtcNow.Ticks);
                                    }

                                    Data.Value = "Completed";
                                }
                            }
                        }
                        else if (Data.FieldName.ToString() == IMAGING.IMAGING_PREVIEW_DOWNLOAD_STATUS.ToString())
                        {
                            AstroData.LoadPerviewImage(StationName, Data.DeviceName, StationCommunication);
                        }

                        //AstroData.NewIMAGINGInformationHandle(StationName, Data.DeviceName, Data.FieldName, Data.Value, new DateTime(Data.DateTimeUTC));
                    }

                    if (IsInsertDB)
                    {
                        DBScheduleEngine.InsertData(Data.DataId, StationName, Data.DeviceCategory, Data.DeviceName, Data.FieldName, Data.Value, Data.DateTimeUTC);
                    }

                    if (IsSentWebSocket)
                    {
                        WebSockets.ReturnWebSubscribe(StationName, Data.DeviceName, Data.FieldName.ToString(), Data.Value, new DateTime(Data.DateTimeUTC));
                    }

                    AstroData.UpdateInformation(StationName, Data.DeviceName, Data.FieldName, Data.Value, new DateTime(Data.DateTimeUTC));
                }
            });
        }
Пример #6
0
        public MainWindows()
        {
            DBEngine.ConnectDB();
            DBScheduleEngine.ConnectDB();
            DBQueueEngine.ConnectDB();

            InitializeComponent();
            InitializeInterface();
            InitializeServer();
            InitializeWebService();
            InitializeSetCommand();
            InitializeWS();


            Task TaskPost = Task.Run(async() =>
            {
                while (true)
                {
                    IQueryable <AstroQueueImpl> IAstroQueues = DBQueueEngine.Find(QUEUE_STATUS.WAITINGSERVER, SENDING_STATUS.IDLE);

                    if (IAstroQueues.Count() > 0)
                    {
                        Dictionary <STATIONNAME, List <AstroQueueImpl> > dictionaryGroup = new Dictionary <STATIONNAME, List <AstroQueueImpl> >();

                        List <AstroQueueImpl> astroQueues = IAstroQueues.ToList();

                        foreach (AstroQueueImpl astroQueue in astroQueues)
                        {
                            if (!dictionaryGroup.ContainsKey(astroQueue.Target.StationName))
                            {
                                dictionaryGroup.Add(astroQueue.Target.StationName, new List <AstroQueueImpl>());
                            }

                            dictionaryGroup[astroQueue.Target.StationName].Add(astroQueue);
                        }

                        if (dictionaryGroup.Count() > 0)
                        {
                            foreach (KeyValuePair <STATIONNAME, List <AstroQueueImpl> > groupAstroQueues in dictionaryGroup)
                            {
                                StationHandler StationCommunication = AstroData.GetStationObject(groupAstroQueues.Key);

                                if (StationCommunication != null)
                                {
                                    StationCommunication.SendingNewTarget(groupAstroQueues.Value);
                                }
                            }
                        }
                    }


                    /*
                     * StationHandler StationCommunication = AstroData.GetStationObject(astroQueue.Target.StationName);
                     *
                     * if (StationCommunication != null)
                     * {
                     *  StationCommunication.SendingNewTarget(astroQueue);
                     * }
                     */

                    await Task.Delay(1000);
                }
            });

            /*
             * QueueStatus astroQueues2 = DBQueueEngine.FindLastestStatus(STATIONNAME.ASTROPARK, "5a4db62e30932557d4ba7445");
             * Console.WriteLine(astroQueues2);
             */
        }