Exemplo n.º 1
0
        public override string Parse(Block block)
        {
            StringBuilder content = new StringBuilder();
            Regex reg = new Regex(@"new Book\({ parent: '.+', pages: \['(?<page>.+)'\]}\)", RegexOptions.Multiline);
            MatchCollection matches = reg.Matches(block.Page);

            foreach (Match match in matches)
            {
                GroupCollection groups = match.Groups;
                string typeStr = groups["page"].Value ?? string.Empty;
                string[] pages = typeStr.Split(new[] { @"','" }, StringSplitOptions.RemoveEmptyEntries);

                content.AppendFormat(@"SET @ENTRY := SELECT `data0` FROM `gameobject_template` WHERE `entry` = {0};", block.Entry).AppendLine();
                content.AppendLine(@"INSERT IGNORE INTO `page_text` (`entry`, `text`, `next_page`) VALUES");

                for (int i = 0; i < pages.Length; ++i)
                {
                    content.AppendFormat(@"({0}, '{1}', {2}){3}",
                        (i == 0 ? "@ENTRY" : string.Format("@ENTRY + {0}", i)), pages[i].HTMLEscapeSumbols(),
                        (i < pages.Length - 1) ? string.Format("@ENTRY + {0}", i + 1) : "0", (i < pages.Length - 1 ? "," : ";")).AppendLine();
                }
                content.AppendLine();
            }

            return content.ToString();
        }
        public override string Parse(Block block)
        {
            StringBuilder content = new StringBuilder();

            string page = block.Page;
            TrainerType type = GetTrainerType(page);

            string pattern = @"data: \[.*;";
            string subPattern = "{[^}]*\"id\":(\\d+)[^}]*\"level\":(\\d+)[^}]*\"skill\":\\[(\\d+)?\\][^}]*\"trainingcost\":(\\d+)[^}]*";

            //[{"cat":9,"id":33095,"learnedat":275,"level":1,"name":"@Рыбная ловля","nskillup":1,"schools":1,"skill":[356],"source":[6],"trainingcost":100000}

            bool print = false;

            MatchCollection find = Regex.Matches(page, pattern);
            foreach (Match item in find)
            {
                MatchCollection matches = Regex.Matches(item.Value, subPattern);
                if (!print && matches.Count > 0)
                {
                    content.AppendLine();
                    content.AppendFormat(@"SET @ENTRY := {0};", block.Entry).AppendLine();
                    content.AppendLine(@"UPDATE `creature_template` SET `npcflag` = `npcflag` | 48 WHERE `entry` = @ENTRY;");
                    content.AppendLine(@"REPLACE INTO `npc_trainer` (`entry`, `spell`, `spellcost`, `reqlevel`, `reqSkill`) VALUES");
                    print = true;
                }

                for (int i = 0; i < matches.Count; ++i)
                {
                    GroupCollection groups = matches[i].Groups;
                    content.AppendFormat(@"(@ENTRY, {0}, {1}, {2}, {3}){4}", groups[1].Value, groups[4].Value, groups[2].Value, string.IsNullOrEmpty(groups[3].Value) ? "0" : groups[3].Value, (i < matches.Count - 1 ? "," : ";")).AppendLine();
                }
            }

            return content.ToString();
        }
Exemplo n.º 3
0
        private void RespCallback(IAsyncResult iar)
        {
            Requests request = (Requests)iar.AsyncState;
            try
            {
                request.Response = (HttpWebResponse)request.Request.EndGetResponse(iar);
                string text = request.ToString();
                if (!string.IsNullOrEmpty(text))
                {
                    Block block = new Block(text, request.Entry);
                    lock (_threadLock)
                        _pages.Enqueue(block);
                }
            }
            catch
            {
            }
            finally
            {
                request.Dispose();
            }

            _semaphore.Release();
            _background.ReportProgress(PercentProgress);
        }
        public override string Parse(Block block)
        {
            StringBuilder content = new StringBuilder();

            string page = block.Page;
            TrainerType type = GetTrainerType(page);

            string pattern = @"data: \[.*;";
            string subPattern = string.Empty;

            switch (type)
            {
                case TrainerType.ClassTrainer:
                    subPattern = "{[^}]*\"id\":(\\d+)[^}]*\"level\":(\\d+)[^}]*\"skill\":\\[(\\d+)?\\][^}]*\"trainingcost\":(\\d+)[^}]*";
                    break;
                case TrainerType.RecipeTrainer:
                    subPattern = "{[^}]*\"id\":(\\d+)[^}]*\"learnedat\":(\\d+)[^}]*\"level\":(\\d+)[^}]*\"skill\":\\[(\\d+)?\\][^}]*\"trainingcost\":(\\d+)[^}]*";
                    break;
                default:
                    return string.Format("-- Unknown trainer type: {0}", type);
            }

            bool print = false;

            MatchCollection find = Regex.Matches(page, pattern);
            foreach (Match item in find)
            {
                MatchCollection matches = Regex.Matches(item.Value, subPattern);
                if (!print && matches.Count > 0)
                {
                    content.AppendLine();
                    content.AppendFormat(@"SET @ENTRY := {0};", block.Entry).AppendLine();
                    content.AppendLine(@"UPDATE `creature_template` SET `npcflag` = `npcflag` | 48 WHERE `entry` = @ENTRY;");
                    content.AppendLine(@"REPLACE INTO `npc_trainer` (`entry`, `spell`, `spellcost`, `reqlevel`, `reqSkill`, `reqSkillValue`) VALUES");
                    print = true;
                }

                for (int i = 0; i < matches.Count; ++i)
                {
                    GroupCollection groups = matches[i].Groups;

                    string spell = groups[1].Value;
                    string end = (i < matches.Count - 1 ? "," : ";");
                    if (type == TrainerType.RecipeTrainer)
                    {
                        string reqSkill = (string.IsNullOrEmpty(groups[4].Value) ? "0" : groups[4].Value);
                        string reqSkillValue = (string.IsNullOrEmpty(groups[2].Value) ? "0" : groups[2].Value);

                        content.AppendFormat(@"(@ENTRY, {0}, {1}, {2}, {3}, {4}){5}", spell, groups[5].Value, groups[3].Value, reqSkill, reqSkillValue, end).AppendLine();
                    }
                    else if (type == TrainerType.ClassTrainer)
                    {
                        string reqSkill = (string.IsNullOrEmpty(groups[3].Value) ? "0" : groups[3].Value);

                        content.AppendFormat(@"(@ENTRY, {0}, {1}, {2}, {3}, {4}){5}", spell, groups[4].Value, groups[2].Value, reqSkill, "0", end).AppendLine();
                    }
                }
            }

            return content.ToString();
        }
Exemplo n.º 5
0
        void DownloadStringAsyncCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                lock (_threadLock)
                {
                    Block block = new Block(e.Result, (uint)_entry);
                    _pages.Enqueue(block);
                }
            }

            if (_background.IsBusy)
                _background.ReportProgress(PercentProgress);

            _semaphore.Release();
        }