Пример #1
0
        public override void FinishInit()
        {
            m_chorusSystem = new ChorusSystem(Cache.ProjectId.ProjectFolder);
            m_chorusSystem.InitWithoutHg(SendReceiveUser);
            // This is a required object for CreateNotesBar. It specifies delegates for getting the information
            // the bar requires about the current object.
            var notesToRecordMapping = new NotesToRecordMapping()
            {
                FunctionToGetCurrentUrlForNewNotes    = GetCurrentUrlForNewNotes,
                FunctionToGoFromObjectToItsId         = GetIdForObject,
                FunctionToGoFromObjectToAdditionalIds = GetAdditionalIdsForObject
            };
            var          dataFilePath        = GetDataFilePath(Cache);
            var          additionalPaths     = GetAdditionalLexiconFilePaths(Cache);
            const string idAttrForOtherFiles = "guid";             // .lexdb chorus notes files identify FLEx object with a url attr of "guid".

            m_notesBar = m_chorusSystem.WinForms.CreateNotesBar(dataFilePath, additionalPaths, idAttrForOtherFiles, notesToRecordMapping, new NullProgress());
            m_notesBar.SetTargetObject(m_obj);
            // Set the writing systems for the NoteDetailDialog.  (See FWNX-1239.)
            var vernWs  = Cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem;
            var labelWs = new ChorusWritingSystem(vernWs.LanguageName, vernWs.RFC5646, vernWs.DefaultFontName, 12);

            m_notesBar.LabelWritingSystem = labelWs;
            var analWs = Cache.ServiceLocator.WritingSystems.DefaultAnalysisWritingSystem;
            var msgWs  = new ChorusWritingSystem(analWs.LanguageName, analWs.RFC5646, analWs.DefaultFontName, 12);

            m_notesBar.MessageWritingSystem = msgWs;
            this.Control = m_notesBar;
        }
Пример #2
0
 public void CreateARepositoryIfOneDoesntAlreadyExist()
 {
     var cs = new ChorusSystem(_dataFolderRoot);
     cs.Init(string.Empty);
     //before your application closes, call:
     cs.Dispose();
 }
        /// <summary>
        /// Start doing whatever is needed for the supported type of action.
        /// </summary>
        public void StartWorking(Dictionary <string, string> commandLineArgs)
        {
            _fwProjectFolder = Path.GetDirectoryName(commandLineArgs["-p"]);

            MainForm = new MainBridgeForm
            {
                ClientSize = new Size(904, 510)
            };
            _chorusUser   = new ChorusUser(commandLineArgs["-u"]);
            _chorusSystem = Utilities.InitializeChorusSystem(Utilities.LiftOffset(_fwProjectFolder), _chorusUser.Name, LiftFolder.AddLiftFileInfoToFolderConfiguration);
            _chorusSystem.EnsureAllNotesRepositoriesLoaded();

            _notesBrowser = _chorusSystem.WinForms.CreateNotesBrowser();
            var conflictHandler = _notesBrowser.MessageContentHandlerRepository.KnownHandlers.OfType <MergeConflictEmbeddedMessageContentHandler>().First();

            _chorusSystem.NavigateToRecordEvent.Subscribe(JumpToLiftObject);
            conflictHandler.HtmlAdjuster = AdjustConflictHtml;
            if (_connectionHelper != null)
            {
                JumpUrlChanged += _connectionHelper.SendJumpUrlToFlex;
            }

            var viewer = new BridgeConflictView();

            MainForm.Controls.Add(viewer);
            MainForm.Text = viewer.Text;
            viewer.Dock   = DockStyle.Fill;
            viewer.SetBrowseView(_notesBrowser);

            // Only used by FLEx, so how can it not be in use?
            //if (_currentLanguageProject.FieldWorkProjectInUse)
            //	viewer.EnableWarning();
            viewer.SetProjectName(LiftUtilties.GetLiftProjectName(_fwProjectFolder));
        }
Пример #4
0
        public DataEditor(ChorusSystem chorusSystem, string dataFilePath)
        {
            _chorusSystem = chorusSystem;
            _dataFilePath = dataFilePath;
            InitializeComponent();

            var notesToRecordMapping = new NotesToRecordMapping()
            {
                FunctionToGetCurrentUrlForNewNotes = GetCurrentUrlForNewNotes,
                FunctionToGoFromObjectToItsId      = GetIdForObject
            };

            _notesBar          = _chorusSystem.WinForms.CreateNotesBar(dataFilePath, notesToRecordMapping, new NullProgress());
            _notesBar.Location = new Point(10, 6);
            this.Controls.Add(_notesBar);

            XmlDocument doc = new XmlDocument();

            doc.Load(dataFilePath);

            var areas = doc.SelectNodes("//area");

            _area1Text.Tag  = _area1Label.Text = areas[0].Attributes["id"].Value;
            _area1Text.Text = areas[0].InnerText.Trim();

            _area2Text.Tag  = _area2Label.Text = areas[1].Attributes["id"].Value;
            _area2Text.Text = areas[1].InnerText.Trim();
        }
Пример #5
0
 public void Dispose()
 {
     if (_chorusSystem != null)
     {
         _chorusSystem.Dispose();
     }
     _chorusSystem = null;
 }
Пример #6
0
        public void CreateARepositoryIfOneDoesntAlreadyExist()
        {
            var cs = new ChorusSystem(_dataFolderRoot);

            cs.Init(string.Empty);
            //before your application closes, call:
            cs.Dispose();
        }
Пример #7
0
        public void Dispose()
        {
            if (_chorusSystem != null)
            {
                _chorusSystem.Dispose();
            }
            _chorusSystem = null;

            GC.SuppressFinalize(this);
        }
Пример #8
0
        public void Setup()
        {
            _tempFolder       = new TemporaryFolder("ChorusSystemUsage");
            _dataFolderRoot   = _tempFolder.Path;
            _someDataFile     = new TempFileFromFolder(_tempFolder, "test.txt", "hello");
            _someDataFilePath = _someDataFile.Path;

            _chorusSystem = new ChorusSystem(_dataFolderRoot);
            _chorusSystem.Init("john");
        }
Пример #9
0
        /// <summary>
        /// Creates and initializes the ChorusSystem for use in FLExBridge
        /// </summary>
        public static ChorusSystem InitializeChorusSystem(string directoryName, string user, Action <ProjectFolderConfiguration> configure)
        {
            var system = new ChorusSystem(directoryName);

            system.Init(user);
            if (configure != null)
            {
                configure(system.ProjectFolderConfiguration);
            }
            return(system);
        }
Пример #10
0
        protected override void Dispose(bool disposing)
        {
            if (!IsDisposed && disposing)
            {
                m_chorusSystem?.Dispose();
                // m_notesBar is stored in Control, which is disposed by base.Dispose.
            }

            m_chorusSystem = null;
            m_notesBar     = null;

            base.Dispose(disposing);
        }
        public delegate HistoryAndNotesDialog Factory();        //autofac uses this

        public HistoryAndNotesDialog(ChorusSystem chorusSystem)
        {
            InitializeComponent();

#if notes
            var notes = chorusSystem.WinForms.CreateNotesBrowser();
            notes.Dock = DockStyle.Fill;
            _notesPage.Controls.Add(notes);
#else
            tabControl1.Controls.Remove(_notesPage);
#endif
            var history = chorusSystem.WinForms.CreateHistoryPage();
            history.Dock = DockStyle.Fill;
            _historyPage.Controls.Add(history);
        }
