Beispiel #1
0
        public override async Task RunAsync()
        {
            var agents = PhotonServer.Instance.Agents.All
                         .Where(x => AgentIds.Any(id => string.Equals(id, x.Id, StringComparison.OrdinalIgnoreCase))).ToArray();

            if (!agents.Any())
            {
                Output.WriteLine("No agents were found!", ConsoleColor.DarkYellow);
                throw new ApplicationException("No agents were found!");
            }

            var queueOptions = new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = Configuration.Parallelism,
                CancellationToken      = TokenSource.Token,
            };

            var queue = new ActionBlock <ServerAgent>(AgentAction, queueOptions);

            foreach (var agent in agents)
            {
                queue.Post(agent);
            }

            queue.Complete();
            await queue.Completion;
        }
Beispiel #2
0
        private bool IncludesAgent(string agentName)
        {
            if (!(AgentIds?.Any() ?? false))
            {
                return(true);
            }

            foreach (var name in AgentIds)
            {
                var escapedName = Regex.Escape(name)
                                  .Replace("\\?", ".")
                                  .Replace("\\*", ".*");

                var namePattern = $"^{escapedName}$";
                if (Regex.IsMatch(agentName, namePattern, RegexOptions.IgnoreCase))
                {
                    return(true);
                }
            }

            return(false);
        }