public static void LoadWSOFile(string filePath, MainViewModel viewModel)
		{
			// Load user's current options and make a copy.
			BuildModel(viewModel, false);

			IVisitorWithContext visitor = new XmlReadVisitor();
			UIOptionRootType optionsRoot = new UIOptionRootType();
			optionsRoot.Accept(visitor, filePath);

			foreach (var cat in optionsRoot.Categories)
			{
				foreach (var subCat in cat.SubCategories)
				{
					foreach (var opt in subCat.Options)
					{
						if (opt is UIOptionGroupType)
						{
							LoadGroup(viewModel, opt);
						}
						IOption targetOpt = viewModel.FindOption(opt.Name);
						if (targetOpt != null)
						{
							LoadOption(targetOpt, opt);
						}
					}
				}
			}

			// We need to pass the OptionsRoot object to somebody who can display it in UI
		}
示例#2
0
		/// <summary>
		/// 	Load option model from default xml
		/// </summary>
		/// <param name = "optRoot"></param>
		public static UIOptionRootType DefaultXmlToOptionModel()
		{
			IVisitorWithContext readVisitor = new DefaultXmlReadVisitor();
			UIOptionRootType optionsRoot = new UIOptionRootType();

			using (Stream s = GetDefaultXml())
			{
				optionsRoot.Accept(readVisitor, s);
			}

			return optionsRoot;
		}
示例#3
0
        void IVisitor.Visit(UIOptionRootType optionsRoot)
        {
            try
            {
                OptionApi.AdminEnter();

				using (UserReadVisitor uservisitor = new UserReadVisitor())
				{
                optionsRoot.Accept(uservisitor);
            }
			}
            finally
            {
                OptionApi.AdminExit();
            }
        }
示例#4
0
		public void TestXmlReader()
		{
			IVisitorWithContext readVisitor = new XmlReadVisitor();
			UIOptionRootType optionsRoot = new UIOptionRootType();
			optionsRoot.Accept(readVisitor, _xmlInputPath);

			Assert.AreEqual(3, optionsRoot.Categories.Count);
			Assert.AreEqual(3, optionsRoot.Categories[0].SubCategories.Count);
			Assert.AreEqual(3, optionsRoot.Categories[1].SubCategories.Count);
			Assert.AreEqual(3, optionsRoot.Categories[2].SubCategories.Count);

			Assert.AreEqual(24, optionsRoot.Categories[0].SubCategories[0].Options.Count);
			Assert.AreEqual(2, optionsRoot.Categories[0].SubCategories[1].Options.Count);
			Assert.AreEqual(2, optionsRoot.Categories[0].SubCategories[2].Options.Count);
			Assert.AreEqual(2, optionsRoot.Categories[1].SubCategories[0].Options.Count);
			Assert.AreEqual(3, optionsRoot.Categories[1].SubCategories[1].Options.Count);
			Assert.AreEqual(2, optionsRoot.Categories[1].SubCategories[2].Options.Count);
			Assert.AreEqual(2, optionsRoot.Categories[2].SubCategories[0].Options.Count);
			Assert.AreEqual(2, optionsRoot.Categories[2].SubCategories[1].Options.Count);
			Assert.AreEqual(4, optionsRoot.Categories[2].SubCategories[2].Options.Count);
		}
示例#5
0
		public void TestDefaultXmlReader_FromStream()
		{
			IVisitorWithContext readVisitor = new DefaultXmlReadVisitor();
			UIOptionRootType optionsRoot = new UIOptionRootType();

			Stream stream = File.OpenRead(_testFilePath);
			optionsRoot.Accept(readVisitor, stream);

			Assert.AreEqual(3, optionsRoot.Categories.Count);
			Assert.AreEqual(3, optionsRoot.Categories[0].SubCategories.Count);
			Assert.AreEqual(3, optionsRoot.Categories[1].SubCategories.Count);
			Assert.AreEqual(3, optionsRoot.Categories[2].SubCategories.Count);

			Assert.AreEqual(24, optionsRoot.Categories[0].SubCategories[0].Options.Count);
			Assert.AreEqual(2, optionsRoot.Categories[0].SubCategories[1].Options.Count);
			Assert.AreEqual(2, optionsRoot.Categories[0].SubCategories[2].Options.Count);
			Assert.AreEqual(2, optionsRoot.Categories[1].SubCategories[0].Options.Count);
			Assert.AreEqual(3, optionsRoot.Categories[1].SubCategories[1].Options.Count);
			Assert.AreEqual(2, optionsRoot.Categories[1].SubCategories[2].Options.Count);
			Assert.AreEqual(2, optionsRoot.Categories[2].SubCategories[0].Options.Count);
			Assert.AreEqual(2, optionsRoot.Categories[2].SubCategories[1].Options.Count);
			Assert.AreEqual(4, optionsRoot.Categories[2].SubCategories[2].Options.Count);
		}
示例#6
0
		public static void UIModelToOptionModel(UIOptionRootType optionsRoot, MainViewModel model, bool bTrimUnchanged,
		                                        bool bDeploymentIconOnly = false)
		{
			IVisitorWithContext ctxVisitor = new ViewModelToOptionModelVisitor(bTrimUnchanged, bDeploymentIconOnly);
			optionsRoot.Accept(ctxVisitor, model);
		}