コード例 #1
0
        // This supports loading objects instead of xaml into the designer
        public void Load(object instance)
        {
            if (isLoaded)
            {
                throw FxTrace.Exception.AsError(new InvalidOperationException(SR.WorkflowDesignerLoadShouldBeCalledOnlyOnce));
            }

            isLoaded = true;

            if (instance == null)
            {
                throw FxTrace.Exception.AsError(new ArgumentNullException("instance"));
            }

            DesignerConfigurationService configurationService = this.context.Services.GetService <DesignerConfigurationService>();

            configurationService.ApplyDefaultPreference();

            // Because we want AutoConnect/AutoSplit to be on even in Dev10 if PU1 is installed.
            // But we cannot know whether PU1 is installed or not, we decide to enable these 2 features for all Dev10.
            if (configurationService.WorkflowDesignerHostId == WorkflowDesignerHostId.Dev10)
            {
                configurationService.AutoConnectEnabled = true;
                configurationService.AutoSplitEnabled   = true;
            }

            configurationService.IsWorkflowLoaded = true;
            configurationService.Validate();

            if (this.PreviewLoad != null)
            {
                this.PreviewLoad(this, new PreviewLoadEventArgs(instance, this.context));
            }

            if (configurationService.TargetFrameworkName.IsLessThan45())
            {
                TargetFrameworkPropertyFilter.FilterOut45Properties();
            }

            modelTreeManager = new ModelTreeManager(this.context);
            modelTreeManager.Load(instance);
            this.context.Services.Publish(typeof(ModelTreeManager), modelTreeManager);
            viewManager = GetViewManager(this.modelTreeManager.Root);
            this.context.Services.Publish <ModelSearchService>(this.ModelSearchService);
            view.Children.Add((UIElement)viewManager.View);

            modelTreeManager.EditingScopeCompleted += new EventHandler <EditingScopeEventArgs>(OnEditingScopeCompleted);

            this.view.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle,
                                             new Action(() => { this.perfEventProvider.WorkflowDesignerApplicationIdleAfterLoad(); }));

            //Subscribe to the ViewStateChanged event of ViewStateService to show document dirty. It would be published in the call to GetViewManager().
            WorkflowViewStateService wfViewStateService = this.Context.Services.GetService(typeof(ViewStateService)) as WorkflowViewStateService;

            if (wfViewStateService != null)
            {
                wfViewStateService.UndoableViewStateChanged += new ViewStateChangedEventHandler(OnViewStateChanged);
            }
            this.isModelChanged = false;
        }
コード例 #2
0
        public MainWindow()
        {
            InitializeComponent();
            EditingContext = new System.Activities.Presentation.EditingContext();

            _mtm = new ModelTreeManager(EditingContext);
            EditingContext.Services.Publish(_mtm);

            // we can add undo/redo
            _undo = new UndoEngine(EditingContext);
            EditingContext.Services.Publish(_undo);
            _undo.UndoRedoBufferChanged += _undo_UndoRedoBufferChanged;

            // add whatever services
            EditingContext.Services.Publish(new MessageBoxService());

            var root = new ObjectRoot();

            root.Text = "This is the root";
            root.Leaves.Add(new ObjectLeaf {
                Text = "this is leaf one"
            });
            _mtm.Load(root);

            ModelItemRoot = _mtm.Root;

            // the hard way
            var mi = ModelItemRoot.Properties["Leaves"].Collection.Add(new ObjectLeaf {
                Text = "this is leaf two"
            });

            mi.PropertyChanged += mi_PropertyChanged;
        }
コード例 #3
0
        private void ImportArgumentsBtn_Click(object sender, RoutedEventArgs e)
        {
            var workflowFilePathArg = ModelItem.Properties["WorkflowFilePath"].ComputedValue as InArgument <string>;

            var workflowFilePath = "";

            if (workflowFilePathArg != null)
            {
                //TODO WJF 此处该转换不确定是否正确,准确用法需要Get(Context)这种用法
                workflowFilePath = GetInArgumentStringValue(workflowFilePathArg);

                //转成绝对路径
                //如果workflowFilePath不是绝对路径,则转成绝对路径
                if (!System.IO.Path.IsPathRooted(workflowFilePath))
                {
                    workflowFilePath = System.IO.Path.Combine(SharedObject.Instance.ProjectPath, workflowFilePath);
                }
            }

            Dictionary <string, Argument> argDict = new Dictionary <string, Argument>();

            if (!string.IsNullOrEmpty(workflowFilePath))
            {
                var activity = ActivityXamlServices.Load(workflowFilePath) as DynamicActivity;
                foreach (var prop in activity.Properties)
                {
                    if (!argDict.ContainsKey(prop.Name))
                    {
                        if (prop.Value == null)
                        {
                            argDict.Add(prop.Name, (Argument)Activator.CreateInstance(prop.Type));
                        }
                        else
                        {
                            argDict.Add(prop.Name, (Argument)prop.Value);
                        }
                    }
                }
            }

            var options = new DynamicArgumentDesignerOptions()
            {
                Title = "导入工作流参数"
            };

            ModelTreeManager mtm = new ModelTreeManager(new EditingContext());

            mtm.Load(argDict);

            if (DynamicArgumentDialog.ShowDialog(this.ModelItem, mtm.Root, Context, this.ModelItem.View, options))
            {
                var saveArgDict = this.ModelItem.Properties["Arguments"].Dictionary;
                saveArgDict.Clear();
                foreach (var item in argDict)
                {
                    saveArgDict.Add(item.Key, item.Value);
                }
            }
        }
コード例 #4
0
ファイル: TestModelItemUtil.cs プロジェクト: Robin--/Warewolf
        public static ModelItem CreateModelItem(object objectToMakeModelItem)
        {
            EditingContext ec = new EditingContext();
            ModelTreeManager mtm = new ModelTreeManager(ec);

            mtm.Load(objectToMakeModelItem);

            return mtm.Root;
        }
コード例 #5
0
        public static ModelItem CreateModelItem(object objectToMakeModelItem)
        {
            EditingContext   ec  = new EditingContext();
            ModelTreeManager mtm = new ModelTreeManager(ec);

            mtm.Load(objectToMakeModelItem);

            return(mtm.Root);
        }
コード例 #6
0
        public static ModelItemCollection CreateModelItemCollection(ICollection objectToMakeModelItem)
        {
            EditingContext   ec  = new EditingContext();
            ModelTreeManager mtm = new ModelTreeManager(ec);

            mtm.Load(objectToMakeModelItem);

            return(mtm.Root as ModelItemCollection);
        }
コード例 #7
0
ファイル: WpfPropertyGrid.cs プロジェクト: wwwK/EntityDB
        /// <summary>
        /// Updates the PropertyGrid's properties
        /// </summary>
        public void RefreshPropertyList()
        {
            var context = new EditingContext();
            var mtm     = new ModelTreeManager(context);

            mtm.Load(this.SelectedObject);
            var selection = Selection.Select(context, mtm.Root);

            OnSelectionChangedMethod.Invoke(Designer.PropertyInspectorView, new object[] { selection });

            // var olditem = this.SelectedObject;
            // this.SelectedObject = null;
            // this.SelectedObject = olditem;
            //RefreshMethod.Invoke(Designer.PropertyInspectorView, new object[] { false });
        }
