/// <summary>
        /// Create a collection of URL elements from a CSV file of dictionary entries
        /// </summary>
        /// <returns>SitemapUrlSet</returns>
        public override SitemapUrlSet GetSitemapUrls(string sitemapName)
        {
            List <SitemapUrl> sitemapUrls = new List <SitemapUrl>();

            try
            {
                _info = GetDictionariesInfo();
            }
            catch (Exception ex)
            {
                log.Error("Error deserializing DictionariesConfig.xml file.");
                throw ex;
            }

            string path = _info.SitemapStore;

            if (path != null)
            {
                String file = HttpContext.Current.Server.MapPath(path);

                List <DictionaryEntryMetadata> entries = new List <DictionaryEntryMetadata>();

                try
                {
                    using (StreamReader sr = new StreamReader(file))
                    {
                        string currentLine;
                        // currentLine will be null when the StreamReader reaches the end of file
                        while ((currentLine = sr.ReadLine()) != null)
                        {
                            string[] values = currentLine.Split(',');

                            if (values.Length == 3)
                            {
                                try
                                {
                                    DictionaryEntryMetadata entry = new DictionaryEntryMetadata();

                                    int  cdrid;
                                    bool validCDRID = int.TryParse(values[0], out cdrid);
                                    if (validCDRID)
                                    {
                                        entry.CDRID      = cdrid;
                                        entry.Dictionary = (NCI.Services.Dictionary.DictionaryType)System.Enum.Parse(typeof(NCI.Services.Dictionary.DictionaryType), values[1]);
                                        entry.Language   = (Language)System.Enum.Parse(typeof(Language), values[2]);
                                        entries.Add(entry);
                                    }
                                    else
                                    {
                                        log.ErrorFormat("Error in dictionary sitemap file for line {0} : invalid CDRID.", currentLine);
                                        continue;
                                    }
                                }
                                catch
                                {
                                    log.ErrorFormat("Error in dictionary sitemap file {0} for line {1} : could not create dictionary entry metadata.", file, currentLine);
                                    continue;
                                }
                            }
                            else
                            {
                                log.ErrorFormat("Error in dictionary sitemap file {0} for line {1} : invalid syntax.", file, currentLine);
                                continue;
                            }
                        }

                        // Check if these entries are valid in the DB. Returns a list of only the valid entries to be included in the sitemap.
                        DictionaryAppManager _dictionaryAppManager = new DictionaryAppManager();
                        entries = _dictionaryAppManager.DoDictionaryEntriesExist(entries);
                    }
                }
                catch (Exception e)
                {
                    log.ErrorFormat("Error in DictionarySitemapUrlStore: unable to read dictionary sitemap file located at {0}.", file);
                    return(new SitemapUrlSet());
                }

                foreach (DictionaryEntryMetadata entry in entries)
                {
                    string dic  = entry.Dictionary.ToString();
                    string lang = entry.Language.ToString();

                    DictionaryInfo entryInfo = _info.DictionaryInfos.First(i => i.Name == entry.Dictionary.ToString() && i.Language == entry.Language.ToString());
                    string         entryUrl  = GetSitemapUrl(entryInfo, entry.CDRID.ToString());
                    double         priority  = 0.5;

                    sitemapUrls.Add(new SitemapUrl(entryUrl, sitemapChangeFreq.weekly, priority));
                }

                return(new SitemapUrlSet(sitemapUrls));
            }
            else
            {
                log.ErrorFormat("Could not load dictionary provider file located at {0}.", path);
                return(new SitemapUrlSet());
            }
        }
