public void UnregisterProperties(System.Activities.ActivityInstance completedInstance, IdSpace currentIdSpace, bool ignoreExceptions)
 {
     if (this.IsOwner(completedInstance))
     {
         RegistrationContext context = new RegistrationContext(this, currentIdSpace);
         foreach (ExecutionProperty property in this.properties.Values)
         {
             property.IsRemoved = true;
             IPropertyRegistrationCallback callback = property.Property as IPropertyRegistrationCallback;
             if (callback != null)
             {
                 try
                 {
                     callback.Unregister(context);
                 }
                 catch (Exception exception)
                 {
                     if (Fx.IsFatal(exception) || !ignoreExceptions)
                     {
                         throw;
                     }
                 }
             }
         }
         this.properties.Clear();
     }
 }
Esempio n. 2
0
 internal bool Remove(string name, bool skipValidations)
 {
     if (!skipValidations)
     {
         if (string.IsNullOrEmpty(name))
         {
             throw FxTrace.Exception.ArgumentNullOrEmpty("name");
         }
         this.ThrowIfActivityExecutionContextDisposed();
     }
     if ((this.properties != null) && this.properties.IsOwner(this.scope))
     {
         object propertyAtCurrentScope = this.properties.GetPropertyAtCurrentScope(name);
         if (propertyAtCurrentScope != null)
         {
             if (!skipValidations)
             {
                 Handle handle = propertyAtCurrentScope as Handle;
                 if ((handle == null) || !handle.CanBeRemovedWithExecutingChildren)
                 {
                     this.ThrowIfChildrenAreExecuting();
                 }
             }
             this.properties.Remove(name);
             IPropertyRegistrationCallback callback = propertyAtCurrentScope as IPropertyRegistrationCallback;
             if (callback != null)
             {
                 callback.Unregister(new RegistrationContext(this.properties, this.currentIdSpace));
             }
             return(true);
         }
     }
     return(false);
 }
        internal void Add(string name, object property, bool skipValidations, bool onlyVisibleToPublicChildren)
        {
            if (!skipValidations)
            {
                if (string.IsNullOrEmpty(name))
                {
                    throw FxTrace.Exception.ArgumentNullOrEmpty("name");
                }

                if (property == null)
                {
                    throw FxTrace.Exception.ArgumentNull("property");
                }

                ThrowIfActivityExecutionContextDisposed();
                ThrowIfChildrenAreExecuting();
            }

            if (this.properties != null)
            {
                this.properties.ThrowIfAlreadyDefined(name, this.scope);
            }

            IPropertyRegistrationCallback registrationCallback = property as IPropertyRegistrationCallback;

            if (registrationCallback != null)
            {
                registrationCallback.Register(new RegistrationContext(this.properties, this.currentIdSpace));
            }

            if (this.properties == null)
            {
                this.properties = new ExecutionPropertyManager(this.scope);
            }
            else if (!this.properties.IsOwner(this.scope))
            {
                //
                this.properties = new ExecutionPropertyManager(this.scope, this.properties);
            }

            IdSpace visibility = null;

            if (onlyVisibleToPublicChildren)
            {
                Fx.Assert(this.currentIdSpace != null, "We should never call OnlyVisibleToPublicChildren when we don't have a currentIdSpace");
                visibility = this.currentIdSpace;
            }

            this.properties.Add(name, property, visibility);
        }
Esempio n. 4
0
        internal bool Remove(string name, bool skipValidations)
        {
            if (!skipValidations)
            {
                if (string.IsNullOrEmpty(name))
                {
                    throw CoreWf.Internals.FxTrace.Exception.ArgumentNullOrEmpty("name");
                }

                ThrowIfActivityExecutionContextDisposed();
            }

            if (_properties != null && _properties.IsOwner(_scope))
            {
                object property = _properties.GetPropertyAtCurrentScope(name);

                if (property != null)
                {
                    if (!skipValidations)
                    {
                        Handle handleProperty = property as Handle;

                        if (handleProperty == null || !handleProperty.CanBeRemovedWithExecutingChildren)
                        {
                            ThrowIfChildrenAreExecuting();
                        }
                    }

                    _properties.Remove(name);

                    IPropertyRegistrationCallback registrationCallback = property as IPropertyRegistrationCallback;

                    if (registrationCallback != null)
                    {
                        registrationCallback.Unregister(new RegistrationContext(_properties, _currentIdSpace));
                    }

                    return(true);
                }
            }

            return(false);
        }
Esempio n. 5
0
        public void UnregisterProperties(ActivityInstance completedInstance, IdSpace currentIdSpace, bool ignoreExceptions)
        {
            if (IsOwner(completedInstance))
            {
                RegistrationContext registrationContext = new RegistrationContext(this, currentIdSpace);

                foreach (ExecutionProperty property in _properties.Values)
                {
                    // We do a soft removal because we're about to throw away this dictionary
                    // and we don't want to mess up our enumerator
                    property.IsRemoved = true;

                    IPropertyRegistrationCallback registrationCallback = property.Property as IPropertyRegistrationCallback;

                    if (registrationCallback != null)
                    {
                        try
                        {
                            registrationCallback.Unregister(registrationContext);
                        }
                        catch (Exception e)
                        {
                            if (Fx.IsFatal(e) || !ignoreExceptions)
                            {
                                throw;
                            }
                        }
                    }
                }

                Fx.Assert(completedInstance == null || completedInstance.GetRawChildren() == null || completedInstance.GetRawChildren().Count == 0, "There must not be any children at this point otherwise our exclusive handle count would be incorrect.");

                // We still need to clear this list in case any non-serializable
                // properties were being used in a no persist zone
                _properties.Clear();
            }
        }