Esempio n. 1
0
        private void LoadAnotherDomains(XElement root)
        {
            AnotherDomains = new List <AnotherDomainInfo>();
            foreach (XElement element in root.Elements("AnotherDomain"))
            {
                var name          = XmlParseHelper.ParseAttribute <string>(element, "name");
                var link          = XmlParseHelper.ParseAttribute <string>(element, "link");
                var flag          = XmlParseHelper.ParseAttribute <string>(element, "flag");
                var anotherDomain = new AnotherDomainInfo(name, link, flag);

                foreach (XElement pageElement in element.Elements("Page"))
                {
                    var pageSectionId = XmlParseHelper.ParseAttribute <SectionId>(pageElement, "sectionId");
                    var pageUrl       = XmlParseHelper.ParseAttribute <string>(pageElement, "url");
                    var pageTitle     = XmlParseHelper.ParseAttribute <string>(pageElement, "title");

                    anotherDomain.AddPage(pageSectionId, pageUrl, pageTitle);
                }

                if (anotherDomain.IsValid() &&
                    !string.Equals(link, DomainWithProtocol, StringComparison.InvariantCultureIgnoreCase))
                {
                    AnotherDomains.Add(anotherDomain);
                }
            }
        }
Esempio n. 2
0
 private void LoadSalesSettings(XElement root)
 {
     //Доступы к платежным системам
     RobokassaSecurityParams =
         new RobokassaSecurityParams(XmlParseHelper.Get <string>(root, "Payment", "Robokassa", "Login"),
                                     XmlParseHelper.Get <string>(root, "Payment", "Robokassa",
                                                                 "Password1"),
                                     XmlParseHelper.Get <string>(root, "Payment", "Robokassa",
                                                                 "Password2"));
     //секции на которых есть продажа материалов
     _salesSections =
         new HashSet <SectionId>(XmlParseHelper.GetList <SectionId>(root, "Payment", "SectionId"));
     _salesSettings = new Dictionary <SectionId, ISalesSettings>();
     foreach (SectionId salesSection in _salesSections)
     {
         AddSalesSettings(root, salesSection);
     }
 }
Esempio n. 3
0
        public void Load(XElement patternsElement)
        {
            _sectionsTemplates.Clear();

            foreach (XElement sectionElement in patternsElement.Elements("Section"))
            {
                var sectionId = XmlParseHelper.ParseAttribute <SectionId>(sectionElement, "Id");
                var pageId    = XmlParseHelper.ParseAttribute <PageId>(sectionElement, "PageId");

                TemplateSection templateSection = GetOrAddSection(sectionId);

                Dictionary <TemplateId, string> templates =
                    XmlParseHelper.GetDictionary <TemplateId, string>(sectionElement, "Template");
                foreach (var template in templates)
                {
                    templateSection.Set(pageId,
                                        template.Key,
                                        template.Value);
                }
            }
        }
Esempio n. 4
0
        private void LoadKeyboardKeys(XElement root)
        {
            var firstForeignChar = XmlParseHelper.Get <char>(root, "Keyboard", "FirstForeignChar");
            var lastForeignChar  = XmlParseHelper.Get <char>(root, "Keyboard", "LastForeignChar");

            var alsoChars = new HashSet <char>(XmlParseHelper.GetList <char>(root, "Keyboard", "AlsoChar"));

            Dictionary <char, char> toRussian = XmlParseHelper.GetDictionary <char, char>(root, "Keyboard", "ToRussian");

            ForeignToRussianKeys = toRussian;
            RussianToForeignKeys = new Dictionary <char, char>();
            foreach (var chars in toRussian)
            {
                char source      = chars.Key;
                char translation = chars.Value;

                if ((source >= firstForeignChar && source <= lastForeignChar && translation >= 'а' && translation <= 'я') ||
                    alsoChars.Contains(source) || alsoChars.Contains(translation))
                {
                    //нормальная иностранная буква и русская буква
                    RussianToForeignKeys.Add(translation, source);
                }
            }
        }
Esempio n. 5
0
        private void AddSalesSettings(XElement root, SectionId sectionId)
        {
            string nodeName     = sectionId.ToString();
            var    defaultPrice = XmlParseHelper.Get <decimal>(root, "Payment",
                                                               "Settings",
                                                               nodeName,
                                                               "DefaultPrice");
            Dictionary <string, decimal> pricesByNames = XmlParseHelper.GetDictionary <string, decimal>(root, "Payment",
                                                                                                        "Settings",
                                                                                                        nodeName,
                                                                                                        "PriceByName");
            Dictionary <long, decimal> pricesByIds = XmlParseHelper.GetDictionary <long, decimal>(root, "Payment",
                                                                                                  "Settings",
                                                                                                  nodeName,
                                                                                                  "PriceById");
            var discount = XmlParseHelper.Get <decimal>(root, "Payment",
                                                        "Settings",
                                                        nodeName,
                                                        "Discount");

            var summDiscountPrice = XmlParseHelper.Get <decimal>(root, "Payment",
                                                                 "Settings",
                                                                 nodeName,
                                                                 "SummDiscountPrice");
            var salesSettings = new SalesSettings(defaultPrice, pricesByNames, pricesByIds)
            {
                Discount = discount, SummDiscountPrice = summDiscountPrice
            };

            if (salesSettings.IsInvalid)
            {
                return;
            }

            _salesSettings.Add(sectionId, salesSettings);
        }
Esempio n. 6
0
        public void Configure()
        {
            string fullConfigName = Path.Combine(BasePathToWriteData, "WebSettings.xml");

            if (_repositoryFactory != null)
            {
                try {
                    _repositoryFactory.Reload();
                } catch (Exception e) {
                    LoggerWrapper.LogTo(LoggerName.Errors).ErrorFormat(
                        "WebSettingsConfig.Configure при попытке перегрузить репозитории возникло исключение {0}", e);
                }
            }
            else
            {
                _repositoryFactory = new RepositoryFactory(new RepositoryCache(BasePathToWriteData));
            }

            if (SalesPicturesCache != null)
            {
                SalesPicturesCache.ClearMemory();
            }
            else
            {
                string salesPicturesPath = Path.Combine(BasePathToWriteData, "Caches", "Sales");
                SalesPicturesCache = new DiskCache(salesPicturesPath);
            }

            if (CommonDiskCache != null)
            {
                CommonDiskCache.ClearMemory();
            }
            else
            {
                string commonDiskPath = Path.Combine(BasePathToWriteData, "Caches", "Common");
                CommonDiskCache = new DiskCache(commonDiskPath, false);
            }

            DefaultUserLanguages = null;

            var       stream   = new StreamReader(fullConfigName, Encoding.UTF8);
            XDocument document = XDocument.Load(stream);
            XElement  root     = document.Root;

            if (root == null)
            {
                //TODO: ругаться
                return;
            }

            Domain           = XmlParseHelper.Get <string>(root, "Domain");
            Logo             = XmlParseHelper.Get <string>(root, "Logo");
            CookieWideDomain = XmlParseHelper.Get <string>(root, "CookieWideDomain");
            CanPronounce     = XmlParseHelper.Get <bool>(root, "CanPronounce");

            XElement defaultLanguages = root.Element("DefaultLanguages");

            DefaultLanguageFrom = GetLanguage(defaultLanguages, "From");
            DefaultLanguageTo   = GetLanguage(defaultLanguages, "To");

            AvailableSections =
                new HashSet <SectionId>(XmlParseHelper.GetList <SectionId>(root, "AvailableSections", "SectionId"));
            //TODO: проверить корректность конфига, если что-то не так, то ругаться

            LoadKeyboardKeys(root);

            YandexMetrikaId = XmlParseHelper.Get <string>(root, "YandexMetrikaId");
            Counters        = XmlParseHelper.Get <string>(root, "Counters");
            //подгружаем другие домены, а также удаляем текущий домен
            LoadAnotherDomains(root);

            LoadSalesSettings(root);

            PathToTopBanner = XmlParseHelper.Get <string>(root, "Banners", "TopPath");

            _templates.Load(root.Element("Patterns"));

            SetDeferredSettings(_deferredActions);

            MaxIDUserForTopMessage = XmlParseHelper.Get <long>(root, "MaxIDUserForTopMessage");

            WebPath = HttpContext.Current != null?HttpContext.Current.Server.MapPath("~/") : null;

            _fullRightUserIds = new HashSet <long>(XmlParseHelper.GetList <long>(root, "FullRightUserId"));
        }
Esempio n. 7
0
 private static LanguageShortName GetLanguage(XElement element, string name)
 {
     return(XmlParseHelper.Get <LanguageShortName>(element, name));
 }