mirror of https://github.com/Squidex/squidex.git
12 changed files with 256 additions and 48 deletions
@ -0,0 +1,88 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System; |
||||
|
using System.IO; |
||||
|
using Orleans.Serialization; |
||||
|
|
||||
|
namespace Squidex.Infrastructure.Orleans |
||||
|
{ |
||||
|
internal sealed class StreamReaderWrapper : Stream |
||||
|
{ |
||||
|
private readonly IBinaryTokenStreamReader reader; |
||||
|
|
||||
|
public override bool CanRead |
||||
|
{ |
||||
|
get { return true; } |
||||
|
} |
||||
|
|
||||
|
public override bool CanSeek |
||||
|
{ |
||||
|
get { return false; } |
||||
|
} |
||||
|
|
||||
|
public override bool CanWrite |
||||
|
{ |
||||
|
get { return false; } |
||||
|
} |
||||
|
|
||||
|
public override long Length |
||||
|
{ |
||||
|
get { return reader.Length; } |
||||
|
} |
||||
|
|
||||
|
public override long Position |
||||
|
{ |
||||
|
get |
||||
|
{ |
||||
|
return reader.CurrentPosition; |
||||
|
} |
||||
|
set |
||||
|
{ |
||||
|
throw new NotSupportedException(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public StreamReaderWrapper(IBinaryTokenStreamReader reader) |
||||
|
{ |
||||
|
this.reader = reader; |
||||
|
} |
||||
|
|
||||
|
public override void Flush() |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public override int Read(byte[] buffer, int offset, int count) |
||||
|
{ |
||||
|
var bytesLeft = reader.Length - reader.CurrentPosition; |
||||
|
|
||||
|
if (bytesLeft < count) |
||||
|
{ |
||||
|
count = bytesLeft; |
||||
|
} |
||||
|
|
||||
|
reader.ReadByteArray(buffer, offset, count); |
||||
|
|
||||
|
return count; |
||||
|
} |
||||
|
|
||||
|
public override long Seek(long offset, SeekOrigin origin) |
||||
|
{ |
||||
|
throw new NotSupportedException(); |
||||
|
} |
||||
|
|
||||
|
public override void SetLength(long value) |
||||
|
{ |
||||
|
throw new NotSupportedException(); |
||||
|
} |
||||
|
|
||||
|
public override void Write(byte[] buffer, int offset, int count) |
||||
|
{ |
||||
|
throw new NotSupportedException(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,79 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System; |
||||
|
using System.IO; |
||||
|
using Orleans.Serialization; |
||||
|
|
||||
|
namespace Squidex.Infrastructure.Orleans |
||||
|
{ |
||||
|
internal sealed class StreamWriterWrapper : Stream |
||||
|
{ |
||||
|
private readonly IBinaryTokenStreamWriter writer; |
||||
|
|
||||
|
public override bool CanRead |
||||
|
{ |
||||
|
get { return false; } |
||||
|
} |
||||
|
|
||||
|
public override bool CanSeek |
||||
|
{ |
||||
|
get { return false; } |
||||
|
} |
||||
|
|
||||
|
public override bool CanWrite |
||||
|
{ |
||||
|
get { return true; } |
||||
|
} |
||||
|
|
||||
|
public override long Length |
||||
|
{ |
||||
|
get { return writer.CurrentOffset; } |
||||
|
} |
||||
|
|
||||
|
public override long Position |
||||
|
{ |
||||
|
get |
||||
|
{ |
||||
|
return writer.CurrentOffset; |
||||
|
} |
||||
|
set |
||||
|
{ |
||||
|
throw new NotSupportedException(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public StreamWriterWrapper(IBinaryTokenStreamWriter writer) |
||||
|
{ |
||||
|
this.writer = writer; |
||||
|
} |
||||
|
|
||||
|
public override void Flush() |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public override void Write(byte[] buffer, int offset, int count) |
||||
|
{ |
||||
|
writer.Write(buffer, offset, count); |
||||
|
} |
||||
|
|
||||
|
public override int Read(byte[] buffer, int offset, int count) |
||||
|
{ |
||||
|
throw new NotSupportedException(); |
||||
|
} |
||||
|
|
||||
|
public override long Seek(long offset, SeekOrigin origin) |
||||
|
{ |
||||
|
throw new NotSupportedException(); |
||||
|
} |
||||
|
|
||||
|
public override void SetLength(long value) |
||||
|
{ |
||||
|
throw new NotSupportedException(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,56 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Diagnostics; |
||||
|
|
||||
|
namespace Squidex.Infrastructure |
||||
|
{ |
||||
|
public struct ValueStopwatch |
||||
|
{ |
||||
|
private const long TicksPerMillisecond = 10000; |
||||
|
private const long TicksPerSecond = TicksPerMillisecond * 1000; |
||||
|
|
||||
|
private static double tickFrequency; |
||||
|
|
||||
|
private readonly long startTime; |
||||
|
|
||||
|
static ValueStopwatch() |
||||
|
{ |
||||
|
if (Stopwatch.IsHighResolution) |
||||
|
{ |
||||
|
tickFrequency = (double)TicksPerSecond / Stopwatch.Frequency; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public ValueStopwatch(long startTime) |
||||
|
{ |
||||
|
this.startTime = startTime; |
||||
|
} |
||||
|
|
||||
|
public static ValueStopwatch StartNew() |
||||
|
{ |
||||
|
return new ValueStopwatch(Stopwatch.GetTimestamp()); |
||||
|
} |
||||
|
|
||||
|
public long Stop() |
||||
|
{ |
||||
|
var elapsed = Stopwatch.GetTimestamp() - startTime; |
||||
|
|
||||
|
if (elapsed < 0) |
||||
|
{ |
||||
|
return elapsed; |
||||
|
} |
||||
|
|
||||
|
if (Stopwatch.IsHighResolution) |
||||
|
{ |
||||
|
elapsed = unchecked((long)(elapsed * tickFrequency)); |
||||
|
} |
||||
|
|
||||
|
return elapsed / TicksPerMillisecond; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue