Example #1
0
        //todo: Change this to accept a path for the file
        //public static CommanderParameterFile ReadCommanderParameterFile(string filename)
        public static CommanderParameterFile ReadCommanderParameterFile()
        {
            //todo: add exception handling
            //Try Read the XML file
            XmlSerializer deserializer = new XmlSerializer(typeof(CommanderParameterFile));
            string        appPath      = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
            TextReader    reader       = new StreamReader(@"C:\Commander\CommanderParameterList.xml");//(Environment.CurrentDirectory + @"\C2xxParameters.xml");

            CommanderParameterContent = reader.ReadToEnd();
            reader = new StringReader((string)CommanderParameterContent.Clone());
            object obj = deserializer.Deserialize(reader);
            CommanderParameterFile f = (CommanderParameterFile)obj;

            reader.Close();
            return(f);
        }
Example #2
0
        public static string CreateCommanderParameterFile(CommanderParameterFile f)
        {
            string result = "File created succesfully";

            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(CommanderParameterFile));
                using (TextWriter writer = new StreamWriter(@"C:\Commander\CommanderParameterList.xml"))
                {
                    serializer.Serialize(writer, f);
                }
            }
            catch (Exception e)
            {
                result = e.ToString();
            }

            return(result);
        }