コード例 #1
0
        public override bool LoadFromDBCommand(CommandRequest cq)
        {
            CommandID        = cq.CommandID;
            CommandRequestID = cq.CommandRequestID;
            Priority         = cq.Priority;
            CommandDetails   = cq.CommandDetails;
            DateTimeUpdated  = cq.DateTimeUpdated;

            // read xml to get parameters
            if (CommandDetails.Trim().Length > 0)
            {
                XmlDocument docCreator = new XmlDocument();
                docCreator.LoadXml(CommandDetails);

                // populate the fields
                TvDBSeriesID =
                    int.Parse(TryGetProperty(docCreator, "CommandRequest_TvDBUpdateSeries", "TvDBSeriesID"));
                ForceRefresh =
                    bool.Parse(TryGetProperty(docCreator, "CommandRequest_TvDBUpdateSeries",
                                              "ForceRefresh"));
                SeriesTitle =
                    TryGetProperty(docCreator, "CommandRequest_TvDBUpdateSeries",
                                   "SeriesTitle");
                if (string.IsNullOrEmpty(SeriesTitle))
                {
                    SeriesTitle = RepoFactory.TvDB_Series.GetByTvDBID(TvDBSeriesID)?.SeriesName ??
                                  string.Intern("Name not Available");
                }
            }

            return(true);
        }
コード例 #2
0
        public override bool LoadFromDBCommand(CommandRequest cq)
        {
            CommandID        = cq.CommandID;
            CommandRequestID = cq.CommandRequestID;
            Priority         = cq.Priority;
            CommandDetails   = cq.CommandDetails;
            DateTimeUpdated  = cq.DateTimeUpdated;

            // read xml to get parameters
            if (CommandDetails.Trim().Length > 0)
            {
                XmlDocument docCreator = new XmlDocument();
                docCreator.LoadXml(CommandDetails);

                // populate the fields
                animeID   = int.Parse(TryGetProperty(docCreator, "CommandRequest_LinkAniDBTvDB", "animeID"));
                aniEpType = (EpisodeType)Enum.Parse(typeof(EpisodeType),
                                                    TryGetProperty(docCreator, "CommandRequest_LinkAniDBTvDB", "aniEpType"));
                aniEpNumber    = int.Parse(TryGetProperty(docCreator, "CommandRequest_LinkAniDBTvDB", "aniEpNumber"));
                tvDBID         = int.Parse(TryGetProperty(docCreator, "CommandRequest_LinkAniDBTvDB", "tvDBID"));
                tvSeasonNumber = int.Parse(
                    TryGetProperty(docCreator, "CommandRequest_LinkAniDBTvDB", "tvSeasonNumber"));
                tvEpNumber          = int.Parse(TryGetProperty(docCreator, "CommandRequest_LinkAniDBTvDB", "tvEpNumber"));
                excludeFromWebCache = bool.Parse(
                    TryGetProperty(docCreator, "CommandRequest_LinkAniDBTvDB", "excludeFromWebCache"));
                additiveLink = bool.Parse(
                    TryGetProperty(docCreator, "CommandRequest_LinkAniDBTvDB", "additiveLink"));
            }

            return(true);
        }
コード例 #3
0
        public async Task TestAttackWithNotEnoughUnits(string attacker, string target)
        {
            var defendingCommand = await context.Commands.Include(c => c.Divisions)
                                   .ThenInclude(d => d.Unit)
                                   .SingleAsync(c => c.ParentCountry.ParentUser.UserName == attacker);

            var targetCountry = await context.Countries.SingleAsync(c => c.ParentUser.UserName == target);

            var normalDivision = defendingCommand.Divisions.First(d => !(d.Unit is LeaderType));
            var leaderDivision = defendingCommand.Divisions.First(d => d.Unit is LeaderType);
            var commandDetails = new CommandDetails
            {
                TargetCountryId = targetCountry.Id,
                Units           = new List <UnitDetails>
                {
                    new UnitDetails
                    {
                        UnitId = normalDivision.Unit.Id,
                        Amount = normalDivision.Count + 1
                    },
                    new UnitDetails
                    {
                        UnitId = leaderDivision.Unit.Id,
                        Amount = leaderDivision.Count
                    }
                }
            };

            await commandService.AttackTargetAsync(attacker, commandDetails);
        }
コード例 #4
0
        public override bool InitFromDB(CommandRequest cq)
        {
            CommandID        = cq.CommandID;
            CommandRequestID = cq.CommandRequestID;
            CommandType      = cq.CommandType;
            Priority         = cq.Priority;
            CommandDetails   = cq.CommandDetails;
            DateTimeUpdated  = cq.DateTimeUpdated;

            // read xml to get parameters
            if (CommandDetails.Trim().Length > 0)
            {
                XmlDocument docCreator = new XmlDocument();
                docCreator.LoadXml(CommandDetails);

                // populate the fields
                Hash = TryGetProperty(docCreator, "CommandRequest_AddFileToMyList", "Hash");
            }

            if (Hash.Trim().Length <= 0)
            {
                return(false);
            }
            vid = RepoFactory.VideoLocal.GetByHash(Hash);
            return(true);
        }
コード例 #5
0
        /// <summary>
        /// Formats the list of command examples.
        /// </summary>
        private string FormatCommandExamples(string prefix, CommandDetails cmd)
        {
            string[] examples = new string[cmd.Examples.Count];
            for (int i = 0; i < cmd.Examples.Count; i++)
            {
                Example example = cmd.Examples[i];

                /*if (string.IsNullOrWhiteSpace(example.Execution)) {
                 *      if (string.IsNullOrWhiteSpace(example.Explanation)) {
                 *              examples[i] = $"‣ {FormatCommand($"{prefix}{cmd.Alias}")}";
                 *      }
                 *      else {
                 *              examples[i] = $"‣ {FormatCommand($"{prefix}{cmd.Alias}")} **-** {example.Explanation}";
                 *      }
                 * }
                 * else {*/
                if (string.IsNullOrWhiteSpace(example.Explanation))
                {
                    examples[i] = $"‣ {FormatCommand($"{prefix}{example.Execution}")}";
                }
                else
                {
                    examples[i] = $"‣ {FormatCommand($"{prefix}{example.Execution}")} **-** {example.Explanation}";
                }
                //}
            }
            return(string.Join("\n", examples));
        }
コード例 #6
0
        public override bool LoadFromDBCommand(CommandRequest cq)
        {
            CommandID        = cq.CommandID;
            CommandRequestID = cq.CommandRequestID;
            Priority         = cq.Priority;
            CommandDetails   = cq.CommandDetails;
            DateTimeUpdated  = cq.DateTimeUpdated;

            // read xml to get parameters
            if (CommandDetails.Trim().Length > 0)
            {
                XmlDocument docCreator = new XmlDocument();
                docCreator.LoadXml(CommandDetails);

                // populate the fields
                FileName  = TryGetProperty(docCreator, "CommandRequest_HashFile", "FileName");
                ForceHash = bool.Parse(TryGetProperty(docCreator, "CommandRequest_HashFile", "ForceHash"));
            }

            if (FileName.Trim().Length > 0)
            {
                return(true);
            }
            return(false);
        }
コード例 #7
0
        private async Task <CommandDetails> SetUpValidAttackAsync(string attacker, string target)
        {
            var defendingCommand = await context.Commands.Include(c => c.Divisions)
                                   .ThenInclude(d => d.Unit)
                                   .SingleAsync(c => c.ParentCountry.ParentUser.UserName == attacker);

            var targetCountry = await context.Countries.SingleAsync(c => c.ParentUser.UserName == target);

            var normalDivision = defendingCommand.Divisions.First(d => !(d.Unit is LeaderType));
            var leaderDivision = defendingCommand.Divisions.First(d => d.Unit is LeaderType);
            var commandDetails = new CommandDetails
            {
                TargetCountryId = targetCountry.Id,
                Units           = new List <UnitDetails>
                {
                    new UnitDetails
                    {
                        UnitId = normalDivision.Unit.Id,
                        Amount = normalDivision.Count
                    },
                    new UnitDetails
                    {
                        UnitId = leaderDivision.Unit.Id,
                        Amount = leaderDivision.Count
                    }
                }
            };

            return(commandDetails);
        }
コード例 #8
0
        public override bool LoadFromDBCommand(CommandRequest cq)
        {
            CommandID        = cq.CommandID;
            CommandRequestID = cq.CommandRequestID;
            Priority         = cq.Priority;
            CommandDetails   = cq.CommandDetails;
            DateTimeUpdated  = cq.DateTimeUpdated;

            // read xml to get parameters
            if (CommandDetails.Trim().Length <= 0)
            {
                return(true);
            }
            XmlDocument docCreator = new XmlDocument();

            docCreator.LoadXml(CommandDetails);

            // populate the fields
            VideoLocalID = int.Parse(TryGetProperty(docCreator, "CommandRequest_ProcessFile", "VideoLocalID"));
            ForceAniDB   = bool.Parse(TryGetProperty(docCreator, "CommandRequest_ProcessFile", "ForceAniDB"));
            SkipMyList   = bool.Parse(TryGetProperty(docCreator, "CommandRequest_ProcessFile", "SkipMyList"));
            vlocal       = RepoFactory.VideoLocal.GetByID(VideoLocalID);

            return(true);
        }
コード例 #9
0
        public override bool LoadFromDBCommand(CommandRequest cq)
        {
            CommandID        = cq.CommandID;
            CommandRequestID = cq.CommandRequestID;
            Priority         = cq.Priority;
            CommandDetails   = cq.CommandDetails;
            DateTimeUpdated  = cq.DateTimeUpdated;

            // read xml to get parameters
            if (CommandDetails.Trim().Length > 0)
            {
                XmlDocument docCreator = new XmlDocument();
                docCreator.LoadXml(CommandDetails);

                // populate the fields
                AnimeID = int.Parse(TryGetProperty(docCreator, "CommandRequest_GetAnimeHTTP", "AnimeID"));
                if (RepoFactory.AniDB_Anime.GetByAnimeID(AnimeID) == null)
                {
                    Priority = (int)CommandRequestPriority.Priority1;
                }
                DownloadRelations =
                    bool.Parse(TryGetProperty(docCreator, "CommandRequest_GetAnimeHTTP", "DownloadRelations"));
                ForceRefresh = bool.Parse(
                    TryGetProperty(docCreator, "CommandRequest_GetAnimeHTTP", "ForceRefresh"));
                RelDepth = int.Parse(TryGetProperty(docCreator, nameof(CommandRequest_GetAnimeHTTP), nameof(RelDepth)));
            }

            return(true);
        }
コード例 #10
0
        public override bool LoadFromDBCommand(CommandRequest cq)
        {
            CommandID        = cq.CommandID;
            CommandRequestID = cq.CommandRequestID;
            Priority         = cq.Priority;
            CommandDetails   = cq.CommandDetails;
            DateTimeUpdated  = cq.DateTimeUpdated;

            // read xml to get parameters
            if (CommandDetails.Trim().Length > 0)
            {
                XmlDocument docCreator = new XmlDocument();
                docCreator.LoadXml(CommandDetails);

                // populate the fields
                Hash = TryGetProperty(docCreator, "CommandRequest_AddFileToMyList", "Hash");
                string read = TryGetProperty(docCreator, "CommandRequest_AddFileToMyList", "ReadStates");
                if (!bool.TryParse(read, out bool read_states))
                {
                    read_states = true;
                }
                ReadStates = read_states;
            }

            if (Hash.Trim().Length <= 0)
            {
                return(false);
            }
            vid = RepoFactory.VideoLocal.GetByHash(Hash);
            return(true);
        }
コード例 #11
0
        public override bool LoadFromDBCommand(CommandRequest cq)
        {
            CommandID        = cq.CommandID;
            CommandRequestID = cq.CommandRequestID;
            Priority         = cq.Priority;
            CommandDetails   = cq.CommandDetails;
            DateTimeUpdated  = cq.DateTimeUpdated;

            // read xml to get parameters
            if (CommandDetails.Trim().Length > 0)
            {
                XmlDocument docCreator = new XmlDocument();
                docCreator.LoadXml(CommandDetails);

                // populate the fields
                Hash     = TryGetProperty(docCreator, "CommandRequest_DeleteFileFromMyList", "Hash");
                FileSize = long.Parse(
                    TryGetProperty(docCreator, "CommandRequest_DeleteFileFromMyList", "FileSize"));
                MyListID = int.Parse(TryGetProperty(docCreator, "CommandRequest_DeleteFileFromMyList", "MyListID"));
            }

            if (Hash.Trim().Length > 0)
            {
                return(true);
            }
            return(false);
        }
コード例 #12
0
        public async Task TestModifyCommand(string attacker, string defender)
        {
            var commandDetails = await SetUpValidAttackAsync(attacker, defender);

            var info = await commandService.AttackTargetAsync(attacker, commandDetails);

            var newDetails = new CommandDetails
            {
                TargetCountryId = info.TargetCountryId,
                Units           = new List <UnitDetails>
                {
                    new UnitDetails
                    {
                        UnitId = info.Units.First().Id,
                        Amount = info.Units.First().Count - 10
                    },
                    new UnitDetails
                    {
                        UnitId = info.Units.Last().Id,
                        Amount = info.Units.Last().Count
                    }
                }
            };

            var newInfo = await commandService.UpdateCommandAsync(attacker, info.Id, newDetails);

            Assert.AreEqual(2, newInfo.Units.Count());
            Assert.AreEqual(newDetails.Units.First().UnitId, newInfo.Units.First().Id);
            Assert.AreEqual(newDetails.Units.First().Amount, newInfo.Units.First().Count);
        }
コード例 #13
0
        public override bool LoadFromDBCommand(CommandRequest cq)
        {
            CommandID        = cq.CommandID;
            CommandRequestID = cq.CommandRequestID;
            Priority         = cq.Priority;
            CommandDetails   = cq.CommandDetails;
            DateTimeUpdated  = cq.DateTimeUpdated;

            NumberStyles style   = NumberStyles.Number;
            CultureInfo  culture = CultureInfo.CreateSpecificCulture("en-GB");

            // read xml to get parameters
            if (CommandDetails.Trim().Length > 0)
            {
                XmlDocument docCreator = new XmlDocument();
                docCreator.LoadXml(CommandDetails);

                // populate the fields
                AnimeID   = int.Parse(TryGetProperty(docCreator, "CommandRequest_VoteAnime", "AnimeID"));
                VoteType  = int.Parse(TryGetProperty(docCreator, "CommandRequest_VoteAnime", "VoteType"));
                VoteValue = decimal.Parse(TryGetProperty(docCreator, "CommandRequest_VoteAnime", "VoteValue"),
                                          style, culture);
            }

            return(true);
        }
コード例 #14
0
        /// <summary>
        /// Builds an embed displaying command help.
        /// </summary>
        /// <param name="context">The context of the command.</param>
        /// <param name="command">The command to build the help for.</param>
        /// <returns>The built embed.</returns>
        public async Task <Embed> BuildCommandHelpAsync(ICommandContext context, CommandDetails command)
        {
            var(prefix, lockContext) = await GetPrefixAndLockContextAsync(context).ConfigureAwait(false);

            var embed = new EmbedBuilder {
                Color       = configParser.EmbedColor,
                Title       = FormatCommandTitle(prefix, lockContext, command),
                Description = command.Summary,
            };

            if (command.Aliases.Count > 1)
            {
                embed.AddField("Aliases", FormatCommandAliases(command));
            }

            embed.AddField("Usage", FormatCommandUsage(prefix, command));

            if (command.Examples.Any())
            {
                embed.AddField("Examples", FormatCommandExamples(prefix, command));
            }

            if (!string.IsNullOrWhiteSpace(command.Remarks))
            {
                embed.AddField("Remarks", command.Remarks);
            }

            if (!string.IsNullOrWhiteSpace(command.ImageUrl))
            {
                embed.WithImageUrl(command.ImageUrl);
            }

            return(embed.Build());
        }
コード例 #15
0
        public override bool LoadFromDBCommand(CommandRequest cq)
        {
            CommandID        = cq.CommandID;
            CommandRequestID = cq.CommandRequestID;
            Priority         = cq.Priority;
            CommandDetails   = cq.CommandDetails;
            DateTimeUpdated  = cq.DateTimeUpdated;

            // read xml to get parameters
            if (CommandDetails.Trim().Length > 0)
            {
                XmlDocument docCreator = new XmlDocument();
                docCreator.LoadXml(CommandDetails);

                // populate the fields
                TvDBEpisodeID =
                    int.Parse(TryGetProperty(docCreator, "CommandRequest_TvDBUpdateEpisode", "TvDBEpisodeID"));
                ForceRefresh =
                    bool.Parse(TryGetProperty(docCreator, "CommandRequest_TvDBUpdateEpisode",
                                              "ForceRefresh"));
                DownloadImages =
                    bool.Parse(TryGetProperty(docCreator, "CommandRequest_TvDBUpdateEpisode",
                                              "DownloadImages"));
                InfoString =
                    TryGetProperty(docCreator, "CommandRequest_TvDBUpdateEpisode",
                                   "InfoString");
            }

            return(true);
        }
コード例 #16
0
        public override bool LoadFromDBCommand(CommandRequest cq)
        {
            CommandID        = cq.CommandID;
            CommandRequestID = cq.CommandRequestID;
            Priority         = cq.Priority;
            CommandDetails   = cq.CommandDetails;
            DateTimeUpdated  = cq.DateTimeUpdated;

            // read xml to get parameters
            if (CommandDetails.Trim().Length > 0)
            {
                XmlDocument docCreator = new XmlDocument();
                docCreator.LoadXml(CommandDetails);

                // populate the fields
                VideoLocalID = int.Parse(TryGetProperty(docCreator, "CommandRequest_LinkFileManually", "VideoLocalID"));
                EpisodeID    = int.Parse(TryGetProperty(docCreator, "CommandRequest_LinkFileManually", "EpisodeID"));
                Percentage   = int.Parse(TryGetProperty(docCreator, "CommandRequest_LinkFileManually", "Percentage"));
                vlocal       = RepoFactory.VideoLocal.GetByID(VideoLocalID);
                if (null == vlocal)
                {
                    logger.Info("videolocal object {0} not found", VideoLocalID);
                    return(false);
                }
                episode = RepoFactory.AnimeEpisode.GetByID(EpisodeID);
            }

            return(true);
        }
コード例 #17
0
 public async Task <ActionResult <CommandInfo> > UpdateCommandAsync(int id, [FromBody] CommandDetails command)
 {
     using (var src = new CancellationTokenSource(Constants.DefaultTurnEndTimeout))
     {
         return(Ok(await _commandService.UpdateCommandAsync(User.Identity.Name, id, command, src.Token)));
     }
 }
        public override bool InitFromDB(CommandRequest cq)
        {
            CommandID        = cq.CommandID;
            CommandRequestID = cq.CommandRequestID;
            CommandType      = cq.CommandType;
            Priority         = cq.Priority;
            CommandDetails   = cq.CommandDetails;
            DateTimeUpdated  = cq.DateTimeUpdated;

            // read xml to get parameters
            if (CommandDetails.Trim().Length > 0)
            {
                XmlDocument docCreator = new XmlDocument();
                docCreator.LoadXml(CommandDetails);

                // populate the fields
                AnimeID =
                    int.Parse(TryGetProperty(docCreator, "CommandRequest_WebCacheDeleteXRefAniDBTrakt", "AnimeID"));
                AniDBStartEpisodeType =
                    int.Parse(TryGetProperty(docCreator, "CommandRequest_WebCacheDeleteXRefAniDBTrakt",
                                             "AniDBStartEpisodeType"));
                AniDBStartEpisodeNumber =
                    int.Parse(TryGetProperty(docCreator, "CommandRequest_WebCacheDeleteXRefAniDBTrakt",
                                             "AniDBStartEpisodeNumber"));
                TraktID           = TryGetProperty(docCreator, "CommandRequest_WebCacheDeleteXRefAniDBTrakt", "TraktID");
                TraktSeasonNumber =
                    int.Parse(TryGetProperty(docCreator, "CommandRequest_WebCacheDeleteXRefAniDBTrakt",
                                             "TraktSeasonNumber"));
                TraktStartEpisodeNumber =
                    int.Parse(TryGetProperty(docCreator, "CommandRequest_WebCacheDeleteXRefAniDBTrakt",
                                             "TraktStartEpisodeNumber"));
            }

            return(true);
        }
コード例 #19
0
        public override bool LoadFromDBCommand(CommandRequest cq)
        {
            CommandID        = cq.CommandID;
            CommandRequestID = cq.CommandRequestID;
            Priority         = cq.Priority;
            CommandDetails   = cq.CommandDetails;
            DateTimeUpdated  = cq.DateTimeUpdated;

            // read xml to get parameters
            if (CommandDetails.Trim().Length > 0)
            {
                XmlDocument docCreator = new XmlDocument();
                docCreator.LoadXml(CommandDetails);

                // populate the fields
                if (!int.TryParse(TryGetProperty(docCreator, "CommandRequest_GetFileMyListStatus", "AniFileID"),
                                  out int ID))
                {
                    return(false);
                }
                AniFileID = ID;

                FileName = TryGetProperty(docCreator, "CommandRequest_GetFileMyListStatus", "FileName");
            }
            return(true);
        }
コード例 #20
0
        public override bool InitFromDB(CommandRequest cq)
        {
            CommandID        = cq.CommandID;
            CommandRequestID = cq.CommandRequestID;
            CommandType      = cq.CommandType;
            Priority         = cq.Priority;
            CommandDetails   = cq.CommandDetails;
            DateTimeUpdated  = cq.DateTimeUpdated;

            // read xml to get parameters
            if (CommandDetails.Trim().Length > 0)
            {
                XmlDocument docCreator = new XmlDocument();
                docCreator.LoadXml(CommandDetails);

                // populate the fields
                AnimeID           = int.Parse(TryGetProperty(docCreator, "CommandRequest_GetAnimeHTTP", "AnimeID"));
                DownloadRelations =
                    bool.Parse(TryGetProperty(docCreator, "CommandRequest_GetAnimeHTTP", "DownloadRelations"));
                ForceRefresh = bool.Parse(
                    TryGetProperty(docCreator, "CommandRequest_GetAnimeHTTP", "ForceRefresh"));
            }

            return(true);
        }
コード例 #21
0
 /// <summary>
 /// Formats the command usage.
 /// </summary>
 private string FormatCommandUsage(string prefix, CommandDetails cmd)
 {
     if (string.IsNullOrWhiteSpace(cmd.Usage))
     {
         return(FormatCommand($"{prefix}{cmd.Alias}"));
     }
     return(FormatCommand($"{prefix}{cmd.Alias} {cmd.Usage}"));
 }
コード例 #22
0
 /// <summary>
 /// Gets if the specified command or its module is locked.
 /// </summary>
 /// <param name="command">The command to check.</param>
 /// <param name="lockContext">The lockable context to work with.</param>
 /// <returns>True if the command or its module is locked.</returns>
 public static bool IsLocked(this CommandDetails command, IDbLockableContext lockContext)
 {
     if (lockContext == null)
     {
         return(command.IsLockedByDefault || command.Module.IsLockedByDefault);
     }
     return(command.IsCommandLocked(lockContext) || command.Module.IsModuleLocked(lockContext));
 }
コード例 #23
0
 /// <summary>
 /// Gets if the specified command is locked.
 /// </summary>
 /// <param name="command">The command to check.</param>
 /// <param name="lockContext">The lockable context to work with.</param>
 /// <returns>True if the command is locked.</returns>
 public static bool IsCommandLocked(this CommandDetails command, IDbLockableContext lockContext)
 {
     if (lockContext == null)
     {
         return(command.IsLockedByDefault);
     }
     return(command.IsLockable && command.IsLockedByDefault !=
            lockContext.LockedCommands.Contains(command.Alias));
 }
