Imported Upstream version 5.0.0.42

Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-04-10 11:41:01 +00:00
parent 1190d13a04
commit 6bdd276d05
19939 changed files with 3099680 additions and 93811 deletions

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\dir.props" />
<PropertyGroup>
<AssemblyVersion>4.0.13.0</AssemblyVersion>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<ItemGroup>
<Project Include="System.Runtime.WindowsRuntime.pkgproj" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.traversal.targets))\dir.traversal.targets" />
</Project>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<ItemGroup>
<ProjectReference Include="..\ref\System.Runtime.WindowsRuntime.csproj">
<SupportedFramework>netcore451;wpa81</SupportedFramework>
</ProjectReference>
<ProjectReference Include="..\src\System.Runtime.WindowsRuntime.builds" />
<!-- Not supported for desktop -->
<InboxOnTargetFramework Include="win8" />
<InboxOnTargetFramework Include="wp80" />
<InboxOnTargetFramework Include="wpa81" />
<InboxOnTargetFramework Include="portable-win8+wp8+wpa81" />
</ItemGroup>
<ItemGroup>
<!-- This package is only supported on win8 and later RIDs -->
<ValidatePackageSuppression Include="PermitImplementation">
<Value>.NETCoreApp,Version=v1.1/win10-arm64;.NETCoreApp,Version=v2.0/win10-arm64</Value>
</ValidatePackageSuppression>
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildConfigurations>
netcoreapp;
uap;
</BuildConfigurations>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,37 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
// ------------------------------------------------------------------------------
// Changes to this file must follow the http://aka.ms/api-review process.
// ------------------------------------------------------------------------------
using System;
using System.Security;
// Including the explicit implementations of IFormattable because if we use what
// the tool generates we will end up with a member name "global::System.IFormattable.ToString"
// which is different then what is in the implementation. We can avoid it in the manual
// file because of the usings at the top of this file instead of fully qualify with global::.
namespace Windows.Foundation
{
public partial struct Point : IFormattable
{
[SecuritySafeCriticalAttribute]
string IFormattable.ToString(string format, IFormatProvider provider) { throw null; }
}
public partial struct Rect : IFormattable
{
[SecuritySafeCriticalAttribute]
string IFormattable.ToString(string format, IFormatProvider provider) { throw null; }
}
}
namespace Windows.UI
{
public partial struct Color : IFormattable
{
[SecuritySafeCriticalAttribute]
string IFormattable.ToString(string format, IFormatProvider provider) { throw null; }
}
}

View File

@@ -0,0 +1,227 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
// ------------------------------------------------------------------------------
// Changes to this file must follow the http://aka.ms/api-review process.
// ------------------------------------------------------------------------------
namespace System
{
[global::System.CLSCompliantAttribute(false)]
[global::System.Security.SecurityCriticalAttribute]
public static partial class WindowsRuntimeSystemExtensions
{
public static global::Windows.Foundation.IAsyncAction AsAsyncAction(this global::System.Threading.Tasks.Task source) { throw null; }
public static global::Windows.Foundation.IAsyncOperation<TResult> AsAsyncOperation<TResult>(this global::System.Threading.Tasks.Task<TResult> source) { throw null; }
public static global::System.Threading.Tasks.Task AsTask(this global::Windows.Foundation.IAsyncAction source) { throw null; }
public static global::System.Threading.Tasks.Task AsTask(this global::Windows.Foundation.IAsyncAction source, global::System.Threading.CancellationToken cancellationToken) { throw null; }
public static global::System.Threading.Tasks.Task AsTask<TProgress>(this global::Windows.Foundation.IAsyncActionWithProgress<TProgress> source) { throw null; }
public static global::System.Threading.Tasks.Task AsTask<TProgress>(this global::Windows.Foundation.IAsyncActionWithProgress<TProgress> source, global::System.IProgress<TProgress> progress) { throw null; }
public static global::System.Threading.Tasks.Task AsTask<TProgress>(this global::Windows.Foundation.IAsyncActionWithProgress<TProgress> source, global::System.Threading.CancellationToken cancellationToken) { throw null; }
public static global::System.Threading.Tasks.Task AsTask<TProgress>(this global::Windows.Foundation.IAsyncActionWithProgress<TProgress> source, global::System.Threading.CancellationToken cancellationToken, global::System.IProgress<TProgress> progress) { throw null; }
public static global::System.Threading.Tasks.Task<TResult> AsTask<TResult>(this global::Windows.Foundation.IAsyncOperation<TResult> source) { throw null; }
public static global::System.Threading.Tasks.Task<TResult> AsTask<TResult>(this global::Windows.Foundation.IAsyncOperation<TResult> source, global::System.Threading.CancellationToken cancellationToken) { throw null; }
public static global::System.Threading.Tasks.Task<TResult> AsTask<TResult, TProgress>(this global::Windows.Foundation.IAsyncOperationWithProgress<TResult, TProgress> source) { throw null; }
public static global::System.Threading.Tasks.Task<TResult> AsTask<TResult, TProgress>(this global::Windows.Foundation.IAsyncOperationWithProgress<TResult, TProgress> source, global::System.IProgress<TProgress> progress) { throw null; }
public static global::System.Threading.Tasks.Task<TResult> AsTask<TResult, TProgress>(this global::Windows.Foundation.IAsyncOperationWithProgress<TResult, TProgress> source, global::System.Threading.CancellationToken cancellationToken) { throw null; }
public static global::System.Threading.Tasks.Task<TResult> AsTask<TResult, TProgress>(this global::Windows.Foundation.IAsyncOperationWithProgress<TResult, TProgress> source, global::System.Threading.CancellationToken cancellationToken, global::System.IProgress<TProgress> progress) { throw null; }
[global::System.ComponentModel.EditorBrowsableAttribute((global::System.ComponentModel.EditorBrowsableState)(1))]
public static global::System.Runtime.CompilerServices.TaskAwaiter GetAwaiter(this global::Windows.Foundation.IAsyncAction source) { throw null; }
[global::System.ComponentModel.EditorBrowsableAttribute((global::System.ComponentModel.EditorBrowsableState)(1))]
public static global::System.Runtime.CompilerServices.TaskAwaiter GetAwaiter<TProgress>(this global::Windows.Foundation.IAsyncActionWithProgress<TProgress> source) { throw null; }
[global::System.ComponentModel.EditorBrowsableAttribute((global::System.ComponentModel.EditorBrowsableState)(1))]
public static global::System.Runtime.CompilerServices.TaskAwaiter<TResult> GetAwaiter<TResult>(this global::Windows.Foundation.IAsyncOperation<TResult> source) { throw null; }
[global::System.ComponentModel.EditorBrowsableAttribute((global::System.ComponentModel.EditorBrowsableState)(1))]
public static global::System.Runtime.CompilerServices.TaskAwaiter<TResult> GetAwaiter<TResult, TProgress>(this global::Windows.Foundation.IAsyncOperationWithProgress<TResult, TProgress> source) { throw null; }
}
}
namespace System.IO
{
[global::System.Security.SecurityCriticalAttribute]
public static partial class WindowsRuntimeStorageExtensions
{
[global::System.CLSCompliantAttribute(false)]
public static global::System.Threading.Tasks.Task<global::System.IO.Stream> OpenStreamForReadAsync(this global::Windows.Storage.IStorageFile windowsRuntimeFile) { throw null; }
[global::System.CLSCompliantAttribute(false)]
public static global::System.Threading.Tasks.Task<global::System.IO.Stream> OpenStreamForReadAsync(this global::Windows.Storage.IStorageFolder rootDirectory, string relativePath) { throw null; }
[global::System.CLSCompliantAttribute(false)]
public static global::System.Threading.Tasks.Task<global::System.IO.Stream> OpenStreamForWriteAsync(this global::Windows.Storage.IStorageFile windowsRuntimeFile) { throw null; }
[global::System.CLSCompliantAttribute(false)]
public static global::System.Threading.Tasks.Task<global::System.IO.Stream> OpenStreamForWriteAsync(this global::Windows.Storage.IStorageFolder rootDirectory, string relativePath, global::Windows.Storage.CreationCollisionOption creationCollisionOption) { throw null; }
}
[global::System.Security.SecurityCriticalAttribute]
public static partial class WindowsRuntimeStreamExtensions
{
[global::System.CLSCompliantAttribute(false)]
public static global::Windows.Storage.Streams.IInputStream AsInputStream(this global::System.IO.Stream stream) { throw null; }
[global::System.CLSCompliantAttribute(false)]
public static global::Windows.Storage.Streams.IOutputStream AsOutputStream(this global::System.IO.Stream stream) { throw null; }
[global::System.CLSCompliantAttribute(false)]
public static global::Windows.Storage.Streams.IRandomAccessStream AsRandomAccessStream(this global::System.IO.Stream stream) { throw null; }
[global::System.CLSCompliantAttribute(false)]
public static global::System.IO.Stream AsStream(this global::Windows.Storage.Streams.IRandomAccessStream windowsRuntimeStream) { throw null; }
[global::System.CLSCompliantAttribute(false)]
public static global::System.IO.Stream AsStream(this global::Windows.Storage.Streams.IRandomAccessStream windowsRuntimeStream, int bufferSize) { throw null; }
[global::System.CLSCompliantAttribute(false)]
public static global::System.IO.Stream AsStreamForRead(this global::Windows.Storage.Streams.IInputStream windowsRuntimeStream) { throw null; }
[global::System.CLSCompliantAttribute(false)]
public static global::System.IO.Stream AsStreamForRead(this global::Windows.Storage.Streams.IInputStream windowsRuntimeStream, int bufferSize) { throw null; }
[global::System.CLSCompliantAttribute(false)]
public static global::System.IO.Stream AsStreamForWrite(this global::Windows.Storage.Streams.IOutputStream windowsRuntimeStream) { throw null; }
[global::System.CLSCompliantAttribute(false)]
public static global::System.IO.Stream AsStreamForWrite(this global::Windows.Storage.Streams.IOutputStream windowsRuntimeStream, int bufferSize) { throw null; }
}
}
namespace System.Runtime.InteropServices.WindowsRuntime
{
[global::System.CLSCompliantAttribute(false)]
[global::System.Security.SecurityCriticalAttribute]
public static partial class AsyncInfo
{
public static global::Windows.Foundation.IAsyncAction Run(global::System.Func<global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task> taskProvider) { throw null; }
public static global::Windows.Foundation.IAsyncActionWithProgress<TProgress> Run<TProgress>(global::System.Func<global::System.Threading.CancellationToken, global::System.IProgress<TProgress>, global::System.Threading.Tasks.Task> taskProvider) { throw null; }
public static global::Windows.Foundation.IAsyncOperation<TResult> Run<TResult>(global::System.Func<global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task<TResult>> taskProvider) { throw null; }
public static global::Windows.Foundation.IAsyncOperationWithProgress<TResult, TProgress> Run<TResult, TProgress>(global::System.Func<global::System.Threading.CancellationToken, global::System.IProgress<TProgress>, global::System.Threading.Tasks.Task<TResult>> taskProvider) { throw null; }
}
[global::System.Security.SecurityCriticalAttribute]
public sealed partial class WindowsRuntimeBuffer
{
internal WindowsRuntimeBuffer() { }
[global::System.CLSCompliantAttribute(false)]
public static global::Windows.Storage.Streams.IBuffer Create(byte[] data, int offset, int length, int capacity) { throw null; }
[global::System.CLSCompliantAttribute(false)]
public static global::Windows.Storage.Streams.IBuffer Create(int capacity) { throw null; }
}
[global::System.Security.SecurityCriticalAttribute]
public static partial class WindowsRuntimeBufferExtensions
{
[global::System.CLSCompliantAttribute(false)]
public static global::Windows.Storage.Streams.IBuffer AsBuffer(this byte[] source) { throw null; }
[global::System.CLSCompliantAttribute(false)]
public static global::Windows.Storage.Streams.IBuffer AsBuffer(this byte[] source, int offset, int length) { throw null; }
[global::System.CLSCompliantAttribute(false)]
public static global::Windows.Storage.Streams.IBuffer AsBuffer(this byte[] source, int offset, int length, int capacity) { throw null; }
[global::System.CLSCompliantAttribute(false)]
public static global::System.IO.Stream AsStream(this global::Windows.Storage.Streams.IBuffer source) { throw null; }
[global::System.CLSCompliantAttribute(false)]
public static void CopyTo(this byte[] source, int sourceIndex, global::Windows.Storage.Streams.IBuffer destination, uint destinationIndex, int count) { }
[global::System.CLSCompliantAttribute(false)]
public static void CopyTo(this byte[] source, global::Windows.Storage.Streams.IBuffer destination) { }
[global::System.CLSCompliantAttribute(false)]
public static void CopyTo(this global::Windows.Storage.Streams.IBuffer source, byte[] destination) { }
[global::System.CLSCompliantAttribute(false)]
public static void CopyTo(this global::Windows.Storage.Streams.IBuffer source, uint sourceIndex, byte[] destination, int destinationIndex, int count) { }
[global::System.CLSCompliantAttribute(false)]
public static void CopyTo(this global::Windows.Storage.Streams.IBuffer source, uint sourceIndex, global::Windows.Storage.Streams.IBuffer destination, uint destinationIndex, uint count) { }
[global::System.CLSCompliantAttribute(false)]
public static void CopyTo(this global::Windows.Storage.Streams.IBuffer source, global::Windows.Storage.Streams.IBuffer destination) { }
[global::System.CLSCompliantAttribute(false)]
public static byte GetByte(this global::Windows.Storage.Streams.IBuffer source, uint byteOffset) { throw null; }
[global::System.CLSCompliantAttribute(false)]
public static global::Windows.Storage.Streams.IBuffer GetWindowsRuntimeBuffer(this global::System.IO.MemoryStream underlyingStream) { throw null; }
[global::System.CLSCompliantAttribute(false)]
public static global::Windows.Storage.Streams.IBuffer GetWindowsRuntimeBuffer(this global::System.IO.MemoryStream underlyingStream, int positionInStream, int length) { throw null; }
[global::System.CLSCompliantAttribute(false)]
public static bool IsSameData(this global::Windows.Storage.Streams.IBuffer buffer, global::Windows.Storage.Streams.IBuffer otherBuffer) { throw null; }
[global::System.CLSCompliantAttribute(false)]
public static byte[] ToArray(this global::Windows.Storage.Streams.IBuffer source) { throw null; }
[global::System.CLSCompliantAttribute(false)]
public static byte[] ToArray(this global::Windows.Storage.Streams.IBuffer source, uint sourceIndex, int count) { throw null; }
}
}
namespace Windows.Foundation
{
[global::System.Security.SecurityCriticalAttribute]
[global::System.Runtime.InteropServices.StructLayoutAttribute(global::System.Runtime.InteropServices.LayoutKind.Sequential)]
public partial struct Point
{
public Point(double x, double y) { throw null; }
public double X { get { throw null; } set { } }
public double Y { get { throw null; } set { } }
[global::System.Security.SecuritySafeCriticalAttribute]
public override bool Equals(object o) { throw null; }
public bool Equals(global::Windows.Foundation.Point value) { throw null; }
[global::System.Security.SecuritySafeCriticalAttribute]
public override int GetHashCode() { throw null; }
public static bool operator ==(global::Windows.Foundation.Point point1, global::Windows.Foundation.Point point2) { throw null; }
public static bool operator !=(global::Windows.Foundation.Point point1, global::Windows.Foundation.Point point2) { throw null; }
[global::System.Security.SecuritySafeCriticalAttribute]
public override string ToString() { throw null; }
public string ToString(global::System.IFormatProvider provider) { throw null; }
}
[global::System.Security.SecurityCriticalAttribute]
[global::System.Runtime.InteropServices.StructLayoutAttribute(global::System.Runtime.InteropServices.LayoutKind.Sequential)]
public partial struct Rect
{
public Rect(double x, double y, double width, double height) { throw null; }
public Rect(global::Windows.Foundation.Point point1, global::Windows.Foundation.Point point2) { throw null; }
public Rect(global::Windows.Foundation.Point location, global::Windows.Foundation.Size size) { throw null; }
public double Bottom { get { throw null; } }
public static global::Windows.Foundation.Rect Empty { get { throw null; } }
public double Height { get { throw null; } set { } }
public bool IsEmpty { get { throw null; } }
public double Left { get { throw null; } }
public double Right { get { throw null; } }
public double Top { get { throw null; } }
public double Width { get { throw null; } set { } }
public double X { get { throw null; } set { } }
public double Y { get { throw null; } set { } }
public bool Contains(global::Windows.Foundation.Point point) { throw null; }
[global::System.Security.SecuritySafeCriticalAttribute]
public override bool Equals(object o) { throw null; }
public bool Equals(global::Windows.Foundation.Rect value) { throw null; }
[global::System.Security.SecuritySafeCriticalAttribute]
public override int GetHashCode() { throw null; }
public void Intersect(global::Windows.Foundation.Rect rect) { }
public static bool operator ==(global::Windows.Foundation.Rect rect1, global::Windows.Foundation.Rect rect2) { throw null; }
public static bool operator !=(global::Windows.Foundation.Rect rect1, global::Windows.Foundation.Rect rect2) { throw null; }
[global::System.Security.SecuritySafeCriticalAttribute]
public override string ToString() { throw null; }
public string ToString(global::System.IFormatProvider provider) { throw null; }
public void Union(global::Windows.Foundation.Point point) { }
public void Union(global::Windows.Foundation.Rect rect) { }
}
[global::System.Security.SecurityCriticalAttribute]
[global::System.Runtime.InteropServices.StructLayoutAttribute(global::System.Runtime.InteropServices.LayoutKind.Sequential)]
public partial struct Size
{
public Size(double width, double height) { throw null; }
public static global::Windows.Foundation.Size Empty { get { throw null; } }
public double Height { get { throw null; } set { } }
public bool IsEmpty { get { throw null; } }
public double Width { get { throw null; } set { } }
[global::System.Security.SecuritySafeCriticalAttribute]
public override bool Equals(object o) { throw null; }
public bool Equals(global::Windows.Foundation.Size value) { throw null; }
[global::System.Security.SecuritySafeCriticalAttribute]
public override int GetHashCode() { throw null; }
public static bool operator ==(global::Windows.Foundation.Size size1, global::Windows.Foundation.Size size2) { throw null; }
public static bool operator !=(global::Windows.Foundation.Size size1, global::Windows.Foundation.Size size2) { throw null; }
[global::System.Security.SecuritySafeCriticalAttribute]
public override string ToString() { throw null; }
}
}
namespace Windows.UI
{
[global::System.Security.SecurityCriticalAttribute]
[global::System.Runtime.InteropServices.StructLayoutAttribute(global::System.Runtime.InteropServices.LayoutKind.Sequential)]
public partial struct Color
{
public byte A { get { throw null; } set { } }
public byte B { get { throw null; } set { } }
public byte G { get { throw null; } set { } }
public byte R { get { throw null; } set { } }
[global::System.Security.SecuritySafeCriticalAttribute]
public override bool Equals(object o) { throw null; }
public bool Equals(global::Windows.UI.Color color) { throw null; }
public static global::Windows.UI.Color FromArgb(byte a, byte r, byte g, byte b) { throw null; }
[global::System.Security.SecuritySafeCriticalAttribute]
public override int GetHashCode() { throw null; }
public static bool operator ==(global::Windows.UI.Color color1, global::Windows.UI.Color color2) { throw null; }
public static bool operator !=(global::Windows.UI.Color color1, global::Windows.UI.Color color2) { throw null; }
[global::System.Security.SecuritySafeCriticalAttribute]
public override string ToString() { throw null; }
public string ToString(global::System.IFormatProvider provider) { throw null; }
}
}

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<UseECMAKey>true</UseECMAKey>
<!--
NOTE: Suppress false positive warning for the special case where we're building System.Runtime.WindowsRuntime itself
at a version other than 4.0.0.0, which is referenced indirectly via the mscorlib.dll design-time facade, which
in turn is a required compile-time-only reference when building anything with a reference to a WinMD.
error CS1698: Warning as Error: Circular assembly reference 'System.Runtime.WindowsRuntime,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' does not
match the output assembly name 'System.Runtime.WindowsRuntime, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
-->
<NoWarn>1698</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Release|AnyCPU'" />
<ItemGroup>
<Compile Include="System.Runtime.WindowsRuntime.cs" />
<Compile Include="System.Runtime.WindowsRuntime.Manual.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Microsoft.TargetingPack.Private.WinRT\ref\Microsoft.TargetingPack.Private.WinRT.depproj" />
<ProjectReference Include="..\..\System.Runtime\ref\System.Runtime.csproj" />
<ProjectReference Include="..\..\System.Runtime.Extensions\ref\System.Runtime.Extensions.csproj" />
<ProjectReference Include="..\..\System.IO\ref\System.IO.csproj" />
<ProjectReference Include="..\..\System.Threading.Tasks\ref\System.Threading.Tasks.csproj" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>

