public delegate EditingModel Factory();        //autofac uses this

        public EditingModel(BookSelection bookSelection, PageSelection pageSelection,
                            LanguageSettings languageSettings,
                            TemplateInsertionCommand templateInsertionCommand,
                            PageListChangedEvent pageListChangedEvent,
                            RelocatePageEvent relocatePageEvent,
                            BookRefreshEvent bookRefreshEvent,
                            DuplicatePageCommand duplicatePageCommand,
                            DeletePageCommand deletePageCommand,
                            SelectedTabChangedEvent selectedTabChangedEvent,
                            SelectedTabAboutToChangeEvent selectedTabAboutToChangeEvent,
                            LibraryClosing libraryClosingEvent,
                            LocalizationChangedEvent localizationChangedEvent,
                            CollectionSettings collectionSettings,
                            SendReceiver sendReceiver,
                            EnhancedImageServer server)
        {
            _bookSelection        = bookSelection;
            _pageSelection        = pageSelection;
            _languageSettings     = languageSettings;
            _duplicatePageCommand = duplicatePageCommand;
            _deletePageCommand    = deletePageCommand;
            _collectionSettings   = collectionSettings;
            _sendReceiver         = sendReceiver;
            _server = server;

            bookSelection.SelectionChanged      += new EventHandler(OnBookSelectionChanged);
            pageSelection.SelectionChanged      += new EventHandler(OnPageSelectionChanged);
            templateInsertionCommand.InsertPage += new EventHandler(OnInsertTemplatePage);

            bookRefreshEvent.Subscribe((book) => OnBookSelectionChanged(null, null));
            selectedTabChangedEvent.Subscribe(OnTabChanged);
            selectedTabAboutToChangeEvent.Subscribe(OnTabAboutToChange);
            duplicatePageCommand.Implementer = OnDuplicatePage;
            deletePageCommand.Implementer    = OnDeletePage;
            pageListChangedEvent.Subscribe(x => _view.UpdatePageList(false));
            relocatePageEvent.Subscribe(OnRelocatePage);
            libraryClosingEvent.Subscribe(o => SaveNow());
            localizationChangedEvent.Subscribe(o =>
            {
                //this is visible was added for https://jira.sil.org/browse/BL-267, where the edit tab has never been
                //shown so the view has never been full constructed, so we're not in a good state to do a refresh
                if (Visible)
                {
                    SaveNow();
                    _view.UpdateButtonLocalizations();
                    RefreshDisplayOfCurrentPage();
                    //_view.UpdateDisplay();
                    _view.UpdatePageList(false);
                    _view.UpdateTemplateList();
                }
                else if (_view != null)
                {
                    // otherwise changing UI language in Publish tab (for instance) won't update these localizations
                    _view.UpdateButtonLocalizations();
                }
            });
            _contentLanguages = new List <ContentLanguage>();
            _server.CurrentCollectionSettings = _collectionSettings;
            _server.CurrentBook = CurrentBook;
        }
Beispiel #2
0
        //autofac uses this
        public EditingModel(BookSelection bookSelection, PageSelection pageSelection,
			LanguageSettings languageSettings,
			TemplateInsertionCommand templateInsertionCommand,
			PageListChangedEvent pageListChangedEvent,
			RelocatePageEvent relocatePageEvent,
			BookRefreshEvent bookRefreshEvent,
			DeletePageCommand deletePageCommand,
			SelectedTabChangedEvent selectedTabChangedEvent,
			SelectedTabAboutToChangeEvent selectedTabAboutToChangeEvent,
			LibraryClosing libraryClosingEvent,
			CollectionSettings collectionSettings,
			SendReceiver sendReceiver)
        {
            _bookSelection = bookSelection;
            _pageSelection = pageSelection;
            _languageSettings = languageSettings;
            _deletePageCommand = deletePageCommand;
            _collectionSettings = collectionSettings;
            _sendReceiver = sendReceiver;

            bookSelection.SelectionChanged += new EventHandler(OnBookSelectionChanged);
            pageSelection.SelectionChanged += new EventHandler(OnPageSelectionChanged);
            templateInsertionCommand.InsertPage += new EventHandler(OnInsertTemplatePage);

            bookRefreshEvent.Subscribe((book) => OnBookSelectionChanged(null, null));
            selectedTabChangedEvent.Subscribe(OnTabChanged);
            selectedTabAboutToChangeEvent.Subscribe(OnTabAboutToChange);
            deletePageCommand.Implementer=OnDeletePage;
            pageListChangedEvent.Subscribe(x => _view.UpdatePageList(false));
            relocatePageEvent.Subscribe(OnRelocatePage);
            libraryClosingEvent.Subscribe(o=>SaveNow());
            _contentLanguages = new List<ContentLanguage>();
        }
Beispiel #3
0
        public delegate EditingModel Factory();        //autofac uses this

        public EditingModel(BookSelection bookSelection, PageSelection pageSelection,
                            LanguageSettings languageSettings,
                            TemplateInsertionCommand templateInsertionCommand,
                            PageListChangedEvent pageListChangedEvent,
                            RelocatePageEvent relocatePageEvent,
                            BookRefreshEvent bookRefreshEvent,
                            DeletePageCommand deletePageCommand,
                            SelectedTabChangedEvent selectedTabChangedEvent,
                            SelectedTabAboutToChangeEvent selectedTabAboutToChangeEvent,
                            LibraryClosing libraryClosingEvent,
                            CollectionSettings collectionSettings,
                            SendReceiver sendReceiver)
        {
            _bookSelection      = bookSelection;
            _pageSelection      = pageSelection;
            _languageSettings   = languageSettings;
            _deletePageCommand  = deletePageCommand;
            _collectionSettings = collectionSettings;
            _sendReceiver       = sendReceiver;

            bookSelection.SelectionChanged      += new EventHandler(OnBookSelectionChanged);
            pageSelection.SelectionChanged      += new EventHandler(OnPageSelectionChanged);
            templateInsertionCommand.InsertPage += new EventHandler(OnInsertTemplatePage);

            bookRefreshEvent.Subscribe((book) => OnBookSelectionChanged(null, null));
            selectedTabChangedEvent.Subscribe(OnTabChanged);
            selectedTabAboutToChangeEvent.Subscribe(OnTabAboutToChange);
            deletePageCommand.Implementer = OnDeletePage;
            pageListChangedEvent.Subscribe(x => _view.UpdatePageList(false));
            relocatePageEvent.Subscribe(OnRelocatePage);
            libraryClosingEvent.Subscribe(o => SaveNow());
            _contentLanguages = new List <ContentLanguage>();
        }
