예제 #1
0
			private RavenJToken GetTheNewResultOrWireTheDefault(RavenJToken result)
			{
				var selectToken = result.SelectToken(Name);
				if (selectToken != null)
					return selectToken;
				return ((RavenJObject)result)[Name] = new RavenJObject();
			}
예제 #2
0
        public static IEnumerable <Tuple <RavenJToken, RavenJToken> > SelectTokenWithRavenSyntaxReturningFlatStructure(this RavenJToken self, string path)
        {
            var pathParts = path.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            var result    = self.SelectToken(pathParts[0]);

            if (pathParts.Length == 1)
            {
                yield return(Tuple.Create(result, self));

                yield break;
            }
            if (result == null || result.Type == JTokenType.Null)
            {
                yield break;
            }
            if (result.Type == JTokenType.Object)
            {
                var ravenJObject = ((RavenJObject)result);
                if (ravenJObject.ContainsKey("$values"))
                {
                    result = ravenJObject.Value <RavenJToken>("$values");
                }
            }
            foreach (var item in result.Values <RavenJToken>())
            {
                foreach (var subItem in item.SelectTokenWithRavenSyntaxReturningFlatStructure(string.Join(",", pathParts.Skip(1).ToArray())))
                {
                    yield return(subItem);
                }
            }
        }
예제 #3
0
            private RavenJToken GetTheNewResultOrWireTheDefault(RavenJToken result)
            {
                var selectToken = result.SelectToken(Name);

                if (selectToken != null)
                {
                    return(selectToken);
                }
                return(((RavenJObject)result)[Name] = new RavenJObject());
            }
예제 #4
0
            public void ForEach(RavenJToken result, RavenJToken item, Action <PathPart, RavenJToken, RavenJToken> action)
            {
                if (string.IsNullOrEmpty(FinalName) == false)
                {
                    action(this, item, result);
                    return;
                }
                RavenJToken newResult = GetTheNewResultOrWireTheDefault(result);

                if (item == null)
                {
                    foreach (var pathPart in Items)
                    {
                        pathPart.Value.ForEach(newResult, null, action);
                    }
                    return;
                }
                if (item is RavenJArray == false)
                {
                    foreach (var pathPart in Items)
                    {
                        pathPart.Value.ForEach(newResult, item.SelectToken(pathPart.Key), action);
                    }
                }
                else
                {
                    var jArray = newResult as RavenJArray;
                    if (jArray == null)
                    {
                        jArray = new RavenJArray();
                        ((RavenJObject)result)[Name] = jArray;
                    }
                    foreach (var subItem in item.Values <RavenJToken>())
                    {
                        newResult = new RavenJObject();
                        jArray.Add(newResult);
                        foreach (var pathPart in Items)
                        {
                            pathPart.Value.ForEach(newResult, subItem.SelectToken(pathPart.Key), action);
                        }
                    }
                }
            }
예제 #5
0
        public static RavenJObject SelectTokenWithRavenSyntax(this RavenJToken self, string[] paths)
        {
            var parts = new PathPart();

            foreach (var path in paths)
            {
                var pathParts = path.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                BuildPathPart(parts, 0, pathParts, path);
            }
            var obj = new RavenJObject();

            foreach (var currentPart in parts.Items)
            {
                currentPart.Value.ForEach(obj, self.SelectToken(currentPart.Key), (part, item, result) =>
                {
                    ((RavenJObject)result)[part.Name] = item;
                });
            }

            return(obj);
        }
예제 #6
0
			public void ForEach(RavenJToken result, RavenJToken item, Action<PathPart, RavenJToken, RavenJToken> action)
			{
				if (string.IsNullOrEmpty(FinalName) == false)
				{
					action(this, item, result);
					return;
				}
				RavenJToken newResult = GetTheNewResultOrWireTheDefault(result);
				if (item == null)
				{
					foreach (var pathPart in Items)
						pathPart.Value.ForEach(newResult, null, action);
					return;
				}
				if (item is RavenJArray == false)
				{
					foreach (var pathPart in Items)
						pathPart.Value.ForEach(newResult, item.SelectToken(pathPart.Key), action);
				}
				else
				{
					var jArray = newResult as RavenJArray;
					if (jArray == null)
					{
						jArray = new RavenJArray();
						((RavenJObject)result)[Name] = jArray;
					}
					foreach (var subItem in item.Values<RavenJToken>())
					{
						newResult = new RavenJObject();
						jArray.Add(newResult);
						foreach (var pathPart in Items)
						{
							pathPart.Value.ForEach(newResult, subItem.SelectToken(pathPart.Key), action);
						}
					}
				}
			}