コード例 #1
0
 /// <summary>
 ///   Catches the specified exception.
 /// </summary>
 /// <param name = "Exc">The exc.</param>
 public static void Catch(Exception Exc)
 {
     try
     {
         if (!File.Exists(ErrorLogFile))
         {
             var fs = new FileStream(ErrorLogFile, FileMode.OpenOrCreate, FileAccess.ReadWrite);
             fs.Close();
         }
         var sw = new StreamWriter(ErrorLogFile, true);
         sw.Write(MakeErrorString(Exc, true));
         sw.Flush();
         sw.Close();
         var    r         = new Random();
         string erCaption = counter == ErrorWelcomeCaptions.GetLength(0)
                                ? ErrorWelcomeCaptions[r.Next(ErrorWelcomeCaptions.GetLength(0))]
                                : ErrorWelcomeCaptions[counter++];
         SearchIO.MessageBoxShow("Error found in " + Exc.Source +
                                 "\nError contents can be found in " + ErrorLogFile, erCaption, "Error");
     }
     catch (Exception e)
     {
         SearchIO.output("Error in ErrorLogger (how did this happen?!)"
                         + e);
     }
 }
コード例 #2
0
 /// <summary>
 /// Loads the default seed and rule sets.
 /// </summary>
 public void LoadDefaultSeedAndRuleSets()
 {
     try
     {
         rulesets = new ruleSet[numOfRuleSets];
         SearchIO.output("There are " + numOfRuleSets + " rulesets.");
         var filename = getOpenFilename(InputDirAbs, DefaultSeedFileName);
         if (filename != "")
         {
             var graphAndCanvas = filer.Open(filename, true);
             if (graphAndCanvas == null)
             {
                 seed = null;
                 DefaultSeedFileName = "";
                 SearchIO.MessageBoxShow("The seed graph was not found. Please change to valid file"
                                         + " in settings.", "Seed Graph Not Found.", "Error");
             }
             else
             {
                 seed = (designGraph)graphAndCanvas[0];
                 DefaultSeedFileName = filename;
                 SearchIO.addAndShowGraphWindow(graphAndCanvas,
                                                "SEED: " + Path.GetFileNameWithoutExtension(filename));
                 SearchIO.output("Seed graph, " + Path.GetFileNameWithoutExtension(filename) + " ,successfully opened.");
             }
         }
         for (var i = 0; i < numOfRuleSets; i++)
         {
             var RSFileName = "";
             if (i < defaultRSFileNames.Count)
             {
                 RSFileName = defaultRSFileNames[i];
             }
             filename = getOpenFilename(RulesDirAbs, RSFileName);
             if (filename == "")
             {
                 continue;
             }
             object objRS = filer.Open(filename, true);
             if (objRS == null)
             {
                 rulesets[i]           = null;
                 defaultRSFileNames[i] = "";
                 SearchIO.output("No Rule Set found at #" + i + ".");
             }
             else
             {
                 rulesets[i] = (ruleSet)((object[])objRS)[0];
                 SearchIO.addAndShowRuleSetWindow(new object[] { rulesets[i], filename },
                                                  "RS" + i + ": " + Path.GetFileNameWithoutExtension(filename));
                 // SearchIO.output("Rule Set #" + i + " sucessfully opened.");
             }
         }
     }
     catch (Exception exc)
     {
         ErrorLogger.Catch(exc);
     }
 }
コード例 #3
0
        /// <summary>
        /// Saves the new settings.
        /// </summary>
        /// <param name="filename">The filename.</param>
        public void saveNewSettings(string filename = "")
        {
            if (string.IsNullOrWhiteSpace(filename))
            {
                filename = FilePath;
            }
            if (string.IsNullOrWhiteSpace(filename))
            {
                filename = "GraphSynthSettings.gsconfig";
            }
            if (!Path.IsPathRooted(filename))
            {
                /* if windows machine,the default errorlog location is in the User\AppData\Roaming\GraphSynth */
                if (Environment.OSVersion.Platform.ToString().StartsWith("Win"))
                {
                    var appDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + DS + "GraphSynth";
                    if (!Directory.Exists(appDir))
                    {
                        Directory.CreateDirectory(appDir);
                    }
                    filename = appDir + DS + filename;
                }
                /* otherwise, put it in the executable directory */
                else
                {
                    filename = ExecDir + filename;
                }
            }
            FilePath = filename;
            var tempConfigDir = ConfigDir;

            ConfigDir = Path.GetDirectoryName(filename);
            StreamWriter streamWriter = null;

            try
            {
                streamWriter = new StreamWriter(filename);
                var SettingsSerializer = new XmlSerializer(typeof(GlobalSettings));
                SettingsSerializer.Serialize(streamWriter, this);
                SearchIO.MessageBoxShow("Saved at " + filename, "Settings file saved successfuly.");
            }
            catch (Exception e)
            {
                SearchIO.MessageBoxShow("The configuration file did not save because of error: "
                                        + e,
                                        "Error Saving config file.", "Error");
            }
            finally
            {
                ConfigDir = tempConfigDir;
                if (streamWriter != null)
                {
                    streamWriter.Close();
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Checks the rule with some issues that may have been overlooked.
        /// </summary>
        /// <param name="gR">The grammar rule.</param>
        /// <returns></returns>
        public static Boolean checkRule(grammarRule gR)
        {
            if ((gR.L.checkForRepeatNames()) &&
                !SearchIO.MessageBoxShow("You are not allowed to have repeat names in L. I have changed these " +
                                         "names to be unique, which may have disrupted your context graph, K. Do you want to continue?",
                                         "Repeat names in L", "Information", "YesNo", "Yes"))
            {
                return(false);
            }

            if ((gR.R.checkForRepeatNames()) &&
                !SearchIO.MessageBoxShow("You are not allowed to have repeat names in R. I have changed" +
                                         " these names to be unique, which may have disrupted your context graph, K. Do you" +
                                         " want to continue?", "Repeat names in R", "Information", "YesNo", "Yes"))
            {
                return(false);
            }

            if ((NotExistElementsinKR(gR)) &&
                !SearchIO.MessageBoxShow("There appears to be common elements between "
                                         + "the left and right hand sides of the rule that are indicated as \"Must NOT Exist\""
                                         + " within the left-hand side. This is not allowed. Continue Anyway?", "Improper use of negative elements",
                                         "Error", "YesNo", "No"))
            {
                return(false);
            }

            if ((NumKElements(gR) == 0) &&
                !SearchIO.MessageBoxShow("There appears to be no common elements between " +
                                         "the left and right hand sides of the rule. Is this intentional? If so, click yes to continue.",
                                         "No Context Graph", "Information", "YesNo", "Yes"))
            {
                return(false);
            }

            if ((KarcsChangeDirection(gR) != "") &&
                !SearchIO.MessageBoxShow("It appears that arc(s): " + KarcsChangeDirection(gR) +
                                         " change direction (to = from or vice-versa). Even though the arc(s) might be undirected," +
                                         " this can still lead to problems in the rule application, it is recommended that this is" +
                                         " fixed before saving. Save anyway?", "Change in Arc Direction", "Information", "YesNo", "Yes"))
            {
                return(false);
            }

            if ((!ValidateFreeArcEmbeddingRules(gR)) &&
                !SearchIO.MessageBoxShow("There appears to be invalid references in the free arc embedding rules." +
                                         " Node names used in free arc embedding rules do not exist. Continue Anyway?",
                                         "Invalid Free-Arc References", "Error", "YesNo", "No"))
            {
                return(false);
            }

            gR.ReorderNodes();
            return(true);
        }
コード例 #5
0
        /// <summary>
        /// Reads in the settings.
        /// </summary>
        /// <param name="configPath">The file path.</param>
        /// <returns></returns>
        public static GlobalSettings readInSettings(string configPath = "")
        {
            GlobalSettings settings  = null;
            var            filePaths = GetPotentialFiles(configPath.TrimEnd(DS));
            var            i         = 0;

            while ((i < filePaths.Count) && !readInSettings(filePaths[i], out settings))
            {
                i++;
            }
            if (i == filePaths.Count)
            {
                SearchIO.MessageBoxShow(
                    "Welcome to GraphSynth. This very well might be your first time with this program, " +
                    "since no valid configuration file was found.\n\nPlease review and edit the default "
                    + "Settings in the Edit Drop-Down Menu.",
                    "Welcome to GraphSynth");
                if (Environment.OSVersion.Platform.ToString().StartsWith("Win"))
                {
                    ConfigDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + DS +
                                "GraphSynth" + DS;
                }
                else
                {
                    ConfigDir = ExecDir;
                }
                settings = new GlobalSettings {
                    FilePath = configPath
                };
                settings.LoadDefaults();
                settings.saveNewSettings();
            }
            else
            {
                SearchIO.output("Loaded settings at" + filePaths[i] + ".");
                if (i > 0)
                {
                    SearchIO.output("Found after trying:");
                    for (var j = 0; j < i; j++)
                    {
                        SearchIO.output(j + ". " + filePaths[j]);
                    }
                }
                settings.FilePath = filePaths[i];
            }
            return(settings);
        }
コード例 #6
0
 private static string getOpenFilename(string dir, string filename)
 {
     if (string.IsNullOrWhiteSpace(filename))
     {
         return("");
     }
     //if (!filename.EndsWith(".xml")) filename += ".xml";
     if ((Path.IsPathRooted(filename)) && File.Exists(filename))
     {
         return(filename);
     }
     if (File.Exists(dir + filename))
     {
         return(dir + filename);
     }
     if (filename.Length > 0)
     {
         SearchIO.MessageBoxShow("File named " + filename + " not found.",
                                 " File not found.", "Error");
     }
     return("");
 }