Esempio n. 1
0
        public override void OnObjectContextCreate(ObjectContext objectContext)
        {
            base.OnObjectContextCreate(objectContext);

            IObjectMapperFactoryRegistry mapperFactoryRegistry = objectContext.GetService <IObjectMapperFactoryRegistry>();

            mapperFactoryRegistry.RegisterFactory(typeof(CustomLibraryMapperFactory));

            IServiceFactoryRegistry serviceFactoryRegistry = objectContext.GetService <IServiceFactoryRegistry>();

            serviceFactoryRegistry.RegisterFactory(typeof(CustomLibraryServiceFactory));
        }
Esempio n. 2
0
    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;
                }
            }
        }
Esempio n. 4
0
        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;
                }
            }
        }