protected internal override void Validate(InstanceView view)
 {
     if (!view.IsBoundToInstanceOwner)
     {
         throw FxTrace.Exception.AsError(new InvalidOperationException(SRCore.OwnerRequired));
     }
     if (view.IsBoundToInstance)
     {
         throw FxTrace.Exception.AsError(new InvalidOperationException(SRCore.AlreadyBoundToInstance));
     }
     if (this.LookupInstanceKey == Guid.Empty)
     {
         throw FxTrace.Exception.AsError(new InvalidOperationException(SRCore.LoadOpKeyMustBeValid));
     }
     if (this.AssociateInstanceKeyToInstanceId == Guid.Empty)
     {
         if (this.InstanceKeysToAssociate.ContainsKey(this.LookupInstanceKey))
         {
             throw FxTrace.Exception.AsError(new InvalidOperationException(SRCore.LoadOpAssociateKeysCannotContainLookupKey));
         }
     }
     else if (!this.AcceptUninitializedInstance)
     {
         throw FxTrace.Exception.AsError(new InvalidOperationException(SRCore.LoadOpFreeKeyRequiresAcceptUninitialized));
     }
     if (this.keysToAssociate != null)
     {
         foreach (KeyValuePair<Guid, IDictionary<XName, InstanceValue>> pair in this.keysToAssociate)
         {
             pair.Value.ValidatePropertyBag();
         }
     }
 }
 protected internal override void Validate(InstanceView view)
 {
     if (!view.IsBoundToInstance)
     {
         throw FxTrace.Exception.AsError(new InvalidOperationException(SRCore.InstanceRequired));
     }
     if (!view.IsBoundToInstanceOwner)
     {
         throw FxTrace.Exception.AsError(new InvalidOperationException(SRCore.OwnerRequired));
     }
     if (this.keysToAssociate != null)
     {
         foreach (KeyValuePair<Guid, IDictionary<XName, InstanceValue>> pair in this.keysToAssociate)
         {
             pair.Value.ValidatePropertyBag();
         }
     }
     if (this.keyMetadataChanges != null)
     {
         foreach (KeyValuePair<Guid, IDictionary<XName, InstanceValue>> pair2 in this.keyMetadataChanges)
         {
             pair2.Value.ValidatePropertyBag(true);
         }
     }
     if (this.CompleteInstance && !this.UnlockInstance)
     {
         throw FxTrace.Exception.AsError(new InvalidOperationException(SRCore.ValidateUnlockInstance));
     }
     this.instanceMetadataChanges.ValidatePropertyBag(true);
     this.instanceData.ValidatePropertyBag();
 }
 protected internal override void Validate(InstanceView view)
 {
     if (!view.IsBoundToInstanceOwner)
     {
         throw FxTrace.Exception.AsError(new InvalidOperationException(SRCore.OwnerRequired));
     }
 }
        InstanceView(InstanceView source)
        {
            this.instanceVersion = source.instanceVersion;

            InstanceOwner = source.InstanceOwner;
            InstanceId = source.InstanceId;
            IsBoundToInstance = source.IsBoundToInstance;

            InstanceState = source.InstanceState;

            InstanceDataConsistency = source.InstanceDataConsistency;
            InstanceMetadataConsistency = source.InstanceMetadataConsistency;
            InstanceOwnerMetadataConsistency = source.InstanceOwnerMetadataConsistency;
            InstanceKeysConsistency = source.InstanceKeysConsistency;

            InstanceData = source.InstanceData;
            InstanceMetadata = source.InstanceMetadata;
            InstanceOwnerMetadata = source.InstanceOwnerMetadata;

            InstanceStoreQueryResults = source.InstanceStoreQueryResults;

            Dictionary<Guid, InstanceKeyView> keys = null;
            if (source.InstanceKeys.Count > 0)
            {
                keys = new Dictionary<Guid, InstanceKeyView>(source.InstanceKeys.Count);
                foreach (KeyValuePair<Guid, InstanceKeyView> key in source.InstanceKeys)
                {
                    keys.Add(key.Key, key.Value.Clone());
                }
            }
            InstanceKeys = keys == null ? null : new ReadOnlyDictionaryInternal<Guid, InstanceKeyView>(keys);
        }
 private InstanceView(InstanceView source)
 {
     this.instanceVersion = source.instanceVersion;
     this.InstanceOwner = source.InstanceOwner;
     this.InstanceId = source.InstanceId;
     this.IsBoundToInstance = source.IsBoundToInstance;
     this.InstanceState = source.InstanceState;
     this.InstanceDataConsistency = source.InstanceDataConsistency;
     this.InstanceMetadataConsistency = source.InstanceMetadataConsistency;
     this.InstanceOwnerMetadataConsistency = source.InstanceOwnerMetadataConsistency;
     this.InstanceKeysConsistency = source.InstanceKeysConsistency;
     this.InstanceData = source.InstanceData;
     this.InstanceMetadata = source.InstanceMetadata;
     this.InstanceOwnerMetadata = source.InstanceOwnerMetadata;
     this.InstanceStoreQueryResults = source.InstanceStoreQueryResults;
     Dictionary<Guid, InstanceKeyView> dictionary = null;
     if (source.InstanceKeys.Count > 0)
     {
         dictionary = new Dictionary<Guid, InstanceKeyView>(source.InstanceKeys.Count);
         foreach (KeyValuePair<Guid, InstanceKeyView> pair in source.InstanceKeys)
         {
             dictionary.Add(pair.Key, pair.Value.Clone());
         }
     }
     this.InstanceKeys = (dictionary == null) ? null : new ReadOnlyDictionary<Guid, InstanceKeyView>(dictionary, false);
 }
 protected internal override void Validate(InstanceView view)
 {
     if (view.IsBoundToInstanceOwner)
     {
         throw FxTrace.Exception.AsError(new InvalidOperationException(SRCore.AlreadyBoundToOwner));
     }
     InstancePersistence.ValidatePropertyBag(this.instanceOwnerMetadata);
 }
    //end
    protected void btnEdit_ServerClick(object sender, EventArgs e)
    {
        if (((this.txtName.Value.Length == 0) || (this.uploadurl.Value.Length == 0)) || (this.selWorkFlow.SelectedValue.Length == 0))
        {
            MessageBox.Show(this, "请您填写完整的信息");
        }
        else
        {
            Model.SelectRecord selectRecord = new Model.SelectRecord("WorkFlow", "", "*", "where id='" + this.selWorkFlow.SelectedValue + "'");
            DataTable table = BLL.SelectRecord.SelectRecordData(selectRecord).Tables[0];
            string content = File.ReadAllText(System.Web.HttpContext.Current.Request.MapPath("../") + table.Rows[0]["URL"].ToString());

            //ziyunhx add 2013-8-5 workflow Persistence
            //old code
            //WorkFlowTracking.instance = engineManager.createInstance(content, null, null);
            //WorkFlowTracking.instance.Run();
            //new code
            instance = engineManager.createInstance(content, null, null);
            if (instanceStore == null)
            {
                instanceStore = new SqlWorkflowInstanceStore(SqlHelper.strconn);
                view = instanceStore.Execute(instanceStore.CreateInstanceHandle(), new CreateWorkflowOwnerCommand(), TimeSpan.FromSeconds(30));
                instanceStore.DefaultInstanceOwner = view.InstanceOwner;
            }
            instance.InstanceStore = instanceStore;
            instance.Run();
            //end

            Model.Document documents = new Model.Document
            {
                ID = id.Trim(),
                Name = this.txtName.Value.Trim(),
                URL = this.uploadurl.Value.Trim(),
                Remark = this.txtReMark.Value.Trim(),
                WID = this.selWorkFlow.SelectedValue,
                WStep = "0",
                Result = "0",
                UID = this.Session["admin"].ToString(),
                //ziyunhx add 2013-8-5 workflow Persistence
                //old code
                //FlowInstranceID = WorkFlowTracking.instance.Id,
                //new code
                FlowInstranceID = instance.Id,
                //end
            };

            if (BLL.Document.DocumentUpdate(documents) == 1)
            {
                UserOperatingManager.InputUserOperating(this.Session["admin"].ToString(), "工作流管理", "编辑工作流" + documents.Name + "的信息成功");
                MessageBox.ShowAndRedirect(this, "编辑公文成功!", "/document/DocumentList.aspx");
            }
            else
            {
                UserOperatingManager.InputUserOperating(this.Session["admin"].ToString(), "工作流管理", "编辑工作流" + documents.Name + "的信息失败");
                MessageBox.Show(this, "编辑工作流失败");
            }
        }
    }
		internal InstancePersistenceContext (InstanceHandle handle, InstanceView view)
		{
			if (handle == null)
				throw new ArgumentNullException ("handle");
			if (view == null)
				throw new ArgumentNullException ("view");

			InstanceHandle = handle;
			InstanceView = view;
		}
Example #9
0
        internal InstanceHandle(InstanceStore store, InstanceOwner owner)
        {
            Fx.Assert(store != null, "Shouldn't be possible.");

            Version = -1;
            Store = store;
            Owner = owner;
            View = new InstanceView(owner);
            IsValid = true;
        }
Example #10
0
        internal InstancePersistenceContext(InstanceHandle handle, InstanceView view)
        {
            if (handle == null)
            {
                throw new ArgumentNullException("handle");
            }
            if (view == null)
            {
                throw new ArgumentNullException("view");
            }

            InstanceHandle = handle;
            InstanceView   = view;
        }
Example #11
0
        internal InstanceHandle(InstanceStore store, InstanceOwner owner, Guid instanceId)
        {
            Fx.Assert(store != null, "Shouldn't be possible here either.");
            Fx.Assert(instanceId != Guid.Empty, "Should be validating this.");

            Version = -1;
            Store = store;
            Owner = owner;
            Id = instanceId;
            View = new InstanceView(owner, instanceId);
            IsValid = true;
            if (Fx.Trace.IsEtwProviderEnabled)
            {
                eventTraceActivity = new EventTraceActivity(instanceId);
            }
        }
Example #12
0
        internal InstanceHandle(InstanceStore store, InstanceOwner owner, Guid instanceId)
        {
            Fx.Assert(store != null, "Shouldn't be possible here either.");
            Fx.Assert(instanceId != Guid.Empty, "Should be validating this.");

            Version = -1;
            Store   = store;
            Owner   = owner;
            Id      = instanceId;
            View    = new InstanceView(owner, instanceId);
            IsValid = true;
            if (Fx.Trace.IsEtwProviderEnabled)
            {
                eventTraceActivity = new EventTraceActivity(instanceId);
            }
        }
