mirror of https://github.com/dahall/Vanara.git
Extended .NET 2, 3, and 4 builds to include Tasks from Theraot library
parent
94b8fe0ffe
commit
eaaaa2f2d4
|
@ -11,10 +11,7 @@ namespace Vanara.InteropServices
|
||||||
/// <seealso cref="System.ICloneable"/>
|
/// <seealso cref="System.ICloneable"/>
|
||||||
/// <seealso cref="System.Collections.IList"/>
|
/// <seealso cref="System.Collections.IList"/>
|
||||||
/// <seealso cref="SafeHGlobalHandle"/>
|
/// <seealso cref="SafeHGlobalHandle"/>
|
||||||
public class SafeByteArray : SafeMemoryHandle<CoTaskMemoryMethods>, IList<byte>, ICloneable, IList
|
public class SafeByteArray : SafeMemoryHandle<CoTaskMemoryMethods>, IList<byte>, ICloneable, IList, IStructuralComparable, IStructuralEquatable
|
||||||
#if !(NET20 || NET35)
|
|
||||||
, IStructuralComparable, IStructuralEquatable
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
/// <summary>Initializes a new instance of the <see cref="SafeByteArray"/> class from a copy of a managed byte array.</summary>
|
/// <summary>Initializes a new instance of the <see cref="SafeByteArray"/> class from a copy of a managed byte array.</summary>
|
||||||
/// <param name="array">The array of bytes to copy.</param>
|
/// <param name="array">The array of bytes to copy.</param>
|
||||||
|
@ -26,12 +23,11 @@ namespace Vanara.InteropServices
|
||||||
|
|
||||||
/// <summary>Initializes a new instance of the <see cref="SafeByteArray"/> class and allocates <paramref name="byteCount"/> bytes.</summary>
|
/// <summary>Initializes a new instance of the <see cref="SafeByteArray"/> class and allocates <paramref name="byteCount"/> bytes.</summary>
|
||||||
/// <param name="byteCount">The byte count to allocate.</param>
|
/// <param name="byteCount">The byte count to allocate.</param>
|
||||||
public SafeByteArray(int byteCount) : base(byteCount)
|
public SafeByteArray(int byteCount) : base(byteCount) => Zero();
|
||||||
{
|
|
||||||
Zero();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Initializes a new instance of the <see cref="SafeByteArray"/> class by copying the bytes from another unmanaged array.</summary>
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="SafeByteArray"/> class by copying the bytes from another unmanaged array.
|
||||||
|
/// </summary>
|
||||||
/// <param name="src">Another unmanaged array.</param>
|
/// <param name="src">Another unmanaged array.</param>
|
||||||
public SafeByteArray(SafeByteArray src) : base(src?.Count ?? 0)
|
public SafeByteArray(SafeByteArray src) : base(src?.Count ?? 0)
|
||||||
{
|
{
|
||||||
|
@ -53,12 +49,17 @@ namespace Vanara.InteropServices
|
||||||
/// <summary>Gets a value indicating whether the <see cref="T:System.Collections.IList"/> has a fixed size.</summary>
|
/// <summary>Gets a value indicating whether the <see cref="T:System.Collections.IList"/> has a fixed size.</summary>
|
||||||
bool IList.IsFixedSize => true;
|
bool IList.IsFixedSize => true;
|
||||||
|
|
||||||
/// <summary>Gets a value indicating whether access to the <see cref="T:System.Collections.ICollection"/> is synchronized (thread safe).</summary>
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether access to the <see cref="T:System.Collections.ICollection"/> is synchronized (thread safe).
|
||||||
|
/// </summary>
|
||||||
bool ICollection.IsSynchronized => true;
|
bool ICollection.IsSynchronized => true;
|
||||||
|
|
||||||
/// <summary>Gets an object that can be used to synchronize access to the <see cref="T:System.Collections.ICollection"/>.</summary>
|
/// <summary>Gets an object that can be used to synchronize access to the <see cref="T:System.Collections.ICollection"/>.</summary>
|
||||||
object ICollection.SyncRoot => this;
|
object ICollection.SyncRoot => this;
|
||||||
|
|
||||||
|
[ExcludeFromCodeCoverage]
|
||||||
|
private new int Size { get => base.Size; set => base.Size = value; }
|
||||||
|
|
||||||
/// <summary>Gets or sets the <see cref="byte"/> at the specified index.</summary>
|
/// <summary>Gets or sets the <see cref="byte"/> at the specified index.</summary>
|
||||||
/// <value>The <see cref="byte"/>.</value>
|
/// <value>The <see cref="byte"/>.</value>
|
||||||
/// <param name="index">The index.</param>
|
/// <param name="index">The index.</param>
|
||||||
|
@ -89,38 +90,28 @@ namespace Vanara.InteropServices
|
||||||
set => this[index] = (byte)value;
|
set => this[index] = (byte)value;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ExcludeFromCodeCoverage]
|
|
||||||
private new int Size { get => base.Size; set => base.Size = value; }
|
|
||||||
|
|
||||||
/// <summary>Removes all items from the <see cref="T:System.Collections.Generic.ICollection{T}"/>.</summary>
|
/// <summary>Removes all items from the <see cref="T:System.Collections.Generic.ICollection{T}"/>.</summary>
|
||||||
/// <exception cref="System.NotSupportedException"></exception>
|
/// <exception cref="System.NotSupportedException"></exception>
|
||||||
public void Clear()
|
public void Clear() => Size = 0;
|
||||||
{
|
|
||||||
Size = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Creates a new object that is a copy of the current instance.</summary>
|
/// <summary>Creates a new object that is a copy of the current instance.</summary>
|
||||||
/// <returns>A new object that is a copy of this instance.</returns>
|
/// <returns>A new object that is a copy of this instance.</returns>
|
||||||
public object Clone()
|
public object Clone() => new SafeByteArray(this);
|
||||||
{
|
|
||||||
return new SafeByteArray(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Determines whether the <see cref="T:System.Collections.Generic.ICollection{T}"/> contains a specific value.</summary>
|
/// <summary>Determines whether the <see cref="T:System.Collections.Generic.ICollection{T}"/> contains a specific value.</summary>
|
||||||
/// <param name="item">The object to locate in the <see cref="T:System.Collections.Generic.ICollection{T}"/>.</param>
|
/// <param name="item">The object to locate in the <see cref="T:System.Collections.Generic.ICollection{T}"/>.</param>
|
||||||
/// <returns>true if <paramref name="item"/> is found in the <see cref="T:System.Collections.Generic.ICollection{T}"/>; otherwise, false.</returns>
|
/// <returns>
|
||||||
public bool Contains(byte item)
|
/// true if <paramref name="item"/> is found in the <see cref="T:System.Collections.Generic.ICollection{T}"/>; otherwise, false.
|
||||||
{
|
/// </returns>
|
||||||
return IndexOf(item) != -1;
|
public bool Contains(byte item) => IndexOf(item) != -1;
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Copies the elements of the <see cref="T:System.Collections.Generic.ICollection{T}"/> to an <see cref="T:System.Array"/>, starting at a particular
|
/// Copies the elements of the <see cref="T:System.Collections.Generic.ICollection{T}"/> to an <see cref="T:System.Array"/>, starting
|
||||||
/// <see cref="T:System.Array"/> index.
|
/// at a particular <see cref="T:System.Array"/> index.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="array">
|
/// <param name="array">
|
||||||
/// The one-dimensional <see cref="T:System.Array"/> that is the destination of the elements copied from
|
/// The one-dimensional <see cref="T:System.Array"/> that is the destination of the elements copied from <see
|
||||||
/// <see cref="T:System.Collections.Generic.ICollection{T}"/> . The <see cref="T:System.Array"/> must have zero-based indexing.
|
/// cref="T:System.Collections.Generic.ICollection{T}"/> . The <see cref="T:System.Array"/> must have zero-based indexing.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="arrayIndex">The zero-based index in <paramref name="array"/> at which copying begins.</param>
|
/// <param name="arrayIndex">The zero-based index in <paramref name="array"/> at which copying begins.</param>
|
||||||
/// <exception cref="System.ArgumentNullException">array</exception>
|
/// <exception cref="System.ArgumentNullException">array</exception>
|
||||||
|
@ -166,28 +157,28 @@ namespace Vanara.InteropServices
|
||||||
|
|
||||||
/// <summary>Adds an item to the <see cref="T:System.Collections.IList"/>.</summary>
|
/// <summary>Adds an item to the <see cref="T:System.Collections.IList"/>.</summary>
|
||||||
/// <param name="value">The object to add to the <see cref="T:System.Collections.IList"/>.</param>
|
/// <param name="value">The object to add to the <see cref="T:System.Collections.IList"/>.</param>
|
||||||
/// <returns>The position into which the new element was inserted, or -1 to indicate that the item was not inserted into the collection.</returns>
|
/// <returns>
|
||||||
|
/// The position into which the new element was inserted, or -1 to indicate that the item was not inserted into the collection.
|
||||||
|
/// </returns>
|
||||||
int IList.Add(object value) => throw new NotSupportedException();
|
int IList.Add(object value) => throw new NotSupportedException();
|
||||||
|
|
||||||
/// <summary>Adds an item to the <see cref="T:System.Collections.Generic.ICollection{T}"/>.</summary>
|
/// <summary>Adds an item to the <see cref="T:System.Collections.Generic.ICollection{T}"/>.</summary>
|
||||||
/// <param name="item">The object to add to the <see cref="T:System.Collections.Generic.ICollection{T}"/>.</param>
|
/// <param name="item">The object to add to the <see cref="T:System.Collections.Generic.ICollection{T}"/>.</param>
|
||||||
/// <exception cref="System.NotSupportedException"></exception>
|
/// <exception cref="System.NotSupportedException"></exception>
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
void ICollection<byte>.Add(byte item)
|
void ICollection<byte>.Add(byte item) => ((IList)this).Add(item);
|
||||||
{
|
|
||||||
((IList)this).Add(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !(NET20 || NET35)
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Determines whether the current collection object precedes, occurs in the same position as, or follows another object in the sort order.
|
/// Determines whether the current collection object precedes, occurs in the same position as, or follows another object in the sort order.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="other">The object to compare with the current instance.</param>
|
/// <param name="other">The object to compare with the current instance.</param>
|
||||||
/// <param name="comparer">An object that compares members of the current collection object with the corresponding members of <paramref name="other"/>.</param>
|
/// <param name="comparer">
|
||||||
|
/// An object that compares members of the current collection object with the corresponding members of <paramref name="other"/>.
|
||||||
|
/// </param>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// An integer that indicates the relationship of the current collection object to <paramref name="other"/>, as shown in the following table.Return
|
/// An integer that indicates the relationship of the current collection object to <paramref name="other"/>, as shown in the
|
||||||
/// valueDescription-1The current instance precedes <paramref name="other"/>.0The current instance and <paramref name="other"/> are equal.1The current
|
/// following table.Return valueDescription-1The current instance precedes <paramref name="other"/>.0The current instance and
|
||||||
/// instance follows <paramref name="other"/>.
|
/// <paramref name="other"/> are equal.1The current instance follows <paramref name="other"/>.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
int IStructuralComparable.CompareTo(object other, IComparer comparer)
|
int IStructuralComparable.CompareTo(object other, IComparer comparer)
|
||||||
{
|
{
|
||||||
|
@ -212,23 +203,19 @@ namespace Vanara.InteropServices
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/// <summary>Determines whether the <see cref="T:System.Collections.IList"/> contains a specific value.</summary>
|
/// <summary>Determines whether the <see cref="T:System.Collections.IList"/> contains a specific value.</summary>
|
||||||
/// <param name="value">The object to locate in the <see cref="T:System.Collections.IList"/>.</param>
|
/// <param name="value">The object to locate in the <see cref="T:System.Collections.IList"/>.</param>
|
||||||
/// <returns>true if the <see cref="T:System.Object"/> is found in the <see cref="T:System.Collections.IList"/>; otherwise, false.</returns>
|
/// <returns>true if the <see cref="T:System.Object"/> is found in the <see cref="T:System.Collections.IList"/>; otherwise, false.</returns>
|
||||||
bool IList.Contains(object value)
|
bool IList.Contains(object value) => Contains((byte)value);
|
||||||
{
|
|
||||||
return Contains((byte)value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Copies the elements of the <see cref="T:System.Collections.ICollection"/> to an <see cref="T:System.Array"/>, starting at a particular
|
/// Copies the elements of the <see cref="T:System.Collections.ICollection"/> to an <see cref="T:System.Array"/>, starting at a
|
||||||
/// <see cref="T:System.Array"/> index.
|
/// particular <see cref="T:System.Array"/> index.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="array">
|
/// <param name="array">
|
||||||
/// The one-dimensional <see cref="T:System.Array"/> that is the destination of the elements copied from <see cref="T:System.Collections.ICollection"/>.
|
/// The one-dimensional <see cref="T:System.Array"/> that is the destination of the elements copied from <see
|
||||||
/// The <see cref="T:System.Array"/> must have zero-based indexing.
|
/// cref="T:System.Collections.ICollection"/>. The <see cref="T:System.Array"/> must have zero-based indexing.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="index">The zero-based index in <paramref name="array"/> at which copying begins.</param>
|
/// <param name="index">The zero-based index in <paramref name="array"/> at which copying begins.</param>
|
||||||
/// <exception cref="System.ArgumentNullException">array</exception>
|
/// <exception cref="System.ArgumentNullException">array</exception>
|
||||||
|
@ -241,7 +228,6 @@ namespace Vanara.InteropServices
|
||||||
array.SetValue(this[i], i + index);
|
array.SetValue(this[i], i + index);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !(NET20 || NET35)
|
|
||||||
/// <summary>Determines whether the specified <see cref="System.Object"/>, is equal to this instance.</summary>
|
/// <summary>Determines whether the specified <see cref="System.Object"/>, is equal to this instance.</summary>
|
||||||
/// <param name="other">The <see cref="System.Object"/> to compare with this instance.</param>
|
/// <param name="other">The <see cref="System.Object"/> to compare with this instance.</param>
|
||||||
/// <param name="comparer">The comparer.</param>
|
/// <param name="comparer">The comparer.</param>
|
||||||
|
@ -274,13 +260,11 @@ namespace Vanara.InteropServices
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/// <summary>Returns an enumerator that iterates through a collection.</summary>
|
/// <summary>Returns an enumerator that iterates through a collection.</summary>
|
||||||
/// <returns>An <see cref="T:System.Collections.IEnumerator"/> object that can be used to iterate through the collection.</returns>
|
/// <returns>An <see cref="T:System.Collections.IEnumerator"/> object that can be used to iterate through the collection.</returns>
|
||||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||||
|
|
||||||
#if !(NET20 || NET35)
|
|
||||||
/// <summary>Returns a hash code for this instance.</summary>
|
/// <summary>Returns a hash code for this instance.</summary>
|
||||||
/// <param name="comparer">The comparer.</param>
|
/// <param name="comparer">The comparer.</param>
|
||||||
/// <returns>A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.</returns>
|
/// <returns>A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.</returns>
|
||||||
|
@ -295,7 +279,6 @@ namespace Vanara.InteropServices
|
||||||
ret = CombineHashCodes(ret, comparer.GetHashCode(this[i]));
|
ret = CombineHashCodes(ret, comparer.GetHashCode(this[i]));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/// <summary>Determines the index of a specific item in the <see cref="T:System.Collections.IList"/>.</summary>
|
/// <summary>Determines the index of a specific item in the <see cref="T:System.Collections.IList"/>.</summary>
|
||||||
/// <param name="value">The object to locate in the <see cref="T:System.Collections.IList"/>.</param>
|
/// <param name="value">The object to locate in the <see cref="T:System.Collections.IList"/>.</param>
|
||||||
|
@ -306,59 +289,39 @@ namespace Vanara.InteropServices
|
||||||
/// <param name="index">The zero-based index at which <paramref name="value"/> should be inserted.</param>
|
/// <param name="index">The zero-based index at which <paramref name="value"/> should be inserted.</param>
|
||||||
/// <param name="value">The object to insert into the <see cref="T:System.Collections.IList"/>.</param>
|
/// <param name="value">The object to insert into the <see cref="T:System.Collections.IList"/>.</param>
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
void IList.Insert(int index, object value)
|
void IList.Insert(int index, object value) => ((IList<byte>)this).Insert(index, (byte)value);
|
||||||
{
|
|
||||||
((IList<byte>)this).Insert(index, (byte)value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Inserts an item to the <see cref="T:System.Collections.Generic.IList{T}"/> at the specified index.</summary>
|
/// <summary>Inserts an item to the <see cref="T:System.Collections.Generic.IList{T}"/> at the specified index.</summary>
|
||||||
/// <param name="index">The zero-based index at which <paramref name="item"/> should be inserted.</param>
|
/// <param name="index">The zero-based index at which <paramref name="item"/> should be inserted.</param>
|
||||||
/// <param name="item">The object to insert into the <see cref="T:System.Collections.Generic.IList{T}"/>.</param>
|
/// <param name="item">The object to insert into the <see cref="T:System.Collections.Generic.IList{T}"/>.</param>
|
||||||
/// <exception cref="System.NotSupportedException"></exception>
|
/// <exception cref="System.NotSupportedException"></exception>
|
||||||
void IList<byte>.Insert(int index, byte item)
|
void IList<byte>.Insert(int index, byte item) => throw new NotSupportedException();
|
||||||
{
|
|
||||||
throw new NotSupportedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Removes the first occurrence of a specific object from the <see cref="T:System.Collections.IList"/>.</summary>
|
/// <summary>Removes the first occurrence of a specific object from the <see cref="T:System.Collections.IList"/>.</summary>
|
||||||
/// <param name="value">The object to remove from the <see cref="T:System.Collections.IList"/>.</param>
|
/// <param name="value">The object to remove from the <see cref="T:System.Collections.IList"/>.</param>
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
void IList.Remove(object value)
|
void IList.Remove(object value) => ((ICollection<byte>)this).Remove((byte)value);
|
||||||
{
|
|
||||||
((ICollection<byte>)this).Remove((byte)value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Removes the first occurrence of a specific object from the <see cref="T:System.Collections.Generic.ICollection{T}"/>.</summary>
|
/// <summary>Removes the first occurrence of a specific object from the <see cref="T:System.Collections.Generic.ICollection{T}"/>.</summary>
|
||||||
/// <param name="item">The object to remove from the <see cref="T:System.Collections.Generic.ICollection{T}"/>.</param>
|
/// <param name="item">The object to remove from the <see cref="T:System.Collections.Generic.ICollection{T}"/>.</param>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// true if <paramref name="item"/> was successfully removed from the <see cref="T:System.Collections.Generic.ICollection{T}"/>; otherwise, false. This
|
/// true if <paramref name="item"/> was successfully removed from the <see cref="T:System.Collections.Generic.ICollection{T}"/>;
|
||||||
/// method also returns false if <paramref name="item"/> is not found in the original <see cref="T:System.Collections.Generic.ICollection{T}"/>.
|
/// otherwise, false. This method also returns false if <paramref name="item"/> is not found in the original <see cref="T:System.Collections.Generic.ICollection{T}"/>.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
/// <exception cref="System.NotSupportedException"></exception>
|
/// <exception cref="System.NotSupportedException"></exception>
|
||||||
bool ICollection<byte>.Remove(byte item)
|
bool ICollection<byte>.Remove(byte item) => throw new NotSupportedException();
|
||||||
{
|
|
||||||
throw new NotSupportedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Removes the <see cref="T:System.Collections.Generic.IList{T}"/> item at the specified index.</summary>
|
/// <summary>Removes the <see cref="T:System.Collections.Generic.IList{T}"/> item at the specified index.</summary>
|
||||||
/// <param name="index">The zero-based index of the item to remove.</param>
|
/// <param name="index">The zero-based index of the item to remove.</param>
|
||||||
/// <exception cref="System.NotSupportedException"></exception>
|
/// <exception cref="System.NotSupportedException"></exception>
|
||||||
void IList.RemoveAt(int index)
|
void IList.RemoveAt(int index) => throw new NotSupportedException();
|
||||||
{
|
|
||||||
throw new NotSupportedException();
|
|
||||||
}
|
|
||||||
/// <summary>Removes the <see cref="T:System.Collections.Generic.IList{T}"/> item at the specified index.</summary>
|
/// <summary>Removes the <see cref="T:System.Collections.Generic.IList{T}"/> item at the specified index.</summary>
|
||||||
/// <param name="index">The zero-based index of the item to remove.</param>
|
/// <param name="index">The zero-based index of the item to remove.</param>
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
void IList<byte>.RemoveAt(int index)
|
void IList<byte>.RemoveAt(int index) => ((IList)this).RemoveAt(index);
|
||||||
{
|
|
||||||
((IList)this).RemoveAt(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int CombineHashCodes(int h1, int h2)
|
private static int CombineHashCodes(int h1, int h2) => ((h1 << 5) + h1) ^ h2;
|
||||||
{
|
|
||||||
return ((h1 << 5) + h1) ^ h2;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void CopyMemory(IntPtr src, IntPtr dest, int length)
|
private static void CopyMemory(IntPtr src, IntPtr dest, int length)
|
||||||
{
|
{
|
||||||
|
|
|
@ -102,9 +102,9 @@ namespace Vanara.IO
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Removes the first occurrence of a specific object from the <see cref="ICollection{T}" />. </summary> <param name="item">The object to
|
/// <summary> Removes the first occurrence of a specific object from the <see cref="ICollection{T}" />. </summary> <param name="item">The object to
|
||||||
/// remove from the <see cref=""ICollection{T}" />.</param> <returns> true if <paramref name="item" /> was successfully removed from the <see
|
/// remove from the <see cref="ICollection{T}" />.</param> <returns> true if <paramref name="item" /> was successfully removed from the <see
|
||||||
/// cref=""ICollection{T}" />; otherwise, false. This method also returns false if <paramref name="item" /> is not found in the original <see
|
/// cref="ICollection{T}" />; otherwise, false. This method also returns false if <paramref name="item" /> is not found in the original <see
|
||||||
/// cref=""ICollection{T}" />. </returns> <exception cref="ArgumentNullException">item</exception>
|
/// cref="ICollection{T}" />. </returns> <exception cref="ArgumentNullException">item</exception>
|
||||||
public bool Remove(BackgroundCopyJob item)
|
public bool Remove(BackgroundCopyJob item)
|
||||||
{
|
{
|
||||||
if (item == null) throw new ArgumentNullException(nameof(item));
|
if (item == null) throw new ArgumentNullException(nameof(item));
|
||||||
|
@ -116,7 +116,7 @@ namespace Vanara.IO
|
||||||
/// <returns>A <see cref="System.String"/> that represents this instance.</returns>
|
/// <returns>A <see cref="System.String"/> that represents this instance.</returns>
|
||||||
public override string ToString() => $"Jobs: {Count}";
|
public override string ToString() => $"Jobs: {Count}";
|
||||||
|
|
||||||
/// <summary>Adds an item to the <see cref=""ICollection{T}" />.</summary> <param name="item">The object to add to the <see cref=""ICollection{T}" />.</param>
|
/// <summary>Adds an item to the <see cref="ICollection{T}" />.</summary> <param name="item">The object to add to the <see cref="ICollection{T}" />.</param>
|
||||||
void ICollection<BackgroundCopyJob>.Add(BackgroundCopyJob item)
|
void ICollection<BackgroundCopyJob>.Add(BackgroundCopyJob item)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -127,9 +127,9 @@ namespace Vanara.IO
|
||||||
/// <exception cref="NotImplementedException"></exception>
|
/// <exception cref="NotImplementedException"></exception>
|
||||||
bool ICollection<BackgroundCopyJob>.Contains(BackgroundCopyJob item) => Contains(item.ID);
|
bool ICollection<BackgroundCopyJob>.Contains(BackgroundCopyJob item) => Contains(item.ID);
|
||||||
|
|
||||||
/// <summary> Copies the elements of the <see cref=""ICollection{T}" /> to an <see cref="Array" />, starting at a particular <see cref="Array" /> index.
|
/// <summary> Copies the elements of the <see cref="ICollection{T}" /> to an <see cref="Array" />, starting at a particular <see cref="Array" /> index.
|
||||||
/// </summary> <param name="array">The one-dimensional <see cref="Array" /> that is the destination of the elements copied from <see
|
/// </summary> <param name="array">The one-dimensional <see cref="Array" /> that is the destination of the elements copied from <see
|
||||||
/// cref=""ICollection{T}" />. The <see cref="Array" /> must have zero-based indexing.</param> <param name="arrayIndex">The zero-based index in <paramref
|
/// cref="ICollection{T}" />. The <see cref="Array" /> must have zero-based indexing.</param> <param name="arrayIndex">The zero-based index in <paramref
|
||||||
/// name="array" /> at which copying begins.</param> <exception cref="NotImplementedException"></exception>
|
/// name="array" /> at which copying begins.</param> <exception cref="NotImplementedException"></exception>
|
||||||
void ICollection<BackgroundCopyJob>.CopyTo(BackgroundCopyJob[] array, int arrayIndex)
|
void ICollection<BackgroundCopyJob>.CopyTo(BackgroundCopyJob[] array, int arrayIndex)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Security.Principal;
|
using System.Security.Principal;
|
||||||
#if !(NET20 || NET35 || NET40)
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
#endif
|
|
||||||
using Vanara.PInvoke;
|
using Vanara.PInvoke;
|
||||||
using static Vanara.PInvoke.BITS;
|
using static Vanara.PInvoke.BITS;
|
||||||
|
|
||||||
|
@ -63,8 +61,6 @@ namespace Vanara.IO
|
||||||
CopyTemplate(sourceFileName, destFileName, () => false, System.Threading.Thread.Sleep, null, f => f.Add(sourceFileName, destFileName));
|
CopyTemplate(sourceFileName, destFileName, () => false, System.Threading.Thread.Sleep, null, f => f.Add(sourceFileName, destFileName));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !(NET20 || NET35 || NET40)
|
|
||||||
|
|
||||||
/// <summary>Copies an existing file to a new file using BITS. Overwriting a file of the same name is not allowed.</summary>
|
/// <summary>Copies an existing file to a new file using BITS. Overwriting a file of the same name is not allowed.</summary>
|
||||||
/// <param name="sourceFileName">The file to copy.</param>
|
/// <param name="sourceFileName">The file to copy.</param>
|
||||||
/// <param name="destFileName">The name of the destination file.</param>
|
/// <param name="destFileName">The name of the destination file.</param>
|
||||||
|
@ -73,13 +69,16 @@ namespace Vanara.IO
|
||||||
/// <returns>A task that represents the asynchronous copy operation.</returns>
|
/// <returns>A task that represents the asynchronous copy operation.</returns>
|
||||||
public static async Task CopyAsync(string sourceFileName, string destFileName, CancellationToken cancellationToken, IProgress<Tuple<BackgroundCopyJobState, byte>> progress)
|
public static async Task CopyAsync(string sourceFileName, string destFileName, CancellationToken cancellationToken, IProgress<Tuple<BackgroundCopyJobState, byte>> progress)
|
||||||
{
|
{
|
||||||
await Task.Run(() => CopyTemplate(sourceFileName, destFileName, () => cancellationToken.IsCancellationRequested,
|
#if NET40
|
||||||
|
await TaskEx.Run(() => CopyTemplate(sourceFileName, destFileName, () => cancellationToken.IsCancellationRequested,
|
||||||
Thread.Sleep, (s, p) => progress?.Report(new Tuple<BackgroundCopyJobState, byte>(s,p)), f => f.Add(sourceFileName, destFileName)), cancellationToken);
|
Thread.Sleep, (s, p) => progress?.Report(new Tuple<BackgroundCopyJobState, byte>(s,p)), f => f.Add(sourceFileName, destFileName)), cancellationToken);
|
||||||
|
#else
|
||||||
|
await Task.Run(() => CopyTemplate(sourceFileName, destFileName, () => cancellationToken.IsCancellationRequested,
|
||||||
|
Thread.Sleep, (s, p) => progress?.Report(new Tuple<BackgroundCopyJobState, byte>(s, p)), f => f.Add(sourceFileName, destFileName)), cancellationToken);
|
||||||
|
#endif
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
private static IBackgroundCopyManager IMgr { get; set; }
|
private static IBackgroundCopyManager IMgr { get; set; }
|
||||||
|
|
||||||
internal static IBackgroundCopyJob CreateJob(string displayName, BG_JOB_TYPE jobType = BG_JOB_TYPE.BG_JOB_TYPE_DOWNLOAD)
|
internal static IBackgroundCopyJob CreateJob(string displayName, BG_JOB_TYPE jobType = BG_JOB_TYPE.BG_JOB_TYPE_DOWNLOAD)
|
||||||
|
|
|
@ -60,8 +60,9 @@ BackgroundCopyACLFlags, BackgroundCopyCost, BackgroundCopyErrorContext, Backgrou
|
||||||
<Reference Include="System.ServiceProcess" />
|
<Reference Include="System.ServiceProcess" />
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' Or '$(TargetFramework)' == 'netcoreapp2.0' Or '$(TargetFramework)' == 'netcoreapp2.1' ">
|
<ItemGroup>
|
||||||
<PackageReference Include="System.IO.FileSystem.AccessControl" Version="4.5.0" />
|
<PackageReference Include="System.IO.FileSystem.AccessControl" Version="4.5.0" Condition=" '$(TargetFramework)' == 'netstandard2.0' Or '$(TargetFramework)' == 'netcoreapp2.0' Or '$(TargetFramework)' == 'netcoreapp2.1' " />
|
||||||
|
<PackageReference Include="Theraot.Core" Version="2.1.0" Condition=" '$(TargetFramework)' == 'net20' Or '$(TargetFramework)' == 'net35' Or '$(TargetFramework)' == 'net40' " />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\PInvoke\BITS\Vanara.PInvoke.BITS.csproj" />
|
<ProjectReference Include="..\PInvoke\BITS\Vanara.PInvoke.BITS.csproj" />
|
||||||
|
|
|
@ -7,10 +7,8 @@ using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Security.AccessControl;
|
using System.Security.AccessControl;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
#if !(NET20 || NET35 || NET40)
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
#endif
|
|
||||||
using Vanara.Extensions;
|
using Vanara.Extensions;
|
||||||
using Vanara.InteropServices;
|
using Vanara.InteropServices;
|
||||||
using Vanara.PInvoke;
|
using Vanara.PInvoke;
|
||||||
|
@ -530,7 +528,6 @@ namespace Vanara.IO
|
||||||
ResizeVirtualDisk(Handle, flags, param, IntPtr.Zero).ThrowIfFailed();
|
ResizeVirtualDisk(Handle, flags, param, IntPtr.Zero).ThrowIfFailed();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !(NET20 || NET35 || NET40)
|
|
||||||
/// <summary>Creates a virtual hard disk (VHD) image file, either using default parameters or using an existing VHD or physical disk.</summary>
|
/// <summary>Creates a virtual hard disk (VHD) image file, either using default parameters or using an existing VHD or physical disk.</summary>
|
||||||
/// <param name="path">A valid file path that represents the path to the new virtual disk image file.</param>
|
/// <param name="path">A valid file path that represents the path to the new virtual disk image file.</param>
|
||||||
/// <param name="sourcePath">
|
/// <param name="sourcePath">
|
||||||
|
@ -569,7 +566,11 @@ namespace Vanara.IO
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
#if (NET20 || NET35)
|
||||||
|
if (!b) throw new Theraot.Core.NewOperationCanceledException(cancellationToken);
|
||||||
|
#else
|
||||||
if (!b) throw new OperationCanceledException(cancellationToken);
|
if (!b) throw new OperationCanceledException(cancellationToken);
|
||||||
|
#endif
|
||||||
return new VirtualDisk(new SafeVIRTUAL_DISK_HANDLE(h), (OPEN_VIRTUAL_DISK_VERSION)param.Version);
|
return new VirtualDisk(new SafeVIRTUAL_DISK_HANDLE(h), (OPEN_VIRTUAL_DISK_VERSION)param.Version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -648,10 +649,17 @@ namespace Vanara.IO
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (prog.CurrentValue == prog.CompletionValue) return true;
|
if (prog.CurrentValue == prog.CompletionValue) return true;
|
||||||
|
#if NET40
|
||||||
|
if (cancellationToken == null)
|
||||||
|
await TaskEx.Delay(250);
|
||||||
|
else
|
||||||
|
await TaskEx.Delay(250, cancellationToken);
|
||||||
|
#else
|
||||||
if (cancellationToken == null)
|
if (cancellationToken == null)
|
||||||
await Task.Delay(250);
|
await Task.Delay(250);
|
||||||
else
|
else
|
||||||
await Task.Delay(250, cancellationToken);
|
await Task.Delay(250, cancellationToken);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -730,7 +738,6 @@ namespace Vanara.IO
|
||||||
|
|
||||||
void ReportProgress(int percent) { progress.Report(new Tuple<int, string>(percent, $"Compacting VHD volume \"{loc}\"")); }
|
void ReportProgress(int percent) { progress.Report(new Tuple<int, string>(percent, $"Compacting VHD volume \"{loc}\"")); }
|
||||||
}*/
|
}*/
|
||||||
#endif
|
|
||||||
|
|
||||||
private static SafeSecurityDescriptor FileSecToSd(FileSecurity sec)
|
private static SafeSecurityDescriptor FileSecToSd(FileSecurity sec)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#if !(NET20 || NET35 || NET40)
|
using System;
|
||||||
using System;
|
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
@ -451,4 +450,3 @@ namespace Vanara.Windows.Forms
|
||||||
public string StatusText { get; set; }
|
public string StatusText { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
Loading…
Reference in New Issue