Esempio n. 1
0
 public void Setup()
 {
     GetSettings();
     SweeperSelecctSettings.LoadCurrentData();
     SweeperSelecctSettings.Initialize();
 }
Esempio n. 2
0
        //////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////  STATIC METHODS  ////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Gets the settings from the xml file, and if it doesn't exist asks whether to create one
        /// </summary>
        private static void GetSettings()
        {
            if (!System.IO.Directory.Exists(DefaultSweeperSettingsDirectoryPath))
            {
                if (main_window.CreateMessageBoxYesNo("No settings were found. \nDO YOU WANT TO CREATE THEM?", "NO SETTINGS FOUND"))
                {
                    System.IO.Directory.CreateDirectory(DefaultSweeperSettingsDirectoryPath);
                    SweeperSelecctSettings.Initialize();
                }
            }
            else
            {
                if (System.IO.Directory.GetFiles(DefaultSweeperSettingsDirectoryPath).Count() != 0)
                {
                    bool          file_found = false;
                    List <string> files      = new List <string>();
                    files = System.IO.Directory.GetFiles(DefaultSweeperSettingsDirectoryPath).ToList();
                    files.ForEach((f) =>
                    {
                        if (f.ToLower().EndsWith(".sws.xml"))
                        {
                            XmlDocument k = new XmlDocument();

                            using (System.IO.StreamReader sr = new System.IO.StreamReader(f, Encoding.Default))
                            {
                                try
                                {
                                    k.Load(sr);
                                }
                                catch
                                {
                                }
                                XmlNode ee = k.FirstChild;
                                if (ee.Name == "SweeperSettings")
                                {
                                    file_found = true;
                                    SweeperSettings.SweeperSettingsFileName = f;
                                    GetDataFromXMLFile(f);
                                    return;
                                }
                            }
                        }
                    });
                    if (!file_found)
                    {
                        if (main_window.CreateMessageBoxYesNo("No settings were found. \nDO YOU WANT TO CREATE THEM?", "NO SETTINGS FOUND"))
                        {
                            System.IO.Directory.CreateDirectory(DefaultSweeperSettingsDirectoryPath);
                            SweeperSelecctSettings.Initialize();
                        }
                    }
                }
                else
                {
                    if (main_window.CreateMessageBoxYesNo("No settings were found!\n Do you want to create new settigs?", "Error: No Settings Found!"))
                    {
                        SweeperSelecctSettings.Initialize();
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the radio sweeper settings data from the xml file
        /// </summary>
        /// <param name="path"></param>
        public static void GetDataFromXMLFile(string path)
        {
            CurrentSettingsFilePath = path;
            XmlDocument doc = new XmlDocument();

            using (StreamReader sr = new StreamReader(path, Encoding.Default))
            {
                try { doc.Load(sr); }
                catch { }
            }

            if (!doc.HasChildNodes)   ////////////////// COME BACK COME BACK COME BACK COME BACK
            {
                if (main_window.CreateMessageBoxYesNo("No settings detected in file. Do you want to create them?", "Error: NO SETTINGS DETECTED!"))
                {
                    System.IO.Directory.CreateDirectory(DefaultSweeperSettingsDirectoryPath);
                    SweeperSelecctSettings.Initialize();
                }
            }
            else
            {
                XmlNode root = doc.FirstChild;
                if (root.Name == "SweeperSettings")
                {
                    XmlNodeList radio_children = root.ChildNodes;
                    foreach (XmlElement r in radio_children)
                    {
                        if (r.Name == "Radio")
                        {
                            //Gets the name and the letter of the given radio
                            RadioSWSettings radioSWS = new RadioSWSettings(r.GetAttribute("name"));
                            radioSWS.RadioLetter = r.GetAttribute("letter");
                            SweeperSettings.AllSweeperSettings.Add(radioSWS);

                            XmlNodeList folder_children = r.ChildNodes;
                            foreach (XmlElement ff in folder_children)
                            {
                                if (ff.Name == "Folders")
                                {
                                    foreach (XmlElement f in ff.ChildNodes)
                                    {
                                        RadioSWSettingsFolders fdr = new RadioSWSettingsFolders(f.GetAttribute("path"), radioSWS.RadioName);

                                        //Gets all child nodes including <Files> , <ExceptionFiles>, <SweepersPerHour> & <SweepersPerHourNumber>
                                        XmlNodeList folder_nodes = f.ChildNodes;
                                        foreach (XmlNode node in folder_nodes)
                                        {
                                            int n;
                                            if (node.Name == "Files" && node.InnerText != string.Empty)
                                            {
                                                fdr.Files = node.InnerText.Split(';').ToList();
                                            }
                                            if (node.Name == "ExceptionFiles" && node.InnerText != string.Empty)
                                            {
                                                fdr.ExceptionFiles = node.InnerText.Split(';').ToList(); fdr.UpdateFilesWithoutExceptionFiles();
                                            }
                                            if (node.Name == "SweepersPerHour")
                                            {
                                                fdr.PerHour = node.InnerText == "One" ? SweeperEveryHour.One :
                                                              (node.Value == "Two" ? SweeperEveryHour.Two :
                                                               (node.Value == "Number" ? SweeperEveryHour.Number :
                                                                (node.Value == "Norman" ? SweeperEveryHour.Normal : SweeperEveryHour.None)));
                                            }
                                            if (node.Name == "SweepersPerHourNumber")
                                            {
                                                fdr.PerHourNumber = int.TryParse(node.InnerText, out n) ? n : 0;
                                            }
                                        }
                                        radioSWS.AddFolder(fdr);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }