Example #1
0
    public static List <string> GetStationNames()
    {
        List <string> stationNames = new List <string>();

        try
        {
            // Get the application configuration file.
            System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                    ConfigurationUserLevel.None) as Configuration;

            // Read and display the custom section.
            ObservingStationsSection myStations =
                config.GetSection("ObservingStations") as ObservingStationsSection;

            if (myStations == null)
            {
                Console.WriteLine("Failed to load ObservingStationsSection.");
            }
            else
            {
                Console.WriteLine("Stations defined in the configuration file:");
                for (int i = 0; i < myStations.Stations.Count; i++)
                {
                    stationNames.Add(myStations.Stations[i].Name);
                }
            }
            return(stationNames);
        }
        catch (Exception ex)
        {
            return(null);
        }
    }
Example #2
0
    // Create a custom section and save it in the
    // application configuration file.
    public static void CreateCustomSection()
    {
        try
        {
            // Create a custom configuration section.
            ObservingStationsSection myStationsSection = new ObservingStationsSection();
            myStationsSection.SectionInformation.RestartOnExternalChanges = false;

            // Get the current configuration file.
            System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                    ConfigurationUserLevel.None);

            // Add the custom section to the application configuration file.
            if (config.Sections["ObservingStations"] == null)
            {
                config.Sections.Add("ObservingStations", myStationsSection);
                config.Sections["ObservingStations"].SectionInformation.RestartOnExternalChanges = false;
            }

            // Save the application configuration file.
            myStationsSection.SectionInformation.ForceSave = true;
            config.Save(ConfigurationSaveMode.Modified);

            ConfigurationManager.RefreshSection("ObservingStations");

            Console.WriteLine("Created custom section in the application configuration file: {0}",
                              config.FilePath);
            Console.WriteLine();
        }
        catch (ConfigurationErrorsException err)
        {
            Console.WriteLine("CreateCustomSection: {0}", err.ToString());
        }
    }
Example #3
0
        public void LoadConfigurationSettings(string stationName)
        {
            Configuration config = GetSystemConfigObject();

            try
            {
                if (!string.IsNullOrEmpty(stationName))
                {
                    // Read and display the custom section.
                    ObservingStationsSection myStations = config.GetSection("ObservingStations") as ObservingStationsSection;

                    StationConfigElement station = null;

                    if (myStations != null)
                    {
                        for (int i = 0; i < myStations.Stations.Count; i++)
                        {
                            if (myStations.Stations[i].Name == stationName)
                            {
                                station = myStations.Stations[i];
                                break;
                            }
                        }

                        if (station == null)
                        {
                            station = new StationConfigElement(stationName, string.Empty, string.Empty, string.Empty, 300, 30, false);

                            myStations.Stations.Add(station);
                        }
                        this.OriginalLogsDirectory              = station.Logs;
                        this.OriginalScreenshotsDirectory       = station.Screenshots;
                        this.HighResolutionScreenshotsDirectory = station.HighResolutions;
                        this.CaptureSpan      = station.CaptureSpan;
                        this.ScreenshotsDelay = station.CaptureDelay;
                        this.UsePagination    = station.UsePagination;
                    }
                    else
                    {
                        UsingConfigurationCollectionAttribute.CreateCustomSection();
                    }
                }

                int temp = 0;

                if (config.AppSettings.Settings["defaultStation"] != null)
                {
                    this.DefaultStation = config.AppSettings.Settings["defaultStation"].Value.ToString();
                }

                int.TryParse(config.AppSettings.Settings["annualTopMeteorCount"].Value, out temp);
                this.AnnualTopMeteorCount = temp;
            }
            catch { }
        }
