private void CreateContext() { ServiceContainer container = new ServiceContainer(); container.AddService(typeof(UserSession), Session); ObjectContext context = new ObjectContext(container); var mapperRegistry = context.GetService <IObjectMapperFactoryRegistry>(); mapperRegistry.RegisterFactory(typeof(SystemCardsMapperFactory)); mapperRegistry.RegisterFactory(typeof(BackOfficeMapperFactory)); mapperRegistry.RegisterFactory(typeof(ApprovalDesignerMapperFactory)); //mapperRegistry.RegisterFactory(typeof(ACSGroup.NormativeDocumentManagement.ObjectModel.Mapping.NormativeDocumentManagementMapperFactory)); var serviceRegistry = context.GetService <IServiceFactoryRegistry>(); serviceRegistry.RegisterFactory(typeof(SystemCardsServiceFactory)); serviceRegistry.RegisterFactory(typeof(BackOfficeServiceFactory)); serviceRegistry.RegisterFactory(typeof(ApprovalDesignerServiceFactory)); // serviceRegistry.RegisterFactory(typeof(ACSGroup.NormativeDocumentManagement.ObjectModel.Services.NormativeDocumentManagementServiceFactory)); IMetadataProvider metaProvider = DocsVisionObjectFactory.CreateMetadataProvider(Session); IMetadataManager metaManager = DocsVisionObjectFactory.CreateMetadataManager(metaProvider, Session); context.AddService(metaManager); context.AddService(metaProvider); IPersistentStore store = DocsVisionObjectFactory.CreatePersistentStore(Session, null); context.AddService(store); Context = context; }
private static ObjectContext GetObjectContext(UserSession session) { UserSession userSession = session; // Инициализация сервис-провайдера var sessionContainer = new System.ComponentModel.Design.ServiceContainer(); sessionContainer.AddService(typeof(DocsVision.Platform.ObjectManager.UserSession), userSession); // Инициализация контекста объектов // В качестве контейнера может выступать компонент карточки, унаследованный от DocsVision.Platform.WinForms.CardControl ObjectContext objectContext = new ObjectContext(sessionContainer); // Получение сервис-реестра и регистрация фабрик преобразователей IObjectMapperFactoryRegistry mapperFactoryRegistry = objectContext.GetService <IObjectMapperFactoryRegistry>(); mapperFactoryRegistry.RegisterFactory(typeof(SystemCardsMapperFactory)); mapperFactoryRegistry.RegisterFactory(typeof(BackOfficeMapperFactory)); mapperFactoryRegistry.RegisterFactory(typeof(ApprovalDesignerMapperFactory)); // Получение сервис-реестра и регистрация фабрик сервисов IServiceFactoryRegistry serviceFactoryRegistry = objectContext.GetService <IServiceFactoryRegistry>(); serviceFactoryRegistry.RegisterFactory(typeof(SystemCardsServiceFactory)); serviceFactoryRegistry.RegisterFactory(typeof(BackOfficeServiceFactory)); serviceFactoryRegistry.RegisterFactory(typeof(ApprovalDesignerServiceFactory)); // Регистрация сервиса для работы с хранилищем Docsvision objectContext.AddService <IPersistentStore>(DocsVisionObjectFactory.CreatePersistentStore(new SessionProvider(userSession), null)); // Регистрация поставщика метаданных карточек IMetadataProvider metadataProvider = DocsVisionObjectFactory.CreateMetadataProvider(userSession); objectContext.AddService <IMetadataManager>(DocsVisionObjectFactory.CreateMetadataManager(metadataProvider, userSession)); objectContext.AddService <IMetadataProvider>(metadataProvider); return(objectContext); }
private void CreateObjectContext() { { try { objectContext = new ObjectContext(this); IObjectMapperFactoryRegistry mapperFactoryRegistry = objectContext.GetService <IObjectMapperFactoryRegistry>(); mapperFactoryRegistry.RegisterFactory(typeof(SystemCardsMapperFactory)); mapperFactoryRegistry.RegisterFactory(typeof(BackOfficeMapperFactory)); mapperFactoryRegistry.RegisterFactory(typeof(ApprovalDesignerMapperFactory)); IServiceFactoryRegistry serviceFactoryRegistry = objectContext.GetService <IServiceFactoryRegistry>(); serviceFactoryRegistry.RegisterFactory(typeof(SystemCardsServiceFactory)); serviceFactoryRegistry.RegisterFactory(typeof(BackOfficeServiceFactory)); serviceFactoryRegistry.RegisterFactory(typeof(ApprovalDesignerServiceFactory)); objectContext.AddService(DocsVisionObjectFactory.CreatePersistentStore(Session)); IMetadataProvider metadataProvider = DocsVisionObjectFactory.CreateMetadataProvider(new SessionProvider(Session)); objectContext.AddService(metadataProvider); objectContext.AddService(DocsVisionObjectFactory.CreateMetadataManager(metadataProvider, Session)); objectContext.GetService <IAccessCheckingService>().EditMode = true; } catch (Exception) { if (objectContext != null) { objectContext.Dispose(); objectContext = null; } // TODO: Log exception throw; } } }
public ObjectContext CreateObjectContext() { var objectContext = new ObjectContext(this); var mapperFactoryRegistry = objectContext.GetService <IObjectMapperFactoryRegistry>(); mapperFactoryRegistry.RegisterFactory(typeof(SystemCardsMapperFactory)); mapperFactoryRegistry.RegisterFactory(typeof(BackOfficeMapperFactory)); var serviceFactoryRegistry = objectContext.GetService <IServiceFactoryRegistry>(); serviceFactoryRegistry.RegisterFactory(typeof(SystemCardsServiceFactory)); serviceFactoryRegistry.RegisterFactory(typeof(BackOfficeServiceFactory)); objectContext.AddService(DocsVisionObjectFactory.CreatePersistentStore(Session)); var metadataProvider = DocsVisionObjectFactory.CreateMetadataProvider(new SessionProvider(Session)); objectContext.AddService(metadataProvider); objectContext.AddService(DocsVisionObjectFactory.CreateMetadataManager(metadataProvider, Session)); objectContext.GetService <IAccessCheckingService>().EditMode = true; return(objectContext); }
private void CreateLocalContext() { { // если не получается сделать через IServiceProvider, то есть второй способ создания контекста, см. внизу try { localContext = new ObjectContext(this); IObjectMapperFactoryRegistry mapperFactoryRegistry = localContext.GetService <IObjectMapperFactoryRegistry>(); mapperFactoryRegistry.RegisterFactory(typeof(SystemCardsMapperFactory)); mapperFactoryRegistry.RegisterFactory(typeof(BackOfficeMapperFactory)); IServiceFactoryRegistry serviceFactoryRegistry = localContext.GetService <IServiceFactoryRegistry>(); serviceFactoryRegistry.RegisterFactory(typeof(SystemCardsServiceFactory)); serviceFactoryRegistry.RegisterFactory(typeof(BackOfficeServiceFactory)); localContext.AddService(DocsVisionObjectFactory.CreatePersistentStore(session)); IMetadataProvider metadataProvider = DocsVisionObjectFactory.CreateMetadataProvider(new SessionProvider(session)); localContext.AddService(metadataProvider); localContext.AddService(DocsVisionObjectFactory.CreateMetadataManager(metadataProvider, session)); localContext.GetService <IAccessCheckingService>().EditMode = true; } catch { if (localContext != null) { localContext.Dispose(); localContext = null; } throw; } } }