Пример #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="chorusSystem"></param>
        /// <param name="getFormWithContextForInvokingErrorDialogs">using a function here rather than a value
        /// becuase this class is created by the dependency injection system while building up this for (a
        /// project window), so that value isn't available yet.</param>
        public SendReceiver(ChorusSystem chorusSystem, Func <Form> getFormWithContextForInvokingErrorDialogs)        //, Form formWithContextForInvokingErrorDialogs)
        {
            _getFormWithContextForInvokingErrorDialogs = getFormWithContextForInvokingErrorDialogs;
            //Guard.AgainstNull(formWithContextForInvokingErrorDialogs, "formWithContextForInvokingErrorDialogs");
            //_formWithContextForInvokingErrorDialogs = formWithContextForInvokingErrorDialogs;

            //we don't do chorus on our source tree
            SendReceiveDisabled = !Settings.Default.ShowSendReceive || !chorusSystem.DidLoadUpCorrectly || chorusSystem.ProjectFolderConfiguration.FolderPath.ToLower().Contains("distfiles");

            if (!SendReceiveDisabled)
            {
                _chorusSystem = chorusSystem;
                BloomChorusRules.AddFileInfoToFolderConfiguration(_chorusSystem.ProjectFolderConfiguration);
            }
        }
        private void InstallExistingSystemControl()
        {
            if (_startupNewView != null)
            {
                _startupNewView.Startup -= Startup;
            }

            var chorusSystem = new ChorusSystem(LiftProjectServices.PathToProject(Liftproject), Environment.UserName);

            LiftFolder.AddLiftFileInfoToFolderConfiguration(chorusSystem.ProjectFolderConfiguration);
            _existingSystemView.SetSystem(chorusSystem, Liftproject);
            _liftBridgeView.ActivateView(_existingSystemView);
            _existingSystemView.ImportLexicon      += OnImportLexicon;
            _existingSystemView.ExportLexicon      += OnExportLexicon;
            _existingSystemView.BasicImportLexicon += OnBasicImport;
        }
Пример #14
0
        public void Setup()
        {
            _folder            = new TemporaryFolder("ChorusSystemTests_" + Path.GetRandomFileName());
            _targetFile1       = new TempFileFromFolder(_folder, "one.txt", "just a pretend file");
            _existingNotesFile = new TempFileFromFolder(_folder, "one.txt." + AnnotationRepository.FileExtension,
                                                        @"<notes version='0'>
					<annotation ref='somwhere://foo?id=x' class='mergeConflict'>
						<message guid='123' author='merger' status='open' date='2009-07-18T23:53:04Z'>
							some description of the conflict
						</message>
					</annotation>
				</notes>"                );

            _system = new ChorusSystem(_folder.Path);
            _system.Init(string.Empty);
        }
Пример #15
0
        public void SetSystem(ChorusSystem chorusSystem, LiftProject liftProject)
        {
            _chorusSystem = chorusSystem;
            _liftProject  = liftProject;

            var notesBrowser = _chorusSystem.WinForms.CreateNotesBrowser();

            _tpNotes.Controls.Add(notesBrowser);
            notesBrowser.Dock = DockStyle.Fill;

            var historyPage = _chorusSystem.WinForms.CreateHistoryPage();

            _tpHistory.Controls.Add(historyPage);
            historyPage.Dock = DockStyle.Fill;

            //_tpAbout
        }
Пример #16
0
 /// <summary>
 /// Determine if the object really has data to be shown in the slice. This method is called by reflection
 /// from DataTree.AddSimpleNode, to determine whether to create the slice when visibility is "ifdata".
 /// </summary>
 /// <param name="obj">object to check; should be an ILexEntry</param>
 /// <returns>true if there are chorus notes for this object; false otherwise</returns>
 public static bool ShowSliceForVisibleIfData(XmlNode node, ICmObject obj)
 {
     using (var chorusSystem = new ChorusSystem(obj.Cache.ProjectId.ProjectFolder))
     {
         chorusSystem.InitWithoutHg(SendReceiveUser);
         // This is a required object for CreateNotesBar. It specifies delegates for getting the information
         // the bar requires about the current object. For this model the FunctionToGetCurrentUrlForNewNotes will not be used.
         var notesToRecordMapping = new NotesToRecordMapping()
         {
             FunctionToGetCurrentUrlForNewNotes = DummyGetCurrentUrlForNewNotes,
             FunctionToGoFromObjectToItsId      = GetIdForObject
         };
         var dataFilePath = GetDataFilePath(obj.Cache);
         var notesmodel   = chorusSystem.WinForms.CreateNotesBarModel(dataFilePath, notesToRecordMapping, new NullProgress());
         notesmodel.SetTargetObject(obj);
         return(notesmodel.GetAnnotationsToShow().Any());
     }
 }
Пример #17
0
        private void ChangeSimulatedUser(string userName)
        {
            ClearOutInAnticipationOfSwitchingUsers();

            var dir = Path.Combine(_testDirectory, userName);

            if (!Directory.Exists(dir))
            {
                UnZipToDirectory(dir);
            }

            var shoppingListDir = Path.Combine(dir, "ShoppingList");

            //note: if you don't have a user name, you can just let chorus try to figure one out.
            //Also note that this is not the same name as that used for any given network repository credentials;
            //Rather, it's the name which will show in the history, and besides Notes that this user makes.
            _chorusSystem = new ChorusSystem(shoppingListDir);
            _chorusSystem.DisplaySettings = new ChorusNotesDisplaySettings()
            {
                WritingSystemForNoteLabel   = new TestWritingSystem("Algerian"),
                WritingSystemForNoteContent = new TestWritingSystem("Bradley Hand ITC")
            };

            _chorusSystem.Init(userName);


            _chorusSystem.Repository.SetKnownRepositoryAddresses(new RepositoryAddress[] { _serverRepository });

            _chorusSystem.ProjectFolderConfiguration.IncludePatterns.Add("*.xml");

            _dataEditor      = new DataEditor(_chorusSystem, Path.Combine(shoppingListDir, "shopping.xml"));
            _dataEditor.Dock = DockStyle.Fill;
            _frontPage.Controls.Add(_dataEditor);

            _notesBrowserControl      = _chorusSystem.WinForms.CreateNotesBrowser();
            _notesBrowserControl.Dock = DockStyle.Fill;
            _notesPage.Controls.Add(_notesBrowserControl);

            _historyControl      = _chorusSystem.WinForms.CreateHistoryPage();
            _historyControl.Dock = DockStyle.Fill;
            _historyPage.Controls.Add(_historyControl);
        }
Пример #18
0
        public void ShowNotesBar()
        {
            using (var folder = new TemporaryFolder("NotesModelTests"))
            using (var dataFile = new TempFileFromFolder(folder, "one.txt", "just a pretend file"))
            using (new TempFileFromFolder(folder, "one.txt." + AnnotationRepository.FileExtension,
                @"<notes version='0'>
                    <annotation ref='somwhere://foo?id=x' class='question'>
                        <message guid='123' author='john' status='open' date='2009-07-18T23:53:04Z'>
                            Suzie, is this ok?
                        </message>
                        <message guid='222' author='suzie' status='closed' date='2009-09-19T23:53:04Z'>
                            It's fine.
                        </message>
                    </annotation>
                    <annotation ref='lift://name%20with%20space.lift?id=x' class='mergeConflict'>
                        <message guid='123' author='merger' status='open' date='2009-07-18T23:53:04Z'>
                            some description of the conflict
                        </message>
                    </annotation>
                    <annotation ref='somwhere://foo2?id=y' class='note'/>
                </notes>"))
            {
                var chorus = new ChorusSystem(folder.Path);
                var view = chorus.WinForms.CreateNotesBar(dataFile.Path, NotesToRecordMapping.SimpleForTest(), _progress);
                view.Height = 32;
                view.SetTargetObject("x");

                TextBox b = new TextBox();
                b.Location = new Point(0, 50);
                b.Text = "x";
                b.TextChanged += new EventHandler((s,e)=>view.SetTargetObject(b.Text));
                var form = new Form();
                form.Size = new Size(700, 600);
                form.Controls.Add(view);
                form.Controls.Add(b);

                Application.EnableVisualStyles();
                Application.Run(form);
            }
        }
Пример #19
0
        public void ShowNotesBar()
        {
            using (var folder = new TemporaryFolder("NotesModelTests"))
                using (var dataFile = new TempFileFromFolder(folder, "one.txt", "just a pretend file"))
                    using (new TempFileFromFolder(folder, "one.txt." + AnnotationRepository.FileExtension,
                                                  @"<notes version='0'>
					<annotation ref='somwhere://foo?id=x' class='question'>
						<message guid='123' author='john' status='open' date='2009-07-18T23:53:04Z'>
							Suzie, is this ok?
						</message>
						<message guid='222' author='suzie' status='closed' date='2009-09-19T23:53:04Z'>
							It's fine.
						</message>
					</annotation>
					<annotation ref='lift://name%20with%20space.lift?id=x' class='mergeConflict'>
						<message guid='123' author='merger' status='open' date='2009-07-18T23:53:04Z'>
							some description of the conflict
						</message>
					</annotation>
					<annotation ref='somwhere://foo2?id=y' class='note'/>
				</notes>"                ))
                    {
                        var chorus = new ChorusSystem(folder.Path);
                        var view   = chorus.WinForms.CreateNotesBar(dataFile.Path, NotesToRecordMapping.SimpleForTest(), _progress);
                        view.Height = 32;
                        view.SetTargetObject("x");

                        TextBox b = new TextBox();
                        b.Location     = new Point(0, 50);
                        b.Text         = "x";
                        b.TextChanged += new EventHandler((s, e) => view.SetTargetObject(b.Text));
                        var form = new Form();
                        form.Size = new Size(700, 600);
                        form.Controls.Add(view);
                        form.Controls.Add(b);

                        Application.EnableVisualStyles();
                        Application.Run(form);
                    }
        }
Пример #20
0
 public GetFileFromRevisionRange(string repoLocation, ChorusSystem chorusSystem)
 {
     InitializeComponent();
     _repoLocation = repoLocation;
     _chorusSystem = chorusSystem;
 }
 public void SetSystem(ChorusSystem chorusSystem, LiftProject liftProject)
 {
     ChorusSys = chorusSystem;
     Project   = liftProject;
 }
Пример #22
0
        /// ------------------------------------------------------------------------------------
        protected void BuildSubContainerForThisProject(string projectSettingsPath, IContainer parentContainer)
        {
            var editableCollectionDirectory = Path.GetDirectoryName(projectSettingsPath);

            _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(DuplicatePageCommand),
                    typeof(DeletePageCommand),
                    typeof(EditBookCommand),
                    typeof(SendReceiveCommand),
                    typeof(SelectedTabAboutToChangeEvent),
                    typeof(SelectedTabChangedEvent),
                    typeof(LibraryClosing),
                    typeof(PageListChangedEvent),                      // REMOVE+++++++++++++++++++++++++++
                    typeof(BookRefreshEvent),
                    typeof(BookDownloadStartingEvent),
                    typeof(BookSelection),
                    typeof(CurrentEditableCollectionSelection),
                    typeof(RelocatePageEvent),
                    typeof(QueueRenameOfCollection),
                    typeof(PageSelection),
                    typeof(LocalizationChangedEvent),
                    typeof(EditingModel)
                }.Contains(t));

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

                try
                {
                    //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();
#if USING_CHORUS
                    chorusSystem.Init(string.Empty /*user name*/);
#endif
                }
                catch (Exception error)
                {
#if USING_CHORUS
#if !DEBUG
                    Palaso.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
                {
                    builder.Register <CollectionSettings>(c => new CollectionSettings(projectSettingsPath)).InstancePerLifetimeScope();
                }
                catch (Exception)
                {
                    return;
                }


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

                builder.Register <IChangeableFileLocator>(c => new BloomFileLocator(c.Resolve <CollectionSettings>(), c.Resolve <XMatterPackFinder>(), GetFactoryFileLocations(), GetFoundFileLocations())).InstancePerLifetimeScope();

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

                    return(new LanguageSettings(librarySettings.Language1Iso639Code, preferredSourceLanguagesInOrder));
                });
                builder.Register <XMatterPackFinder>(c =>
                {
                    var locations = new List <string>();
                    locations.Add(FileLocator.GetDirectoryDistributedWithApplication("xMatter"));
                    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>(), c.Resolve <BookCollection.Factory>(), editableCollectionDirectory);
                    l.RepositoryFolders = new string[] { 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 <BookTransfer>().AsSelf().SingleInstance();
                builder.RegisterType <LoginDialog>().AsSelf();

                //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();

                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
                {
                    _httpServer = new EnhancedImageServer(new LowResImageCache(bookRenameEvent));
                }
                builder.Register((c => _httpServer)).AsSelf().SingleInstance();

                builder.Register <Func <WorkspaceView> >(c => () =>
                {
                    var factory = c.Resolve <WorkspaceView.Factory>();
                    if (projectSettingsPath.ToLower().Contains("web"))
                    {
                        return(factory(c.Resolve <WebLibraryView>()));
                    }
                    else
                    {
                        return(factory(c.Resolve <LibraryView>()));
                    }
                });
            });
        }
Пример #23
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);
        }
