示例#1
0
        public void RefreshBus_RefreshObject(object sender, RefreshObjectEventArgs e)
        {
            var descendancy = e.DeletedObjectDescendancy ?? _activator.CoreChildProvider.GetDescendancyListIfAnyFor(e.Object);

            //implementation of the anoymous callback
            var o = e.Object as T;

            //if the descendancy contained our object Type we should also consider a refresh
            if (o == null && descendancy != null)
            {
                o = (T)descendancy.Parents.LastOrDefault(p => p is T);
            }

            //don't respond to events raised by the user themself!
            if (sender == User)
            {
                return;
            }

            //if the original object does not exist anymore (could be a CASCADE event so we do have to check it every time regardless of what object type is refreshing)
            if (!OriginalObject.Exists())//object no longer exists!
            {
                var parent = User.ParentForm;
                if (parent != null && !parent.IsDisposed)
                {
                    parent.Close();//self destruct because object was deleted
                }
                return;
            }

            if (o != null && o.ID == OriginalObject.ID && o.GetType() == OriginalObject.GetType()) //object was refreshed, probably an update to some fields in it
            {
                User.SetDatabaseObject(_activator, o);                                             //give it the new object
            }
        }
示例#2
0
文件: RefreshBus.cs 项目: lulzzz/RDMP
        public void Publish(object sender, RefreshObjectEventArgs e)
        {
            if (PublishInProgress)
            {
                throw new SubscriptionException("Refresh Publish Cascade error.  Subscriber " + sender + " just attempted a publish during an existing publish execution, cylic inception publishing is not allowed, you cannot respond to a refresh callback by issuing more refresh publishes");
            }

            lock (oPublishLock)
            {
                if (BeforePublish != null)
                {
                    BeforePublish(sender, e);
                }

                PublishInProgress = true;

                //refresh it from the child provider
                if (e.Exists)
                {
                    if (ChildProvider != null)
                    {
                        var fresh = ChildProvider.GetLatestCopyOf(e.Object);

                        if (fresh != null)
                        {
                            e.Object = fresh;
                        }
                        else
                        {
                            e.Object.RevertToDatabaseState();
                        }
                    }
                    else
                    {
                        e.Object.RevertToDatabaseState();
                    }
                }

                try
                {
                    if (RefreshObject != null)
                    {
                        RefreshObject(sender, e);
                    }
                }
                finally
                {
                    PublishInProgress = false;
                }
            }
        }
示例#3
0
        public void Publish(object sender, RefreshObjectEventArgs e)
        {
            if (PublishInProgress)
            {
                throw new SubscriptionException("Refresh Publish Cascade error.  Subscriber " + sender + " just attempted a publish during an existing publish execution, cylic inception publishing is not allowed, you cannot respond to a refresh callback by issuing more refresh publishes");
            }

            lock (oPublishLock)
            {
                BeforePublish?.Invoke(sender, e);

                try
                {
                    PublishInProgress = true;
                    // Set cursor as hourglass
                    Cursor.Current = Cursors.WaitCursor;

                    //refresh it from the child provider
                    if (e.Exists)
                    {
                        if (ChildProvider != null)
                        {
                            var fresh = ChildProvider.GetLatestCopyOf(e.Object);

                            if (fresh != null)
                            {
                                e.Object = fresh;
                            }
                            else
                            {
                                e.Object.RevertToDatabaseState();
                            }
                        }
                        else
                        {
                            e.Object.RevertToDatabaseState();
                        }
                    }

                    RefreshObject?.Invoke(sender, e);
                }
                finally
                {
                    AfterPublish?.Invoke(this, e);
                    PublishInProgress = false;
                    Cursor.Current    = Cursors.Default;
                }
            }
        }