View File

@@ -0,0 +1,348 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Argument_BufferIndexExceedsCapacity" xml:space="preserve">
<value>The specified buffer index is not within the buffer capacity.</value>
</data>
<data name="Argument_BufferLengthExceedsCapacity" xml:space="preserve">
<value>The specified useful data length exceeds the capacity of this buffer.</value>
</data>
<data name="Argument_IndexOutOfArrayBounds" xml:space="preserve">
<value>The specified index is out of bounds of the specified array.</value>
</data>
<data name="Argument_InstancesImplementingIRASThatCanReadMustImplementIIS" xml:space="preserve">
<value>The specified Windows Runtime stream supports the IRandomAccessStream interface and its CanRead property returns TRUE, however it does not implement the IInputStream interface. Windows Runtime streams with such inconsistent capabilities cannot be converted to managed Stream objects. IRandomAccessStream instances whose CanRead property returns TRUE must implement the IInputStream interface.</value>
</data>
<data name="Argument_InstancesImplementingIRASThatCanWriteMustImplementIOS" xml:space="preserve">
<value>The specified Windows Runtime stream supports the IRandomAccessStream interface and its CanWrite property returns TRUE, however it does not implement the IOutputStream interface. Windows Runtime streams with such inconsistent capabilities cannot be converted to managed Stream objects. IRandomAccessStream instances whose CanWrite property returns TRUE must implement the IOutputStream interface.</value>
</data>
<data name="Argument_InsufficientArrayElementsAfterOffset" xml:space="preserve">
<value>The specified array does not contain the specified number of elements starting at the specified offset.</value>
</data>
<data name="Argument_InsufficientBufferCapacity" xml:space="preserve">
<value>The specified buffer capacity is not sufficient to hold data of the specified length.</value>
</data>
<data name="Argument_InsufficientSpaceInSourceBuffer" xml:space="preserve">
<value>The specified source buffer does not contain the specified number of elements starting at the specified offset.</value>
</data>
<data name="Argument_InsufficientSpaceInTargetBuffer" xml:space="preserve">
<value>The specified destination buffer is not large enough to hold the specified number of bytes starting at the specified offset.</value>
</data>
<data name="Argument_NotSufficientCapabilitiesToConvertToWinRtStream" xml:space="preserve">
<value>Cannot convert the specified Stream object to a Windows Runtime stream because it does not have sufficient capabilities. In order to convert a System.IO.Stream instance to a Windows Runtime stream at least one of the properties CanRead, CanWrite, CanSeek must return TRUE; however, none of these properties returns TRUE for the specified Stream.</value>
</data>
<data name="Argument_ObjectMustBeWinRtStreamToConvertToNetFxStream" xml:space="preserve">
<value>The specified object cannot be converted to a System.IO.Stream instance because it is not a Windows Runtime stream. In order to convert an object to a Stream instance it must implement at least one of the following 3 Windows Runtime stream interfaces: IInputStream, IOutputStream, IRandomAccessStream.</value>
</data>
<data name="Argument_RelativePathMayNotBeWhitespaceOnly" xml:space="preserve">
<value>The specified relative path may not consist of white spaces only</value>
</data>
<data name="Argument_StreamPositionBeyondEOS" xml:space="preserve">
<value>The specified stream position is beyond the end of the stream.</value>
</data>
<data name="Argument_UnexpectedAsyncResult" xml:space="preserve">
<value>The specified AsyncResult does not correspond to any outstanding IO operation.</value>
</data>
<data name="Argument_WinRtStreamCannotReadOrWrite" xml:space="preserve">
<value>The specified Windows Runtime stream does not support reading nor writing. Windows Runtime streams with such capabilities cannot be converted to managed Stream objects. Use a Windows Runtime stream that can support reading, writing or both.</value>
</data>
<data name="ArgumentOutOfRange_CannotResizeStreamToNegative" xml:space="preserve">
<value>Cannot set the length of a stream to a negative value.</value>
</data>
<data name="ArgumentOutOfRange_IO_CannotSeekToNegativePosition" xml:space="preserve">
<value>Cannot seek to an absolute stream position that is negative.</value>
</data>
<data name="ArgumentOutOfRange_InvalidInputStreamOptionsEnumValue" xml:space="preserve">
<value>The specified value is not a valid member of the InputStreamOptions enumeration.</value>
</data>
<data name="ArgumentOutOfRange_WinRtAdapterBufferSizeMayNotBeNegative" xml:space="preserve">
<value>The buffer size for a Windows Runtime stream adapter may not be negative. Use a positive buffer size or 0 to disable buffering.</value>
</data>
<data name="InvalidOperation_CannotCallThisMethodInCurrentState" xml:space="preserve">
<value>The state of this object does not permit invoking this method.</value>
</data>
<data name="InvalidOperation_CannotChangeBufferSizeOfWinRtStreamAdapter" xml:space="preserve">
<value>Cannot convert the specified Windows Runtime stream to a managed System.IO.Stream object with the specified buffer size because this Windows Runtime stream has been previously converted to a managed Stream object with a different buffer size. Ensure that the 'bufferSize' argument matches the existing buffer or use the '{0}'-overload without the 'bufferSize' argument to convert the specified Windows Runtime stream to a Stream object with the same buffer size as previously.</value>
</data>
<data name="InvalidOperation_CannotChangeBufferSizeOfWinRtStreamAdapterToZero" xml:space="preserve">
<value>Cannot convert the specified Windows Runtime stream to a managed System.IO.Stream object without a buffer because this Windows Runtime stream has been previously converted to a managed Stream object with a buffer. Ensure that the 'bufferSize' argument matches the existing buffer or use the '{0}'-overload without the 'bufferSize' argument to convert the specified Windows Runtime stream to a Stream object with the same buffer size as previously.</value>
</data>
<data name="InvalidOperation_CannotGetResultsFromIncompleteOperation" xml:space="preserve">
<value>Cannot call GetResults on this asynchronous info because the underlying operation has not completed.</value>
</data>
<data name="InvalidOperation_CannotSetCompletionHanlderMoreThanOnce" xml:space="preserve">
<value>The 'Completed' handler delegate cannot be set more than once, but this handler has already been set.</value>
</data>
<data name="InvalidOperation_CannotSetStreamSizeCannotWrite" xml:space="preserve">
<value>Cannot set the size of this stream because it cannot be written to.</value>
</data>
<data name="InvalidOperation_IllegalStateChange" xml:space="preserve">
<value>The specified state transition is illegal for the current state of this object.</value>
</data>
<data name="InvalidOperation_InvalidAsyncCompletion" xml:space="preserve">
<value>The asynchronous operation could not be completed.</value>
</data>
<data name="InvalidOperation_MultipleIOCompletionCallbackInvocation" xml:space="preserve">
<value>A callback for the same asynchronous IO operation was invoked more than once.</value>
</data>
<data name="InvalidOperation_TaskProviderReturnedUnstartedTask" xml:space="preserve">
<value>The Task provider delegate specified for this IAsyncInfo instance returned a Task object that was not started. Task instances must be run immediately upon creation.</value>
</data>
<data name="InvalidOperation_UnexpectedAsyncOperationID" xml:space="preserve">
<value>This AsyncResult or Task corresponds to a different asynchronous operation ID than the one that invoked the completion callback.</value>
</data>
<data name="InvalidOperation_UnstartedTaskSpecified" xml:space="preserve">
<value>The specified underlying Task is not started. Task instances must be run immediately upon creation.</value>
</data>
<data name="IO_CannotSeekBeyondInt64MaxValue" xml:space="preserve">
<value>Cannot seek to an absolute stream position that is larger than 2^63 - 1 bytes. (2^63 - 1 = 0x7FFFFFFFFFFFFFFF = Int64.MaxValue).</value>
</data>
<data name="IO_CannotSetSizeBeyondInt64MaxValue" xml:space="preserve">
<value>This Windows Runtime stream is backed by a .NET Stream; its size cannot be set to a value that is larger than 2^63 - 1 bytes. (2^63 - 1 = 0x7FFFFFFFFFFFFFFF = Int64.MaxValue).</value>
</data>
<data name="IO_General" xml:space="preserve">
<value>An IO error occurred in the Windows runtime system.</value>
</data>
<data name="IO_UnderlyingWinRTStreamTooLong_CannotUseLengthOrPosition" xml:space="preserve">
<value>This Stream is backed by a Windows Runtime stream with a length that exceeds 2^63 - 1 bytes. Operations related to the stream's length or position cannot be performed on streams when the length exceeds 2^63 - 1 bytes. (2^63 - 1 = 0x7FFFFFFFFFFFFFFF = Int64.MaxValue = approx. 8000 PetaBytes.)</value>
</data>
<data name="NotImplemented_NativeRoutineNotFound" xml:space="preserve">
<value>A native library routine was not found: {0}.</value>
</data>
<data name="NotSupported_CannotConvertNotReadableToInputStream" xml:space="preserve">
<value>Cannot use the specified Stream as a Windows Runtime IInputStream because this Stream is not readable.</value>
</data>
<data name="NotSupported_CannotConvertNotSeekableToRandomAccessStream" xml:space="preserve">
<value>Cannot use the specified Stream as a Windows Runtime IRandomAccessStream because this Stream does not support seeking.</value>
</data>
<data name="NotSupported_CannotConvertNotWritableToOutputStream" xml:space="preserve">
<value>Cannot use the specified Stream as a Windows Runtime IOutputStream because this Stream is not writable.</value>
</data>
<data name="NotSupported_CannotReadFromStream" xml:space="preserve">
<value>This stream does not support read access.</value>
</data>
<data name="NotSupported_CannotSeekInStream" xml:space="preserve">
<value>This stream does not support seeking.</value>
</data>
<data name="NotSupported_CannotUseLength_StreamNotSeekable" xml:space="preserve">
<value>This stream does not support the Length property because it is not seekable.</value>
</data>
<data name="NotSupported_CannotUsePosition_StreamNotSeekable" xml:space="preserve">
<value>This stream does not support the Position property because it is not seekable.</value>
</data>
<data name="NotSupported_CannotWriteToStream" xml:space="preserve">
<value>This stream does not support write access.</value>
</data>
<data name="NotSupported_CloningNotSupported" xml:space="preserve">
<value>This IRandomAccessStream does not support the {0} method because it requires cloning and this stream does not support cloning.</value>
</data>
<data name="NullReference_IOCompletionCallbackCannotProcessNullAsyncInfo" xml:space="preserve">
<value>The Windows Runtime stream that underlies this System.IO.Stream object has invoked an IO completion callback and specified null for the IAsyncInfo instance that describes the completed IO operation. This behavior is not supported because results cannot be retrieved from a null operation. Either the underlying Windows Runtime stream has a faulty implementation, or you are using a Windows Runtime object in an unsupported runtime environment.</value>
</data>
<data name="NullReference_TaskProviderReturnedNull" xml:space="preserve">
<value>The task provider delegate used to create this asynchronous operation returned null, but a valid Task object was expected.</value>
</data>
<data name="ObjectDisposed_AsyncInfoIsClosed" xml:space="preserve">
<value>The requested invocation is not permitted because this IAsyncInfo instance has already been closed.</value>
</data>
<data name="ObjectDisposed_CannotPerformOperation" xml:space="preserve">
<value>The requested operation cannot be performed because this stream has already been disposed.</value>
</data>
<data name="WinRtCOM_Error" xml:space="preserve">
<value>An error has occurred.</value>
</data>
<data name="ArgumentOutOfRange_MustBePositive" xml:space="preserve">
<value>'{0}' must be greater than zero.</value>
</data>
<data name="ObjectDisposed_StreamClosed" xml:space="preserve">
<value>Cannot access a closed Stream.</value>
</data>
<data name="NotSupported_UnseekableStream" xml:space="preserve">
<value>Stream does not support seeking.</value>
</data>
<data name="NotSupported_UnreadableStream" xml:space="preserve">
<value>Stream does not support reading.</value>
</data>
<data name="NotSupported_UnwritableStream" xml:space="preserve">
<value>Stream does not support writing.</value>
</data>
<data name="ArgumentNull_Buffer" xml:space="preserve">
<value>Buffer cannot be null.</value>
</data>
<data name="ArgumentOutOfRange_NegFileSize" xml:space="preserve">
<value>Length must be non-negative.</value>
</data>
<data name="NotSupported_CannotWriteToBufferedStreamIfReadBufferCannotBeFlushed" xml:space="preserve">
<value>Cannot write to a BufferedStream while the read buffer is not empty if the underlying stream is not seekable. Ensure that the stream underlying this BufferedStream can seek or avoid interleaving read and write operations on this BufferedStream.</value>
</data>
<data name="Argument_InvalidSafeBufferOffLen" xml:space="preserve">
<value>Offset and length were greater than the size of the SafeBuffer.</value>
</data>
<data name="InvalidOperation_CalledTwice" xml:space="preserve">
<value>The method cannot be called twice on the same instance.</value>
</data>
<data name="ArgumentOutOfRange_LengthGreaterThanCapacity" xml:space="preserve">
<value>The length cannot be greater than the capacity.</value>
</data>
<data name="ArgumentOutOfRange_UnmanagedMemStreamWrapAround" xml:space="preserve">
<value>The UnmanagedMemoryStream capacity would wrap around the high end of the address space.</value>
</data>
<data name="ArgumentOutOfRange_Enum" xml:space="preserve">
<value>Enum value was out of legal range.</value>
</data>
<data name="NotSupported_UmsSafeBuffer" xml:space="preserve">
<value>This operation is not supported for an UnmanagedMemoryStream created from a SafeBuffer.</value>
</data>
<data name="IndexOutOfRange_UMSPosition" xml:space="preserve">
<value>Unmanaged memory stream position was beyond the capacity of the stream.</value>
</data>
<data name="IO_SeekBeforeBegin" xml:space="preserve">
<value>An attempt was made to move the position before the beginning of the stream.</value>
</data>
<data name="Argument_InvalidSeekOrigin" xml:space="preserve">
<value>Invalid seek origin.</value>
</data>
<data name="IO_FixedCapacity" xml:space="preserve">
<value>Unable to expand length of this stream beyond its capacity.</value>
</data>
<data name="IO_StreamTooLong" xml:space="preserve">
<value>Stream was too long.</value>
</data>
<data name="Arg_BufferTooSmall" xml:space="preserve">
<value>Not enough space available in the buffer.</value>
</data>
<data name="ArgumentOutOfRange_NeedNonNegNum" xml:space="preserve">
<value>Non-negative number required.</value>
</data>
<data name="Argument_InvalidOffLen" xml:space="preserve">
<value>Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.</value>
</data>
<data name="ArgumentOutOfRange_StreamLength" xml:space="preserve">
<value>Stream length must be non-negative and less than 2^31 - 1 - origin.</value>
</data>
<data name="DirectUI_Empty" xml:space="preserve">
<value>Empty.</value>
</data>
<data name="InvalidOperation_SendNotSupportedOnWindowsRTSynchronizationContext" xml:space="preserve">
<value>Send is not supported in the Windows Runtime SynchronizationContext</value>
</data>
<data name="UnauthorizedAccess_InternalBuffer" xml:space="preserve">
<value>MemoryStream's internal buffer cannot be accessed.</value>
</data>
</root>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<ItemGroup>
<Project Include="System.Runtime.WindowsRuntime.csproj">
<OSGroup>Windows_NT</OSGroup>
</Project>
<Project Include="System.Runtime.WindowsRuntime.csproj">
<OSGroup>Windows_NT</OSGroup>
<TargetGroup>uap101aot</TargetGroup>
</Project>
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.traversal.targets))\dir.traversal.targets" />
</Project>

