public void XmlDocFilenameReturnsValue()
        {
            string fileName         = "Core\\guilib\\TestData\\MediaPortal.xml";
            XmlSettingsProvider doc = new XmlSettingsProvider(fileName);

            Assert.AreEqual(fileName, doc.FileName);
        }
Exemplo n.º 2
0
        static ISettingsProvider GetXmlProvider()
        {
            var storage  = new FileStreamStorageProvider("config.xml");
            var provider = new XmlSettingsProvider(storage);

            return(provider);
        }
        public void XmlDocGetValueReturnsValue()
        {
            XmlSettingsProvider doc = CreateDoc();

            string ret = (string)doc.GetValue("capture", "country");

            Assert.AreEqual("31", ret);
        }
        public void XmlDocSetValueSetsValue()
        {
            XmlSettingsProvider doc = CreateDoc();

            int prerecord = Convert.ToInt32(doc.GetValue("capture", "prerecord"));

            doc.SetValue("capture", "prerecord", prerecord + 1);
            Assert.AreEqual(prerecord + 1, Convert.ToInt32(doc.GetValue("capture", "prerecord")));
        }
        public void XmlDocRemoveEntryRemovesEntry()
        {
            XmlSettingsProvider doc = CreateDoc();

            //Make sure entry exists
            Assert.IsNotNull(doc.GetValue("capture", "postrecord"));

            doc.RemoveEntry("capture", "postrecord");

            Assert.IsNull(doc.GetValue("capture", "postrecord"));
        }
Exemplo n.º 6
0
 public static ConfigurationServiceBuilder AddXml <TSettings>(this ConfigurationServiceBuilder builder,
                                                              string path,
                                                              Action <IServiceProvider, SettingsProviderOptions> configure)
     where TSettings : class, new()
 => AddProvider(builder, serviceProvider =>
 {
     var settingsProviderOptions = new SettingsProviderOptions();
     configure?.Invoke(serviceProvider, settingsProviderOptions);
     var provider = new XmlSettingsProvider <TSettings>(settingsProviderOptions, path);
     return(provider);
 });
Exemplo n.º 7
0
        public static SettingsProviderDictionary AddXml <TSettings>(this SettingsProviderDictionary providers, string path, Action <SettingsProviderOptions> configure = null)
            where TSettings : class, new()
        {
            if (providers == null)
            {
                throw new ArgumentNullException(nameof(providers));
            }

            var options = new SettingsProviderOptions();

            configure?.Invoke(options);

            var provider = new XmlSettingsProvider <TSettings>(options, path);

            providers.Add(provider);

            return(providers);
        }
Exemplo n.º 8
0
        public void Prefetch1()
        {
            string xml =
                @"<?xml version=""1.0"" encoding=""utf-8""?>
<profile>
  <section name=""capture"">
    <entry name=""tuner"">Cable</entry>
  </section>
</profile>
";

            using (TextWriter writer = File.CreateText("prefetchtest.xml"))
            {
                writer.Write(xml);
            }

            XmlSettingsProvider provider = new XmlSettingsProvider("prefetchtest.xml");

            provider.Prefetch(this.Remember);

            Assert.AreEqual("capture", rememberedSettings[0][0]);
            Assert.AreEqual("tuner", rememberedSettings[0][1]);
            Assert.AreEqual("Cable", rememberedSettings[0][2]);
        }