コード例 #8
0
        private static void SelectedObjectsPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
        {
            WpfPropertyGrid pg = source as WpfPropertyGrid;

            pg.CoerceValue(SelectedObjectsProperty);

            object[] collection = e.NewValue as object[];

            if (collection.Length == 0)
            {
                pg.OnSelectionChangedMethod.Invoke(pg.Designer.PropertyInspectorView, new object[] { null });
                pg.SelectionTypeLabel.Text = string.Empty;
            }
            else
            {
                bool same  = true;
                Type first = null;

                var       context   = new EditingContext();
                var       mtm       = new ModelTreeManager(context);
                Selection selection = null;

                // Accumulates the selection and determines the type to be shown in the top of the PG
                for (int i = 0; i < collection.Length; i++)
                {
                    mtm.Load(collection[i]);
                    if (i == 0)
                    {
                        selection = Selection.Select(context, mtm.Root);
                        first     = collection[0].GetType();
                    }
                    else
                    {
                        selection = Selection.Union(context, mtm.Root);
                        if (!collection[i].GetType().Equals(first))
                        {
                            same = false;
                        }
                    }
                }

                pg.OnSelectionChangedMethod.Invoke(pg.Designer.PropertyInspectorView, new object[] { selection });
                pg.SelectionTypeLabel.Text = same ? first.Name + " <multiple>" : "Object <multiple>";
            }

            pg.ChangeHelpText(string.Empty, string.Empty);
        }
コード例 #9
0
        private static void SelectedObjectPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
        {
            WpfPropertyGrid pg = source as WpfPropertyGrid;
            pg.CoerceValue(SelectedObjectsProperty);

            if (e.NewValue == null)
            {
                pg.OnSelectionChangedMethod.Invoke(pg.Designer.PropertyInspectorView, new object[] { null });
                pg.SelectionTypeLabel.Text = string.Empty;
            }
            else
            {
                var context = new EditingContext();
                var mtm = new ModelTreeManager(context);
                mtm.Load(e.NewValue);
                Selection selection = Selection.Select(context, mtm.Root);

                pg.OnSelectionChangedMethod.Invoke(pg.Designer.PropertyInspectorView, new object[] { selection });
                pg.SelectionTypeLabel.Text = e.NewValue.GetType().Name;
            }

            pg.ChangeHelpText(string.Empty, string.Empty);
        }
コード例 #10
0
        private static void SelectedObjectPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
        {
            WpfPropertyGrid pg = source as WpfPropertyGrid;

            pg.CoerceValue(SelectedObjectsProperty);

            if (e.NewValue == null)
            {
                pg.OnSelectionChangedMethod.Invoke(pg.Designer.PropertyInspectorView, new object[] { null });
            }
            else
            {
                var context = new EditingContext();
                var mtm     = new ModelTreeManager(context);
                mtm.Load(e.NewValue);
                Selection selection = Selection.Select(context, mtm.Root);

                pg.OnSelectionChangedMethod.Invoke(pg.Designer.PropertyInspectorView, new object[] { selection });
                ((AdoDotNetConnectionProperties)pg.SelectedObject).PropertyValueChanged += WpfPropertyGrid_PropertyValueChanged;
                ((AdoDotNetConnectionProperties)pg.SelectedObject).ErrorValidating      += WpfPropertyGrid_ErrorValidating;
            }

            pg.ChangeHelpText(((AdoDotNetConnectionProperties)e.NewValue).ToDisplayString());
        }
コード例 #11
0
        private static void SelectedObjectsPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
        {
            WpfPropertyGrid pg = source as WpfPropertyGrid;
            pg.CoerceValue(SelectedObjectsProperty);

            object[] collection = e.NewValue as object[];

            if (collection.Length == 0)
            {
                pg.OnSelectionChangedMethod.Invoke(pg.Designer.PropertyInspectorView, new object[] { null });
                pg.SelectionTypeLabel.Text = string.Empty;
            }
            else
            {
                bool same = true;
                Type first = null;

                var context = new EditingContext();
                var mtm = new ModelTreeManager(context);
                Selection selection = null;

                // Accumulates the selection and determines the type to be shown in the top of the PG
                for (int i = 0; i < collection.Length; i++)
                {
                    mtm.Load(collection[i]);
                    if (i == 0)
                    {
                        selection = Selection.Select(context, mtm.Root);
                        first = collection[0].GetType();
                    }
                    else
                    {
                        selection = Selection.Union(context, mtm.Root);
                        if (!collection[i].GetType().Equals(first))
                            same = false;
                    }
                }

                pg.OnSelectionChangedMethod.Invoke(pg.Designer.PropertyInspectorView, new object[] { selection });
                pg.SelectionTypeLabel.Text = same ? first.Name + " <multiple>" : "Object <multiple>";
            }

            pg.ChangeHelpText(string.Empty, string.Empty);
        }
