Exemplo n.º 1
0
        /// <summary>
        /// Load the station collection from an XML file.
        /// </summary>
        /// <param name="fileName">The full name of the xml file.</param>
        /// <returns>A collection of stations or null if the file cannot be opened.</returns>
        public static Collection <TVStation> Load(string fileName)
        {
            TVStation station = null;
            XmlReader reader  = null;

            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreWhitespace = true;

            try
            {
                reader = XmlReader.Create(fileName, settings);
            }
            catch (IOException)
            {
                Logger.Instance.Write("Failed to open station store from " + fileName);
                return(null);
            }

            Collection <TVStation> stations = new Collection <TVStation>();

            try
            {
                while (!reader.EOF)
                {
                    reader.Read();
                    if (reader.IsStartElement())
                    {
                        switch (reader.Name)
                        {
                        case "Station":
                            if (station != null)
                            {
                                addStation(stations, station);
                            }

                            station = new TVStation("");

                            break;

                        default:
                            if (station != null)
                            {
                                station.load(reader);
                            }
                            break;
                        }
                    }
                }

                if (station != null)
                {
                    addStation(stations, station);
                }
            }
            catch (XmlException e)
            {
                Logger.Instance.Write("Failed to load file " + fileName);
                Logger.Instance.Write("Data exception: " + e.Message);
                stations = null;
            }
            catch (IOException e)
            {
                Logger.Instance.Write("Failed to load file " + fileName);
                Logger.Instance.Write("I/O exception: " + e.Message);
                stations = null;
            }

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

            return(stations);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Load the station collection from an XML file.
        /// </summary>
        /// <param name="fileName">The full name of the xml file.</param>
        /// <returns>A collection of stations or null if the file cannot be opened.</returns>
        public static Collection<TVStation> Load(string fileName)
        {
            TVStation station = null;
            XmlReader reader = null;

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

            try
            {
                reader = XmlReader.Create(fileName, settings);
            }
            catch (IOException)
            {
                Logger.Instance.Write("Failed to open station store from " + fileName);
                return (null);
            }

            Collection<TVStation> stations = new Collection<TVStation>();

            try
            {
                while (!reader.EOF)
                {
                    reader.Read();
                    if (reader.IsStartElement())
                    {
                        switch (reader.Name)
                        {
                            case "Station":
                                if (station != null)
                                    addStation(stations, station);

                                station = new TVStation("");

                                break;
                            default:
                                if (station != null)
                                    station.load(reader);
                                break;
                        }
                    }
                }

                if (station != null)
                    addStation(stations, station);
            }
            catch (XmlException e)
            {
                Logger.Instance.Write("Failed to load file " + fileName);
                Logger.Instance.Write("Data exception: " + e.Message);
                stations = null;
            }
            catch (IOException e)
            {
                Logger.Instance.Write("Failed to load file " + fileName);
                Logger.Instance.Write("I/O exception: " + e.Message);
                stations = null;
            }

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

            return (stations);
        }