예제 #1
0
        public void TestInsertNested()
        {
            using (var store = NewDocumentStore())
            {
                store.DatabaseCommands.Put("groups/1", null, RavenJObject.Parse(groupsString), new RavenJObject());

                store.DatabaseCommands.Patch("groups/1", new[]
                {
                    new PatchRequest
                    {
                        Type     = PatchCommandType.Modify,
                        Name     = "Groups",
                        Position = 1,
                        Nested   = new[]
                        {
                            new PatchRequest
                            {
                                Type  = PatchCommandType.Insert,
                                Name  = "Members",
                                Value = RavenJToken.Parse("{  'Name' : 'Pinky', 'Nick': 'pinky' }")
                            }
                        }
                    }
                });

                var groups      = store.DatabaseCommands.Get("groups/1").DataAsJson;
                var groupsInner = groups.Value <RavenJArray>("Groups");
                Assert.Equal(2, groupsInner.Length);
                var members = groupsInner[1].Value <RavenJArray>("Members");
                Assert.Equal(3, members.Length);
                Assert.Equal("Pinky", members[2].Value <string>("Name"));
            }
        }
예제 #2
0
        public virtual void MarkCommitAsDispatched(Commit commit)
        {
            if (commit == null)
            {
                throw new ArgumentNullException("commit");
            }

            var patch = new PatchRequest {
                Type = PatchCommandType.Set, Name = "Dispatched", Value = RavenJToken.Parse("true")
            };
            var data = new PatchCommandData {
                Key = commit.ToRavenCommitId(), Patches = new[] { patch }
            };

            Logger.Debug(Messages.MarkingCommitAsDispatched, commit.CommitId, commit.BucketId);

            TryRaven(() =>
            {
                using (TransactionScope scope = OpenCommandScope())
                    using (IDocumentSession session = _store.OpenSession())
                    {
                        session.Advanced.DocumentStore.DatabaseCommands.Batch(new[] { data });
                        session.SaveChanges();
                        scope.Complete();
                        return(true);
                    }
            });
        }
예제 #3
0
 public static object ParseJsonResult(string json)
 {
     try {
         var token = RavenJToken.Parse(json);
         return(Visit(token));
     } catch {
         return(json);
     }
 }
예제 #4
0
        public Task <RavenJToken> ReadResponseJsonAsync()
        {
            return(ReadResponseStringAsync()
                   .ContinueWith(x =>
            {
                var result = x.Result;

                return RavenJToken.Parse(result);
            }));
        }
예제 #5
0
        public async Task <RavenJToken> ExecuteRequestAsync()
        {
            var s = await ReadResponseStringAsync();

            if (string.IsNullOrEmpty(s))
            {
                return(null);
            }
            return(RavenJToken.Parse(s));
        }
예제 #6
0
        public void can_read_array_into_ravenjobject()
        {
            const string json =
                @"[{""Username"":""user3"",""Email"":""*****@*****.**"",""IsActive"":true,""@metadata"":{""Raven-Entity-Name"":""UserDbs"",
""Raven-Clr-Type"":""Persistence.Models.UserDb, Infrastructure""}},
{""Username"":""user4"",""Email"":""*****@*****.**"",""IsActive"":true,""@metadata"":{""Raven-Entity-Name"":""UserDbs"",
""Raven-Clr-Type"":""Persistence.Models.UserDb, Infrastructure""}}]
";

            var obj = RavenJToken.Parse(json);

            Assert.NotNull(obj);
        }
예제 #7
0
 /// <summary>
 /// Gets the list of databases from the server asynchronously
 /// </summary>
 public Task <string[]> GetDatabaseNamesAsync()
 {
     return(url.Databases()
            .NoCache()
            .ToJsonRequest(this, credentials, convention)
            .ReadResponseStringAsync()
            .ContinueWith(task =>
     {
         var json = (RavenJArray)RavenJToken.Parse(task.Result);
         return json
         .Select(x => x.Value <RavenJObject>("@metadata").Value <string>("@id").Replace("Raven/Databases/", string.Empty))
         .ToArray();
     }));
 }
예제 #8
0
        private string FilterData(string result)
        {
            RavenJToken token;

            try
            {
                token = RavenJToken.Parse(result);
            }
            catch (Exception)
            {
                return(result);
            }
            Visit(token);
            return(token.ToString(Formatting.Indented));
        }
예제 #9
0
파일: Index.cs 프로젝트: JontyMC/ravendb
        private static KeyValuePair <string, RavenJToken> CreateProperty(Field fld, Document document)
        {
            var stringValue = fld.StringValue();

            if (document.GetField(fld.Name() + "_ConvertToJson") != null)
            {
                var val = RavenJToken.Parse(fld.StringValue()) as RavenJObject;
                return(new KeyValuePair <string, RavenJToken>(fld.Name(), val));
            }
            if (stringValue == Constants.NullValue)
            {
                stringValue = null;
            }
            return(new KeyValuePair <string, RavenJToken>(fld.Name(), stringValue));
        }
예제 #10
0
        private static RavenJToken SetValueInDocument(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(value);
            }

            var ch = value[0];

            if (ch == '[' || ch == '{')
            {
                try
                {
                    return(RavenJToken.Parse(value));
                }
                catch (Exception)
                {
                    // ignoring failure to parse, will proceed to insert as a string value
                }
            }
            else if (char.IsDigit(ch) || ch == '-' || ch == '.')
            {
                // maybe it is a number?
                long longResult;
                if (long.TryParse(value, out longResult))
                {
                    return(longResult);
                }

                decimal decimalResult;
                if (decimal.TryParse(value, out decimalResult))
                {
                    return(decimalResult);
                }
            }
            else if (ch == '"' && value.Length > 1 && value[value.Length - 1] == '"')
            {
                return(value.Substring(1, value.Length - 2));
            }

            return(value);
        }
예제 #11
0
        public void SetValueInNestedElement()
        {
            var patchedDoc = new JsonPatcher(doc).Apply(
                new[]
            {
                new PatchRequest
                {
                    Type   = PatchCommandType.Modify,
                    Name   = "user",
                    Nested = new[]
                    {
                        new PatchRequest {
                            Type = PatchCommandType.Set, Name = "name", Value = new RavenJValue("rahien")
                        },
                    }
                },
            });

            Assert.Equal(RavenJToken.Parse(@"{""title"":""A Blog Post"",""body"":""html markup"",""comments"":[{""author"":""ayende"",""text"":""good post 1""},{""author"":""ayende"",""text"":""good post 2""}],""user"":{""name"":""rahien"",""id"":13}}"),
                         patchedDoc, RavenJTokenEqualityComparer.Default);
        }
예제 #12
0
        public object ParseJsonResult(string json)
        {
            if (null == json)
            {
                return(null);
            }
            if (json == "")
            {
                return("");
            }

            try
            {
                var token = RavenJToken.Parse(json);
                return(Visit(token));
            }
            catch
            {
                return(json);
            }
        }
예제 #13
0
        public virtual void MarkCommitAsDispatched(Commit commit)
        {
            if (commit == null)
            {
                throw new ArgumentNullException("commit");
            }

            var patch = new PatchRequest
            {
                Type  = PatchCommandType.Set,
                Name  = "Dispatched",
                Value = RavenJToken.Parse("true")
            };
            var data = new PatchCommandData
            {
                Key     = commit.ToRavenCommitId(),
                Patches = new[] { patch }
            };

            try
            {
                using (var scope = this.OpenCommandScope())
                    using (var session = this.store.OpenSession())
                    {
                        session.Advanced.DatabaseCommands.Batch(new[] { data });
                        session.SaveChanges();
                        scope.Complete();
                    }
            }
            catch (WebException e)
            {
                throw new StorageUnavailableException(e.Message, e);
            }
            catch (Exception e)
            {
                throw new StorageException(e.Message, e);
            }
        }
예제 #14
0
        public void Should_deserialize_correctly()
        {
            var rjson = RavenJToken.FromObject(new Bar()).ToString();
            var robj  = RavenJToken.Parse(rjson);

            var json = JToken.FromObject(new Bar()).ToString();
            var obj  = JToken.Parse(json);

            Assert.Equal(json, rjson);

            using (var store = NewDocumentStore())
            {
                string id;
                using (var session = store.OpenSession())
                {
                    var bar = new Bar();
                    session.Store(bar);
                    session.SaveChanges();
                    id = bar.Id;
                }

                using (var session = store.OpenSession())
                {
                    var bar = session.Load <Bar>(id);
                    Assert.NotNull(bar);
                }

                WaitForIndexing(store);

                using (var session = store.OpenSession())
                {
                    var bar = session.Query <Bar>().FirstOrDefault();
                    Assert.NotNull(bar);
                }
            }
        }
 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     RavenJToken.Parse(Newtonsoft.Json.JsonConvert.SerializeObject(value)).WriteTo(writer);
 }
예제 #16
0
        public async Task <RavenJToken> ReadResponseJsonAsync()
        {
            var result = await ReadResponseStringAsync();

            return(RavenJToken.Parse(result));
        }
예제 #17
0
 public Task <RavenJToken> ReadResponseJsonAsync()
 {
     return(ReadResponseStringAsync()
            .ContinueWith(task => RavenJToken.Parse(task.Result)));
 }
예제 #18
0
 public RavenJToken ReadResponseJson()
 {
     return(RavenJToken.Parse(ReadResponseString()));
 }