public async Task Documents() { using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context)) using (var stream = new ArrayStream(RequestBodyStream(), "Docs")) using (var source = new StreamSource(stream, context, Database)) { var destination = new DatabaseDestination(Database); var options = new DatabaseSmugglerOptionsServerSide { ReadLegacyEtag = true, OperateOnTypes = DatabaseItemType.Documents }; var smuggler = new DatabaseSmuggler(Database, source, destination, Database.Time, options); var result = smuggler.Execute(); var replicationSource = GetSourceReplicationInformation(context, GetRemoteServerInstanceId(), out var documentId); replicationSource.LastDocumentEtag = result.LegacyLastDocumentEtag; replicationSource.Source = GetFromServer(); replicationSource.LastBatchSize = result.Documents.ReadCount + result.Tombstones.ReadCount; replicationSource.LastModified = DateTime.UtcNow; await SaveSourceReplicationInformation(replicationSource, context, documentId); } }
private void HandleLegacyIndexes() { using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context)) using (var stream = new ArrayStream(RequestBodyStream(), nameof(DatabaseItemType.Indexes))) using (var source = new StreamSource(stream, context, Database)) { var destination = new DatabaseDestination(Database); var options = new DatabaseSmugglerOptionsServerSide { OperateOnTypes = DatabaseItemType.Indexes }; var smuggler = new DatabaseSmuggler(Database, source, destination, Database.Time, options); smuggler.Execute(); } }
public void ArrayStream_ConstructorTest() { // Test the first overload ArrayStream<Int32> stream1 = new ArrayStream<int>(100); Assert.AreEqual(100, stream1.Length); // Test the second overload ArrayStream<Int32> stream2 = new ArrayStream<int>(Data, 0); ArrayStream<Int32> stream3 = new ArrayStream<int>(Data, 8); Assert.AreEqual(Data.Length, stream2.Length); Assert.AreEqual(Data.Length - 8, stream3.Length); // Test the second overload ArrayStream<Int32> stream4 = new ArrayStream<int>(Data, 8, 2); Assert.AreEqual(2, stream4.Length); }
public void ArrayStream_ReadTest() { ArrayStream<Int32> stream = new ArrayStream<int>(Data); // Test ReadElement Int32[] temp1 = new int[Data.Length]; for (int i = 0; i < temp1.Length; i++) temp1[i] = stream.ReadElement(); CollectionAssert.AreEqual(Data, temp1); // Test Read stream.Position = 0; Int32[] temp2 = new Int32[Data.Length]; stream.Read(temp2); CollectionAssert.AreEqual(Data, temp2); // Test Read stream.Position = 0; Int32[] temp3 = new Int32[Data.Length]; stream.Read(temp3, 0, Data.Length); CollectionAssert.AreEqual(Data, temp3); }
public Value Evaluate(ArrayStream stream) { var array = new Array(); while (array.Length < stream.Limit) { Value value = stream.Next(); if (value.Type == Value.ValueType.Nil) { return(array); } var skip = false; foreach (Item item in items) { var iterItem = new Array.IterItem { Value = value, Key = Array.GetKey(), Index = array.Length }; value = item.Process(iterItem, array.Length); if (value == null || value.Type == Value.ValueType.Nil) { /* if (item.IsTerminating) * return array;*/ skip = true; break; } } if (!skip) { array.Add(value); } } return(array); }
public void ArrayStream_ConstructorLargeOffsetTest() { ArrayStream<Int32> stream = new ArrayStream<int>(Data, Data.Length + 1); }
public void ArrayStream_ConstructorArrayNullTest() { ArrayStream<Int32> stream = new ArrayStream<int>(null); }
public void ArrayStream_WriteTest() { // Test WriteElement ArrayStream<Int32> stream1 = new ArrayStream<int>(Data.Length); foreach (int v in Data) stream1.WriteElement(v); CollectionAssert.AreEqual(Data, stream1.ToArray()); // Test Write ArrayStream<Int32> stream2 = new ArrayStream<int>(Data.Length); stream2.Write(Data); CollectionAssert.AreEqual(Data, stream2.ToArray()); // Test Write ArrayStream<Int32> stream3 = new ArrayStream<int>(Data.Length); stream3.Write(Data, 0, Data.Length); CollectionAssert.AreEqual(Data, stream3.ToArray()); }