public void MsarAddsObserverToAll()
        {
            var progress = new NullProgress();
            var observer = new MockObserver();
            _msar.AddObserver(observer, progress);

            Assert.That(_primary.Observer, Is.EqualTo(observer));
            Assert.That(_other1.Observer, Is.EqualTo(observer));
            Assert.That(_primary.ProgressPassedToAddObserver, Is.EqualTo(progress));
            Assert.That(_other2.ProgressPassedToAddObserver, Is.EqualTo(progress));
        }
Ejemplo n.º 2
0
 public void EnsureAllNotesRepositoriesLoaded()
 {
     if(!_searchedForAllExistingNotesFiles)
     {
         var progress = new NullProgress();
         foreach (var repo in AnnotationRepository.CreateRepositoriesFromFolder(_dataFolderPath, progress))
         {
             if (!_annotationRepositories.ContainsKey(repo.AnnotationFilePath))
             {
                 _annotationRepositories.Add(repo.AnnotationFilePath, repo);
             }
         }
         _searchedForAllExistingNotesFiles=true;
     }
 }
 public void MsarSaveNowSavesAll()
 {
     var progress = new NullProgress();
     _msar.SaveNowIfNeeded(progress);
     Assert.That(_primary.ProgressPassedToSaveNow, Is.EqualTo(progress), "SaveNow not forwarded properly to _primary");
     Assert.That(_other1.ProgressPassedToSaveNow, Is.EqualTo(progress), "SaveNow not forwarded properly to first other");
     Assert.That(_other2.ProgressPassedToSaveNow, Is.EqualTo(progress), "SaveNow not forwarded properly to second other");
 }
        public void MakePdf(string inputHtmlPath, string outputPdfPath, string paperSizeName,
			bool landscape, bool saveMemoryMode, Control owner, BackgroundWorker worker, DoWorkEventArgs doWorkEventArgs)
        {
            #if !__MonoCS__
            // Mono doesn't current provide System.Printing.  Leave the 'if' here to emphasize the
            // system specific nature of the following check.
            if (Platform.IsWindows)
            {
                // Check whether we have a default printer set (or for that matter, any printers).
                // Gecko on Windows requires a default printer for any print operation, even one
                // to a file.  See https://jira.sil.org/browse/BL-1237.
                string errorMessage = null;
                System.Printing.LocalPrintServer printServer = null;
                try
                {
                    printServer = new System.Printing.LocalPrintServer();
                }
                catch (Exception) // System.Printing.PrintQueueException isn't in our System.Printing assembly, so... using Exception
                {
                    // http://issues.bloomlibrary.org/youtrack/issue/BL-4060
                    Logger.WriteEvent("reproduced BL-4060 when trying to create LocalPrinterServer");
                }
                if (printServer == null || !printServer.GetPrintQueues().Any())
                {
                    errorMessage = GetNoDefaultPrinterErrorMessage();
                }
                else
                {
                    System.Printing.PrintQueue defaultPrinter;
                    // BL-2535 it's possible get past the above printQueues.Any() but then get
                    // a System.Printing.PrintQueueException exception with "Access Denied" error here, if
                    // the default printer for some reason is no longer "allowed".
                    try
                    {
                        defaultPrinter = System.Printing.LocalPrintServer.GetDefaultPrintQueue();

                        if(defaultPrinter == null || String.IsNullOrEmpty(defaultPrinter.FullName))
                        {
                            errorMessage = GetNoDefaultPrinterErrorMessage();
                        }
                    }
                    catch(Exception error) // System.Printing.PrintQueueException isn't in our System.Printing assembly, so... using Exception
                    {
                        defaultPrinter = null;
                        errorMessage = L10NSharp.LocalizationManager.GetDynamicString(@"Bloom", @"MakePDF.PrinterError",
                            "Bloom requires access to a printer in order to make a PDF, even though you are not printing.  Windows gave this error when Bloom tried to access the default printer: {0}",
                            @"Error message displayed in a message dialog box");
                        errorMessage = string.Format(errorMessage, error.Message);
                    }
                }
                if (errorMessage !=null)
                {
                    var exception = new ApplicationException(errorMessage);
                    // Note that if we're being run by a BackgroundWorker, it will catch the exception.
                    // If not, but the caller provides a DoWorkEventArgs, pass the exception through
                    // that object rather than throwing it.
                    if (worker != null || doWorkEventArgs == null)
                        throw exception;
                    doWorkEventArgs.Result = exception;
                    return;
                }
            }
            #endif
            var runner = new CommandLineRunner();
            string exePath;
            var bldr = new StringBuilder();
            // Codebase is reliable even when Resharper copies the EXE somewhere else for testing.
            var loc = Assembly.GetExecutingAssembly().CodeBase.Substring((Platform.IsUnix ? "file://" : "file:///").Length);
            var execDir = Path.GetDirectoryName(loc);
            var fromDirectory = String.Empty;
            var filePath = Path.Combine(execDir, "BloomPdfMaker.exe");
            if (!RobustFile.Exists(filePath))
            {
                var msg = LocalizationManager.GetString("InstallProblem.BloomPdfMaker",
                    "A component of Bloom, BloomPdfMaker.exe, seems to be missing. This prevents previews and printing. Antivirus software sometimes does this. You may need technical help to repair the Bloom installation and protect this file from being deleted again.");
                throw new FileNotFoundException(msg, "BloomPdfMaker.exe"); // must be this class to trigger the right reporting mechanism.
            }
            if (Platform.IsMono)
            {
                exePath = "mono";
                bldr.AppendFormat("--debug \"{0}\" ", filePath);
            }
            else
            {
                exePath = filePath;
            }
            SetArguments(bldr, inputHtmlPath, outputPdfPath, paperSizeName, landscape, saveMemoryMode);
            var arguments = bldr.ToString();
            var progress = new NullProgress();
            var res = runner.Start(exePath, arguments, Encoding.UTF8, fromDirectory, 3600, progress, null);
            if (res.DidTimeOut || !RobustFile.Exists (outputPdfPath))
            {
                Logger.WriteEvent(@"***ERROR PDF generation failed: res.StandardOutput = "+res.StandardOutput);

                var msg = L10NSharp.LocalizationManager.GetDynamicString(@"Bloom", @"MakePDF.Failed",
                    "Bloom was not able to create the PDF file ({0}).{1}{1}Details: BloomPdfMaker (command line) did not produce the expected document.",
                    @"Error message displayed in a message dialog box. {0} is the filename, {1} is a newline character.");

                // This message string is intentionally separate because it was added after the previous string had already been localized in most languages.
                var msg2 = L10NSharp.LocalizationManager.GetDynamicString(@"Bloom", @"MakePDF.TrySinglePage",
                    "The book's images might have exceeded the amount of RAM memory available. Please turn on the \"Use Less Memory\" option which is slower but uses less memory.",
                    @"Error message displayed in a message dialog box");

                var fullMsg = String.Format(msg, outputPdfPath, Environment.NewLine) + Environment.NewLine + msg2 + Environment.NewLine + res.StandardOutput;

                var except = new ApplicationException(fullMsg);
                // Note that if we're being run by a BackgroundWorker, it will catch the exception.
                // If not, but the caller provides a DoWorkEventArgs, pass the exception through
                // that object rather than throwing it.
                if (worker != null || doWorkEventArgs == null)
                    throw except;
                else
                    doWorkEventArgs.Result = except;
            }
        }
        public static void TestThatALargeFileIsNotInRepository(string extension)
        {
            var pathToTestRoot = Path.Combine(Path.GetTempPath(), "LargeFileFilterTestFolder_" + extension + "_" + Guid.NewGuid());
            try
            {
                if (Directory.Exists(pathToTestRoot))
                {
                    Thread.Sleep(2000);
                    Directory.Delete(pathToTestRoot, true);
                }
                Directory.CreateDirectory(pathToTestRoot);

                var allHandlers = ChorusFileTypeHandlerCollection.CreateWithInstalledHandlers().Handlers.ToList();
                allHandlers.Add(new ChorusTestFileHandler());
                var handlerForExtension = allHandlers.FirstOrDefault(handler => handler.GetExtensionsOfKnownTextFileTypes().Contains(extension.ToLowerInvariant()))
                    ?? new DefaultFileTypeHandler();

                var goodFileName = "smallfry." + extension;
                var goodPathname = Path.Combine(pathToTestRoot, goodFileName);
                var goodFile = TempFile.WithFilename(goodPathname);
                File.WriteAllText(goodFile.Path, "Nice, short text.");

                var whopperFileName = "whopper." + extension;
                var whopperPathname = Path.Combine(pathToTestRoot, whopperFileName);
                var whopperFile = TempFile.WithFilename(whopperPathname);
                var whopperData = "whopperdata ";
                while (whopperData.Length < handlerForExtension.MaximumFileSize)
                    whopperData += whopperData;
                File.WriteAllText(whopperFile.Path, whopperData);

                var progress = new NullProgress();
                var projectFolderConfiguration = new ProjectFolderConfiguration(pathToTestRoot);
                projectFolderConfiguration.IncludePatterns.Clear();
                projectFolderConfiguration.ExcludePatterns.Clear();
                projectFolderConfiguration.IncludePatterns.Add("*.*");
                RepositorySetup.MakeRepositoryForTest(pathToTestRoot, "Pesky", progress);
                var synchronizer = Synchronizer.FromProjectConfiguration(projectFolderConfiguration, progress);
                synchronizer.Repository.SetUserNameInIni("Pesky", progress);
                var syncOptions = new SyncOptions
                    {
                        // Basic commit. Nothing fancy.
                        DoPullFromOthers = false,
                        DoMergeWithOthers = false,
                        DoSendToOthers = false,
                        CheckinDescription = "Added"
                    };

                var syncResults = synchronizer.SyncNow(syncOptions);
                Assert.IsTrue(syncResults.Succeeded);

                projectFolderConfiguration.ExcludePatterns.Remove(ProjectFolderConfiguration.BareFolderReadmeFileName);
                Assert.AreEqual(2, projectFolderConfiguration.ExcludePatterns.Count);
                Assert.IsTrue(projectFolderConfiguration.ExcludePatterns[0].Contains(whopperFileName));

                var repo = new HgRepository(pathToTestRoot, progress);
                Assert.IsTrue(repo.GetFileExistsInRepo(goodFileName), goodFileName);
                Assert.IsFalse(repo.GetFileExistsInRepo(whopperFileName), whopperFileName);
            }
            finally
            {
                if (Directory.Exists(pathToTestRoot))
                {
                    Thread.Sleep(2000);
                    Directory.Delete(pathToTestRoot, true);
                }
            }
        }
 public void UserCancelledBreakupShouldThrow()
 {
     using (var tempFile = TempFile.WithFilename("foo" + Utilities.FwXmlExtension))
     {
         var progress = new NullProgress
             {
                 CancelRequested = true
             };
         var pathname = tempFile.Path;
         Assert.Throws<UserCancelledException>(() => FLExProjectSplitter.PushHumptyOffTheWall(progress, pathname));
     }
 }
Ejemplo n.º 7
0
 public RevisionInspector(HgRepository repository, ChorusFileTypeHandlerCollection fileHandlerCollection)
 {
     Repository = repository;
     _fileHandlerCollection = fileHandlerCollection;
     ProgressIndicator = new NullProgress();
 }