private void FillArguments()
        {
            string propertyName = PropertyReferenceUtilities.GetPropertyReference(this.ModelItem.GetCurrentValue(), DelegatePropertyName);

            if (string.IsNullOrEmpty(propertyName))
            {
                return;
            }

            ModelTreeManager        manager  = this.Context.Services.GetService <ModelTreeManager>();
            DynamicActivityProperty property = DynamicActivityPropertyUtilities.Find(manager.Root.Properties["Properties"].Collection, propertyName);

            if (property == null || !property.Type.IsSubclassOf(typeof(ActivityDelegate)))
            {
                return;
            }

            ActivityDelegateMetadata metadata = ActivityDelegateUtilities.GetMetadata(property.Type);

            ModelItemCollection collection = this.ModelItem.Properties[DelegateArgumentsPropertyName].Value.Properties["ItemsCollection"].Collection;

            Type underlyingArgumentType = this.ModelItem.Properties[DelegateArgumentsPropertyName].Value.GetCurrentValue().GetType().GetGenericArguments()[1];

            if (!typeof(Argument).IsAssignableFrom(underlyingArgumentType))
            {
                return;
            }

            if (collection.Count == 0)
            {
                using (ModelEditingScope change = collection.BeginEdit(SR.FillDelegateArguments))
                {
                    Type dictionaryEntryType = typeof(ModelItemKeyValuePair <,>).MakeGenericType(new Type[] { typeof(string), underlyingArgumentType });
                    foreach (ActivityDelegateArgumentMetadata arg in metadata)
                    {
                        Argument  argument       = Argument.Create(arg.Type, arg.Direction == ActivityDelegateArgumentDirection.In ? ArgumentDirection.In : ArgumentDirection.Out);
                        object    mutableKVPair  = Activator.CreateInstance(dictionaryEntryType, new object[] { arg.Name, argument });
                        ModelItem argumentKVPair = collection.Add(mutableKVPair);
                    }

                    change.Complete();
                }
            }
        }
Beispiel #2
0
        internal bool ShouldAppearOnBreadCrumb(ModelItem modelItem, bool checkIfCanBeMadeRoot)
        {
            bool shouldAppearOnBreadCrumb = false;

            if (modelItem != null)
            {
                Type designerType = this.GetDesignerType(modelItem.ItemType);
                if (null != designerType)
                {
                    if (checkIfCanBeMadeRoot)
                    {
                        ActivityDesignerOptionsAttribute options = WorkflowViewService.GetAttribute <ActivityDesignerOptionsAttribute>(modelItem.ItemType);
                        shouldAppearOnBreadCrumb = (typeof(WorkflowViewElement).IsAssignableFrom(designerType) &&
                                                    (typeof(ActivityDesigner) != designerType || ActivityDelegateUtilities.HasActivityDelegate(modelItem.ItemType)) &&
                                                    typeof(WorkflowService) != designerType &&
                                                    (options == null || options.AllowDrillIn));
                    }
                    else
                    {
                        shouldAppearOnBreadCrumb = typeof(WorkflowViewElement).IsAssignableFrom(designerType);
                    }
                }
            }
            return(shouldAppearOnBreadCrumb);
        }
            protected override void Execute(NativeActivityContext context)
            {
                StringBuilder  errorBuilder = new StringBuilder();
                InvokeDelegate activity     = this.Activity.Get(context);

                string reference = PropertyReferenceUtilities.GetPropertyReference(activity, "Delegate");

                if (reference != null)
                {
                    DynamicActivityProperty property = null;

                    ModelTreeManager manager = this.EditingContext.Services.GetService <ModelTreeManager>();
                    if (manager.Root.ItemType == typeof(ActivityBuilder))
                    {
                        property = DynamicActivityPropertyUtilities.Find(manager.Root.Properties["Properties"].Collection, reference);
                    }

                    if (property == null)
                    {
                        this.EmitValidationError(context, string.Format(CultureInfo.CurrentUICulture, SR.PropertyReferenceNotResolved, reference));
                        return;
                    }

                    if (property.Type == typeof(ActivityDelegate))
                    {
                        this.EmitValidationWarning(context, string.Format(CultureInfo.CurrentUICulture, SR.PropertyIsNotAConcreteActivityDelegate, reference));
                        return;
                    }

                    if (!property.Type.IsSubclassOf(typeof(ActivityDelegate)))
                    {
                        this.EmitValidationError(context, string.Format(CultureInfo.CurrentUICulture, SR.PropertyIsNotAnActivityDelegate, reference));
                        return;
                    }

                    if (property.Type.IsAbstract)
                    {
                        this.EmitValidationWarning(context, string.Format(CultureInfo.CurrentUICulture, SR.PropertyIsNotAConcreteActivityDelegate, reference));
                        return;
                    }

                    ActivityDelegateMetadata metadata = ActivityDelegateUtilities.GetMetadata(property.Type);

                    if (activity.DelegateArguments.Count != metadata.Count)
                    {
                        this.EmitValidationWarning(context, SR.WrongNumberOfArgumentsForActivityDelegate);
                        return;
                    }

                    foreach (ActivityDelegateArgumentMetadata expectedArgument in metadata)
                    {
                        Argument delegateArgument = null;

                        if (activity.DelegateArguments.TryGetValue(expectedArgument.Name, out delegateArgument))
                        {
                            if ((expectedArgument.Direction == ActivityDelegateArgumentDirection.In && delegateArgument.Direction != ArgumentDirection.In) ||
                                (expectedArgument.Direction == ActivityDelegateArgumentDirection.Out && delegateArgument.Direction != ArgumentDirection.Out))
                            {
                                errorBuilder.AppendFormat(CultureInfo.CurrentUICulture, SR.DelegateArgumentsDirectionalityMismatch, expectedArgument.Name, delegateArgument.Direction, expectedArgument.Direction);
                            }

                            if (delegateArgument.ArgumentType != expectedArgument.Type)
                            {
                                if (expectedArgument.Direction == ActivityDelegateArgumentDirection.In)
                                {
                                    if (!TypeHelper.AreTypesCompatible(delegateArgument.ArgumentType, expectedArgument.Type))
                                    {
                                        errorBuilder.AppendFormat(CultureInfo.CurrentUICulture, SR.DelegateInArgumentTypeMismatch, expectedArgument.Name, expectedArgument.Type, delegateArgument.ArgumentType);
                                    }
                                }
                                else
                                {
                                    if (!TypeHelper.AreTypesCompatible(expectedArgument.Type, delegateArgument.ArgumentType))
                                    {
                                        errorBuilder.AppendFormat(CultureInfo.CurrentUICulture, SR.DelegateOutArgumentTypeMismatch, expectedArgument.Name, expectedArgument.Type, delegateArgument.ArgumentType);
                                    }
                                }
                            }
                        }
                        else
                        {
                            errorBuilder.AppendFormat(CultureInfo.CurrentUICulture, SR.DelegateArgumentMissing, expectedArgument.Name);
                        }
                    }

                    if (errorBuilder.Length > 0)
                    {
                        this.EmitValidationWarning(context, errorBuilder.ToString());
                    }
                }
            }