コード例 #24
0
ファイル: CommandService.cs プロジェクト: gszasza1/UnderSea
        public async Task <CommandInfo> AttackTargetAsync(string username, CommandDetails details)
        {
            var country = await _context.Countries.Include(c => c.Commands)
                          .ThenInclude(c => c.Divisions)
                          .ThenInclude(d => d.Unit)
                          .ThenInclude(u => u.Content)
                          .SingleAsync(c => c.ParentUser.UserName == username);

            var targetCountry = await _context.Countries.FindAsync(details.TargetCountryId);

            if (targetCountry == null)
            {
                throw new ArgumentOutOfRangeException(nameof(details.TargetCountryId), "Invalid country id.");
            }

            var defendingCommand = country.GetAllDefending();
            var attackingCommand = new Command
            {
                TargetCountry = targetCountry,
                ParentCountry = country
            };

            foreach (var detail in details.Units)
            {
                var defendingDivision = defendingCommand.Divisions.SingleOrDefault(d => d.Unit.Id == detail.UnitId);
                if (defendingDivision == null)
                {
                    throw new ArgumentOutOfRangeException(nameof(detail.UnitId), "Invalid unit id.");
                }

                if (defendingDivision.Count < detail.Amount)
                {
                    throw new ArgumentException("Not enough units.");
                }

                defendingDivision.Count -= detail.Amount;
                var attackingDivision = new Division
                {
                    Unit          = defendingDivision.Unit,
                    ParentCommand = attackingCommand,
                    Count         = detail.Amount
                };

                _context.Divisions.Add(attackingDivision);
            }

            if (!attackingCommand.Divisions.Any(d => d.Unit is LeaderType && d.Count > 0))
            {
                throw new InvalidOperationException("Every attack must contain a leader.");
            }

            _context.Commands.Add(attackingCommand);
            await _context.SaveChangesAsync();

            return(ToCommandInfo(attackingCommand, _mapper));
        }
コード例 #25
0
 // Update is called once per frame
 void Update()
 {
     if (UICamera.hoveredObject != null)
     {
         // get current hoveredObject
         //Debug.Log (UICamera.hoveredObject);
         //Debug.Log (UICamera.hoveredObject.GetComponent("CommandDetails"));
         CommandDetails test = UICamera.hoveredObject.GetComponent("CommandDetails") as CommandDetails;
         description.text = test._message;
     }
 }
コード例 #26
0
        public void TriggerThreadProfile()
        {
            var threadProfileArguments = new Dictionary <string, object>();

            threadProfileArguments["profile_id"]    = -1;
            threadProfileArguments["sample_period"] = 0.1F; //Agent enforces minimums
            threadProfileArguments["duration"]      = 120;  //Agent enforces minimums

            var threadProfileDetails = new CommandDetails("start_profiler", threadProfileArguments);
            var threadProfileCommand = new AgentCommand(-1, threadProfileDetails);

            _queuedCommands.Add(threadProfileCommand);
        }
コード例 #27
0
            public async Task HelpSearchCommand([Remainder] string commandName)
            {
                commandName = string.Join(" ", commandName.Trim().Split(' '));
                CommandDetails command = Commands.CommandSet.FindCommand(commandName, Context);

                if (command == null)
                {
                    await ReplyAsync($"No command with the name `{commandName}` exists").ConfigureAwait(false);
                }
                else
                {
                    await ReplyAsync(embed : await help.BuildCommandHelpAsync(Context, command).ConfigureAwait(false)).ConfigureAwait(false);
                }
            }
コード例 #28
0
        public async Task TestAttackNotExistingTarget(string attacker)
        {
            var commandDetails = new CommandDetails
            {
                TargetCountryId = -1,
                Units           = new List <UnitDetails>
                {
                    new UnitDetails
                    {
                        UnitId = -1,
                        Amount = 5
                    }
                }
            };

            await commandService.AttackTargetAsync(attacker, commandDetails);
        }
コード例 #29
0
        public void TriggerCustomInstrumentationEditorAgentCommand()
        {
            var configObj = new Dictionary <string, object>
            {
                ["config"] = _liveInstrumentation
            };

            var liveInstrumentationAgentCommandArguments = new Dictionary <string, object>
            {
                ["instrumentation"] = configObj
            };

            var liveInstrumentationAgentCommandDetails = new CommandDetails("instrumentation_update", liveInstrumentationAgentCommandArguments);
            var liveInstrumentationAgentCommand        = new AgentCommand(-1, liveInstrumentationAgentCommandDetails);

            _queuedCommands.Add(liveInstrumentationAgentCommand);
        }
コード例 #30
0
        public override bool LoadFromDBCommand(CommandRequest cq)
        {
            CommandID        = cq.CommandID;
            CommandRequestID = cq.CommandRequestID;
            Priority         = cq.Priority;
            CommandDetails   = cq.CommandDetails;
            DateTimeUpdated  = cq.DateTimeUpdated;

            // read xml to get parameters
            if (CommandDetails.Trim().Length > 0)
            {
                XmlDocument docCreator = new XmlDocument();
                docCreator.LoadXml(CommandDetails);
            }

            return(true);
        }