Example #4
0
    public static List <string> ReadCustomSection(string stationName, ConfigObject localConfig)
    {
        List <string> stationNames = new List <string>();

        try
        {
            // Get the application configuration file.
            System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                    ConfigurationUserLevel.None) as Configuration;

            // Read and display the custom section.
            ObservingStationsSection myStations =
                config.GetSection("ObservingStations") as ObservingStationsSection;

            if (myStations == null)
            {
                Console.WriteLine("Failed to load ObservingStationsSection.");
            }
            else
            {
                Console.WriteLine("Stations defined in the configuration file:");
                for (int i = 0; i < myStations.Stations.Count; i++)
                {
                    stationNames.Add(myStations.Stations[i].Name);

                    Console.WriteLine("  Name={0} InputLogs={1} Screenshots={2} CaptureDelay={3}",
                                      myStations.Stations[i].Name,
                                      myStations.Stations[i].Logs,
                                      myStations.Stations[i].Screenshots,
                                      myStations.Stations[i].HighResolutions,
                                      myStations.Stations[i].CaptureSpan,
                                      myStations.Stations[i].CaptureDelay,
                                      myStations.Stations[i].UsePagination);
                }
            }
        }
        catch (ConfigurationErrorsException err)
        {
            Console.WriteLine("ReadCustomSection(string): {0}", err.ToString());
        }

        return(stationNames);
    }
Example #5
0
        public void SaveConfigurationSettings(string stationName)
        {
            Configuration config = GetSystemConfigObject();

            if (!string.IsNullOrEmpty(stationName) && config != null)
            {
                try
                {
                    // Read and display the custom section.
                    ObservingStationsSection myStations = config.GetSection("ObservingStations") as ObservingStationsSection;

                    if (myStations == null)
                    {
                        UsingConfigurationCollectionAttribute.CreateCustomSection();
                    }

                    // Update station-specific properties...
                    myStations.Stations.Remove(stationName);

                    StationConfigElement station = new StationConfigElement(stationName,
                                                                            this.OriginalLogsDirectory,
                                                                            this.OriginalScreenshotsDirectory,
                                                                            this.HighResolutionScreenshotsDirectory,
                                                                            this.CaptureSpan,
                                                                            this.ScreenshotsDelay,
                                                                            this.UsePagination);

                    myStations.Stations.Add(station);

                    // Process the common properties...
                    if (config.AppSettings.Settings["defaultStation"] != null)
                    {
                        config.AppSettings.Settings["defaultStation"].Value = this.DefaultStation;
                    }

                    config.AppSettings.Settings["annualTopMeteorCount"].Value = this.AnnualTopMeteorCount.ToString();

                    config.Save(ConfigurationSaveMode.Full);
                }
                catch { }
            }
        }
Example #6
0
        public void UpdateConfigurationSettings(string stationName)
        {
            try
            {
                // Get the current configuration file.
                Configuration systemConfig = GetSystemConfigObject();

                // Read and display the custom section.
                ObservingStationsSection myStations = systemConfig.GetSection("ObservingStations") as ObservingStationsSection;

                List <StationConfigElement> arrayOfStations = new List <StationConfigElement>();

                if (myStations != null)
                {
                    foreach (StationConfigElement stationElement in myStations.Stations)
                    {
                        if (stationElement.Name != stationName)
                        {
                            StationConfigElement station = new StationConfigElement(stationElement.Name,
                                                                                    stationElement.Logs,
                                                                                    stationElement.Screenshots,
                                                                                    stationElement.HighResolutions,
                                                                                    stationElement.CaptureSpan,
                                                                                    stationElement.CaptureDelay,
                                                                                    stationElement.UsePagination);

                            arrayOfStations.Add(station);
                        }
                    }

                    systemConfig.Sections.Remove("ObservingStations");
                }

                // Create a custom configuration section.
                ObservingStationsSection myStationsSection = new ObservingStationsSection();

                foreach (StationConfigElement stationElement in arrayOfStations)
                {
                    myStationsSection.Stations.Add(stationElement);
                }

                // Take care to save the changes...
                StationConfigElement updatedStation = new StationConfigElement(stationName,
                                                                               this.OriginalLogsDirectory,
                                                                               this.OriginalScreenshotsDirectory,
                                                                               this.HighResolutionScreenshotsDirectory,
                                                                               this.CaptureSpan,
                                                                               this.ScreenshotsDelay,
                                                                               this.UsePagination);

                //myStations.Stations.Add(updatedStation);
                myStationsSection.Stations.Add(updatedStation);

                // Add the custom section to the application configuration file.
                if (systemConfig.Sections["ObservingStations"] == null)
                {
                    systemConfig.Sections.Add("ObservingStations", myStationsSection);
                }

                // Save the application configuration file.
                myStationsSection.SectionInformation.ForceSave = true;

                systemConfig.Save(ConfigurationSaveMode.Modified);

                ConfigurationManager.RefreshSection("ObservingStations");
            }
            catch { }
        }