public void ModelChanged(object sender, ModelChangedEventArgs e)
        {
            //mainSequence = ((System.Activities.Presentation.Model.) (sender)).Root;

                mainSequence = (e.ModelChangeInfo).Value.Root.GetCurrentValue() as Sequence;

            //workflowDesigner.Context.Items.Load(mainSequence);

            //{
            //    ModelItem item = e.ItemsAdded.FirstOrDefault<ModelItem>();
            //    var test = item.GetCurrentValue() as HttpRequestActivity;

            //    if (test != null && test.Id == null)
            //    {
            //        //do whatever initialization logic is needed here
            //    }
            //}
        }
 public void TestModelServiceModelChanged(ModelChangedEventArgs e)
 {
     ModelServiceModelChanged(null, e);
 }
            void ModelChanged(object sender, ModelChangedEventArgs e)
            {
                ModelChangeInfo changeInfo = e.ModelChangeInfo;

                if (changeInfo != null && changeInfo.ModelChangeType == ModelChangeType.PropertyChanged)
                {
                    Type propertyType = changeInfo.Subject.ItemType;
                    if (changeInfo.PropertyName == "Name")
                    {
                        if (propertyType.Equals(typeof(ActivityBuilder)))
                        {
                            activityBuilderDisplayNameProperty.NotifyPropertyChanged(changeInfo.Subject);
                        }
                        else if (propertyType.Equals(typeof(ActivityTemplateFactoryBuilder)))
                        {
                            activityTemplateFactoryBuilderDisplayNameProperty.NotifyPropertyChanged(changeInfo.Subject);
                        }
                    }
                }
            }
        /// <summary>
        /// Sets the defaults on InArgument, OutArgument and InOutArgument Activity arguments based on a DefaultValue
        /// </summary>
        /// <param name="sender">The </param>
        /// <param name="e"></param>
        private void SetDefaultArguments(object sender, ModelChangedEventArgs e)
        {
            IEnumerable<ModelItem> enumerator = e.ItemsAdded;
            if (enumerator == null)
            {
                return;
            }

            foreach (ModelItem mi in enumerator)
            {
                if (mi == null)
                {
                    return;
                }
                foreach (var item in mi.Properties)
                {
                    if (item == null)
                    {
                        return;
                    }
                    Type propertyType = item.PropertyType;

                    Type[] typeParameters = propertyType.GetGenericArguments();

                    if (typeParameters.Length > 0)
                    {
                        Type genericType = typeParameters[0];
                        if (item.DefaultValue != null)
                        {
                            object genericArgumentInstance = null;

                            if (typeof(InArgument).IsAssignableFrom(propertyType))
                            {
                                var inArgument = typeof(InArgument<>);
                                var vbValue = typeof(VisualBasicValue<>);
                                genericArgumentInstance = GetGenericArgumentInstance(item, inArgument, genericType, vbValue);
                            }
                            else if (typeof(InOutArgument).IsAssignableFrom(propertyType))
                            {
                                var inOutArgument = typeof(InOutArgument<>);
                                var vbRefernec = typeof(VisualBasicReference<>);
                                genericArgumentInstance = GetGenericArgumentInstance(item, inOutArgument, genericType, vbRefernec);
                            }
                            else if (typeof(OutArgument).IsAssignableFrom(propertyType))
                            {
                                var outArgument = typeof(OutArgument<>);
                                var vbRefernece1 = typeof(VisualBasicReference<>);
                                genericArgumentInstance = GetGenericArgumentInstance(item, outArgument, genericType, vbRefernece1);
                            }
                            else
                            {
                                throw new DevFacingException(MSG_SetArguments_Error);
                            }

                            item.SetValue(genericArgumentInstance);
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Response the model items changed
 /// </summary>
 private void ModelService_ModelChanged(object sender, ModelChangedEventArgs e)
 {
     if (e.ItemsAdded != null)
     {
         CompositeWorkflow.ModelService_ItemsAdded(e.ItemsAdded);
     }
     else if (e.PropertiesChanged != null)
     {
         CompositeWorkflow.ModelService_PropertiesChanged(e.PropertiesChanged);
     }
 }