Example #13
0
        // Returns null if an InstanceHandleConflictException should be thrown.
        internal InstanceView Commit(InstanceView newState)
        {
            Fx.Assert(newState != null, "Null view passed to Commit.");
            newState.MakeReadOnly();
            View = newState;

            List<InstanceHandleReference> handlesPendingResolution = null;
            InstanceHandle handleToFree = null;
            List<InstancePersistenceEvent> normals = null;
            WaitForEventsAsyncResult resultToComplete = null;
            try
            {
                lock (ThisLock)
                {
                    if (this.inProgressBind != null)
                    {
                        // If there's a Version, it should be committed.
                        if (Version != -1)
                        {
                            if (!Owner.TryCompleteBind(ref this.inProgressBind, ref handlesPendingResolution, out handleToFree))
                            {
                                return null;
                            }
                        }
                        else
                        {
                            Fx.Assert(OperationPending, "Should have cancelled this bind in FinishOperation.");
                            Fx.Assert(AcquirePending == null, "Should not be in Commit during AcquirePending.");
                            Owner.CancelBind(ref this.inProgressBind, ref handlesPendingResolution);
                        }
                    }

                    if (this.pendingOwnerEvents != null && IsValid)
                    {
                        if (this.boundOwnerEvents == null)
                        {
                            this.boundOwnerEvents = new HashSet<XName>();
                        }

                        foreach (InstancePersistenceEvent persistenceEvent in this.pendingOwnerEvents)
                        {
                            if (!this.boundOwnerEvents.Add(persistenceEvent.Name))
                            {
                                Fx.Assert("Should not have conflicts between pending and bound events.");
                                continue;
                            }

                            InstancePersistenceEvent normal = Store.AddHandleToEvent(this, persistenceEvent, Owner);
                            if (normal != null)
                            {
                                if (normals == null)
                                {
                                    normals = new List<InstancePersistenceEvent>(this.pendingOwnerEvents.Count);
                                }
                                normals.Add(normal);
                            }
                        }

                        this.pendingOwnerEvents = null;

                        if (normals != null && this.waitResult != null)
                        {
                            resultToComplete = this.waitResult;
                            this.waitResult = null;
                        }
                    }

                    return View;
                }
            }
            finally
            {
                InstanceOwner.ResolveHandles(handlesPendingResolution);

                // This is a convenience, it is not required for correctness.
                if (handleToFree != null)
                {
                    Fx.Assert(!object.ReferenceEquals(handleToFree, this), "Shouldn't have been told to free ourselves.");
                    handleToFree.Free();
                }

                if (resultToComplete != null)
                {
                    resultToComplete.Signaled(normals);
                }
            }
        }
