Ejemplo n.º 1
0
 public RecursiveResolutionParameters(Hashtable subTree, IsolatedNodeProvider destinationProvider, IsolatedNodeProvider sourceProvider, IsolatedChangeSet <Guid, object, EdgeData> changeSet, Dictionary <Guid, Guid> intermediateChanges, Hashtable visitedNodes)
 {
     this.SubTree             = subTree;
     this.DestinationProvider = destinationProvider;
     this.SourceProvider      = sourceProvider;
     this.ChangeSet           = changeSet;
     this.IntermediateChanges = intermediateChanges;
     this.VisitedNodes        = visitedNodes;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates new instance of Workspace type
        /// </summary>
        internal Workspace(Guid snapshotId, TimeSpan timeout, INodeProvider <Guid, object, EdgeData> nodeProvider, IWorkspaceFacade commitTarget, ProxyCreatorService proxyCreatorService, TypesService typesService, IsolationLevel isolationLevel, IProxyMap immutableProxyMap)
        {
            this.workspaceId = Guid.NewGuid();
            this.thread      = Thread.CurrentThread;

            if (!typeof(TDataType).IsInterface)
            {
                throw new ArgumentException("Interface type expected: " + typeof(TDataType).AssemblyQualifiedName);
            }

            this.snapshotId          = snapshotId;
            this.nodeProvider        = nodeProvider;
            this.proxyCreatorService = proxyCreatorService;
            this.typesService        = typesService;
            this.isolationLevel      = isolationLevel;
            this.workspaceFacade     = commitTarget;
            this.immutableProxyMap   = immutableProxyMap;

            workspaceFacade.OpenWorkspace(workspaceId, snapshotId, isolationLevel, timeout);

            if (isolationLevel == IsolationLevel.ReadOnly)
            {
                // Rely directly on parent provider if read only
                this.objectInstancesService     = new ObjectInstancesService(nodeProvider, typesService);
                this.immutableInstancesService  = new ObjectInstancesService(nodeProvider, typesService);
                this.collectionInstancesService = new CollectionInstancesService(nodeProvider, typesService);
                this.dictionaryInstancesService = new DictionaryInstancesService(nodeProvider, typesService);
            }
            else
            {
                // Construct isolated provider for local changes
                var isolatedStorage = new DirectNodeProviderUnsafe <Guid, object, EdgeData>(new MemoryStorageUnsafe <Guid, object>(), false);
                isolatedProvider                = new IsolatedNodeProvider(nodeProvider, isolatedStorage, thread);
                this.objectInstancesService     = new ObjectInstancesService(isolatedProvider, typesService);
                this.immutableInstancesService  = new ObjectInstancesService(nodeProvider, typesService);
                this.collectionInstancesService = new CollectionInstancesService(isolatedProvider, typesService);
                this.dictionaryInstancesService = new DictionaryInstancesService(isolatedProvider, typesService);
            }

            this.runtimeProxyFacade = new RuntimeProxyFacade(typesService, objectInstancesService, immutableInstancesService, collectionInstancesService, new CollectionInstancesService(nodeProvider, typesService), dictionaryInstancesService, new DictionaryInstancesService(nodeProvider, typesService), mutableProxyMap, immutableProxyMap, proxyCreatorService);

            // Initialize root data proxy
            var rootObjectId = commitTarget.GetRootObjectId(snapshotId);

            rootProxy = proxyCreatorService.NewObject <TDataType>(runtimeProxyFacade, rootObjectId, isolationLevel == IsolationLevel.ReadOnly);

            if (isolationLevel == IsolationLevel.ReadOnly)
            {
                immutableProxyMap.AddProxy(rootObjectId, rootProxy);
            }
            else
            {
                mutableProxyMap.AddProxy(rootObjectId, rootProxy);
            }
        }
Ejemplo n.º 3
0
        private AppendableChangeSet <Guid, object, EdgeData> CreateMergedChangeSet(Guid latestSnapshot, Hashtable subTree, IsolatedChangeSet <Guid, object, EdgeData> changeSet, Dictionary <Guid, Guid> intermediateChanges)
        {
#if DEBUG
            Debug.WriteLine("Merging over intermediate changes");
#endif
            // We create node provider which will host changes to the last snapshot made by the merge process
            var isolatedNodes = new DirectNodeProviderUnsafe <Guid, object, EdgeData>(new MemoryStorageUnsafe <Guid, object>(), false);
            // Perform merging on the current thread
            IsolatedNodeProvider destinationProvider = new IsolatedNodeProvider(nodes, isolatedNodes, Thread.CurrentThread);
            IsolatedNodeProvider sourceProvider      = new IsolatedNodeProvider(nodes, changeSet.Nodes, Thread.CurrentThread);

            // Make changes from incoming changes within a subtree
            MergeRecursive(latestSnapshot, new RecursiveResolutionParameters(subTree, destinationProvider, sourceProvider, changeSet, intermediateChanges, new Hashtable()));

            // We create an appendable change set from changes made to last snapshot, defining a new snapshot
            return(CreateAppendableChangeSet(latestSnapshot, Guid.NewGuid(), destinationProvider.GetChanges(latestSnapshot)));
        }
Ejemplo n.º 4
0
        private AppendableChangeSet<Guid, object, EdgeData> CreateMergedChangeSet(Guid latestSnapshot, Hashtable subTree, IsolatedChangeSet<Guid, object, EdgeData> changeSet, Dictionary<Guid, Guid> intermediateChanges)
        {
            #if DEBUG
            Debug.WriteLine("Merging over intermediate changes");
            #endif
            // We create node provider which will host changes to the last snapshot made by the merge process
            var isolatedNodes = new DirectNodeProviderUnsafe<Guid,object, EdgeData>(new MemoryStorageUnsafe<Guid, object>(), false);
            // Perform merging on the current thread
            IsolatedNodeProvider destinationProvider = new IsolatedNodeProvider(nodes, isolatedNodes, Thread.CurrentThread);
            IsolatedNodeProvider sourceProvider = new IsolatedNodeProvider(nodes, changeSet.Nodes, Thread.CurrentThread);

            // Make changes from incoming changes within a subtree
            MergeRecursive(latestSnapshot, new RecursiveResolutionParameters(subTree, destinationProvider, sourceProvider, changeSet, intermediateChanges, new Hashtable()));

            // We create an appendable change set from changes made to last snapshot, defining a new snapshot
            return CreateAppendableChangeSet(latestSnapshot, Guid.NewGuid(), destinationProvider.GetChanges(latestSnapshot));
        }