コード例 #1
0
        public static void ReadOptions()
        {
            string optionsFilePath = Project.GetMiscPath(Project.OPTIONS_FILE_NAME);

#if DEBUG
            Tracer.Trace("IP: Project:ReadOptions() path=" + optionsFilePath);
#endif
            DateTime startedRead = DateTime.Now;
            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(optionsFilePath);

                // we want to traverse XmlDocument fast, as tile load operations can be numerous
                // and come in pack. So we avoid using XPath and rely mostly on "foreach child":
                foreach (XmlNode nnode in xmlDoc.ChildNodes)
                {
                    if (nnode.Name.Equals("options"))
                    {
                        foreach (XmlNode node in nnode.ChildNodes)
                        {
                            string nodeName = node.Name;
                            try
                            {
                            }
                            catch (Exception ee)
                            {
                                // bad node - not a big deal...
                                Tracer.Error("Project:ReadOptions() node=" + nodeName + " " + ee.Message);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Tracer.Error("Project:ReadOptions() " + e.Message);
            }

            Tracer.Trace("ReadOptions: " + Math.Round((DateTime.Now - startedRead).TotalMilliseconds) + " ms");

            // restore controllerPortSettings from the file or fill it with default values:
            restoreOrDefaultPortSettings();
        }
コード例 #2
0
        // returns true if could restore from file
        public static bool restoreOrDefaultPortSettings()
        {
            bool ret = false;

            // restore controllerPortSettings from the file or fill it with default values:
            string controllerPortFilePath = Project.GetMiscPath(Project.CONTROLLER_PORTCONFIG_FILE_NAME + "-" + currentControllerMake + ".xml");

            if (!File.Exists(controllerPortFilePath))
            {
                // older versions used single file for all Controllers
                controllerPortFilePath = Project.GetMiscPath(Project.CONTROLLER_PORTCONFIG_FILE_NAME + ".xml");
            }
            Stream fs = null;

            try
            {
                fs = new FileStream(controllerPortFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
                Project.controllerPortSettings = CommBaseSettings.LoadFromXML(fs);
                if (Project.controllerPortSettings == null)
                {
                    throw new Exception();
                }
                ret = true;
            }
            catch
            {
                Project.controllerPortSettings            = new CommBaseSettings();
                Project.controllerPortSettings.port       = "COM1:";
                Project.controllerPortSettings.baudRate   = 9600;
                Project.controllerPortSettings.parity     = Parity.none;
                Project.controllerPortSettings.autoReopen = true;
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
            }

            return(ret);
        }
コード例 #3
0
        public static void SaveOptions()
        {
            string optionsFilePath = Project.GetMiscPath(Project.OPTIONS_FILE_NAME);

            //Tracer.Trace("Project:SaveOptions: " + optionsFilePath);
            try
            {
                string      seedXml = Project.SEED_XML + "<options></options>";
                XmlDocument xmlDoc  = new XmlDocument();
                xmlDoc.LoadXml(seedXml);

                XmlNode root = xmlDoc.DocumentElement;

                SetValue(xmlDoc, root, "time", "" + DateTime.Now);
            }
            catch (Exception e)
            {
                Tracer.Error("Project:SaveOptions() " + e.Message);
            }
        }
コード例 #4
0
        public static void savePortSettings()
        {
            FileStream fs = null;

            try
            {
                string controllerPortFilePath = Project.GetMiscPath(Project.CONTROLLER_PORTCONFIG_FILE_NAME + "-" + currentControllerMake + ".xml");
                fs = new FileStream(controllerPortFilePath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
                Project.controllerPortSettings.SaveAsXML(fs);
            }
            catch (Exception ee)
            {
                Tracer.Error("saving port settings: " + ee.Message);
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }