Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
 public RuntimeProxyFacade(TypesService typesService, ObjectInstancesService objectInstancesService, ObjectInstancesService immutableInstancesService, CollectionInstancesService collectionInstancesService, CollectionInstancesService immutableCollectionInstancesService, DictionaryInstancesService dictionaryInstancesService, DictionaryInstancesService immutableDictionaryInstancesService, IProxyMap mutableProxyMap, IProxyMap immutableProxyMap, ProxyCreatorService proxyCreatorService)
 {
     this.objectInstancesService              = objectInstancesService;
     this.immutableInstancesService           = immutableInstancesService;
     this.collectionInstancesService          = collectionInstancesService;
     this.dictionaryInstancesService          = dictionaryInstancesService;
     this.immutableCollectionInstancesService = immutableCollectionInstancesService;
     this.immutableDictionaryInstancesService = immutableDictionaryInstancesService;
     this.mutableProxyMap     = mutableProxyMap;
     this.immutableProxyMap   = immutableProxyMap;
     this.proxyCreatorService = proxyCreatorService;
     this.typesService        = typesService;
 }
Exemplo n.º 3
0
        private object GetProxyInstance(bool isReadOnly, Guid referenceId, Guid typeId)
        {
            if (referenceId.Equals(Constants.NullReferenceNodeId))
            {
                return(null);
            }
            else
            {
                object proxy = null;

                IProxyMap map = mutableProxyMap;
                var       collectionService = collectionInstancesService;
                var       objectService     = objectInstancesService;

                if (isReadOnly)
                {
                    map = immutableProxyMap;
                    collectionService = immutableCollectionInstancesService;
                    objectService     = immutableInstancesService;
                }

                if (!map.TryGetProxy(referenceId, out proxy))
                {
                    if (typeId.Equals(Guid.Empty))
                    {
                        if (collectionService.IsCollectionInstance(referenceId)) // TODO (nsabo) Merge this information into proxy static data
                        {
                            typeId = collectionService.GetInstanceTypeId(referenceId);
                        }
                        else
                        {
                            // Get type ID of referenced instance
                            typeId = objectService.GetInstanceTypeId(referenceId);
                        }
                    }
                    // Create proxy object
                    proxy = proxyCreatorService.NewObject(this, typeId, referenceId, isReadOnly);
                    // Add to proxy map
                    map.AddProxy(referenceId, proxy);
                }

                return(proxy);
            }
        }