예제 #1
0
파일: nametree.cs 프로젝트: hlorenzi/trapl
        public void Add(Name name, T value)
        {
            if (name.identifiers.Length == 0)
            {
                throw new System.ArgumentException("empty name");
            }

            var curIdentifier = 0;
            var curGroup      = globalGroup;

            while (curIdentifier < name.identifiers.Length)
            {
                IdentifierGroup nextGroup;
                if (!curGroup.innerGroups.TryGetValue(name.identifiers[curIdentifier], out nextGroup))
                {
                    nextGroup = new IdentifierGroup();
                    curGroup.innerGroups.Add(name.identifiers[curIdentifier], nextGroup);
                }

                curGroup = nextGroup;
                curIdentifier++;
            }

            if (curGroup.hasValue)
            {
                throw new System.ArgumentException("duplicate name");
            }

            curGroup.hasValue = true;
            curGroup.value    = value;
        }
예제 #2
0
        /// <summary>
        /// Get all the unique identifiers of the commands that match the input request settings
        /// </summary>
        private static async Task <IEnumerable <string> > AllLeaguesIdentifierGroupProcess(
            LeaguesIdentifierGroup_Request request,
            ILogger log)
        {
            #region Logging
            if (null != log)
            {
                log.LogInformation($"Creating identifier group processor for leagues");
            }
            #endregion

            #region Input validations
            // If as of date is stupid, clear it
            if (request.AsOfDate.HasValue)
            {
                if (request.AsOfDate.Value.Year < 2000)
                {
                    request.AsOfDate = null;
                }
            }
            #endregion

            IdentifierGroup allLeagues = new IdentifierGroup("Leagues",
                                                             "League",
                                                             "All leagues");

            if (null != allLeagues)
            {
                return(await allLeagues.GetAll(request.AsOfDate));
            }
            else
            {
                return(Enumerable.Empty <string>());
            }
        }
        /// <summary>
        /// Get all the unique identifiers of the commands that match the input request settings
        /// </summary>
        private static async Task <IEnumerable <string> > AllCommandsIdentifierGroupProcess(
            AllCommandsIdentifierGroup_Request request,
            ILogger log)
        {
            #region Logging
            if (null != log)
            {
                log.LogInformation($"Creating identifier group processor for {request.CommandName}");
            }
            #endregion

            #region Input validations
            // If no match status, default to ALL
            if (string.IsNullOrWhiteSpace(request.MatchStatus))
            {
                request.MatchStatus = @"All";
            }
            // If as of date is stupid, clear it
            if (request.AsOfDate.HasValue)
            {
                if (request.AsOfDate.Value.Year < 2000)
                {
                    request.AsOfDate = null;
                }
            }
            #endregion

            IdentifierGroup allCommands = new IdentifierGroup(Constants.Domain_Command,
                                                              request.CommandName,
                                                              request.MatchStatus);

            if (null != allCommands)
            {
                return(await allCommands.GetAll(request.AsOfDate));
            }
            else
            {
                return(Enumerable.Empty <string>());
            }
        }
예제 #4
0
파일: nametree.cs 프로젝트: hlorenzi/trapl
        private IEnumerable <System.Tuple <Name, T> > EnumerateGroup(List <string> path, IdentifierGroup group)
        {
            if (group.hasValue)
            {
                yield return(new System.Tuple <Name, T>(Name.FromPath(path.ToArray()), group.value));
            }

            foreach (var innerGroup in group.innerGroups)
            {
                path.Add(innerGroup.Key);
                foreach (var value in this.EnumerateGroup(path, innerGroup.Value))
                {
                    yield return(value);
                }
                path.RemoveAt(path.Count - 1);
            }
        }