示例#1
0
        internal override void MergeItem(object content, JsonMergeSettings?settings)
        {
            if (!(content is JObject o))
            {
                return;
            }

            foreach (KeyValuePair <string, JToken?> contentItem in o)
            {
                JProperty?existingProperty = Property(contentItem.Key, settings?.PropertyNameComparison ?? StringComparison.Ordinal);

                if (existingProperty == null)
                {
                    Add(contentItem.Key, contentItem.Value);
                }
                else if (contentItem.Value != null)
                {
                    if (!(existingProperty.Value is JContainer existingContainer) || existingContainer.Type != contentItem.Value.Type)
                    {
                        if (!IsNull(contentItem.Value) || settings?.MergeNullValueHandling == MergeNullValueHandling.Merge)
                        {
                            existingProperty.Value = contentItem.Value;
                        }
                    }
                    else
                    {
                        existingContainer.Merge(contentItem.Value, settings);
                    }
                }
            }
示例#2
0
        /// <inheritdoc />
        public override IMetadataSchemaProvider ReadJson(
            JsonReader reader,
            Type objectType,
            IMetadataSchemaProvider?existingValue,
            bool hasExistingValue,
            JsonSerializer serializer)
        {
            if (Options.UseSchemasRoot)
            {
                ISchemaRepository?schemaRepository = reader.AsMetadataProvider().GetMetadata <ISchemaRepository>();
                if (schemaRepository == null)
                {
                    schemaRepository = new SchemaRepository();

                    // Load json in memory (first iteration).
                    JObject jObject = JObject.Load(reader);
                    if (jObject.Property(Options.SchemasRootName)?.Value is JObject schemasRoot)
                    {
                        foreach (JProperty property in schemasRoot.Properties())
                        {
                            string schemaName    = property.Name;
                            string root          = $"#/{Options.SchemasRootName}/";
                            string referenceName = root + schemaName;

                            JProperty?jProperty = ((JObject)property.Value).Property("$metadata.schema.compact");
                            if (jProperty is { First: { } schemaBody })
示例#3
0
        /// <inheritdoc />
        public override IPropertyContainer ReadJson(
            JsonReader reader,
            Type objectType,
            IPropertyContainer?existingValue,
            bool hasExistingValue,
            JsonSerializer serializer)
        {
            IPropertySet?schema            = null;
            bool         hasSchemaFromType = false;
            bool         hasSchemaFromJson = false;

            var propertyContainer = new MutablePropertyContainer();

            IPropertySet?knownPropertySet = objectType.GetSchemaByKnownPropertySet();

            if (knownPropertySet != null)
            {
                schema            = knownPropertySet;
                hasSchemaFromType = true;
            }

            ISchemaRepository?schemaRepository = reader.AsMetadataProvider().GetMetadata <ISchemaRepository>();

            if (Options.ReadSchemaFirst)
            {
                JObject jObject = JObject.Load(reader);

                JProperty?jProperty = jObject.Property("$metadata.schema.compact");
                if (jProperty is { First : { } schemaBody })
        protected override JProperty MainElement(RewardPortrait rewardPortrait)
        {
            if (FileOutputOptions.IsLocalizedText)
            {
                AddLocalizedGameString(rewardPortrait);
            }

            JObject portraitObject = new JObject();

            if (!string.IsNullOrEmpty(rewardPortrait.Name) && !FileOutputOptions.IsLocalizedText)
            {
                portraitObject.Add("name", rewardPortrait.Name);
            }

            portraitObject.Add("hyperlinkId", rewardPortrait.HyperlinkId);
            portraitObject.Add("rarity", rewardPortrait.Rarity.ToString());

            if (!string.IsNullOrEmpty(rewardPortrait.CollectionCategory))
            {
                portraitObject.Add("category", rewardPortrait.CollectionCategory);
            }

            if (!string.IsNullOrEmpty(rewardPortrait.Description?.RawDescription) && !FileOutputOptions.IsLocalizedText)
            {
                portraitObject.Add("description", GetTooltip(rewardPortrait.Description, FileOutputOptions.DescriptionType));
            }

            if (!string.IsNullOrEmpty(rewardPortrait.DescriptionUnearned?.RawDescription) && !FileOutputOptions.IsLocalizedText)
            {
                portraitObject.Add("descriptionUnearned", GetTooltip(rewardPortrait.DescriptionUnearned, FileOutputOptions.DescriptionType));
            }

            if (!string.IsNullOrEmpty(rewardPortrait.HeroId))
            {
                portraitObject.Add(new JProperty("heroId", rewardPortrait.HeroId));
            }

            if (!string.IsNullOrEmpty(rewardPortrait.PortraitPackId))
            {
                portraitObject.Add(new JProperty("portraitPackId", rewardPortrait.PortraitPackId));
            }

            portraitObject.Add(new JProperty("iconSlot", rewardPortrait.IconSlot));

            JProperty?image = GetImageObject(rewardPortrait);

            if (image != null)
            {
                portraitObject.Add(image);
            }

            return(new JProperty(rewardPortrait.Id, portraitObject));
        }
示例#5
0
        public BrimeChatMessage(JToken message)
        {
            // Logger.Trace("Loading Chat Message: " + message);
            string?__notice = message.Value <string>("__notice");

            if (!string.IsNullOrWhiteSpace(__notice))
            {
                Logger.Info("Notice: " + __notice);
            }

            string?curr = message.Value <string>("channelID");

            ChannelID = (curr == null) ? "" : curr;

            curr = message.Value <string>("_id");
            ID   = (curr == null) ? "" : curr;

            curr    = message.Value <string>("message");
            Message = (curr == null) ? "" : curr;

            JToken?sender = message["sender"];

            Sender = (sender == null) ? new BrimeUser() : new BrimeUser(sender);

            JToken?emotes = message["emotes"];

            if (emotes != null)
            {
                foreach (JToken item in emotes)
                {
                    if (item != null)
                    {
                        JProperty?prop = item.ToObject <JProperty>();
                        if (prop != null)
                        {
                            string name = prop.Name;
                            string?id   = prop.Value.Value <string>("_id");
                            if (id != null)
                            {
                                Emotes.Add(name, new BrimeChatEmote(id));
                            }
                        }
                    }
                }
            }
            Timestamp = message.Value <DateTime>("timestamp");
        }
示例#6
0
        /// <summary>
        /// Scrubs the json fields by their name.
        /// </summary>
        /// <param name="json">The json.</param>
        /// <param name="scrubFields">The scrub fields.</param>
        /// <param name="scrubMask">The scrub mask.</param>
        public static void ScrubJsonFieldsByName(JProperty?json, IEnumerable <string> scrubFields, string scrubMask)
        {
            if (json == null)
            {
                return;
            }

            var fields = scrubFields as string[] ?? scrubFields.ToArray();

            if (fields.Contains(json.Name))
            {
                json.Value = scrubMask;
                return;
            }

            if (json.Value is JContainer propertyValue)
            {
                foreach (var child in propertyValue)
                {
                    ScrubJsonFieldsByName(child, fields, scrubMask);
                }
            }
        }
示例#7
0
        private async Task ReadContentFromAsync(JsonReader reader, JsonLoadSettings?settings, CancellationToken cancellationToken = default)
        {
            IJsonLineInfo?lineInfo = reader as IJsonLineInfo;

            JContainer?parent = this;

            do
            {
                if (parent is JProperty p && p.Value != null)
                {
                    if (parent == this)
                    {
                        return;
                    }

                    parent = parent.Parent;
                }

                MiscellaneousUtils.Assert(parent != null);

                switch (reader.TokenType)
                {
                case JsonToken.None:
                    // new reader. move to actual content
                    break;

                case JsonToken.StartArray:
                    JArray a = new JArray();
                    a.SetLineInfo(lineInfo, settings);
                    parent.Add(a);
                    parent = a;
                    break;

                case JsonToken.EndArray:
                    if (parent == this)
                    {
                        return;
                    }

                    parent = parent.Parent;
                    break;

                case JsonToken.StartObject:
                    JObject o = new JObject();
                    o.SetLineInfo(lineInfo, settings);
                    parent.Add(o);
                    parent = o;
                    break;

                case JsonToken.EndObject:
                    if (parent == this)
                    {
                        return;
                    }

                    parent = parent.Parent;
                    break;

                case JsonToken.StartConstructor:
                    JConstructor constructor = new JConstructor(reader.Value !.ToString());
                    constructor.SetLineInfo(lineInfo, settings);
                    parent.Add(constructor);
                    parent = constructor;
                    break;

                case JsonToken.EndConstructor:
                    if (parent == this)
                    {
                        return;
                    }

                    parent = parent.Parent;
                    break;

                case JsonToken.String:
                case JsonToken.Integer:
                case JsonToken.Float:
                case JsonToken.Date:
                case JsonToken.Boolean:
                case JsonToken.Bytes:
                    JValue v = new JValue(reader.Value);
                    v.SetLineInfo(lineInfo, settings);
                    parent.Add(v);
                    break;

                case JsonToken.Comment:
                    if (settings != null && settings.CommentHandling == CommentHandling.Load)
                    {
                        v = JValue.CreateComment(reader.Value !.ToString());
                        v.SetLineInfo(lineInfo, settings);
                        parent.Add(v);
                    }
                    break;

                case JsonToken.Null:
                    v = JValue.CreateNull();
                    v.SetLineInfo(lineInfo, settings);
                    parent.Add(v);
                    break;

                case JsonToken.Undefined:
                    v = JValue.CreateUndefined();
                    v.SetLineInfo(lineInfo, settings);
                    parent.Add(v);
                    break;

                case JsonToken.PropertyName:
                    JProperty?property = ReadProperty(reader, settings, lineInfo, parent);
                    if (property != null)
                    {
                        parent = property;
                    }
                    else
                    {
                        await reader.SkipAsync().ConfigureAwait(false);
                    }
                    break;

                default:
                    throw new InvalidOperationException("The JsonReader should not be on a token of type {0}.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
                }
            } while (await reader.ReadAsync(cancellationToken).ConfigureAwait(false));
        }
        protected override JObject AbilityTalentInfoElement(AbilityTalentBase abilityTalentBase)
        {
            if (FileOutputOptions.IsLocalizedText)
            {
                AddLocalizedGameString(abilityTalentBase);
            }

            JObject info = new JObject
            {
                { "nameId", abilityTalentBase.AbilityTalentId.ReferenceId },
            };

            if (!string.IsNullOrEmpty(abilityTalentBase.AbilityTalentId.ButtonId))
            {
                info.Add("buttonId", abilityTalentBase.AbilityTalentId.ButtonId);
            }

            if (!string.IsNullOrEmpty(abilityTalentBase.Name) && !FileOutputOptions.IsLocalizedText)
            {
                info.Add("name", abilityTalentBase.Name);
            }

            if (!string.IsNullOrEmpty(abilityTalentBase.IconFileName))
            {
                info.Add("icon", Path.ChangeExtension(abilityTalentBase.IconFileName?.ToLowerInvariant(), ".png"));
            }

            if (abilityTalentBase.Tooltip.Cooldown.ToggleCooldown.HasValue)
            {
                info.Add("toggleCooldown", abilityTalentBase.Tooltip.Cooldown.ToggleCooldown.Value);
            }

            JProperty?life = UnitAbilityTalentLifeCost(abilityTalentBase.Tooltip.Life);

            if (life != null)
            {
                info.Add(life);
            }

            JProperty?energy = UnitAbilityTalentEnergyCost(abilityTalentBase.Tooltip.Energy);

            if (energy != null)
            {
                info.Add(energy);
            }

            JProperty?charges = UnitAbilityTalentCharges(abilityTalentBase.Tooltip.Charges);

            if (charges != null)
            {
                info.Add(charges);
            }

            JProperty?cooldown = UnitAbilityTalentCooldown(abilityTalentBase.Tooltip.Cooldown);

            if (cooldown != null)
            {
                info.Add(cooldown);
            }

            if (!string.IsNullOrEmpty(abilityTalentBase.Tooltip.ShortTooltip?.RawDescription) && !FileOutputOptions.IsLocalizedText)
            {
                info.Add("shortTooltip", GetTooltip(abilityTalentBase.Tooltip.ShortTooltip, FileOutputOptions.DescriptionType));
            }

            if (!string.IsNullOrEmpty(abilityTalentBase.Tooltip.FullTooltip?.RawDescription) && !FileOutputOptions.IsLocalizedText)
            {
                info.Add("fullTooltip", GetTooltip(abilityTalentBase.Tooltip.FullTooltip, FileOutputOptions.DescriptionType));
            }

            info.Add("abilityType", abilityTalentBase.AbilityTalentId.AbilityType.ToString());

            if (abilityTalentBase.IsActive && abilityTalentBase is Talent)
            {
                info.Add("isActive", abilityTalentBase.IsActive);
            }
            else if (!abilityTalentBase.IsActive && abilityTalentBase is Ability)
            {
                info.Add("isActive", abilityTalentBase.IsActive);
            }

            if (abilityTalentBase.AbilityTalentId.IsPassive)
            {
                info.Add("isPassive", abilityTalentBase.AbilityTalentId.IsPassive);
            }

            if (abilityTalentBase.IsQuest)
            {
                info.Add("isQuest", abilityTalentBase.IsQuest);
            }

            return(info);
        }
        protected override JProperty MainElement(Unit unit)
        {
            if (FileOutputOptions.IsLocalizedText)
            {
                AddLocalizedGameString(unit);
            }

            JObject unitObject = new JObject();

            if (!string.IsNullOrEmpty(unit.Name) && !FileOutputOptions.IsLocalizedText)
            {
                unitObject.Add("name", unit.Name);
            }
            if (!string.IsNullOrEmpty(unit.HyperlinkId))
            {
                unitObject.Add("hyperlinkId", unit.HyperlinkId);
            }
            if (unit.InnerRadius > 0)
            {
                unitObject.Add("innerRadius", unit.InnerRadius);
            }
            if (unit.Radius > 0)
            {
                unitObject.Add("radius", unit.Radius);
            }
            if (unit.Sight > 0)
            {
                unitObject.Add("sight", unit.Sight);
            }
            if (unit.Speed > 0)
            {
                unitObject.Add("speed", unit.Speed);
            }
            if (unit.KillXP > 0)
            {
                unitObject.Add("killXP", unit.KillXP);
            }
            if (!string.IsNullOrEmpty(unit.DamageType) && !FileOutputOptions.IsLocalizedText)
            {
                unitObject.Add("damageType", unit.DamageType);
            }
            if (!string.IsNullOrEmpty(unit.ScalingBehaviorLink))
            {
                unitObject.Add(new JProperty("scalingLinkId", unit.ScalingBehaviorLink));
            }
            if (!string.IsNullOrEmpty(unit.Description?.RawDescription) && !FileOutputOptions.IsLocalizedText)
            {
                unitObject.Add("description", GetTooltip(unit.Description, FileOutputOptions.DescriptionType));
            }
            if (!string.IsNullOrEmpty(unit.InfoText?.RawDescription) && !FileOutputOptions.IsLocalizedText)
            {
                unitObject.Add("infoText", GetTooltip(unit.InfoText, FileOutputOptions.DescriptionType));
            }
            if (unit.HeroDescriptors.Count > 0)
            {
                unitObject.Add(new JProperty("descriptors", unit.HeroDescriptors.OrderBy(x => x, StringComparer.OrdinalIgnoreCase)));
            }
            if (unit.Attributes.Count > 0)
            {
                unitObject.Add(new JProperty("attributes", unit.Attributes.OrderBy(x => x, StringComparer.OrdinalIgnoreCase)));
            }
            if (unit.UnitIds.Count > 0)
            {
                unitObject.Add(new JProperty("units", unit.UnitIds.OrderBy(x => x, StringComparer.OrdinalIgnoreCase)));
            }

            JProperty?portraits = UnitPortraits(unit);

            if (portraits != null)
            {
                unitObject.Add(portraits);
            }

            JProperty?life = UnitLife(unit);

            if (life != null)
            {
                unitObject.Add(life);
            }

            JProperty?shield = UnitShield(unit);

            if (shield != null)
            {
                unitObject.Add(shield);
            }

            JProperty?energy = UnitEnergy(unit);

            if (energy != null)
            {
                unitObject.Add(energy);
            }

            JProperty?armor = UnitArmor(unit);

            if (armor != null)
            {
                unitObject.Add(armor);
            }

            JProperty?weapons = UnitWeapons(unit);

            if (weapons != null)
            {
                unitObject.Add(weapons);
            }

            JProperty?abilities = UnitAbilities(unit);

            if (abilities != null)
            {
                unitObject.Add(abilities);
            }

            JProperty?subAbilities = UnitSubAbilities(unit);

            if (subAbilities != null)
            {
                unitObject.Add(subAbilities);
            }

            return(new JProperty(unit.Id, unitObject));
        }
        protected override JProperty MainElement(Spray spray)
        {
            if (FileOutputOptions.IsLocalizedText)
            {
                AddLocalizedGameString(spray);
            }

            JObject sprayObject = new JObject();

            if (!string.IsNullOrEmpty(spray.Name) && !FileOutputOptions.IsLocalizedText)
            {
                sprayObject.Add("name", spray.Name);
            }

            sprayObject.Add("hyperlinkId", spray.HyperlinkId);
            sprayObject.Add("attributeId", spray.AttributeId);
            sprayObject.Add("rarity", spray.Rarity.ToString());

            if (!string.IsNullOrEmpty(spray.CollectionCategory))
            {
                sprayObject.Add("category", spray.CollectionCategory);
            }

            if (!string.IsNullOrEmpty(spray.EventName))
            {
                sprayObject.Add("event", spray.EventName);
            }

            if (spray.ReleaseDate.HasValue)
            {
                sprayObject.Add("releaseDate", spray.ReleaseDate.Value.ToString("yyyy-MM-dd"));
            }

            if (!string.IsNullOrEmpty(spray.SortName) && !FileOutputOptions.IsLocalizedText)
            {
                sprayObject.Add("sortName", spray.SortName);
            }

            if (!string.IsNullOrEmpty(spray.SearchText) && !FileOutputOptions.IsLocalizedText)
            {
                sprayObject.Add("searchText", spray.SearchText);
            }

            if (!string.IsNullOrEmpty(spray.Description?.RawDescription) && !FileOutputOptions.IsLocalizedText)
            {
                sprayObject.Add("description", GetTooltip(spray.Description, FileOutputOptions.DescriptionType));
            }

            if (!string.IsNullOrEmpty(spray.TextureSheet.Image))
            {
                if (spray.AnimationCount < 1)
                {
                    sprayObject.Add("image", Path.ChangeExtension(spray.TextureSheet.Image.ToLowerInvariant(), StaticImageExtension));
                }
                else
                {
                    sprayObject.Add("image", Path.ChangeExtension(spray.TextureSheet.Image.ToLowerInvariant(), AnimatedImageExtension));
                }
            }

            JProperty?animation = AnimationObject(spray);

            if (animation != null)
            {
                sprayObject.Add(animation);
            }

            return(new JProperty(spray.Id, sprayObject));
        }
        protected override JProperty MainElement(Hero hero)
        {
            if (FileOutputOptions.IsLocalizedText)
            {
                AddLocalizedGameString(hero);
            }

            JObject heroObject = new JObject();

            if (!string.IsNullOrEmpty(hero.Name) && !FileOutputOptions.IsLocalizedText)
            {
                heroObject.Add("name", hero.Name);
            }
            if (!string.IsNullOrEmpty(hero.CUnitId))
            {
                heroObject.Add("unitId", hero.CUnitId);
            }
            if (!string.IsNullOrEmpty(hero.HyperlinkId))
            {
                heroObject.Add("hyperlinkId", hero.HyperlinkId);
            }
            if (!string.IsNullOrEmpty(hero.AttributeId))
            {
                heroObject.Add("attributeId", hero.AttributeId);
            }

            if (!FileOutputOptions.IsLocalizedText && !string.IsNullOrEmpty(hero.Difficulty))
            {
                heroObject.Add("difficulty", hero.Difficulty);
            }

            heroObject.Add("franchise", hero.Franchise.ToString());

            if (hero.Gender.HasValue)
            {
                heroObject.Add("gender", hero.Gender.Value.ToString());
            }
            if (!FileOutputOptions.IsLocalizedText && !string.IsNullOrEmpty(hero.Title))
            {
                heroObject.Add("title", hero.Title);
            }
            if (hero.InnerRadius > 0)
            {
                heroObject.Add("innerRadius", hero.InnerRadius);
            }
            if (hero.Radius > 0)
            {
                heroObject.Add("radius", hero.Radius);
            }
            if (hero.ReleaseDate.HasValue)
            {
                heroObject.Add("releaseDate", hero.ReleaseDate.Value.ToString("yyyy-MM-dd"));
            }
            if (hero.Sight > 0)
            {
                heroObject.Add("sight", hero.Sight);
            }
            if (hero.Speed > 0)
            {
                heroObject.Add("speed", hero.Speed);
            }
            if (!string.IsNullOrEmpty(hero.Type?.RawDescription) && !FileOutputOptions.IsLocalizedText)
            {
                heroObject.Add("type", GetTooltip(hero.Type, FileOutputOptions.DescriptionType));
            }
            heroObject.Add("rarity", hero.Rarity.ToString());
            if (!string.IsNullOrEmpty(hero.ScalingBehaviorLink))
            {
                heroObject.Add(new JProperty("scalingLinkId", hero.ScalingBehaviorLink));
            }
            if (!FileOutputOptions.IsLocalizedText && !string.IsNullOrEmpty(hero.SearchText))
            {
                heroObject.Add("searchText", hero.SearchText);
            }
            if (!string.IsNullOrEmpty(hero.Description?.RawDescription) && !FileOutputOptions.IsLocalizedText)
            {
                heroObject.Add("description", GetTooltip(hero.Description, FileOutputOptions.DescriptionType));
            }
            if (!string.IsNullOrEmpty(hero.InfoText?.RawDescription) && !FileOutputOptions.IsLocalizedText)
            {
                heroObject.Add("infoText", GetTooltip(hero.InfoText, FileOutputOptions.DescriptionType));
            }
            if (hero.HeroDescriptors.Count > 0)
            {
                heroObject.Add(new JProperty("descriptors", hero.HeroDescriptors.OrderBy(x => x, StringComparer.OrdinalIgnoreCase)));
            }
            if (hero.UnitIds.Count > 0)
            {
                heroObject.Add(new JProperty("units", hero.UnitIds.OrderBy(x => x, StringComparer.OrdinalIgnoreCase)));
            }

            JProperty?portraits = HeroPortraits(hero);

            if (portraits != null)
            {
                heroObject.Add(portraits);
            }

            JProperty?life = UnitLife(hero);

            if (life != null)
            {
                heroObject.Add(life);
            }

            JProperty?shield = UnitShield(hero);

            if (shield != null)
            {
                heroObject.Add(shield);
            }

            JProperty?energy = UnitEnergy(hero);

            if (energy != null)
            {
                heroObject.Add(energy);
            }

            JProperty?armor = UnitArmor(hero);

            if (armor != null)
            {
                heroObject.Add(armor);
            }

            if (hero.Roles.Count > 0 && !FileOutputOptions.IsLocalizedText)
            {
                heroObject.Add(new JProperty("roles", hero.Roles));
            }

            if (!string.IsNullOrEmpty(hero.ExpandedRole) && !FileOutputOptions.IsLocalizedText)
            {
                heroObject.Add(new JProperty("expandedRole", hero.ExpandedRole));
            }

            JProperty?ratings = HeroRatings(hero);

            if (ratings != null)
            {
                heroObject.Add(ratings);
            }

            JProperty?weapons = UnitWeapons(hero);

            if (weapons != null)
            {
                heroObject.Add(weapons);
            }

            JProperty?abilities = UnitAbilities(hero);

            if (abilities != null)
            {
                heroObject.Add(abilities);
            }

            JProperty?subAbilities = UnitSubAbilities(hero);

            if (subAbilities != null)
            {
                heroObject.Add(subAbilities);
            }

            JProperty?talents = HeroTalents(hero);

            if (talents != null)
            {
                heroObject.Add(talents);
            }

            JProperty?units = Units(hero);

            if (units != null)
            {
                heroObject.Add(units);
            }

            return(new JProperty(hero.Id, heroObject));
        }
        protected override JProperty MainElement(Emoticon emoticon)
        {
            if (FileOutputOptions.IsLocalizedText)
            {
                AddLocalizedGameString(emoticon);
            }

            JObject emoticonObject = new JObject();

            if (!string.IsNullOrEmpty(emoticon.Name) && !FileOutputOptions.IsLocalizedText)
            {
                emoticonObject.Add("expression", emoticon.Name);
            }

            if (!string.IsNullOrEmpty(emoticon.HyperlinkId))
            {
                emoticonObject.Add("hyperlinkId", emoticon.HyperlinkId);
            }

            if (emoticon.IsAliasCaseSensitive)
            {
                emoticonObject.Add("caseSensitive", true);
            }

            if (emoticon.IsHidden)
            {
                emoticonObject.Add("isHidden", true);
            }

            if (emoticon.SearchTexts != null && emoticon.SearchTexts.Any() && !FileOutputOptions.IsLocalizedText)
            {
                emoticonObject.Add("searchText", string.Join(' ', emoticon.SearchTexts));
            }

            if (!string.IsNullOrEmpty(emoticon.Description?.RawDescription) && !FileOutputOptions.IsLocalizedText)
            {
                emoticonObject.Add("description", GetTooltip(emoticon.Description, FileOutputOptions.DescriptionType));
            }

            if (!string.IsNullOrEmpty(emoticon.DescriptionLocked?.RawDescription) && !FileOutputOptions.IsLocalizedText)
            {
                emoticonObject.Add("descriptionLocked", GetTooltip(emoticon.DescriptionLocked, FileOutputOptions.DescriptionType));
            }

            if (emoticon.LocalizedAliases != null && emoticon.LocalizedAliases.Any() && !FileOutputOptions.IsLocalizedText)
            {
                emoticonObject.Add(new JProperty("localizedAliases", emoticon.LocalizedAliases));
            }

            if (emoticon.UniversalAliases != null && emoticon.UniversalAliases.Any() && !FileOutputOptions.IsLocalizedText)
            {
                emoticonObject.Add(new JProperty("aliases", emoticon.UniversalAliases));
            }

            if (!string.IsNullOrEmpty(emoticon.HeroId))
            {
                emoticonObject.Add(new JProperty("heroId", emoticon.HeroId));

                if (!string.IsNullOrEmpty(emoticon.HeroSkinId))
                {
                    emoticonObject.Add(new JProperty("heroSkinId", emoticon.HeroSkinId));
                }
            }

            if (!string.IsNullOrEmpty(emoticon.Image.FileName))
            {
                if (!emoticon.Image.Count.HasValue)
                {
                    emoticonObject.Add("image", Path.ChangeExtension(emoticon.Image.FileName?.ToLowerInvariant(), StaticImageExtension));
                }
                else
                {
                    emoticonObject.Add("image", Path.ChangeExtension(emoticon.Image.FileName?.ToLowerInvariant(), AnimatedImageExtension));
                }
            }

            JProperty?animation = AnimationObject(emoticon);

            if (animation != null)
            {
                emoticonObject.Add(animation);
            }

            return(new JProperty(emoticon.Id, emoticonObject));
        }
示例#13
0
        public override void WriteJson(JsonWriter writer, object?value, JsonSerializer serializer)
        {
            if (value == null)
            {
                writer.WriteNull();

                return;
            }

            try
            {
                _isWriting = true;

                var json              = JObject.FromObject(value, serializer);
                var jsonError         = json[ApiResponseConstants.Error];
                var hasError          = jsonError != null && jsonError.Type != JTokenType.Null;
                var isUnitOrHasErrors = value is ApiResponse <Unit> || hasError;

                JProperty?dataPropertyToDelete       = null;
                JProperty?errorPropertyToDelete      = null;
                JProperty?statusCodePropertyToDelete = null;
                JProperty?isOkPropertyToDelete       = null;
                JProperty?hasErrorsPropertyToDelete  = null;

                foreach (var property in json.Properties())
                {
                    if (isUnitOrHasErrors && property.IsNameEquals(nameof(ApiResponse <int> .Data)))
                    {
                        dataPropertyToDelete = property;
                    }
                    else if (!hasError &&
                             property.IsNameEquals(nameof(ApiResponse <int> .Error)))
                    {
                        errorPropertyToDelete = property;
                    }
                    else if (property.IsNameEquals(nameof(ApiResponse <int> .StatusCode)))
                    {
                        statusCodePropertyToDelete = property;
                    }
                    else if (property.IsNameEquals(nameof(ApiResponse <int> .IsOk)))
                    {
                        isOkPropertyToDelete = property;
                    }
                    else if (property.IsNameEquals(nameof(ApiResponse <int> .HasErrors)))
                    {
                        hasErrorsPropertyToDelete = property;
                    }
                }

                dataPropertyToDelete?.Remove();
                errorPropertyToDelete?.Remove();
                statusCodePropertyToDelete?.Remove();
                isOkPropertyToDelete?.Remove();
                hasErrorsPropertyToDelete?.Remove();

                json.WriteTo(writer);
            }
            finally
            {
                _isWriting = false;
            }
        }