Example #14
0
        internal InstanceView Commit(InstanceView newState)
        {
            InstanceView view;

            newState.MakeReadOnly();
            this.View = newState;
            List <InstanceHandleReference> handlesPendingResolution = null;
            InstanceHandle handleToFree = null;
            List <InstancePersistenceEvent> persistenceEvents = null;
            WaitForEventsAsyncResult        waitResult        = null;

            try
            {
                lock (this.ThisLock)
                {
                    if (this.inProgressBind != null)
                    {
                        if (this.Version != -1L)
                        {
                            if (!this.Owner.TryCompleteBind(ref this.inProgressBind, ref handlesPendingResolution, out handleToFree))
                            {
                                return(null);
                            }
                        }
                        else
                        {
                            this.Owner.CancelBind(ref this.inProgressBind, ref handlesPendingResolution);
                        }
                    }
                    if ((this.pendingOwnerEvents != null) && this.IsValid)
                    {
                        if (this.boundOwnerEvents == null)
                        {
                            this.boundOwnerEvents = new HashSet <XName>();
                        }
                        foreach (InstancePersistenceEvent event2 in this.pendingOwnerEvents)
                        {
                            if (this.boundOwnerEvents.Add(event2.Name))
                            {
                                InstancePersistenceEvent item = this.Store.AddHandleToEvent(this, event2, this.Owner);
                                if (item != null)
                                {
                                    if (persistenceEvents == null)
                                    {
                                        persistenceEvents = new List <InstancePersistenceEvent>(this.pendingOwnerEvents.Count);
                                    }
                                    persistenceEvents.Add(item);
                                }
                            }
                        }
                        this.pendingOwnerEvents = null;
                        if ((persistenceEvents != null) && (this.waitResult != null))
                        {
                            waitResult      = this.waitResult;
                            this.waitResult = null;
                        }
                    }
                    view = this.View;
                }
            }
            finally
            {
                InstanceOwner.ResolveHandles(handlesPendingResolution);
                if (handleToFree != null)
                {
                    handleToFree.Free();
                }
                if (waitResult != null)
                {
                    waitResult.Signaled(persistenceEvents);
                }
            }
            return(view);
        }
 protected internal virtual void Validate(InstanceView view)
 {
 }
Example #16
0
 protected internal virtual void Validate(InstanceView view)
 {
 }
 void CommitHelper()
 {
     this.finalState = this.context.InstanceHandle.Commit(this.context.InstanceView);
 }
            bool DoWaitForTransaction(bool synchronous)
            {
                if (this.waitForTransaction != null)
                {
                    if (synchronous)
                    {
                        TimeSpan waitTimeout = this.timeoutHelper.RemainingTime();
                        if (!this.waitForTransaction.Wait(waitTimeout))
                        {
                            throw Fx.Exception.AsError(new TimeoutException(InternalSR.TimeoutOnOperation(waitTimeout)));
                        }
                    }
                    else
                    {
                        if (!this.waitForTransaction.WaitAsync(ExecuteAsyncResult.onCommitWait, this, this.timeoutHelper.RemainingTime()))
                        {
                            return false;
                        }
                    }
                    Exception exception = AfterCommitWait();
                    if (exception != null)
                    {
                        throw Fx.Exception.AsError(exception);
                    }
                }
                else if (this.context.IsHostTransaction)
                {
                    // For host transactions, we need to provide a clone of the intermediate state as the final state.
                    this.finalState = this.context.InstanceView.Clone();
                    this.finalState.MakeReadOnly();

                    // The intermediate state should have the query results cleared - they are per-call of Execute.
                    this.context.InstanceView.InstanceStoreQueryResults = null;
                }
                else
                {
                    // If we get here, there's no transaction at all.  Need to "commit" the intermediate state.
                    CommitHelper();
                    if (this.finalState == null)
                    {
                        this.context.InstanceHandle.Free();
                        throw Fx.Exception.AsError(new InstanceHandleConflictException(null, this.context.InstanceView.InstanceId));
                    }
                }
                return true;
            }
 /// <summary>
 ///   Initializes the instance store
 /// </summary>
 public void CreateOwner()
 {
     using (var instanceHandle = new DisposableInstanceHandle(this.InstanceStore))
     {
         this.instanceView = this.InstanceStore.Execute(
             instanceHandle, new CreateWorkflowOwnerCommand(), Global.Timeout);
         this.InstanceStore.DefaultInstanceOwner = this.instanceView.InstanceOwner;
     }
 }
		protected internal virtual void Validate (InstanceView view)
		{
			throw new NotImplementedException ();
		}
 private bool DoWaitForTransaction(bool synchronous)
 {
     if (this.waitForTransaction != null)
     {
         if (synchronous)
         {
             TimeSpan timeout = this.timeoutHelper.RemainingTime();
             if (!this.waitForTransaction.Wait(timeout))
             {
                 throw Fx.Exception.AsError(new TimeoutException(SRCore.TimeoutOnOperation(timeout)));
             }
         }
         else if (!this.waitForTransaction.WaitAsync(onCommitWait, this, this.timeoutHelper.RemainingTime()))
         {
             return false;
         }
         Exception exception = this.AfterCommitWait();
         if (exception != null)
         {
             throw Fx.Exception.AsError(exception);
         }
     }
     else if (this.context.IsHostTransaction)
     {
         this.finalState = this.context.InstanceView.Clone();
         this.finalState.MakeReadOnly();
         this.context.InstanceView.InstanceStoreQueryResults = null;
     }
     else
     {
         this.CommitHelper();
         if (this.finalState == null)
         {
             this.context.InstanceHandle.Free();
             throw Fx.Exception.AsError(new InstanceHandleConflictException(null, this.context.InstanceView.InstanceId));
         }
     }
     return true;
 }
    //end
    protected void btnEdit_ServerClick(object sender, EventArgs e)
    {
        if (this.DropDown_sp.SelectedValue.Length == 0)
        {
            MessageBox.Show(this, "请您选择审核结果");
        }
        else
        {
            Model.SelectRecord selectRecords = new Model.SelectRecord("view_DocumentInfo", "", "*", "where id='" + id + "'");
            DataTable dt = BLL.SelectRecord.SelectRecordData(selectRecords).Tables[0];
            //ziyunhx add 2013-8-5 workflow Persistence
            if (dt == null)
            {
                return;
            }
            Model.SelectRecord selectRecord = new Model.SelectRecord("WorkFlow", "", "*", "where id='" + dt.Rows[0]["WorkFlowID"].ToString() + "'");
            DataTable table = BLL.SelectRecord.SelectRecordData(selectRecord).Tables[0];

            string content = File.ReadAllText(System.Web.HttpContext.Current.Request.MapPath("../") + table.Rows[0]["URL"].ToString());

            instance = engineManager.createInstance(content, null, null);
            if (instanceStore == null)
            {
                instanceStore = new SqlWorkflowInstanceStore(SqlHelper.strconn);
                view = instanceStore.Execute(instanceStore.CreateInstanceHandle(), new CreateWorkflowOwnerCommand(), TimeSpan.FromSeconds(30));
                instanceStore.DefaultInstanceOwner = view.InstanceOwner;
            }
            instance.InstanceStore = instanceStore;
            Guid guid = new Guid(dt.Rows[0]["FlowInstranceID"].ToString());
            instance.Load(guid);
            //end

            if (this.DropDown_sp.SelectedValue == "true")
            {
                string[] s = dt.Rows[0]["OID"].ToString().Split(new char[] { ',' });
                if (s[s.Length - 1] == "1")
                {
                    Model.SelectRecord selectExecut = new Model.SelectRecord("WorkFlowExecution", "", "*", "where DID='" + id + "' and step ='" + dt.Rows[0]["WStep"].ToString() + "' and UID='"+this.Session["admin"].ToString()+"'");
                    DataTable executdt = BLL.SelectRecord.SelectRecordData(selectExecut).Tables[0];
                    if (executdt.Rows.Count > 0)
                    {
                        MessageBox.ShowAndRedirect(this, "该公文您已审核,请等待其他人审核!", "/document/DocumentList.aspx");
                    }
                    else {
                        Model.SelectRecord selectExecutCount = new Model.SelectRecord("WorkFlowExecution", "", "distinct UID", "where DID='" + id + "' and step ='" + dt.Rows[0]["WStep"].ToString() + "'");
                        DataTable dtcount = BLL.SelectRecord.SelectRecordData(selectExecutCount).Tables[0];

                        string where = "where IsState=2 AND (1=2 ";

                        string[] str = dt.Rows[0]["OID"].ToString().Split(new char[] { ',' });
                        for (int j = 1; j < str.Length-1; j++)
                        {
                            where += "OR OID like '%" + str[j].ToString() + "%' ";
                        }
                        where += ") order by id desc";

                        Model.SelectRecord selectUserCount = new Model.SelectRecord("Users", "", "ID", where);
                        DataTable usercount = BLL.SelectRecord.SelectRecordData(selectUserCount).Tables[0];

                        if (dtcount.Rows.Count + 1 == usercount.Rows.Count)
                        {
                            if (instance.GetBookmarks().Count(p => p.BookmarkName == dt.Rows[0]["value"].ToString()) == 1)
                            {
                                instance.ResumeBookmark(dt.Rows[0]["value"].ToString(), this.DropDown_sp.SelectedValue.ToString());
                            }
                        }

                    }
                }
                else
                {
                    //一旦审批未通过,删除该公文当前流转步骤信息
                    BLL.GeneralMethods.GeneralDelDB("WorkFlowExecution", "where DID ='" + id + "' and step='" + dt.Rows[0]["WStep"].ToString() + "'");
                    if (instance.GetBookmarks().Count(p => p.BookmarkName == dt.Rows[0]["value"].ToString()) == 1)
                    {
                        instance.ResumeBookmark(dt.Rows[0]["value"].ToString(), this.DropDown_sp.SelectedValue.ToString());
                    }
                }

                Model.WorkFlowExecution workexe = new Model.WorkFlowExecution
                {
                    DID = dt.Rows[0]["ID"].ToString(),
                    UID = this.Session["admin"].ToString(),
                    step = dt.Rows[0]["WStep"].ToString(),
                    Remark = this.txtSP.Value.Trim(),
                    Result = "1",
                };

                BLL.WorkFlowExecution.Add(workexe);
            }
            else
            {
                Model.WorkFlowExecution workexe = new Model.WorkFlowExecution
                {
                    DID = dt.Rows[0]["ID"].ToString(),
                    UID = this.Session["admin"].ToString(),
                    step = dt.Rows[0]["WStep"].ToString(),
                    Remark = this.txtSP.Value.Trim(),
                    Result = "2",
                };

                BLL.WorkFlowExecution.Add(workexe);

                if (instance.GetBookmarks().Count(p => p.BookmarkName == dt.Rows[0]["value"].ToString()) == 1)
                {
                    instance.ResumeBookmark(dt.Rows[0]["value"].ToString(), this.DropDown_sp.SelectedValue.ToString());
                }
            }
            UserOperatingManager.InputUserOperating(this.Session["admin"].ToString(), "公文管理", "公文审核" + dt.Rows[0]["Name"].ToString() + "的信息成功");
            MessageBox.ShowAndRedirect(this, "审核公文成功!", "/document/DocumentList.aspx");

            instance.Unload();
        }
    }
 internal virtual IEnumerable<InstancePersistenceCommand> Reduce(InstanceView view)
 {
     return null;
 }
Example #24
0
        // Returns null if an InstanceHandleConflictException should be thrown.
        internal InstanceView Commit(InstanceView newState)
        {
            Fx.Assert(newState != null, "Null view passed to Commit.");
            newState.MakeReadOnly();
            View = newState;

            List <InstanceHandleReference> handlesPendingResolution = null;
            InstanceHandle handleToFree                      = null;
            List <InstancePersistenceEvent> normals          = null;
            WaitForEventsAsyncResult        resultToComplete = null;

            try
            {
                lock (ThisLock)
                {
                    if (this.inProgressBind != null)
                    {
                        // If there's a Version, it should be committed.
                        if (Version != -1)
                        {
                            if (!Owner.TryCompleteBind(ref this.inProgressBind, ref handlesPendingResolution, out handleToFree))
                            {
                                return(null);
                            }
                        }
                        else
                        {
                            Fx.Assert(OperationPending, "Should have cancelled this bind in FinishOperation.");
                            Fx.Assert(AcquirePending == null, "Should not be in Commit during AcquirePending.");
                            Owner.CancelBind(ref this.inProgressBind, ref handlesPendingResolution);
                        }
                    }

                    if (this.pendingOwnerEvents != null && IsValid)
                    {
                        if (this.boundOwnerEvents == null)
                        {
                            this.boundOwnerEvents = new HashSet <XName>();
                        }

                        foreach (InstancePersistenceEvent persistenceEvent in this.pendingOwnerEvents)
                        {
                            if (!this.boundOwnerEvents.Add(persistenceEvent.Name))
                            {
                                Fx.Assert("Should not have conflicts between pending and bound events.");
                                continue;
                            }

                            InstancePersistenceEvent normal = Store.AddHandleToEvent(this, persistenceEvent, Owner);
                            if (normal != null)
                            {
                                if (normals == null)
                                {
                                    normals = new List <InstancePersistenceEvent>(this.pendingOwnerEvents.Count);
                                }
                                normals.Add(normal);
                            }
                        }

                        this.pendingOwnerEvents = null;

                        if (normals != null && this.waitResult != null)
                        {
                            resultToComplete = this.waitResult;
                            this.waitResult  = null;
                        }
                    }

                    return(View);
                }
            }
            finally
            {
                InstanceOwner.ResolveHandles(handlesPendingResolution);

                // This is a convenience, it is not required for correctness.
                if (handleToFree != null)
                {
                    Fx.Assert(!object.ReferenceEquals(handleToFree, this), "Shouldn't have been told to free ourselves.");
                    handleToFree.Free();
                }

                if (resultToComplete != null)
                {
                    resultToComplete.Signaled(normals);
                }
            }
        }
