예제 #1
0
        private void LoadConnectionOptions()
        {
            Dictionary <String, ConnectionProtocolOption> options = GetConnectionOptionsDictionary(_connectionSettingsID);

            var defSett = _protocol.GetProtocolSettings();

            foreach (KeyValuePair <String, ConnectionProtocolOption> kvp in options)
            {
                if (_sessionSettings.ContainsKey(kvp.Key))
                {
                    var sett = defSett[kvp.Key];
                    var a    = new ProtocolSetting(kvp.Key, sett.GetTitle(), sett.GetDescription(), sett.GetDataType());
                    if (sett.GetDataType() == typeof(UserCredential))
                    {
                        var _cred = StorageCore.Core.GetUserCredentials((int)kvp.Value.getSettingvalue());
                        if (_cred != null)
                        {
                            a.Value = new DefinedProtocolSettingValue(sett.GetTitle(), new UserCredentials(_cred.Domain, _cred.Username, Helper.ConvertToUnsecureString(Helper.DecryptStringFromBytes(_cred.Password, Helper.GetHash1(StorageCore.Core.GetUserSalt1()), Encoding.UTF8.GetBytes(StorageCore.Core.GetDatabaseGuid()), StorageCore.Core.GetUserSalt3()))));
                        }
                    }
                    else
                    {
                        a.Value = new DefinedProtocolSettingValue(sett.GetTitle(), kvp.Value.getSettingvalue());
                    }
                    _sessionSettings[kvp.Key] = a;
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Initiate Protocol settings with default values
        /// </summary>
        private void InitiateProtocolSettings()
        {
            _protocolSettings = new SortedList <string, ProtocolSetting>();
            FileInfo _propertyMappingsIniFile = new FileInfo(this.Config.GetDirectory() + "\\mapping.ini");

            if (!_propertyMappingsIniFile.Exists)
            {
                throw new ProtocolConfigurationException(beRemoteExInfoPackage.SignificantInformationPackage, "Could not find mappings file for protocol setting mappings. (FileNotFound: " + _propertyMappingsIniFile.FullName + ")");
            }

            _propertyMappings = new IniFile(_propertyMappingsIniFile);

            foreach (String key in Config.GetSection(IniSection.SETTINGS_CUSTOM).Keys)
            {
                String dataTypeString = _propertyMappings.GetValue(IniSection.SETTINGS_MAPPING_DATATYPES, key);
                bool   multiple       = false;
                if (dataTypeString.ToLower().Contains("multiple"))
                {
                    dataTypeString = dataTypeString.Split(new String[] { ";" }, StringSplitOptions.None)[1];
                    multiple       = true;
                }
                Type dataType;

                if (Type.GetType(dataTypeString) != null)
                {
                    dataType = Type.GetType(dataTypeString, false, true);
                }
                else if (Type.GetType("System." + dataTypeString, false, true) != null)
                {
                    dataType = Type.GetType("System." + dataTypeString, false, true);
                }
                else if (dataTypeString.Contains("credential"))
                {
                    dataType = typeof(UserCredential);
                }
                else
                {
                    throw new TypeAccessException("This System.Type is not known (" + dataTypeString + ")");
                }

                ProtocolSetting ps = new ProtocolSetting(key, _propertyMappings.GetValue(IniSection.SETTINGS_MAPPING_DISPLAYTEXT, key), "description", dataType);
                ps.SetDefaultValue(new DefinedProtocolSettingValue(Config.GetValue(IniSection.SETTINGS_CUSTOM, key) + GetDefinedValueTitle(key), Config.GetValue(IniSection.SETTINGS_CUSTOM, key)));
                if (multiple)
                {
                    String[] definedValues = _propertyMappings.GetValue(IniSection.SETTINGS_MAPPING_DEFINEDVALUES, key).Split(new String[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (String value in definedValues)
                    {
                        DefinedProtocolSettingValue dv = new DefinedProtocolSettingValue(value + GetDefinedValueTitle(key), value);
                        ps.AddDefinedProtocolSettingValue(dv);
                    }
                }

                _protocolSettings.Add(key, ps);
            }
        }