public static void LoadPerviewImage(STATIONNAME StationName, DEVICENAME DeviceName, StationHandler ExistingStation) { Task PreviewTask = Task.Run(async() => { if (Client == null) { Client = new FtpClient("192.168.2.217"); Client.Credentials = new NetworkCredential("astronetbot", "P@ssw0rd"); Client.ConnectTimeout = 1000; } if (!Client.IsConnected) { Client.Connect(); } String FilePath = "/files/" + StationName.ToString() + "/PreviewImg.jpg"; if (Client.FileExists(@FilePath)) { await Client.DownloadFileAsync(@"/TEMP/" + StationName.ToString() + "_PreviewImg.jpg", FilePath); Bitmap tmpBitmap = (Bitmap)Bitmap.FromFile(@"/TEMP/" + StationName.ToString() + "_PreviewImg.jpg"); Image Image = (Image)tmpBitmap; using (MemoryStream m = new MemoryStream()) { Image.Save(m, Image.RawFormat); byte[] imageBytes = m.ToArray(); //ExistingStation.NewIMAGINGInformation(DeviceName, IMAGING.IMAGING_PREVIEW_BASE64, imageBytes, DateTime.UtcNow); //ExistingStation.NewIMAGINGInformation(DeviceName, IMAGING.IMAGING_PREVIEW_READY, true, DateTime.UtcNow); AstroData.UpdateInformation(StationName, DeviceName, IMAGING.IMAGING_PREVIEW_BASE64.ToString(), Convert.ToBase64String(imageBytes), DateTime.UtcNow); AstroData.UpdateInformation(StationName, DeviceName, IMAGING.IMAGING_PREVIEW_READY.ToString(), true, DateTime.UtcNow); } //streamReader.Close(); } else { await Task.Delay(1000); LoadPerviewImage(StationName, DeviceName, ExistingStation); } /* * String GetPath = ""; * switch (StationName) * { * case STATIONNAME.AIRFORCE: GetPath = @"c:\FTP\AF\PreviewImg.jpg"; break; * case STATIONNAME.ASTROPARK: GetPath = @"c:\FTP\ASP\PreviewImg.jpg"; break; * case STATIONNAME.CHACHOENGSAO: GetPath = @"c:\FTP\CCO\PreviewImg.jpg"; break; * case STATIONNAME.NAKHONRATCHASIMA: GetPath = @"c:\FTP\NKA\PreviewImg.jpg"; break; * case STATIONNAME.CHINA: GetPath = @"c:\FTP\CHA\PreviewImg.jpg"; break; * case STATIONNAME.AUSTRALIA: GetPath = @"c:\FTP\AUS\PreviewImg.jpg"; break; * case STATIONNAME.USA: GetPath = @"c:\FTP\USA\PreviewImg.jpg"; break; * } * * if (File.Exists(GetPath)) * { * StreamReader streamReader = new StreamReader(GetPath); * Bitmap tmpBitmap = (Bitmap)Bitmap.FromStream(streamReader.BaseStream); * Image Image = (Image)tmpBitmap; * * using (MemoryStream m = new MemoryStream()) * { * Image.Save(m, Image.RawFormat); * byte[] imageBytes = m.ToArray(); * * ExistingStation.NewIMAGINGInformation(DeviceName, IMAGING.IMAGING_PREVIEW_BASE64, imageBytes, DateTime.UtcNow); * ExistingStation.NewIMAGINGInformation(DeviceName, IMAGING.IMAGING_PREVIEW_READY, true, DateTime.UtcNow); * } * * streamReader.Close(); * } * else * { * await Task.Delay(1000); * LoadPerviewImage(StationName, DeviceName, ExistingStation); * } */ }); }
public static DEVICECATEGORY ConvertDeviceNameToDeviceCategory(STATIONNAME StationName, DEVICENAME DeviceName) { return(AstroData.GetDeviceCategoryByDeviceName(StationName, DeviceName)); }