Esempio n. 1
0
 public void StopReportingAfterDaysValid()
 {
     Settings.StopReportingAfter = 99;
     new BugReport().Report(new Exception(), ExceptionThread.Main);
     Assert.Equal(1, Storer.GetReportCount());
     Storer.TruncateReportFiles(0);
 }
Esempio n. 2
0
        private void Dispatch()
        {
            // Make sure that we are not interfering with the crucial startup work);
            if (!Settings.RemoveThreadSleep)
            {
                Thread.Sleep(Settings.SleepBeforeSend * 1000);
            }

            // Turncate extra report files and try to send the first one in the queue
            Storer.TruncateReportFiles();

            // Now go through configured destinations and submit to all automatically
            for (var hasReport = true; hasReport;)
            {
                using (var storer = new Storer())
                    using (var stream = storer.GetFirstReportFile())
                    {
                        if (stream != null)
                        {
                            var exceptionData = this.GetDataFromZip(stream);
                            if (this.EnumerateDestinations(stream, exceptionData) == false)
                            {
                                break;
                            }

                            // Delete the file after it was sent
                            storer.DeleteCurrentReportFile();
                        }
                        else
                        {
                            hasReport = false;
                        }
                    }
            }
        }
 internal void VerifyAndDeleteCompressedReportFile(bool verifyCustomReport)
 {
     using (var storer = new Storer())
         using (var stream = storer.GetFirstReportFile())
         {
             Assert.NotNull(stream);
             this.VerifyIndividualReportItems(stream, verifyCustomReport);
             storer.DeleteCurrentReportFile();
         }
 }
    static void Main(string[] args)
    {
        int intBorder = 1900;
        int intN      = int.Parse(Console.ReadLine());

        for (int i = 0; i < intBorder; i++)
        {
            Storer.Store(Console.ReadLine().Split());
        }
    }
 internal void DeleteGarbageReportFile()
 {
     using (var storer = new Storer())
         using (var stream = storer.GetFirstReportFile())
         {
             if (stream != null)
             {
                 storer.DeleteCurrentReportFile();
             }
         }
 }
Esempio n. 6
0
        public void MaxQueuedReports()
        {
            Settings.MaxQueuedReports = 2;
            new BugReport().Report(new Exception(), ExceptionThread.Main);
            new BugReport().Report(new Exception(), ExceptionThread.Main);
            new BugReport().Report(new Exception(), ExceptionThread.Main);

            Assert.Equal(2, Storer.GetReportCount());
            Storer.TruncateReportFiles(1);
            Assert.Equal(1, Storer.GetReportCount());
            Storer.TruncateReportFiles(0);
            Assert.Equal(0, Storer.GetReportCount());
        }
Esempio n. 7
0
        public ActionResult StoreDataXML(Person person)
        {
            var storer = new Storer(new DataStoreXML());

            if (storer.FetchFormData <Person>(person))
            {
                ViewBag.Message = "Data stored to xml";
            }
            else
            {
                ViewBag.Message = "Failed to save data to xml";
            }
            return(View("~/Views/Home/Index.cshtml"));
        }
        private void Dispatch()
        {
            // Make sure that we are not interfering with the crucial startup work);
            if (!Settings.RemoveThreadSleep)
            {
                Thread.Sleep(Settings.SleepBeforeSend * 1000);
            }

            // Truncate extra report files and try to send the first one in the queue
            Storer.TruncateReportFiles();

            // Now go through configured destinations and submit to all automatically
            for (var hasReport = true; hasReport;)
            {
                using (var storer = new Storer())
                    using (var stream = storer.GetFirstReportFile())
                    {
                        if (stream != null)
                        {
                            // Extract crash/exception report data from the zip file. Delete the zip file if no data can be retrieved (i.e. corrupt file)
                            ExceptionData exceptionData;
                            try
                            {
                                exceptionData = GetDataFromZip(stream);
                            }
                            catch (Exception exception)
                            {
                                storer.DeleteCurrentReportFile();
                                Logger.Error(
                                    "An exception occurred while extraction report data from zip file. Check the inner exception for details.",
                                    exception);
                                return;
                            }

                            // Now submit the report file to all configured bug report submission targets
                            if (EnumerateDestinations(stream, exceptionData) == false)
                            {
                                break;
                            }

                            // Delete the file after it was sent
                            storer.DeleteCurrentReportFile();
                        }
                        else
                        {
                            hasReport = false;
                        }
                    }
            }
        }
