예제 #1
0
        private static void ConvertNamespaces(object root, EditingContext context)
        {
            VisualBasicSettings       settings = VisualBasic.GetSettings(root);
            IList <AssemblyReference> references;
            IList <string>            importedNamespaces = NamespaceHelper.GetTextExpressionNamespaces(root, out references);
            FrameworkName             targetFramework    = WorkflowDesigner.GetTargetFramework(context);

            if (targetFramework.IsLessThan45())
            {
                if (settings == null)
                {
                    if ((importedNamespaces != null) && (importedNamespaces.Count > 0))
                    {
                        NamespaceHelper.ConvertToVBSettings(
                            importedNamespaces,
                            references,
                            context,
                            out settings);
                    }
                    else
                    {
                        settings = new VisualBasicSettings();
                    }

                    NamespaceHelper.SetVisualBasicSettings(root, settings);
                    NamespaceHelper.SetTextExpressionNamespaces(root, null, null);
                }

                IDebuggableWorkflowTree debuggableWorkflowTree = root as IDebuggableWorkflowTree;
                if (debuggableWorkflowTree != null)
                {
                    Activity rootActivity = debuggableWorkflowTree.GetWorkflowRoot();
                    if (rootActivity != null)
                    {
                        NamespaceHelper.SetVisualBasicSettings(rootActivity, settings);
                        NamespaceHelper.SetTextExpressionNamespaces(rootActivity, null, null);
                    }
                }
            }
            else
            {
                if ((importedNamespaces == null) || (importedNamespaces.Count == 0))
                {
                    if (settings != null)
                    {
                        NamespaceHelper.ConvertToTextExpressionImports(settings, out importedNamespaces, out references);
                        NamespaceHelper.SetTextExpressionNamespaces(root, importedNamespaces, references);
                        NamespaceHelper.SetVisualBasicSettings(root, null);
                    }
                    else
                    {
                        NamespaceHelper.SetTextExpressionNamespaces(root, new Collection <string>(), new Collection <AssemblyReference>());
                    }
                }
            }
        }
예제 #2
0
        public override object GetValue(object component)
        {
            VisualBasicSettings       settings = VisualBasic.GetSettings(component);
            IList <AssemblyReference> references;
            IList <string>            namespaces = NamespaceHelper.GetTextExpressionNamespaces(component, out references);

            if ((namespaces != null) && ((namespaces.Count > 0) || ((namespaces.Count == 0) && (settings == null))))
            {
                return(new TextExpressionNamespaceList(namespaces, references));
            }
            else
            {
                Fx.Assert(settings != null, "Either VB settings or new TextExpression attached properties should be set");
                return(new VisualBasicNamespaceList(settings.ImportReferences));
            }
        }
예제 #3
0
        public void SetNamespaces(object target)
        {
            var dev2ActivitiesAssembly = typeof(WorkflowHelper).Assembly;
            var dev2CommonAssembly     = typeof(GlobalConstants).Assembly;
            var dev2DataAssembly       = typeof(Dev2DataListDecisionHandler).Assembly;

            var namespaces = new Dictionary <string, Assembly>
            {
                { "Dev2.Common", dev2CommonAssembly },
                { "Dev2.Data.Decisions.Operations", dev2DataAssembly },
                { "Dev2.Data.SystemTemplates.Models", dev2DataAssembly },
                { "Dev2.DataList.Contract", dev2DataAssembly },
                { "Dev2.DataList.Contract.Binary_Objects", dev2DataAssembly },
                { "Unlimited.Applications.BusinessDesignStudio.Activities", dev2ActivitiesAssembly }
            };

            #region Set C# assembly references

            // http://stackoverflow.com/questions/16086612/wf-4-5-using-c-sharp-expressions-with-external-class-references
            // http://blogs.msdn.com/b/tilovell/archive/2012/05/25/wf4-5-using-csharpvalue-lt-t-gt-and-csharpreference-lt-t-gt-in-net-4-5-compiling-expressions-and-changes-in-visual-studio-generated-xaml.aspx

            TextExpression.SetReferencesForImplementation(target, namespaces.Values.Distinct().Select(a => new AssemblyReference {
                Assembly = a
            }).ToArray());

            var impl = new AttachableMemberIdentifier(typeof(TextExpression), "NamespacesForImplementation");

            AttachablePropertyServices.SetProperty(target, impl, namespaces.Keys.ToList());

            #endregion

            #region Set VB assembly references

            var vbSettings = VisualBasic.GetSettings(target) ?? new VisualBasicSettings();
            vbSettings.ImportReferences.Clear();

            foreach (var ns in namespaces.Keys)
            {
                vbSettings.ImportReferences.Add(new VisualBasicImportReference {
                    Assembly = namespaces[ns].GetName().Name, Import = ns
                });
            }

            VisualBasic.SetSettings(target, vbSettings);

            #endregion
        }
