예제 #1
0
        /// <summary>
        /// Opens a new workspace with assumed latest available snapshot
        /// </summary>
        /// <typeparam name="TDataType">Type of root entity interface for data navigation. This is the "all containing" entity, which has access to all other entities.</typeparam>
        /// <param name="isolationLevel">Workspace isolation</param>
        /// <param name="timeout">Workspace timeout</param>
        /// <returns>New workspace instance</returns>
        public Workspace <TDataType> OpenWorkspace <TDataType>(IsolationLevel isolationLevel, TimeSpan timeout)
        {
            if (!SnapshotIsolationEnabled && isolationLevel == IsolationLevel.Snapshot)
            {
                throw new ArgumentException("Snapshot isolation level disabled by configuration");
            }

            if (isolationLevel == IsolationLevel.Exclusive)
            {
                workspaceExclusiveLockProvider.EnterLockExclusive();
            }

            Guid snapshotId = snapshotsService.GetLatestSnapshotId();

            return(new Workspace <TDataType>(snapshotId, timeout, provider, workspaceFacade, proxyCreatorService, typesService, isolationLevel, immutableProxyMap));
        }
예제 #2
0
        /// <summary>
        /// Creates subscription to object changes
        /// </summary>
        /// <param name="workspaceId">Workspace ID</param>
        /// <param name="instanceId">Instance Id which changes are going to be notified</param>
        /// <param name="notifyChangesFromSameWorkspace">Defines if changes from same workspace should be notified</param>
        /// <param name="del">Delegate to be called</param>
        /// <returns>Subscription object</returns>
        public Subscription CreateSubscription(Guid workspaceId, Guid instanceId, bool notifyChangesFromSameWorkspace, EventHandler <ObjectChangedEventArgs> del)
        {
            lock (commitSync)
            {
                Guid snapshotId = workspaceStateProvider.GetWorkspaceSnapshotId(workspaceId);

                var result = subscriptionManagerService.Create(workspaceId, instanceId, notifyChangesFromSameWorkspace, del);

                var lastSnapshotId = snapshotsService.GetLatestSnapshotId();

                if (!lastSnapshotId.Equals(snapshotId))
                {
                    var changes = commitDataService.ChangesBetween(snapshotId, lastSnapshotId);
                    subscriptionManagerService.InvokeEvents(Guid.Empty, new CommitResult <Guid>(lastSnapshotId, changes));
                }

                return(result);
            }
        }