/// <summary>
        /// Writes settings to mer file.
        /// </summary>
        private void WriteToConfigFile()
        {
            try
            {
                IniParser writer = new IniParser(this.merFilePath());

                writer.AddSetting("programPath", this.ProgramPath);
                writer.AddSetting("workingDir", this.WorkingDir);
                writer.AddSetting("database", this.Database);
                writer.AddSetting("username", this.Username);
                writer.AddSetting("password", this.Password);
                string projects = "";
                foreach (string s in this.Projects)
                {
                    projects += ";" + s;
                }
                // Delete the first character which is the delimiter (';')
                projects = projects.Substring(1, projects.Length - 1);
                writer.AddSetting("projects", projects);
                writer.AddSetting("hostname", this.Host);
                writer.AddSetting("port", this.Port.ToString());
                writer.AddSetting("logging", this.Logging.ToString());
                writer.SaveSettings();

                this.Version = this.ParseVersion(this.ProgramPath);
            }
            catch (Exception ex)
            {
                DialogProvider.ShowMessageDialog("Error writing .mer file. " + ex.Message, "Error writing .mer file");
            }
        }
Beispiel #2
0
        ///<summary>
        /// Initializes the graph view by getting the graphs from MetaEdit.
        ///</summary>
        ///<returns>Array of graphs.</returns>
        public static Graph [] Init()
        {
            MetaEditAPI.MetaEditAPI port = Launcher.Port;
            METype graphType             = new MetaEditAPI.METype();

            graphType.name = "Graph";
            List <Graph> graphs         = new List <Graph>();
            List <Graph> topLevelGraphs = new List <Graph>();

            MetaEditAPI.MEOop[] meOops = new MetaEditAPI.MEOop[0];
            if (!Launcher.IsApiOK())
            {
                return(topLevelGraphs.ToArray());
            }
            try {
                meOops = port.allSimilarInstances(graphType);
            } catch (Exception e) {
                DialogProvider.ShowMessageDialog("API error: " + e.Message, "API error");
            }
            foreach (MEOop m in meOops)
            {
                Graph g = Graph.MEOopToGraph(m);
                graphs.Add(g);
            }
            List <Graph> done = new List <Graph>();

            foreach (Graph g in graphs)
            {
                g.InitChildren(port, done);
            }
            foreach (Graph g in graphs)
            {
                if (!g.getIsChild())
                {
                    topLevelGraphs.Add(g);
                }
            }
            List <Graph> reachableGraphsList = ReachableGraphs(topLevelGraphs);

            graphs.Sort(delegate(Graph g1, Graph g2) { return(g1.Name.CompareTo(g2.Name)); });

            foreach (Graph g in graphs)
            {
                if (!reachableGraphsList.Contains(g))
                {
                    topLevelGraphs.Add(g);
                    BuildReachableGraphs(g, reachableGraphsList);
                }
            }
            return(topLevelGraphs.ToArray());
        }
Beispiel #3
0
 /// <summary>
 /// Run "Generate" action for the selected graph. Shows window containen all the possible generators.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ButtonGenerate_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         GraphViewModel gvm = (GraphViewModel)treeView1.SelectedItem;
         if (gvm == null)
         {
             return;
         }
         Settings s = Settings.GetSettings();
         if (s.Version.IsEqualOrGreaterThan("5.0"))
         {
             string[]      _generators   = Launcher.Port.generatorNames(gvm.getGraph().GetMEType()).Split(new Char[] { '\r' });
             List <string> generatorList = new List <string>();
             foreach (string _generator in _generators)
             {
                 if (!_generator.StartsWith("_") && !_generator.StartsWith("!"))
                 {
                     generatorList.Add(_generator);
                 }
             }
             SelectionWindow sw = new SelectionWindow(generatorList, "Select the generator to run", false, false);
             sw.Height = 300;
             sw.WindowStartupLocation = WindowStartupLocation.CenterScreen;
             sw.ShowDialog();
             string generator = "";
             if (sw.SelectedItems.Count > 0)
             {
                 generator = sw.SelectedItems[0];
                 if (generator.Length > 0)
                 {
                     gvm.getGraph().ExecuteGenerator(generator);
                 }
             }
         }
         else
         {
             gvm.getGraph().ExecuteGenerator("Autobuild");
         }
     }
     catch (Exception err)
     {
         DialogProvider.ShowMessageDialog("API error: " + err.Message, "API error");
         this.correctErrorSituation();
     }
 }
Beispiel #4
0
 /// <summary>
 /// Action for the "Run Autobuild" button. Runs Autobuild for the selected graph.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ButtonRunAutobuild_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         GraphViewModel gvm = (GraphViewModel)treeView1.SelectedItem;
         if (gvm == null)
         {
             return;
         }
         gvm.getGraph().ExecuteGenerator("Autobuild");
     }
     catch (Exception err)
     {
         DialogProvider.ShowMessageDialog("API error: " + err.Message, "API error");
         this.correctErrorSituation();
     }
 }
Beispiel #5
0
        /// <summary>
        /// Launches MetaEdit+, or uses available API connection if found.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonStartMetaEdit_Click(object sender, RoutedEventArgs e)
        {
            bool runUpdate = true;

            if (IsAPI())
            {
                DialogProvider.ShowMessageDialog("Found an existing API connection.", "API connection found.");
                runUpdate = true;
            }
            else
            {
                runUpdate = Launcher.DoInitialLaunch();
            }
            if (runUpdate)
            {
                UpdateGraphView();
            }
        }
Beispiel #6
0
 private void ButtonOpen_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (treeView1.SelectedItem == null)
         {
             return;
         }
         GraphViewModel          gvm  = (GraphViewModel)treeView1.SelectedItem;
         MetaEditAPI.MetaEditAPI port = Launcher.Port;
         MEAPI.AllowSetForegroundWindow();
         port.open(gvm.getGraph().ToMEOop());
     }
     catch (Exception err)
     {
         DialogProvider.ShowMessageDialog("API error: " + err.Message, "API error");
         this.correctErrorSituation();
     }
 }
 /// <summary>
 /// Reads settings from mer file.
 /// </summary>
 private void ReadFromConfigFile()
 {
     try
     {
         IniParser reader = new IniParser(this.merFilePath());
         this.ProgramPath = reader.GetSetting("programPath");
         this.WorkingDir  = reader.GetSetting("workingDir");
         this.Database    = reader.GetSetting("database");
         this.Username    = reader.GetSetting("username");
         this.Password    = reader.GetSetting("password");
         this.Projects    = reader.GetSetting("projects").Split(new Char[] { ';' });
         this.Host        = reader.GetSetting("hostname");
         int tempPort;
         int.TryParse(reader.GetSetting("port"), out tempPort);
         this.Port    = tempPort;
         this.Logging = reader.GetSetting("logging").Equals("true");
         this.Version = this.ParseVersion(this.ProgramPath);
     }
     catch (Exception ex)
     {
         DialogProvider.ShowMessageDialog("Error reading .mer file. " + ex.Message, "Error reading .mer file");
     }
 }
Beispiel #8
0
        /// <summary>
        /// Runs the named generator
        /// </summary>
        /// <param name="port">Connection to MetaEdit+ API server.</param>
        /// <param name="generator">Name of the generator</param>
        /// <returns>Was the generation successful (unknown=true, e.g. for 4.5)</returns>
        public bool RunGenerator(MetaEditAPI.MetaEditAPI port, String generator)
        {
            bool success = true;

            MEAPI.AllowSetForegroundWindow();
            try
            {
                if (Settings.GetSettings().Version.IsEqualOrGreaterThan("5.0"))
                {
                    success = port.forGraphRun(this.ToMEOop(), generator);
                }
                else
                {
                    MetaEditAPI.MENull meNull = new MetaEditAPI.MENull();
                    port.forName(meNull, this.Name, this.TypeName, generator);
                }
            }
            catch (Exception e)
            {
                DialogProvider.ShowMessageDialog("API error: " + e.Message, "API error");
                success = false;
            }
            return(success);
        }
Beispiel #9
0
        /// <summary>
        /// Lauches MetaEdit+ logs in opens one or more projects and starts API.
        /// </summary>
        /// <returns>True if launching succeeded.</returns>
        public static Boolean launchMetaEdit()
        {
            // Create the arguments
            string arguments = " currentDir: " + '"' + settings.WorkingDir + '"' + " " + "loginDB:user:password: "******" " +
                               settings.Username + " " + settings.Password;

            string[] projects = settings.Projects;
            foreach (string project in projects)
            {
                if (!project.Equals(""))
                {
                    arguments += " setProject: " + '"' + project + '"';
                }
            }
            arguments += " startAPIHostname:port:logEvents: " + settings.Host + " " + settings.Port + " " + settings.Logging;

            //Then launch MetaEdit+
            try
            {
                needStopAPI = true;
                System.Diagnostics.Process          process   = new System.Diagnostics.Process();
                System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
                startInfo.FileName    = settings.ProgramPath;
                startInfo.Arguments   = arguments;
                process.StartInfo     = startInfo;
                process.Start();

                return(true);
            }
            catch (Exception e)
            {
                DialogProvider.ShowMessageDialog("Could not start MetaEdit+: " + e.Message + "\nPlease start MetaEdit+ API and click OK to proceed", "Launch error");
                return(false);
            }
        }