Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Net;
- using System.Text;
- public class Program
- {
- public static readonly string Name = "Dividing program";
- public static readonly string Version = "0.1";
- public static string ProgramId
- {
- get { return string.Format("{0}/{1}", Name, Version); }
- }
- public static int Main(string[] args)
- {
- float a = 0, b = 0, c = 0;
- try
- {
- Console.WriteLine(ProgramId);
- Console.WriteLine("This program divides one number by another.");
- Console.Write("Enter number 1: ");
- a = float.Parse(Console.ReadLine());
- Console.Write("Enter number 2: ");
- b = float.Parse(Console.ReadLine());
- c = a / b;
- Console.WriteLine("Number 1 divided by number 2 is {0}.", c);
- }
- catch(Exception error)
- {
- Console.WriteLine("An error has occurred!");
- Console.Write("Would you like to report it? [Y/n] ");
- bool sendReport = false;
- while(true)
- {
- ConsoleKey key = Console.ReadKey().Key;
- if (key == ConsoleKey.Y) {
- sendReport = true;
- break;
- }
- else if (key == ConsoleKey.N)
- break;
- }
- Console.WriteLine();
- if(!sendReport)
- {
- Console.WriteLine("No report has been sent.");
- Console.WriteLine("Press any key to exit.");
- Console.ReadKey(true);
- return 1;
- }
- Console.Write("Collecting data - ");
- MemoryStream dataStream = new MemoryStream();
- StreamWriter dataIn = new StreamWriter(dataStream);
- dataIn.WriteLine("***** Error Report *****");
- dataIn.WriteLine(error.ToString());
- dataIn.WriteLine();
- dataIn.WriteLine("*** Details ***");
- dataIn.WriteLine("a: {0}", a);
- dataIn.WriteLine("b: {0}", b);
- dataIn.WriteLine("c: {0}", c);
- dataIn.Flush();
- dataStream.Seek(0, SeekOrigin.Begin);
- string errorReport = new StreamReader(dataStream).ReadToEnd();
- Console.WriteLine("done");
- Console.Write("Sending report - ");
- HttpWebRequest reportSender = WebRequest.CreateHttp("https://starbeamrainbowlabs.com/reportSender.php");
- reportSender.Method = "POST";
- byte[] payload = Encoding.UTF8.GetBytes(errorReport);
- reportSender.ContentType = "text/plain";
- reportSender.ContentLength = payload.Length;
- reportSender.UserAgent = ProgramId;
- Stream requestStream = reportSender.GetRequestStream();
- requestStream.Write(payload, 0, payload.Length);
- requestStream.Close();
- WebResponse reportResponse = reportSender.GetResponse();
- Console.WriteLine("done");
- Console.WriteLine("Server response: {0}", ((HttpWebResponse)reportResponse).StatusDescription);
- Console.WriteLine("Press any key to exit.");
- Console.ReadKey(true);
- return 1;
- }
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement