예제 #1
0
        private void ApplyViewToDocument_DictionarySettings(ObfuscationConfiguration obfuscationConfiguration)
        {
            if ((object)obfuscationConfiguration == null)
            {
                throw new ArgumentNullException("obfuscationConfiguration");
            }

            foreach (IDictionarySpecListView dictionarySpecView in this.View.ObfuscationPartialView.DictionarySettingsPartialView.DictionarySpecListViews)
            {
                DictionaryConfiguration dictionaryConfiguration;

                //if ((object)dictionarySpecView.DictionaryAdapterSettingsPartialView.CurrentAdapterSpecificSettingsPartialView != null)
                //dictionarySpecView.DictionaryAdapterSettingsPartialView.CurrentAdapterSpecificSettingsPartialView.ApplyViewToDocument(obfuscationConfiguration);

                dictionaryConfiguration = new DictionaryConfiguration()
                {
                    DictionaryId   = dictionarySpecView.DictionaryId,
                    PreloadEnabled = dictionarySpecView.PreloadEnabled,
                    RecordCount    = dictionarySpecView.RecordCount,
                    DictionaryAdapterConfiguration = new AdapterConfiguration()
                };

                obfuscationConfiguration.DictionaryConfigurations.Add(dictionaryConfiguration);
            }
        }
예제 #2
0
        public static void DeleteKeyFromNameDict(string key, bool useSort, bool usePrimary)
        {
            NameDict.Remove(key);
            NameOneMeaningDict.Remove(key);
            VietPhraseAndNameDict.Remove(key);
            VietPhraseOneMeaningDict.Remove(key);

            var selectedNameDict = usePrimary ? PrimaryNameDict : SecondaryNameDict;

            if (!selectedNameDict.Remove(key))
            {
                return;
            }

            var selectedNameDictPath = usePrimary
                ? DictionaryConfiguration.GetPrimaryNameDictPath()
                : DictionaryConfiguration.GetSecondaryNameDictPath();

            if (useSort)
            {
                SaveDictionaryToFileSorted(selectedNameDict, selectedNameDictPath);
            }
            else
            {
                SaveDictionaryToFile(selectedNameDict, selectedNameDictPath);
            }

            WriteNamesLog(key, "Deleted", usePrimary);
        }
        protected override object CoreGetAlternativeValueFromId(DictionaryConfiguration dictionaryConfiguration, IMetaColumn metaColumn, object surrogateId)
        {
            object           value;
            IDbDataParameter dbDataParameterKey;

            if ((object)dictionaryConfiguration == null)
            {
                throw new ArgumentNullException("dictionaryConfiguration");
            }

            if ((object)metaColumn == null)
            {
                throw new ArgumentNullException("metaColumn");
            }

            if ((object)surrogateId == null)
            {
                throw new ArgumentNullException("surrogateId");
            }

            if (DataTypeFascade.Instance.IsNullOrWhiteSpace(this.AdapterConfiguration.AdapterSpecificConfiguration.ExecuteCommandText))
            {
                throw new InvalidOperationException(string.Format("Configuration missing: '{0}'.", "ExecuteCommandText"));
            }

            dbDataParameterKey = this.DictionaryUnitOfWork.CreateParameter(ParameterDirection.Input, DbType.Object, 0, 0, 0, false, "@ID", surrogateId);

            value = this.DictionaryUnitOfWork.ExecuteScalar <string>(this.AdapterConfiguration.AdapterSpecificConfiguration.ExecuteCommandType ?? CommandType.Text, this.AdapterConfiguration.AdapterSpecificConfiguration.ExecuteCommandText, new IDbDataParameter[] { dbDataParameterKey });

            return(value);
        }
        private DictionaryConfiguration GetDictionaryConfiguration(IOxymoronEngine oxymoronEngine, ColumnConfiguration <SubstitutionObfuscationStrategyConfiguration> columnConfiguration)
        {
            DictionaryConfiguration dictionaryConfiguration;

            if ((object)oxymoronEngine == null)
            {
                throw new ArgumentNullException("oxymoronEngine");
            }

            if ((object)columnConfiguration == null)
            {
                throw new ArgumentNullException("columnConfiguration");
            }

            if (columnConfiguration.ObfuscationStrategySpecificConfiguration.DictionaryReference.SafeToString().Trim().ToLower() == string.Empty)
            {
                dictionaryConfiguration = new DictionaryConfiguration();
            }
            else
            {
                dictionaryConfiguration = oxymoronEngine.ObfuscationConfiguration.DictionaryConfigurations.SingleOrDefault(d => d.DictionaryId.SafeToString().Trim().ToLower() == columnConfiguration.ObfuscationStrategySpecificConfiguration.DictionaryReference.SafeToString().Trim().ToLower());
            }

            if ((object)dictionaryConfiguration == null)
            {
                throw new InvalidOperationException(string.Format("Unknown dictionary reference '{0}' specified for column '{1}'.", columnConfiguration.ObfuscationStrategySpecificConfiguration.DictionaryReference, columnConfiguration.ColumnName));
            }

            return(dictionaryConfiguration);
        }
예제 #5
0
        public static void UpdateSinoVietPronunciationDict(string key, string value, bool useSort)
        {
            string action;

            if (SinoVietPronunciationDict.ContainsKey(key))
            {
                SinoVietPronunciationDict[key] = value;
                action = "Update";
            }
            else
            {
                if (useSort)
                {
                    SinoVietPronunciationDict[key] = value;
                }
                else
                {
                    SinoVietPronunciationDict = AddEntryToDictionaryNoSort(SinoVietPronunciationDict, key, value);
                }
                action = "Added";
            }
            WriteSinoVietPronunciationLog(key, action);

            var dictPath = DictionaryConfiguration.GetSinoVietPronunciationDictPath();

            if (useSort)
            {
                SaveDictionaryToFileSorted(SinoVietPronunciationDict, dictPath);
            }
            else
            {
                SaveDictionaryToFile(SinoVietPronunciationDict, dictPath);
            }
        }
 static DictionaryConfiguration()
 {
     Default = new DictionaryConfiguration()
     {
         UseType = DictionaryLocalizationType.HEADER,
         Keyword = "accept-language"
     };
 }
예제 #7
0
        public static P2PConfiguration LoadConfiguration(string path, string certsPath, string defaultPath)
        {
            var lines = new DictionaryConfiguration(path);

            X509Certificate2 cert     = null;
            IPEndPoint       endpoint = null;

            try
            {
                var certFileName = lines.GetValue("TLS_CERT");
                var pwd          = lines.GetValue("TLS_PWD");
                var certificate  = Path.Combine(certsPath, certFileName);
                if (File.Exists(certificate))
                {
                    cert = new X509Certificate2(certificate, pwd);
                }
            }
            catch (Exception e)
            {
            }

            if (cert == null)
            {
                if (File.Exists(defaultPath))
                {
                    cert = new X509Certificate2(defaultPath, "");
                }
            }

            try
            {
                var ip = IPAddress.Any;
                if (!string.IsNullOrEmpty(lines.GetValue("Ip")))
                {
                    ip = IPAddress.Parse(lines.GetValue("Ip"));
                }
                endpoint = new IPEndPoint(ip, int.Parse(lines.GetValue("Port")));
            }
            catch (Exception e) { }

            int forwarded = 0;

            try
            {
                if (!string.IsNullOrEmpty(lines.GetValue("ForwardedPort")))
                {
                    forwarded = Int32.Parse(lines.GetValue("ForwardedPort"));
                }
            }
            catch (Exception e) { }

            return(new P2PConfiguration
            {
                IPEndpoint = endpoint,
                Certificate = cert,
                ForwardedPort = forwarded
            });
        }
예제 #8
0
 public static void CompressNameOnlyDictLog(bool usePrimary)
 {
     CompressDictLog(
         usePrimary ? NameOnlyLogDataSet : NamePhuOnlyLogDataSet,
         usePrimary
             ? DictionaryConfiguration.GetNameLogPath()
             : DictionaryConfiguration.GetSecondaryNameLogPath()
         );
 }
예제 #9
0
        static void WriteNamesLog(string key, string action, bool usePrimary)
        {
            var dataSet = usePrimary ? NameOnlyLogDataSet : NamePhuOnlyLogDataSet;

            UpdateLogInCache(key, action, ref dataSet);
            WriteLog(key, action, usePrimary
                ? DictionaryConfiguration.GetNameLogPath()
                : DictionaryConfiguration.GetSecondaryNameLogPath());
        }
예제 #10
0
        public void TryGetValue_KeyIsNull_ThrowsArgumentNullException()
        {
            // Arrange
            var conf = new DictionaryConfiguration <Dictionary <string, string> >(new Dictionary <string, string>());

            // Act
            // Assert
            Assert.That(() => conf.TryGetValue(null), Throws.ArgumentNullException);
        }
        protected override object CoreGetAlternativeValueFromId(DictionaryConfiguration dictionaryConfiguration, IMetaColumn metaColumn, object surrogateId)
        {
            object value;
            int    index;

            HeaderSpec[] headerSpecs;
            IEnumerable <IDictionary <string, object> > records;

            if ((object)dictionaryConfiguration == null)
            {
                throw new ArgumentNullException("dictionaryConfiguration");
            }

            if ((object)metaColumn == null)
            {
                throw new ArgumentNullException("metaColumn");
            }

            if ((object)surrogateId == null)
            {
                throw new ArgumentNullException("surrogateId");
            }

            if ((object)this.AdapterConfiguration.AdapterSpecificConfiguration.DelimitedTextSpec == null)
            {
                throw new InvalidOperationException(string.Format("Configuration missing: '{0}'.", "DelimitedTextSpec"));
            }

            if (DataTypeFascade.Instance.IsNullOrWhiteSpace(this.AdapterConfiguration.AdapterSpecificConfiguration.DelimitedTextFilePath))
            {
                throw new InvalidOperationException(string.Format("Configuration missing: '{0}'.", "DelimitedTextFilePath"));
            }

            using (RecordTextReader delimitedTextReader = new DelimitedTextReader(new StreamReader(File.Open(this.AdapterConfiguration.AdapterSpecificConfiguration.DelimitedTextFilePath, FileMode.Open, FileAccess.Read, FileShare.None)), this.AdapterConfiguration.AdapterSpecificConfiguration.DelimitedTextSpec))
            {
                index = surrogateId.ChangeType <int>() - 1;

                headerSpecs = delimitedTextReader.ReadHeaderSpecs().ToArray();
                records     = delimitedTextReader.ReadRecords();

                var record = records.ElementAtOrDefault(index);

                if ((object)record == null)
                {
                    value = null;
                }
                else
                {
                    value = record[headerSpecs[index].HeaderName];
                }
            }

            return(value);
        }
예제 #12
0
        protected override void CorePreloadCache(DictionaryConfiguration dictionaryConfiguration, IDictionary <string, IDictionary <long, object> > substitutionCacheRoot)
        {
            if ((object)dictionaryConfiguration == null)
            {
                throw new ArgumentNullException("dictionaryConfiguration");
            }

            if ((object)substitutionCacheRoot == null)
            {
                throw new ArgumentNullException("substitutionCacheRoot");
            }
        }
예제 #13
0
        public static WebSocketServer.Configuration LoadConfiguration(string path)
        {
            var lines = new DictionaryConfiguration(path);

            return(new WebSocketServer.Configuration
            {
                Ip = lines.GetValue("Ip"),
                Port = int.Parse(lines.GetValue("Port")),
                TLS_CERT = lines.GetValue("TLS_CERT"),
                TLS_PWD = lines.GetValue("TLS_PWD"),
            });
        }
        private void ApplyDocumentToViewDelimitedTextDictionary(DictionaryConfiguration dictionaryConfiguration, IAdapterSettingsPartialView adapterSettingsPartialView)
        {
            //if ((object)dictionaryConfiguration == null)
            //	throw new ArgumentNullException("dictionaryConfiguration");

            //if ((object)adapterSettingsView == null)
            //	throw new ArgumentNullException("adapterSettingsView");

            //if ((object)dictionaryConfiguration.DictionaryAdapterConfiguration != null &&
            //	(object)dictionaryConfiguration.DictionaryAdapterConfiguration.DelimitedTextAdapterConfiguration != null)
            //	_ApplyDocumentToViewDelimitedText(dictionaryConfiguration.DictionaryAdapterConfiguration.DelimitedTextAdapterConfiguration, adapterSettingsView.DelTextAdapterSettingsView);
        }
 public JSONDictionarySourceProvider(string name, IDictionaryReader reader, DictionaryConfiguration configuration = null)
 {
     _reader = reader;
     if (configuration == null)
     {
         configuration = DictionaryConfiguration.Default;
     }
     _dictionaryConfiguration = configuration;
     _dictionaries            = _reader.Initialize();
     // var _default = _dictionaries.FirstOrDefault(x => x.Value.Language.IsDefault == true);
     _defaultDictionarySource = _dictionaries.FirstOrDefault(x => x.Value.Language.IsDefault == true).Value; //_default != null ? _default.Value : null;
 }
예제 #16
0
        public void TryGetValue_ReturnsDictionaryValue()
        {
            // Arrange
            var conf = new DictionaryConfiguration <Dictionary <string, string> >(new Dictionary <string, string> {
                ["Foo"] = "Bar"
            });

            // Act
            var result = conf.TryGetValue("Foo");

            // Assert
            Assert.That(result, Is.EqualTo("Bar"));
        }
        public void SaveConfiguration_ShouldSaveCorrectWriteIntIntDictionary()
        {
            var config = new DictionaryConfiguration()
            {
                IntsDictionary = new Dictionary <int, int>()
                {
                    [1] = 2,
                    [2] = 3
                }
            };

            _iniWrapper.SaveConfiguration(config);
            _iniParser.Received(1).Write(nameof(DictionaryConfiguration.IntsDictionary), "1", "2");
            _iniParser.Received(1).Write(nameof(DictionaryConfiguration.IntsDictionary), "2", "3");
        }
        public void SaveConfiguration_ShouldSaveCorrectWriteStringStringDictionary()
        {
            var config = new DictionaryConfiguration()
            {
                StringStringDictionary = new Dictionary <string, string>()
                {
                    ["test1"] = "testValue",
                    ["test2"] = "testValue2"
                }
            };

            _iniWrapper.SaveConfiguration(config);
            _iniParser.Received(1).Write(nameof(DictionaryConfiguration.StringStringDictionary), config.StringStringDictionary.ElementAt(0).Key, config.StringStringDictionary.ElementAt(0).Value);
            _iniParser.Received(1).Write(nameof(DictionaryConfiguration.StringStringDictionary), config.StringStringDictionary.ElementAt(1).Key, config.StringStringDictionary.ElementAt(1).Value);
        }
        public void SaveConfiguration_ShouldSaveCorrectWriteEnumDictionary()
        {
            var config = new DictionaryConfiguration()
            {
                EnumDictionary = new Dictionary <TestEnum, TestEnum>()
                {
                    [TestEnum.Five] = TestEnum.Five,
                    [TestEnum.Two]  = TestEnum.Four
                }
            };

            _iniWrapper.SaveConfiguration(config);
            _iniParser.Received(1).Write(nameof(DictionaryConfiguration.EnumDictionary), "5", "5");
            _iniParser.Received(1).Write(nameof(DictionaryConfiguration.EnumDictionary), "2", "4");
        }
        public void SaveConfiguration_ShouldSaveCorrectWriteStringIntDictionary()
        {
            var config = new DictionaryConfiguration()
            {
                StringIntDictionary = new Dictionary <string, int>()
                {
                    ["test1"] = 2,
                    ["test2"] = 3
                }
            };

            _iniWrapper.SaveConfiguration(config);
            _iniParser.Received(1).Write(nameof(DictionaryConfiguration.StringIntDictionary), config.StringIntDictionary.FirstOrDefault().Key, "2");
            _iniParser.Received(1).Write(nameof(DictionaryConfiguration.StringIntDictionary), config.StringIntDictionary.ElementAt(1).Key, "3");
        }
예제 #21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RandomWordGenerator"/>
        /// class thats able to generate random words.
        /// </summary>
        /// <param name="dictionaryService">A service for retrieving dictionaries.</param>
        /// <param name="characterSetProvider">A service for providing a character list.</param>
        /// <param name="threadService">A service for getting the number of threads.</param>
        /// <param name="dictionaryConfiguration">The dictionary configuration settings.</param>
        public RandomWordGenerator(
            IDictionaryLoader dictionaryService,
            ICharacterSetProvider characterSetProvider,
            IThreadBalancer threadService,
            DictionaryConfiguration dictionaryConfiguration)
        {
            // Set member dependencies.
            this.dictionaryService       = dictionaryService;
            this.threadService           = threadService;
            this.dictionaryConfiguration = dictionaryConfiguration;

            characterList = characterSetProvider.ToCharArray();
            random        = RandomProvider.Random;

            progressPercentage = 0;
        }
예제 #22
0
        public static void AddIgnoredChinesePhrase(string ignoredChinesePhrase)
        {
            if (IgnoredChinesePhrases.Contains(ignoredChinesePhrase))
            {
                return;
            }

            IgnoredChinesePhrases.Add(ignoredChinesePhrase);
            try
            {
                File.WriteAllLines(DictionaryConfiguration.GetIgnoredChinesePhraseListPath(),
                                   IgnoredChinesePhrases, Encoding.UTF8);
            }
            catch { }
            LoadIgnoredChinesePhraseLists();
        }
예제 #23
0
        public static void DeleteKeyFromSinoVietPronunciationDict(string key, bool useSort)
        {
            SinoVietPronunciationDict.Remove(key);

            var dictPath = DictionaryConfiguration.GetSinoVietPronunciationDictPath();

            if (useSort)
            {
                SaveDictionaryToFileSorted(SinoVietPronunciationDict, dictPath);
            }
            else
            {
                SaveDictionaryToFile(SinoVietPronunciationDict, dictPath);
            }

            WriteSinoVietPronunciationLog(key, "Deleted");
        }
        protected override void CorePreloadCache(DictionaryConfiguration dictionaryConfiguration, IDictionary <string, IDictionary <long, object> > substitutionCacheRoot)
        {
            HeaderSpec[] headerSpecs;
            IEnumerable <IDictionary <string, object> > records;
            IDictionary <long, object> dictionaryCache;

            if ((object)dictionaryConfiguration == null)
            {
                throw new ArgumentNullException("dictionaryConfiguration");
            }

            if ((object)substitutionCacheRoot == null)
            {
                throw new ArgumentNullException("substitutionCacheRoot");
            }

            if ((object)this.AdapterConfiguration.AdapterSpecificConfiguration.DelimitedTextSpec == null)
            {
                throw new InvalidOperationException(string.Format("Configuration missing: '{0}'.", "DelimitedTextSpec"));
            }

            if (DataTypeFascade.Instance.IsNullOrWhiteSpace(this.AdapterConfiguration.AdapterSpecificConfiguration.DelimitedTextFilePath))
            {
                throw new InvalidOperationException(string.Format("Configuration missing: '{0}'.", "DelimitedTextFilePath"));
            }

            using (RecordTextReader delimitedTextReader = new DelimitedTextReader(new StreamReader(File.Open(this.AdapterConfiguration.AdapterSpecificConfiguration.DelimitedTextFilePath, FileMode.Open, FileAccess.Read, FileShare.None)), this.AdapterConfiguration.AdapterSpecificConfiguration.DelimitedTextSpec))
            {
                dictionaryCache = new Dictionary <long, object>();

                headerSpecs = delimitedTextReader.ReadHeaderSpecs().ToArray();
                records     = delimitedTextReader.ReadRecords();

                foreach (IDictionary <string, object> record in records)
                {
                    object[] values = record.Values.ToArray();
                    long     id     = values[0].ChangeType <long>();
                    object   value  = values[1].ChangeType <string>();

                    dictionaryCache.Add(id, value);
                }

                substitutionCacheRoot.Add(dictionaryConfiguration.DictionaryId, dictionaryCache);
            }
        }
예제 #25
0
        public static void DeleteVietPhrase(string key, bool useSort)
        {
            VietPhraseAndNameDict.Remove(key);
            VietPhraseOneMeaningDict.Remove(key);
            VietPhraseDict.Remove(key);

            var dictPath = DictionaryConfiguration.GetVietPhraseDictPath();

            if (useSort)
            {
                SaveDictionaryToFileSorted(VietPhraseDict, dictPath);
            }
            else
            {
                SaveDictionaryToFile(VietPhraseDict, dictPath);
            }

            WriteVietPhraseLog(key, "Deleted");
        }
예제 #26
0
        /// <inheritdoc />
        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterType <MetroWindowManager>()
            .AsSelf()
            .As <IWindowManager>()
            .SingleInstance();

            builder.RegisterType <MetroThemeManager>()
            .AsSelf()
            .SingleInstance();

            builder
            .Register(c => DictionaryConfiguration <IMetroUiConfiguration> .Create())
            .IfNotRegistered(typeof(IMetroUiConfiguration))
            .As <IMetroUiConfiguration>()
            .SingleInstance();

            base.Load(builder);
        }
        protected override void CorePreloadCache(DictionaryConfiguration dictionaryConfiguration, IDictionary <string, IDictionary <long, object> > substitutionCacheRoot)
        {
            IEnumerable <IRecord>      records;
            IDictionary <long, object> dictionaryCache;

            if ((object)dictionaryConfiguration == null)
            {
                throw new ArgumentNullException("dictionaryConfiguration");
            }

            if ((object)substitutionCacheRoot == null)
            {
                throw new ArgumentNullException("substitutionCacheRoot");
            }

            if (dictionaryConfiguration.PreloadEnabled)
            {
                if (DataTypeFascade.Instance.IsNullOrWhiteSpace(this.AdapterConfiguration.AdapterSpecificConfiguration.ExecuteCommandText))
                {
                    throw new InvalidOperationException(string.Format("Configuration missing: '{0}'.", "ExecuteCommandText"));
                }

                records = this.DictionaryUnitOfWork.ExecuteRecords(this.AdapterConfiguration.AdapterSpecificConfiguration.ExecuteCommandType ?? CommandType.Text, this.AdapterConfiguration.AdapterSpecificConfiguration.ExecuteCommandText, new IDbDataParameter[] { }, null);

                if ((object)records == null)
                {
                    throw new InvalidOperationException(string.Format("Records were invalid."));
                }

                dictionaryCache = new Dictionary <long, object>();

                foreach (IRecord record in records)
                {
                    object[] values = record.Values.ToArray();
                    long     id     = values[0].ChangeType <long>();
                    object   value  = values[1].ChangeType <string>();

                    dictionaryCache.Add(id, value);
                }

                substitutionCacheRoot.Add(dictionaryConfiguration.DictionaryId, dictionaryCache);
            }
        }
예제 #28
0
        protected override object CoreGetAlternativeValueFromId(DictionaryConfiguration dictionaryConfiguration, IMetaColumn metaColumn, object surrogateId)
        {
            if ((object)dictionaryConfiguration == null)
            {
                throw new ArgumentNullException("dictionaryConfiguration");
            }

            if ((object)metaColumn == null)
            {
                throw new ArgumentNullException("metaColumn");
            }

            if ((object)surrogateId == null)
            {
                throw new ArgumentNullException("surrogateId");
            }

            return(null);
        }
예제 #29
0
        public static void UpdateVietPhraseDict(string key, string value, bool useSort)
        {
            VietPhraseAndNameDict[key]    = value;
            VietPhraseOneMeaningDict[key] = value.Split('/', '|')[0];

            string action;

            if (VietPhraseDict.ContainsKey(key))
            {
                VietPhraseDict[key] = value;
                action = "Updated";
            }
            else
            {
                if (useSort)
                {
                    VietPhraseDict[key] = value;
                }
                else
                {
                    VietPhraseDict = AddEntryToDictionaryNoSort(VietPhraseDict, key, value);
                }
                action = "Added";
            }
            WriteVietPhraseLog(key, action);

            var dictPath = DictionaryConfiguration.GetVietPhraseDictPath();

            if (useSort)
            {
                SaveDictionaryToFileSorted(VietPhraseDict, dictPath);
            }
            else
            {
                SaveDictionaryToFile(VietPhraseDict, dictPath);
            }
        }
예제 #30
0
 public object GetValueForIdViaDictionaryResolution(DictionaryConfiguration dictionaryConfiguration, IMetaColumn metaColumn, object surrogateId)
 {
     return(this.CoreGetValueForIdViaDictionaryResolution(dictionaryConfiguration, metaColumn, surrogateId));
 }