Ejemplo n.º 1
0
        private void SaveRule(string filename, grammarRule rule, designGraph graphK, CanvasProperty canvProp)
        {
            if (UserCancelled)
            {
                return;
            }
            progress  = 3;
            rule.name = Path.GetFileNameWithoutExtension(filename);

            if (checkRule(rule))
            {
                // progress is now at 13
                string SaveString = null;
                dispatch.Invoke((ThreadStart) delegate
                {
                    var xamlPage = BuildXAMLRulePage(rule, graphK, canvProp);
                    SaveString   = XamlWriter.Save(xamlPage);
                });
                progress   = 85;
                SaveString = MyXamlHelpers.CleanOutxNulls(SaveString);

                /* A little manipulation is needed to stick the GraphSynth objects within the page. *
                 * The IgnorableSetup string ensures that XAML viewers ignore the following      *
                 * GraphSynth specific elements: the canvas data, and the graph data. This eff-  *
                 * ectively separates the topology and data of the graph from the graphic elements.       */
                SaveString = SaveString.Insert(SaveString.IndexOf(">"),
                                               IgnorableSetup + "Tag=\"Rule\" ");
                /* remove the ending Page tag but put it back at the end. */
                SaveString = SaveString.Replace("</Page>", "");

                /* add the canvas properties. */
                if (canvProp != null)
                {
                    dispatch.Invoke(
                        (ThreadStart)
                        delegate { SaveString += "\n\n" + AddIgnorablePrefix(CanvasProperty.SerializeCanvasToXml(canvProp)); });
                }
                progress = 92;
                /* add the graph data. */
                SaveString += "\n\n" + AddIgnorablePrefix(SerializeRuleToXml(rule)) + "\n\n";
                /* put the closing tag back on. */
                SaveString += "</Page>";
                try
                {
                    File.WriteAllText(filename, SaveString);
                }
                catch (Exception E)
                {
                    if (!suppressWarnings)
                    {
                        progWindow.QueryUser("File Access Exception" + E.Message, 10000, "", "Cancel", false);
                    }
                }
                progress = 100;
                if ((progWindow != null) && (!suppressWarnings))
                {
                    progWindow.QueryUser("\n                     **** Rule successfully saved. ****", 1000, "OK", "",
                                         false);
                }
                else
                {
                    SearchIO.output("**** Rule successfully saved. ****", 2);
                }
            }
        }
Ejemplo n.º 2
0
        private void SaveGraph(string filename, designGraph graph, CanvasProperty canvProp)
        {
            if (UserCancelled)
            {
                return;
            }
            progress   = 5;
            graph.name = Path.GetFileNameWithoutExtension(filename);
            removeNullWhiteSpaceEmptyLabels(graph);

            if ((graph.checkForRepeatNames()) && !suppressWarnings)
            {
                progWindow.QueryUser("Sorry, but you are not allowed to have repeat names. I have changed" +
                                     " these names to be unique", 5000, "OK", "", false);
            }

            progress = 7;
            if (UserCancelled)
            {
                return;
            }
            progressEnd = 80;
            /* go build the browser page */
            string SaveString = null;

            dispatch.Invoke((ThreadStart) delegate
            {
                var xamlPage = BuildXAMLGraphPage(graph, canvProp);
                progress     = 80;
                SaveString   = XamlWriter.Save(xamlPage);
            });
            progress = 87;
            if (UserCancelled)
            {
                return;
            }
            SaveString = MyXamlHelpers.CleanOutxNulls(SaveString);

            /* A little manipulation is needed to stick the GraphSynth objects within the page. *
             * The IgnorableSetup string ensures that XAML viewers ignore the following      *
             * GraphSynth specific elements: the canvas data, and the graph data. This eff-  *
             * ectively separates the topology and data of the graph from the graphic elements.       */
            SaveString = SaveString.Insert(SaveString.IndexOf(">"),
                                           IgnorableSetup + "Tag=\"Graph\" ");
            /* remove the ending Page tag but put it back at the end. */
            SaveString = SaveString.Replace("</Page>", "");

            /* add the canvas properties. */
            if (canvProp != null)
            {
                dispatch.Invoke(
                    (ThreadStart)
                    delegate { SaveString += "\n\n" + AddIgnorablePrefix(CanvasProperty.SerializeCanvasToXml(canvProp)); });
            }
            progress = 95;
            if (UserCancelled)
            {
                return;
            }
            /* add the graph data. */
            SaveString += "\n\n" + AddIgnorablePrefix(SerializeGraphToXml(graph)) + "\n\n";
            if (UserCancelled)
            {
                return;
            }
            /* put the closing tag back on. */
            SaveString += "</Page>";
            try
            {
                File.WriteAllText(filename, SaveString);
                progress = 100;
                if ((progWindow != null) && !suppressWarnings)
                {
                    progWindow.QueryUser("\n                     **** Graph successfully saved. ****", 1000, "OK", "",
                                         false);
                }
                else
                {
                    SearchIO.output("**** Graph successfully saved. ****", 2);
                }
            }
            catch (Exception E)
            {
                if ((progWindow != null) && !suppressWarnings)
                {
                    progWindow.QueryUser("File Access Exception" + E.Message, 10000, "", "Cancel", false);
                }
                else
                {
                    SearchIO.output("File Access Exception" + E.Message, 2);
                }
            }
        }