private static bool CompareBlittableArray(string id, BlittableJsonReaderArray oldArray, BlittableJsonReaderArray newArray, IDictionary <string, DocumentsChanges[]> changes, List <DocumentsChanges> docChanges, LazyStringValue propName) { // if we don't care about the changes if (oldArray.Length != newArray.Length && changes == null) { return(true); } var position = 0; var changed = false; while (position < oldArray.Length && position < newArray.Length) { switch (oldArray[position]) { case BlittableJsonReaderObject bjro1: if (newArray[position] is BlittableJsonReaderObject bjro2) { changed |= CompareBlittable(id, bjro1, bjro2, changes, docChanges); } else { changed = true; if (changes != null) { NewChange(propName, newArray[position], oldArray[position], docChanges, DocumentsChanges.ChangeType.ArrayValueChanged); } } break; case BlittableJsonReaderArray bjra1: if (newArray[position] is BlittableJsonReaderArray bjra2) { changed |= CompareBlittableArray(id, bjra1, bjra2, changes, docChanges, propName); } else { changed = true; if (changes != null) { NewChange(propName, newArray[position], oldArray[position], docChanges, DocumentsChanges.ChangeType.ArrayValueChanged); } } break; case null: if (newArray[position] != null) { changed = true; if (changes != null) { NewChange(propName, newArray[position], oldArray[position], docChanges, DocumentsChanges.ChangeType.ArrayValueChanged); } } break; default: if (oldArray[position].Equals(newArray[position]) == false) { if (changes != null) { NewChange(propName, newArray[position], oldArray[position], docChanges, DocumentsChanges.ChangeType.ArrayValueChanged); } changed = true; } break; } position++; } if (changes == null) { return(changed); } // if one of the arrays is larger than the other while (position < oldArray.Length) { NewChange(propName, null, oldArray[position], docChanges, DocumentsChanges.ChangeType.ArrayValueRemoved); position++; } while (position < newArray.Length) { NewChange(propName, newArray[position], null, docChanges, DocumentsChanges.ChangeType.ArrayValueAdded); position++; } return(changed); }
public void UnwatchDocumentCounter(BlittableJsonReaderArray parameters) { var val = GetDocumentCounterParameters(parameters); _matchingDocumentCounter.TryRemove(val); }
public void HandleCommand(string command, string commandParameter, BlittableJsonReaderArray commandParameters) { long.TryParse(commandParameter, out long commandParameterAsLong); if (Match(command, "watch-index")) { WatchIndex(commandParameter); } else if (Match(command, "unwatch-index")) { UnwatchIndex(commandParameter); } else if (Match(command, "watch-indexes")) { WatchAllIndexes(); } else if (Match(command, "unwatch-indexes")) { UnwatchAllIndexes(); } else if (Match(command, "watch-doc")) { WatchDocument(commandParameter); } else if (Match(command, "unwatch-doc")) { UnwatchDocument(commandParameter); } else if (Match(command, "watch-docs")) { WatchAllDocuments(); } else if (Match(command, "unwatch-docs")) { UnwatchAllDocuments(); } else if (Match(command, "watch-prefix")) { WatchDocumentPrefix(commandParameter); } else if (Equals(command, "unwatch-prefix")) { UnwatchDocumentPrefix(commandParameter); } else if (Match(command, "watch-collection")) { WatchDocumentInCollection(commandParameter); } else if (Equals(command, "unwatch-collection")) { UnwatchDocumentInCollection(commandParameter); } else if (Match(command, "watch-type")) { WatchDocumentOfType(commandParameter); } else if (Equals(command, "unwatch-type")) { UnwatchDocumentOfType(commandParameter); } else if (Equals(command, "watch-operation")) { WatchOperation(commandParameterAsLong); } else if (Equals(command, "unwatch-operation")) { UnwatchOperation(commandParameterAsLong); } else if (Equals(command, "watch-operations")) { WatchAllOperations(); } else if (Equals(command, "unwatch-operations")) { UnwatchAllOperations(); } else if (Match(command, "watch-counters")) { WatchAllCounters(); } else if (Match(command, "unwatch-counters")) { UnwatchAllCounters(); } else if (Match(command, "watch-counter")) { WatchCounter(commandParameter); } else if (Match(command, "unwatch-counter")) { UnwatchCounter(commandParameter); } else if (Match(command, "watch-document-counters")) { WatchDocumentCounters(commandParameter); } else if (Match(command, "unwatch-document-counters")) { UnwatchDocumentCounters(commandParameter); } else if (Match(command, "watch-document-counter")) { WatchDocumentCounter(commandParameters); } else if (Match(command, "unwatch-document-counter")) { UnwatchDocumentCounter(commandParameters); } else { throw new ArgumentOutOfRangeException(nameof(command), "Command argument is not valid"); } }
public ArrayWithWarning(BlittableJsonReaderArray mergedArray) { MergedArray = mergedArray; }
public void UnwatchDocumentTimeSeries(BlittableJsonReaderArray parameters) { var val = GetParameters(parameters); _matchingDocumentTimeSeries.TryRemove(val); }
public void WatchDocumentCounter(BlittableJsonReaderArray parameters) { var val = GetParameters(parameters); _matchingDocumentCounter.TryAdd(val); }
private int CompareBlittableArray(BlittableJsonReaderArray xBlittableJsonReaderArray, BlittableJsonReaderArray yBlittableJsonReaderArray) { var xCurr = 0; var yCurr = 0; while (xCurr < xBlittableJsonReaderArray.Length && yCurr < yBlittableJsonReaderArray.Length) { var res = Compare(xBlittableJsonReaderArray[xCurr++], yBlittableJsonReaderArray[yCurr++]); //Here we don't multiply by order since the recursive call to Compare already applied order. if (res != 0) { return(res); } } if (xCurr == xBlittableJsonReaderArray.Length && yCurr == yBlittableJsonReaderArray.Length) { return(0); } return((xCurr - yCurr) * _order); //longer with equal prefix is bigger }
public static IEnumerable <T> ParseValuesFromBlittableArray <T>(InMemoryDocumentSessionOperations session, BlittableJsonReaderArray blittableArray) { for (var i = 0; i < blittableArray.Length; i++) { var blittableJsonToken = blittableArray.GetValueTokenTupleByIndex(i).Item2; switch (blittableJsonToken) { case BlittableJsonToken.StartArray: foreach (var inner in ParseValuesFromBlittableArray <T>(session, blittableArray[i] as BlittableJsonReaderArray)) { yield return(inner); } break; case BlittableJsonToken.StartObject: yield return((T)session.DeserializeFromTransformer(typeof(T), null, blittableArray[i] as BlittableJsonReaderObject)); break; case BlittableJsonToken.String: var lazyString = blittableArray[i] as LazyStringValue; if (lazyString != null) { yield return((T)(object)lazyString.ToString()); } break; case BlittableJsonToken.CompressedString: var lazyCompressedString = blittableArray[i] as LazyCompressedStringValue; if (lazyCompressedString != null) { yield return((T)(object)lazyCompressedString.ToString()); } break; default: // TODO, check if other types need special handling as well yield return((T)blittableArray[i]); break; } } }