예제 #1
0
            public IConfigurationSettingItem Parse(XmlNode node)
            {
                var setting  = new RegistryInstanceSetting();
                var rootKey  = node.GetAttributeValue("rootKey");
                var subKey   = node.GetAttributeValue("subKey");
                var valueKey = node.GetAttributeValue("valueKey");

                return(Parse(rootKey, subKey, valueKey));
            }
예제 #2
0
            public IConfigurationSettingItem Parse(IConfiguration configuration)
            {
                var setting  = new RegistryInstanceSetting();
                var rootKey  = configuration.GetSection("rootKey").Value;
                var subKey   = configuration.GetSection("subKey").Value;
                var valueKey = configuration.GetSection("valueKey").Value;

                return(Parse(rootKey, subKey, valueKey));
            }
예제 #3
0
            private IConfigurationSettingItem Parse(string rootKey, string subKey, string valueKey)
            {
                var setting = new RegistryInstanceSetting
                {
                    RootKey  = rootKey,
                    SubKey   = subKey,
                    ValueKey = valueKey
                };

                if (string.IsNullOrEmpty(setting.RootKey) ||
                    string.IsNullOrEmpty(setting.SubKey) ||
                    string.IsNullOrEmpty(setting.ValueKey))
                {
                    ThrowRegistryInvalid();
                }

                var regRoot = GetRootKey(setting.RootKey);

                if (regRoot == null)
                {
                    ThrowRegistryInvalid();
                }

                var srKey = regRoot.OpenSubKey(setting.SubKey);

                if (srKey == null)
                {
                    ThrowRegistryInvalid();
                }

                var regData = srKey.GetValue(setting.ValueKey);

                srKey.Close();
                Guard.NullReference(regData, "regData");

                if (ParseRegistryData(setting, regData))
                {
                    return(setting);
                }

                return(null);
            }
예제 #4
0
            public IConfigurationSettingItem Parse(XmlNode node)
            {
                var setting = new RegistryInstanceSetting();

                setting.Name     = node.GetAttributeValue("name");
                setting.RootKey  = node.GetAttributeValue("rootKey");
                setting.SubKey   = node.GetAttributeValue("subKey");
                setting.ValueKey = node.GetAttributeValue("valueKey");

                if (string.IsNullOrEmpty(setting.RootKey) ||
                    string.IsNullOrEmpty(setting.SubKey) ||
                    string.IsNullOrEmpty(setting.ValueKey))
                {
                    ThrowRegistryInvalid();
                }
                var regRoot = GetRootKey(setting.RootKey);

                if (regRoot == null)
                {
                    ThrowRegistryInvalid();
                }

                var srKey = regRoot.OpenSubKey(setting.SubKey);

                if (srKey == null)
                {
                    ThrowRegistryInvalid();
                }
                var regData = srKey.GetValue(setting.ValueKey);

                srKey.Close();
                Guard.NullReference(regData, "regData");

                if (ParseRegistryData(setting, regData))
                {
                    return(setting);
                }
                return(null);
            }
예제 #5
0
            private bool ParseRegistryData(RegistryInstanceSetting setting, object data)
            {
                if (data is byte[] bytes)
                {
                    try
                    {
                        //反序列化
                        //var header = new SerializeHeader { HeaderBytes = Encoding.ASCII.GetBytes(Name) };
                        var store = new BinaryCompressSerializer().Deserialize <BinaryConnectionStore>(bytes);
                        if (store != null)
                        {
                            if (!string.IsNullOrEmpty(store.DatabaseType))
                            {
                                setting.DatabaseType = Type.GetType(store.DatabaseType, false, true);
                            }

                            setting.ProviderType     = store.ProviderType;
                            setting.ConnectionString = ConnectionStringHelper.GetConnectionString(store.ConnectionString);
                            return(true);
                        }
                    }
                    catch
                    {
                        throw new InvalidOperationException(SR.GetString(SRKind.FailInDataParse));
                    }
                }
                else if (data is string)
                {
                    var con = new ConnectionString(data.ToString());
                    setting.ProviderType     = con.ProviderType;
                    setting.DatabaseType     = Type.GetType(con.DatabaseType, false, true);
                    setting.ConnectionString = con.ToString();
                    return(true);
                }

                return(false);
            }