Skip to content

Instantly share code, notes, and snippets.

@Ganeshcse
Last active March 3, 2017 15:22
Show Gist options
  • Save Ganeshcse/431d739b9de445423adb2aa8667a3113 to your computer and use it in GitHub Desktop.
Save Ganeshcse/431d739b9de445423adb2aa8667a3113 to your computer and use it in GitHub Desktop.
Task.Run(() =>
{
isDirectoryCopySuccessful = CopyHelper.CopyDirectory(sourceLocation, destinationLocation);
Win.Application.Current.Dispatcher.Invoke(() =>
{
BaseWindow.HideNotification();
ShowMessage?.Invoke("Files copied into destination location successfully", "Information");
});
}).ContinueWith((t) =>
{
if(t.IsFaulted)
{
throw t.Exception;
}
else
{
if (isDirectoryCopySuccessful)
{
var description = "Copied To : " + selectedItem.GetFolderServerRelativeUrl();
CopyHelper.InsertAuditLog(
sourceLocation,
selectedItem.GetFolderServerRelativeUrl(),
selectedItem.GetSiteUrl(),
description,
emailId,
userFullName);
}
}
}, TaskScheduler.FromCurrentSynchronizationContext());
foreach (var file in files)
{
var fileInfo = new FileInfo(file);
CopyFile(fileInfo, destinationLocation);
currentProgressValue += 1;
//Dispatcher.CurrentDispatcher.Invoke(() => {
// BaseWindow.UpdateProgress(currentProgressValue, "Copying...");
//});
Win.Application.Current.Dispatcher.Invoke(() =>
{
BaseWindow.UpdateProgress(currentProgressValue, "Copying...");
});
}
Win.Application.Current.Dispatcher.Invoke(() =>
{
canOverWriteFile = (bool)GetOverWriteConfirmation?
.Invoke("A file name already exists in the destination location? Do you want to overwrite it?",
"Confirmation", "Yes");
});
//canOverWriteFile = (bool)GetOverWriteConfirmation?
// .Invoke("A file name already exists in the destination location? Do you want to overwrite it?",
// "Confirmation", "Yes");
if (!canOverWriteFile)
{
// Log message with oldfile and new file name
var oldFileName = fullPath.Replace(destinationLocation + "\\", "");
fullPath = GetFinalFileNameWithPath(fullPath);
string newName = fullPath.Replace(destinationLocation + "\\", "");
var logMessgeBuilder = new StringBuilder();
logMessgeBuilder.Append("Due to exsistance of another copy, File Name has been changed from");
logMessgeBuilder.Append("" + oldFileName + " to " + newName + " on " + DateTime.Now.ToShortDateString() + "");
// Log message that file name has been changed from old file to new file.
LogHelper.Info(logMessgeBuilder.ToString());
}
@Ganeshcse
Copy link
Author

Exception I got is below,

Unknown error: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread.

Index was outside the bounds of the array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment