Exemplo n.º 1
0
        public void ArrayIndexWithNestProperty()
        {
            var expected = "/NestMore/5/Nest";
            var actual   = JsonPointer.Create <TestClass>(x => x.NestMore[5].Nest);

            Assert.AreEqual(expected, actual.ToString());
        }
Exemplo n.º 2
0
        public void NestedWithArrayIndexProperty()
        {
            var expected = "/Nest/Ints/5";
            var actual   = JsonPointer.Create <TestClass>(x => x.Nest.Ints[5]);

            Assert.AreEqual(expected, actual.ToString());
        }
Exemplo n.º 3
0
        public void NestedProperty()
        {
            var expected = "/Nest/Nest";
            var actual   = JsonPointer.Create <TestClass>(x => x.Nest.Nest);

            Assert.AreEqual(expected, actual.ToString());
        }
Exemplo n.º 4
0
        public void SimpleArrayIndex()
        {
            var expected = "/Ints/1";
            var actual   = JsonPointer.Create <TestClass>(x => x.Ints[1]);

            Assert.AreEqual(expected, actual.ToString());
        }
Exemplo n.º 5
0
        public void SimpleProperty()
        {
            var expected = "/String";
            var actual   = JsonPointer.Create <TestClass>(x => x.String);

            Assert.AreEqual(expected, actual.ToString());
        }
Exemplo n.º 6
0
        internal (JsonSchema, Uri) FindSubschema(JsonPointer pointer, Uri currentUri)
        {
            IRefResolvable resolvable = this;

            for (var i = 0; i < pointer.Segments.Length; i++)
            {
                var segment       = pointer.Segments[i];
                var newResolvable = resolvable.ResolvePointerSegment(segment.Value);
                if (newResolvable == null)
                {
                    // TODO: document that this process does not consider `$id` in extraneous data
                    if (resolvable is JsonSchema subSchema &&
                        subSchema.OtherData != null &&
                        subSchema.OtherData.TryGetValue(segment.Value, out var element))
                    {
                        var newPointer = JsonPointer.Create(pointer.Segments.Skip(i + 1), true);
                        var value      = newPointer.Evaluate(element);
                        var asSchema   = FromText(value.ToString());
                        return(asSchema, currentUri);
                    }

                    return(null, currentUri);
                }

                if (newResolvable is JsonSchema schema && schema.Keywords != null)
                {
                    var idKeyword = schema.Keywords.OfType <IdKeyword>().SingleOrDefault();
                    if (idKeyword != null && i != pointer.Segments.Length - 1)
                    {
                        currentUri = idKeyword.UpdateUri(currentUri);
                    }
                }

                resolvable = newResolvable;
            }

            if (!(resolvable is JsonSchema))
            {
                resolvable = resolvable.ResolvePointerSegment(null);
            }

            return(resolvable as JsonSchema, currentUri);
        }
Exemplo n.º 7
0
        public override async Task ExecuteAsync(SetMaintenancePacket setMaintenancePacket, ClientSession session)
        {
            var servers = (await _channelHttpClient.GetChannelsAsync().ConfigureAwait(false))
                          ?.Where(c => c.Type == ServerType.WorldServer).ToList();

            var patch = new JsonPatch(PatchOperation.Replace(JsonPointer.Create <ChannelInfo>(o => o.IsMaintenance), setMaintenancePacket.MaintenanceMode.AsJsonElement()));

            if (setMaintenancePacket.IsGlobal == false)
            {
                await _channelHttpClient.PatchAsync(_channel.ChannelId, patch);
            }
            else
            {
                foreach (var server in servers ?? new List <ChannelInfo>())
                {
                    await _channelHttpClient.PatchAsync(server.Id, patch);
                }
            }
        }
Exemplo n.º 8
0
        internal Uri BuildAbsoluteUri(JsonPointer pointer)
        {
            if (_currentUri == null || !_currentUri.IsAbsoluteUri)
            {
                return(null);
            }
            if (pointer.Segments.All(s => s.Value != RefKeyword.Name &&
                                     s.Value != RecursiveRefKeyword.Name))
            {
                return(null);
            }

            var lastIndexOfRef = pointer.Segments
                                 .Select((s, i) => (s, i))
                                 .Last(s => s.s.Value == RefKeyword.Name || s.s.Value == RecursiveRefKeyword.Name).i;
            var absoluteSegments = pointer.Segments.Skip(lastIndexOfRef + 1);

            if (_reference != null)
            {
                absoluteSegments = _reference.Value.Segments.Concat(absoluteSegments);
            }

            return(new Uri(_currentUri, JsonPointer.Create(absoluteSegments, true).ToString()));
        }
        public override async Task ExecuteAsync(PstClientPacket pstClientPacket, ClientSession clientSession)
        {
            var isCopy = pstClientPacket.Type == 2;
            var mail   = await _mailHttpClient.GetGiftAsync(pstClientPacket.Id, clientSession.Character.VisualId, isCopy).ConfigureAwait(false);

            switch (pstClientPacket.ActionType)
            {
            case 3:
                if (mail == null)
                {
                    return;
                }

                var patch = new JsonPatch(PatchOperation.Replace(JsonPointer.Create <MailDto>(o => o.IsOpened), true.AsJsonElement()));
                await _mailHttpClient.ViewGiftAsync(mail.MailDto.MailId, patch).ConfigureAwait(false);

                await clientSession.SendPacketAsync(mail.GeneratePostMessage(pstClientPacket.Type)).ConfigureAwait(false);

                break;

            case 2:
                if (mail == null)
                {
                    return;
                }

                await _mailHttpClient.DeleteGiftAsync(pstClientPacket.Id, clientSession.Character.VisualId, isCopy).ConfigureAwait(false);

                await clientSession.SendPacketAsync(
                    clientSession.Character.GenerateSay(
                        GameLanguage.Instance.GetMessageFromKey(LanguageKey.MAIL_DELETED,
                                                                clientSession.Account.Language),
                        SayColorType.Purple)).ConfigureAwait(false);

                break;

            case 1:
                if (string.IsNullOrEmpty(pstClientPacket.Text) || string.IsNullOrEmpty(pstClientPacket.Title))
                {
                    return;
                }

                var dest = await _characterDao.FirstOrDefaultAsync(s => s.Name == pstClientPacket.ReceiverName).ConfigureAwait(false);

                if (dest != null)
                {
                    await _mailHttpClient.SendMessageAsync(clientSession.Character, dest.CharacterId, pstClientPacket.Title,
                                                           pstClientPacket.Text).ConfigureAwait(false);

                    await clientSession.SendPacketAsync(clientSession.Character.GenerateSay(
                                                            GameLanguage.Instance.GetMessageFromKey(
                                                                LanguageKey.MAILED,
                                                                clientSession.Account.Language), SayColorType.Yellow)).ConfigureAwait(false);
                }
                else
                {
                    await clientSession.SendPacketAsync(
                        clientSession.Character.GenerateSay(
                            GameLanguage.Instance.GetMessageFromKey(LanguageKey.USER_NOT_FOUND,
                                                                    clientSession.Account.Language),
                            SayColorType.Yellow)).ConfigureAwait(false);
                }

                break;

            default:
                return;
            }
        }
        public void ImplicitCastTest()
        {
            var pointer = JsonPointer.Create("string", 1, "foo");

            Assert.AreEqual("/string/1/foo", pointer.ToString());
        }