Example #1
0
        private void Init()
        {
            try {
                string basepath = System.Reflection.Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", "").Replace("/", @"\");
                basepath = System.IO.Path.GetDirectoryName(basepath) + @"\";

                GameCatalogSerializer  gcs = new GameCatalogSerializer();
                System.Xml.XmlDocument doc = gcs.Serialize(games);

                System.Xml.XPath.XPathNavigator nav    = doc.CreateNavigator();
                System.Xml.Xsl.XslTransform     xt     = new System.Xml.Xsl.XslTransform();
                System.Xml.XmlResolver          res    = new System.Xml.XmlUrlResolver();
                System.IO.StringWriter          writer = new System.IO.StringWriter();
                System.Xml.Xsl.XsltArgumentList args   = new System.Xml.Xsl.XsltArgumentList();

                System.Xml.XmlNameTable xnt  = new System.Xml.NameTable();
                System.Xml.XmlReader    xslt = new System.Xml.XmlTextReader(new System.IO.StreamReader(basepath + "GameList.xslt"), xnt);

                xt.Load(xslt, res, new System.Security.Policy.Evidence());
                xt.Transform(nav, args, writer, res);

                string html = writer.ToString();

                WriteHTML(html);
            } catch (Exception ex) {
                string    error = "There was an error generating HTML";
                Exception xe    = ex;
                while (xe != null)
                {
                    error += "<p><b>" + xe.Message + "</b><br><pre>" + xe.StackTrace + "</pre></p>\r\n";
                }
                WriteHTML(error);
            }
        }
Example #2
0
        /// <summary>Reads config data from config file.</summary>
        /// <param name="file">Config file name.</param>
        /// <returns></returns>
        public static GameCatalog ReadFile(string file)
        {
            GameCatalogSerializer serializer = new GameCatalogSerializer();

            try {
                string xml = string.Empty;
                using (StreamReader reader = new StreamReader(file)) {
                    xml = reader.ReadToEnd();
                    reader.Close();
                }
                return(serializer.Deserialize(xml));
            } catch {}
            return(new GameCatalog());
        }
Example #3
0
        /// <summary>Writes config data to config file.</summary>
        /// <param name="file">Config file name.</param>
        /// <param name="config">Config object.</param>
        /// <returns></returns>
        public static bool WriteFile(string file, GameCatalog config)
        {
            bool ok = false;
            GameCatalogSerializer serializer = new GameCatalogSerializer();

            try {
                string xml = serializer.Serialize(config).OuterXml;
                using (StreamWriter writer = new StreamWriter(file, false)) {
                    writer.Write(xml);
                    writer.Flush();
                    writer.Close();
                }
                ok = true;
            } catch {}
            return(ok);
        }
Example #4
0
 private void SaveFile(string filename)
 {
     GameCatalogSerializer.WriteFile(filename, games);
     this.filename = filename;
     dirty         = false;
 }
Example #5
0
 private void OpenFile(string filename)
 {
     this.filename = filename;
     games         = GameCatalogSerializer.ReadFile(filename);
     dirty         = false;
 }