當前位置: 首頁>>代碼示例>>C#>>正文


C# ParserState.UpdateCurrentNode方法代碼示例

本文整理匯總了C#中System.ParserState.UpdateCurrentNode方法的典型用法代碼示例。如果您正苦於以下問題:C# ParserState.UpdateCurrentNode方法的具體用法?C# ParserState.UpdateCurrentNode怎麽用?C# ParserState.UpdateCurrentNode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.ParserState的用法示例。


在下文中一共展示了ParserState.UpdateCurrentNode方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Handle

        public static void Handle(string timestamp, string data, ParserState state)
        {
            data = data.Trim();
            var match = Regexes.OptionsEntityRegex.Match(data);
            if(match.Success)
            {
                var id = match.Groups[1].Value;
                state.Options = new Options {Id = int.Parse(id), OptionList = new List<Option>(), TimeStamp = timestamp};
                state.UpdateCurrentNode(typeof(Game));
                if(state.Node.Type == typeof(Game))
                    ((Game)state.Node.Object).Data.Add(state.Options);
                else
                    throw new Exception("Invalid node " + state.Node.Type + " -- " + data);
                return;
            }
            match = Regexes.OptionsOptionRegex.Match(data);
            if(match.Success)
            {
                var index = match.Groups[1].Value;
                var rawType = match.Groups[2].Value;
                var rawEntity = match.Groups[3].Value;
                var entity = Helper.ParseEntity(rawEntity, state);
                var type = Helper.ParseEnum<OptionType>(rawType);
                var option = new Option {Entity = entity, Index = int.Parse(index), Type = type, OptionItems = new List<OptionItem>()};
                state.Options.OptionList.Add(option);
                state.CurrentOption = option;
                state.LastOption = option;
                return;
            }
            match = Regexes.OptionsSuboptionRegex.Match(data);
            if(match.Success)
            {
                var subOptionType = match.Groups[1].Value;
                var index = match.Groups[2].Value;
                var rawEntity = match.Groups[3].Value;
                var entity = Helper.ParseEntity(rawEntity, state);

                if(subOptionType == "subOption")
                {
                    var subOption = new SubOption {Entity = entity, Index = int.Parse(index), Targets = new List<Target>()};
                    state.CurrentOption.OptionItems.Add(subOption);
                    state.LastOption = subOption;
                }
                else if(subOptionType == "target")
                {
                    var target = new Target {Entity = entity, Index = int.Parse(index)};
                    var lastOption = state.LastOption as Option;
                    if(lastOption != null)
                    {
                        lastOption.OptionItems.Add(target);
                        return;
                    }
                    var lastSubOption = state.LastOption as SubOption;
                    if(lastSubOption != null)
                        lastSubOption.Targets.Add(target);
                }
                else
                    throw new Exception("Unexpected suboption type: " + subOptionType);
            }
        }
開發者ID:sebastientromp,項目名稱:HSReplay,代碼行數:60,代碼來源:OptionsHandler.cs

示例2: Handle

        public static void Handle(string timestamp, string data, ParserState state)
        {
            var trimmed = data.Trim();
            var indentLevel = data.Length - trimmed.Length;
            data = trimmed;

            if(data == "ACTION_END")
            {
                state.Node = state.Node.Parent ?? state.Node;
                return;
            }

            if(data == "CREATE_GAME")
            {
                state.CurrentGame = new Game {Data = new List<GameData>(), TimeStamp = timestamp};
                state.Replay.Games.Add(state.CurrentGame);
                state.Node = new Node(typeof(Game), state.CurrentGame, 0, null);
                return;
            }

            var match = Regexes.ActionCreategameRegex.Match(data);
            if(match.Success)
            {
                var id = match.Groups[1].Value;
                Debug.Assert(id == "1");
                var gEntity = new GameEntity {Id = int.Parse(id), Tags = new List<Tag>()};
                state.CurrentGame.Data.Add(gEntity);
                state.Node = new Node(typeof(GameEntity), gEntity, indentLevel, state.Node);
                return;
            }

            match = Regexes.ActionCreategamePlayerRegex.Match(data);
            if(match.Success)
            {
                var id = match.Groups[1].Value;
                var playerId = match.Groups[2].Value;
                var accountHi = match.Groups[3].Value;
                var accountLo = match.Groups[4].Value;
                var pEntity = new PlayerEntity
                {
                    Id = int.Parse(id),
                    AccountHi = accountHi,
                    AccountLo = accountLo,
                    PlayerId = int.Parse(playerId),
                    Tags = new List<Tag>()
                };
                state.UpdateCurrentNode(typeof(Game));
                state.CurrentGame.Data.Add(pEntity);
                state.Node = new Node(typeof(PlayerEntity), pEntity, indentLevel, state.Node);
                return;
            }

            match = Regexes.ActionStartRegex.Match(data);
            if(match.Success)
            {
                var rawEntity = match.Groups[1].Value;
                var rawType = match.Groups[2].Value;
                var index = match.Groups[3].Value;
                var rawTarget = match.Groups[4].Value;
                var entity = Helper.ParseEntity(rawEntity, state);
                var target = Helper.ParseEntity(rawTarget, state);
                var type = Helper.ParseEnum<PowSubType>(rawType);
                var action = new Action
                {
                    Data = new List<GameData>(),
                    Entity = entity,
                    Index = int.Parse(index),
                    Target = target,
                    TimeStamp = timestamp,
                    Type = type
                };
                state.UpdateCurrentNode(typeof(Game), typeof(Action));
                if(state.Node.Type == typeof(Game))
                    ((Game)state.Node.Object).Data.Add(action);
                else if(state.Node.Type == typeof(Action))
                    ((Action)state.Node.Object).Data.Add(action);
                else
                    throw new Exception("Invalid node " + state.Node.Type);
                state.Node = new Node(typeof(Action), action, indentLevel, state.Node);
                return;
            }

            match = Regexes.ActionMetadataRegex.Match(data);
            if(match.Success)
            {
                var rawMeta = match.Groups[1].Value;
                var rawData = match.Groups[2].Value;
                var info = match.Groups[3].Value;
                var parsedData = Helper.ParseEntity(rawData, state);
                var meta = Helper.ParseEnum<MetaDataType>(rawMeta);
                var metaData = new MetaData {Data = parsedData, Info = int.Parse(info), Meta = meta, MetaInfo = new List<Info>()};
                state.UpdateCurrentNode(typeof(Action));
                if(state.Node.Type == typeof(Action))
                    ((Action)state.Node.Object).Data.Add(metaData);
                else
                    throw new Exception("Invalid node " + state.Node.Type);
                state.Node = new Node(typeof(MetaData), metaData, indentLevel, state.Node);
                return;
            }

//.........這裏部分代碼省略.........
開發者ID:sebastientromp,項目名稱:HSReplay,代碼行數:101,代碼來源:DataHandler.cs


注:本文中的System.ParserState.UpdateCurrentNode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。