Ejemplo n.º 1
0
 /// <summary>
 /// Creates new instance of WorkspaceFacade type
 /// </summary>
 /// <param name="commitDataService">Commit data service</param>
 /// <param name="workspaceStateProvider">Workspace state tracker</param>
 public WorkspaceFacade(CommitDataService commitDataService, TrackingWorkspaceStateProvider workspaceStateProvider, ISubscriptionManagerService subscriptionManagerService, SnapshotsService snapshotsService, WorkspaceExclusiveLockProvider workspaceExclusiveLockProvider)
 {
     this.commitDataService              = commitDataService;
     this.workspaceStateProvider         = workspaceStateProvider;
     this.subscriptionManagerService     = subscriptionManagerService;
     this.snapshotsService               = snapshotsService;
     this.workspaceExclusiveLockProvider = workspaceExclusiveLockProvider;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates new instance of WorkspaceFacade type
 /// </summary>
 /// <param name="commitDataService">Commit data service</param>
 /// <param name="workspaceStateProvider">Workspace state tracker</param>
 public WorkspaceFacade(CommitDataService commitDataService, TrackingWorkspaceStateProvider workspaceStateProvider, ISubscriptionManagerService subscriptionManagerService, SnapshotsService snapshotsService, WorkspaceExclusiveLockProvider workspaceExclusiveLockProvider)
 {
     this.commitDataService = commitDataService;
     this.workspaceStateProvider = workspaceStateProvider;
     this.subscriptionManagerService = subscriptionManagerService;
     this.snapshotsService = snapshotsService;
     this.workspaceExclusiveLockProvider = workspaceExclusiveLockProvider;
 }
Ejemplo n.º 3
0
        private void InitializeServices(Type rootEntityType, Type[] entityTypes, UpgradeConfiguration upgradeConfiguration)
        {
            this.rootEntityType = rootEntityType;
            this.entityTypes    = entityTypes;

            typesService = new TypesService(provider);

            objectSerializationService.TypesService = typesService;

            var interfaceToTypeIdMapping = typesService.InitializeTypeSystem(entityTypes);

            var completeTypesList = interfaceToTypeIdMapping.Keys;

            generationService = new GenerationService(typesService);
            // TODO (nsabo) Optional loading of proxy types from the given assembly (we dont want always to generate on small devices, Silverlight...)
            // Note: Collection/Dictionary types are not saved in the assembly
            var interfaceToGeneratedMapping = generationService.GenerateProxyTypes(completeTypesList, Properties.Settings.Default.SaveGeneratedAssemblyToDisk, Properties.Settings.Default.GeneratedAssemblyFileName);

            proxyCreatorService = new ProxyCreatorService(completeTypesList, interfaceToTypeIdMapping, interfaceToGeneratedMapping);

            snapshotsService = new SnapshotsService(provider);

            #region Parent map provider setup
            if (Properties.Settings.Default.ParentMappingFileStorageUsed)
            {
                // Usage of file for caching parent information
                var indexedFile = new IndexedFileStorage(new FileStream(this.parentMappingFileName, FileMode.Create), Properties.Settings.Default.ParentMappingFileBlockSize, false);
                indexedFile.Serializer = this.objectSerializationService;
                disposables.Add(indexedFile);

                var parentProviderStorage = new CachedWriteNodeProviderUnsafe <Guid, object, EdgeData>(
                    new DirectNodeProviderUnsafe <Guid, object, EdgeData>(indexedFile, true),
                    new LimitedDirectNodeProviderUnsafe <Guid, object, EdgeData>(
                        new LimitedMemoryStorageUnsafe <Guid, object>(Properties.Settings.Default.ParentMappingMemoryMinimumCount, Properties.Settings.Default.ParentMappingMemoryMaximumCount), false)
                    );
                disposables.Add(parentProviderStorage);

                mutableParentProvider = new ParentMapProvider(parentProviderStorage, provider, null, true);
            }
            else
            {
                // Default parent information is stored in memory and has only the last snapshot available
                mutableParentProvider = new ParentMapProvider(new DirectNodeProviderUnsafe <Guid, object, EdgeData>(new MemoryStorageUnsafe <Guid, object>(), false), provider, null, true);
            }
            #endregion

            #region Merge rule provider setup
            IMergeRuleProvider mergeRuleProvider = null;

            if (SnapshotIsolationEnabled)
            {
                if (Properties.Settings.Default.ConcurrencyAutoOverrideResolution)
                {
                    mergeRuleProvider = new AutoOverrideMergeRuleProvider();
                }
                else
                {
                    if (Properties.Settings.Default.ConcurrencyAttributesEnabled)
                    {
                        mergeRuleProvider = new AttributeBasedMergeRuleProvider(typesService);
                    }
                    else
                    {
                        throw new ArgumentException("No selected provider for merge rules in snapshot isolation conflicts. Check configuration of merge rule providers.");
                    }
                }
            }
            #endregion

            #region Setup change set provider
            // TODO (nsabo) Provide option for change set safety when context goes offline, OfflineWorkspaces should enable commits when context is back online

            if (Properties.Settings.Default.ChangeSetHistoryFileStorageUsed)
            {
                var indexedFile = new IndexedFileStorage(new FileStream(Properties.Settings.Default.ChangeSetHistoryFileStorageFileName, FileMode.Create), 256, false);
                indexedFile.Serializer = this.objectSerializationService;
                disposables.Add(indexedFile);

                var changeSetProviderStorage = new CachedWriteNodeProviderUnsafe <Guid, object, EdgeData>(
                    new DirectNodeProviderUnsafe <Guid, object, EdgeData>(indexedFile, true),
                    new LimitedDirectNodeProviderUnsafe <Guid, object, EdgeData>(
                        new LimitedMemoryStorageUnsafe <Guid, object>(Properties.Settings.Default.ChangeSetHistoryWriteCacheMinimumCount, Properties.Settings.Default.ChangeSetHistoryWriteCacheMaximumCount), false)
                    );
                disposables.Add(changeSetProviderStorage);

                changeSetProvider = new TrackingChangeSetProvider(changeSetProviderStorage);
            }
            else
            {
                changeSetProvider = new TrackingChangeSetProvider(new DirectNodeProviderUnsafe <Guid, object, EdgeData>(new MemoryStorageUnsafe <Guid, object>(), false));
            }

            #endregion

            var immutableParentProvider = new ParentMapProvider(new DirectNodeProviderUnsafe <Guid, object, EdgeData>(new MemoryStorageUnsafe <Guid, object>(), false), provider, null, false);
            collectedNodesProvider = new CollectedNodesProvider(new DirectNodeProviderUnsafe <Guid, object, EdgeData>(new MemoryStorageUnsafe <Guid, object>(), false), provider);

            commitDataService = new CommitDataService(provider, typesService, snapshotsService, mutableParentProvider, immutableParentProvider, changeSetProvider, new NodeMergeExecutor(mergeRuleProvider, typesService), collectedNodesProvider);

            workspaceExclusiveLockProvider = new WorkspaceExclusiveLockProvider();
            disposables.Add(workspaceExclusiveLockProvider);

            trackingWorkspaceStateProvider = new TrackingWorkspaceStateProvider(workspaceExclusiveLockProvider);

            objectInstancesService = new ObjectInstancesService(provider, typesService);

            subscriptionManagerService = new SubscriptionManagerService(typesService, objectInstancesService);

            workspaceFacade = new WorkspaceFacade(commitDataService, trackingWorkspaceStateProvider, subscriptionManagerService, snapshotsService, workspaceExclusiveLockProvider);

            backupService = new BackupService();

            bool firstRun = snapshotsService.InitializeSnapshots();

            if (firstRun)
            {
                InitializeDefaultSnapshot();
            }
            else
            {
                OptimizeData();
            }

            StaticProxyFacade.Initialize(typesService);
        }