Example #1
0
        public static ModelItem CreateModelItem(object parent, object objectToMakeModelItem)
        {
            EditingContext   ec  = new EditingContext();
            ModelTreeManager mtm = new ModelTreeManager(ec);

            return(mtm.CreateModelItem(CreateModelItem(parent), objectToMakeModelItem));
        }
        private void GenerateExpression()
        {
            //TODO: Enhance the type infering logic
            if (ExpressionType == null)
            {
                // Get the variables in scope
                List <ModelItem> declaredVariables = CSharpExpressionHelper.GetVariablesInScope(OwnerActivity);

                if (declaredVariables.Count > 0)
                {
                    InferredType = ((LocationReference)declaredVariables[0].GetCurrentValue()).Type;
                }
            }

            Type resultType = ExpressionType != null ? ExpressionType : InferredType;

            ////This could happen when:
            ////1) No ExpressionType is specified and
            ////2) The expression is invalid so that the inferred type equals to null
            if (resultType == null)
            {
                resultType = typeof(object);
            }

            // If the text is null we don't need to bother generating the expression (this would be the case the
            // first time you enter an ETB. We still need to generate the expression when it is EMPTY however - otherwise
            // the case where you had an expression (valid or invalid), then deleted the whole thing will not be evaluated.
            if (Text != null)
            {
                using (ModelEditingScope scope = OwnerActivity.BeginEdit("Property Change"))
                    if (OwnerActivity != null)
                    {
                        EditingState = EditingState.Validating;
                        // we set the expression to null
                        // a) when the expressionText is empty AND it's a reference expression or
                        // b) when the expressionText is empty AND the DefaultValue property is null
                        if (Text.Length == 0 &&
                            (UseLocationExpression || DefaultValue == null))
                        {
                            Expression = null;
                        }
                        else
                        {
                            if (Text.Length == 0)
                            {
                                Text = DefaultValue;
                            }

                            ModelTreeManager   modelTreeManager = Context.Services.GetService <ModelTreeManager>();
                            ActivityWithResult newExpression    = CSharpExpressionHelper.CreateExpressionFromString(Text, UseLocationExpression, resultType);
                            ModelItem          expressionItem   = modelTreeManager.CreateModelItem(null, newExpression);

                            Expression = expressionItem;
                        }
                        scope.Complete();
                    }
            }
        }
        //public void placeholder()
        //{
        //    ModelItem modelItem = this.ModelItem.Properties["Arguments"].Dictionary;
        //    using (ModelEditingScope change = modelItem.BeginEdit("ArgumentsEditing"))
        //    {
        //        if (DynamicArgumentDialog.ShowDialog(this.ModelItem, modelItem, Context, this.ModelItem.View, options))
        //        {
        //            change.Complete();
        //        }
        //        else
        //        {
        //            change.Revert();
        //        }
        //    }
        //}
        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (this.ModelItem.GetCurrentValue() is NestedActivity)
            {
                //string s = @"Test.xaml";
                //if (File.Exists(s))
                //{
                //    File.Delete(s);
                //}
                Activity workflow1 = ActivityXamlServices.Load(ActivityXamlServices.CreateReader(new XamlXmlReader(txtActivityFullName.Text, new XamlXmlReaderSettings {
                    LocalAssembly = System.Reflection.Assembly.GetExecutingAssembly()
                })));

                NestedActivity owa = (NestedActivity)this.ModelItem.GetCurrentValue();
                owa.NestedActivityCreated = workflow1;
                owa.ActivityPath          = txtActivityFullName.Text;
                // SelectHelper._wfDesigner.Save(s);

                //SelectHelper._wfDesigner = new WorkflowDesigner();
                //SelectHelper._wfDesigner.Context.Services.GetService<DesignerConfigurationService>().TargetFrameworkName = new System.Runtime.Versioning.FrameworkName(".NETFramework", new Version(4, 5));
                //SelectHelper._wfDesigner.Context.Services.GetService<DesignerConfigurationService>().LoadingFromUntrustedSourceEnabled = true;

                ////associates all of the basic activities with their designers
                //new DesignerMetadata().Register();

                //SelectHelper._wfDesigner.Load(s);

                //SelectHelper._wfDesigner.View.UpdateLayout();
                //System.Windows.Controls.Border WfDesignerBorder = (System.Windows.Controls.Border)SelectHelper.Border;
                //WfDesignerBorder.Child = SelectHelper._wfDesigner.View;
                //SelectHelper._wfPropertyBorder.Child = SelectHelper._wfDesigner.PropertyInspectorView;

                EditingContext   ed        = this.Context; // SelectHelper._wfDesigner.Context;
                ModelTreeManager mtm       = new ModelTreeManager(ed);
                ModelItem        modelItem = mtm.CreateModelItem(null, owa.NestedActivityCreated);
                //modelItem.Properties["Activities"].Collection.Add(activity);
                //modelItem.ac
                this.ModelItem = modelItem;
            }
        }
Example #4
0
 protected override ModelItem CreateItem(object instance)
 {
     return(modelTreeManager.CreateModelItem(null, instance));
 }