public bool ClickOnNodeAction(Diagram.Diagram diagram, DiagramView diagramview, Node node)
        {
            if (diagram.FileName != "" && this.IsUid(node.link))
            {
                string uid = this.GetUid(node.link);
                if (Os.FileExists(diagram.FileName))
                {
                    string diagramDirectory = Os.GetFileDirectory(diagram.FileName);

                    List <FileNameAndSizePair> files = new List <FileNameAndSizePair>();

                    foreach (string file in Directory.EnumerateFiles(diagramDirectory, "*.*", SearchOption.AllDirectories))
                    {
                        FileNameAndSizePair pair = new FileNameAndSizePair();
                        pair.name = file;
                        pair.size = new System.IO.FileInfo(file).Length;
                        files.Add(pair);
                    }

                    files.Sort(delegate(FileNameAndSizePair p1, FileNameAndSizePair p2) {
                        return(p1.size <p2.size ? -1 : p1.size> p2.size ? 1 : 0);
                    });

                    foreach (FileNameAndSizePair file in files)
                    {
                        try
                        {
                            // skip self
                            if (file.name == diagram.FileName)
                            {
                                continue;
                            }

                            long pos = 1;
                            foreach (string line in File.ReadAllLines(file.name))
                            {
                                if (line.Contains(uid))
                                {
                                    this.OpenFileOnPosition(file.name, pos);
                                    return(true);
                                }
                                pos++;
                            }
                        }
                        catch (Exception ex)
                        {
                            Program.log.Write("FindUidPlugin: " + ex.Message);
                        }
                    }
                }
            }

            return(false);
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="script">Script with python code</param>
        /// <example>
        /// import clr
        /// clr.AddReference('Diagram')
        /// from Diagram import Position
        /// DiagramView.CreateNode(Position(0,0))
        /// </example>
        /// <example>
        /// Tools.log("test")
        /// Tools.ShowMessage("test")
        /// Tools.setClipboard("test")
        /// clp = Tools.getClipboard()
        /// <returns>Return script string result</returns>
        public string RunScript(String script)
        {
            if (pyEngine == null)
            {
                pyEngine = Python.CreateEngine();
                var paths = pyEngine.GetSearchPaths();
                if (Os.FileExists(this.StandardLibraryPath))
                {
                    paths.Add(this.StandardLibraryPath);
                }
                pyEngine.SetSearchPaths(paths);
                pyScope = pyEngine.CreateScope();

                /// add items to scope
                pyScope.Diagram     = this.diagram;
                pyScope.Tools       = this.tools;
                pyScope.F           = this.tools;
                pyScope.DiagramView = this.diagramView;
            }

            string output = null;

            try
            {
                /// set streams
                MemoryStream ms       = new MemoryStream();
                StreamWriter outputWr = new StreamWriter(ms);
                pyEngine.Runtime.IO.SetOutput(ms, outputWr);
                pyEngine.Runtime.IO.SetErrorOutput(ms, outputWr);

                /// execute script
                this.CompileSourceAndExecute(script);

                /// read script output
                ms.Position = 0;
                StreamReader sr = new StreamReader(ms);
                output = sr.ReadToEnd();

                Program.log.Write("Script: output:\n" + output);
            }
            catch (Exception ex)
            {
                Program.log.Write("Script: error: " + ex.ToString());
            }

            return(output);
        }
示例#3
0
        public string getStandardLibraryPath()
        {
            string standardLibraryPath = "";
            
            if (Os.FileExists(this.location))
            {
                string pluginDirectory = Os.GetDirectoryName(this.location);
                standardLibraryPath = Os.Combine(pluginDirectory, "IronPython.zip");

                if (!Os.FileExists(standardLibraryPath))
                {
                    Program.log.Write("ScriptPlugim: standard python librar IronPython.zip not exist");
                    return null;
                }

            }

            return standardLibraryPath;
        }
示例#4
0
        public void CreateDirectoryItem_Click(object sender, EventArgs e, Diagram.DiagramView diagramview)
        {
            string DiagramPath = diagramview.diagram.FileName.Trim();

            if (DiagramPath == "" && !Os.FileExists(DiagramPath))
            {
                return;
            }

            string NewDirectoryPath = Os.Combine(Os.GetFileDirectory(DiagramPath), "test");

            Os.CreateDirectory(NewDirectoryPath);

            Node newrec = diagramview.CreateNode(diagramview.actualMousePos.Clone());

            newrec.SetName("test");
            newrec.link = NewDirectoryPath;
            diagramview.diagram.Unsave("create", newrec, diagramview.shift, diagramview.currentLayer.id);
        }