Exemple #1
0
		public void Execute(RavenJObject document)
		{
			if (Includes == null)
				return;
			foreach (var include in Includes)
			{
				if (string.IsNullOrEmpty(include))
					continue;

				var path = include;
				string prefix = null;
				var match = IncludePrefixRegex.Match(path);
				if (match.Success && match.Groups.Count >= 2)
				{
					prefix = match.Groups[1].Value;
					path = path.Replace(prefix, "");
					prefix = prefix.Substring(1, prefix.Length - 2);
				}

				foreach (var token in document.SelectTokenWithRavenSyntaxReturningFlatStructure(path))
				{
					ExecuteInternal(token.Item1, prefix);
				}
			}
		}
Exemple #2
0
        public void Execute(RavenJObject document)
        {
            if (Includes == null)
            {
                return;
            }
            foreach (var include in Includes)
            {
                if (string.IsNullOrEmpty(include))
                {
                    continue;
                }

                var    path   = include;
                string prefix = null;
                var    match  = IncludePrefixRegex.Match(path);
                if (match.Success && match.Groups.Count >= 2)
                {
                    prefix = match.Groups[1].Value;
                    path   = path.Replace(prefix, "");
                    prefix = prefix.Substring(1, prefix.Length - 2);
                }

                foreach (var token in document.SelectTokenWithRavenSyntaxReturningFlatStructure(path))
                {
                    ExecuteInternal(token.Item1, prefix);
                }
            }
        }
Exemple #3
0
        public bool MatchFilters(RavenJObject document)
        {
            foreach (var filter in Filters)
            {
                bool anyRecords    = false;
                bool matchedFilter = false;
                foreach (var tuple in document.SelectTokenWithRavenSyntaxReturningFlatStructure(filter.Path))
                {
                    if (tuple == null || tuple.Item1 == null)
                    {
                        continue;
                    }

                    anyRecords = true;

                    var val = tuple.Item1.Type == JTokenType.String
                                  ? tuple.Item1.Value <string>()
                                  : tuple.Item1.ToString(Formatting.None);
                    matchedFilter |= filter.Values.Any(value => string.Equals(val, value, StringComparison.OrdinalIgnoreCase)) ==
                                     filter.ShouldMatch;
                }

                if (filter.ShouldMatch == false && anyRecords == false) // RDBQA-7
                {
                    return(true);
                }

                if (matchedFilter == false)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #4
0
        private void Apply(PatchRequest patchCmd)
        {
            if (patchCmd.Name == null)
            {
                throw new InvalidOperationException("Patch property must have a name property");
            }
            foreach (var result in document.SelectTokenWithRavenSyntaxReturningFlatStructure(patchCmd.Name))
            {
                var token  = result.Item1;
                var parent = result.Item2;
                switch (patchCmd.Type)
                {
                case PatchCommandType.Set:
                    SetProperty(patchCmd, patchCmd.Name, token);
                    break;

                case PatchCommandType.Unset:
                    RemoveProperty(patchCmd, patchCmd.Name, token, parent);
                    break;

                case PatchCommandType.Add:
                    AddValue(patchCmd, patchCmd.Name, token);
                    break;

                case PatchCommandType.Insert:
                    InsertValue(patchCmd, patchCmd.Name, token);
                    break;

                case PatchCommandType.Remove:
                    RemoveValue(patchCmd, patchCmd.Name, token);
                    break;

                case PatchCommandType.Modify:
                    // create snapshot of property
                    token.EnsureCannotBeChangeAndEnableSnapshotting();
                    token = token.CreateSnapshot();
                    document[patchCmd.Name] = token;
                    ModifyValue(patchCmd, patchCmd.Name, token);
                    break;

                case PatchCommandType.Inc:
                    IncrementProperty(patchCmd, patchCmd.Name, token);
                    break;

                case PatchCommandType.Copy:
                    CopyProperty(patchCmd, token);
                    break;

                case PatchCommandType.Rename:
                    RenameProperty(patchCmd, patchCmd.Name, token);
                    break;

                default:
                    throw new ArgumentException(string.Format("Cannot understand command: '{0}'", patchCmd.Type));
                }
            }
        }
		public void Execute(RavenJObject document)
		{
			foreach (var include in Includes)
			{
				foreach (var token in document.SelectTokenWithRavenSyntaxReturningFlatStructure(include))
				{
					ExecuteInternal(token.Item1);
				}
			}
		}
Exemple #6
0
 public void Execute(RavenJObject document)
 {
     foreach (var include in Includes)
     {
         foreach (var token in document.SelectTokenWithRavenSyntaxReturningFlatStructure(include))
         {
             ExecuteInternal(token.Item1);
         }
     }
 }
Exemple #7
0
        private void Apply(PatchRequest patchCmd)
        {
            if (patchCmd.Name == null)
            {
                throw new InvalidOperationException("Patch property must have a name property");
            }
            foreach (var result in document.SelectTokenWithRavenSyntaxReturningFlatStructure(patchCmd.Name))
            {
                var token  = result.Item1;
                var parent = result.Item2;
                switch (patchCmd.Type)
                {
                case PatchCommandType.Set:
                    SetProperty(patchCmd, patchCmd.Name, token as RavenJValue);
                    break;

                case PatchCommandType.Unset:
                    RemoveProperty(patchCmd, patchCmd.Name, token, parent);
                    break;

                case PatchCommandType.Add:
                    AddValue(patchCmd, patchCmd.Name, token);
                    break;

                case PatchCommandType.Insert:
                    InsertValue(patchCmd, patchCmd.Name, token);
                    break;

                case PatchCommandType.Remove:
                    RemoveValue(patchCmd, patchCmd.Name, token);
                    break;

                case PatchCommandType.Modify:
                    ModifyValue(patchCmd, patchCmd.Name, token);
                    break;

                case PatchCommandType.Inc:
                    IncrementProperty(patchCmd, patchCmd.Name, token);
                    break;

                case PatchCommandType.Copy:
                    CopyProperty(patchCmd, patchCmd.Name, token);
                    break;

                case PatchCommandType.Rename:
                    RenameProperty(patchCmd, patchCmd.Name, token);
                    break;

                default:
                    throw new ArgumentException("Cannot understand command: " + patchCmd.Type);
                }
            }
        }
Exemple #8
0
        public static void Include(RavenJObject document, string include, Func<string, bool> loadId)
        {
            if (string.IsNullOrEmpty(include) || document == null)
                return;

            var path = GetIncludePath(include);

            foreach (var token in document.SelectTokenWithRavenSyntaxReturningFlatStructure(path.Path))
            {
                ExecuteInternal(token.Item1, path.Prefix, (value, prefix) =>
                {
                    value = (prefix != null ? prefix + value : value);
                    return loadId(value);
                });
            }
        }
Exemple #9
0
        public static void Include(RavenJObject document, string include, Func <string, bool> loadId)
        {
            if (string.IsNullOrEmpty(include) || document == null)
            {
                return;
            }

            var path = GetIncludePath(include);

            foreach (var token in document.SelectTokenWithRavenSyntaxReturningFlatStructure(path.Path))
            {
                ExecuteInternal(token.Item1, path.Prefix, (value, prefix) =>
                {
                    value = (prefix != null ? prefix + value : value);
                    return(loadId(value));
                });
            }
        }
Exemple #10
0
        public static void Include(RavenJObject document, string include, Func <string, bool> loadId)
        {
            if (string.IsNullOrEmpty(include) || document == null)
            {
                return;
            }
            bool isPrefix;
            var  path = GetIncludePath(include, out isPrefix);

            foreach (var token in document.SelectTokenWithRavenSyntaxReturningFlatStructure(path.Path))
            {
                ExecuteInternal(token.Item1, path.Addition, (value, addition) =>
                {
                    value = (addition != null ?
                             (isPrefix ? addition + value : string.Format(addition, value)) : value);
                    return(loadId(value));
                });
            }
        }