internal Shell CreateShell(BrowseForRepositoryEvent browseForRepositoryEvent, Arguments arguments) { var builder = new Autofac.ContainerBuilder(); ChorusUIComponentsInjector.Inject(builder, _projectPath, SyncUIFeatures.Advanced); builder.RegisterInstance(browseForRepositoryEvent).As<BrowseForRepositoryEvent>().SingleInstance(); //For now, we like the idea of just using the login name. But //this allows someone to override that in the ini (which would be for all users of this machine, then) builder.Register<IChorusUser>(c => new ChorusUser(c.Resolve<HgRepository>().GetUserNameFromIni(new NullProgress(), System.Environment.UserName))); builder.RegisterType<Shell>(); if(arguments!=null) { builder.RegisterInstance(arguments); Synchronizer.s_testingDoNotPush = arguments.DontPush; //hack, at this point it would take a lot of plumbing //to get this properly to any synchronizer that is created. Can be fixed if/when we go to the //autofac generated factor approach } _container = builder.Build(); var shell= _container.Resolve<Shell>(); var system = new ChorusSystem(_projectPath); system.Init(string.Empty); shell.AddPage("Review", system.WinForms.CreateHistoryPage()); shell.AddPage("Notes", system.WinForms.CreateNotesBrowser()); shell.AddPage("Send/Receive", _container.Resolve<SyncPanel>()); shell.AddPage("Settings", _container.Resolve<SettingsView>()); shell.AddPage("Troubleshooting", _container.Resolve<TroubleshootingView>()); return shell; }
internal Shell CreateShell(BrowseForRepositoryEvent browseForRepositoryEvent, Arguments arguments) { var builder = new Autofac.ContainerBuilder(); ChorusUIComponentsInjector.Inject(builder, _projectPath, SyncUIFeatures.Advanced); builder.RegisterInstance(browseForRepositoryEvent).As <BrowseForRepositoryEvent>().SingleInstance(); //For now, we like the idea of just using the login name. But //this allows someone to override that in the ini (which would be for all users of this machine, then) builder.Register <IChorusUser>(c => new ChorusUser(c.Resolve <HgRepository>().GetUserNameFromIni(new NullProgress(), System.Environment.UserName))); builder.RegisterType <Shell>(); if (arguments != null) { builder.RegisterInstance(arguments); Synchronizer.s_testingDoNotPush = arguments.DontPush; //hack, at this point it would take a lot of plumbing //to get this properly to any synchronizer that is created. Can be fixed if/when we go to the //autofac generated factor approach } _container = builder.Build(); var shell = _container.Resolve <Shell>(); var system = new ChorusSystem(_projectPath); system.Init(string.Empty); shell.AddPage("Review", system.WinForms.CreateHistoryPage()); shell.AddPage("Notes", system.WinForms.CreateNotesBrowser()); shell.AddPage("Send/Receive", _container.Resolve <SyncPanel>()); shell.AddPage("Settings", _container.Resolve <SettingsView>()); shell.AddPage("Troubleshooting", _container.Resolve <TroubleshootingView>()); return(shell); }
/// ------------------------------------------------------------------------------------ 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(BloomParseClient), 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>(), GetFactoryFileLocations(),GetFoundFileLocations())).InstancePerLifetimeScope(); const int kListViewIconHeightAndWidth = 70; builder.Register<HtmlThumbNailer>(c => new HtmlThumbNailer(kListViewIconHeightAndWidth, kListViewIconHeightAndWidth)).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>()); } }); }); }
/// <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; }
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); /* * Eberhard: I commented out the following lines because these components use the * Windows Forms WebBrowser. When we try to bring up the GeckoTestDlg this causes * a crash on Linux. _notesBrowserControl = _chorusSystem.WinForms.CreateNotesBrowser(); _notesBrowserControl.Dock = DockStyle.Fill; _notesPage.Controls.Add(_notesBrowserControl); _historyControl = _chorusSystem.WinForms.CreateHistoryPage(); _historyControl.Dock = DockStyle.Fill; _historyPage.Controls.Add(_historyControl); */ }