/// <summary>
 /// Loads StreamSources from a specified file.
 /// </summary>
 /// <param name="fileName">The filename to load. If you are trying to load multiple distinct files, set bypassCache to true.</param>
 /// <param name="bypassCache">
 /// Set to true to always read from the disk and return a distinct copy
 /// Set to false to use the cached copy if available.
 /// </param>
 /// <returns>the StreamSources from the indicated file</returns>
 public static SourceDiscoveryConfiguration LoadFromFile(string fileName, bool bypassCache)
 {
     if ((_configuration == null) || bypassCache)
     {
         FileStream file = null;
         try
         {
             XmlSerializer serializer = new XmlSerializer(typeof(SourceDiscoveryConfiguration));
             file = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
             SourceDiscoveryConfiguration s = (SourceDiscoveryConfiguration)serializer.Deserialize(file);
             if (bypassCache)
             {
                 return(s);
             }
             else
             {
                 _configuration = s;
             }
         }
         finally
         {
             if (file != null)
             {
                 file.Close();
                 file.Dispose();
             }
         }
     }
     return(_configuration);
 }
        /// <summary>
        /// Writes a <see cref="StreamSources"/> collection to disk at the <see cref="P:PersistFileName"/> location.
        /// </summary>
        /// <param name="sources">sources to write</param>
        public static void SaveToFile(SourceDiscoveryConfiguration configuration)
        {
            FileStream file = null;

            try
            {
                XmlSerializer xmlSerializer = new XmlSerializer(configuration.GetType());
                file = new FileStream(PersistFileName, FileMode.Create, FileAccess.Write, FileShare.None);
                xmlSerializer.Serialize(file, configuration);
            }
            finally
            {
                if (file != null)
                {
                    file.Close();
                    file.Dispose();
                }
            }
        }
        private void CreateTestConfig()
        {
            FileStream             file       = null;
            DataContractSerializer serializer = new DataContractSerializer(typeof(SourceDiscoveryConfiguration),
                                                                           new List <Type> {
                typeof(SourceDiscoveryDefinition)
            });
            String fileName = @"C:\Temp\test.xml";

            file = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write, FileShare.ReadWrite);
            SourceDiscoveryDefinition testdef = new SourceDiscoveryDefinition();

            testdef.Name         = "Dave";
            testdef.Type         = "roogy";
            testdef.URL          = "floor";
            testdef.PollInterval = 30000;
            SourceDiscoveryConfiguration testconfig = new SourceDiscoveryConfiguration();

            testconfig.Items = new List <SourceDiscoveryDefinition>();
            testconfig.Items.Add(testdef);
            serializer.WriteObject(file, testconfig);
            file.Close();
        }