Ejemplo n.º 1
0
 /// <summary>
 /// Reset the engines.
 /// </summary>
 public void Clear()
 {
     _engines               = new SearchEngines();
     _engines.Engines       = new List <SearchEngine>();
     validationErrorOccured = false;
     enginesLoaded          = true;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Reset the engines.
 /// </summary>
 public void Clear()
 {
     _engines                = new SearchEngines();
     _engines.Engines        = new ArrayList();
     _engines.NewTabRequired = true;
     validationErrorOccured  = false;
     enginesLoaded           = true;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads the search engines list from the given URL.
        /// </summary>
        /// <param name="configUrl">The URL of the engines config</param>
        /// <param name="veh">The event handler that should be invoked on the client if validation errors occur</param>
        /// <exception cref="XmlException">XmlException thrown if XML is not well-formed</exception>
        public void LoadEngines(string configUrl, ValidationEventHandler veh)
        {
            XmlDocument doc = new XmlDocument();

            XmlReaderSettings settings = new XmlReaderSettings();

            settings.ValidationType = ValidationType.Schema;
            settings.Schemas.Add(searchConfigSchema);
            //specify validation event handler passed by caller and the one we use
            //internally to track state
            if (veh != null)
            {
                settings.ValidationEventHandler += veh;
            }
            settings.ValidationEventHandler += LoaderValidationCallback;
            validationErrorOccured           = false;
            enginesLoaded = false;

            XmlReader vr = XmlReader.Create(new XmlTextReader(configUrl), settings);

            doc.Load(vr);
            vr.Close();

            if (!validationErrorOccured)
            {
                //convert XML to objects
                XmlNodeReader reader          = new XmlNodeReader(doc);
                XmlSerializer serializer      = XmlHelper.SerializerCache.GetSerializer(typeof(SearchEngines));
                SearchEngines mySearchEngines = (SearchEngines)serializer.Deserialize(reader);
                reader.Close();

                _engines      = mySearchEngines;
                enginesLoaded = true;

                if (this.RepairedPhrasePlaceholders())
                {
                    using (Stream stream = FileHelper.OpenForWrite(configUrl)) {
                        this.SaveEngines(stream);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Loads the search engines list from the given URL.
        /// </summary>
        /// <param name="configStream">The Stream of the engines config</param>
        /// <exception cref="Exception">Exception thrown on file access errors</exception>
        public void SaveEngines(Stream configStream)
        {
            XmlSerializer serializer = XmlHelper.SerializerCache.GetSerializer(typeof(SearchEngines));

            if (_engines != null)
            {
                if (_engines.Engines == null)
                {
                    _engines.Engines = new List <SearchEngine>();
                }
            }            //if(_engines != null)
            else
            {
                _engines = new SearchEngines();
            }

            TextWriter writer = new StreamWriter(configStream);

            serializer.Serialize(writer, _engines);
            writer.Flush();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Loads the search engines list from the given URL.
        /// </summary>
        /// <param name="configUrl">The Stream of the engines config</param>
        /// <exception cref="Exception">Exception thrown on file access errors</exception>
        public void SaveEngines(Stream configUrl)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(SearchEngines));


            if (_engines != null)
            {
                if (_engines.Engines == null)
                {
                    _engines.Engines = new ArrayList();
                }
            }            //if(_engines != null)
            else
            {
                _engines = new SearchEngines();
            }

            TextWriter writer = new StreamWriter(configUrl);

            serializer.Serialize(writer, _engines);
            writer.Close();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Loads the search engines list from the given URL.
        /// </summary>
        /// <param name="configUrl">The URL of the engines config</param>
        /// <param name="veh">The event handler that should be invoked on the client if validation errors occur</param>
        /// <exception cref="XmlException">XmlException thrown if XML is not well-formed</exception>
        public void LoadEngines(string configUrl, ValidationEventHandler veh)
        {
            XmlDocument         doc = new XmlDocument();
            XmlValidatingReader vr  = new XmlValidatingReader(new XmlTextReader(configUrl));

            vr.Schemas.Add(searchConfigSchema);
            vr.ValidationType = ValidationType.Schema;

            //specify validation event handler passed by caller and the one we use
            //internally to track state
            vr.ValidationEventHandler += veh;
            vr.ValidationEventHandler += new ValidationEventHandler(LoaderValidationCallback);
            validationErrorOccured     = false;
            enginesLoaded              = false;

            doc.Load(vr);
            vr.Close();

            if (!validationErrorOccured)
            {
                //convert XML to objects
                XmlNodeReader reader          = new XmlNodeReader(doc);
                XmlSerializer serializer      = new XmlSerializer(typeof(SearchEngines));
                SearchEngines mySearchEngines = (SearchEngines)serializer.Deserialize(reader);
                reader.Close();

                _engines      = mySearchEngines;
                enginesLoaded = true;

                if (this.RepairedPhrasePlaceholders())
                {
                    using (Stream stream = RssComponents.FileUtils.OpenForWrite(configUrl)) {
                        this.SaveEngines(stream);
                    }
                }
            }
        }