Ejemplo n.º 2
0
        internal void Init()
        {
            if (Words == null)
            {
                Words = new List <Word>();
            }
            else
            {
                Words.Clear();
            }

            if (Dictionaties == null)
            {
                Dictionaties = new List <Dictionary>();
            }
            else
            {
                Dictionaties.Clear();
            }

            if (ApplestsData == null)
            {
                ApplestsData = new List <AppletData>();
            }
            else
            {
                ApplestsData.Clear();
            }

            if (WordsInfo == null)
            {
                WordsInfo = new List <WordInfo>();
            }
            else
            {
                WordsInfo.Clear();
            }

            if (WordsInfoDelete == null)
            {
                WordsInfoDelete = new List <WordInfo>();
            }
            else
            {
                WordsInfoDelete.Clear();
            }

            if (DictionariesInfo == null)
            {
                DictionariesInfo = new List <DictionaryInfo>();
            }
            else
            {
                DictionariesInfo.Clear();
            }

            if (DictionariesInfoDelete == null)
            {
                DictionariesInfoDelete = new List <DictionaryInfo>();
            }
            else
            {
                DictionariesInfoDelete.Clear();
            }

            if (AppletsDataInfo == null)
            {
                AppletsDataInfo = new List <AppletDataInfo>();
            }
            else
            {
                AppletsDataInfo.Clear();
            }

            if (AppletsDataInfoDelete == null)
            {
                AppletsDataInfoDelete = new List <AppletDataInfo>();
            }
            else
            {
                AppletsDataInfoDelete.Clear();
            }

            currentDictionaty = null;

            xdoc = XDocument.Load(Environment.CurrentDirectory + "\\" + xml_Name);

            Init_Word();
            Init_Dic();
            Init_Progress();
        }
Ejemplo n.º 3
0
 /// <summary>Осуществляет внесение изменений в базу данных. Изменения будут применены после Commit().</summary>
 /// <param name="info">см. описание к Push(DictionaryCreateIfon info)</param>
 public void Push(List <DictionaryInfo> info)
 {
     DictionariesInfo.AddRange(info);
 }
Ejemplo n.º 4
0
        private void Commit_Dic(XDocument doc)
        {
            doc.Element(root_xml_name).Add(new XElement(xml_personal_dictionaries_name));
            var root = doc.Element(root_xml_name).Element(xml_personal_dictionaries_name);

            #region Часть 1. Вносятся изменения в существующие словари и создаются новые

            DictionariesInfo.Where(i => (i.Dictionary != null)).ToList().ForEach(delegate(DictionaryInfo info)
            {
                if (info.Description != null) //Изменения в описание словаря
                {
                    if (info.Description != string.Empty)
                    {
                        info.Dictionary.Description = info.Description;
                    }
                }

                if (info.Name != null) //Изменение в наименование словаря
                {
                    if (info.Name != string.Empty)
                    {
                        info.Dictionary.Name = info.Name;
                    }
                }

                if (info.WordsNew != null && info.WordsNew.Count != 0) //Добавляем новые слова
                {
                    info.Dictionary.Words.AddRange(info.WordsNew);
                }

                if (info.WordsExclude != null && info.WordsExclude.Count != 0) //Исключаем слова из словаря
                {
                    info.WordsExclude.ForEach(delegate(Word w)
                    {
                        info.Dictionary.Words.Remove(w);
                    });
                }
            });

            DictionariesInfo.Where(i => (i.Dictionary == null)).ToList().ForEach(delegate(DictionaryInfo info)
            {
                Dictionary dic  = new Dictionary();
                dic.Name        = info.Name;
                dic.Description = info.Description;

                this.Dictionaties.Add(dic);
            });

            #endregion

            #region Часть 2. Удаляем словари

            DictionariesInfoDelete.ForEach(delegate(DictionaryInfo info)
                                           { Dictionaties.Remove(info.Dictionary); });

            #endregion

            #region Часть 3. Записываем все в XDocument

            Dictionaties.ForEach(delegate(Dictionary d)
            {
                XElement xe = new XElement("dictionary");
                xe.Add(new XAttribute("name", d.Name));
                xe.Add(new XAttribute("descr", d.Description));
                xe.Add(new XAttribute("cost", d.COST));

                if (d.COST)
                {
                    xe.Add(new XAttribute("words", string.Empty));
                }

                else
                {
                    string words = string.Empty;

                    d.Words.ForEach(delegate(Word w)
                                    { words += "#" + w.ID; });

                    xe.Add(new XAttribute("words", words));
                }

                root.Add(xe);
            });

            #endregion
        }
Ejemplo n.º 5
0
 /// <summary>Осуществляет внесение изменений в базу данных. Изменения будут применены после Commit().</summary>
 /// <param name="info">Если свойство Dictionary != null,
 /// то выполняется внесение изменений в существующий объкт Dictionary в базе данных.
 /// В противном случае выполняется занесение нового словаря в базу</param>
 public void Push(DictionaryInfo info)
 {
     DictionariesInfo.Add(info);
 }