Esempio n. 9
0
        public void MiniDumpTypeTiny()
        {
            Settings.MiniDumpType = MiniDumpType.Tiny;
            new BugReport().Report(new Exception(), ExceptionThread.Main);
            Assert.Equal(Storer.GetReportCount(), 1);

            using (var storer = new Storer())
                using (var stream = storer.GetFirstReportFile())
                {
                    Assert.NotNull(stream);
                    Assert.InRange(stream.Length, 10 * 1024, 1 * 1024 * 1024);
                    storer.DeleteCurrentReportFile();
                }

            Assert.Equal(Storer.GetReportCount(), 0);
        }
Esempio n. 10
0
        public void StoragePathWindowsTemp()
        {
            Settings.StoragePath = StoragePath.WindowsTemp;
            new BugReport().Report(new Exception(), ExceptionThread.Main);
            Assert.Equal(Storer.GetReportCount(), 1);

            using (var storer = new Storer())
                using (var stream = storer.GetFirstReportFile())
                {
                    Assert.NotNull(stream);
                    Assert.True(storer.FilePath.Contains(Path.Combine(new[] { Path.GetTempPath(), Settings.EntryAssembly.GetName().Name })));
                    storer.DeleteCurrentReportFile();
                }

            Assert.Equal(Storer.GetReportCount(), 0);
        }
Esempio n. 11
0
        public void StoragePathCustom()
        {
            Settings.StoragePath = "C:\\";
            new BugReport().Report(new Exception(), ExceptionThread.Main);
            Assert.Equal(Storer.GetReportCount(), 1);

            using (var storer = new Storer())
                using (var stream = storer.GetFirstReportFile())
                {
                    Assert.NotNull(stream);
                    Assert.True(storer.FilePath.Contains("C:\\"));
                    storer.DeleteCurrentReportFile();
                }

            Assert.Equal(Storer.GetReportCount(), 0);
        }
Esempio n. 12
0
        public void StoragePathCurrentDirectory()
        {
            Settings.StoragePath = StoragePath.CurrentDirectory;
            new BugReport().Report(new Exception(), ExceptionThread.Main);
            Assert.Equal(Storer.GetReportCount(), 1);

            using (var storer = new Storer())
                using (var stream = storer.GetFirstReportFile())
                {
                    Assert.NotNull(stream);
                    Assert.True(storer.FilePath.Contains(Path.GetDirectoryName(Settings.EntryAssembly.Location)));
                    storer.DeleteCurrentReportFile();
                }

            Assert.Equal(Storer.GetReportCount(), 0);
        }
