public HorizonCheck Get(String key, int year, int month, int day, int hour, int minute, float targetRA, float targetDec) { if (key != null && key.Equals(AstroAPIKey.getKey())) { // altitude of the telescope is at 390 feet above sea level, find this in the configs DrawSky.Easel easel = GenerateImage(year, month, day, hour, minute, -76.704564F, 40.024409F, 390, targetRA, targetDec); HorizonCheck HC = new HorizonCheck(); HC.azimuth = easel.azimuth; HC.elevation = easel.elevation; HC.visible = easel.elevation > 0; return(HC); } else { HorizonCheck HC = new HorizonCheck(); HC.azimuth = 0; HC.elevation = 0; HC.visible = false; return(HC); } }
public static SkyView GenerateImage(String key, int year, int month, int day, int hour, int minute, float longitude, float laditude, int altitude, float targetRA, float targetDec) { Console.WriteLine(year + ", " + month + ", " + day + ", " + hour); SkyView view = new SkyView(); if (key != null && key.Equals(AstroAPIKey.getKey())) { int WIDTH = 720; int HEIGHT = 180; DrawSky.Easel easel = new DrawSky.Easel(new System.Drawing.Size(WIDTH, HEIGHT)); easel.dt = new DateTime(year, month, day, hour, minute, 0); easel.longitude = longitude; easel.latitude = laditude; easel.altitude = altitude; easel.targetRA = targetRA; easel.targetDec = targetDec; easel.coordinates = false; easel.MakeNewEasel(); String filename = "skyview-" + year + "-" + month + "-" + day + "-" + hour + "-" + minute + "-" + (int)longitude + "-" + (int)laditude + "-" + altitude + "-" + (int)targetRA + "-" + (int)targetDec + ".png"; Image image = easel.sky; view.filepath = filename; view.view = image; view.bitmap_view = (Bitmap)image; var stream = new System.IO.MemoryStream(); view.bitmap_view.Save(stream, ImageFormat.Bmp); view.bytes = stream.ToArray(); return(view); } else { view.filepath = "Secret Key Missing, image was not created."; return(view); } }
public String Get(String key, String command) { String responseData = ""; if (key != null && key.Equals(AstroAPIKey.getKey())) { try { // Create a TcpClient. // Note, for this client to work you need to have a TcpServer // connected to the same address as specified by the server, port // combination. Int32 port = 3333; TcpClient client = new TcpClient(AstroAPIKey.getIP(), port); // Hosted Middleman // TcpClient client = new TcpClient("localhost", port); // Localhost testing // Translate the passed message into ASCII and store it as a Byte array. Byte[] data = System.Text.Encoding.ASCII.GetBytes(command); // Get a client stream for reading and writing. // Stream stream = client.GetStream(); NetworkStream stream = client.GetStream(); // Send the message to the connected TcpServer. stream.Write(data, 0, data.Length); Console.WriteLine("Sent: {0}", command); // Receive the TcpServer.response. // Buffer to store the response bytes. data = new Byte[256]; // String to store the response ASCII representation. responseData = String.Empty; // Read the first batch of the TcpServer response bytes. Int32 bytes = stream.Read(data, 0, data.Length); responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes); Console.WriteLine("Received: {0}", responseData); // Close everything. stream.Close(); client.Close(); } catch (ArgumentNullException e) { Console.WriteLine("ArgumentNullException: {0}", e); responseData = "ArgumentNullException: " + e; } catch (SocketException e) { Console.WriteLine("SocketException: {0}", e); responseData = "SocketException: " + e; } } else { responseData = "Secret key missing."; } return(responseData); }