Ejemplo n.º 1
0
        protected virtual void OnRemoveEventHooks(T item)
        {
            INotifyBusy busy = item as INotifyBusy;

            if (busy != null)
            {
                busy.BusyChanged -= new BusyChangedEventHandler(busy_BusyChanged);
            }

            INotifyUnhandledAsyncException unhandled = item as INotifyUnhandledAsyncException;

            if (unhandled != null)
            {
                unhandled.UnhandledAsyncException -= new EventHandler <ErrorEventArgs>(unhandled_UnhandledAsyncException);
            }

            INotifyPropertyChanged c = item as INotifyPropertyChanged;

            if (c != null)
            {
                c.PropertyChanged -= Child_PropertyChanged;
            }

            //IBindingList list = item as IBindingList;
            //if(list!=null)
            //  list.ListChanged -= new ListChangedEventHandler(Child_ListChanged);

            INotifyChildChanged child = item as INotifyChildChanged;

            if (child != null)
            {
                child.ChildChanged -= new EventHandler <ChildChangedEventArgs>(Child_Changed);
            }
        }
Ejemplo n.º 2
0
        protected virtual void OnAddEventHooks(T item)
        {
            INotifyBusy busy = item as INotifyBusy;

            if (busy != null)
            {
                busy.BusyChanged += new BusyChangedEventHandler(busy_BusyChanged);
            }

            INotifyUnhandledAsyncException unhandled = item as INotifyUnhandledAsyncException;

            if (unhandled != null)
            {
                unhandled.UnhandledAsyncException += new EventHandler <ErrorEventArgs>(unhandled_UnhandledAsyncException);
            }

            INotifyPropertyChanged c = item as INotifyPropertyChanged;

            if (c != null)
            {
                c.PropertyChanged += Child_PropertyChanged;
            }

            INotifyChildChanged child = item as INotifyChildChanged;

            if (child != null)
            {
                child.ChildChanged += Child_Changed;
            }
        }
Ejemplo n.º 3
0
        private void AttachSource(object source)
        {
            var p = source as INotifyPropertyChanged;

            if (p != null)
            {
                p.PropertyChanged += source_PropertyChanged;
            }
            INotifyBusy busy = source as INotifyBusy;

            if (busy != null)
            {
                busy.BusyChanged += source_BusyChanged;
            }
        }
Ejemplo n.º 4
0
        private void DetachSource(object source)
        {
            INotifyBusy busy = source as INotifyBusy;

            if (busy != null)
            {
                busy.BusyChanged -= new BusyChangedEventHandler(source_BusyChanged);
            }

            INotifyPropertyChanged changed = source as INotifyPropertyChanged;

            if (changed != null)
            {
                changed.PropertyChanged -= new PropertyChangedEventHandler(source_PropertyChanged);
            }
        }
Ejemplo n.º 5
0
        private void DetachSource(object source)
        {
            var p = source as INotifyPropertyChanged;

            if (p != null)
            {
                p.PropertyChanged -= source_PropertyChanged;
            }
            INotifyBusy busy = source as INotifyBusy;

            if (busy != null)
            {
                busy.BusyChanged -= source_BusyChanged;
            }

            ClearState();
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Creates an instance of the object.
 /// </summary>
 /// <param name="target">Target object.</param>
 /// <param name="timeout">Timeout value.</param>
 public BusyLocker(INotifyBusy target, TimeSpan timeout)
 {
     _event.Reset(); // set the event to non-signaled by default.
     _target  = target;
     _timeout = timeout;
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Wait until the specified object is not busy
        /// (IsBusy is false).
        /// </summary>
        /// <param name="obj">Target object.</param>
        /// <param name="timeout">Timeout value.</param>
        public static void WaitOne(INotifyBusy obj, TimeSpan timeout)
        {
            BusyLocker locker = new BusyLocker(obj, timeout);

            locker.WaitOne();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Wait until the specified object is not busy
        /// (IsBusy is false).
        /// </summary>
        /// <param name="obj">Target object.</param>
        public static void WaitOne(INotifyBusy obj)
        {
            BusyLocker locker = new BusyLocker(obj, TimeSpan.FromMilliseconds(Timeout.Infinite));

            locker.WaitOne();
        }
Ejemplo n.º 9
0
        private void SetProperties()
        {
            ITrackStatus targetObject = Model as ITrackStatus;
            ICollection  list         = Model as ICollection;
            INotifyBusy  busyObject   = Model as INotifyBusy;
            var          isObjectBusy = false;

            if (busyObject != null && busyObject.IsBusy)
            {
                isObjectBusy = true;
            }

            // Does Model instance implement ITrackStatus
            if (targetObject != null)
            {
                var canDeleteInstance = BusinessRules.HasPermission(AuthorizationActions.DeleteObject, targetObject);

                IsDirty   = targetObject.IsDirty;
                IsValid   = targetObject.IsValid;
                CanSave   = CanEditObject && targetObject.IsSavable && !isObjectBusy;
                CanCancel = CanEditObject && targetObject.IsDirty && !isObjectBusy;
                CanCreate = CanCreateObject && !targetObject.IsDirty && !isObjectBusy;
                CanDelete = CanDeleteObject && !isObjectBusy && canDeleteInstance;
                CanFetch  = CanGetObject && !targetObject.IsDirty && !isObjectBusy;

                // Set properties for List
                if (list == null)
                {
                    CanRemove = false;
                    CanAddNew = false;
                }
                else
                {
                    Type itemType = Csla.Utilities.GetChildItemType(Model.GetType());
                    if (itemType == null)
                    {
                        CanAddNew = false;
                        CanRemove = false;
                    }
                    else
                    {
                        CanRemove = BusinessRules.HasPermission(AuthorizationActions.DeleteObject, itemType) &&
                                    list.Count > 0 && !isObjectBusy;

                        CanAddNew = BusinessRules.HasPermission(AuthorizationActions.CreateObject, itemType) &&
                                    !isObjectBusy;
                    }
                }
            }

            // Else if Model instance implement ICollection
            else if (list != null)
            {
                Type itemType = Csla.Utilities.GetChildItemType(Model.GetType());
                if (itemType == null)
                {
                    CanAddNew = false;
                    CanRemove = false;
                }
                else
                {
                    CanRemove = BusinessRules.HasPermission(AuthorizationActions.DeleteObject, itemType) &&
                                list.Count > 0 && !isObjectBusy;

                    CanAddNew = BusinessRules.HasPermission(AuthorizationActions.CreateObject, itemType) &&
                                !isObjectBusy;
                }
            }
            else
            {
                IsDirty   = false;
                IsValid   = false;
                CanCancel = false;
                CanCreate = CanCreateObject;
                CanDelete = false;
                CanFetch  = CanGetObject && !IsBusy;
                CanSave   = false;
                CanRemove = false;
                CanAddNew = false;
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Creates an instance of the object.
 /// </summary>
 /// <param name="target">Target object.</param>
 /// <param name="timeout">Timeout value.</param>
 public BusyLocker(INotifyBusy target, TimeSpan timeout)
 {
   _event.Reset(); // set the event to non-signaled by default.
   _target = target;
   _timeout = timeout;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Wait until the specified object is not busy 
 /// (IsBusy is false).
 /// </summary>
 /// <param name="obj">Target object.</param>
 /// <param name="timeout">Timeout value.</param>
 public static void WaitOne(INotifyBusy obj, TimeSpan timeout)
 {
   BusyLocker locker = new BusyLocker(obj, timeout);
   locker.WaitOne();
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Wait until the specified object is not busy 
 /// (IsBusy is false).
 /// </summary>
 /// <param name="obj">Target object.</param>
 public static void WaitOne(INotifyBusy obj)
 {
   BusyLocker locker = new BusyLocker(obj, TimeSpan.FromMilliseconds(Timeout.Infinite));
   locker.WaitOne();
 }
Ejemplo n.º 13
0
        private void RefreshCanOperationsValues()
        {
            ITrackStatus targetObject = this.Data as ITrackStatus;
            ICollection  list         = this.Data as ICollection;
            INotifyBusy  busyObject   = this.Data as INotifyBusy;
            bool         isObjectBusy = false;

            if (busyObject != null && busyObject.IsBusy)
            {
                isObjectBusy = true;
            }
            if (this.Data != null && targetObject != null)
            {
                if (Csla.Rules.BusinessRules.HasPermission(Rules.AuthorizationActions.EditObject, this.Data) && targetObject.IsSavable)
                {
                    this.CanSave = true;
                }
                else
                {
                    this.CanSave = false;
                }

                if (Csla.Rules.BusinessRules.HasPermission(Rules.AuthorizationActions.EditObject, this.Data) && targetObject.IsDirty && !isObjectBusy)
                {
                    this.CanCancel = true;
                }
                else
                {
                    this.CanCancel = false;
                }

                if (Csla.Rules.BusinessRules.HasPermission(Rules.AuthorizationActions.CreateObject, this.Data) && !targetObject.IsDirty && !isObjectBusy)
                {
                    this.CanCreate = true;
                }
                else
                {
                    this.CanCreate = false;
                }

                if (Csla.Rules.BusinessRules.HasPermission(Rules.AuthorizationActions.DeleteObject, this.Data) && !isObjectBusy)
                {
                    this.CanDelete = true;
                }
                else
                {
                    this.CanDelete = false;
                }

                if (Csla.Rules.BusinessRules.HasPermission(Rules.AuthorizationActions.GetObject, this.Data) && !targetObject.IsDirty && !isObjectBusy)
                {
                    this.CanFetch = true;
                }
                else
                {
                    this.CanFetch = false;
                }

                if (list != null)
                {
                    Type itemType = Csla.Utilities.GetChildItemType(this.Data.GetType());
                    if (itemType != null)
                    {
                        if (Csla.Rules.BusinessRules.HasPermission(Rules.AuthorizationActions.DeleteObject, itemType) && ((ICollection)this.Data).Count > 0 && !isObjectBusy)
                        {
                            this.CanRemoveItem = true;
                        }
                        else
                        {
                            this.CanRemoveItem = false;
                        }

                        if (Csla.Rules.BusinessRules.HasPermission(Rules.AuthorizationActions.CreateObject, itemType) && !isObjectBusy)
                        {
                            this.CanAddNewItem = true;
                        }
                        else
                        {
                            this.CanAddNewItem = false;
                        }
                    }
                    else
                    {
                        this.CanAddNewItem = false;
                        this.CanRemoveItem = false;
                    }
                }
                else
                {
                    this.CanRemoveItem = false;
                    this.CanAddNewItem = false;
                }
            }
            else if (list != null)
            {
                Type itemType = Csla.Utilities.GetChildItemType(this.Data.GetType());
                if (itemType != null)
                {
                    if (Csla.Rules.BusinessRules.HasPermission(Rules.AuthorizationActions.DeleteObject, itemType) && ((ICollection)this.Data).Count > 0 && !isObjectBusy)
                    {
                        this.CanRemoveItem = true;
                    }
                    else
                    {
                        this.CanRemoveItem = false;
                    }

                    if (Csla.Rules.BusinessRules.HasPermission(Rules.AuthorizationActions.CreateObject, itemType) && !isObjectBusy)
                    {
                        this.CanAddNewItem = true;
                    }
                    else
                    {
                        this.CanAddNewItem = false;
                    }
                }
                else
                {
                    this.CanAddNewItem = false;
                    this.CanRemoveItem = false;
                }
            }
            else
            {
                this.CanCancel     = false;
                this.CanCreate     = false;
                this.CanDelete     = false;
                this.CanFetch      = !this.IsBusy;
                this.CanSave       = false;
                this.CanRemoveItem = false;
                this.CanAddNewItem = false;
            }
        }