Esempio n. 13
0
        public void StoragePathIsolatedStorage()
        {
            Settings.StoragePath = StoragePath.IsolatedStorage;
            new BugReport().Report(new Exception(), ExceptionThread.Main);
            Assert.Equal(Storer.GetReportCount(), 1);

            using (var storer = new Storer())
                using (var stream = storer.GetFirstReportFile())
                {
                    Assert.NotNull(stream);
                    var filePath = stream.GetType().GetField("m_FullPath", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(stream).ToString();
                    Assert.True(filePath.Contains("IsolatedStorage"));
                    storer.DeleteCurrentReportFile();
                }

            Assert.Equal(Storer.GetReportCount(), 0);
        }
        public void MixedDestinations()
        {
            Settings.AddDestinationFromConnectionString(this.settings.ReadCustomDispatcherDestinationSettings(typeof(Mail).Name)[0]);
            Settings.AddDestinationFromConnectionString(this.settings.ReadCustomDispatcherDestinationSettings(typeof(Http).Name)[0]);
            Settings.AddDestinationFromConnectionString(this.settings.ReadCustomDispatcherDestinationSettings(typeof(Ftp).Name)[0]);
            Settings.AddDestinationFromConnectionString(this.settings.ReadCustomDispatcherDestinationSettings(typeof(Redmine).Name)[0]);

            // ToDo: Settings.Destination5 = this.settings.ReadCustomDispatcherDestinationSettings(Protocols.Trac)[0];
            try
            {
                throw new DummyArgumentException();
            }
            catch (Exception exception)
            {
                Trace.WriteLine("Submitting bug report to 5 different destinations at once: Mail, HTTP, FTP, Redmine, Trac");
                new BugReport().Report(exception, ExceptionThread.Main);
                Assert.Equal(1, Storer.GetReportCount());
                new Dispatcher(false);                 // Dispatch async = false;
                Assert.Equal(0, Storer.GetReportCount());
            }
        }
        public void RedmineDispatcher()
        {
            var destinations = this.settings.ReadCustomDispatcherDestinationSettings(typeof(Redmine).Name);

            foreach (var destination in destinations)
            {
                Settings.Destinations.Clear();
                Settings.AddDestinationFromConnectionString(destination);
                try
                {
                    throw new DummyArgumentException();
                }
                catch (Exception exception)
                {
                    Trace.WriteLine("Submitting bug report to Redmine issue tracker with connection string: " + destination);
                    new BugReport().Report(exception, ExceptionThread.Main);
                    Assert.Equal(1, Storer.GetReportCount());
                    new Dispatcher(false);                     // Dispatch async = false;
                    Assert.Equal(0, Storer.GetReportCount());
                }
            }

            Trace.WriteLine("Redmine submissions: " + destinations.Count);
        }
        public void HttpDispatcher()
        {
            var destinations = this.settings.ReadCustomDispatcherDestinationSettings(typeof(Http).Name);

            foreach (var destination in destinations)
            {
                Settings.Destinations.Clear();
                Settings.AddDestinationFromConnectionString(destination);
                try
                {
                    throw new DummyArgumentException();
                }
                catch (Exception exception)
                {
                    Trace.WriteLine("Uploading report using HTTP with connection string: " + destination);
                    new BugReport().Report(exception, ExceptionThread.Main);
                    Assert.Equal(1, Storer.GetReportCount());
                    new Dispatcher(false);                     // Dispatch async = false;
                    Assert.Equal(0, Storer.GetReportCount());
                }
            }

            Trace.WriteLine("HTTP uploads: " + destinations.Count);
        }
Esempio n. 17
0
        protected Crawler(IDocumentFactory documentFactory, IKeyValueStore <string, Result> store, IKeyValueStore <string, FetchTarget> frontier)
        {
            _store    = store;
            _frontier = frontier;

            var fetcherOptions = new FetcherOptions
            {
                UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.62 Safari/537.36",
            };

            var parserOptions = new ParserOptions
            {
            };

            var scraperOptions = new ScraperOptions
            {
            };

            var extractorOptions = new ExtractorOptions
            {
            };

            //var storerOptions = new StorerOptions
            //{
            //};

            var builderOptions = new BuilderOptions
            {
            };

            var providerOptions = new ProviderOptions
            {
            };

            //var dispatcherOptions = new DispatcherOptions
            //{
            //};


            Fetcher    = new Fetcher(fetcherOptions);
            Parser     = new Parser(parserOptions, documentFactory);
            Scraper    = new Scraper(scraperOptions);
            Extractor  = new Extractor(extractorOptions);
            Storer     = new Storer(store);
            Builder    = new Builder(builderOptions);
            Provider   = new Provider(providerOptions, store, frontier);
            Dispatcher = new Dispatcher();

            Fetcher.SendTo(Parser, x => x.StatusCode == System.Net.HttpStatusCode.OK);

            Parser.SendTo(Scraper);
            Parser.SendTo(Extractor);

            Fetcher.SendTo(Builder, x => x.StatusCode == System.Net.HttpStatusCode.OK);
            Scraper.SendTo(Builder);
            Extractor.SendTo(Builder);

            Builder.SendTo(Storer);

            //Storer.LinkTo(new ActionBlock<Result>(x =>
            //{
            //}));

            Builder.SendTo(Provider);
            Provider.SendTo(Dispatcher, x => x != null);
            Dispatcher.SendTo(Fetcher);
        }
Esempio n. 18
0
        protected Crawler(IDocumentFactory documentFactory, IKeyValueStore<string, Result> store, IKeyValueStore<string, FetchTarget> frontier)
        {
            _store = store;
            _frontier = frontier;

            var fetcherOptions = new FetcherOptions
            {
                UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.62 Safari/537.36",
            };

            var parserOptions = new ParserOptions
            {
            };

            var scraperOptions = new ScraperOptions
            {
            };

            var extractorOptions = new ExtractorOptions
            {
            };

            //var storerOptions = new StorerOptions
            //{
            //};

            var builderOptions = new BuilderOptions
            {
            };

            var providerOptions = new ProviderOptions
            {
            };

            //var dispatcherOptions = new DispatcherOptions
            //{
            //};

            Fetcher = new Fetcher(fetcherOptions);
            Parser = new Parser(parserOptions, documentFactory);
            Scraper = new Scraper(scraperOptions);
            Extractor = new Extractor(extractorOptions);
            Storer = new Storer(store);
            Builder = new Builder(builderOptions);
            Provider = new Provider(providerOptions, store, frontier);
            Dispatcher = new Dispatcher();

            Fetcher.SendTo(Parser, x => x.StatusCode == System.Net.HttpStatusCode.OK);

            Parser.SendTo(Scraper);
            Parser.SendTo(Extractor);

            Fetcher.SendTo(Builder, x => x.StatusCode == System.Net.HttpStatusCode.OK);
            Scraper.SendTo(Builder);
            Extractor.SendTo(Builder);

            Builder.SendTo(Storer);

            //Storer.LinkTo(new ActionBlock<Result>(x =>
            //{
            //}));

            Builder.SendTo(Provider);
            Provider.SendTo(Dispatcher, x => x != null);
            Dispatcher.SendTo(Fetcher);
        }
Esempio n. 19
0
 public void StopReportingAfterDaysExpired()
 {
     Settings.StopReportingAfter = 0;
     new BugReport().Report(new Exception(), ExceptionThread.Main);
     Assert.Equal(0, Storer.GetReportCount());
 }
Esempio n. 20
0
        private void CreateReportZip(SerializableException serializableException, Report report)
        {
            // Test if it has NOT been more than x many days since entry assembly was last modified)
            if (Settings.StopReportingAfter < 0 ||
                File.GetLastWriteTime(Settings.EntryAssembly.Location).AddDays(Settings.StopReportingAfter).CompareTo(DateTime.Now) > 0)
            {
                // Test if there is already more than enough queued report files
                if (Settings.MaxQueuedReports < 0 || Storer.GetReportCount() < Settings.MaxQueuedReports)
                {
                    var reportFileName   = "Exception_" + DateTime.UtcNow.ToFileTime() + ".zip";
                    var minidumpFilePath = Path.Combine(
                        Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Exception_MiniDump_" + DateTime.UtcNow.ToFileTime() + ".mdmp");

                    using (var storer = new Storer())
                        using (var zipStorer = ZipStorer.Create(storer.CreateReportFile(reportFileName), string.Empty))
                            using (var stream = new MemoryStream())
                            {
                                // Store the exception
                                var serializer = new XmlSerializer(typeof(SerializableException));
                                serializer.Serialize(stream, serializableException);
                                stream.Position = 0;
                                zipStorer.AddStream(ZipStorer.Compression.Deflate, StoredItemFile.Exception, stream, DateTime.UtcNow, string.Empty);

                                // Store the report
                                stream.SetLength(0);

                                try
                                {
                                    serializer = report.CustomInfo != null
                                                                             ? new XmlSerializer(typeof(Report), new[] { report.CustomInfo.GetType() })
                                                                             : new XmlSerializer(typeof(Report));

                                    serializer.Serialize(stream, report);
                                }
                                catch (Exception exception)
                                {
                                    Logger.Error(
                                        string.Format(
                                            "The given custom info of type [{0}] cannot be serialized. Make sure that given type and inner types are XML serializable.",
                                            report.CustomInfo.GetType()),
                                        exception);
                                    report.CustomInfo = null;
                                    serializer        = new XmlSerializer(typeof(Report));
                                    serializer.Serialize(stream, report);
                                }

                                stream.Position = 0;
                                zipStorer.AddStream(ZipStorer.Compression.Deflate, StoredItemFile.Report, stream, DateTime.UtcNow, string.Empty);

                                // Add the memory minidump to the report file (only if configured so)
                                if (DumpWriter.Write(minidumpFilePath))
                                {
                                    zipStorer.AddFile(ZipStorer.Compression.Deflate, minidumpFilePath, StoredItemFile.MiniDump, string.Empty);
                                    File.Delete(minidumpFilePath);
                                }

                                // Add any user supplied files in the report (if any)
                                if (Settings.AdditionalReportFiles.Count != 0)
                                {
                                    // ToDo: This needs a lot more work!
                                    this.AddAdditionalFiles(zipStorer);
                                }
                            }

                    Logger.Trace("Created a new report file. Currently the number of report files queued to be send is: " + Storer.GetReportCount());
                }
                else
                {
                    Logger.Trace(
                        "Current report count is at its limit as per 'Settings.MaxQueuedReports (" + Settings.MaxQueuedReports
                        + ")' setting: Skipping bug report generation.");
                }
            }
            else
            {
                Logger.Trace(
                    "As per setting 'Settings.StopReportingAfter(" + Settings.StopReportingAfter
                    + ")', bug reporting feature was enabled for a certain amount of time which has now expired: Bug reporting is now disabled.");

                // ToDo: Completely eliminate this with SettingsOverride.DisableReporting = true; since enumerating filesystem adds overhead);
                if (Storer.GetReportCount() > 0)
                {
                    Logger.Trace(
                        "As per setting 'Settings.StopReportingAfter(" + Settings.StopReportingAfter
                        + ")', bug reporting feature was enabled for a certain amount of time which has now expired: Truncating all expired bug reports.");
                    Storer.TruncateReportFiles(0);
                }
            }
        }