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); }
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)); } }); }