Example #1
0
        SenderConfiguration LoadConfiguration(string fileName)
        {
            Console.WriteLine("Loading configuration from file '" + fileName + "'");
            string[]            lines  = File.ReadAllLines(fileName);
            SenderConfiguration result = new SenderConfiguration();

            foreach (string line in lines)
            {
                ProcessConfigLine(line, result);
            }
            return(result);
        }
Example #2
0
        void ProcessConfigLine(string line, SenderConfiguration result)
        {
            if (String.IsNullOrEmpty(line))
            {
                return;
            }
            string[] parts = line.Split('=');
            if (parts == null || parts.Length != 2)
            {
                return;
            }

            string parameterName = parts[0].Trim();
            Action <SenderConfiguration, string> handler;

            if (configHandlers.TryGetValue(parameterName, out handler))
            {
                string value = parts[1].Trim();
                handler(result, value);
            }
        }
Example #3
0
 bool ValidateConfiguration(SenderConfiguration config)
 {
     if (String.IsNullOrEmpty(config.Url))
     {
         Console.WriteLine("ERROR: service Url not specified");
         return(false);
     }
     if (String.IsNullOrEmpty(config.ApiKey))
     {
         Console.WriteLine("ERROR: ApiKey not specified");
         return(false);
     }
     if (String.IsNullOrEmpty(config.ReportFileName))
     {
         Console.WriteLine("ERROR: ReportFileName not specified");
         return(false);
     }
     if (!File.Exists(config.ReportFileName))
     {
         Console.WriteLine("ERROR: file '" + config.ReportFileName + "' not found");
         return(false);
     }
     return(true);
 }
Example #4
0
 static void ReadUpdate(SenderConfiguration sender, string value)
 {
     sender.Update = value;
 }
Example #5
0
 static void ReadMiniDumpServiceUrl(SenderConfiguration sender, string value)
 {
     sender.MiniDumpServiceUrl = value;
 }
Example #6
0
 static void ReadMiniDumpFileName(SenderConfiguration sender, string value)
 {
     sender.MiniDumpFileName = value;
 }
Example #7
0
 static void ReadMiniDumpGuid(SenderConfiguration sender, string value)
 {
     sender.MiniDumpGuid = value;
 }
Example #8
0
 static void ReadDeleteConfigFile(SenderConfiguration sender, string value)
 {
     sender.DeleteConfigFile = value;
 }
Example #9
0
 static void ReadReportFileName(SenderConfiguration sender, string value)
 {
     sender.ReportFileName = value;
 }
Example #10
0
 static void ReadApiKey(SenderConfiguration sender, string value)
 {
     sender.ApiKey = value;
 }
Example #11
0
        public int SendReport(string configFileName)
        {
            if (!File.Exists(configFileName))
            {
                Console.WriteLine("file '" + configFileName + "' not found.");
                return(2);
            }


            SenderConfiguration config = LoadConfiguration(configFileName);

            if (!ValidateConfiguration(config))
            {
                return(2);
            }

            Console.WriteLine("Configuration:");
            Console.WriteLine("ServiceUrl=" + config.Url);
            Console.WriteLine("ApiKey=" + config.ApiKey);
            Console.WriteLine("ReportFileName=" + config.ReportFileName);
            Console.WriteLine("MiniDumpGuid=" + config.MiniDumpGuid);
            Console.WriteLine("MiniDumpFileName=" + config.MiniDumpFileName);
            Console.WriteLine("MiniDumpServiceUrl=" + config.MiniDumpServiceUrl);

            InnerExceptionReportSender sender = new InnerExceptionReportSender();

            sender.ServiceUrl = config.Url;
            sender.ApiKey     = config.ApiKey;
            string report = File.ReadAllText(config.ReportFileName, Encoding.UTF8);

            Console.WriteLine("Sending report...");
            if (!String.IsNullOrEmpty(config.MiniDumpGuid) && !String.IsNullOrEmpty(config.MiniDumpFileName))
            {
                sender.SendExceptionReport(report);
                //TODO:
                //AM: use send protocol with confirmation, to avoid duplicate minidump send
                //AM: send minidump, if report is not dup
                MiniDumpSender dumpSender = new MiniDumpSender(config.MiniDumpServiceUrl);
                dumpSender.UploadWithConfirmation(config.ApiKey, config.MiniDumpGuid, config.MiniDumpFileName);
            }
            else
            {
                sender.SendExceptionReport(report);
            }
            if (!String.IsNullOrEmpty(config.DeleteReportFile) && !String.IsNullOrEmpty(config.DeleteReportFile.Trim()))
            {
                try {
                    File.Delete(config.ReportFileName);
                }
                catch {
                }
            }
            if (!String.IsNullOrEmpty(config.DeleteConfigFile) && !String.IsNullOrEmpty(config.DeleteConfigFile.Trim()))
            {
                try {
                    File.Delete(configFileName);
                }
                catch {
                }
            }
            if (!String.IsNullOrEmpty(config.MiniDumpFileName) && File.Exists(config.MiniDumpFileName.Trim()))
            {
                try {
                    File.Delete(config.MiniDumpFileName.Trim());
                }
                catch {
                }
            }
            Console.WriteLine("Complete.");

            if (!String.IsNullOrEmpty(config.Update))
            {
                try {
                    Console.WriteLine("Updating client...");
                    AutoUpdater updater = new AutoUpdater();
                    updater.Run(config.ApiKey);
                    Console.WriteLine("Complete.");
                }
                catch {
                }
            }

            return(0);
        }