Пример #1
0
        /// <summary>
        /// Load the parental rating collection from the configuration file.
        /// </summary>
        public static int Load()
        {
            string actualFileName = Path.Combine(RunParameters.DataDirectory, fileName);

            if (!File.Exists(actualFileName))
            {
                actualFileName = Path.Combine(RunParameters.ConfigDirectory, fileName);
            }

            Logger.Instance.Write("Loading Parental Ratings from " + actualFileName);

            parentalRatings = new Collection <ParentalRating>();

            XmlReader reader = null;

            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreWhitespace = true;

            try
            {
                reader = XmlReader.Create(actualFileName, settings);
            }
            catch (IOException)
            {
                Logger.Instance.Write("Failed to open " + actualFileName);
                return(0);
            }

            try
            {
                string currentLocation = null;
                string currentSystem   = null;
                string currentProtocol = null;

                while (!reader.EOF)
                {
                    reader.Read();
                    if (reader.IsStartElement())
                    {
                        switch (reader.Name)
                        {
                        case "Location":
                            currentLocation = reader.GetAttribute("code").Trim().ToUpperInvariant();
                            try
                            {
                                currentSystem = reader.GetAttribute("system").Trim().ToUpperInvariant();
                            }
                            catch (NullReferenceException)
                            {
                                currentSystem = null;
                            }
                            break;

                        case "Protocol":
                            currentProtocol = reader.GetAttribute("name").Trim().ToUpperInvariant();
                            break;

                        case "ParentalRating":
                            ParentalRating parentalRating = new ParentalRating(currentLocation,
                                                                               currentSystem,
                                                                               currentProtocol,
                                                                               reader.GetAttribute("code").Trim(),
                                                                               reader.GetAttribute("rating").Trim(),
                                                                               reader.GetAttribute("mpaaRating").Trim());
                            parentalRatings.Add(parentalRating);
                            break;

                        default:
                            break;
                        }
                    }
                }

                Logger.Instance.Write("Parental ratings loaded");
            }
            catch (XmlException e)
            {
                Logger.Instance.Write("Failed to load file " + actualFileName);
                Logger.Instance.Write("Data exception: " + e.Message);
            }
            catch (IOException e)
            {
                Logger.Instance.Write("Failed to load file " + actualFileName);
                Logger.Instance.Write("I/O exception: " + e.Message);
            }

            if (reader != null)
            {
                reader.Close();
            }

            return(parentalRatings.Count);
        }
Пример #2
0
        /// <summary>
        /// Load the parental rating collection from the configuration file.
        /// </summary>
        public static int Load()
        {
            string actualFileName = Path.Combine(RunParameters.DataDirectory, fileName);
            if (!File.Exists(actualFileName))
                actualFileName = Path.Combine(RunParameters.ConfigDirectory, fileName);

            Logger.Instance.Write("Loading Parental Ratings from " + actualFileName);

            parentalRatings = new Collection<ParentalRating>();

            XmlReader reader = null;

            XmlReaderSettings settings = new XmlReaderSettings();
            settings.IgnoreWhitespace = true;

            try
            {
                reader = XmlReader.Create(actualFileName, settings);
            }
            catch (IOException)
            {
                Logger.Instance.Write("Failed to open " + actualFileName);
                return (0);
            }

            try
            {
                string currentLocation = null;
                string currentSystem = null;
                string currentProtocol = null;

                while (!reader.EOF)
                {
                    reader.Read();
                    if (reader.IsStartElement())
                    {
                        switch (reader.Name)
                        {
                            case "Location":
                                currentLocation = reader.GetAttribute("code").Trim().ToUpperInvariant();
                                try
                                {
                                    currentSystem = reader.GetAttribute("system").Trim().ToUpperInvariant();
                                }
                                catch (NullReferenceException)
                                {
                                    currentSystem = null;
                                }
                                break;
                            case "Protocol":
                                currentProtocol = reader.GetAttribute("name").Trim().ToUpperInvariant();
                                break;
                            case "ParentalRating":
                                ParentalRating parentalRating = new ParentalRating(currentLocation,
                                    currentSystem,
                                    currentProtocol,
                                    reader.GetAttribute("code").Trim(),
                                    reader.GetAttribute("rating").Trim(),
                                    reader.GetAttribute("mpaaRating").Trim());
                                parentalRatings.Add(parentalRating);
                                break;
                            default:
                                break;
                        }
                    }
                }

                Logger.Instance.Write("Parental ratings loaded");
            }
            catch (XmlException e)
            {
                Logger.Instance.Write("Failed to load file " + actualFileName);
                Logger.Instance.Write("Data exception: " + e.Message);
            }
            catch (IOException e)
            {
                Logger.Instance.Write("Failed to load file " + actualFileName);
                Logger.Instance.Write("I/O exception: " + e.Message);
            }

            if (reader != null)
                reader.Close();

            return (parentalRatings.Count);
        }