Пример #24
0
        public void Setup()
        {
            _folder = new TemporaryFolder("ChorusSystemTests");
            _targetFile1 = new TempFileFromFolder(_folder,  "one.txt", "just a pretend file");
            _existingNotesFile = new TempFileFromFolder(_folder, "one.txt." + AnnotationRepository.FileExtension,
                        @"<notes version='0'>
                    <annotation ref='somwhere://foo?id=x' class='mergeConflict'>
                        <message guid='123' author='merger' status='open' date='2009-07-18T23:53:04Z'>
                            some description of the conflict
                        </message>
                    </annotation>
                </notes>");

            _system = new ChorusSystem(_folder.Path);
            _system.Init(string.Empty);
        }
Пример #25
0
        /// <summary>
        /// Open the given repo in the 'HistoryPage' control and its sub-system of controls.
        /// </summary>
        private void OpenLocalRepo()
        {
            if (string.IsNullOrWhiteSpace(_repoFolder))
            {
                return;
            }

            SuspendLayout();
            if (_historyPage != null)
            {
                _historyPage.RevisionSelectionChanged -= HistoryPageRevisionSelectionChanged;
                Controls.Remove(_historyPage);
                _historyPage.Dispose();
                _historyPage = null;
            }
            if (_chorusSystem != null)
            {
                _chorusSystem.Dispose();
                _chorusSystem = null;
            }

            var          repoType = GetRepoType();
            ChorusSystem newChorusSystem;

            switch (repoType)
            {
            case RepoType.None:
                return;

            case RepoType.NotSupported:
                MessageBox.Show(this, "The selected repository is not supported.", "Unsupported Repository Type",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;

            case RepoType.LIFT:
                newChorusSystem = Utilities.InitializeChorusSystem(_repoFolder, Environment.UserName, LiftFolder.AddLiftFileInfoToFolderConfiguration);
                break;

            case RepoType.FLEx:
                newChorusSystem = Utilities.InitializeChorusSystem(_repoFolder, Environment.UserName, FlexFolderSystem.ConfigureChorusProjectFolder);
                break;

            default:
                MessageBox.Show(this, "The selected repository is recognized, but not yet supported.", "Unsupported Repository Type",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            _chorusSystem = newChorusSystem;

            // Set up some new columns in the main control of the history page.
            // This makes it easy for the user to know the selected revision's branch and simple rev id.
            var historyPageOptions  = new HistoryPageOptions();
            var revisionListOptions = historyPageOptions.RevisionListOptions;
            // Not enabled in Chorus. revisionListOptions.ShowRevisionChoiceControls = true;
            var branchColumnDefinition = new HistoryColumnDefinition
            {
                ColumnLabel    = "Branch",
                StringSupplier = BranchName
            };
            // This is available as a tool tip of the icon cell, but show it here, anyway.
            var revisionIdColumnDefinition = new HistoryColumnDefinition
            {
                ColumnLabel    = "Revision Id",
                StringSupplier = RevisionId
            };

            revisionListOptions.ExtraColumns = new List <HistoryColumnDefinition>
            {
                branchColumnDefinition,
                revisionIdColumnDefinition
            };
            _historyPage = _chorusSystem.WinForms.CreateHistoryPage(historyPageOptions);
            _historyPage.RevisionSelectionChanged += HistoryPageRevisionSelectionChanged;
            Controls.Add(_historyPage);
            _historyPage.Dock = DockStyle.Fill;

            ResumeLayout(true);
        }
Пример #26
0
        public void Setup()
        {
            _tempFolder = new TemporaryFolder("ChorusSystemUsage");
            _dataFolderRoot = _tempFolder.Path;
            _someDataFile = new TempFileFromFolder(_tempFolder, "test.txt", "hello");
            _someDataFilePath = _someDataFile.Path;

            _chorusSystem = new ChorusSystem(_dataFolderRoot);
            _chorusSystem.Init("john");
        }
Пример #27
0
        /// ------------------------------------------------------------------------------------
        protected void BuildSubContainerForThisProject(string projectSettingsPath, IContainer parentContainer)
        {
            var editableCollectionDirectory = Path.GetDirectoryName(projectSettingsPath);

            _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(DeletePageCommand),
                    typeof(EditBookCommand),
                    typeof(SendReceiveCommand),
                    typeof(SelectedTabAboutToChangeEvent),
                    typeof(SelectedTabChangedEvent),
                    typeof(BookRenamedEvent),
                    typeof(LibraryClosing),
                    typeof(PageListChangedEvent),                      // REMOVE+++++++++++++++++++++++++++
                    typeof(BookRefreshEvent),
                    typeof(BookSelection),
                    typeof(CurrentEditableCollectionSelection),
                    typeof(RelocatePageEvent),
                    typeof(QueueRenameOfCollection),
                    typeof(PageSelection),
                    typeof(EditingModel)
                }.Contains(t));



                try
                {
                    //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*/);
                }
                catch (Exception error)
                {
                    Palaso.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"));
                }


                //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
                {
                    builder.Register <CollectionSettings>(c => new CollectionSettings(projectSettingsPath)).InstancePerLifetimeScope();
                }
                catch (Exception)
                {
                    return;
                }


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

                builder.Register <IChangeableFileLocator>(c => new BloomFileLocator(c.Resolve <CollectionSettings>(), c.Resolve <XMatterPackFinder>(), GetFileLocations())).InstancePerLifetimeScope();

                const int kListViewIconHeightAndSize = 70;
                builder.Register <HtmlThumbNailer>(c => new HtmlThumbNailer(kListViewIconHeightAndSize)).InstancePerLifetimeScope();

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

                    return(new LanguageSettings(librarySettings.Language1Iso639Code, preferredSourceLanguagesInOrder));
                });
                builder.Register <XMatterPackFinder>(c =>
                {
                    var locations = new List <string>();
                    locations.Add(FileLocator.GetDirectoryDistributedWithApplication("xMatter"));
                    locations.Add(XMatterAppDataFolder);
                    return(new XMatterPackFinder(locations));
                });

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

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

                //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();


                builder.Register <Func <WorkspaceView> >(c => () =>
                {
                    var factory = c.Resolve <WorkspaceView.Factory>();
                    if (projectSettingsPath.ToLower().Contains("web"))
                    {
                        return(factory(c.Resolve <WebLibraryView>()));
                    }
                    else
                    {
                        return(factory(c.Resolve <LibraryView>()));
                    }
                });
            });
        }
Пример #28
0
//autofac uses this

        public WorkspaceView(WorkspaceModel model,
                             Control libraryView,
                             EditingView.Factory editingViewFactory,
                             PublishView.Factory pdfViewFactory,
                             CollectionSettingsDialog.Factory settingsDialogFactory,
                             EditBookCommand editBookCommand,
                             SendReceiveCommand sendReceiveCommand,
                             SelectedTabAboutToChangeEvent selectedTabAboutToChangeEvent,
                             SelectedTabChangedEvent selectedTabChangedEvent,
                             LocalizationChangedEvent localizationChangedEvent,
                             FeedbackDialog.Factory feedbackDialogFactory,
                             ChorusSystem chorusSystem,
                             Sparkle sparkleApplicationUpdater,
                             LocalizationManager localizationManager

                             )
        {
            _model = model;
            _settingsDialogFactory         = settingsDialogFactory;
            _selectedTabAboutToChangeEvent = selectedTabAboutToChangeEvent;
            _selectedTabChangedEvent       = selectedTabChangedEvent;
            _localizationChangedEvent      = localizationChangedEvent;
            _feedbackDialogFactory         = feedbackDialogFactory;
            _chorusSystem = chorusSystem;
            _sparkleApplicationUpdater = sparkleApplicationUpdater;
            _localizationManager       = localizationManager;
            _model.UpdateDisplay      += new System.EventHandler(OnUpdateDisplay);
            InitializeComponent();

#if !DEBUG
            _sparkleApplicationUpdater.CheckOnFirstApplicationIdle();
#endif
            _toolStrip.Renderer = new NoBorderToolStripRenderer();

            //we have a number of buttons which don't make sense for the remote (therefore vulnerable) low-end user
            //_settingsLauncherHelper.CustomSettingsControl = _toolStrip;

            _settingsLauncherHelper.ManageComponent(_settingsButton);

            //NB: the rest of these aren't really settings, but we're using that feature to simplify this menu down to what makes sense for the easily-confused user
            _settingsLauncherHelper.ManageComponent(_openCreateCollectionButton);
            _settingsLauncherHelper.ManageComponent(deepBloomMenuItem);
            _settingsLauncherHelper.ManageComponent(_makeASuggestionMenuItem);
            _settingsLauncherHelper.ManageComponent(_webSiteMenuItem);
            _settingsLauncherHelper.ManageComponent(_showLogMenuItem);
            _settingsLauncherHelper.ManageComponent(_releaseNotesMenuItem);
            _settingsLauncherHelper.ManageComponent(_divider2);
            _settingsLauncherHelper.ManageComponent(_divider3);
            _settingsLauncherHelper.ManageComponent(_divider4);

            OnSettingsProtectionChanged(this, null);            //initial setup
            SettingsProtectionSettings.Default.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(OnSettingsProtectionChanged);


            _uiLanguageMenu.Visible = true;
            _settingsLauncherHelper.ManageComponent(_uiLanguageMenu);

            editBookCommand.Subscribe(OnEditBook);
            sendReceiveCommand.Subscribe(OnSendReceive);

            //Cursor = Cursors.AppStarting;
            Application.Idle += new EventHandler(Application_Idle);
            Text              = _model.ProjectName;

            //SetupTabIcons();

            //
            // _collectionView
            //
            this._collectionView      = (LibraryView)libraryView;
            this._collectionView.Dock = System.Windows.Forms.DockStyle.Fill;

            //
            // _editingView
            //
            this._editingView      = editingViewFactory();
            this._editingView.Dock = System.Windows.Forms.DockStyle.Fill;

            //
            // _pdfView
            //
            this._publishView      = pdfViewFactory();
            this._publishView.Dock = System.Windows.Forms.DockStyle.Fill;

            _collectionTab.Tag = _collectionView;
            _publishTab.Tag    = _publishView;
            _editTab.Tag       = _editingView;

            this._collectionTab.Text = _collectionView.CollectionTabLabel;

            SetTabVisibility(_publishTab, false);
            SetTabVisibility(_editTab, false);

//			if (Program.StartUpWithFirstOrNewVersionBehavior)
//			{
//				_tabStrip.SelectedTab = _infoTab;
//				SelectPage(_infoView);
//			}
//			else
//			{
            _tabStrip.SelectedTab = _collectionTab;
            SelectPage(_collectionView);
//			}

            SetupUILanguageMenu();
        }