Inheritance: Palaso.IO.FileLocator
示例#1
0
        /// <summary>
        /// Give the locations of the bedrock files/folders that come with Bloom. These will have priority.
        /// (But compare GetAfterXMatterFileLocations, for further paths that are searched after factory XMatter).
        /// </summary>
        public static IEnumerable <string> GetFactoryFileLocations()
        {
            //bookLayout has basepage.css. We have it first because it will find its way to many other folders, but this is the authoritative one
            yield return(FileLocationUtilities.GetDirectoryDistributedWithApplication(BloomFileLocator.BrowserRoot, "bookLayout"));

            yield return(FileLocationUtilities.GetDirectoryDistributedWithApplication(BloomFileLocator.BrowserRoot));

            //hack to get the distfiles folder itself
            yield return(Path.GetDirectoryName(FileLocationUtilities.GetDirectoryDistributedWithApplication("localization")));

            yield return(FileLocationUtilities.GetDirectoryDistributedWithApplication(BloomFileLocator.BrowserRoot));

            yield return(FileLocationUtilities.GetDirectoryDistributedWithApplication(Path.Combine(BloomFileLocator.BrowserRoot, "bookEdit/js")));

            yield return(FileLocationUtilities.GetDirectoryDistributedWithApplication(Path.Combine(BloomFileLocator.BrowserRoot, "bookEdit/js/toolbar")));

            yield return(FileLocationUtilities.GetDirectoryDistributedWithApplication(Path.Combine(BloomFileLocator.BrowserRoot, "bookEdit/css")));

            yield return(FileLocationUtilities.GetDirectoryDistributedWithApplication(Path.Combine(BloomFileLocator.BrowserRoot, "bookEdit/html")));

            yield return(FileLocationUtilities.GetDirectoryDistributedWithApplication(Path.Combine(BloomFileLocator.BrowserRoot, "bookEdit/html/font-awesome/css")));

            yield return(FileLocationUtilities.GetDirectoryDistributedWithApplication(Path.Combine(BloomFileLocator.BrowserRoot, "bookEdit/img")));

            yield return(FileLocationUtilities.GetDirectoryDistributedWithApplication(Path.Combine(BloomFileLocator.BrowserRoot, "images")));

            foreach (var dir in ToolboxView.GetToolboxServerDirectories())
            {
                yield return(dir);
            }
            yield return(FileLocationUtilities.GetDirectoryDistributedWithApplication(Path.Combine(BloomFileLocator.BrowserRoot, "bookEdit/StyleEditor")));

            yield return(FileLocationUtilities.GetDirectoryDistributedWithApplication(Path.Combine(BloomFileLocator.BrowserRoot, "bookEdit/TopicChooser")));

            yield return(FileLocationUtilities.GetDirectoryDistributedWithApplication(Path.Combine(BloomFileLocator.BrowserRoot, "collection")));

            var x = FileLocationUtilities.GetDirectoryDistributedWithApplication(Path.Combine(BloomFileLocator.BrowserRoot, "performance"));

            yield return(FileLocationUtilities.GetDirectoryDistributedWithApplication(Path.Combine(BloomFileLocator.BrowserRoot, "performance")));

            yield return(FileLocationUtilities.GetDirectoryDistributedWithApplication(Path.Combine(BloomFileLocator.BrowserRoot, "themes/bloom-jqueryui-theme")));

            yield return(FileLocationUtilities.GetDirectoryDistributedWithApplication(Path.Combine(BloomFileLocator.BrowserRoot, "lib")));

            // not needed: yield return FileLocationUtilities.GetDirectoryDistributedWithApplication(Path.Combine(BloomFileLocator.BrowserRoot,"lib/localizationManager"));
            yield return(FileLocationUtilities.GetDirectoryDistributedWithApplication(Path.Combine(BloomFileLocator.BrowserRoot, "lib/long-press")));

            yield return(FileLocationUtilities.GetDirectoryDistributedWithApplication(Path.Combine(BloomFileLocator.BrowserRoot, "lib/split-pane")));

            yield return(FileLocationUtilities.GetDirectoryDistributedWithApplication(Path.Combine(BloomFileLocator.BrowserRoot, "lib/ckeditor/skins/icy_orange")));

            yield return(FileLocationUtilities.GetDirectoryDistributedWithApplication(Path.Combine(BloomFileLocator.BrowserRoot, "bookEdit/toolbox/talkingBook")));

            yield return(BloomFileLocator.GetInstalledXMatterDirectory());

            yield return(FileLocationUtilities.GetDirectoryDistributedWithApplication(Path.Combine(BloomFileLocator.BrowserRoot, "publish/ePUBPublish")));
        }
        /// <summary>
        /// This can be used to find the best localized file when there is only one file with the given name,
        /// and the file is part of the files distributed with Bloom (i.e., not something in a downloaded template).
        /// </summary>
        public static string GetBestLocalizableFileDistributedWithApplication(bool existenceOfEnglishVersionIsOptional, params string[] partsOfEnglishFilePath)
        {
            var englishPath = FileLocator.GetFileDistributedWithApplication(existenceOfEnglishVersionIsOptional, partsOfEnglishFilePath);

            if (!RobustFile.Exists(englishPath))
            {
                return(englishPath);                // just return whatever the original GetFileDistributedWithApplication gave. "", null, whatever it is.
            }
            return(BloomFileLocator.GetBestLocalizedFile(englishPath));
        }
 /// <summary>
 /// Gets a file in the specified branding folder
 /// </summary>
 /// <param name="brandingNameOrFolderPath"> Normally, the branding is just a name, which we look up in the official branding folder
 //  but unit tests can instead provide a path to the folder.
 /// </param>
 /// <param name="fileName"></param>
 /// <returns></returns>
 public static string GetOptionalBrandingFile(string brandingNameOrFolderPath, string fileName)
 {
     if (Path.IsPathRooted(brandingNameOrFolderPath))            //if it looks like a path
     {
         var path = Path.Combine(brandingNameOrFolderPath, fileName);
         if (RobustFile.Exists(path))
         {
             return(path);
         }
         return(null);
     }
     return(BloomFileLocator.GetFileDistributedWithApplication(true, "branding", brandingNameOrFolderPath, fileName));
 }
示例#4
0
 public override IFileLocator CloneAndCustomize(IEnumerable<string> addedSearchPaths)
 {
     var locator= new BloomFileLocator(_collectionSettings, _xMatterPackFinder,_factorySearchPaths, _userInstalledSearchPaths);
     foreach (var path in _bookSpecificSearchPaths)
     {
         locator.AddPath(path);
     }
     foreach (var path in addedSearchPaths)
     {
         locator.AddPath(path);
     }
     return locator;
 }
        public override IFileLocator CloneAndCustomize(IEnumerable <string> addedSearchPaths)
        {
            var locator = new BloomFileLocator(_collectionSettings, _xMatterPackFinder, _factorySearchPaths, _userInstalledSearchPaths, _afterXMatterSearchPaths);

            foreach (var path in _bookSpecificSearchPaths)
            {
                locator.AddPath(path);
            }
            foreach (var path in addedSearchPaths)
            {
                locator.AddPath(path);
            }
            return(locator);
        }
示例#6
0
        public BloomFileLocator(CollectionSettings collectionSettings, XMatterPackFinder xMatterPackFinder, IEnumerable <string> factorySearchPaths, IEnumerable <string> userInstalledSearchPaths,
                                IEnumerable <string> afterXMatterSearchPaths = null)
        {
            if (afterXMatterSearchPaths == null)
            {
                afterXMatterSearchPaths = new string[] {};
            }
            _bookSpecificSearchPaths  = new List <string>();
            _collectionSettings       = collectionSettings;
            _xMatterPackFinder        = xMatterPackFinder;
            _factorySearchPaths       = factorySearchPaths;
            _userInstalledSearchPaths = userInstalledSearchPaths;
            _afterXMatterSearchPaths  = afterXMatterSearchPaths;

            sTheMostRecentBloomFileLocator = this;
        }
示例#7
0
 /// <summary>
 /// Gets a file in the specified branding folder
 /// </summary>
 /// <param name="brandingNameOrFolderPath"> Normally, the branding is just a name, which we look up in the official branding folder
 //  but unit tests can instead provide a path to the folder.
 /// </param>
 /// <param name="fileName"></param>
 /// <returns></returns>
 public static string GetOptionalBrandingFile(string brandingNameOrFolderPath, string fileName)
 {
     if (Path.IsPathRooted(brandingNameOrFolderPath))            //if it looks like a path
     {
         var path = Path.Combine(brandingNameOrFolderPath, fileName);
         if (RobustFile.Exists(path))
         {
             return(path);
         }
         return(null);
     }
     if (Path.IsPathRooted(fileName) && RobustFile.Exists(fileName))             // also just for unit tests
     {
         return(fileName);
     }
     return(BloomFileLocator.GetBrowserFile(true, "branding", brandingNameOrFolderPath, fileName));
 }
        public BloomFileLocator(CollectionSettings collectionSettings, XMatterPackFinder xMatterPackFinder, IEnumerable <string> factorySearchPaths, IEnumerable <string> userInstalledSearchPaths,
                                IEnumerable <string> afterXMatterSearchPaths = null)
            : base(factorySearchPaths.Concat(userInstalledSearchPaths))             //review: is this even used, since we override GetSearchPaths()?
        {
            if (afterXMatterSearchPaths == null)
            {
                afterXMatterSearchPaths = new string[] {};
            }
            _bookSpecificSearchPaths  = new List <string>();
            _collectionSettings       = collectionSettings;
            _xMatterPackFinder        = xMatterPackFinder;
            _factorySearchPaths       = factorySearchPaths;
            _userInstalledSearchPaths = userInstalledSearchPaths;
            _afterXMatterSearchPaths  = afterXMatterSearchPaths;

            sTheMostRecentBloomFileLocator = this;
        }
        //review: is this even used, since we override GetSearchPaths()?
        public BloomFileLocator(CollectionSettings collectionSettings, XMatterPackFinder xMatterPackFinder, IEnumerable<string> factorySearchPaths, IEnumerable<string> userInstalledSearchPaths,
			IEnumerable<string> afterXMatterSearchPaths = null)
            : base(factorySearchPaths.Concat( userInstalledSearchPaths))
        {
            if (afterXMatterSearchPaths == null)
            {
                afterXMatterSearchPaths = new string[] {};
            }
            _bookSpecificSearchPaths = new List<string>();
            _collectionSettings = collectionSettings;
            _xMatterPackFinder = xMatterPackFinder;
            _factorySearchPaths = factorySearchPaths;
            _userInstalledSearchPaths = userInstalledSearchPaths;
            _afterXMatterSearchPaths = afterXMatterSearchPaths;

            sTheMostRecentBloomFileLocator = this;
        }
        /// <summary>
        /// This can be used to find the best localized file when there is only one file with the given name,
        /// and the file is part of the files distributed with Bloom (i.e., not something in a downloaded template).
        /// </summary>
        public static string GetBestLocalizableFileDistributedWithApplication(bool existenceOfEnglishVersionIsOptional, params string[] partsOfEnglishFilePath)
        {
            // at this time, FileLocator does not have a way for the app to actually tell it where to find things distributed
            // with the application...
            var englishPath = FileLocator.GetFileDistributedWithApplication(true, partsOfEnglishFilePath);

            // ... so if it doesn't find it, we have to keep looking
            if (string.IsNullOrWhiteSpace(englishPath))
            {
                //this one will throw if we still can't find it and existenceOfEnglishVersionIsOptional is false
                englishPath = BloomFileLocator.GetBrowserFile(existenceOfEnglishVersionIsOptional, partsOfEnglishFilePath);
            }

            if (!RobustFile.Exists(englishPath))
            {
                return(englishPath);                // just return whatever the original GetFileDistributedWithApplication gave. "", null, whatever it is.
            }
            return(BloomFileLocator.GetBestLocalizedFile(englishPath));
        }
示例#11
0
        private static Book MakeBook(CollectionSettings collectionSettings, string sourceBookFolderPath)
        {
            var xmatterLocations = new List<string>();
            xmatterLocations.Add(ProjectContext.XMatterAppDataFolder);
            xmatterLocations.Add(FileLocator.GetDirectoryDistributedWithApplication( kpathToSHRPTemplates));
            xmatterLocations.Add(FileLocator.GetDirectoryDistributedWithApplication("xMatter"));
            var locator = new BloomFileLocator(collectionSettings, new XMatterPackFinder(xmatterLocations), new string[] {});

            var starter = new BookStarter(locator,
                                          path =>
                                          new BookStorage(path, locator, new BookRenamedEvent(),
                                                          collectionSettings),
                                          collectionSettings);
            var pathToFolderOfNewBook = starter.CreateBookOnDiskFromTemplate(sourceBookFolderPath, collectionSettings.FolderPath);

            var newBookInfo = new BookInfo(pathToFolderOfNewBook, false /*saying not editable works us around a langdisplay issue*/);

            BookStorage bookStorage = new BookStorage(pathToFolderOfNewBook, locator, new BookRenamedEvent(), collectionSettings);
            var book = new Book(newBookInfo, bookStorage, null,
                            collectionSettings, null, null, null, null);

            return book;
        }
        public void Setup()
        {
            var locations = new List<string>();
            locations.Add(BloomFileLocator.GetInstalledXMatterDirectory());
            _xMatterParentFolder = new TemporaryFolder("UserCollection");
            _xMatterFolder = new TemporaryFolder(_xMatterParentFolder, "User-XMatter");
            locations.Add(_xMatterParentFolder.Path);
            RobustFile.WriteAllText(Path.Combine(_xMatterFolder.Path, "SomeRandomXYZABCStyles.css"), "Some arbitrary test data");
            RobustFile.WriteAllText(Path.Combine(_xMatterFolder.Path, "Decodable Reader.css"), "Fake DR test data");
            //locations.Add(XMatterAppDataFolder);
            //locations.Add(XMatterCommonDataFolder);
            _xMatterFinder = new XMatterPackFinder(locations);

            _otherFilesForTestingFolder = new TemporaryFolder("BloomFileLocatorTests");
            var userInstalledSearchPaths = new List<string>( ProjectContext.GetFoundFileLocations());
            userInstalledSearchPaths.Add(_otherFilesForTestingFolder.Path);
            _fileLocator = new BloomFileLocator(new CollectionSettings(), _xMatterFinder, ProjectContext.GetFactoryFileLocations(), userInstalledSearchPaths,
                ProjectContext.GetAfterXMatterFileLocations());

            //Without this, tests can interact with one another, leaving the language set as something unexpected.
            LocalizationManager.SetUILanguage("en", false);
        }
 public static string GetInstalledXMatterDirectory()
 {
     return(BloomFileLocator.GetBrowserDirectory("templates", "xMatter"));
 }
示例#14
0
 public static string GetProjectSpecificInstalledXMatterDirectory()
 {
     return(BloomFileLocator.GetBrowserDirectory("templates", "xMatter", "project-specific"));
 }
        public void Setup()
        {
            Logger.Init();
            _folder = new TemporaryFolder("ImageServerTests");
            var localizationDirectory = FileLocator.GetDirectoryDistributedWithApplication("localization");
            LocalizationManager.Create("fr", "Bloom", "Bloom", "1.0.0", localizationDirectory, "SIL/Bloom", null, "", new string[] { });

            ErrorReport.IsOkToInteractWithUser = false;
            _collectionPath = Path.Combine(_folder.Path, "TestCollection");
            var cs = new CollectionSettings(Path.Combine(_folder.Path, "TestCollection.bloomCollection"));
            _fileLocator = new BloomFileLocator(cs, new XMatterPackFinder(new string[] { BloomFileLocator.GetInstalledXMatterDirectory() }), ProjectContext.GetFactoryFileLocations(),
                ProjectContext.GetFoundFileLocations(), ProjectContext.GetAfterXMatterFileLocations());
        }