Example #25
0
 internal virtual IEnumerable <InstancePersistenceCommand> Reduce(InstanceView view)
 {
     return(null);
 }
 internal InstanceView Commit(InstanceView newState)
 {
     InstanceView view;
     newState.MakeReadOnly();
     this.View = newState;
     List<InstanceHandleReference> handlesPendingResolution = null;
     InstanceHandle handleToFree = null;
     List<InstancePersistenceEvent> persistenceEvents = null;
     WaitForEventsAsyncResult waitResult = null;
     try
     {
         lock (this.ThisLock)
         {
             if (this.inProgressBind != null)
             {
                 if (this.Version != -1L)
                 {
                     if (!this.Owner.TryCompleteBind(ref this.inProgressBind, ref handlesPendingResolution, out handleToFree))
                     {
                         return null;
                     }
                 }
                 else
                 {
                     this.Owner.CancelBind(ref this.inProgressBind, ref handlesPendingResolution);
                 }
             }
             if ((this.pendingOwnerEvents != null) && this.IsValid)
             {
                 if (this.boundOwnerEvents == null)
                 {
                     this.boundOwnerEvents = new HashSet<XName>();
                 }
                 foreach (InstancePersistenceEvent event2 in this.pendingOwnerEvents)
                 {
                     if (this.boundOwnerEvents.Add(event2.Name))
                     {
                         InstancePersistenceEvent item = this.Store.AddHandleToEvent(this, event2, this.Owner);
                         if (item != null)
                         {
                             if (persistenceEvents == null)
                             {
                                 persistenceEvents = new List<InstancePersistenceEvent>(this.pendingOwnerEvents.Count);
                             }
                             persistenceEvents.Add(item);
                         }
                     }
                 }
                 this.pendingOwnerEvents = null;
                 if ((persistenceEvents != null) && (this.waitResult != null))
                 {
                     waitResult = this.waitResult;
                     this.waitResult = null;
                 }
             }
             view = this.View;
         }
     }
     finally
     {
         InstanceOwner.ResolveHandles(handlesPendingResolution);
         if (handleToFree != null)
         {
             handleToFree.Free();
         }
         if (waitResult != null)
         {
             waitResult.Signaled(persistenceEvents);
         }
     }
     return view;
 }
 protected internal virtual void Validate(InstanceView view)
 {
     throw new NotImplementedException();
 }