internal static void ThrowException(int errorCode, string errorMessage = null, string paramName = null)
{
DownloadError err = (DownloadError)errorCode;
+ string message;
+
if (String.IsNullOrEmpty(errorMessage))
{
- errorMessage = err.ToString();
+ message = err.ToString();
+ }
+ else
+ {
+ message = errorMessage;
}
switch ((DownloadError)errorCode)
{
case DownloadError.InvalidParameter:
case DownloadError.InvalidUrl:
case DownloadError.InvalidDestination:
- case DownloadError.InvalidNetworkType: throw new ArgumentException(errorMessage, paramName);
+ case DownloadError.InvalidNetworkType: throw new ArgumentException(message, paramName);
case DownloadError.OutOfMemory:
case DownloadError.NetworkUnreachable:
case DownloadError.ConnectionTimedOut:
case DownloadError.SystemDown:
case DownloadError.IdNotFound:
case DownloadError.NoData:
- case DownloadError.IoError: throw new InvalidOperationException(errorMessage);
- case DownloadError.NotSupported: throw new NotSupportedException(errorMessage);
- case DownloadError.PermissionDenied: throw new UnauthorizedAccessException(errorMessage);
+ case DownloadError.IoError: throw new InvalidOperationException(message);
+ case DownloadError.NotSupported: throw new NotSupportedException(message);
+ case DownloadError.PermissionDenied: throw new UnauthorizedAccessException(message);
}
}
}
}
set
{
- int ret = Interop.Download.SetNotificationTitle(_downloadId, value.ToString());
+ int ret = Interop.Download.SetNotificationTitle(_downloadId, value);
if (ret != (int)DownloadError.None)
{
DownloadErrorFactory.ThrowException(ret, "Failed to set Notification Title");
}
set
{
- int ret = Interop.Download.SetNotificationDescription(_downloadId, value.ToString());
+ int ret = Interop.Download.SetNotificationDescription(_downloadId, value);
if (ret != (int)DownloadError.None)
{
DownloadErrorFactory.ThrowException(ret, "Failed to set Notification Description");
}
set
{
- int ret = Interop.Download.SetDestination(_downloadId, value.ToString());
+ int ret = Interop.Download.SetDestination(_downloadId, value);
if (ret != (int)DownloadError.None)
{
DownloadErrorFactory.ThrowException(ret, "Failed to set DestinationPath");
}
set
{
- int ret = Interop.Download.SetFileName(_downloadId, value.ToString());
+ int ret = Interop.Download.SetFileName(_downloadId, value);
if (ret != (int)DownloadError.None)
{
DownloadErrorFactory.ThrowException(ret, "Failed to set FileName");
/// <exception cref="UnauthorizedAccessException">Thrown when a permission is denied.</exception>
public void Start()
{
- int ret = (int)DownloadError.None;
+ int ret;
foreach (KeyValuePair<string, string> entry in _httpHeaders)
{
ret = Interop.Download.AddHttpHeaderField(_downloadId, entry.Key, entry.Value);
_disposed = true;
}
- static private void IntPtrToStringArray(IntPtr unmanagedArray, int size, out string[] managedArray)
- {
- managedArray = new string[size];
- IntPtr[] IntPtrArray = new IntPtr[size];
-
- Marshal.Copy(unmanagedArray, IntPtrArray, 0, size);
-
- for (int iterator = 0; iterator < size; iterator++)
- {
- managedArray[iterator] = Marshal.PtrToStringAnsi(IntPtrArray[iterator]);
- }
- }
-
private void RegisterStateChangedEvent()
{
_downloadStateChangedCallback = (int downloadId, int downloadState, IntPtr userData) =>