Beispiel #1
0
        /// <summary>
        /// If we are able to directly submit to YouTrack, we do that. But otherwise,
        /// this makes a zip file of everything we want to submit, in order to
        /// give the user a single thing they need to attach and send.
        /// </summary>
        private void MakeEmailableReportFile()
        {
            var filename = ("Report " + DateTime.UtcNow.ToString("u") + ".zip").Replace(':', '.');

            filename = filename.SanitizeFilename('#');
            var zipFile = TempFile.WithFilename(filename);

            _emailableReportFilePath = zipFile.Path;

            var zip = new BloomZipFile(_emailableReportFilePath);

            using (var file = TempFile.WithFilenameInTempFolder("report.txt"))
            {
                using (var stream = RobustFile.CreateText(file.Path))
                {
                    stream.WriteLine(GetFullDescriptionContents(false));

                    if (_includeBook.Visible && _includeBook.Checked)                     // only Visible if Book is not null
                    {
                        stream.WriteLine();
                        stream.WriteLine(
                            "REMEMBER: if the attached zip file appears empty, it may have non-ascii in the file names. Open with 7zip and you should see it.");
                    }
                }
                zip.AddTopLevelFile(file.Path);

                if (_includeBook.Visible && _includeBook.Checked)                 // only Visible if Book is not null
                {
                    zip.AddDirectory(Book.FolderPath);
                    if (WantReaderInfo())
                    {
                        AddReaderInfo(zip);
                    }
                    AddCollectionSettings(zip);
                }
            }
            if (_includeScreenshot.Checked)
            {
                using (var file = TempFile.WithFilenameInTempFolder("screenshot.png"))
                {
                    RobustImageIO.SaveImage(_screenshot, file.Path, ImageFormat.Png);
                    zip.AddTopLevelFile(file.Path);
                }
            }
            if (Logger.Singleton != null)
            {
                try
                {
                    using (var logFile = GetLogFile())
                    {
                        zip.AddTopLevelFile(logFile.Path);
                    }
                }
                catch (Exception)
                {
                    // just ignore
                }
            }
            zip.Save();
        }
Beispiel #2
0
        public void StartMeasuring()
        {
            CurrentlyMeasuring = true;

            if (_stream != null)
            {
                _stream.Close();
                _stream.Dispose();
                // no, leave it and its contents around: _folder.Dispose();
            }

            _csvFilePath      = TempFileUtils.GetTempFilepathWithExtension(".csv");
            _stream           = RobustFile.CreateText(_csvFilePath);
            _stream.AutoFlush = true;

            try
            {
                _stream.WriteLine(Form.ActiveForm.Text);
            }
            catch (Exception)
            {
                // swallow. This happens when we call from firefox, while debugging.
            }
            using (Measure("Initial Memory Reading"))
            {
            }
        }
 private string MakeEmailableReportFile(bool includeBook, bool includeScreenshot, string userDesc, string diagnosticInfo)
 {
     try
     {
         var filename = ("Report " + DateTime.UtcNow.ToString("u") + ".zip").Replace(':', '.');
         filename = filename.SanitizeFilename('#');
         var emailZipPath = Path.Combine(Path.GetTempPath(), filename);
         var emailZipper  = new BloomZipFile(emailZipPath);
         using (var file = TempFile.WithFilenameInTempFolder("report.txt"))
         {
             using (var stream = RobustFile.CreateText(file.Path))
             {
                 stream.WriteLine(diagnosticInfo);
                 if (includeBook)
                 {
                     stream.WriteLine();
                     stream.WriteLine(
                         "REMEMBER: if the attached zip file appears empty, it may have non-ascii in the file names. Open with 7zip and you should see it.");
                 }
             }
             emailZipper.AddTopLevelFile(file.Path);
         }
         if (includeBook)
         {
             var bookZipPath = CreateBookZipFile("ProblemBook", userDesc);
             if (bookZipPath != null)
             {
                 emailZipper.AddTopLevelFile(bookZipPath);
             }
         }
         if (includeScreenshot && _screenshotTempFile != null && RobustFile.Exists(_screenshotTempFile.Path))
         {
             emailZipper.AddTopLevelFile(_screenshotTempFile.Path);
         }
         emailZipper.Save();
         return(emailZipPath);
     }
     catch (Exception error)
     {
         var msg = "***Error as ProblemReportApi attempted to zip up error information to email: " + error.Message;
         userDesc += Environment.NewLine + msg;
         Logger.WriteEvent(userDesc);
         return(null);
     }
 }
Beispiel #4
0
 public void CreateText()
 {
     byte[] correct = null;
     using (var temp = new TempFile())
     {
         var writer = File.CreateText(temp.Path);
         WriteTestDataToStreamWriter(writer);
         correct = File.ReadAllBytes(temp.Path);
     }
     byte[] result;
     using (var temp = new TempFile())
     {
         var writer = RobustFile.CreateText(temp.Path);
         WriteTestDataToStreamWriter(writer);
         result = File.ReadAllBytes(temp.Path);
     }
     Assert.That(result, Is.EqualTo(correct));
 }