本文整理汇总了C#中RandomStream类的典型用法代码示例。如果您正苦于以下问题:C# RandomStream类的具体用法?C# RandomStream怎么用?C# RandomStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RandomStream类属于命名空间,在下文中一共展示了RandomStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldFailOver
public async Task ShouldFailOver()
{
var sourceClient = NewClient(0);
var destinationClient = NewClient(1);
var source1Content = new RandomStream(10000);
await sourceClient.UploadAsync("test1.bin", source1Content);
await sourceClient.Config.SetConfig(SynchronizationConstants.RavenSynchronizationDestinations, new NameValueCollection
{
{
"url", destinationClient.ServerUrl
}
});
await sourceClient.ReplicationInformer.RefreshReplicationInformationAsync(sourceClient);
await sourceClient.Synchronization.SynchronizeDestinationsAsync();
var destinationFiles = await destinationClient.GetFilesAsync("/");
Assert.Equal(1, destinationFiles.FileCount);
Assert.Equal(1, destinationFiles.Files.Length);
var server = GetRavenFileSystem(0);
server.Dispose();
var fileFromSync = await sourceClient.GetFilesAsync("/");
Assert.Equal(1, fileFromSync.FileCount);
Assert.Equal(1, fileFromSync.Files.Length);
}
示例2: ToBitmapHolderAsync
public async static Task<BitmapHolder> ToBitmapHolderAsync(this Stream imageStream, Tuple<int, int> downscale, bool useDipUnits, InterpolationMode mode)
{
if (imageStream == null)
return null;
using (IRandomAccessStream image = new RandomStream(imageStream))
{
if (downscale != null && (downscale.Item1 > 0 || downscale.Item2 > 0))
{
using (var downscaledImage = await image.ResizeImage(downscale.Item1, downscale.Item2, mode, useDipUnits).ConfigureAwait(false))
{
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(downscaledImage);
PixelDataProvider pixelDataProvider = await decoder.GetPixelDataAsync();
var bytes = pixelDataProvider.DetachPixelData();
int[] array = new int[decoder.PixelWidth * decoder.PixelHeight];
CopyPixels(bytes, array);
return new BitmapHolder(array, (int)decoder.PixelWidth, (int)decoder.PixelHeight);
}
}
else
{
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(image);
PixelDataProvider pixelDataProvider = await decoder.GetPixelDataAsync();
var bytes = pixelDataProvider.DetachPixelData();
int[] array = new int[decoder.PixelWidth * decoder.PixelHeight];
CopyPixels(bytes, array);
return new BitmapHolder(array, (int)decoder.PixelWidth, (int)decoder.PixelHeight);
}
}
}
示例3: CreateRandomStream
public static void CreateRandomStream(ref RandomStream stream, uint seed, int capacity = 1000)
{
if(stream != null)
{
stream.Dispose();
}
stream = new RandomStream(seed, capacity);
}
示例4: ToBitmapImageAsync
public async static Task<WriteableBitmap> ToBitmapImageAsync(this Stream imageStream, Tuple<int, int> downscale, bool useDipUnits, InterpolationMode mode, ImageInformation imageInformation = null)
{
if (imageStream == null)
return null;
using (IRandomAccessStream image = new RandomStream(imageStream))
{
if (downscale != null && (downscale.Item1 > 0 || downscale.Item2 > 0))
{
using (var downscaledImage = await image.ResizeImage(downscale.Item1, downscale.Item2, mode, useDipUnits, imageInformation).ConfigureAwait(false))
{
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(downscaledImage);
downscaledImage.Seek(0);
WriteableBitmap resizedBitmap = null;
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () =>
{
resizedBitmap = new WriteableBitmap((int)decoder.PixelWidth, (int)decoder.PixelHeight);
using (var s = downscaledImage.AsStream())
{
resizedBitmap.SetSource(s);
}
});
return resizedBitmap;
}
}
else
{
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(image);
image.Seek(0);
WriteableBitmap bitmap = null;
if (imageInformation != null)
{
imageInformation.SetCurrentSize((int)decoder.PixelWidth, (int)decoder.PixelHeight);
imageInformation.SetOriginalSize((int)decoder.PixelWidth, (int)decoder.PixelHeight);
}
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () =>
{
bitmap = new WriteableBitmap((int)decoder.PixelWidth, (int)decoder.PixelHeight);
bitmap.SetSource(imageStream);
});
return bitmap;
}
}
}
示例5: Should_be_the_same_signatures
public void Should_be_the_same_signatures()
{
const int size = 1024*1024*5;
var randomStream = new RandomStream(size);
var buffer = new byte[size];
randomStream.Read(buffer, 0, size);
var stream = new MemoryStream(buffer);
var firstSigContentHashes = new List<string>();
using (var signatureRepository = new VolatileSignatureRepository("test"))
using (var rested = new SigGenerator())
{
var result = rested.GenerateSignatures(stream, "test", signatureRepository);
foreach (var signatureInfo in result)
{
using (var content = signatureRepository.GetContentForReading(signatureInfo.Name))
{
firstSigContentHashes.Add(content.GetMD5Hash());
}
}
}
stream.Position = 0;
var secondSigContentHashes = new List<string>();
using (var signatureRepository = new VolatileSignatureRepository("test"))
using (var rested = new SigGenerator())
{
var result = rested.GenerateSignatures(stream, "test", signatureRepository);
foreach (var signatureInfo in result)
{
using (var content = signatureRepository.GetContentForReading(signatureInfo.Name))
{
secondSigContentHashes.Add(content.GetMD5Hash());
}
}
}
Assert.Equal(firstSigContentHashes.Count, secondSigContentHashes.Count);
for (var i = 0; i < firstSigContentHashes.Count; i++)
{
Assert.Equal(firstSigContentHashes[i], secondSigContentHashes[i]);
}
}
示例6: ToBitmapImageAsync
public async static Task<WriteableBitmap> ToBitmapImageAsync(this byte[] imageBytes, Tuple<int, int> downscale, InterpolationMode mode)
{
if (imageBytes == null)
return null;
using (var imageStream = imageBytes.AsBuffer().AsStream())
using (IRandomAccessStream image = new RandomStream(imageStream))
{
if (downscale != null && (downscale.Item1 > 0 || downscale.Item2 > 0))
{
using (var downscaledImage = await image.ResizeImage((uint)downscale.Item1, (uint)downscale.Item2, mode).ConfigureAwait(false))
{
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(downscaledImage);
downscaledImage.Seek(0);
WriteableBitmap resizedBitmap = null;
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () =>
{
resizedBitmap = new WriteableBitmap((int)decoder.PixelWidth, (int)decoder.PixelHeight);
using (var s = downscaledImage.AsStream())
{
resizedBitmap.SetSource(s);
}
});
return resizedBitmap;
}
}
else
{
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(image);
image.Seek(0);
WriteableBitmap bitmap = null;
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () =>
{
bitmap = new WriteableBitmap((int)decoder.PixelWidth, (int)decoder.PixelHeight);
bitmap.SetSource(imageStream);
});
return bitmap;
}
}
}
示例7: Should_confirm_that_file_is_safe
public async Task Should_confirm_that_file_is_safe()
{
var sourceContent = new RandomStream(1024*1024);
var sourceClient = NewAsyncClient(1);
var destinationClient = NewAsyncClient(0);
await sourceClient.UploadAsync("test.bin", sourceContent);
await sourceClient.Synchronization.SetDestinationsAsync(destinationClient.ToSynchronizationDestination());
await sourceClient.Synchronization.StartAsync();
var metadata = await sourceClient.GetMetadataForAsync("test.bin");
var confirmations = await destinationClient.Synchronization.GetConfirmationForFilesAsync(
new List<Tuple<string, Etag>>
{
new Tuple<string, Etag>("test.bin", metadata.Value<string>(Constants.MetadataEtagField))
});
var synchronizationConfirmations = confirmations as SynchronizationConfirmation[] ?? confirmations.ToArray();
Assert.Equal(1, synchronizationConfirmations.Count());
Assert.Equal(FileStatus.Safe, synchronizationConfirmations.ToArray()[0].Status);
Assert.Equal(FileHeader.Canonize("test.bin"), synchronizationConfirmations.ToArray()[0].FileName);
}
示例8: Source_should_delete_configuration_record_if_destination_confirm_that_file_is_safe
public async Task Source_should_delete_configuration_record_if_destination_confirm_that_file_is_safe()
{
var sourceClient = NewAsyncClient(0);
var sourceContent = new RandomStream(10000);
var destinationClient = (IAsyncFilesCommandsImpl)NewAsyncClient(1);
await sourceClient.UploadAsync("test.bin", sourceContent);
await sourceClient.Synchronization.SetDestinationsAsync(destinationClient.ToSynchronizationDestination());
await sourceClient.Synchronization.StartAsync();
// start synchronization again to force confirmation by source
await sourceClient.Synchronization.StartAsync();
var shouldBeNull = await sourceClient.Configuration.GetKeyAsync<SynchronizationDetails>(RavenFileNameHelper.SyncNameForFile("test.bin", destinationClient.ServerUrl));
Assert.Null(shouldBeNull);
}
示例9: Make_sure_that_locks_are_released_after_synchronization_when_two_files_synchronized_simultaneously
public async Task Make_sure_that_locks_are_released_after_synchronization_when_two_files_synchronized_simultaneously()
{
var sourceClient = NewAsyncClient(0);
var destinationClient = NewAsyncClient(1);
var source1Content = new RandomStream(10000);
await sourceClient.UploadAsync("test1.bin", source1Content);
var source2Content = new RandomStream(10000);
await sourceClient.UploadAsync("test2.bin", source2Content);
await sourceClient.Synchronization.SetDestinationsAsync(destinationClient.ToSynchronizationDestination());
await sourceClient.Synchronization.StartAsync();
var configs = await destinationClient.Configuration.GetKeyNamesAsync();
Assert.DoesNotContain(RavenFileNameHelper.SyncLockNameForFile("test1.bin"), configs);
Assert.DoesNotContain(RavenFileNameHelper.SyncLockNameForFile("test2.bin"), configs);
// also make sure that results exist
Assert.Contains(RavenFileNameHelper.SyncResultNameForFile("test1.bin"), configs);
Assert.Contains(RavenFileNameHelper.SyncResultNameForFile("test2.bin"), configs);
}
示例10: Should_confirm_that_file_is_safe
public async Task Should_confirm_that_file_is_safe()
{
var sourceContent = new RandomStream(1024*1024);
var sourceClient = NewClient(1);
var destinationClient = NewClient(0);
await sourceClient.UploadAsync("test.bin", sourceContent);
await sourceClient.Config.SetConfig(SynchronizationConstants.RavenSynchronizationDestinations, new NameValueCollection
{
{
"url", destinationClient.ServerUrl
}
});
await sourceClient.Synchronization.SynchronizeDestinationsAsync();
var confirmations = await
destinationClient.Synchronization.ConfirmFilesAsync(new List<Tuple<string, Guid>>
{
new Tuple<string, Guid>("test.bin"
,sourceClient.GetMetadataForAsync("test.bin").Result.Value<Guid>("ETag"))
});
var synchronizationConfirmations = confirmations as SynchronizationConfirmation[] ?? confirmations.ToArray();
Assert.Equal(1, synchronizationConfirmations.Count());
Assert.Equal(FileStatus.Safe, synchronizationConfirmations.ToArray()[0].Status);
Assert.Equal("test.bin", synchronizationConfirmations.ToArray()[0].FileName);
}
示例11: Source_should_delete_configuration_record_if_destination_confirm_that_file_is_safe
public async Task Source_should_delete_configuration_record_if_destination_confirm_that_file_is_safe()
{
var sourceClient = NewClient(0);
var sourceContent = new RandomStream(10000);
var destinationClient = NewClient(1);
await sourceClient.UploadAsync("test.bin", sourceContent);
await sourceClient.Config.SetConfig(SynchronizationConstants.RavenSynchronizationDestinations, new NameValueCollection
{
{
"url", destinationClient.ServerUrl
}
});
await sourceClient.Synchronization.SynchronizeDestinationsAsync();
// start synchronization again to force confirmation by source
await sourceClient.Synchronization.SynchronizeDestinationsAsync();
var shouldBeNull = await
sourceClient.Config.GetConfig(RavenFileNameHelper.SyncNameForFile("test.bin", destinationClient.ServerUrl));
Assert.Null(shouldBeNull);
}
示例12: Destination_should_know_what_is_last_file_etag_after_synchronization
public async Task Destination_should_know_what_is_last_file_etag_after_synchronization()
{
var sourceContent = new RandomStream(10);
var sourceMetadata = new RavenJObject
{
{"SomeTest-metadata", "some-value"}
};
var destinationClient = NewAsyncClient(0);
var sourceClient = NewAsyncClient(1);
await sourceClient.UploadAsync("test.bin", sourceContent, sourceMetadata);
await sourceClient.Synchronization.StartAsync("test.bin", destinationClient);
var lastSynchronization = await destinationClient.Synchronization.GetLastSynchronizationFromAsync(await sourceClient.GetServerIdAsync());
var sourceMetadataWithEtag = await sourceClient.GetMetadataForAsync("test.bin");
Assert.Equal(sourceMetadataWithEtag.Value<string>(Constants.MetadataEtagField), lastSynchronization.LastSourceFileEtag.ToString());
}
示例13: Big_file_test
public void Big_file_test(long size)
{
var sourceContent = new RandomStream(size);
var destinationContent = new RandomlyModifiedStream(new RandomStream(size), 0.01);
var destinationClient = NewAsyncClient(0);
var sourceClient = NewAsyncClient(1);
var sourceMetadata = new RavenJObject
{
{"SomeTest-metadata", "some-value"}
};
var destinationMetadata = new RavenJObject
{
{"SomeTest-metadata", "should-be-overwritten"}
};
destinationClient.UploadAsync("test.bin", destinationContent, destinationMetadata).Wait();
sourceClient.UploadAsync("test.bin", sourceContent, sourceMetadata).Wait();
SynchronizationReport result = SyncTestUtils.ResolveConflictAndSynchronize(sourceClient, destinationClient, "test.bin");
Assert.Equal(sourceContent.Length, result.BytesCopied + result.BytesTransfered);
}
示例14: Should_mark_file_as_conflicted_when_two_differnet_versions
public async void Should_mark_file_as_conflicted_when_two_differnet_versions()
{
var sourceContent = new RandomStream(10);
var sourceMetadata = new RavenJObject
{
{"SomeTest-metadata", "some-value"}
};
var destinationClient = NewClient(0);
var sourceClient = NewClient(1);
await sourceClient.UploadAsync("test.bin", sourceMetadata, sourceContent);
await destinationClient.UploadAsync("test.bin", sourceMetadata, sourceContent);
var synchronizationReport = await sourceClient.Synchronization.StartAsync("test.bin", destinationClient);
Assert.NotNull(synchronizationReport.Exception);
var resultFileMetadata = await destinationClient.GetMetadataForAsync("test.bin");
Assert.True(resultFileMetadata.Value<bool>(SynchronizationConstants.RavenSynchronizationConflict));
}
示例15: Should_be_possible_to_apply_conflict
public void Should_be_possible_to_apply_conflict()
{
var content = new RandomStream(10);
var client = NewClient(1);
client.UploadAsync("test.bin", content).Wait();
var guid = Guid.NewGuid().ToString();
client.Synchronization.ApplyConflictAsync("test.bin", 8, guid,
new List<HistoryItem> {new HistoryItem {ServerId = guid, Version = 3}},
"http://localhost:12345").Wait();
var resultFileMetadata = client.GetMetadataForAsync("test.bin").Result;
var conflict = client.Config.GetConfig<ConflictItem>(RavenFileNameHelper.ConflictConfigNameForFile("test.bin")).Result;
Assert.Equal(true.ToString(), resultFileMetadata[SynchronizationConstants.RavenSynchronizationConflict]);
Assert.Equal(guid, conflict.RemoteHistory.Last().ServerId);
Assert.Equal(8, conflict.RemoteHistory.Last().Version);
Assert.Equal(1, conflict.CurrentHistory.Last().Version);
Assert.Equal(2, conflict.RemoteHistory.Count);
Assert.Equal(guid, conflict.RemoteHistory[0].ServerId);
Assert.Equal(3, conflict.RemoteHistory[0].Version);
}