Beispiel #4
0
        public void Setup()
        {
            _storage = new Moq.Mock <IBookStorage>();
            _storage.Setup(x => x.GetLooksOk()).Returns(true);
            _bookDom = new HtmlDom(GetThreePageDom());
            _storage.SetupGet(x => x.Dom).Returns(() => _bookDom);
            _storage.SetupGet(x => x.Key).Returns("testkey");
            _storage.SetupGet(x => x.FileName).Returns("testTitle");
            _storage.SetupGet(x => x.BookType).Returns(Bloom.Book.Book.BookType.Publication);
            _storage.Setup(x => x.GetRelocatableCopyOfDom(It.IsAny <IProgress>())).Returns(() =>
            {
                return
                (_bookDom.Clone());
            });                                                                  // review: the real thing does more than just clone
            _storage.Setup(x => x.MakeDomRelocatable(It.IsAny <HtmlDom>(), It.IsAny <IProgress>())).Returns(
                (HtmlDom x, IProgress y) => { return(x.Clone()); });             // review: the real thing does more than just clone

            _storage.Setup(x => x.GetFileLocator()).Returns(() => _fileLocator.Object);

            _testFolder = new TemporaryFolder("BookTests");
            _tempFolder = new TemporaryFolder(_testFolder, "book");
            MakeSamplePngImageWithMetadata(Path.Combine(_tempFolder.Path, "original.png"));
            _storage.SetupGet(x => x.FolderPath).Returns(_tempFolder.Path);            // review: the real thing does more than just clone


            _templateFinder = new Moq.Mock <ITemplateFinder>();
            _fileLocator    = new Moq.Mock <IFileLocator>();
            string root               = FileLocator.GetDirectoryDistributedWithApplication("BloomBrowserUI");
            string xMatter            = FileLocator.GetDirectoryDistributedWithApplication("xMatter");
            string factoryCollections = FileLocator.GetDirectoryDistributedWithApplication("factoryCollections");
            string templates          = FileLocator.GetDirectoryDistributedWithApplication("factoryCollections", "templates");

            _fileLocator.Setup(x => x.LocateFileWithThrow("languageDisplayTemplate.css")).Returns(root.CombineForPath("bookLayout", "languageDisplayTemplate.css"));
            _fileLocator.Setup(x => x.LocateFileWithThrow("previewMode.css")).Returns("../notareallocation/previewMode.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("editMode.css")).Returns("../notareallocation/editMode.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("editTranslationMode.css")).Returns("../notareallocation/editTranslationMode.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("editOriginalMode.css")).Returns("../notareallocation/editOriginalMode.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("basePage.css")).Returns("../notareallocation/basePage.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("bloomBootstrap.js")).Returns("../notareallocation/bloomBootstrap.js");
            _fileLocator.Setup(x => x.LocateFileWithThrow("bloomPreviewBootstrap.js")).Returns("../notareallocation/bloomPreviewBootstrap.js");
            _fileLocator.Setup(x => x.LocateDirectory("Factory-XMatter")).Returns(xMatter.CombineForPath("Factory-XMatter"));
            _fileLocator.Setup(x => x.LocateDirectory("Factory-XMatter", It.IsAny <string>())).Returns(xMatter.CombineForPath("Factory-XMatter"));
            _fileLocator.Setup(x => x.LocateFileWithThrow("Factory-XMatter".CombineForPath("Factory-XMatter.htm"))).Returns(xMatter.CombineForPath("Factory-XMatter", "Factory-XMatter.htm"));

            //warning: we're neutering part of what the code under test is trying to do here:
            _fileLocator.Setup(x => x.CloneAndCustomize(It.IsAny <IEnumerable <string> >())).Returns(_fileLocator.Object);

            _thumbnailer          = new Moq.Mock <HtmlThumbNailer>(new object[] { 60 });
            _pageSelection        = new Mock <PageSelection>();
            _pageListChangedEvent = new PageListChangedEvent();
        }
Beispiel #5
0
        public Book(BookInfo info, IBookStorage storage, ITemplateFinder templateFinder,
		   CollectionSettings collectionSettings, HtmlThumbNailer thumbnailProvider,
			PageSelection pageSelection,
			PageListChangedEvent pageListChangedEvent,
			BookRefreshEvent bookRefreshEvent)
        {
            BookInfo = info;

            Guard.AgainstNull(storage,"storage");

            // This allows the _storage to
            storage.MetaData = info;

            _storage = storage;

            //this is a hack to keep these two in sync (in one direction)
            _storage.FolderPathChanged +=(x,y)=>BookInfo.FolderPath = _storage.FolderPath;

            _templateFinder = templateFinder;

            _collectionSettings = collectionSettings;

            _thumbnailProvider = thumbnailProvider;
            _pageSelection = pageSelection;
            _pageListChangedEvent = pageListChangedEvent;
            _bookRefreshEvent = bookRefreshEvent;
            _bookData = new BookData(OurHtmlDom,
                    _collectionSettings, UpdateImageMetadataAttributes);

            if (IsEditable && !HasFatalError)
            {
                _bookData.SynchronizeDataItemsThroughoutDOM();

                WriteLanguageDisplayStyleSheet(); //NB: if you try to do this on a file that's in program files, access will be denied
                OurHtmlDom.AddStyleSheet(@"languageDisplay.css");
            }

            FixBookIdAndLineageIfNeeded();
            _storage.Dom.RemoveExtraContentTypesMetas();
            Guard.Against(OurHtmlDom.RawDom.InnerXml=="","Bloom could not parse the xhtml of this document");
        }
        public virtual void Setup()
        {
            _storage = new Moq.Mock<IBookStorage>();
            _storage.Setup(x => x.GetLooksOk()).Returns(true);
            _bookDom = new HtmlDom(GetThreePageDom());
            _storage.SetupGet(x => x.Dom).Returns(() => _bookDom);
            _storage.SetupGet(x => x.Key).Returns("testkey");
            _storage.SetupGet(x => x.FileName).Returns("testTitle");
            _storage.Setup(x => x.GetRelocatableCopyOfDom(It.IsAny<IProgress>())).Returns(() =>
            {
                return
                    _bookDom.Clone();
            });// review: the real thing does more than just clone
            _storage.Setup(x => x.MakeDomRelocatable(It.IsAny<HtmlDom>(), It.IsAny<IProgress>())).Returns(
                (HtmlDom x, IProgress y) => { return x.Clone(); });// review: the real thing does more than just clone

            _storage.Setup(x => x.GetFileLocator()).Returns(() => _fileLocator.Object);

            _testFolder = new TemporaryFolder("BookTests");
            _tempFolder = new TemporaryFolder(_testFolder, "book");
            MakeSamplePngImageWithMetadata(Path.Combine(_tempFolder.Path, "original.png"));
            _storage.SetupGet(x => x.FolderPath).Returns(_tempFolder.Path);// review: the real thing does more than just clone
            _metadata = new BookInfo(_tempFolder.Path, true);
            _storage.SetupGet(x => x.MetaData).Returns(_metadata);
            _storage.Setup(x => x.HandleRetiredXMatterPacks(It.IsAny<HtmlDom>(), It.IsAny<string>()))
                .Returns((HtmlDom dom, string y) => { return y == "BigBook" ? "Factory" : y; });

            _templateFinder = new Moq.Mock<ITemplateFinder>();
            _fileLocator = new Moq.Mock<IFileLocator>();
            string root = FileLocator.GetDirectoryDistributedWithApplication(BloomFileLocator.BrowserRoot);
            string xMatter = BloomFileLocator.GetInstalledXMatterDirectory();
            _fileLocator.Setup(x => x.LocateFileWithThrow("languageDisplay.css")).Returns("../notareallocation/languageDisplay.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("previewMode.css")).Returns("../notareallocation/previewMode.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("origami.css")).Returns("../notareallocation/origami.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("editMode.css")).Returns("../notareallocation/editMode.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("editTranslationMode.css")).Returns("../notareallocation/editTranslationMode.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("editOriginalMode.css")).Returns("../notareallocation/editOriginalMode.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("editPaneGlobal.css")).Returns("../notareallocation/editPaneGlobal.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("basePage.css")).Returns("../notareallocation/basePage.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("bloomBootstrap.js")).Returns("../notareallocation/bloomBootstrap.js");
            _fileLocator.Setup(x => x.LocateFileWithThrow("bloomPreviewBootstrap.js")).Returns("../notareallocation/bloomPreviewBootstrap.js");
            _fileLocator.Setup(x => x.LocateFileWithThrow("baseEPUB.css")).Returns("../notareallocation/baseEPUB.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("customBookStyles.css")).Returns(Path.Combine(_tempFolder.Path, "customBookStyles.css"));
            _fileLocator.Setup(x => x.LocateFileWithThrow("settingsCollectionStyles.css")).Returns(Path.Combine(_testFolder.Path, "settingsCollectionStyles.css"));
            _fileLocator.Setup(x => x.LocateFileWithThrow("customCollectionStyles.css")).Returns(Path.Combine(_testFolder.Path, "customCollectionStyles.css"));

            _fileLocator.Setup(x => x.LocateDirectory("Factory-XMatter")).Returns(xMatter.CombineForPath("Factory-XMatter"));
            _fileLocator.Setup(x => x.LocateDirectoryWithThrow("Factory-XMatter")).Returns(xMatter.CombineForPath("Factory-XMatter"));
            _fileLocator.Setup(x => x.LocateDirectory("Factory-XMatter", It.IsAny<string>())).Returns(xMatter.CombineForPath("Factory-XMatter"));
            _fileLocator.Setup(x => x.LocateFileWithThrow("Factory-XMatter".CombineForPath("Factory-XMatter.htm"))).Returns(xMatter.CombineForPath("Factory-XMatter", "Factory-XMatter.htm"));

            _fileLocator.Setup(x => x.LocateDirectory("Traditional-XMatter")).Returns(xMatter.CombineForPath("Traditional-XMatter"));
            _fileLocator.Setup(x => x.LocateDirectoryWithThrow("Traditional-XMatter")).Returns(xMatter.CombineForPath("Traditional-XMatter"));
            _fileLocator.Setup(x => x.LocateDirectory("Traditional-XMatter", It.IsAny<string>())).Returns(xMatter.CombineForPath("Traditional-XMatter"));
            _fileLocator.Setup(x => x.LocateFileWithThrow("Traditional-XMatter".CombineForPath("Traditional-XMatter.htm"))).Returns(xMatter.CombineForPath("Traditional-XMatter", "Factory-XMatter.htm"));

            _fileLocator.Setup(x => x.LocateDirectory("BigBook-XMatter")).Returns(xMatter.CombineForPath("BigBook-XMatter"));
            _fileLocator.Setup(x => x.LocateDirectoryWithThrow("BigBook-XMatter")).Returns(xMatter.CombineForPath("BigBook-XMatter"));
            _fileLocator.Setup(x => x.LocateDirectory("BigBook-XMatter", It.IsAny<string>())).Returns(xMatter.CombineForPath("BigBook-XMatter"));
            _fileLocator.Setup(x => x.LocateFileWithThrow("BigBook-XMatter".CombineForPath("BigBook-XMatter.htm"))).Returns(xMatter.CombineForPath("BigBook-XMatter", "BigBook-XMatter.htm"));

            //warning: we're neutering part of what the code under test is trying to do here:
            _fileLocator.Setup(x => x.CloneAndCustomize(It.IsAny<IEnumerable<string>>())).Returns(_fileLocator.Object);

            _thumbnailer = new Moq.Mock<HtmlThumbNailer>(new object[] { new NavigationIsolator() });
            _pageSelection = new Mock<PageSelection>();
            _pageListChangedEvent = new PageListChangedEvent();
        }
Beispiel #7
0
        public void Setup()
        {
            _storage = new Moq.Mock<IBookStorage>();
            _storage.Setup(x => x.GetLooksOk()).Returns(true);
            _bookDom = new HtmlDom(GetThreePageDom());
            _storage.SetupGet(x => x.Dom).Returns(() => _bookDom);
            _storage.SetupGet(x => x.Key).Returns("testkey");
            _storage.SetupGet(x => x.FileName).Returns("testTitle");
            _storage.SetupGet(x => x.BookType).Returns(Bloom.Book.Book.BookType.Publication);
            _storage.Setup(x => x.GetRelocatableCopyOfDom(It.IsAny<IProgress>())).Returns(()=>
                                                                                              {
                                                                                                  return
                                                                                                      _bookDom.Clone();
                                                                                              });// review: the real thing does more than just clone
            _storage.Setup(x => x.MakeDomRelocatable(It.IsAny<HtmlDom>(),It.IsAny<IProgress>())).Returns(
                (HtmlDom x, IProgress y) => {return x.Clone();});// review: the real thing does more than just clone

            _storage.Setup(x => x.GetFileLocator()).Returns(()=>_fileLocator.Object);

            _testFolder = new TemporaryFolder("BookTests");
            _tempFolder = new TemporaryFolder(_testFolder, "book");
            MakeSamplePngImageWithMetadata(Path.Combine(_tempFolder.Path,"original.png"));
            _storage.SetupGet(x => x.FolderPath).Returns(_tempFolder.Path);// review: the real thing does more than just clone

            _templateFinder = new Moq.Mock<ITemplateFinder>();
            _fileLocator = new Moq.Mock<IFileLocator>();
            string root = FileLocator.GetDirectoryDistributedWithApplication("BloomBrowserUI");
            string xMatter = FileLocator.GetDirectoryDistributedWithApplication("xMatter");
            string factoryCollections = FileLocator.GetDirectoryDistributedWithApplication("factoryCollections");
            string templates = FileLocator.GetDirectoryDistributedWithApplication("factoryCollections","templates");
            _fileLocator.Setup(x => x.LocateFileWithThrow("languageDisplayTemplate.css")).Returns(root.CombineForPath("bookLayout","languageDisplayTemplate.css"));
            _fileLocator.Setup(x => x.LocateFileWithThrow("previewMode.css")).Returns("../notareallocation/previewMode.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("editMode.css")).Returns("../notareallocation/editMode.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("editTranslationMode.css")).Returns("../notareallocation/editTranslationMode.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("editOriginalMode.css")).Returns("../notareallocation/editOriginalMode.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("basePage.css")).Returns("../notareallocation/basePage.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("bloomBootstrap.js")).Returns("../notareallocation/bloomBootstrap.js");
            _fileLocator.Setup(x => x.LocateFileWithThrow("bloomPreviewBootstrap.js")).Returns("../notareallocation/bloomPreviewBootstrap.js");
            _fileLocator.Setup(x => x.LocateDirectory("Factory-XMatter")).Returns(xMatter.CombineForPath("Factory-XMatter"));
            _fileLocator.Setup(x => x.LocateDirectory("Factory-XMatter", It.IsAny<string>())).Returns(xMatter.CombineForPath("Factory-XMatter"));
            _fileLocator.Setup(x => x.LocateFileWithThrow("Factory-XMatter".CombineForPath("Factory-XMatter.htm"))).Returns(xMatter.CombineForPath("Factory-XMatter", "Factory-XMatter.htm"));

            //warning: we're neutering part of what the code under test is trying to do here:
            _fileLocator.Setup(x => x.CloneAndCustomize(It.IsAny<IEnumerable<string>>())).Returns(_fileLocator.Object);

            _thumbnailer = new Moq.Mock<HtmlThumbNailer>(new object[] { 60 });
            _pageSelection = new Mock<PageSelection>();
            _pageListChangedEvent = new PageListChangedEvent();
        }
        public virtual void Setup()
        {
            _testFolder = new TemporaryFolder(GetTestFolderName());
            _tempFolder = new TemporaryFolder(_testFolder, "book");

            _bookDom = new HtmlDom(GetThreePageDom());             // a default, many tests replace this
            // Note that we're passing a function which returns the _bookDom member variable. By the time we return it,
            // it may have a different value than the _bookDom created on the previous line.
            // Thus, we are making a mock storage which, unlike a real one, doesn't itself
            // store a DOM set at creation; many tests update _bookDom to something else AFTER
            // this setup routine makes the Storage they use in their books.
            _storage  = MakeMockStorage(_tempFolder.Path, () => _bookDom);
            _bookDom  = _storage.Object.Dom;
            _metadata = _storage.Object.BookInfo;

            _templateFinder = new Moq.Mock <ITemplateFinder>();
            _fileLocator    = new Moq.Mock <IFileLocator>();
            string root    = FileLocationUtilities.GetDirectoryDistributedWithApplication(BloomFileLocator.BrowserRoot);
            string xMatter = BloomFileLocator.GetInstalledXMatterDirectory();

            _fileLocator.Setup(x => x.LocateFileWithThrow("langVisibility.css")).Returns("../notareallocation/langVisibility.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("previewMode.css")).Returns("../notareallocation/previewMode.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("origami.css")).Returns("../notareallocation/origami.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("origamiEditing.css")).Returns("../notareallocation/origamiEditing.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("editMode.css")).Returns("../notareallocation/editMode.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("editTranslationMode.css")).Returns("../notareallocation/editTranslationMode.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("editOriginalMode.css")).Returns("../notareallocation/editOriginalMode.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("editPaneGlobal.css")).Returns("../notareallocation/editPaneGlobal.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("basePage.css")).Returns("../notareallocation/basePage.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("bloomBootstrap.js")).Returns("../notareallocation/bloomBootstrap.js");
            _fileLocator.Setup(x => x.LocateFileWithThrow("bloomPreviewBootstrap.js")).Returns("../notareallocation/bloomPreviewBootstrap.js");
            _fileLocator.Setup(x => x.LocateFileWithThrow("baseEPUB.css")).Returns("../notareallocation/baseEPUB.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("Device-XMatter.css")).Returns("../notareallocation/Device-XMatter.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("customBookStyles.css")).Returns(Path.Combine(_tempFolder.Path, "customBookStyles.css"));
            _fileLocator.Setup(x => x.LocateFileWithThrow("defaultLangStyles.css")).Returns(Path.Combine(_testFolder.Path, "defaultLangStyles.css"));
            _fileLocator.Setup(x => x.LocateFileWithThrow("customCollectionStyles.css")).Returns(Path.Combine(_testFolder.Path, "customCollectionStyles.css"));
            var basicBookPath = BloomFileLocator.GetCodeBaseFolder() + "/../browser/templates/template books/Basic Book/Basic Book.css";

            _fileLocator.Setup(x => x.LocateFile("Basic Book.css")).Returns(basicBookPath);

            _fileLocator.Setup(x => x.LocateDirectory("Factory-XMatter")).Returns(xMatter.CombineForPath("Factory-XMatter"));
            _fileLocator.Setup(x => x.LocateDirectoryWithThrow("Factory-XMatter")).Returns(xMatter.CombineForPath("Factory-XMatter"));
            _fileLocator.Setup(x => x.LocateDirectory("Factory-XMatter", It.IsAny <string>())).Returns(xMatter.CombineForPath("Factory-XMatter"));
            _fileLocator.Setup(x => x.LocateFileWithThrow("Factory-XMatter".CombineForPath("Factory-XMatter.htm"))).Returns(xMatter.CombineForPath("Factory-XMatter", "Factory-XMatter.htm"));

            _fileLocator.Setup(x => x.LocateDirectory("Traditional-XMatter")).Returns(xMatter.CombineForPath("Traditional-XMatter"));
            _fileLocator.Setup(x => x.LocateDirectoryWithThrow("Traditional-XMatter")).Returns(xMatter.CombineForPath("Traditional-XMatter"));
            _fileLocator.Setup(x => x.LocateDirectory("Traditional-XMatter", It.IsAny <string>())).Returns(xMatter.CombineForPath("Traditional-XMatter"));
            _fileLocator.Setup(x => x.LocateFileWithThrow("Traditional-XMatter".CombineForPath("Traditional-XMatter.htm"))).Returns(xMatter.CombineForPath("Traditional-XMatter", "Factory-XMatter.htm"));


            _fileLocator.Setup(x => x.LocateDirectory("BigBook-XMatter")).Returns(xMatter.CombineForPath("BigBook-XMatter"));
            _fileLocator.Setup(x => x.LocateDirectoryWithThrow("BigBook-XMatter")).Returns(xMatter.CombineForPath("BigBook-XMatter"));
            _fileLocator.Setup(x => x.LocateDirectory("BigBook-XMatter", It.IsAny <string>())).Returns(xMatter.CombineForPath("BigBook-XMatter"));
            _fileLocator.Setup(x => x.LocateFileWithThrow("BigBook-XMatter".CombineForPath("BigBook-XMatter.htm"))).Returns(xMatter.CombineForPath("BigBook-XMatter", "BigBook-XMatter.htm"));

            //warning: we're neutering part of what the code under test is trying to do here:
            _fileLocator.Setup(x => x.CloneAndCustomize(It.IsAny <IEnumerable <string> >())).Returns(_fileLocator.Object);

            _thumbnailer          = new Moq.Mock <HtmlThumbNailer>(new object[] { NavigationIsolator.GetOrCreateTheOneNavigationIsolator() });
            _pageSelection        = new Mock <PageSelection>();
            _pageListChangedEvent = new PageListChangedEvent();
        }
Beispiel #9
0
        public virtual void Setup()
        {
            _storage = new Moq.Mock <IBookStorage>();
            _storage.Setup(x => x.GetLooksOk()).Returns(true);
            _bookDom = new HtmlDom(GetThreePageDom());
            _storage.SetupGet(x => x.Dom).Returns(() => _bookDom);
            _storage.SetupGet(x => x.Key).Returns("testkey");
            _storage.SetupGet(x => x.FileName).Returns("testTitle");
            _storage.Setup(x => x.GetRelocatableCopyOfDom()).Returns(() =>
            {
                return
                (_bookDom.Clone());
            });                                         // review: the real thing does more than just clone
            _storage.Setup(x => x.MakeDomRelocatable(It.IsAny <HtmlDom>())).Returns(
                (HtmlDom x) => { return(x.Clone()); }); // review: the real thing does more than just clone

            _storage.Setup(x => x.GetFileLocator()).Returns(() => _fileLocator.Object);

            _testFolder = new TemporaryFolder("BookTests");
            _tempFolder = new TemporaryFolder(_testFolder, "book");
            MakeSamplePngImageWithMetadata(Path.Combine(_tempFolder.Path, "original.png"));
            _storage.SetupGet(x => x.FolderPath).Returns(_tempFolder.Path);            // review: the real thing does more than just clone
            _metadata = new BookInfo(_tempFolder.Path, true);
            _storage.SetupGet(x => x.MetaData).Returns(_metadata);
            _storage.Setup(x => x.HandleRetiredXMatterPacks(It.IsAny <HtmlDom>(), It.IsAny <string>()))
            .Returns((HtmlDom dom, string y) => { return(y == "BigBook" ? "Factory" : y); });

            _templateFinder = new Moq.Mock <ITemplateFinder>();
            _fileLocator    = new Moq.Mock <IFileLocator>();
            string root    = FileLocator.GetDirectoryDistributedWithApplication(BloomFileLocator.BrowserRoot);
            string xMatter = BloomFileLocator.GetInstalledXMatterDirectory();

            _fileLocator.Setup(x => x.LocateFileWithThrow("languageDisplay.css")).Returns("../notareallocation/languageDisplay.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("previewMode.css")).Returns("../notareallocation/previewMode.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("origami.css")).Returns("../notareallocation/origami.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("editMode.css")).Returns("../notareallocation/editMode.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("editTranslationMode.css")).Returns("../notareallocation/editTranslationMode.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("editOriginalMode.css")).Returns("../notareallocation/editOriginalMode.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("editPaneGlobal.css")).Returns("../notareallocation/editPaneGlobal.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("basePage.css")).Returns("../notareallocation/basePage.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("bloomBootstrap.js")).Returns("../notareallocation/bloomBootstrap.js");
            _fileLocator.Setup(x => x.LocateFileWithThrow("bloomPreviewBootstrap.js")).Returns("../notareallocation/bloomPreviewBootstrap.js");
            _fileLocator.Setup(x => x.LocateFileWithThrow("baseEPUB.css")).Returns("../notareallocation/baseEPUB.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("customBookStyles.css")).Returns(Path.Combine(_tempFolder.Path, "customBookStyles.css"));
            _fileLocator.Setup(x => x.LocateFileWithThrow("settingsCollectionStyles.css")).Returns(Path.Combine(_testFolder.Path, "settingsCollectionStyles.css"));
            _fileLocator.Setup(x => x.LocateFileWithThrow("customCollectionStyles.css")).Returns(Path.Combine(_testFolder.Path, "customCollectionStyles.css"));
            var basicBookPath = BloomFileLocator.GetCodeBaseFolder() + "/../browser/templates/template books/Basic Book/Basic Book.css";

            _fileLocator.Setup(x => x.LocateFile("Basic Book.css")).Returns(basicBookPath);

            _fileLocator.Setup(x => x.LocateDirectory("Factory-XMatter")).Returns(xMatter.CombineForPath("Factory-XMatter"));
            _fileLocator.Setup(x => x.LocateDirectoryWithThrow("Factory-XMatter")).Returns(xMatter.CombineForPath("Factory-XMatter"));
            _fileLocator.Setup(x => x.LocateDirectory("Factory-XMatter", It.IsAny <string>())).Returns(xMatter.CombineForPath("Factory-XMatter"));
            _fileLocator.Setup(x => x.LocateFileWithThrow("Factory-XMatter".CombineForPath("Factory-XMatter.htm"))).Returns(xMatter.CombineForPath("Factory-XMatter", "Factory-XMatter.htm"));

            _fileLocator.Setup(x => x.LocateDirectory("Traditional-XMatter")).Returns(xMatter.CombineForPath("Traditional-XMatter"));
            _fileLocator.Setup(x => x.LocateDirectoryWithThrow("Traditional-XMatter")).Returns(xMatter.CombineForPath("Traditional-XMatter"));
            _fileLocator.Setup(x => x.LocateDirectory("Traditional-XMatter", It.IsAny <string>())).Returns(xMatter.CombineForPath("Traditional-XMatter"));
            _fileLocator.Setup(x => x.LocateFileWithThrow("Traditional-XMatter".CombineForPath("Traditional-XMatter.htm"))).Returns(xMatter.CombineForPath("Traditional-XMatter", "Factory-XMatter.htm"));


            _fileLocator.Setup(x => x.LocateDirectory("BigBook-XMatter")).Returns(xMatter.CombineForPath("BigBook-XMatter"));
            _fileLocator.Setup(x => x.LocateDirectoryWithThrow("BigBook-XMatter")).Returns(xMatter.CombineForPath("BigBook-XMatter"));
            _fileLocator.Setup(x => x.LocateDirectory("BigBook-XMatter", It.IsAny <string>())).Returns(xMatter.CombineForPath("BigBook-XMatter"));
            _fileLocator.Setup(x => x.LocateFileWithThrow("BigBook-XMatter".CombineForPath("BigBook-XMatter.htm"))).Returns(xMatter.CombineForPath("BigBook-XMatter", "BigBook-XMatter.htm"));

            //warning: we're neutering part of what the code under test is trying to do here:
            _fileLocator.Setup(x => x.CloneAndCustomize(It.IsAny <IEnumerable <string> >())).Returns(_fileLocator.Object);

            _thumbnailer          = new Moq.Mock <HtmlThumbNailer>(new object[] { new NavigationIsolator() });
            _pageSelection        = new Mock <PageSelection>();
            _pageListChangedEvent = new PageListChangedEvent();
        }
Beispiel #10
0
        public Book(BookInfo info, IBookStorage storage, ITemplateFinder templateFinder,
		   CollectionSettings collectionSettings,
			PageSelection pageSelection,
			PageListChangedEvent pageListChangedEvent,
			BookRefreshEvent bookRefreshEvent)
        {
            BookInfo = info;
            UserPrefs = UserPrefs.LoadOrMakeNew(Path.Combine(info.FolderPath, "book.userPrefs"));

            Guard.AgainstNull(storage,"storage");

            // This allows the _storage to
            storage.MetaData = info;

            _storage = storage;

            //this is a hack to keep these two in sync (in one direction)
            _storage.FolderPathChanged += _storage_FolderPathChanged;

            _templateFinder = templateFinder;

            _collectionSettings = collectionSettings;

            _pageSelection = pageSelection;
            _pageListChangedEvent = pageListChangedEvent;
            _bookRefreshEvent = bookRefreshEvent;
            _bookData = new BookData(OurHtmlDom,
                    _collectionSettings, UpdateImageMetadataAttributes);

            InjectStringListingActiveLanguagesOfBook();

            if (!HasFatalError && IsEditable)
            {
                _bookData.SynchronizeDataItemsThroughoutDOM();
            }

            //if we're showing the user a shell/template book, pick a color for it
            //If it is editable, then we don't want to change to the next color, we
            //want to use the color that we used for the sample shell/template we
            //showed them previously.
            if (!info.IsEditable)
            {
                Book.SelectNextCoverColor(); // we only increment when showing a template or shell
                InitCoverColor();
            }

            // If it doesn't already have a cover color give it one.
            if (OurHtmlDom.SafeSelectNodes("//head/style/text()[contains(., 'coverColor')]").Count == 0)
            {
                InitCoverColor(); // should use the same color as what they saw in the preview of the template/shell
            }
            FixBookIdAndLineageIfNeeded();
            _storage.Dom.RemoveExtraBookTitles();
            _storage.Dom.RemoveExtraContentTypesMetas();
            Guard.Against(OurHtmlDom.RawDom.InnerXml=="","Bloom could not parse the xhtml of this document");
        }
Beispiel #11
0
        //autofac uses this
        public EditingModel(BookSelection bookSelection, PageSelection pageSelection,
			TemplateInsertionCommand templateInsertionCommand,
			PageListChangedEvent pageListChangedEvent,
			RelocatePageEvent relocatePageEvent,
			BookRefreshEvent bookRefreshEvent,
			PageRefreshEvent pageRefreshEvent,
			DuplicatePageCommand duplicatePageCommand,
			DeletePageCommand deletePageCommand,
			SelectedTabChangedEvent selectedTabChangedEvent,
			SelectedTabAboutToChangeEvent selectedTabAboutToChangeEvent,
			LibraryClosing libraryClosingEvent,
			LocalizationChangedEvent localizationChangedEvent,
			CollectionSettings collectionSettings,
			//SendReceiver sendReceiver,
			EnhancedImageServer server,
			BloomWebSocketServer webSocketServer)
        {
            _bookSelection = bookSelection;
            _pageSelection = pageSelection;
            _duplicatePageCommand = duplicatePageCommand;
            _deletePageCommand = deletePageCommand;
            _collectionSettings = collectionSettings;
            //_sendReceiver = sendReceiver;
            _server = server;
            _webSocketServer = webSocketServer;
            _templatePagesDict = null;

            bookSelection.SelectionChanged += new EventHandler(OnBookSelectionChanged);
            pageSelection.SelectionChanged += new EventHandler(OnPageSelectionChanged);
            pageSelection.SelectionChanging += OnPageSelectionChanging;
            templateInsertionCommand.InsertPage += new EventHandler(OnInsertTemplatePage);

            bookRefreshEvent.Subscribe((book) => OnBookSelectionChanged(null, null));
            pageRefreshEvent.Subscribe((PageRefreshEvent.SaveBehavior behavior) =>
            {
                switch (behavior)
                {
                    case PageRefreshEvent.SaveBehavior.SaveBeforeRefresh:
                        RethinkPageAndReloadIt(null);
                        break;

                    case PageRefreshEvent.SaveBehavior.JustRedisplay:
                        RefreshDisplayOfCurrentPage();
                        break;
                }
            });

            selectedTabChangedEvent.Subscribe(OnTabChanged);
            selectedTabAboutToChangeEvent.Subscribe(OnTabAboutToChange);
            duplicatePageCommand.Implementer = OnDuplicatePage;
            deletePageCommand.Implementer = OnDeletePage;
            pageListChangedEvent.Subscribe(x => _view.UpdatePageList(false));
            relocatePageEvent.Subscribe(OnRelocatePage);
            libraryClosingEvent.Subscribe(o =>
            {
                if (Visible)
                    SaveNow();
            });
            localizationChangedEvent.Subscribe(o =>
            {
                //this is visible was added for https://jira.sil.org/browse/BL-267, where the edit tab has never been
                //shown so the view has never been full constructed, so we're not in a good state to do a refresh
                if (Visible)
                {
                    SaveNow();
                    _view.UpdateButtonLocalizations();
                    RefreshDisplayOfCurrentPage();
                    //_view.UpdateDisplay();
                    _view.UpdatePageList(false);
                }
                else if (_view != null)
                {
                    // otherwise changing UI language in Publish tab (for instance) won't update these localizations
                    _view.UpdateButtonLocalizations();
                }
            });
            _contentLanguages = new List<ContentLanguage>();
            _server.CurrentCollectionSettings = _collectionSettings;
        }