Exemplo n.º 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);
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
 }
Exemplo n.º 4
0
 static void ReadUpdate(SenderConfiguration sender, string value)
 {
     sender.Update = value;
 }
Exemplo n.º 5
0
 static void ReadMiniDumpServiceUrl(SenderConfiguration sender, string value)
 {
     sender.MiniDumpServiceUrl = value;
 }
Exemplo n.º 6
0
 static void ReadMiniDumpFileName(SenderConfiguration sender, string value)
 {
     sender.MiniDumpFileName = value;
 }
Exemplo n.º 7
0
 static void ReadMiniDumpGuid(SenderConfiguration sender, string value)
 {
     sender.MiniDumpGuid = value;
 }
Exemplo n.º 8
0
 static void ReadDeleteConfigFile(SenderConfiguration sender, string value)
 {
     sender.DeleteConfigFile = value;
 }
Exemplo n.º 9
0
 static void ReadReportFileName(SenderConfiguration sender, string value)
 {
     sender.ReportFileName = value;
 }
Exemplo n.º 10
0
 static void ReadApiKey(SenderConfiguration sender, string value)
 {
     sender.ApiKey = value;
 }
Exemplo n.º 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);
        }