Example #1
0
 public void InitializeSnippets()
 {
     if (toolbox.Categories.Count > 0)
     {
         return;
     }
     try
     {
         if (dag == null)
         {
             dag = new DynamicActivityGenerator("Snippets", Interfaces.Extensions.ProjectsDirectory);
         }
         var cs = new Dictionary <string, ToolboxCategory>();
         foreach (var s in Plugins.Snippets)
         {
             try
             {
                 if (!cs.ContainsKey(s.Category))
                 {
                     cs.Add(s.Category, new ToolboxCategory(s.Category));
                 }
                 ToolboxCategory cat = cs[s.Category];
                 var             t   = dag.AppendSubWorkflowTemplate(s.Name, s.Xaml);
                 cat.Add(new ToolboxItemWrapper(t, s.Name));
             }
             catch (Exception ex)
             {
                 Log.Error(ex.ToString());
             }
         }
         try
         {
             dag.Save();
         }
         catch (Exception ex)
         {
             Log.Error(ex.ToString());
         }
         if (cs == null || cs.Count == 0)
         {
             Console.WriteLine("No snippets!");
         }
         foreach (var c in cs)
         {
             try
             {
                 toolbox.Categories.Add(c.Value);
             }
             catch (Exception ex)
             {
                 Log.Error(ex.ToString());
             }
         }
     }
     catch (Exception ex)
     {
         Log.Error(ex, "");
         MessageBox.Show("InitializeSnippets: " + ex.Message);
     }
 }
Example #2
0
        public ToolboxControl InitializeSnippets()
        {
            try
            {
                var Toolbox = new ToolboxControl();
                var cs      = new Dictionary <string, ToolboxCategory>();
                foreach (var s in Plugins.Snippets)
                {
                    try
                    {
                        if (!cs.ContainsKey(s.Category))
                        {
                            cs.Add(s.Category, new ToolboxCategory(s.Category));
                        }
                        ToolboxCategory cat = cs[s.Category];
                        var             t   = dag.AppendSubWorkflowTemplate(s.Name, s.Xaml);
                        cat.Add(new ToolboxItemWrapper(t, s.Name));
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex.ToString());
                    }
                }
                try
                {
                    dag.Save();
                }
                catch (Exception)
                {
                }
                foreach (var c in cs)
                {
                    try
                    {
                        Toolbox.Categories.Add(c.Value);
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex.ToString());
                    }
                }

                return(Toolbox);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "");
                MessageBox.Show("InitializeSnippets: " + ex.Message);
                return(null);
            }
        }
Example #3
0
        public override void StartDrag(IDragInfo dragInfo)
        {
            var item = dragInfo.SourceItem as ProjectTreeItem;

            //让xaml文件支持拖拽生成执行工作流文件的组件
            if (item.IsXaml && ViewModelLocator.Instance.Dock.ActiveDocument != null)
            {
                var designer = ViewModelLocator.Instance.Dock.ActiveDocument.WorkflowDesignerInstance;

                var type = Type.GetType("RPA.Core.Activities.Workflow.InvokeWorkflowFileActivity,RPA.Core.Activities");

                dynamic dragActivity = Activator.CreateInstance(type);
                dragActivity.SetWorkflowFilePath(item.Path);


                //通过类型获取对应的显示名并进行设置

                var activity_item = ViewModelLocator.Instance.Activities.GetActivityTreeItemByType(type);
                if (activity_item != null)
                {
                    dragActivity.DisplayName = activity_item.Name;
                }

                Activity resultActivity = dragActivity;
                if (Common.IsWorkflowDesignerEmpty(designer))
                {
                    resultActivity = Common.ProcessAutoSurroundWithSequence(dragActivity);
                }

                if (resultActivity != null)
                {
                    //动态生成组件,以便解决拖动到flowchart报错的问题
                    var dag = new DynamicActivityGenerator("_DynamicActivityGenerator_" + System.Guid.NewGuid().ToString());
                    var t   = dag.AppendSubWorkflowTemplate(System.Guid.NewGuid().ToString(), Common.ToXaml(resultActivity));
                    try
                    {
                        dag.Save();
                    }
                    catch (Exception)
                    {
                    }

                    DataObject data = new DataObject(System.Activities.Presentation.DragDropHelper.WorkflowItemTypeNameFormat, t.AssemblyQualifiedName);

                    dragInfo.DataObject = data;
                }
            }

            //让Python文件支持拖拽生成执行Python脚本文件组件的功能
            if (item.IsPython && ViewModelLocator.Instance.Dock.ActiveDocument != null)
            {
                var designer = ViewModelLocator.Instance.Dock.ActiveDocument.WorkflowDesignerInstance;

                var type = Type.GetType("RPA.Script.Activities.Python.InvokePythonFileActivity,RPA.Script.Activities");

                dynamic dragActivity = Activator.CreateInstance(type);

                if (item.Path.StartsWith(SharedObject.Instance.ProjectPath, System.StringComparison.CurrentCultureIgnoreCase))
                {
                    //如果在项目目录下,则使用相对路径保存
                    dragActivity.PythonFilePath = Common.MakeRelativePath(SharedObject.Instance.ProjectPath, item.Path);
                }

                //通过类型获取对应的显示名并进行设置

                var activity_item = ViewModelLocator.Instance.Activities.GetActivityTreeItemByType(type);
                if (activity_item != null)
                {
                    dragActivity.DisplayName = activity_item.Name;
                }

                Activity resultActivity = dragActivity;
                if (Common.IsWorkflowDesignerEmpty(designer))
                {
                    resultActivity = Common.ProcessAutoSurroundWithSequence(dragActivity);
                }

                if (resultActivity != null)
                {
                    //动态生成组件,以便解决拖动到flowchart报错的问题
                    var dag = new DynamicActivityGenerator("_DynamicActivityGenerator_" + System.Guid.NewGuid().ToString());
                    var t   = dag.AppendSubWorkflowTemplate(System.Guid.NewGuid().ToString(), Common.ToXaml(resultActivity));
                    try
                    {
                        dag.Save();
                    }
                    catch (Exception)
                    {
                    }

                    DataObject data = new DataObject(System.Activities.Presentation.DragDropHelper.WorkflowItemTypeNameFormat, t.AssemblyQualifiedName);

                    dragInfo.DataObject = data;
                }
            }


            //只允许文件夹或文件拖动
            if (!item.IsDirectory && !item.IsFile)
            {
                return;
            }

            base.StartDrag(dragInfo);
        }