View File

@@ -0,0 +1,137 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<Configuration Condition="'$(Configuration)'==''">Windows_Debug</Configuration>
</PropertyGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<UseECMAKey>true</UseECMAKey>
<AssemblyName>System.Runtime.WindowsRuntime</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<ClsCompliant>true</ClsCompliant>
<IsPartialFacadeAssembly Condition="'$(TargetGroup)' == 'uap101aot'">true</IsPartialFacadeAssembly>
<!-- CS1698 - Disable warning about reference to 4.0.0.0 System.Runtime.WindowsRuntime having same simple name as target assembly -->
<!-- CS0436 - System.Private.CoreLib has internals visible to System.Runtime.WindowsRuntime and is colliding internals on common shared code -->
<NoWarn>$(NoWarn);1698;0436</NoWarn>
<ProjectGuid>{844A2A0B-4169-49C3-B367-AFDC4894E487}</ProjectGuid>
<PackageTargetRuntime>win8</PackageTargetRuntime>
<PackageTargetRuntime Condition="'$(TargetGroup)' == 'uap101aot'">win8-aot</PackageTargetRuntime>
<NuGetTargetMoniker Condition="'$(TargetGroup)' == ''">.NETStandard,Version=v1.7</NuGetTargetMoniker>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetGroup)'==''">
<DefineConstants>$(DefineConstants);netstandard;FEATURE_APPX</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Windows_Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Windows_Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap101aot_Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap101aot_Release|AnyCPU'" />
<ItemGroup Condition="'$(TargetGroup)'==''">
<TargetingPackReference Include="System.Private.CoreLib" />
<ProjectReference Include="$(SourceDir)\mscorlib.WinRT-Facade\mscorlib.WinRT-Facade.csproj" />
<!-- Needed for the compiler to resolve IObservableMap.MapChanged. -->
<ProjectReference Include="..\..\System.Runtime\src\System.Runtime.csproj" />
<ProjectReference Include="..\..\System.Runtime.Extensions\ref\System.Runtime.Extensions.csproj">
<UndefineProperties>OSGroup;TargetGroup</UndefineProperties>
<Aliases>System_Runtime_Extensions</Aliases>
</ProjectReference>
<ProjectReference Include="..\..\System.Diagnostics.Debug\src\System.Diagnostics.Debug.csproj" />
<ProjectReference Include="..\..\System.Diagnostics.Tools\src\System.Diagnostics.Tools.csproj" />
<ProjectReference Include="..\..\System.Runtime.InteropServices.WindowsRuntime\src\System.Runtime.InteropServices.WindowsRuntime.csproj">
<UndefineProperties>OSGroup</UndefineProperties>
</ProjectReference>
<ProjectReference Include="..\..\System.ObjectModel\src\System.ObjectModel.csproj">
<UndefineProperties>OSGroup</UndefineProperties>
</ProjectReference>
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)' == 'uap101aot'">
<!-- We need to add this for now because these three types exist in System.Private.Interop.dll and Windows.winmd. -->
<SeedTypePreference Include="Windows.Foundation.Point">
<Assembly>System.Private.Interop</Assembly>
</SeedTypePreference>
<SeedTypePreference Include="Windows.Foundation.Rect">
<Assembly>System.Private.Interop</Assembly>
</SeedTypePreference>
<SeedTypePreference Include="Windows.Foundation.Size">
<Assembly>System.Private.Interop</Assembly>
</SeedTypePreference>
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)' == 'uap101aot'">
<TargetingPackReference Include="System.Private.Interop" />
<TargetingPackReference Include="System.Private.Corelib" />
<TargetingPackReference Include="System.Private.Threading" />
<TargetingPackReference Include="Windows" />
<ProjectReference Include="$(SourceDir)\mscorlib.WinRT-Facade\mscorlib.WinRT-Facade.csproj" />
<TargetingPackReference Include="System.Private.CoreLib.WinRTInterop" />
<ProjectReference Include="..\..\System.Runtime\src\System.Runtime.csproj">
<TargetGroup>uap101aot</TargetGroup>
</ProjectReference>
<ProjectReference Include="..\..\System.Runtime.Extensions\ref\System.Runtime.Extensions.csproj">
<UndefineProperties>OSGroup;TargetGroup</UndefineProperties>
<Aliases>System_Runtime_Extensions</Aliases>
</ProjectReference>
<ProjectReference Include="..\..\System.Resources.ResourceManager\src\System.Resources.ResourceManager.csproj">
<TargetGroup>uap101aot</TargetGroup>
</ProjectReference>
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)'==''">
<Compile Include="System\IO\StreamOperationAsyncResult.CoreCLR.cs" />
<Compile Include="System\Runtime\InteropServices\WindowsRuntime\MarshalingHelpers.cs" />
<Compile Include="System\Runtime\InteropServices\WindowsRuntime\RestrictedErrorInfoHelper.cs" />
<Compile Include="System\Threading\Tasks\AsyncInfoToTaskBridge.CoreCLR.cs" />
<Compile Include="System\Threading\WindowsRuntimeSynchronizationContext.cs" />
<Compile Include="System\WindowsRuntimeSystemExtensions.CoreCLR.cs" />
<Compile Include="$(CommonPath)\Interop\Windows\mincore\Interop.GetRestrictedErrorInfo.cs">
<Link>Common\Interop\Windows\mincore\Interop.GetRestrictedErrorInfo.cs</Link>
</Compile>
<Compile Include="System\Windows\Point.cs" />
<Compile Include="System\Windows\Rect.cs" />
<Compile Include="System\Windows\Size.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)'=='uap101aot'">
<Compile Include="System\IO\StreamOperationAsyncResult.CoreRT.cs" />
<Compile Include="System\IO\UnmanagedMemoryStreamInternal.cs" />
<Compile Include="System\Threading\Tasks\AsyncInfoToTaskBridge.CoreRT.cs" />
<Compile Include="System\WindowsRuntimeSystemExtensions.CoreRT.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.ResolveLocaleName.cs">
<Link>Common\Interop\Windows\kernel32\Interop.ResolveLocaleName.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Windows\mincore\Interop.RoGetBufferMarshaler.cs">
<Link>Common\Interop\Windows\mincore\Interop.RoGetBufferMarshaler.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Windows\Interop.Libraries.cs">
<Link>Common\Interop\Windows\Interop.Libraries.cs</Link>
</Compile>
<Compile Include="System\InternalHelpers.cs" />
<Compile Include="System\IO\NetFxToWinRtStreamAdapter.cs" />
<Compile Include="System\IO\StreamOperationAsyncResult.cs" />
<Compile Include="System\IO\StreamOperationsImplementation.cs" />
<Compile Include="System\IO\WindowsRuntimeStorageExtensions.cs" />
<Compile Include="System\IO\WindowsRuntimeStreamExtensions.cs" />
<Compile Include="System\IO\WinRtIOHelper.cs" />
<Compile Include="System\IO\WinRtToNetFxStreamAdapter.cs" />
<Compile Include="System\Resources\WindowsRuntimeResourceManager.cs" />
<Compile Include="System\Runtime\InteropServices\HResults.cs" />
<Compile Include="System\Runtime\InteropServices\IAgileObject.cs" />
<Compile Include="System\Runtime\InteropServices\IMarshal.cs" />
<Compile Include="System\Runtime\InteropServices\WindowsRuntime\AsyncInfo.cs" />
<Compile Include="System\Runtime\InteropServices\WindowsRuntime\IBufferByteAccess.cs" />
<Compile Include="System\Runtime\InteropServices\WindowsRuntime\WindowsRuntimeBuffer.cs" />
<Compile Include="System\Runtime\InteropServices\WindowsRuntime\WindowsRuntimeBufferExtensions.cs" />
<Compile Include="System\Threading\Tasks\AsyncInfoIdGenerator.cs" />
<Compile Include="System\Threading\Tasks\ExceptionDispatchHelper.cs" />
<Compile Include="System\Threading\Tasks\TaskToAsyncActionAdapter.cs" />
<Compile Include="System\Threading\Tasks\TaskToAsyncActionWithProgressAdapter.cs" />
<Compile Include="System\Threading\Tasks\TaskToAsyncInfoAdapter.cs" />
<Compile Include="System\Threading\Tasks\TaskToAsyncOperationAdapter.cs" />
<Compile Include="System\Threading\Tasks\TaskToAsyncOperationWithProgressAdapter.cs" />
<Compile Include="System\VoidTypeParameter.cs" />
<Compile Include="System\Windows\TokenizerHelper.cs" />
<Compile Include="System\Windows\UI\Color.cs" />
</ItemGroup>
<ItemGroup>
<None Include="project.json" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>

View File

@@ -0,0 +1,38 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Runtime.CompilerServices;
using System.Security;
using System.Threading.Tasks;
using Windows.Storage;
namespace System.IO.IsolatedStorage
{
[FriendAccessAllowed]
internal class IsolatedStorageFileIOHelper : IsolatedStorageFileIOHelperBase
{
internal override void UnsafeMoveFile(string sourceFileFullPath, string destinationFileFullPath)
{
if (Directory.Exists(destinationFileFullPath))
{
string destinationFileName = Path.GetFileName(sourceFileFullPath);
Task.Run(() => { UnsafeMoveFileAsync(sourceFileFullPath, destinationFileFullPath, destinationFileName).Wait(); }).Wait();
}
else
{
string destinationFileName = Path.GetFileName(destinationFileFullPath);
string destinationDirectoryFullPath = Path.GetDirectoryName(destinationFileFullPath);
Task.Run(() => { UnsafeMoveFileAsync(sourceFileFullPath, destinationDirectoryFullPath, destinationFileName).Wait(); }).Wait();
}
}
private static async Task UnsafeMoveFileAsync(string sourceFileFullPath, string destinationFolderFullPath, string destinationFileName)
{
StorageFile sourceStorageFile = await StorageFile.GetFileFromPathAsync(sourceFileFullPath).ConfigureAwait(false);
StorageFolder destinationStorageFolder = await StorageFolder.GetFolderFromPathAsync(destinationFolderFullPath).ConfigureAwait(false);
await sourceStorageFile.MoveAsync(destinationStorageFolder, destinationFileName, NameCollisionOption.FailIfExists).ConfigureAwait(false);
}
}
}

View File

@@ -0,0 +1,478 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
extern alias System_Runtime_Extensions;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Runtime.InteropServices;
using System.Runtime.WindowsRuntime.Internal;
using System.Threading.Tasks;
using System.Threading;
using Windows.Foundation;
using Windows.Storage.Streams;
using MemoryStream = System_Runtime_Extensions::System.IO.MemoryStream;
namespace System.IO
{
/// <summary>
/// An <code>wrapper</code> for a managed stream that implements all WinRT stream operations.
/// This class must not implement any WinRT stream interfaces directly.
/// We never create instances of this class directly; instead we use classes defined in
/// the region Interface adapters to implement WinRT ifaces and create instances of those types.
/// See comment in that region for technical details.
/// </summary>
internal abstract class NetFxToWinRtStreamAdapter : IDisposable
{
#region Construction
#region Interface adapters
// Instances of private types defined in this section will be returned from NetFxToWinRtStreamAdapter.Create(..).
// Depending on the capabilities of the .NET stream for which we need to construct the adapter, we need to return
// an object that can be QIed (COM speak for "cast") to a well-defined set of ifaces.
// E.g, if the specified stream CanRead, but not CanSeek and not CanWrite, then we *must* return an object that
// can be QIed to IInputStream, but *not* IRandomAccessStream and *not* IOutputStream.
// There are two ways to do that:
// - We could explicitly implement ICustomQueryInterface and respond to QI requests by analyzing the stream capabilities
// - We can use the runtime's ability to do that for us, based on the ifaces the concrete class implements (or does not).
// The latter is much more elegant, and likely also faster.
private class InputStream : NetFxToWinRtStreamAdapter, IInputStream, IDisposable
{
internal InputStream(Stream stream, StreamReadOperationOptimization readOptimization)
: base(stream, readOptimization)
{
}
}
private class OutputStream : NetFxToWinRtStreamAdapter, IOutputStream, IDisposable
{
internal OutputStream(Stream stream, StreamReadOperationOptimization readOptimization)
: base(stream, readOptimization)
{
}
}
private class RandomAccessStream : NetFxToWinRtStreamAdapter, IRandomAccessStream, IInputStream, IOutputStream, IDisposable
{
internal RandomAccessStream(Stream stream, StreamReadOperationOptimization readOptimization)
: base(stream, readOptimization)
{
}
}
private class InputOutputStream : NetFxToWinRtStreamAdapter, IInputStream, IOutputStream, IDisposable
{
internal InputOutputStream(Stream stream, StreamReadOperationOptimization readOptimization)
: base(stream, readOptimization)
{
}
}
#endregion Interface adapters
// We may want to define different behaviour for different types of streams.
// For instance, ReadAsync treats MemoryStream special for performance reasons.
// The enum 'StreamReadOperationOptimization' describes the read optimization to employ for a
// given NetFxToWinRtStreamAdapter instance. In future, we might define other enums to follow a
// similar pattern, e.g. 'StreamWriteOperationOptimization' or 'StreamFlushOperationOptimization'.
private enum StreamReadOperationOptimization
{
AbstractStream = 0, MemoryStream
}
internal static NetFxToWinRtStreamAdapter Create(Stream stream)
{
if (stream == null)
throw new ArgumentNullException(nameof(stream));
StreamReadOperationOptimization readOptimization = StreamReadOperationOptimization.AbstractStream;
if (stream.CanRead)
readOptimization = DetermineStreamReadOptimization(stream);
NetFxToWinRtStreamAdapter adapter;
if (stream.CanSeek)
adapter = new RandomAccessStream(stream, readOptimization);
else if (stream.CanRead && stream.CanWrite)
adapter = new InputOutputStream(stream, readOptimization);
else if (stream.CanRead)
adapter = new InputStream(stream, readOptimization);
else if (stream.CanWrite)
adapter = new OutputStream(stream, readOptimization);
else
throw new ArgumentException(SR.Argument_NotSufficientCapabilitiesToConvertToWinRtStream);
return adapter;
}
private static StreamReadOperationOptimization DetermineStreamReadOptimization(Stream stream)
{
Debug.Assert(stream != null);
if (CanApplyReadMemoryStreamOptimization(stream))
return StreamReadOperationOptimization.MemoryStream;
return StreamReadOperationOptimization.AbstractStream;
}
private static bool CanApplyReadMemoryStreamOptimization(Stream stream)
{
MemoryStream memStream = stream as MemoryStream;
if (memStream == null)
return false;
ArraySegment<byte> arrSeg;
return memStream.TryGetBuffer(out arrSeg);
}
private NetFxToWinRtStreamAdapter(Stream stream, StreamReadOperationOptimization readOptimization)
{
Debug.Assert(stream != null);
Debug.Assert(stream.CanRead || stream.CanWrite || stream.CanSeek);
Contract.EndContractBlock();
Debug.Assert(!stream.CanRead || (stream.CanRead && this is IInputStream));
Debug.Assert(!stream.CanWrite || (stream.CanWrite && this is IOutputStream));
Debug.Assert(!stream.CanSeek || (stream.CanSeek && this is IRandomAccessStream));
_readOptimization = readOptimization;
_managedStream = stream;
}
#endregion Construction
#region Instance variables
private Stream _managedStream = null;
private bool _leaveUnderlyingStreamOpen = true;
private readonly StreamReadOperationOptimization _readOptimization;
#endregion Instance variables
#region Tools and Helpers
/// <summary>
/// We keep tables for mappings between managed and WinRT streams to make sure to always return the same adapter for a given underlying stream.
/// However, in order to avoid global locks on those tables, several instances of this type may be created and then can race to be entered
/// into the appropriate map table. All except for the winning instances will be thrown away. However, we must ensure that when the losers are
/// finalized, they do not dispose the underlying stream. To ensure that, we must call this method on the winner to notify it that it is safe to
/// dispose the underlying stream.
/// </summary>
internal void SetWonInitializationRace()
{
_leaveUnderlyingStreamOpen = false;
}
public Stream GetManagedStream()
{
return _managedStream;
}
private Stream EnsureNotDisposed()
{
Stream str = _managedStream;
if (str == null)
{
ObjectDisposedException ex = new ObjectDisposedException(SR.ObjectDisposed_CannotPerformOperation);
ex.SetErrorCode(HResults.RO_E_CLOSED);
throw ex;
}
return str;
}
#endregion Tools and Helpers
#region Common public interface
/// <summary>Implements IDisposable.Dispose (IClosable.Close in WinRT)</summary>
void IDisposable.Dispose()
{
Stream str = _managedStream;
if (str == null)
return;
_managedStream = null;
if (!_leaveUnderlyingStreamOpen)
str.Dispose();
}
#endregion Common public interface
#region IInputStream public interface
public IAsyncOperationWithProgress<IBuffer, UInt32> ReadAsync(IBuffer buffer, UInt32 count, InputStreamOptions options)
{
if (buffer == null)
{
// Mapped to E_POINTER.
throw new ArgumentNullException(nameof(buffer));
}
if (count < 0 || Int32.MaxValue < count)
{
ArgumentOutOfRangeException ex = new ArgumentOutOfRangeException(nameof(count));
ex.SetErrorCode(HResults.E_INVALIDARG);
throw ex;
}
if (buffer.Capacity < count)
{
ArgumentException ex = new ArgumentException(SR.Argument_InsufficientBufferCapacity);
ex.SetErrorCode(HResults.E_INVALIDARG);
throw ex;
}
if (!(options == InputStreamOptions.None || options == InputStreamOptions.Partial || options == InputStreamOptions.ReadAhead))
{
ArgumentOutOfRangeException ex = new ArgumentOutOfRangeException(nameof(options),
SR.ArgumentOutOfRange_InvalidInputStreamOptionsEnumValue);
ex.SetErrorCode(HResults.E_INVALIDARG);
throw ex;
}
// Commented due to a reported CCRewrite bug. Should uncomment when fixed:
//Contract.Ensures(Contract.Result<IAsyncOperationWithProgress<IBuffer, UInt32>>() != null);
//Contract.EndContractBlock();
Stream str = EnsureNotDisposed();
IAsyncOperationWithProgress<IBuffer, UInt32> readAsyncOperation;
switch (_readOptimization)
{
case StreamReadOperationOptimization.MemoryStream:
readAsyncOperation = StreamOperationsImplementation.ReadAsync_MemoryStream(str, buffer, count);
break;
case StreamReadOperationOptimization.AbstractStream:
readAsyncOperation = StreamOperationsImplementation.ReadAsync_AbstractStream(str, buffer, count, options);
break;
// Use this pattern to add more optimisation options if necessary:
//case StreamReadOperationOptimization.XxxxStream:
// readAsyncOperation = StreamOperationsImplementation.ReadAsync_XxxxStream(str, buffer, count, options);
// break;
default:
Debug.Assert(false, "We should never get here. Someone forgot to handle an input stream optimisation option.");
readAsyncOperation = null;
break;
}
return readAsyncOperation;
}
#endregion IInputStream public interface
#region IOutputStream public interface
public IAsyncOperationWithProgress<UInt32, UInt32> WriteAsync(IBuffer buffer)
{
if (buffer == null)
{
// Mapped to E_POINTER.
throw new ArgumentNullException(nameof(buffer));
}
if (buffer.Capacity < buffer.Length)
{
ArgumentException ex = new ArgumentException(SR.Argument_BufferLengthExceedsCapacity);
ex.SetErrorCode(HResults.E_INVALIDARG);
throw ex;
}
// Commented due to a reported CCRewrite bug. Should uncomment when fixed:
//Contract.Ensures(Contract.Result<IAsyncOperationWithProgress<UInt32, UInt32>>() != null);
//Contract.EndContractBlock();
Stream str = EnsureNotDisposed();
return StreamOperationsImplementation.WriteAsync_AbstractStream(str, buffer);
}
public IAsyncOperation<Boolean> FlushAsync()
{
Contract.Ensures(Contract.Result<IAsyncOperation<Boolean>>() != null);
Contract.EndContractBlock();
Stream str = EnsureNotDisposed();
return StreamOperationsImplementation.FlushAsync_AbstractStream(str);
}
#endregion IOutputStream public interface
#region IRandomAccessStream public interface
#region IRandomAccessStream public interface: Not cloning related
public void Seek(UInt64 position)
{
if (position > Int64.MaxValue)
{
ArgumentException ex = new ArgumentException(SR.IO_CannotSeekBeyondInt64MaxValue);
ex.SetErrorCode(HResults.E_INVALIDARG);
throw ex;
}
// Commented due to a reported CCRewrite bug. Should uncomment when fixed:
//Contract.EndContractBlock();
Stream str = EnsureNotDisposed();
Int64 pos = unchecked((Int64)position);
Debug.Assert(str != null);
Debug.Assert(str.CanSeek, "The underlying str is expected to support Seek, but it does not.");
Debug.Assert(0 <= pos, "Unexpected pos=" + pos + ".");
str.Seek(pos, SeekOrigin.Begin);
}
public bool CanRead
{
get
{
Stream str = EnsureNotDisposed();
return str.CanRead;
}
}
public bool CanWrite
{
get
{
Stream str = EnsureNotDisposed();
return str.CanWrite;
}
}
public UInt64 Position
{
get
{
Contract.Ensures(Contract.Result<UInt64>() >= 0);
Stream str = EnsureNotDisposed();
return (UInt64)str.Position;
}
}
public UInt64 Size
{
get
{
Contract.Ensures(Contract.Result<UInt64>() >= 0);
Stream str = EnsureNotDisposed();
return (UInt64)str.Length;
}
set
{
if (value > Int64.MaxValue)
{
ArgumentException ex = new ArgumentException(SR.IO_CannotSetSizeBeyondInt64MaxValue);
ex.SetErrorCode(HResults.E_INVALIDARG);
throw ex;
}
// Commented due to a reported CCRewrite bug. Should uncomment when fixed:
//Contract.EndContractBlock();
Stream str = EnsureNotDisposed();
if (!str.CanWrite)
{
InvalidOperationException ex = new InvalidOperationException(SR.InvalidOperation_CannotSetStreamSizeCannotWrite);
ex.SetErrorCode(HResults.E_ILLEGAL_METHOD_CALL);
throw ex;
}
Int64 val = unchecked((Int64)value);
Debug.Assert(str != null);
Debug.Assert(str.CanSeek, "The underlying str is expected to support Seek, but it does not.");
Debug.Assert(0 <= val, "Unexpected val=" + val + ".");
str.SetLength(val);
}
}
#endregion IRandomAccessStream public interface: Not cloning related
#region IRandomAccessStream public interface: Cloning related
// We do not want to support the cloning-related operation for now.
// They appear to mainly target corner-case scenarios in Windows itself,
// and are (mainly) a historical artefact of abandoned early designs
// for IRandonAccessStream.
// Cloning can be added in future, however, it would be quite complex
// to support it correctly for generic streams.
private static void ThrowCloningNotSupported(String methodName)
{
NotSupportedException nse = new NotSupportedException(SR.Format(SR.NotSupported_CloningNotSupported, methodName));
nse.SetErrorCode(HResults.E_NOTIMPL);
throw nse;
}
public IRandomAccessStream CloneStream()
{
ThrowCloningNotSupported("CloneStream");
return null;
}
public IInputStream GetInputStreamAt(UInt64 position)
{
ThrowCloningNotSupported("GetInputStreamAt");
return null;
}
public IOutputStream GetOutputStreamAt(UInt64 position)
{
ThrowCloningNotSupported("GetOutputStreamAt");
return null;
}
#endregion IRandomAccessStream public interface: Cloning related
#endregion IRandomAccessStream public interface
} // class NetFxToWinRtStreamAdapter
} // namespace
// NetFxToWinRtStreamAdapter.cs

View File

@@ -0,0 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Runtime.InteropServices.WindowsRuntime;
namespace System.IO
{
internal partial class StreamOperationAsyncResult
{
private void ThrowWithIOExceptionDispatchInfo(Exception e)
{
WinRtIOHelper.NativeExceptionToIOExceptionInfo(RestrictedErrorInfoHelper.AttachRestrictedErrorInfo(_completedOperation.ErrorCode)).Throw();
}
}
}

View File

@@ -0,0 +1,17 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Internal.Interop;
using System.Runtime.InteropServices.WindowsRuntime;
namespace System.IO
{
internal partial class StreamOperationAsyncResult
{
private void ThrowWithIOExceptionDispatchInfo(Exception e)
{
WinRtIOHelper.NativeExceptionToIOExceptionInfo(_completedOperation.ErrorCode.AttachRestrictedErrorInfo()).Throw();
}
}
}

View File

