public void Migrate(string code)
        {
            string jsonFilePath       = Path.Combine(Configuration.DictionariesDirectoryPath, $"{code}");
            var    jsonDictionary     = ReadJsonObject <JsonDictionary>(jsonFilePath + ".json");
            var    jsonDictionaryMeta = ReadJsonObject <DictionaryMeta>(jsonFilePath + "-meta.json");

            WriteDictionary(code, jsonDictionary.Name, jsonDictionaryMeta.Copyright);
            int index = 0;

            foreach (var entry in jsonDictionary.Entries)
            {
                index++;
                string root            = ArabicHelper.Substitute(entry.Name);
                string rootLetterNames = ArabicHelper.ArabicToLetterNames(root);
                string html            = entry.Text;
                html = HeaderRegex.Replace(entry.Text, "");
                html = EmptyElementRegex.Replace(html, m => m.Groups[1].Value + m.Groups[2].Value);
                html = html.Replace("\r\n", " ").Replace("\r", " ").Replace("\n", " ");
                if (jsonDictionaryMeta.RemoveNewLines)
                {
                    html = NewLineRegex.Replace(html, " ");
                }
                else
                {
                    html = NewLineRegex.Replace(html, "\r");
                }
                //TODO: Not until we know we are not already inside a html element
                //html = ArabicRegex.Replace(html, m => $"<span class=\"arabic\">{m.Value}</span>");
                string[] htmlLines       = html.Split('\r');
                var      dictionaryEntry = new DictionaryEntry(
                    dictionaryCode: code,
                    word: root,
                    entryIndex: index,
                    html: htmlLines);
                DictionaryEntryWriteRepository.Write(dictionaryEntry);

                if (index % 100 == 0)
                {
                    Logger.Debug($"{code} {rootLetterNames}");
                }
            }
        }
示例#2
0
        static void SanitizeQueryString(ref string queryString)
        {
            if (string.IsNullOrEmpty(queryString))
            {
                return;
            }
            queryString = ArabicHelper.Substitute(queryString);

            string[] specialCharacters = new string[]
            {
                "&", "|", "!", "(", ")", "{", "}", "[", "]",
                "^", "\"", "~", "?", ":", "\\"
            };
            foreach (string s in specialCharacters)
            {
                queryString = queryString.Replace(s, @"\" + s);
            }

            queryString = "+(" + queryString + ")";
        }
        public ActionResult Index(string dictionaryCode, string word)
        {
            Dictionary dictionary = DictionaryRepository.Get(dictionaryCode);

            if (dictionary == null)
            {
                return(HttpNotFound());
            }
            string indexValue = ArabicHelper.Substitute(word);
            IEnumerable <DictionaryEntry> entries = DictionaryEntryRepository.Get(
                dictionaryCode: dictionaryCode,
                word: indexValue);

            if (!entries.Any())
            {
                return(HttpNotFound());
            }

            var viewModel = new ViewModel(word, dictionary, entries);

            return(View("DictionaryEntry", viewModel));
        }