Exemplo n.º 9
0
        public Startup(string[] arguments)
        {
            Thread.CurrentThread.Name     = "Config Main";
            Thread.CurrentThread.Priority = ThreadPriority.AboveNormal;

            // Logger should write into Configuration.log
            Log.SetConfigurationMode();
            Log.BackupLogFile(LogType.Config);

            FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(Application.ExecutablePath);

            Log.Info("Configuration v" + versionInfo.FileVersion + " is starting up on " + OSInfo.OSInfo.GetOSDisplayVersion());
#if DEBUG
            Log.Info("Debug build: " + Application.ProductVersion);
#else
            Log.Info("Build: " + Application.ProductVersion);
#endif

            //Check for unsupported operating systems
            OSPrerequisites.OSPrerequisites.OsCheck(true);

            Log.Info("Verifying DirectX 9");
            if (!DirectXCheck.IsInstalled())
            {
                string strLine = "Please install a newer DirectX 9.0c redist!\r\n";
                strLine = strLine + "MediaPortal cannot run without DirectX 9.0c redist (August 2008)\r\n";
                strLine = strLine + "http://install.team-mediaportal.com/DirectX";
                MessageBox.Show(strLine, "MediaPortal", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            Log.Info("Using Directories:");
            foreach (string options in Enum.GetNames(typeof(Config.Dir)))
            {
                Log.Info("{0} - {1}", options, Config.GetFolder((Config.Dir)Enum.Parse(typeof(Config.Dir), options)));
            }

            // rtv: disabled Wizard due to frequent bug reports on serveral sections.
            // please fix those before re-enabling.
            //
            //if (!File.Exists(Config.GetFile(Config.Dir.Config, "mediaportal.xml")))
            //  startupMode = StartupMode.Wizard;
            //else
            if (arguments != null)
            {
                foreach (string argument in arguments)
                {
                    string trimmedArgument = argument.ToLower();

                    if (trimmedArgument.StartsWith("/wizard"))
                    {
                        //startupMode = StartupMode.Wizard;
                        //Log.Debug("Startup: Argument did request Wizard mode - {0}", trimmedArgument);
                        Log.Warn("Startup: Wizard mode invoked but currently disabled: argument ignored!");
                    }

                    if (trimmedArgument.StartsWith("/section"))
                    {
                        string[] subArguments = argument.Split('=');

                        if (subArguments.Length >= 2)
                        {
                            sectionsConfiguration = subArguments[1];
                        }
                    }

                    //  deploymode used to upgrade the configuration files
                    if (trimmedArgument == "--deploymode")
                    {
                        Log.Info("Running in deploy mode - upgrading config file");

                        try
                        {
                            ISettingsProvider mpConfig = new XmlSettingsProvider(MPSettings.ConfigPathName);
                            SettingsUpgradeManager.Instance.UpgradeToLatest(mpConfig);
                        }
                        catch (Exception ex)
                        {
                            Log.Error("Unhandled exception when upgrading config file '" + MPSettings.ConfigPathName + "'\r\n\r\n" + ex.ToString());
                        }
                        finally
                        {
                            _preventGUILaunch = true;
                        }
                    }

                    if (trimmedArgument == "/debugoptions")
                    {
                        _debugOptions = true;
                    }

                    if (trimmedArgument.ToLowerInvariant() == "/avoidversioncheck")
                    {
                        _avoidVersionChecking = true;
                        Log.Warn("Version check is disabled by command line switch \"/avoidVersionCheck\"");
                    }
                }
            }
        }
		public void MultipleEntriesXmlHasExpectedValue(string key, string value)
		{
			var provider = new XmlSettingsProvider("MultipleEntries.xml");

			Assert.Equal(value, provider[key]);
		}
		public void SingleEntriesXmlHasExpectedKeys(string key)
		{
			var provider = new XmlSettingsProvider("MultipleEntries.xml");

			Assert.Contains(key, provider.AllKeys);
		}
		public void MultipleEntriesXmlHasExpectedNumberOfKeys()
		{
			var provider = new XmlSettingsProvider("MultipleEntries.xml");

			Assert.Equal(3, provider.AllKeys.Count());
		}
		public void SingleEntryXmlHasExpectedValue()
		{
			var provider = new XmlSettingsProvider("SingleEntry.xml");

			Assert.Equal("5", provider["Test:Value"]);
		}
		public void SingleEntryXmlHasExpectedKey()
		{
			var provider = new XmlSettingsProvider("SingleEntry.xml");

			Assert.Contains("Test:Value", provider.AllKeys);
		}
		public void SingleEntryXmlHasExpectedNumberOfKeys()
		{
			var provider = new XmlSettingsProvider("SingleEntry.xml");

			Assert.Equal(1, provider.AllKeys.Count());
		}