@@ -0,0 +1,390 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Diagnostics;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Threading;
using Windows.Foundation;
using Windows.Storage.Streams;
namespace System.IO
{
#region class StreamOperationAsyncResult
internal abstract partial class StreamOperationAsyncResult : IAsyncResult
{
private AsyncCallback _userCompletionCallback = null;
private Object _userAsyncStateInfo = null;
private IAsyncInfo _asyncStreamOperation = null;
private volatile bool _completed = false;
private volatile bool _callbackInvoked = false;
private volatile ManualResetEvent _waitHandle = null;
private Int64 _bytesCompleted = 0;
private ExceptionDispatchInfo _errorInfo = null;
private readonly bool _processCompletedOperationInCallback;
private IAsyncInfo _completedOperation = null;
protected internal StreamOperationAsyncResult(IAsyncInfo asyncStreamOperation,
AsyncCallback userCompletionCallback, Object userAsyncStateInfo,
bool processCompletedOperationInCallback)
{
if (asyncStreamOperation == null)
throw new ArgumentNullException("asyncReadOperation");
_userCompletionCallback = userCompletionCallback;
_userAsyncStateInfo = userAsyncStateInfo;
_asyncStreamOperation = asyncStreamOperation;
_completed = false;
_callbackInvoked = false;
_bytesCompleted = 0;
_errorInfo = null;
_processCompletedOperationInCallback = processCompletedOperationInCallback;
}
public object AsyncState
{
get { return _userAsyncStateInfo; }
}
internal bool ProcessCompletedOperationInCallback
{
get { return _processCompletedOperationInCallback; }
}
#pragma warning disable 420 // "a reference to a volatile field will not be treated as volatile"
public WaitHandle AsyncWaitHandle
{
get
{
ManualResetEvent wh = _waitHandle;
if (wh != null)
return wh;
// What if someone calls this public property and decides to wait on it?
// > Use 'completed' in the ctor - this way the handle wait will return as appropriate.
wh = new ManualResetEvent(_completed);
ManualResetEvent otherHandle = Interlocked.CompareExchange(ref _waitHandle, wh, null);
// We lost the race. Dispose OUR handle and return OTHER handle:
if (otherHandle != null)
{
wh.Dispose();
return otherHandle;
}
// We won the race. Return OUR new handle:
return wh;
}
}
#pragma warning restore 420 // "a reference to a volatile field will not be treated as volatile"
public bool CompletedSynchronously
{
get { return false; }
}
public bool IsCompleted
{
get { return _completed; }
}
internal void Wait()
{
if (_completed)
return;
WaitHandle wh = AsyncWaitHandle;
while (_completed == false)
wh.WaitOne();
}
internal Int64 BytesCompleted
{
get { return _bytesCompleted; }
}
internal bool HasError
{
get { return _errorInfo != null; }
}
internal void ThrowCachedError()
{
if (_errorInfo == null)
return;
_errorInfo.Throw();
}
internal bool CancelStreamOperation()
{
if (_callbackInvoked)
return false;
if (_asyncStreamOperation != null)
{
_asyncStreamOperation.Cancel();
_asyncStreamOperation = null;
}
return true;
}
internal void CloseStreamOperation()
{
try
{
if (_asyncStreamOperation != null)
_asyncStreamOperation.Close();
}
catch { }
_asyncStreamOperation = null;
}
~StreamOperationAsyncResult()
{
// This finalisation is not critical, but we can still make an effort to notify the underlying WinRT stream
// that we are not any longer interested in the results:
CancelStreamOperation();
}
internal abstract void ProcessConcreteCompletedOperation(IAsyncInfo completedOperation, out Int64 bytesCompleted);
private static void ProcessCompletedOperation_InvalidOperationThrowHelper(ExceptionDispatchInfo errInfo, String errMsg)
{
Exception errInfoSrc = (errInfo == null) ? null : errInfo.SourceException;
if (errInfoSrc == null)
throw new InvalidOperationException(errMsg);
else
throw new InvalidOperationException(errMsg, errInfoSrc);
}
internal void ProcessCompletedOperation()
{
// The error handling is slightly tricky here:
// Before processing the IO results, we are verifying some basic assumptions and if they do not hold, we are
// throwing InvalidOperation. However, by the time this method is called, we might have already stored something
// into errorInfo, e.g. if an error occurred in StreamOperationCompletedCallback. If that is the case, then that
// previous exception might include some important info relevant for detecting the problem. So, we take that
// previous exception and attach it as the inner exception to the InvalidOperationException being thrown.
// In cases where we have a good understanding of the previously saved errorInfo, and we know for sure that it
// the immediate reason for the state validation to fail, we can avoid throwing InvalidOperation altogether
// and only rethrow the errorInfo.
if (!_callbackInvoked)
ProcessCompletedOperation_InvalidOperationThrowHelper(_errorInfo, SR.InvalidOperation_CannotCallThisMethodInCurrentState);
if (!_processCompletedOperationInCallback && !_completed)
ProcessCompletedOperation_InvalidOperationThrowHelper(_errorInfo, SR.InvalidOperation_CannotCallThisMethodInCurrentState);
if (_completedOperation == null)
{
ExceptionDispatchInfo errInfo = _errorInfo;
Exception errInfoSrc = (errInfo == null) ? null : errInfo.SourceException;
// See if errorInfo is set because we observed completedOperation == null previously (being slow is Ok on error path):
if (errInfoSrc != null && errInfoSrc is NullReferenceException
&& SR.NullReference_IOCompletionCallbackCannotProcessNullAsyncInfo.Equals(errInfoSrc.Message))
{
errInfo.Throw();
}
else
{
throw new InvalidOperationException(SR.InvalidOperation_CannotCallThisMethodInCurrentState);
}
}
if (_completedOperation.Id != _asyncStreamOperation.Id)
ProcessCompletedOperation_InvalidOperationThrowHelper(_errorInfo, SR.InvalidOperation_UnexpectedAsyncOperationID);
if (_completedOperation.Status == AsyncStatus.Error)
{
_bytesCompleted = 0;
ThrowWithIOExceptionDispatchInfo(_completedOperation.ErrorCode);
}
ProcessConcreteCompletedOperation(_completedOperation, out _bytesCompleted);
}
internal void StreamOperationCompletedCallback(IAsyncInfo completedOperation, AsyncStatus unusedCompletionStatus)
{
try
{
if (_callbackInvoked)
throw new InvalidOperationException(SR.InvalidOperation_MultipleIOCompletionCallbackInvocation);
_callbackInvoked = true;
// This happens in rare stress cases in Console mode and the WinRT folks said they are unlikely to fix this in Dev11.
// Moreover, this can happen if the underlying WinRT stream has a faulty user implementation.
// If we did not do this check, we would either get the same exception without the explaining message when dereferencing
// completedOperation later, or we will get an InvalidOperation when processing the Op. With the check, they will be
// aggregated and the user will know what went wrong.
if (completedOperation == null)
throw new NullReferenceException(SR.NullReference_IOCompletionCallbackCannotProcessNullAsyncInfo);
_completedOperation = completedOperation;
// processCompletedOperationInCallback == false indicates that the stream is doing a blocking wait on the waitHandle of this IAsyncResult.
// In that case calls on completedOperation may deadlock if completedOperation is not free threaded.
// By setting processCompletedOperationInCallback to false the stream that created this IAsyncResult indicated that it
// will call ProcessCompletedOperation after the waitHandle is signalled to fetch the results.
if (_processCompletedOperationInCallback)
ProcessCompletedOperation();
}
catch (Exception ex)
{
_bytesCompleted = 0;
_errorInfo = ExceptionDispatchInfo.Capture(ex);
}
finally
{
_completed = true;
Interlocked.MemoryBarrier();
// From this point on, AsyncWaitHandle would create a handle that is readily set,
// so we do not need to check if it is being produced asynchronously.
if (_waitHandle != null)
_waitHandle.Set();
}
if (_userCompletionCallback != null)
_userCompletionCallback(this);
}
} // class StreamOperationAsyncResult
#endregion class StreamOperationAsyncResult
#region class StreamReadAsyncResult
internal class StreamReadAsyncResult : StreamOperationAsyncResult
{
private IBuffer _userBuffer = null;
internal StreamReadAsyncResult(IAsyncOperationWithProgress<IBuffer, UInt32> asyncStreamReadOperation, IBuffer buffer,
AsyncCallback userCompletionCallback, Object userAsyncStateInfo,
bool processCompletedOperationInCallback)
: base(asyncStreamReadOperation, userCompletionCallback, userAsyncStateInfo, processCompletedOperationInCallback)
{
if (buffer == null)
throw new ArgumentNullException(nameof(buffer));
_userBuffer = buffer;
asyncStreamReadOperation.Completed = this.StreamOperationCompletedCallback;
}
internal override void ProcessConcreteCompletedOperation(IAsyncInfo completedOperation, out Int64 bytesCompleted)
{
ProcessConcreteCompletedOperation((IAsyncOperationWithProgress<IBuffer, UInt32>)completedOperation, out bytesCompleted);
}
private void ProcessConcreteCompletedOperation(IAsyncOperationWithProgress<IBuffer, UInt32> completedOperation, out Int64 bytesCompleted)
{
IBuffer resultBuffer = completedOperation.GetResults();
Debug.Assert(resultBuffer != null);
WinRtIOHelper.EnsureResultsInUserBuffer(_userBuffer, resultBuffer);
bytesCompleted = _userBuffer.Length;
}
} // class StreamReadAsyncResult
#endregion class StreamReadAsyncResult
#region class StreamWriteAsyncResult
internal class StreamWriteAsyncResult : StreamOperationAsyncResult
{
internal StreamWriteAsyncResult(IAsyncOperationWithProgress<UInt32, UInt32> asyncStreamWriteOperation,
AsyncCallback userCompletionCallback, Object userAsyncStateInfo,
bool processCompletedOperationInCallback)
: base(asyncStreamWriteOperation, userCompletionCallback, userAsyncStateInfo, processCompletedOperationInCallback)
{
asyncStreamWriteOperation.Completed = this.StreamOperationCompletedCallback;
}
internal override void ProcessConcreteCompletedOperation(IAsyncInfo completedOperation, out Int64 bytesCompleted)
{
ProcessConcreteCompletedOperation((IAsyncOperationWithProgress<UInt32, UInt32>)completedOperation, out bytesCompleted);
}
private void ProcessConcreteCompletedOperation(IAsyncOperationWithProgress<UInt32, UInt32> completedOperation, out Int64 bytesCompleted)
{
UInt32 bytesWritten = completedOperation.GetResults();
bytesCompleted = bytesWritten;
}
} // class StreamWriteAsyncResult
#endregion class StreamWriteAsyncResult
#region class StreamFlushAsyncResult
internal class StreamFlushAsyncResult : StreamOperationAsyncResult
{
internal StreamFlushAsyncResult(IAsyncOperation<Boolean> asyncStreamFlushOperation, bool processCompletedOperationInCallback)
: base(asyncStreamFlushOperation, null, null, processCompletedOperationInCallback)
{
asyncStreamFlushOperation.Completed = this.StreamOperationCompletedCallback;
}
internal override void ProcessConcreteCompletedOperation(IAsyncInfo completedOperation, out Int64 bytesCompleted)
{
ProcessConcreteCompletedOperation((IAsyncOperation<Boolean>)completedOperation, out bytesCompleted);
}
private void ProcessConcreteCompletedOperation(IAsyncOperation<Boolean> completedOperation, out Int64 bytesCompleted)
{
Boolean success = completedOperation.GetResults();
bytesCompleted = (success ? 0 : -1);
}
} // class StreamFlushAsyncResult
#endregion class StreamFlushAsyncResult
} // namespace
// StreamOperationAsyncResult.cs

View File

@@ -0,0 +1,255 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
extern alias System_Runtime_Extensions;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Threading;
using Windows.Foundation;
using Windows.Storage.Streams;
// Type aliases cannot match existing typenames. In this file our code is in System.IO, which would
// create two MemoryStream definitions that are in scope if we defined as MemoryStream.
using SREMemoryStream = System_Runtime_Extensions::System.IO.MemoryStream;
namespace System.IO
{
/// <summary>Depending on the concrete type of the stream managed by a <c>NetFxToWinRtStreamAdapter</c>,
/// we want the <c>ReadAsync</c> / <c>WriteAsync</c> / <c>FlushAsync</c> / etc. operation to be implemented
/// differently. This is for best performance as we can take advantage of the specifics of particular stream
/// types. For instance, <c>ReadAsync</c> currently has a special implementation for memory streams.
/// Moreover, knowledge about the actual runtime type of the <c>IBuffer</c> can also help chosing the optimal
/// implementation. This type provides static methods that encapsulate the performance logic and can be used
/// by <c>NetFxToWinRtStreamAdapter</c>.</summary>
internal static class StreamOperationsImplementation
{
#region ReadAsync implementations
internal static IAsyncOperationWithProgress<IBuffer, UInt32> ReadAsync_MemoryStream(Stream stream, IBuffer buffer, UInt32 count)
{
Debug.Assert(stream != null);
Debug.Assert(stream is SREMemoryStream);
Debug.Assert(stream.CanRead);
Debug.Assert(stream.CanSeek);
Debug.Assert(buffer != null);
Debug.Assert(buffer is IBufferByteAccess);
Debug.Assert(0 <= count);
Debug.Assert(count <= Int32.MaxValue);
Debug.Assert(count <= buffer.Capacity);
Contract.EndContractBlock();
// We will return a different buffer to the user backed directly by the memory stream (avoids memory copy).
// This is permitted by the WinRT stream contract.
// The user specified buffer will not have any data put into it:
buffer.Length = 0;
SREMemoryStream memStream = stream as SREMemoryStream;
Debug.Assert(memStream != null);
try
{
IBuffer dataBuffer = memStream.GetWindowsRuntimeBuffer((Int32)memStream.Position, (Int32)count);
if (dataBuffer.Length > 0)
memStream.Seek(dataBuffer.Length, SeekOrigin.Current);
return AsyncInfo.CreateCompletedOperation<IBuffer, UInt32>(dataBuffer);
}
catch (Exception ex)
{
return AsyncInfo.CreateFaultedOperation<IBuffer, UInt32>(ex);
}
} // ReadAsync_MemoryStream
internal static IAsyncOperationWithProgress<IBuffer, UInt32> ReadAsync_AbstractStream(Stream stream, IBuffer buffer, UInt32 count,
InputStreamOptions options)
{
Debug.Assert(stream != null);
Debug.Assert(stream.CanRead);
Debug.Assert(buffer != null);
Debug.Assert(buffer is IBufferByteAccess);
Debug.Assert(0 <= count);
Debug.Assert(count <= Int32.MaxValue);
Debug.Assert(count <= buffer.Capacity);
Debug.Assert(options == InputStreamOptions.None || options == InputStreamOptions.Partial || options == InputStreamOptions.ReadAhead);
Contract.EndContractBlock();
Int32 bytesRequested = (Int32)count;
// Check if the buffer is our implementation.
// IF YES: In that case, we can read directly into its data array.
// IF NO: The buffer is of unknown implementation. It's not backed by a managed array, but the wrapped stream can only
// read into a managed array. If we used the user-supplied buffer we would need to copy data into it after every read.
// The spec allows to return a buffer instance that is not the same as passed by the user. So, we will create an own
// buffer instance, read data *directly* into the array backing it and then return it to the user.
// Note: the allocation costs we are paying for the new buffer are unavoidable anyway, as we we would need to create
// an array to read into either way.
IBuffer dataBuffer = buffer as WindowsRuntimeBuffer;
if (dataBuffer == null)
dataBuffer = WindowsRuntimeBuffer.Create((Int32)Math.Min((UInt32)Int32.MaxValue, buffer.Capacity));
// This operation delegate will we run inside of the returned IAsyncOperationWithProgress:
Func<CancellationToken, IProgress<UInt32>, Task<IBuffer>> readOperation = async (cancelToken, progressListener) =>
{
// No bytes read yet:
dataBuffer.Length = 0;
// Get the buffer backing array:
Byte[] data;
Int32 offset;
bool managedBufferAssert = dataBuffer.TryGetUnderlyingData(out data, out offset);
Debug.Assert(managedBufferAssert);
// Init tracking values:
bool done = cancelToken.IsCancellationRequested;
Int32 bytesCompleted = 0;
// Loop until EOS, cancelled or read enough data according to options:
while (!done)
{
Int32 bytesRead = 0;
try
{
// Read asynchronously:
bytesRead = await stream.ReadAsync(data, offset + bytesCompleted, bytesRequested - bytesCompleted, cancelToken)
.ConfigureAwait(continueOnCapturedContext: false);
// We will continue here on a different thread when read async completed:
bytesCompleted += bytesRead;
// We will handle a cancelation exception and re-throw all others:
}
catch (OperationCanceledException)
{
// We assume that cancelToken.IsCancellationRequested is has been set and simply proceed.
// (we check cancelToken.IsCancellationRequested later)
Debug.Assert(cancelToken.IsCancellationRequested);
// This is because if the cancellation came after we read some bytes we want to return the results we got instead
// of an empty cancelled task, so if we have not yet read anything at all, then we can throw cancellation:
if (bytesCompleted == 0 && bytesRead == 0)
throw;
}
// Update target buffer:
dataBuffer.Length = (UInt32)bytesCompleted;
Debug.Assert(bytesCompleted <= bytesRequested);
// Check if we are done:
done = options == InputStreamOptions.Partial // If no complete read was requested, any amount of data is OK
|| bytesRead == 0 // this implies EndOfStream
|| bytesCompleted == bytesRequested // read all requested bytes
|| cancelToken.IsCancellationRequested; // operation was cancelled
// Call user Progress handler:
if (progressListener != null)
progressListener.Report(dataBuffer.Length);
} // while (!done)
// If we got here, then no error was detected. Return the results buffer:
return dataBuffer;
}; // readOperation
return AsyncInfo.Run<IBuffer, UInt32>(readOperation);
} // ReadAsync_AbstractStream
#endregion ReadAsync implementations
#region WriteAsync implementations
internal static IAsyncOperationWithProgress<UInt32, UInt32> WriteAsync_AbstractStream(Stream stream, IBuffer buffer)
{
Debug.Assert(stream != null);
Debug.Assert(stream.CanWrite);
Debug.Assert(buffer != null);
Contract.EndContractBlock();
// Choose the optimal writing strategy for the kind of buffer supplied:
Func<CancellationToken, IProgress<UInt32>, Task<UInt32>> writeOperation;
Byte[] data;
Int32 offset;
// If buffer is backed by a managed array:
if (buffer.TryGetUnderlyingData(out data, out offset))
{
writeOperation = async (cancelToken, progressListener) =>
{
if (cancelToken.IsCancellationRequested) // CancellationToken is non-nullable
return 0;
Debug.Assert(buffer.Length <= Int32.MaxValue);
Int32 bytesToWrite = (Int32)buffer.Length;
await stream.WriteAsync(data, offset, bytesToWrite, cancelToken).ConfigureAwait(continueOnCapturedContext: false);
if (progressListener != null)
progressListener.Report((UInt32)bytesToWrite);
return (UInt32)bytesToWrite;
};
// Otherwise buffer is of an unknown implementation:
}
else
{
writeOperation = async (cancelToken, progressListener) =>
{
if (cancelToken.IsCancellationRequested) // CancellationToken is non-nullable
return 0;
UInt32 bytesToWrite = buffer.Length;
Stream dataStream = buffer.AsStream();
Int32 buffSize = 0x4000;
if (bytesToWrite < buffSize)
buffSize = (Int32)bytesToWrite;
await dataStream.CopyToAsync(stream, buffSize, cancelToken).ConfigureAwait(continueOnCapturedContext: false);
if (progressListener != null)
progressListener.Report((UInt32)bytesToWrite);
return (UInt32)bytesToWrite;
};
} // if-else
// Construct and run the async operation:
return AsyncInfo.Run<UInt32, UInt32>(writeOperation);
} // WriteAsync_AbstractStream
#endregion WriteAsync implementations
#region FlushAsync implementations
internal static IAsyncOperation<Boolean> FlushAsync_AbstractStream(Stream stream)
{
Debug.Assert(stream != null);
Debug.Assert(stream.CanWrite);
Contract.EndContractBlock();
Func<CancellationToken, Task<Boolean>> flushOperation = async (cancelToken) =>
{
if (cancelToken.IsCancellationRequested) // CancellationToken is non-nullable
return false;
await stream.FlushAsync(cancelToken).ConfigureAwait(continueOnCapturedContext: false);
return true;
};
// Construct and run the async operation:
return AsyncInfo.Run<Boolean>(flushOperation);
}
#endregion FlushAsync implementations
} // class StreamOperationsImplementation
} // namespace

View File

@@ -0,0 +1,450 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.WindowsRuntime.Internal;
using System.Runtime;
using System.Security;
using System.Threading;
namespace System.IO
{
[Flags]
internal enum FileAccess
{
// Specifies read access to the file. Data can be read from the file and
// the file pointer can be moved. Combine with WRITE for read-write access.
Read = 1,
// Specifies write access to the file. Data can be written to the file and
// the file pointer can be moved. Combine with READ for read-write access.
Write = 2,
// Specifies read and write access to the file. Data can be written to the
// file and the file pointer can be moved. Data can also be read from the
// file.
ReadWrite = 3,
}
/*
* This class is used to access a contiguous block of memory, likely outside
* the GC heap (or pinned in place in the GC heap, but a MemoryStream may
* make more sense in those cases). It's great if you have a pointer and
* a length for a section of memory mapped in by someone else and you don't
* want to copy this into the GC heap. UnmanagedMemoryStream assumes these
* two things:
*
* 1) All the memory in the specified block is readable or writable,
* depending on the values you pass to the constructor.
* 2) The lifetime of the block of memory is at least as long as the lifetime
* of the UnmanagedMemoryStream.
* 3) You clean up the memory when appropriate. The UnmanagedMemoryStream
* currently will do NOTHING to free this memory.
* 4) All calls to Write and WriteByte may not be threadsafe currently.
*
* It may become necessary to add in some sort of
* DeallocationMode enum, specifying whether we unmap a section of memory,
* call free, run a user-provided delegate to free the memory, etc etc.
* We'll suggest user write a subclass of UnmanagedMemoryStream that uses
* a SafeHandle subclass to hold onto the memory.
* Check for problems when using this in the negative parts of a
* process's address space. We may need to use unsigned longs internally
* and change the overflow detection logic.
*/
internal class UnmanagedMemoryStream : Stream
{
private unsafe byte* _mem;
private long _length;
private long _capacity;
private long _position;
private FileAccess _access;
internal bool _isOpen;
// Needed for subclasses that need to map a file, etc.
protected UnmanagedMemoryStream()
{
unsafe
{
_mem = null;
}
_isOpen = false;
}
public unsafe UnmanagedMemoryStream(byte* pointer, long length)
{
Initialize(pointer, length, length, FileAccess.Read, false);
}
public unsafe UnmanagedMemoryStream(byte* pointer, long length, long capacity, FileAccess access)
{
Initialize(pointer, length, capacity, access, false);
}
// We must create one of these without doing a security check. This
// class is created while security is trying to start up. Plus, doing
// a Demand from Assembly.GetManifestResourceStream isn't useful.
internal unsafe UnmanagedMemoryStream(byte* pointer, long length, long capacity, FileAccess access, bool skipSecurityCheck)
{
Initialize(pointer, length, capacity, access, skipSecurityCheck);
}
protected unsafe void Initialize(byte* pointer, long length, long capacity, FileAccess access)
{
Initialize(pointer, length, capacity, access, false);
}
internal unsafe void Initialize(byte* pointer, long length, long capacity, FileAccess access, bool skipSecurityCheck)
{
if (pointer == null)
throw new ArgumentNullException(nameof(pointer));
if (length < 0 || capacity < 0)
throw new ArgumentOutOfRangeException((length < 0) ? nameof(length): nameof(capacity), SR.ArgumentOutOfRange_NeedNonNegNum);
if (length > capacity)
throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_LengthGreaterThanCapacity);
Contract.EndContractBlock();
// Check for wraparound.
if (((byte*)((long)pointer + capacity)) < pointer)
throw new ArgumentOutOfRangeException(nameof(capacity), SR.ArgumentOutOfRange_UnmanagedMemStreamWrapAround);
if (access < FileAccess.Read || access > FileAccess.ReadWrite)
throw new ArgumentOutOfRangeException(nameof(access), SR.ArgumentOutOfRange_Enum);
if (_isOpen)
throw new InvalidOperationException(SR.InvalidOperation_CalledTwice);
_mem = pointer;
_length = length;
_capacity = capacity;
_access = access;
_isOpen = true;
}
public override bool CanRead
{
[Pure]
get
{ return _isOpen && (_access & FileAccess.Read) != 0; }
}
public override bool CanSeek
{
[Pure]
get
{ return _isOpen; }
}
public override bool CanWrite
{
[Pure]
get
{ return _isOpen && (_access & FileAccess.Write) != 0; }
}
[System.Security.SecuritySafeCritical] // auto-generated
protected override void Dispose(bool disposing)
{
_isOpen = false;
unsafe { _mem = null; }
// Stream allocates WaitHandles for async calls. So for correctness
// call base.Dispose(disposing) for better perf, avoiding waiting
// for the finalizers to run on those types.
base.Dispose(disposing);
}
public override void Flush()
{
if (!_isOpen) throw new ObjectDisposedException(null, SR.ObjectDisposed_StreamClosed);
}
public override long Length
{
get
{
if (!_isOpen) throw new ObjectDisposedException(null, SR.ObjectDisposed_StreamClosed);
return Interlocked.Read(ref _length);
}
}
public long Capacity
{
get
{
if (!_isOpen) throw new ObjectDisposedException(null, SR.ObjectDisposed_StreamClosed);
return _capacity;
}
}
public override long Position
{
get
{
if (!CanSeek) throw new ObjectDisposedException(null, SR.ObjectDisposed_StreamClosed);
Contract.EndContractBlock();
return Interlocked.Read(ref _position);
}
[System.Security.SecuritySafeCritical] // auto-generated
set
{
if (value < 0)
throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_NeedNonNegNum);
Contract.EndContractBlock();
if (!CanSeek) throw new ObjectDisposedException(null, SR.ObjectDisposed_StreamClosed);
#if WIN32
unsafe
{
// On 32 bit machines, ensure we don't wrap around.
if (value > (long)Int32.MaxValue || _mem + value < _mem)
throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_StreamLength);
}
#endif
Interlocked.Exchange(ref _position, value);
}
}
public unsafe byte* PositionPointer
{
get
{
// Use a temp to avoid a race
long pos = Interlocked.Read(ref _position);
if (pos > _capacity)
throw new IndexOutOfRangeException(SR.IndexOutOfRange_UMSPosition);
byte* ptr = _mem + pos;
if (!_isOpen) throw new ObjectDisposedException(null, SR.ObjectDisposed_StreamClosed);
return ptr;
}
set
{
if (!_isOpen) throw new ObjectDisposedException(null, SR.ObjectDisposed_StreamClosed);
if (value < _mem)
throw new IOException(SR.IO_SeekBeforeBegin);
Interlocked.Exchange(ref _position, value - _mem);
}
}
internal unsafe byte* Pointer
{
get
{
return _mem;
}
}
[System.Security.SecuritySafeCritical] // auto-generated
public override int Read([In, Out] byte[] buffer, int offset, int count)
{
if (buffer == null)
throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
if (offset < 0)
throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum);
if (count < 0)
throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
if (buffer.Length - offset < count)
throw new ArgumentException(SR.Argument_InvalidOffLen);
Contract.EndContractBlock();
if (!_isOpen) throw new ObjectDisposedException(null, SR.ObjectDisposed_StreamClosed);
if (!CanRead) throw new NotSupportedException(SR.NotSupported_UnreadableStream);
// Use a local variable to avoid a race where another thread
// changes our position after we decide we can read some bytes.
long pos = Interlocked.Read(ref _position);
long len = Interlocked.Read(ref _length);
long n = len - pos;
if (n > count)
n = count;
if (n <= 0)
return 0;
int nInt = (int)n; // Safe because n <= count, which is an Int32
Debug.Assert(pos + nInt >= 0, "_position + n >= 0"); // len is less than 2^63 -1.
unsafe
{
Marshal.Copy((IntPtr)(_mem + pos), buffer, offset, nInt);
}
Interlocked.Exchange(ref _position, pos + n);
return nInt;
}
[System.Security.SecuritySafeCritical] // auto-generated
public override int ReadByte()
{
if (!_isOpen) throw new ObjectDisposedException(null, SR.ObjectDisposed_StreamClosed);
if (!CanRead) throw new NotSupportedException(SR.NotSupported_UnreadableStream);
long pos = Interlocked.Read(ref _position); // Use a local to avoid a race condition
long len = Interlocked.Read(ref _length);
if (pos >= len)
return -1;
Interlocked.Exchange(ref _position, pos + 1);
int result;
unsafe
{
result = _mem[pos];
}
return result;
}
public override long Seek(long offset, SeekOrigin loc)
{
if (!_isOpen) throw new ObjectDisposedException(null, SR.ObjectDisposed_StreamClosed);
switch (loc)
{
case SeekOrigin.Begin:
if (offset < 0)
throw new IOException(SR.IO_SeekBeforeBegin);
Interlocked.Exchange(ref _position, offset);
break;
case SeekOrigin.Current:
long pos = Interlocked.Read(ref _position);
if (offset + pos < 0)
throw new IOException(SR.IO_SeekBeforeBegin);
Interlocked.Exchange(ref _position, offset + pos);
break;
case SeekOrigin.End:
long len = Interlocked.Read(ref _length);
if (len + offset < 0)
throw new IOException(SR.IO_SeekBeforeBegin);
Interlocked.Exchange(ref _position, len + offset);
break;
default:
throw new ArgumentException(SR.Argument_InvalidSeekOrigin);
}
long finalPos = Interlocked.Read(ref _position);
Debug.Assert(finalPos >= 0, "_position >= 0");
return finalPos;
}
[System.Security.SecuritySafeCritical] // auto-generated
public override void SetLength(long value)
{
if (value < 0)
throw new ArgumentOutOfRangeException("length", SR.ArgumentOutOfRange_NeedNonNegNum);
Contract.EndContractBlock();
if (!_isOpen) throw new ObjectDisposedException(null, SR.ObjectDisposed_StreamClosed);
if (!CanWrite) throw new NotSupportedException(SR.NotSupported_UnwritableStream);
if (value > _capacity)
throw new IOException(SR.IO_FixedCapacity);
long pos = Interlocked.Read(ref _position);
long len = Interlocked.Read(ref _length);
if (value > len)
{
unsafe
{
Helpers.ZeroMemory(_mem + len, value - len);
}
}
Interlocked.Exchange(ref _length, value);
if (pos > value)
{
Interlocked.Exchange(ref _position, value);
}
}
[System.Security.SecuritySafeCritical] // auto-generated
public override void Write(byte[] buffer, int offset, int count)
{
if (buffer == null)
throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
if (offset < 0)
throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum);
if (count < 0)
throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
if (buffer.Length - offset < count)
throw new ArgumentException(SR.Argument_InvalidOffLen);
Contract.EndContractBlock();
if (!_isOpen) throw new ObjectDisposedException(null, SR.ObjectDisposed_StreamClosed);
if (!CanWrite) throw new NotSupportedException(SR.NotSupported_UnwritableStream);
long pos = Interlocked.Read(ref _position); // Use a local to avoid a race condition
long len = Interlocked.Read(ref _length);
long n = pos + count;
// Check for overflow
if (n < 0)
throw new IOException(SR.IO_StreamTooLong);
if (n > _capacity)
{
throw new NotSupportedException(SR.IO_FixedCapacity);
}
// Check to see whether we are now expanding the stream and must
// zero any memory in the middle.
if (pos > len)
{
unsafe
{
Helpers.ZeroMemory(_mem + len, pos - len);
}
}
// set length after zeroing memory to avoid race condition of accessing unzeroed memory
if (n > len)
{
Interlocked.Exchange(ref _length, n);
}
unsafe
{
Marshal.Copy(buffer, offset, (IntPtr)(_mem + pos), count);
}
Interlocked.Exchange(ref _position, n);
return;
}
[System.Security.SecuritySafeCritical] // auto-generated
public override void WriteByte(byte value)
{
if (!_isOpen) throw new ObjectDisposedException(null, SR.ObjectDisposed_StreamClosed);
if (!CanWrite) throw new NotSupportedException(SR.NotSupported_UnwritableStream);
long pos = Interlocked.Read(ref _position); // Use a local to avoid a race condition
long len = Interlocked.Read(ref _length);
long n = pos + 1;
if (pos >= len)
{
// Check for overflow
if (n < 0)
throw new IOException(SR.IO_StreamTooLong);
if (n > _capacity)
throw new NotSupportedException(SR.IO_FixedCapacity);
// Check to see whether we are now expanding the stream and must
// zero any memory in the middle.
if (pos > len)
{
unsafe
{
Helpers.ZeroMemory(_mem + len, pos - len);
}
}
// set length after zeroing memory to avoid race condition of accessing unzeroed memory
Interlocked.Exchange(ref _length, n);
}
unsafe
{
_mem[pos] = value;
}
Interlocked.Exchange(ref _position, n);
}
}
}