예제 #4
0
        static DynamicActivity GetDynamicActivity(ActivityBuilder activityDefinition)
        {
            DynamicActivity result = new DynamicActivity
            {
                Name = activityDefinition.Name
            };

            foreach (DynamicActivityProperty property in activityDefinition.Properties)
            {
                result.Properties.Add(property);
            }
            foreach (Attribute attrib in activityDefinition.Attributes)
            {
                result.Attributes.Add(attrib);
            }
            foreach (Constraint constraint in activityDefinition.Constraints)
            {
                result.Constraints.Add(constraint);
            }
            result.Implementation = () => activityDefinition.Implementation;

            VisualBasicSettings vbsettings = VisualBasic.GetSettings(activityDefinition);

            if (vbsettings != null)
            {
                VisualBasic.SetSettings(result, vbsettings);
            }

            IList <string> namespacesForImplementation = TextExpression.GetNamespacesForImplementation(activityDefinition);

            if (namespacesForImplementation.Count > 0)
            {
                TextExpression.SetNamespacesForImplementation(result, namespacesForImplementation);
            }

            IList <AssemblyReference> referencesForImplementation = TextExpression.GetReferencesForImplementation(activityDefinition);

            if (referencesForImplementation.Count > 0)
            {
                TextExpression.SetReferencesForImplementation(result, referencesForImplementation);
            }

            return(result);
        }
예제 #5
0
        private static DynamicActivity GetDynamicActivity(ActivityBuilder activityDefinition)
        {
            var result = new DynamicActivity
            {
                Name = activityDefinition.Name
            };

            foreach (var property in activityDefinition.Properties)
            {
                result.Properties.Add(property);
            }
            foreach (var attrib in activityDefinition.Attributes)
            {
                result.Attributes.Add(attrib);
            }
            foreach (var constraint in activityDefinition.Constraints)
            {
                result.Constraints.Add(constraint);
            }
            result.Implementation = () => activityDefinition.Implementation;

            var vbsettings = VisualBasic.GetSettings(activityDefinition);

            if (vbsettings != null)
            {
                VisualBasic.SetSettings(result, vbsettings);
            }

            var namespacesForImplementation = TextExpression.GetNamespacesForImplementation(activityDefinition);

            if (namespacesForImplementation.Count > 0)
            {
                TextExpression.SetNamespacesForImplementation(result, namespacesForImplementation);
            }

            var referencesForImplementation = TextExpression.GetReferencesForImplementation(activityDefinition);

            if (referencesForImplementation.Count > 0)
            {
                TextExpression.SetReferencesForImplementation(result, referencesForImplementation);
            }

            return(result);
        }
예제 #6
0
        /// <summary>
        /// Creates a DynamicActivityProperty for each argument and variable in the current context.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private Activity CreateDynamicActivity(AsyncCodeActivityContext context)
        {
            DynamicActivity result = new DynamicActivity();

            foreach (DynamicActivityProperty dap in
                     context.DataContext.GetProperties()
                     .Cast <PropertyDescriptor>()
                     .Select(property => new DynamicActivityProperty
            {
                Name = property.Name,
                Type = typeof(InArgument <>).MakeGenericType(property.PropertyType)
            }))
            {
                dap.Value = Activator.CreateInstance(dap.Type);
                result.Properties.Add(dap);
            }

            VisualBasic.SetSettings(result, VisualBasic.GetSettings(this));
            result.Implementation = () => Body.Handler;
            return(result);
        }
