Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
965 changes: 965 additions & 0 deletions src/Authentication/Authentication/Cmdlets/InvokeGraphRequest.cs

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions src/Authentication/Authentication/Helpers/AttachDebugger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

using System;
using System.Management.Automation;

using Microsoft.Graph.PowerShell.Authentication.Cmdlets;

namespace Microsoft.Graph.PowerShell.Authentication.Helpers
{
internal static class AttachDebugger
{
internal static void Break(PSCmdlet invokedCmdLet)
{
while (!System.Diagnostics.Debugger.IsAttached)
{
Console.Error.WriteLine($"Waiting for debugger to attach to process {System.Diagnostics.Process.GetCurrentProcess().Id}");
//invokedCmdLet.WriteDebug($"Waiting for debugger to attach to process {System.Diagnostics.Process.GetCurrentProcess().Id}");
Comment thread
georgend marked this conversation as resolved.
Outdated
for (var i = 0; i < 50; i++)
{
if (System.Diagnostics.Debugger.IsAttached)
{
break;
}
System.Threading.Thread.Sleep(100);
//invokedCmdLet.WriteDebug(".");
Console.Error.Write(".");
}
//invokedCmdLet.WriteDebug(Environment.NewLine);
Console.Error.WriteLine();
}
System.Diagnostics.Debugger.Break();
}
}
}
101 changes: 101 additions & 0 deletions src/Authentication/Authentication/Helpers/BufferingStreamReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using System;
using System.IO;

namespace Microsoft.Graph.PowerShell.Authentication.Helpers
{
internal class BufferingStreamReader : Stream
{
internal BufferingStreamReader(Stream baseStream)
{
_baseStream = baseStream;
_streamBuffer = new MemoryStream();
_length = long.MaxValue;
_copyBuffer = new byte[4096];
}

private readonly Stream _baseStream;
private readonly MemoryStream _streamBuffer;
private readonly byte[] _copyBuffer;

public override bool CanRead => true;

public override bool CanSeek => true;

public override bool CanWrite => false;

public override void Flush()
{
_streamBuffer.SetLength(0);
}

public override long Length => _length;

private long _length;

public override long Position
{
get => _streamBuffer.Position;

set => _streamBuffer.Position = value;
}

public override int Read(byte[] buffer, int offset, int count)
{
long previousPosition = Position;
bool consumedStream = false;
int totalCount = count;
while ((!consumedStream) &&
((Position + totalCount) > _streamBuffer.Length))
{
// If we don't have enough data to fill this from memory, cache more.
// We try to read 4096 bytes from base stream every time, so at most we
// may cache 4095 bytes more than what is required by the Read operation.
int bytesRead = _baseStream.Read(_copyBuffer, 0, _copyBuffer.Length);

if (_streamBuffer.Position < _streamBuffer.Length)
{
// Win8: 651902 no need to -1 here as Position refers to the place
// where we can start writing from.
_streamBuffer.Position = _streamBuffer.Length;
}

_streamBuffer.Write(_copyBuffer, 0, bytesRead);

totalCount -= bytesRead;
if (bytesRead < _copyBuffer.Length)
{
consumedStream = true;
}
}

// Reset our backing store to its official position, as reading
// for the CopyTo updates the position.
_streamBuffer.Seek(previousPosition, SeekOrigin.Begin);

// Read from the backing store into the requested buffer.
int read = _streamBuffer.Read(buffer, offset, count);

if (read < count)
{
SetLength(Position);
}

return read;
}

public override long Seek(long offset, SeekOrigin origin)
{
return _streamBuffer.Seek(offset, origin);
}

public override void SetLength(long value)
{
_length = value;
}

public override void Write(byte[] buffer, int offset, int count)
{
throw new NotSupportedException();
}
}
}
Loading