View File

@@ -0,0 +1,56 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Diagnostics;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Runtime.InteropServices;
using Windows.Storage.Streams;
namespace System.IO
{
internal static class WinRtIOHelper
{
internal const Int32 DefaultIOBufferSize = 0x3000; // = 12 KBytes = 12288 Bytes
internal static ExceptionDispatchInfo NativeExceptionToIOExceptionInfo(Exception nativeException)
{
// If the interop layer gave us a specific exception type, we assume it knew what it was doing.
// If it gave us an ExternalException or a generic Exception, we assume that it hit a
// general/unknown case and wrap it into an IOException as this is what Stream users expect.
// We will return a captured ExceptionDispatchInfo such that we can invoke .Throw() close to where
// nativeException was caught - this will result in the most readable call stack.
Debug.Assert(nativeException != null);
if (!(nativeException.GetType().Equals(typeof(Exception)) /*|| nativeException is ExternalException */))
return ExceptionDispatchInfo.Capture(nativeException);
// If we do not have a meaningful message, we use a general IO error message:
String message = nativeException.Message;
if (String.IsNullOrWhiteSpace(message))
message = SR.IO_General;
return ExceptionDispatchInfo.Capture(new IOException(message, nativeException));
}
internal static void EnsureResultsInUserBuffer(IBuffer userBuffer, IBuffer resultBuffer)
{
// Results buffer may be different from user specified buffer. If so - copy data to the user.
Debug.Assert(userBuffer != null);
Debug.Assert(resultBuffer != null);
if (resultBuffer.IsSameData(userBuffer))
return;
resultBuffer.CopyTo(userBuffer);
userBuffer.Length = resultBuffer.Length;
}
} // class WinRtIOHelper
} // namespace

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,220 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage.FileProperties;
using Windows.Storage.Streams;
using Windows.Storage;
namespace System.IO
{
/// <summary>
/// Contains extension methods that provide convenience helpers for WinRT IO.
/// </summary>
public static class WindowsRuntimeStorageExtensions
{
#region Extensions on IStorageFile for retreaving a managed Stream
[CLSCompliant(false)]
public static Task<Stream> OpenStreamForReadAsync(this IStorageFile windowsRuntimeFile)
{
if (windowsRuntimeFile == null)
throw new ArgumentNullException(nameof(windowsRuntimeFile));
Contract.Ensures(Contract.Result<Task<Stream>>() != null);
Contract.EndContractBlock();
return OpenStreamForReadAsyncCore(windowsRuntimeFile);
}
private static async Task<Stream> OpenStreamForReadAsyncCore(this IStorageFile windowsRuntimeFile)
{
Debug.Assert(windowsRuntimeFile != null);
Contract.Ensures(Contract.Result<Task<Stream>>() != null);
Contract.EndContractBlock();
try
{
IRandomAccessStream windowsRuntimeStream = await windowsRuntimeFile.OpenAsync(FileAccessMode.Read)
.AsTask().ConfigureAwait(continueOnCapturedContext: false);
Stream managedStream = windowsRuntimeStream.AsStreamForRead();
return managedStream;
}
catch (Exception ex)
{
// From this API, managed dev expect IO exceptions for "something wrong":
WinRtIOHelper.NativeExceptionToIOExceptionInfo(ex).Throw();
return null;
}
}
[CLSCompliant(false)]
public static Task<Stream> OpenStreamForWriteAsync(this IStorageFile windowsRuntimeFile)
{
if (windowsRuntimeFile == null)
throw new ArgumentNullException(nameof(windowsRuntimeFile));
Contract.Ensures(Contract.Result<Task<Stream>>() != null);
Contract.EndContractBlock();
return OpenStreamForWriteAsyncCore(windowsRuntimeFile, 0);
}
private static async Task<Stream> OpenStreamForWriteAsyncCore(this IStorageFile windowsRuntimeFile, Int64 offset)
{
Debug.Assert(windowsRuntimeFile != null);
Debug.Assert(offset >= 0);
Contract.Ensures(Contract.Result<Task<Stream>>() != null);
Contract.EndContractBlock();
try
{
IRandomAccessStream windowsRuntimeStream = await windowsRuntimeFile.OpenAsync(FileAccessMode.ReadWrite)
.AsTask().ConfigureAwait(continueOnCapturedContext: false);
Stream managedStream = windowsRuntimeStream.AsStreamForWrite();
managedStream.Position = offset;
return managedStream;
}
catch (Exception ex)
{
// From this API, managed dev expect IO exceptions for "something wrong":
WinRtIOHelper.NativeExceptionToIOExceptionInfo(ex).Throw();
return null;
}
}
#endregion Extensions on IStorageFile for retreaving a managed Stream
#region Extensions on IStorageFolder for retreaving a managed Stream
[CLSCompliant(false)]
public static Task<Stream> OpenStreamForReadAsync(this IStorageFolder rootDirectory, String relativePath)
{
if (rootDirectory == null)
throw new ArgumentNullException(nameof(rootDirectory));
if (relativePath == null)
throw new ArgumentNullException(nameof(relativePath));
if (String.IsNullOrWhiteSpace(relativePath))
throw new ArgumentException(SR.Argument_RelativePathMayNotBeWhitespaceOnly, nameof(relativePath));
Contract.Ensures(Contract.Result<Task<Stream>>() != null);
Contract.EndContractBlock();
return OpenStreamForReadAsyncCore(rootDirectory, relativePath);
}
private static async Task<Stream> OpenStreamForReadAsyncCore(this IStorageFolder rootDirectory, String relativePath)
{
Debug.Assert(rootDirectory != null);
Debug.Assert(!String.IsNullOrWhiteSpace(relativePath));
Contract.Ensures(Contract.Result<Task<Stream>>() != null);
Contract.EndContractBlock();
try
{
IStorageFile windowsRuntimeFile = await rootDirectory.GetFileAsync(relativePath)
.AsTask().ConfigureAwait(continueOnCapturedContext: false);
Stream managedStream = await windowsRuntimeFile.OpenStreamForReadAsync()
.ConfigureAwait(continueOnCapturedContext: false);
return managedStream;
}
catch (Exception ex)
{
// From this API, managed dev expect IO exceptions for "something wrong":
WinRtIOHelper.NativeExceptionToIOExceptionInfo(ex).Throw();
return null;
}
}
[CLSCompliant(false)]
public static Task<Stream> OpenStreamForWriteAsync(this IStorageFolder rootDirectory, String relativePath,
CreationCollisionOption creationCollisionOption)
{
if (rootDirectory == null)
throw new ArgumentNullException(nameof(rootDirectory));
if (relativePath == null)
throw new ArgumentNullException(nameof(relativePath));
if (String.IsNullOrWhiteSpace(relativePath))
throw new ArgumentException(SR.Argument_RelativePathMayNotBeWhitespaceOnly, nameof(relativePath));
Contract.Ensures(Contract.Result<Task<Stream>>() != null);
Contract.EndContractBlock();
return OpenStreamForWriteAsyncCore(rootDirectory, relativePath, creationCollisionOption);
}
private static async Task<Stream> OpenStreamForWriteAsyncCore(this IStorageFolder rootDirectory, String relativePath,
CreationCollisionOption creationCollisionOption)
{
Debug.Assert(rootDirectory != null);
Debug.Assert(!String.IsNullOrWhiteSpace(relativePath));
Debug.Assert(creationCollisionOption == CreationCollisionOption.FailIfExists
|| creationCollisionOption == CreationCollisionOption.GenerateUniqueName
|| creationCollisionOption == CreationCollisionOption.OpenIfExists
|| creationCollisionOption == CreationCollisionOption.ReplaceExisting,
"The specified creationCollisionOption has a value that is not a value we considered when devising the"
+ " policy about Append-On-OpenIfExists used in this method. Apparently a new enum value was added to the"
+ " CreationCollisionOption type and we need to make sure that the policy still makes sense.");
Contract.Ensures(Contract.Result<Task<Stream>>() != null);
Contract.EndContractBlock();
try
{
// Open file and set up default options for opening it:
IStorageFile windowsRuntimeFile = await rootDirectory.CreateFileAsync(relativePath, creationCollisionOption)
.AsTask().ConfigureAwait(continueOnCapturedContext: false);
Int64 offset = 0;
// If the specified creationCollisionOption was OpenIfExists, then we will try to APPEND, otherwise we will OVERWRITE:
if (creationCollisionOption == CreationCollisionOption.OpenIfExists)
{
BasicProperties fileProperties = await windowsRuntimeFile.GetBasicPropertiesAsync()
.AsTask().ConfigureAwait(continueOnCapturedContext: false);
UInt64 fileSize = fileProperties.Size;
Debug.Assert(fileSize <= Int64.MaxValue, ".NET streams assume that file sizes are not larger than Int64.MaxValue,"
+ " so we are not supporting the situation where this is not the case.");
offset = checked((Int64)fileSize);
}
// Now open a file with the correct options:
Stream managedStream = await OpenStreamForWriteAsyncCore(windowsRuntimeFile, offset).ConfigureAwait(continueOnCapturedContext: false);
return managedStream;
}
catch (Exception ex)
{
// From this API, managed dev expect IO exceptions for "something wrong":
WinRtIOHelper.NativeExceptionToIOExceptionInfo(ex).Throw();
return null;
}
}
#endregion Extensions on IStorageFolder for retreaving a managed Stream
} // class WindowsRuntimeStorageExtensions
} // namespace
// WindowsRuntimeStorageExtensions.cs

Some files were not shown because too many files have changed in this diff Show More