Ejemplo n.º 1
0
        public override void SetValue(object component, object value)
        {
            if (component != null)
            {
                ISite site = GetSite(component);
                IComponentChangeService changeService = null;
                if (site != null)
                {
                    changeService = (IComponentChangeService)site.GetService(typeof(IComponentChangeService));
                }

                // Raise the OnComponentChanging event
                changeService.OnComponentChanging(component, this);

                // Save the old value
                object oldValue = GetValue(component);

                try
                {
                    WorkflowParameterBindingCollection parameters = GetParameters(component);
                    if (parameters != null)
                    {
                        if (value == null)
                        {
                            // Remove the binding from the ParameterBindings collection
                            parameters.Remove(this.Name);
                        }
                        else
                        {
                            // Add the binding to the ParameterBindings collection
                            WorkflowParameterBinding binding = null;
                            if (parameters.Contains(this.Name))
                            {
                                binding = parameters[this.Name];
                            }
                            else
                            {
                                binding = new WorkflowParameterBinding(this.Name);
                                parameters.Add(binding);
                            }

                            // Set the binding value on the ParameterBindings collection correspondent binding item
                            if (value is ActivityBind)
                            {
                                binding.SetBinding(WorkflowParameterBinding.ValueProperty, value as ActivityBind);
                            }
                            else
                            {
                                binding.SetValue(WorkflowParameterBinding.ValueProperty, value);
                            }
                        }
                    }
                    // Raise the OnValueChanged event
                    OnValueChanged(component, EventArgs.Empty);
                }
                catch (Exception)
                {
                    value = oldValue;
                    throw;
                }
                finally
                {
                    if (changeService != null)
                    {
                        // Raise the OnComponentChanged event
                        changeService.OnComponentChanged(component, this, oldValue, value);
                    }
                }
            }
        }