예제 #7
0
        public static ActivityBuilder ToBuilder(DynamicActivity dynamicActivity)
        {
            var activityBuilder = new ActivityBuilder
            {
                Implementation                       = dynamicActivity.Implementation != null?dynamicActivity.Implementation() : null,
                                                Name = dynamicActivity.Name
            };

            foreach (var item in dynamicActivity.Attributes)
            {
                activityBuilder.Attributes.Add(item);
            }

            foreach (var item in dynamicActivity.Constraints)
            {
                activityBuilder.Constraints.Add(item);
            }

            foreach (var item in dynamicActivity.Properties)
            {
                var property = new DynamicActivityProperty
                {
                    Name  = item.Name,
                    Type  = item.Type,
                    Value = null
                };

                foreach (var attribute in item.Attributes)
                {
                    property.Attributes.Add(attribute);
                }

                activityBuilder.Properties.Add(property);
            }

            VisualBasic.SetSettings(activityBuilder, VisualBasic.GetSettings(dynamicActivity));

            return(activityBuilder);
        }
        internal static void ConvertActivityBuilderToDynamicActivity(ActivityBuilder activityBuilder, DynamicActivity bodyPlaceholder)
        {
            bodyPlaceholder.Name           = activityBuilder.Name;
            bodyPlaceholder.Implementation = () => activityBuilder.Implementation;

            if (activityBuilder.Implementation != null)
            {
                VisualBasic.SetSettings(bodyPlaceholder, VisualBasic.GetSettings(activityBuilder));
            }

            bodyPlaceholder.Attributes.Clear();
            foreach (Attribute attribute in activityBuilder.Attributes)
            {
                bodyPlaceholder.Attributes.Add(attribute);
            }

            bodyPlaceholder.Properties.Clear();
            foreach (DynamicActivityProperty property in activityBuilder.Properties)
            {
                bodyPlaceholder.Properties.Add(property);
            }
        }
예제 #9
0
        static void OnRootPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            ModelItem rootModel = sender as ModelItem;

            Fx.Assert(rootModel != null, "sender item could not be null");
            ModelProperty changedProperty = rootModel.Properties[e.PropertyName];

            if (changedProperty == null)
            {
                return;
            }

            object changedPropertyValue = changedProperty.ComputedValue;

            if (changedPropertyValue == null)
            {
                return;
            }

            Fx.Assert(rootModel.GetCurrentValue().GetType() == WorkflowServiceType, "This handler should only be attached when the root is WorkflowService");
            IDebuggableWorkflowTree root = rootModel.GetCurrentValue() as IDebuggableWorkflowTree;
            Activity rootActivity        = root.GetWorkflowRoot();

            if (rootActivity == changedPropertyValue)
            {
                if (WorkflowDesigner.GetTargetFramework(rootModel.GetEditingContext()).IsLessThan45())
                {
                    VisualBasicSettings settings = VisualBasic.GetSettings(root);
                    NamespaceHelper.SetVisualBasicSettings(changedPropertyValue, settings);
                }
                else
                {
                    IList <AssemblyReference> referencedAssemblies;
                    IList <string>            namespaces = NamespaceHelper.GetTextExpressionNamespaces(root, out referencedAssemblies);
                    NamespaceHelper.SetTextExpressionNamespaces(rootActivity, namespaces, referencedAssemblies);
                }
            }
        }
예제 #10
0
        private void AddDynamicAssembly(Assembly asm)
        {
            AssemblyContextControlItem acci = (AssemblyContextControlItem)(_WorkflowDesigner.Context.Items.GetValue(typeof(AssemblyContextControlItem)));
            var root     = GetRootElement();
            var fullname = asm.FullName;

            if (null == root)
            {
                return;
            }
            VisualBasicSettings vbs = VisualBasic.GetSettings(root) ?? new VisualBasicSettings();

            var namespaces = (from type in asm.GetTypes() select type.Namespace).Distinct();

            foreach (var name in namespaces)
            {
                var import = new VisualBasicImportReference()
                {
                    Assembly = fullname, Import = name
                };
                vbs.ImportReferences.Add(import);
            }
            VisualBasic.SetSettings(root, vbs);
        }