示例#16
0
 public static string GetCustomXMatterDirectory()
 {
     return(BloomFileLocator.GetBrowserDirectory("templates", "customXMatter"));
 }
示例#17
0
 public string GetBrandingFile(Boolean optional, string fileName)
 {
     return(BloomFileLocator.GetBrowserFile(optional, "branding", _collectionSettings.GetBrandingFolderName(), fileName));
 }
示例#18
0
 public static string GetBrandingFolder(string fullBrandingName)
 {
     BrandingSettings.ParseBrandingKey(fullBrandingName, out var brandingFolderName, out var flavor);
     return(BloomFileLocator.GetBrowserDirectory("branding", brandingFolderName));
 }
示例#19
0
        /// ------------------------------------------------------------------------------------
        protected void BuildSubContainerForThisProject(string projectSettingsPath, IContainer parentContainer)
        {
            var commandTypes = new[]
            {
                typeof(DuplicatePageCommand),
                typeof(DeletePageCommand),
                typeof(CutCommand),
                typeof(CopyCommand),
                typeof(PasteCommand),
                typeof(UndoCommand)
            };

            var editableCollectionDirectory = Path.GetDirectoryName(projectSettingsPath);

            try
            {
                _scope = parentContainer.BeginLifetimeScope(builder =>
                {
                    //BloomEvents are by nature, singletons (InstancePerLifetimeScope)
                    builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
                    .InstancePerLifetimeScope()
                    // Didn't work .Where(t => t.GetInterfaces().Contains(typeof(Bloom.Event<>)));
                    .Where(t => t is IEvent);

                    //Other classes which are also  singletons
                    builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
                    .InstancePerLifetimeScope()
                    .Where(t => new[]
                    {
                        typeof(TemplateInsertionCommand),
                        typeof(EditBookCommand),
                        typeof(SendReceiveCommand),
                        typeof(SelectedTabAboutToChangeEvent),
                        typeof(SelectedTabChangedEvent),
                        typeof(LibraryClosing),
                        typeof(PageListChangedEvent),                                  // REMOVE+++++++++++++++++++++++++++
                        typeof(BookRefreshEvent),
                        typeof(BookSavedEvent),
                        typeof(PageRefreshEvent),
                        typeof(BookDownloadStartingEvent),
                        typeof(BookSelection),
                        typeof(CurrentEditableCollectionSelection),
                        typeof(RelocatePageEvent),
                        typeof(QueueRenameOfCollection),
                        typeof(PageSelection),
                        typeof(LocalizationChangedEvent),
                        typeof(ControlKeyEvent),
                        typeof(BookStatusChangeEvent),
                        typeof(EditingModel),
                        typeof(AudioRecording),
                        typeof(BookSettingsApi),
                        typeof(BookMetadataApi),
                        typeof(PublishToAndroidApi),
                        typeof(PublishEpubApi),
                        typeof(AccessibilityCheckApi),
                        typeof(CollectionSettingsApi),
                        typeof(CollectionApi),
                        typeof(PageControlsApi),
                        typeof(ReadersApi),
                        typeof(PageTemplatesApi),
                        typeof(AddOrChangePageApi),
                        typeof(BloomWebSocketServer),
                        typeof(PerformanceMeasurement),
                        typeof(KeyboardingConfigApi),
                        typeof(ImageApi),
                        typeof(MusicApi),
                        typeof(PageListApi),
                        typeof(TalkingBookApi),
                        typeof(ToolboxApi),
                        typeof(CommonApi),
                        typeof(TeamCollectionApi),
                        typeof(BrandingSettings),
                        typeof(AppApi),
                        typeof(I18NApi),
                        typeof(SignLanguageApi),
                        typeof(AudioSegmentationApi),
                        typeof(FileIOApi),
                        typeof(EditingViewApi),
                        typeof(BrowserDialogApi),
                        typeof(ProblemReportApi)
                    }.Contains(t));

                    builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
                    .InstancePerLifetimeScope()
                    .Where(commandTypes.Contains).As <ICommand>();

                    var bookRenameEvent = new BookRenamedEvent();
                    builder.Register(c => bookRenameEvent).AsSelf().InstancePerLifetimeScope();

                    try
                    {
#if Chorus                      //nb: we split out the ChorusSystem.Init() so that this won't ever fail, so we have something registered even if we aren't
                        //going to be able to do HG for some reason.
                        var chorusSystem = new ChorusSystem(Path.GetDirectoryName(projectSettingsPath));
                        builder.Register <ChorusSystem>(c => chorusSystem).InstancePerLifetimeScope();
                        builder.Register <SendReceiver>(c => new SendReceiver(chorusSystem, () => ProjectWindow))
                        .InstancePerLifetimeScope();

                        chorusSystem.Init(string.Empty /*user name*/);
#endif
                    }
                    catch (Exception error)
                    {
#if USING_CHORUS
#if !DEBUG
                        SIL.Reporting.ErrorReport.NotifyUserOfProblem(error,
                                                                      "There was a problem loading the Chorus Send/Receive system for this collection. Bloom will try to limp along, but you'll need technical help to resolve this. If you have no other choice, find this folder: {0}, move it somewhere safe, and restart Bloom.", Path.GetDirectoryName(projectSettingsPath).CombineForPath(".hg"));
#endif
                        //swallow for develoeprs, because this happens if you don't have the Mercurial and "Mercurial Extensions" folders in the root, and our
                        //getdependencies doesn't yet do that.
#endif
                    }


                    //This deserves some explanation:
                    //*every* collection has a "*.BloomCollection" settings file. But the one we make the most use of is the one editable collection
                    //That's why we're registering it... it gets used all over. At the moment (May 2012), we don't ever read the
                    //settings file of the collections we're using for sources.
                    try
                    {
                        // It's important to create the TC manager before we create CollectionSettings, as its constructor makes sure
                        // we have a current version of the file that CollectionSettings is built from.
                        builder.Register <TeamCollectionManager>(c => new TeamCollectionManager(projectSettingsPath,
                                                                                                c.Resolve <BloomWebSocketServer>(), c.Resolve <BookRenamedEvent>(),
                                                                                                c.Resolve <BookStatusChangeEvent>(),
                                                                                                c.Resolve <BookSelection>(),
                                                                                                c.Resolve <LibraryClosing>())).InstancePerLifetimeScope();
                        builder.Register <ITeamCollectionManager>(c => c.Resolve <TeamCollectionManager>()).InstancePerLifetimeScope();
                        builder.Register <CollectionSettings>(c =>
                        {
                            c.Resolve <TeamCollectionManager>();
                            return(GetCollectionSettings(projectSettingsPath));
                        }).InstancePerLifetimeScope();
                    }
                    catch (Exception)
                    {
                        return;
                    }


                    builder.Register <LibraryModel>(
                        c =>
                        new LibraryModel(editableCollectionDirectory, c.Resolve <CollectionSettings>(),
                                                        #if Chorus
                                         c.Resolve <SendReceiver>(),
                                                        #endif
                                         c.Resolve <BookSelection>(), c.Resolve <SourceCollectionsList>(), c.Resolve <BookCollection.Factory>(),
                                         c.Resolve <EditBookCommand>(), c.Resolve <CreateFromSourceBookCommand>(), c.Resolve <BookServer>(),
                                         c.Resolve <CurrentEditableCollectionSelection>(), c.Resolve <BookThumbNailer>(), c.Resolve <TeamCollectionManager>())).InstancePerLifetimeScope();

                    // Keep in sync with OptimizedFileLocator: it wants to return the object created here.
                    builder.Register <IChangeableFileLocator>(
                        c =>
                        new BloomFileLocator(c.Resolve <CollectionSettings>(), c.Resolve <XMatterPackFinder>(), GetFactoryFileLocations(),
                                             GetFoundFileLocations(), GetAfterXMatterFileLocations())).InstancePerLifetimeScope();

                    builder.Register <LanguageSettings>(c =>
                    {
                        var librarySettings = c.Resolve <CollectionSettings>();
                        var preferredSourceLanguagesInOrder = new List <string>();
                        preferredSourceLanguagesInOrder.Add(librarySettings.Language2.Iso639Code);
                        if (!String.IsNullOrEmpty(librarySettings.Language3.Iso639Code) &&
                            librarySettings.Language3.Iso639Code != librarySettings.Language2.Iso639Code)
                        {
                            preferredSourceLanguagesInOrder.Add(librarySettings.Language3.Iso639Code);
                        }

                        return(new LanguageSettings(librarySettings.Language1.Iso639Code, preferredSourceLanguagesInOrder));
                    });
                    builder.Register <XMatterPackFinder>(c =>
                    {
                        var locations = new List <string>();
                        locations.Add(BloomFileLocator.GetInstalledXMatterDirectory());
                        locations.Add(XMatterAppDataFolder);
                        locations.Add(XMatterCommonDataFolder);
                        return(new XMatterPackFinder(locations));
                    });

                    builder.Register <SourceCollectionsList>(c =>
                    {
                        var l = new SourceCollectionsList(c.Resolve <Book.Book.Factory>(), c.Resolve <BookStorage.Factory>(),
                                                          editableCollectionDirectory, new string[] { BloomFileLocator.FactoryCollectionsDirectory, GetInstalledCollectionsDirectory() });
                        return(l);
                    }).InstancePerLifetimeScope();

                    builder.Register <ITemplateFinder>(c =>
                    {
                        return(c.Resolve <SourceCollectionsList>());
                    }).InstancePerLifetimeScope();

                    builder.RegisterType <BloomParseClient>().AsSelf().SingleInstance();

                    // Enhance: may need some way to test a release build in the sandbox.
                    builder.Register(c => CreateBloomS3Client()).AsSelf().SingleInstance();
                    builder.RegisterType <BookUpload>().AsSelf().SingleInstance();

                    //TODO: this gave a stackoverflow exception
//				builder.Register<WorkspaceModel>(c => c.Resolve<WorkspaceModel.Factory>()(rootDirectoryPath)).InstancePerLifetimeScope();
                    //so we're doing this
                    builder.Register(c => editableCollectionDirectory).InstancePerLifetimeScope();

                    builder.RegisterType <CreateFromSourceBookCommand>().InstancePerLifetimeScope();

                    // See related comment below for BL-688
//				string collectionDirectory = Path.GetDirectoryName(projectSettingsPath);
//				if (Path.GetFileNameWithoutExtension(projectSettingsPath).ToLower().Contains("web"))
//				{
//					// REVIEW: This seems to be used only for testing purposes
//					BookCollection editableCollection = _scope.Resolve<BookCollection.Factory>()(collectionDirectory, BookCollection.CollectionType.TheOneEditableCollection);
//					var sourceCollectionsList = _scope.Resolve<SourceCollectionsList>();
//					_httpServer = new BloomServer(_scope.Resolve<CollectionSettings>(), editableCollection, sourceCollectionsList, parentContainer.Resolve<HtmlThumbNailer>());
//				}
//				else
//				{
                    builder.Register <BloomServer>(
                        c =>
                        new BloomServer(new RuntimeImageProcessor(bookRenameEvent), c.Resolve <BookSelection>(), c.Resolve <CollectionSettings>())).SingleInstance();

                    builder.Register <Func <WorkspaceView> >(c => () =>
                    {
                        var factory = c.Resolve <WorkspaceView.Factory>();

                        // Removing this check because finding "web" anywhere in the path is problematic.
                        // This was discovered by a user whose username included "web" (https://jira.sil.org/browse/BL-688)
                        // It appears this code block was for some experimental development but no longer works anyway.
//					if (projectSettingsPath.ToLower().Contains("web"))
//					{
//						return factory(c.Resolve<WebLibraryView>());
//					}
//					else
//					{
                        return(factory(c.Resolve <LibraryView>()));
//					}
                    });

                    builder.RegisterType <AccessibilityCheckWindow>();
                });

                /*
                 * this is from spike, which worked, but we aren't using (yet)
                 * var allCommands = from c in commandTypes select _scope.Resolve(c) as ICommand;
                 * _commandAvailabilityPublisher = new CommandAvailabilityPublisher(allCommands);
                 */
            }
            catch (FileNotFoundException error)
            {
                MessageBox.Show("Bloom was not able to find all its bits. This sometimes happens when upgrading to a newer version. To fix it, please run the installer again and choose 'Repair', or uninstall and reinstall. We truly value your time and apologize for wasting it. The error was:" + Environment.NewLine + Environment.NewLine + error.Message, "Bloom Installation Problem", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }

            var server = _scope.Resolve <BloomServer>();
            server.StartListening();
            _scope.Resolve <AudioRecording>().RegisterWithApiHandler(server.ApiHandler);

            _scope.Resolve <BloomWebSocketServer>().Init((BloomServer.portForHttp + 1).ToString(CultureInfo.InvariantCulture));
            HelpLauncher.RegisterWithApiHandler(server.ApiHandler);
            ExternalLinkController.RegisterWithApiHandler(server.ApiHandler);
            ToolboxView.RegisterWithApiHandler(server.ApiHandler);
            _scope.Resolve <PageTemplatesApi>().RegisterWithApiHandler(server.ApiHandler);
            _scope.Resolve <AddOrChangePageApi>().RegisterWithApiHandler(server.ApiHandler);
            _scope.Resolve <PublishToAndroidApi>().RegisterWithApiHandler(server.ApiHandler);
            _scope.Resolve <PublishEpubApi>().RegisterWithApiHandler(server.ApiHandler);
            _scope.Resolve <AccessibilityCheckApi>().RegisterWithApiHandler(server.ApiHandler);
            _scope.Resolve <CollectionSettingsApi>().RegisterWithApiHandler(server.ApiHandler);
            _scope.Resolve <CollectionApi>().RegisterWithApiHandler(server.ApiHandler);
            _scope.Resolve <PageControlsApi>().RegisterWithApiHandler(server.ApiHandler);
            _scope.Resolve <KeyboardingConfigApi>().RegisterWithApiHandler(server.ApiHandler);
            _scope.Resolve <BookSettingsApi>().RegisterWithApiHandler(server.ApiHandler);
            _scope.Resolve <BookMetadataApi>().RegisterWithApiHandler(server.ApiHandler);
            _scope.Resolve <ImageApi>().RegisterWithApiHandler(server.ApiHandler);
            _scope.Resolve <ReadersApi>().RegisterWithApiHandler(server.ApiHandler);
            _scope.Resolve <MusicApi>().RegisterWithApiHandler(server.ApiHandler);
            _scope.Resolve <PageListApi>().RegisterWithApiHandler(server.ApiHandler);
            _scope.Resolve <TalkingBookApi>().RegisterWithApiHandler(server.ApiHandler);
            _scope.Resolve <ToolboxApi>().RegisterWithApiHandler(server.ApiHandler);
            _scope.Resolve <CommonApi>().RegisterWithApiHandler(server.ApiHandler);
            _scope.Resolve <TeamCollectionApi>().RegisterWithApiHandler(server.ApiHandler);
            _scope.Resolve <AppApi>().RegisterWithApiHandler(server.ApiHandler);
            _scope.Resolve <SignLanguageApi>().RegisterWithApiHandler(server.ApiHandler);
            _scope.Resolve <AudioSegmentationApi>().RegisterWithApiHandler(server.ApiHandler);
            _scope.Resolve <BrowserDialogApi>().RegisterWithApiHandler(server.ApiHandler);
            _scope.Resolve <ProblemReportApi>().RegisterWithApiHandler(server.ApiHandler);
            _scope.Resolve <I18NApi>().RegisterWithApiHandler(server.ApiHandler);
            _scope.Resolve <FileIOApi>().RegisterWithApiHandler(server.ApiHandler);
            _scope.Resolve <EditingViewApi>().RegisterWithApiHandler(server.ApiHandler);
            _scope.Resolve <PerformanceMeasurement>().RegisterWithApiHandler(server.ApiHandler);
        }
示例#20
0
 public static string GetBrandingFolder(string brandingName)
 {
     return(BloomFileLocator.GetBrowserDirectory("branding", brandingName));
 }