コード例 #12
0
        private static void SelectedObjectPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
        {
            WpfPropertyGrid pg = source as WpfPropertyGrid;
            pg.CoerceValue(SelectedObjectsProperty);

            if (e.NewValue == null)
            {
                pg.OnSelectionChangedMethod.Invoke(pg.Designer.PropertyInspectorView, new object[] { null });
                pg.SelectionTypeLabel.Text = string.Empty;
            }
            else
            {
                var context = new EditingContext();
                var mtm = new ModelTreeManager(context);
                mtm.Load(e.NewValue);
                Selection selection = Selection.Select(context, mtm.Root);

                pg.OnSelectionChangedMethod.Invoke(pg.Designer.PropertyInspectorView, new object[] { selection });
                pg.SelectionTypeLabel.Text = e.NewValue.GetType().Name;
            }

            pg.ChangeHelpText(string.Empty, string.Empty);
        }
コード例 #13
0
        // This supports loading objects instead of xaml into the designer 
        public void Load(object instance)
        {
            if (isLoaded)
            {
                throw FxTrace.Exception.AsError(new InvalidOperationException(SR.WorkflowDesignerLoadShouldBeCalledOnlyOnce));
            }

            isLoaded = true;

            if (instance == null)
            {
                throw FxTrace.Exception.AsError(new ArgumentNullException("instance"));
            }

            DesignerConfigurationService configurationService = this.context.Services.GetService<DesignerConfigurationService>();
            configurationService.ApplyDefaultPreference();

            // Because we want AutoConnect/AutoSplit to be on even in Dev10 if PU1 is installed.
            // But we cannot know whether PU1 is installed or not, we decide to enable these 2 features for all Dev10.
            if (configurationService.WorkflowDesignerHostId == WorkflowDesignerHostId.Dev10)
            {
                configurationService.AutoConnectEnabled = true;
                configurationService.AutoSplitEnabled = true;
            }

            configurationService.IsWorkflowLoaded = true;
            configurationService.Validate();

            if (this.PreviewLoad != null)
            {
                this.PreviewLoad(this, new PreviewLoadEventArgs(instance, this.context));
            }

            if (configurationService.TargetFrameworkName.IsLessThan45())
            {
                TargetFrameworkPropertyFilter.FilterOut45Properties();
            }

            modelTreeManager = new ModelTreeManager(this.context);
            modelTreeManager.Load(instance);
            this.context.Services.Publish(typeof(ModelTreeManager), modelTreeManager);
            viewManager = GetViewManager(this.modelTreeManager.Root);
            this.context.Services.Publish<ModelSearchService>(this.ModelSearchService);
            view.Children.Add((UIElement)viewManager.View);

            modelTreeManager.EditingScopeCompleted += new EventHandler<EditingScopeEventArgs>(OnEditingScopeCompleted);

            this.view.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle,
                             new Action(() => { this.perfEventProvider.WorkflowDesignerApplicationIdleAfterLoad(); }));

            //Subscribe to the ViewStateChanged event of ViewStateService to show document dirty. It would be published in the call to GetViewManager().
            WorkflowViewStateService wfViewStateService = this.Context.Services.GetService(typeof(ViewStateService)) as WorkflowViewStateService;
            if (wfViewStateService != null)
            {
                wfViewStateService.UndoableViewStateChanged += new ViewStateChangedEventHandler(OnViewStateChanged);
            }
            this.isModelChanged = false;
        }