/// <summary> /// <para>Initializes the provider with a <see cref="ConfigurationView"/>.</para> /// </summary> /// <param name="configurationView"> /// <para>A <see cref="ConfigurationView"/> object.</para> /// </param> /// <remarks> /// <para>The method expects a <see cref="RuntimeConfigurationView"/> object for the <paramref name="configurationView"/></para> /// </remarks> public override void Initialize(ConfigurationView configurationView) { ArgumentValidation.CheckForNullReference(configurationView, "configurationView"); runtimeConfigurationView = GetStorageCursor(configurationView); GetFileKeyAlgorithmPairStorageProviderData(); }
public void CreateTransformer() { XmlSerializerTransformer xmlTransformer = new XmlSerializerTransformer(); // just a fake out to test the transformer RuntimeConfigurationView configurationView = new RuntimeConfigurationView(Context); xmlTransformer.CurrentSectionName = "ApplConfig1"; xmlTransformer.Initialize(configurationView); transformer = xmlTransformer; }
private void SetCurrentDirectory(RuntimeConfigurationView RuntimeConfigurationView) { if (RuntimeConfigurationView.ConfigurationFile.Length == 0) { this.currentDirectory = AppDomain.CurrentDomain.BaseDirectory; } else { this.currentDirectory = Path.GetDirectoryName(RuntimeConfigurationView.ConfigurationFile); } }
public void CannotInvokeNonPublicMethodWhenCallsMadeDirectly() { ReflectionPermission permission = new ReflectionPermission(ReflectionPermissionFlag.TypeInformation); permission.Deny(); XmlIncludeTypeDataCollection xmlIncludeTypes = new XmlIncludeTypeDataCollection(); xmlIncludeTypes.Add(new XmlIncludeTypeData("shouldNotBeAccessible", typeof(TestingInternal.ShouldNotBeAccessible).AssemblyQualifiedName)); RuntimeConfigurationView view = new RuntimeConfigurationView(new ConfigurationContext(new ConfigurationDictionary())); Type [] collectedTypes = view.CollectTypes(xmlIncludeTypes); Assert.AreEqual(1, collectedTypes.Length); }
public void InitializeTest() { ConfigurationSettings settings = GetConfigurationSettings(XmlString); ConfigurationSectionData sectionData = settings.ConfigurationSections[applConfig1]; XmlFileStorageProviderData providerData = (XmlFileStorageProviderData)sectionData.StorageProvider; providerData.SectionName = applConfig1; XmlFileStorageProvider provider = new XmlFileStorageProvider(); provider.CurrentSectionName = applConfig1; RuntimeConfigurationView configurationView = new RuntimeConfigurationView(context); provider.Initialize(configurationView); }
public void CannotInvokeNonPublicMethodWhenCallsMadeThroughReflection() { ReflectionPermission permission = new ReflectionPermission(ReflectionPermissionFlag.TypeInformation); permission.Deny(); XmlIncludeTypeDataCollection xmlIncludeTypes = new XmlIncludeTypeDataCollection(); xmlIncludeTypes.Add(new XmlIncludeTypeData("shouldNotBeAccessible", typeof(TestingInternal.ShouldNotBeAccessible).AssemblyQualifiedName)); RuntimeConfigurationView view = new RuntimeConfigurationView(new ConfigurationContext(new ConfigurationDictionary())); MethodInfo collectTypes = view.GetType().GetMethod("CollectTypes", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] { typeof(XmlIncludeTypeDataCollection)}, null); object returnedTypes = collectTypes.Invoke(view, new object[] { xmlIncludeTypes }); Type [] collectedTypes = returnedTypes as Type[]; Assert.AreEqual(1, collectedTypes.Length); }
public void CannotInvokeNonPublicMethodWhenCallsMadeDirectly() { ReflectionPermission permission = new ReflectionPermission(ReflectionPermissionFlag.TypeInformation); permission.Deny(); XmlIncludeTypeDataCollection xmlIncludeTypes = new XmlIncludeTypeDataCollection(); xmlIncludeTypes.Add(new XmlIncludeTypeData("shouldNotBeAccessible", typeof(TestingInternal.ShouldNotBeAccessible).AssemblyQualifiedName)); RuntimeConfigurationView view = new RuntimeConfigurationView(new ConfigurationContext(new ConfigurationDictionary())); Type [] collectedTypes = view.CollectTypes(xmlIncludeTypes); Assert.AreEqual(1, collectedTypes.Length); }
public void CannotInvokeNonPublicMethodWhenCallsMadeThroughReflection() { ReflectionPermission permission = new ReflectionPermission(ReflectionPermissionFlag.TypeInformation); permission.Deny(); XmlIncludeTypeDataCollection xmlIncludeTypes = new XmlIncludeTypeDataCollection(); xmlIncludeTypes.Add(new XmlIncludeTypeData("shouldNotBeAccessible", typeof(TestingInternal.ShouldNotBeAccessible).AssemblyQualifiedName)); RuntimeConfigurationView view = new RuntimeConfigurationView(new ConfigurationContext(new ConfigurationDictionary())); MethodInfo collectTypes = view.GetType().GetMethod("CollectTypes", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] { typeof(XmlIncludeTypeDataCollection) }, null); object returnedTypes = collectTypes.Invoke(view, new object[] { xmlIncludeTypes }); Type [] collectedTypes = returnedTypes as Type[]; Assert.AreEqual(1, collectedTypes.Length); }
private void SaveAndLoad(RuntimeConfigurationView configurationView) { FileKeyAlgorithmPairStorageProvider provider = new FileKeyAlgorithmPairStorageProvider(); provider.Initialize(configurationView); provider.Save(DefaultKey); KeyAlgorithmPair key = provider.Load(); Assert.IsNotNull(key); Assert.AreEqual(DefaultKey.AlgorithmTypeName, key.AlgorithmTypeName); Assert.IsTrue(CryptographyUtility.CompareBytes(DefaultKey.Key, key.Key)); FileKeyAlgorithmPairStorageProviderData data = (FileKeyAlgorithmPairStorageProviderData)configurationView.GetKeyAlgorithmPairStorageProviderData(); // If protected, ensure it's protected properly if (null != data.DpapiSettings) { using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { BinaryFormatter formatter = new BinaryFormatter(); bool deserialized = true; try { KeyAlgorithmPair deserializedKey = (KeyAlgorithmPair)formatter.Deserialize(fs); Assert.IsNotNull(deserializedKey); } catch { deserialized = false; } // Shouldn't deserialize if it's DPAPI protected Assert.IsFalse(deserialized); } } }
public void ReadAndWriteToEncryptedConfiguration() { const string sectionName = "MyEncryptedConfig"; KeyAlgorithmPair keyAlgorithmPair = new KeyAlgorithmPair(); keyAlgorithmPair.Key = new SymmetricAlgorithmKeyCreator(typeof(RijndaelManaged).AssemblyQualifiedName).GenerateKey(); keyAlgorithmPair.AlgorithmTypeName = typeof(RijndaelManaged).AssemblyQualifiedName; FileKeyAlgorithmPairStorageProvider provider = new FileKeyAlgorithmPairStorageProvider(); provider.ConfigurationName = "FileKeyAlgorithmPairStorageProviderData"; using (ConfigurationBuilder builder = new ConfigurationBuilder()) { // change wher the file is RuntimeConfigurationView view = new RuntimeConfigurationView(new ConfigurationContext(new NonDisposingWrapper(builder))); FileKeyAlgorithmPairStorageProviderData fileData = (FileKeyAlgorithmPairStorageProviderData)view.GetKeyAlgorithmPairStorageProviderData(); fileData.Path = Path.GetTempFileName(); provider.Initialize(view); provider.Save(keyAlgorithmPair); builder.WriteConfiguration(sectionName, data); MockConfigurationData myData = (MockConfigurationData)builder.ReadConfiguration(sectionName); Assert.AreEqual(myData.ToString(), data.ToString()); builder.ClearSectionCache(); myData = (MockConfigurationData)builder.ReadConfiguration(sectionName); Assert.AreEqual(myData.ToString(), data.ToString()); } }
public void CreateTransformer() { XmlSerializerTransformer xmlTransformer = new XmlSerializerTransformer(); // just a fake out to test the transformer RuntimeConfigurationView configurationView = new RuntimeConfigurationView(Context); xmlTransformer.CurrentSectionName = "ApplConfig1"; xmlTransformer.Initialize(configurationView); transformer = xmlTransformer; }
private void SetCurrentDirectory(RuntimeConfigurationView RuntimeConfigurationView) { if (RuntimeConfigurationView.ConfigurationFile.Length == 0) { this.currentDirectory = AppDomain.CurrentDomain.BaseDirectory; } else { this.currentDirectory = Path.GetDirectoryName(RuntimeConfigurationView.ConfigurationFile); } }
internal void AddDeployResources(object input) { //TODO 1018 Move code to show the settings tab to it's own button const string tabName = "Settings"; FrameworkElement tab = FindTabByName(tabName); if (tab != null) { SetActiveDocument(tab); } else { RuntimeConfigurationView runtimeConfigurationView = new RuntimeConfigurationView() { DataContext = new RuntimeConfigurationViewModel(((IEnvironmentModel)input)) }; AttachedPropertyHelper.SetAttachedProperties(runtimeConfigurationView, tabName); Tabs.Add(runtimeConfigurationView); SetActiveDocument(runtimeConfigurationView); } //const string tabName = "Deploy Resources"; //FrameworkElement tab = FindTabByName(tabName); //if (tab != null) //{ // SetActiveDocument(tab); // Mediator.SendMessage(MediatorMessages.SelectItemInDeploy, input); //} //else //{ // var view = new DeployView { DataContext = DeployViewModelFactory.GetDeployViewModel(input) }; // AttachedPropertyHelper.SetAttachedProperties(view, tabName); // Tabs.Add(view); // SetActiveDocument(view); //} }
public void InitializeTest() { ConfigurationSettings settings = GetConfigurationSettings(XmlString); ConfigurationSectionData sectionData = settings.ConfigurationSections[applConfig1]; XmlFileStorageProviderData providerData = (XmlFileStorageProviderData)sectionData.StorageProvider; providerData.SectionName = applConfig1; XmlFileStorageProvider provider = new XmlFileStorageProvider(); provider.CurrentSectionName = applConfig1; RuntimeConfigurationView configurationView = new RuntimeConfigurationView(context); provider.Initialize(configurationView); }
public static void SetAttachedProperties(RuntimeConfigurationView view, string tabName) { UIElementTabActionContext.SetTabActionContext(view, WorkSurfaceContext.Settings); UIElementTitleProperty.SetTitle(view, tabName); UIElementImageProperty.SetImage(view, "/images/database_save.png"); }
private void GetStorageCursor(ConfigurationView configurationView) { ArgumentValidation.CheckExpectedType(configurationView, typeof(RuntimeConfigurationView)); runtimeConfigurationView = (RuntimeConfigurationView)configurationView; }
private void SaveAndLoad(RuntimeConfigurationView configurationView) { FileKeyAlgorithmPairStorageProvider provider = new FileKeyAlgorithmPairStorageProvider(); provider.Initialize(configurationView); provider.Save(DefaultKey); KeyAlgorithmPair key = provider.Load(); Assert.IsNotNull(key); Assert.AreEqual(DefaultKey.AlgorithmTypeName, key.AlgorithmTypeName); Assert.IsTrue(CryptographyUtility.CompareBytes(DefaultKey.Key, key.Key)); FileKeyAlgorithmPairStorageProviderData data = (FileKeyAlgorithmPairStorageProviderData)configurationView.GetKeyAlgorithmPairStorageProviderData(); // If protected, ensure it's protected properly if (null != data.DpapiSettings) { using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { BinaryFormatter formatter = new BinaryFormatter(); bool deserialized = true; try { KeyAlgorithmPair deserializedKey = (KeyAlgorithmPair)formatter.Deserialize(fs); Assert.IsNotNull(deserializedKey); } catch { deserialized = false; } // Shouldn't deserialize if it's DPAPI protected Assert.IsFalse(deserialized); } } }
public static void SetAttachedProperties(RuntimeConfigurationView view, string tabName) { UIElementTabActionContext.SetTabActionContext(view, WorkSurfaceContext.Settings); UIElementTitleProperty.SetTitle(view, tabName); UIElementImageProperty.SetImage(view, "/images/database_save.png"); }
private void GetStorageCursor(ConfigurationView configurationView) { ArgumentValidation.CheckExpectedType(configurationView, typeof(RuntimeConfigurationView)); runtimeConfigurationView = (RuntimeConfigurationView)configurationView; }