コード例 #1
0
        public static async Task <GetHenchmenReply> GetHenchmenAsync(GetHenchmenRequest request, ServerCallContext context)
        {
            using var db = new LegendaryDatabase();
            var connector = DbConnector.Create(db.Connection, new DbConnectorSettings {
                AutoOpen = true, LazyOpen = true
            });

            var reply = new GetHenchmenReply {
                Status = new Status {
                    Code = 200
                }
            };

            if (request.Fields.Count() == 0)
            {
                request.Fields.AddRange(DatabaseDefinition.BasicFields);
            }

            // Need to remove abilityIds field because it's handled separately from the main db request
            var includeAbilityIds = request.Fields.Remove(HenchmanField.HenchmanAbilityIds);

            var select = DatabaseDefinition.BuildSelectStatement(request.Fields);
            var joins  = DatabaseDefinition.BuildRequiredJoins(request.Fields);

            var where = !string.IsNullOrWhiteSpace(request.Name) ?
                        $"where { DatabaseDefinition.BuildWhereStatement(HenchmanField.HenchmanName, DatabaseUtility.GetWhereComparisonType(request.NameMatchStyle))}" :
                        request.HenchmanIds.Count() != 0 ?
                        $"where { DatabaseDefinition.BuildWhereStatement(HenchmanField.HenchmanId, WhereStatementType.Includes)}" :
                        "";

            var whereMatch = !string.IsNullOrWhiteSpace(request.Name) ?
                             new (string, object)[] { (DatabaseDefinition.GetSelectResult(HenchmanField.HenchmanName), request.NameMatchStyle == NameMatchStyle.Similar ? $"%{request.Name}%" : request.Name) } :
コード例 #2
0
        public static async Task <IReadOnlyList <Henchman> > GetHenchmenAsync(GameServiceClient client, IReadOnlyList <int> henchmanIds = null, string name = null, NameMatchStyle nameMatchStyle = NameMatchStyle.MixedCase)
        {
            var request = new GetHenchmenRequest();

            if (henchmanIds != null && henchmanIds.Count() != 0)
            {
                request.HenchmanIds.AddRange(henchmanIds);
            }
            else if (!string.IsNullOrWhiteSpace(name))
            {
                request.Name = name;
            }

            request.NameMatchStyle = nameMatchStyle;

            return((await client.GetHenchmenAsync(request)).Henchmen);
        }
コード例 #3
0
        public static async Task <CreateHenchmenReply> CreateHenchmenAsync(CreateHenchmenRequest request, ServerCallContext context)
        {
            using var db = new LegendaryDatabase();
            var connector = DbConnector.Create(db.Connection, new DbConnectorSettings {
                AutoOpen = true, LazyOpen = true
            });

            var reply = new CreateHenchmenReply {
                Status = new Status {
                    Code = 200
                }
            };

            List <int> newHenchmenIds = new List <int>();

            foreach (var henchman in request.Henchmen)
            {
                // Validate the GamePackageId
                var packageRequest = new GetGamePackagesRequest();
                packageRequest.GamePackageIds.Add(henchman.GamePackageId);
                packageRequest.Fields.Add(GamePackageField.Id);
                var packageReply = await GamePackageUtility.GetGamePackagesAsync(packageRequest, context);

                if (packageReply.Status.Code != 200)
                {
                    reply.Status = packageReply.Status;
                    return(reply);
                }

                // Validate the AbilityIds
                var abilitiesRequest = new GetAbilitiesRequest();
                abilitiesRequest.AbilityIds.AddRange(henchman.AbilityIds);
                abilitiesRequest.AbilityFields.Add(AbilityField.Id);
                var abilitiesReply = await AbilityUtility.GetAbilitiesAsync(abilitiesRequest, context);

                if (abilitiesReply.Status.Code != 200)
                {
                    reply.Status = abilitiesReply.Status;
                    return(reply);
                }

                // Verify that this henchman doesn't already exist
                var henchmanRequest = new GetHenchmenRequest();
                henchmanRequest.Name = henchman.Name;
                henchmanRequest.Fields.AddRange(new[] { HenchmanField.HenchmanId, HenchmanField.HenchmanName, HenchmanField.HenchmanGamePackageId });
                henchmanRequest.NameMatchStyle = NameMatchStyle.MixedCase;
                var henchmanReply = await GetHenchmenAsync(henchmanRequest, context);

                if (henchmanReply.Status.Code == 200 && henchmanReply.Henchmen.Any())
                {
                    var matchingHenchman = henchmanReply.Henchmen.First();
                    reply.Status = new Status {
                        Code = 400, Message = $"Henchman {matchingHenchman.Id} with name '{matchingHenchman.Name}' was found in game package '{matchingHenchman.GamePackageId}'"
                    };
                    return(reply);
                }

                // Create the henchman
                var newHenchmanId = ((int)(await connector.Command($@"
					insert
						into {DatabaseDefinition.DefaultTableName}
							({DatabaseDefinition.ColumnName[HenchmanField.HenchmanName]})
									values (@HenchmanName);
								select last_insert_id();"                                ,
                                                                   ("HenchmanName", henchman.Name))
                                           .QuerySingleAsync <ulong>()));

                // Add to game package
                await connector.Command(
                    $@"
						insert
							into {TableNames.GamePackageHenchmen}
								({DatabaseDefinition.ColumnName[HenchmanField.HenchmanId]}, {GamePackageUtility.DatabaseDefinition.ColumnName[GamePackageField.Id]})
							values (@HenchmanId, @GamePackageId);"                            ,
                    ("HenchmanId", newHenchmanId),
                    ("GamePackageId", henchman.GamePackageId))
                .ExecuteAsync();

                // Link abilities
                foreach (var abilityId in henchman.AbilityIds)
                {
                    await connector.Command(
                        $@"
							insert
								into {TableNames.HenchmanAbilities}
									({DatabaseDefinition.ColumnName[HenchmanField.HenchmanId]}, {AbilityUtility.DatabaseDefinition.ColumnName[AbilityField.Id]})
								values (@HenchmanId, @AbilityId);"                                ,
                        ("HenchmanId", newHenchmanId),
                        ("AbilityId", abilityId))
                    .ExecuteAsync();
                }

                newHenchmenIds.Add(newHenchmanId);
            }

            // Get all of the created henchmen
            var finalRequest = new GetHenchmenRequest();

            finalRequest.HenchmanIds.AddRange(newHenchmenIds);
            var finalReply = await GetHenchmenAsync(finalRequest, context);

            reply.Status = finalReply.Status;
            reply.Henchmen.AddRange(finalReply.Henchmen);

            return(reply);
        }
コード例 #4
0
 public override async Task <GetHenchmenReply> GetHenchmen(GetHenchmenRequest request, ServerCallContext context)
 {
     return(await HenchmanUtility.GetHenchmenAsync(request, context));
 }