private void MenuItem_Export_Click(object sender, RoutedEventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.FilterIndex = 1; saveFileDialog.Filter = Properties.Resources.ExportFileDialogFilter; saveFileDialog.AddExtension = true; saveFileDialog.DefaultExt = ".xml"; saveFileDialog.OverwritePrompt = true; saveFileDialog.FileName = "AutoHostsUpdateConfig.xml"; bool?result = saveFileDialog.ShowDialog(); if (result == true) { string fileName = saveFileDialog.FileName; LoadRegistryToXmlResources(); XmlResources xmlResources = LoadRegistryToXmlResources(); if (XmlImportExportUtility.XmlSerialize(fileName, xmlResources)) { MessageBox.Show(Properties.Resources.ExportSuccessMessageBoxText, Properties.Resources.MessageBoxTitle, MessageBoxButton.OK, MessageBoxImage.Information); } else { MessageBox.Show(Properties.Resources.ExportErrorMessageBoxText, Properties.Resources.MessageBoxTitle, MessageBoxButton.OK, MessageBoxImage.Error); } } }
private void MenuItem_Import_Click(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.FilterIndex = 1; openFileDialog.Filter = Properties.Resources.ImportFileDialogFilter; openFileDialog.Multiselect = false; bool?result = openFileDialog.ShowDialog(); if (result == true) { string fileName = openFileDialog.FileName; XmlResources xmlResources = XmlImportExportUtility.XmlDeserialize(fileName); if (xmlResources != null) { SaveRegistryFromXmlResources(xmlResources); LoadRegistry(); MessageBox.Show(Properties.Resources.ImportSuccessMessageBoxText, Properties.Resources.MessageBoxTitle, MessageBoxButton.OK, MessageBoxImage.Information); } else { MessageBox.Show(Properties.Resources.ImportErrorMessageBoxText, Properties.Resources.MessageBoxTitle, MessageBoxButton.OK, MessageBoxImage.Error); } } }
/// <summary> /// Configures the mappers. /// </summary> /// <param name="fileName">Name of the file.</param> public static void ConfigureMappers(string fileName) { XmlDocument document = XmlResources.GetFromResource(fileName); if (document == null) { document = XmlResources.GetFromEmbeddedResource(fileName); } ConfigureMappers(document); }
/// <summary> /// Loads from XML. /// </summary> /// <param name="fileName">Name of the file.</param> /// <returns></returns> public bool LoadFromXml(string fileName, string path) { XmlDocument document = XmlResources.GetFromResource(fileName); if (document == null) { return(false); } this.LoadRules(document, path); return(true); }
private void SaveRegistryFromXmlResources(XmlResources xmlResources) { // ExternalHostsTarget RegistryUtility.FRegistrySetValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrExternalHostsTargetRegistryName, xmlResources.ExternalHostsTarget); // InternalHostsTarget RegistryUtility.FRegistrySetValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrInternalHostsTargetRegistryName, xmlResources.InternalHostsTarget); // ApplyInExternalHosts (Enabled) RegistryUtility.FRegistrySetDwordValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrIsApplyInExternalHostsRegistryName, (uint)xmlResources.ApplyInExternalHosts); // UpdateInternalHosts (Enabled) RegistryUtility.FRegistrySetDwordValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrIsUpdateInternalHostsRegistryName, (uint)xmlResources.UpdateInternalHosts); // NetworkAuthentication (Disabled) RegistryUtility.FRegistrySetDwordValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrIsNetworkAuthenticationName, (uint)xmlResources.NetworkAuthentication); // NetworkAuthenticationUsername (Empty) RegistryUtility.FRegistrySetValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrNetworkAuthenticationUsernameName, xmlResources.NetworkUsername); // NetworkAuthenticationPassword (Empty) RegistryUtility.FRegistrySetBinaryValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrNetworkAuthenticationPasswordName, xmlResources.NetworkPassword); }
private XmlResources LoadRegistryToXmlResources() { string internalHostsSaveTarget = RegistryUtility.StrRegistryReadValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrInternalHostsTargetRegistryName); string externalHostsSaveTarget = RegistryUtility.StrRegistryReadValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrExternalHostsTargetRegistryName); string networkAuthenticationUsername = RegistryUtility.StrRegistryReadValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrNetworkAuthenticationUsernameName); byte[] networkAuthenticationPassword = RegistryUtility.RGBRegistryReadBinaryValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrNetworkAuthenticationPasswordName); int isUpdateInternalHosts = 0; int isApplyInExternalHosts = 0; int isNetworkAuthentication = 0; RegistryUtility.FRegistryReadDwordValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrIsUpdateInternalHostsRegistryName, out isUpdateInternalHosts); RegistryUtility.FRegistryReadDwordValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrIsApplyInExternalHostsRegistryName, out isApplyInExternalHosts); RegistryUtility.FRegistryReadDwordValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrIsNetworkAuthenticationName, out isNetworkAuthentication); XmlResources xmlResources = new XmlResources(internalHostsSaveTarget, externalHostsSaveTarget, isUpdateInternalHosts, isApplyInExternalHosts, isNetworkAuthentication, networkAuthenticationUsername, networkAuthenticationPassword); return(xmlResources); }
/// <summary> /// Run the scanning for services, initializing from an xml with the information of the service API. /// </summary> /// <param name="fileName">Name of the file.</param> public static void Initialize(string fileName) { if (string.IsNullOrEmpty(fileName)) { fileName = "Supido.xml"; } XmlDocument document = XmlResources.GetFromResource(fileName); if (document == null) { document = XmlResources.GetFromEmbeddedResource(fileName); } if (document != null) { ConfigureSecurityManager(document); ConfigureService(document); } DiscoverServices(); }
/// <summary> /// Configures the Security Manager from a file. /// </summary> /// <param name="fileName">Name of the file.</param> public virtual void Configure(string fileName) { MetadataContainer metadata = this.GetOpenAccessMetadata(); Dictionary <string, MetaPersistentType> metatables = this.GetMetaTables(metadata); XmlDocument document = null; if (!string.IsNullOrEmpty(fileName)) { document = XmlResources.GetFromResource(fileName); if (document == null) { document = XmlResources.GetFromEmbeddedResource(fileName); } } if (document != null) { ObjectProxyFactory.ConfigureMappers(document); XmlNode rootNode = document.SelectSingleNode("configuration/entities"); if (rootNode != null) { this.ConfigureEntities(rootNode, metatables); } } else { this.Scanner = new SecurityScanner(this); this.Scanner.EntityPreffix = string.Empty; this.Scanner.EntitySuffix = string.Empty; this.Scanner.DtoPreffix = string.Empty; this.Scanner.DtoSuffix = "Dto"; this.Scanner.FilterPreffix = string.Empty; this.Scanner.FilterSuffix = "Filter"; this.Scanner.BOPreffix = string.Empty; this.Scanner.BOSuffix = "BO"; this.Scanner.Metatables = metatables; this.Scanner.ScanNamespace(string.Empty); } }