2273 lines
78 KiB
C#
2273 lines
78 KiB
C#
// Decompiled with JetBrains decompiler
|
|
// Type: CarotDAV.AsyncCopy
|
|
// Assembly: CarotDAV, Version=1.13.2.18337, Culture=neutral, PublicKeyToken=null
|
|
// MVID: C31F2651-A4A8-4D09-916A-8C6106F5E7C8
|
|
// Assembly location: F:\Eigene Dateien\Dropbox\portable Collection\Progs\CarotDAV\CarotDAV.exe
|
|
|
|
using Microsoft.VisualBasic.CompilerServices;
|
|
using Rei.Com;
|
|
using Rei.Fs;
|
|
using Rei.Fs.IO;
|
|
using Rei.Fs.Webdav;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Windows.Forms;
|
|
|
|
namespace CarotDAV
|
|
{
|
|
public class AsyncCopy : Component
|
|
{
|
|
private static DateTime win32timeorigin = new DateTime(1601, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
|
private IContainer components;
|
|
private object pLock;
|
|
private int pWorkerState;
|
|
private bool pStopAfterFile;
|
|
private LinkedList<AsyncCopy.DavCopyTask> pTaskList;
|
|
private FsBase pFS;
|
|
private CacheManager pCache;
|
|
private UCSNormalization pUploadFilenameNormalization;
|
|
private UCSNormalization pDownloadFilenameNormalization;
|
|
private SendOrPostCallback pServerResourceChangedCallback;
|
|
private SendOrPostCallback pCompleteCallback;
|
|
private AsyncCopy.DavCopyWorkerDelegate pDavCopyWorkerDelegate;
|
|
private AsyncCopy.DavCopyStateType pCurrentState;
|
|
private long pTotalCost;
|
|
private long pTotalProgress;
|
|
private double pTotalTransferSeconds;
|
|
private long pCurrentCost;
|
|
private long pCurrentProgress;
|
|
private double pCurrentSeconds;
|
|
private string pCurrentDesc;
|
|
private long pTotalFiles;
|
|
private long pTotalFolders;
|
|
private long pCurrentFiles;
|
|
private long pCurrentFolders;
|
|
private bool pCancelled;
|
|
private Exception pLastException;
|
|
private AsyncOperation pAsyncOp;
|
|
|
|
[DebuggerNonUserCode]
|
|
public AsyncCopy(IContainer container)
|
|
: this()
|
|
{
|
|
if (container == null)
|
|
return;
|
|
container.Add((IComponent) this);
|
|
}
|
|
|
|
[DebuggerNonUserCode]
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
try
|
|
{
|
|
if (!disposing || this.components == null)
|
|
return;
|
|
this.components.Dispose();
|
|
}
|
|
finally
|
|
{
|
|
base.Dispose(disposing);
|
|
}
|
|
}
|
|
|
|
[DebuggerStepThrough]
|
|
private void InitializeComponent()
|
|
{
|
|
this.components = (IContainer) new System.ComponentModel.Container();
|
|
}
|
|
|
|
public event EventHandler<ResourceChangedEventArgs> RemoteResourceChanged;
|
|
|
|
public event AsyncCompletedEventHandler CopyCompleted;
|
|
|
|
public event EventHandler<AsyncCopy.CopyConflictedEventArgs> ConflictionOccurred;
|
|
|
|
public event EventHandler<ExceptionOccurredEventArgs> ExceptionOccurred;
|
|
|
|
[DebuggerNonUserCode]
|
|
public AsyncCopy()
|
|
{
|
|
this.Disposed += new EventHandler(this.AsyncCopy_Disposed);
|
|
this.pServerResourceChangedCallback = new SendOrPostCallback(this.ServerResourceChangedCallback);
|
|
this.pCompleteCallback = new SendOrPostCallback(this.DavCopyCompletedCallback);
|
|
this.pDavCopyWorkerDelegate = new AsyncCopy.DavCopyWorkerDelegate(this.Worker);
|
|
this.InitializeComponent();
|
|
this.pLock = RuntimeHelpers.GetObjectValue(new object());
|
|
this.pTaskList = new LinkedList<AsyncCopy.DavCopyTask>();
|
|
this.pUploadFilenameNormalization = UCSNormalization.None;
|
|
this.pDownloadFilenameNormalization = UCSNormalization.None;
|
|
}
|
|
|
|
public int TaskCount
|
|
{
|
|
get
|
|
{
|
|
object pLock = this.pLock;
|
|
ObjectFlowControl.CheckForSyncLockOnValueType(pLock);
|
|
Monitor.Enter(pLock);
|
|
try
|
|
{
|
|
return this.pTaskList.Count;
|
|
}
|
|
finally
|
|
{
|
|
Monitor.Exit(pLock);
|
|
}
|
|
}
|
|
}
|
|
|
|
public int UncompleteTaskCount
|
|
{
|
|
get
|
|
{
|
|
object pLock = this.pLock;
|
|
ObjectFlowControl.CheckForSyncLockOnValueType(pLock);
|
|
Monitor.Enter(pLock);
|
|
int num=0;
|
|
try
|
|
{
|
|
LinkedList<AsyncCopy.DavCopyTask>.Enumerator enumerator = this.pTaskList.GetEnumerator();
|
|
try
|
|
{
|
|
while (enumerator.MoveNext())
|
|
{
|
|
AsyncCopy.DavCopyTask current = enumerator.Current;
|
|
if (current.State != AsyncCopy.TaskStateType.Complete && current.State != AsyncCopy.TaskStateType.ErrorIgnore && current.State != AsyncCopy.TaskStateType.Skipped)
|
|
checked { ++num; }
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
enumerator.Dispose();
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
Monitor.Exit(pLock);
|
|
}
|
|
return num;
|
|
}
|
|
}
|
|
|
|
public int FinishedTaskCount
|
|
{
|
|
get
|
|
{
|
|
object pLock = this.pLock;
|
|
ObjectFlowControl.CheckForSyncLockOnValueType(pLock);
|
|
Monitor.Enter(pLock);
|
|
int num=0;
|
|
try
|
|
{
|
|
LinkedList<AsyncCopy.DavCopyTask>.Enumerator enumerator = this.pTaskList.GetEnumerator();
|
|
try
|
|
{
|
|
while (enumerator.MoveNext())
|
|
{
|
|
AsyncCopy.DavCopyTask current = enumerator.Current;
|
|
if (current.State == AsyncCopy.TaskStateType.Complete)
|
|
checked { ++num; }
|
|
if (current.State == AsyncCopy.TaskStateType.ErrorIgnore)
|
|
checked { ++num; }
|
|
if (current.State == AsyncCopy.TaskStateType.Skipped)
|
|
checked { ++num; }
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
enumerator.Dispose();
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
Monitor.Exit(pLock);
|
|
}
|
|
return num;
|
|
}
|
|
}
|
|
|
|
public void SetClient(FsBase fs, CacheManager cm, UCSNormalization downnormalization, UCSNormalization uploadnormalization)
|
|
{
|
|
this.pFS = fs;
|
|
this.pCache = cm;
|
|
this.pDownloadFilenameNormalization = downnormalization;
|
|
this.pUploadFilenameNormalization = uploadnormalization;
|
|
}
|
|
|
|
public void Download(ResourceId[] remoteids, string localdir)
|
|
{
|
|
object pLock = this.pLock;
|
|
ObjectFlowControl.CheckForSyncLockOnValueType(pLock);
|
|
Monitor.Enter(pLock);
|
|
try
|
|
{
|
|
ResourceId[] resourceIdArray = remoteids;
|
|
int index = 0;
|
|
while (index < resourceIdArray.Length)
|
|
{
|
|
this.pTaskList.AddLast(new AsyncCopy.DavCopyTask(AsyncCopy.TaskType.Download, resourceIdArray[index], localdir));
|
|
checked { ++index; }
|
|
}
|
|
this.pTotalCost = -1L;
|
|
}
|
|
finally
|
|
{
|
|
Monitor.Exit(pLock);
|
|
}
|
|
}
|
|
|
|
public void Upload(string[] localfiles, ResourceId remoteid, IDataObject dobj, DragDropEffects finisheffect)
|
|
{
|
|
object pLock = this.pLock;
|
|
ObjectFlowControl.CheckForSyncLockOnValueType(pLock);
|
|
Monitor.Enter(pLock);
|
|
try
|
|
{
|
|
int num1 = 0;
|
|
int num2 = checked (localfiles.Length - 1);
|
|
int index = num1;
|
|
while (index <= num2)
|
|
{
|
|
this.pTaskList.AddLast(new AsyncCopy.DavCopyTask(AsyncCopy.TaskType.Upload, remoteid, localfiles[index]));
|
|
checked { ++index; }
|
|
}
|
|
this.pTaskList.Last.Value.DataObject = dobj;
|
|
this.pTaskList.Last.Value.FinishEffect = finisheffect;
|
|
this.pTotalCost = -1L;
|
|
}
|
|
finally
|
|
{
|
|
Monitor.Exit(pLock);
|
|
}
|
|
}
|
|
|
|
public void UploadDescriptors(VirtualFileInfo[] vfinfos, ResourceId remoteid, IDataObject dobj, DragDropEffects finisheffect)
|
|
{
|
|
List<AsyncCopy.DavCopyTask> davCopyTaskList = new List<AsyncCopy.DavCopyTask>();
|
|
int num1 = 0;
|
|
int num2 = checked (vfinfos.Length - 1);
|
|
int index1 = num1;
|
|
while (index1 <= num2)
|
|
{
|
|
bool flag = (vfinfos[index1].FileAttributes & FileAttributes.Directory) != (FileAttributes) 0;
|
|
string[] strArray = vfinfos[index1].FileName.Split(new char[2]
|
|
{
|
|
'\\',
|
|
'/'
|
|
}, StringSplitOptions.RemoveEmptyEntries);
|
|
AsyncCopy.DavCopyTask parenttask = (AsyncCopy.DavCopyTask) null;
|
|
int num3 = 0;
|
|
int num4 = checked (strArray.Length - 2);
|
|
int index2 = num3;
|
|
while (index2 <= num4)
|
|
{
|
|
AsyncCopy.DavCopyTask davCopyTask = (AsyncCopy.DavCopyTask) null;
|
|
AsyncCopy.DavCopyTask[] davCopyTaskArray = parenttask != null ? parenttask.SubTasks : davCopyTaskList.ToArray();
|
|
int num5 = 0;
|
|
int num6 = checked (davCopyTaskArray.Length - 1);
|
|
int index3 = num5;
|
|
while (index3 <= num6)
|
|
{
|
|
if (Operators.CompareString(davCopyTaskArray[index3].LocalPath, strArray[index2], false) == 0 && davCopyTaskArray[index3].IsCollection)
|
|
{
|
|
davCopyTask = davCopyTaskArray[index3];
|
|
break;
|
|
}
|
|
checked { ++index3; }
|
|
}
|
|
if (davCopyTask == null)
|
|
{
|
|
if (parenttask == null)
|
|
{
|
|
davCopyTask = new AsyncCopy.DavCopyTask(AsyncCopy.TaskType.Upload, remoteid, strArray[index2]);
|
|
davCopyTaskList.Add(davCopyTask);
|
|
}
|
|
else
|
|
davCopyTask = new AsyncCopy.DavCopyTask(parenttask, strArray[index2]);
|
|
davCopyTask.Size = -1L;
|
|
davCopyTask.IsCollection = true;
|
|
davCopyTask.LastModifiedTime = DateTime.MinValue;
|
|
davCopyTask.CreationDate = DateTime.MinValue;
|
|
davCopyTask.LastModifiedTime = DateTime.MinValue;
|
|
davCopyTask.State = AsyncCopy.TaskStateType.PropertyAcquired;
|
|
}
|
|
parenttask = davCopyTask;
|
|
checked { ++index2; }
|
|
}
|
|
AsyncCopy.DavCopyTask davCopyTask1 = (AsyncCopy.DavCopyTask) null;
|
|
AsyncCopy.DavCopyTask[] davCopyTaskArray1 = parenttask != null ? parenttask.SubTasks : davCopyTaskList.ToArray();
|
|
int num7 = 0;
|
|
int num8 = checked (davCopyTaskArray1.Length - 1);
|
|
int index4 = num7;
|
|
while (index4 <= num8)
|
|
{
|
|
if (Operators.CompareString(davCopyTaskArray1[index4].LocalPath, strArray[index2], false) == 0 && davCopyTaskArray1[index4].IsCollection == flag)
|
|
{
|
|
davCopyTask1 = davCopyTaskArray1[index4];
|
|
break;
|
|
}
|
|
checked { ++index4; }
|
|
}
|
|
if (davCopyTask1 == null)
|
|
{
|
|
if (parenttask == null)
|
|
{
|
|
davCopyTask1 = new AsyncCopy.DavCopyTask(AsyncCopy.TaskType.Upload, remoteid, vfinfos[index1]);
|
|
davCopyTaskList.Add(davCopyTask1);
|
|
}
|
|
else
|
|
davCopyTask1 = new AsyncCopy.DavCopyTask(parenttask, strArray[index2], vfinfos[index1]);
|
|
}
|
|
if ((vfinfos[index1].Flags & FDFlags.FD_CREATETIME) != (FDFlags) 0)
|
|
davCopyTask1.CreationDate = vfinfos[index1].CreationTime;
|
|
if ((vfinfos[index1].Flags & FDFlags.FD_ACCESSTIME) != (FDFlags) 0)
|
|
davCopyTask1.LastAccessTime = vfinfos[index1].LastAccessTime;
|
|
if ((vfinfos[index1].Flags & FDFlags.FD_WRITESTIME) != (FDFlags) 0)
|
|
davCopyTask1.LastModifiedTime = vfinfos[index1].LastWriteTime;
|
|
davCopyTask1.Size = (vfinfos[index1].Flags & FDFlags.FD_FILESIZE) == (FDFlags) 0 ? -1L : checked ((long) vfinfos[index1].FileSize);
|
|
davCopyTask1.IsCollection = flag;
|
|
davCopyTask1.State = AsyncCopy.TaskStateType.PropertyAcquired;
|
|
checked { ++index1; }
|
|
}
|
|
object pLock = this.pLock;
|
|
ObjectFlowControl.CheckForSyncLockOnValueType(pLock);
|
|
Monitor.Enter(pLock);
|
|
try
|
|
{
|
|
int num3 = 0;
|
|
int num4 = checked (davCopyTaskList.Count - 1);
|
|
int index2 = num3;
|
|
while (index2 <= num4)
|
|
{
|
|
this.pTaskList.AddLast(davCopyTaskList[index2]);
|
|
checked { ++index2; }
|
|
}
|
|
this.pTaskList.Last.Value.DataObject = dobj;
|
|
this.pTaskList.Last.Value.FinishEffect = finisheffect;
|
|
this.pTotalCost = -1L;
|
|
}
|
|
finally
|
|
{
|
|
Monitor.Exit(pLock);
|
|
}
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
object pLock = this.pLock;
|
|
ObjectFlowControl.CheckForSyncLockOnValueType(pLock);
|
|
Monitor.Enter(pLock);
|
|
try
|
|
{
|
|
this.pTotalCost = -1L;
|
|
this.pTaskList.Clear();
|
|
}
|
|
finally
|
|
{
|
|
Monitor.Exit(pLock);
|
|
}
|
|
}
|
|
|
|
public void DavCopyAsync()
|
|
{
|
|
object pLock = this.pLock;
|
|
ObjectFlowControl.CheckForSyncLockOnValueType(pLock);
|
|
Monitor.Enter(pLock);
|
|
try
|
|
{
|
|
if (this.pWorkerState != 0)
|
|
throw new InvalidOperationException();
|
|
this.pWorkerState = 1;
|
|
this.pCancelled = false;
|
|
}
|
|
finally
|
|
{
|
|
Monitor.Exit(pLock);
|
|
}
|
|
if (this.pFS == null)
|
|
throw new InvalidOperationException();
|
|
this.pDavCopyWorkerDelegate.BeginInvoke(AsyncOperationManager.CreateOperation(RuntimeHelpers.GetObjectValue(this.pLock)), (AsyncCallback) null, (object) null);
|
|
}
|
|
|
|
public bool IsBusy
|
|
{
|
|
get
|
|
{
|
|
object pLock = this.pLock;
|
|
ObjectFlowControl.CheckForSyncLockOnValueType(pLock);
|
|
Monitor.Enter(pLock);
|
|
try
|
|
{
|
|
return this.pWorkerState != 0;
|
|
}
|
|
finally
|
|
{
|
|
Monitor.Exit(pLock);
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool StopAfterFile
|
|
{
|
|
get
|
|
{
|
|
object pLock = this.pLock;
|
|
ObjectFlowControl.CheckForSyncLockOnValueType(pLock);
|
|
Monitor.Enter(pLock);
|
|
try
|
|
{
|
|
return this.pStopAfterFile;
|
|
}
|
|
finally
|
|
{
|
|
Monitor.Exit(pLock);
|
|
}
|
|
}
|
|
set
|
|
{
|
|
object pLock = this.pLock;
|
|
ObjectFlowControl.CheckForSyncLockOnValueType(pLock);
|
|
Monitor.Enter(pLock);
|
|
try
|
|
{
|
|
this.pStopAfterFile = value;
|
|
}
|
|
finally
|
|
{
|
|
Monitor.Exit(pLock);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void DavCopyAsyncCancel()
|
|
{
|
|
object pLock = this.pLock;
|
|
ObjectFlowControl.CheckForSyncLockOnValueType(pLock);
|
|
Monitor.Enter(pLock);
|
|
try
|
|
{
|
|
if (this.pWorkerState != 1)
|
|
return;
|
|
this.pWorkerState = 2;
|
|
}
|
|
finally
|
|
{
|
|
Monitor.Exit(pLock);
|
|
}
|
|
}
|
|
|
|
protected void OnServerResourceChanged(ResourceChangedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
EventHandler<ResourceChangedEventArgs> resourceChangedEvent = this.RemoteResourceChanged;
|
|
if (resourceChangedEvent == null)
|
|
return;
|
|
resourceChangedEvent((object) null, e);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ProjectData.SetProjectError(ex);
|
|
ProjectData.ClearProjectError();
|
|
}
|
|
}
|
|
|
|
protected void OnDavCopyCompleted(AsyncCompletedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
this.pWorkerState = 0;
|
|
this.pFS.ResetConnection();
|
|
AsyncCompletedEventHandler copyCompletedEvent = this.CopyCompleted;
|
|
if (copyCompletedEvent == null)
|
|
return;
|
|
copyCompletedEvent((object) null, e);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ProjectData.SetProjectError(ex);
|
|
int num = (int) MessageBox.Show("Error\r\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
|
|
ProjectData.ClearProjectError();
|
|
}
|
|
}
|
|
|
|
public AsyncCopy.StateContainer GetState()
|
|
{
|
|
AsyncCopy.StateContainer stateContainer = new AsyncCopy.StateContainer();
|
|
stateContainer.CurrentState = this.pCurrentState;
|
|
stateContainer.TotalCost = this.pTotalCost;
|
|
stateContainer.TotalProgress = this.pTotalProgress;
|
|
stateContainer.TotalSeconds = this.pTotalTransferSeconds;
|
|
stateContainer.CurrentCost = this.pCurrentCost;
|
|
stateContainer.CurrentProgress = this.pCurrentProgress;
|
|
stateContainer.CurrentSeconds = this.pCurrentSeconds;
|
|
stateContainer.CurrentDesc = this.pCurrentDesc;
|
|
stateContainer.TotalFiles = this.pTotalFiles;
|
|
stateContainer.CurrentFiles = this.pCurrentFiles;
|
|
stateContainer.TotalFolders = this.pTotalFolders;
|
|
stateContainer.CurrentFolders = this.pCurrentFolders;
|
|
if (stateContainer.CurrentProgress >= 0L && stateContainer.TotalProgress >= 0L)
|
|
stateContainer.TotalProgress = checked (stateContainer.TotalProgress + stateContainer.CurrentProgress);
|
|
if (stateContainer.TotalSeconds >= 0.0 && stateContainer.CurrentSeconds >= 0.0)
|
|
stateContainer.TotalSeconds = stateContainer.TotalSeconds + stateContainer.CurrentSeconds;
|
|
return stateContainer;
|
|
}
|
|
|
|
private void Worker(AsyncOperation asyncop)
|
|
{
|
|
this.pLastException = (Exception) null;
|
|
this.pAsyncOp = asyncop;
|
|
try
|
|
{
|
|
while (true)
|
|
{
|
|
if (this.pWorkerState == 2)
|
|
this.pCancelled = true;
|
|
if (this.pStopAfterFile)
|
|
this.pCancelled = true;
|
|
if (!this.pCancelled)
|
|
{
|
|
long num1 = 0;
|
|
long num2 = 0;
|
|
double num3 = 0.0;
|
|
long num4 = 0;
|
|
long num5 = 0;
|
|
long num6 = 0;
|
|
long num7 = 0;
|
|
object pLock = this.pLock;
|
|
ObjectFlowControl.CheckForSyncLockOnValueType(pLock);
|
|
Monitor.Enter(pLock);
|
|
try
|
|
{
|
|
LinkedList<AsyncCopy.DavCopyTask>.Enumerator enumerator = this.pTaskList.GetEnumerator();
|
|
try
|
|
{
|
|
while (enumerator.MoveNext())
|
|
{
|
|
AsyncCopy.DavCopyTask current = enumerator.Current;
|
|
if (current.State != AsyncCopy.TaskStateType.ErrorIgnore && current.State != AsyncCopy.TaskStateType.Skipped)
|
|
{
|
|
if (current.Size < 0L || num1 < 0L)
|
|
num1 = -1L;
|
|
else
|
|
checked { num1 += current.Size; }
|
|
if (current.IsCollection)
|
|
checked { ++num5; }
|
|
else
|
|
checked { ++num4; }
|
|
if (current.State == AsyncCopy.TaskStateType.Complete)
|
|
{
|
|
if (current.Size < 0L || num2 < 0L)
|
|
num2 = -1L;
|
|
else
|
|
checked { num2 += current.Size; }
|
|
if (current.IsCollection)
|
|
checked { ++num7; }
|
|
else
|
|
checked { ++num6; }
|
|
num3 += current.TransferSeconds;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
enumerator.Dispose();
|
|
}
|
|
this.pTotalCost = num1;
|
|
this.pTotalProgress = num2;
|
|
this.pTotalTransferSeconds = num3;
|
|
this.pTotalFiles = num4;
|
|
this.pTotalFolders = num5;
|
|
this.pCurrentFiles = num6;
|
|
this.pCurrentFolders = num7;
|
|
}
|
|
finally
|
|
{
|
|
Monitor.Exit(pLock);
|
|
}
|
|
AsyncCopy.DavCopyTask task = this.Worker_GetTask();
|
|
if (task != null)
|
|
{
|
|
switch (task.TaskType)
|
|
{
|
|
case AsyncCopy.TaskType.Download:
|
|
switch (task.State)
|
|
{
|
|
case AsyncCopy.TaskStateType.Initialized:
|
|
this.Worker_Download_GetProperty(task);
|
|
continue;
|
|
case AsyncCopy.TaskStateType.PropertyAcquired:
|
|
if (task.IsCollection)
|
|
{
|
|
this.Worker_Download_ConfirmFolder(task);
|
|
continue;
|
|
}
|
|
this.Worker_Download_DownloadFile(task);
|
|
continue;
|
|
case AsyncCopy.TaskStateType.FolderConfirmed:
|
|
this.Worker_Download_SetFolderProperty(task);
|
|
continue;
|
|
default:
|
|
goto label_35;
|
|
}
|
|
case AsyncCopy.TaskType.Upload:
|
|
switch (task.State)
|
|
{
|
|
case AsyncCopy.TaskStateType.Initialized:
|
|
this.Worker_Upload_GetProperty(task);
|
|
continue;
|
|
case AsyncCopy.TaskStateType.PropertyAcquired:
|
|
if (task.IsCollection)
|
|
{
|
|
this.Worker_Upload_ConfirmFolder(task);
|
|
continue;
|
|
}
|
|
this.Worker_Upload_UploadFile(task);
|
|
continue;
|
|
case AsyncCopy.TaskStateType.FolderConfirmed:
|
|
this.Worker_Upload_SetFolderProperty(task);
|
|
continue;
|
|
default:
|
|
goto label_42;
|
|
}
|
|
default:
|
|
goto label_43;
|
|
}
|
|
}
|
|
else
|
|
goto label_45;
|
|
}
|
|
else
|
|
goto label_45;
|
|
}
|
|
label_35:
|
|
throw new Exception();
|
|
label_42:
|
|
throw new Exception();
|
|
label_43:
|
|
throw new Exception();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ProjectData.SetProjectError(ex);
|
|
this.pLastException = ex;
|
|
ProjectData.ClearProjectError();
|
|
}
|
|
label_45:
|
|
this.pAsyncOp.PostOperationCompleted(this.pCompleteCallback, (object) new AsyncCompletedEventArgs(this.pLastException, this.pCancelled, (object) null));
|
|
}
|
|
|
|
private AsyncCopy.DavCopyTask Worker_GetTask()
|
|
{
|
|
object pLock = this.pLock;
|
|
ObjectFlowControl.CheckForSyncLockOnValueType(pLock);
|
|
Monitor.Enter(pLock);
|
|
try
|
|
{
|
|
LinkedList<AsyncCopy.DavCopyTask>.Enumerator enumerator1 = this.pTaskList.GetEnumerator();
|
|
try
|
|
{
|
|
while (enumerator1.MoveNext())
|
|
{
|
|
AsyncCopy.DavCopyTask current = enumerator1.Current;
|
|
if (current.State == AsyncCopy.TaskStateType.Initialized)
|
|
return current;
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
enumerator1.Dispose();
|
|
}
|
|
LinkedList<AsyncCopy.DavCopyTask>.Enumerator enumerator2 = this.pTaskList.GetEnumerator();
|
|
try
|
|
{
|
|
while (enumerator2.MoveNext())
|
|
{
|
|
AsyncCopy.DavCopyTask davCopyTask1 = enumerator2.Current;
|
|
if (davCopyTask1.IsRootTask)
|
|
{
|
|
if (davCopyTask1.State == AsyncCopy.TaskStateType.PropertyAcquired)
|
|
return davCopyTask1;
|
|
if (davCopyTask1.State == AsyncCopy.TaskStateType.FolderConfirmed)
|
|
{
|
|
label_11:
|
|
AsyncCopy.DavCopyTask[] subTasks1 = davCopyTask1.SubTasks;
|
|
int index1 = 0;
|
|
while (index1 < subTasks1.Length)
|
|
{
|
|
AsyncCopy.DavCopyTask davCopyTask2 = subTasks1[index1];
|
|
if (!davCopyTask2.IsCollection && davCopyTask2.State == AsyncCopy.TaskStateType.PropertyAcquired)
|
|
return davCopyTask2;
|
|
checked { ++index1; }
|
|
}
|
|
AsyncCopy.DavCopyTask[] subTasks2 = davCopyTask1.SubTasks;
|
|
int index2 = 0;
|
|
while (index2 < subTasks2.Length)
|
|
{
|
|
AsyncCopy.DavCopyTask davCopyTask2 = subTasks2[index2];
|
|
if (davCopyTask2.State == AsyncCopy.TaskStateType.FolderConfirmed)
|
|
{
|
|
davCopyTask1 = davCopyTask2;
|
|
goto label_11;
|
|
}
|
|
else
|
|
checked { ++index2; }
|
|
}
|
|
AsyncCopy.DavCopyTask[] subTasks3 = davCopyTask1.SubTasks;
|
|
int index3 = 0;
|
|
while (index3 < subTasks3.Length)
|
|
{
|
|
AsyncCopy.DavCopyTask davCopyTask2 = subTasks3[index3];
|
|
if (davCopyTask2.State == AsyncCopy.TaskStateType.PropertyAcquired)
|
|
return davCopyTask2;
|
|
checked { ++index3; }
|
|
}
|
|
return davCopyTask1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
enumerator2.Dispose();
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
Monitor.Exit(pLock);
|
|
}
|
|
return (AsyncCopy.DavCopyTask) null;
|
|
}
|
|
|
|
private void Worker_Download_GetProperty(AsyncCopy.DavCopyTask task)
|
|
{
|
|
int retryminutes = 1;
|
|
this.pCurrentState = AsyncCopy.DavCopyStateType.DownloadProperty;
|
|
this.pCurrentCost = -1L;
|
|
this.pCurrentProgress = 0L;
|
|
this.pCurrentDesc = task.GetDownloadFileName();
|
|
ResourceInfo[] resourceInfoArray;
|
|
while (true)
|
|
{
|
|
try
|
|
{
|
|
resourceInfoArray = !task.IsRootTask ? this.pCache.GetEntries(this.pFS, task.RemoteId, false) : this.pCache.GetInfoAndEntries(this.pFS, task.RemoteId, false);
|
|
break;
|
|
}
|
|
catch (Exception ex1)
|
|
{
|
|
ProjectData.SetProjectError(ex1);
|
|
Exception ex2 = ex1;
|
|
this.pFS.ResetConnection();
|
|
ExceptionOccurredEventArgs e = new ExceptionOccurredEventArgs("Error occurred during downloading property.", task.GetDownloadFileName(), ErrorPromptType.IgnoreAllIgnoreRetryCancel, ex2, retryminutes);
|
|
EventHandler<ExceptionOccurredEventArgs> exceptionOccurredEvent = this.ExceptionOccurred;
|
|
if (exceptionOccurredEvent != null)
|
|
exceptionOccurredEvent((object) this, e);
|
|
switch (e.Result.Action)
|
|
{
|
|
case ErrorAction.Ignore:
|
|
task.State = AsyncCopy.TaskStateType.ErrorIgnore;
|
|
ProjectData.ClearProjectError();
|
|
return;
|
|
case ErrorAction.Retry:
|
|
ProjectData.ClearProjectError();
|
|
continue;
|
|
case ErrorAction.AutoRetry:
|
|
checked { retryminutes *= 2; }
|
|
ProjectData.ClearProjectError();
|
|
continue;
|
|
case ErrorAction.Cancel:
|
|
this.pCancelled = true;
|
|
ProjectData.ClearProjectError();
|
|
return;
|
|
default:
|
|
ProjectData.ClearProjectError();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
if (task.IsRootTask)
|
|
{
|
|
task.RemoteId = resourceInfoArray[0].Id;
|
|
task.UriDic.Add(resourceInfoArray[0].Id.Uri, true);
|
|
task.Info = resourceInfoArray[0];
|
|
task.LastModifiedTime = resourceInfoArray[0].LastModifiedTime;
|
|
task.IsCollection = resourceInfoArray[0].IsCollection;
|
|
task.CreationDate = resourceInfoArray[0].CreationTime;
|
|
task.LastAccessTime = resourceInfoArray[0].LastAccessTime;
|
|
task.Size = !task.IsCollection ? resourceInfoArray[0].Size : 0L;
|
|
}
|
|
task.State = AsyncCopy.TaskStateType.PropertyAcquired;
|
|
int num1 = 0;
|
|
int num2 = checked (resourceInfoArray.Length - 1);
|
|
int index = num1;
|
|
while (index <= num2)
|
|
{
|
|
if (!task.UriDic.ContainsKey(resourceInfoArray[index].Id.Uri))
|
|
{
|
|
task.UriDic.Add(resourceInfoArray[index].Id.Uri, true);
|
|
object pLock = this.pLock;
|
|
ObjectFlowControl.CheckForSyncLockOnValueType(pLock);
|
|
Monitor.Enter(pLock);
|
|
try
|
|
{
|
|
AsyncCopy.DavCopyTask davCopyTask = new AsyncCopy.DavCopyTask(task, resourceInfoArray[index].Id);
|
|
davCopyTask.Info = resourceInfoArray[index];
|
|
davCopyTask.LastModifiedTime = resourceInfoArray[index].LastModifiedTime;
|
|
davCopyTask.IsCollection = resourceInfoArray[index].IsCollection;
|
|
davCopyTask.CreationDate = resourceInfoArray[index].CreationTime;
|
|
davCopyTask.LastAccessTime = resourceInfoArray[index].LastAccessTime;
|
|
davCopyTask.Size = !davCopyTask.IsCollection ? resourceInfoArray[index].Size : 0L;
|
|
if (!davCopyTask.IsCollection)
|
|
davCopyTask.State = AsyncCopy.TaskStateType.PropertyAcquired;
|
|
this.pTaskList.AddLast(davCopyTask);
|
|
}
|
|
finally
|
|
{
|
|
Monitor.Exit(pLock);
|
|
}
|
|
}
|
|
checked { ++index; }
|
|
}
|
|
}
|
|
|
|
private void Worker_Download_ConfirmFolder(AsyncCopy.DavCopyTask task)
|
|
{
|
|
int namecount = 0;
|
|
int retryminutes = 1;
|
|
while (true)
|
|
{
|
|
string path2 = task.CalcLocalPathForDownload(this.pDownloadFilenameNormalization, namecount);
|
|
string str = Path.Combine(task.BaseLocalPath, path2);
|
|
this.pCurrentState = AsyncCopy.DavCopyStateType.ConfirmFolder;
|
|
this.pCurrentCost = -1L;
|
|
this.pCurrentProgress = 0L;
|
|
this.pCurrentDesc = task.GetDownloadFileName();
|
|
try
|
|
{
|
|
SimpleResourceInfo localFileInfo = SimpleResourceInfo.CreateLocalFileInfo(str);
|
|
ConflictType type;
|
|
if (localFileInfo == null)
|
|
{
|
|
type = ConflictType.NoConfliction;
|
|
}
|
|
else
|
|
{
|
|
if (namecount > 0)
|
|
{
|
|
checked { ++namecount; }
|
|
continue;
|
|
}
|
|
type = !localFileInfo.IsCollection ? ConflictType.FolderToFile : ConflictType.FolderToFolder;
|
|
}
|
|
ConflictAction conflictAction;
|
|
if (type == ConflictType.NoConfliction)
|
|
{
|
|
conflictAction = ConflictAction.NoConfliction;
|
|
}
|
|
else
|
|
{
|
|
AsyncCopy.CopyConflictedEventArgs e = new AsyncCopy.CopyConflictedEventArgs(new SimpleResourceInfo(task.GetDownloadFileName(), task.Size, task.LastModifiedTime, true), localFileInfo, type, (this.pFS.Ability & FsAbility.PartialRead) != FsAbility.None, FsAbility.All, retryminutes);
|
|
EventHandler<AsyncCopy.CopyConflictedEventArgs> conflictionOccurredEvent = this.ConflictionOccurred;
|
|
if (conflictionOccurredEvent != null)
|
|
conflictionOccurredEvent((object) this, e);
|
|
conflictAction = e.Result.Action;
|
|
}
|
|
switch (conflictAction)
|
|
{
|
|
case ConflictAction.NoConfliction:
|
|
Directory.CreateDirectory(str);
|
|
goto case ConflictAction.Integrate;
|
|
case ConflictAction.Integrate:
|
|
task.LocalPath = str;
|
|
task.State = AsyncCopy.TaskStateType.FolderConfirmed;
|
|
return;
|
|
case ConflictAction.DeleteTarget:
|
|
if (type == ConflictType.FileToFile)
|
|
File.Delete(str);
|
|
else
|
|
Directory.Delete(str, true);
|
|
Directory.CreateDirectory(str);
|
|
goto case ConflictAction.Integrate;
|
|
case ConflictAction.Retry:
|
|
continue;
|
|
case ConflictAction.AutoRetry:
|
|
checked { retryminutes *= 2; }
|
|
continue;
|
|
case ConflictAction.ChangeName:
|
|
checked { ++namecount; }
|
|
continue;
|
|
case ConflictAction.Skip:
|
|
LinkedList<AsyncCopy.DavCopyTask> linkedList = new LinkedList<AsyncCopy.DavCopyTask>();
|
|
linkedList.AddFirst(task);
|
|
while (linkedList.Count > 0)
|
|
{
|
|
AsyncCopy.DavCopyTask davCopyTask1 = linkedList.First.Value;
|
|
linkedList.RemoveFirst();
|
|
davCopyTask1.State = AsyncCopy.TaskStateType.Skipped;
|
|
AsyncCopy.DavCopyTask[] subTasks = davCopyTask1.SubTasks;
|
|
int index = 0;
|
|
while (index < subTasks.Length)
|
|
{
|
|
AsyncCopy.DavCopyTask davCopyTask2 = subTasks[index];
|
|
linkedList.AddLast(davCopyTask2);
|
|
checked { ++index; }
|
|
}
|
|
}
|
|
return;
|
|
case ConflictAction.CancelAll:
|
|
this.pCancelled = true;
|
|
return;
|
|
default:
|
|
throw new InvalidOperationException();
|
|
}
|
|
}
|
|
catch (Exception ex1)
|
|
{
|
|
ProjectData.SetProjectError(ex1);
|
|
Exception ex2 = ex1;
|
|
ExceptionOccurredEventArgs e = new ExceptionOccurredEventArgs("Error occurred during confirming folder property.", str, ErrorPromptType.IgnoreAllIgnoreRetryCancel, ex2, retryminutes);
|
|
EventHandler<ExceptionOccurredEventArgs> exceptionOccurredEvent = this.ExceptionOccurred;
|
|
if (exceptionOccurredEvent != null)
|
|
exceptionOccurredEvent((object) this, e);
|
|
switch (e.Result.Action)
|
|
{
|
|
case ErrorAction.Ignore:
|
|
LinkedList<AsyncCopy.DavCopyTask> linkedList = new LinkedList<AsyncCopy.DavCopyTask>();
|
|
linkedList.AddLast(task);
|
|
while (linkedList.Count > 0)
|
|
{
|
|
AsyncCopy.DavCopyTask davCopyTask1 = linkedList.First.Value;
|
|
linkedList.RemoveFirst();
|
|
davCopyTask1.State = AsyncCopy.TaskStateType.ErrorIgnore;
|
|
AsyncCopy.DavCopyTask[] subTasks = davCopyTask1.SubTasks;
|
|
int index = 0;
|
|
while (index < subTasks.Length)
|
|
{
|
|
AsyncCopy.DavCopyTask davCopyTask2 = subTasks[index];
|
|
linkedList.AddLast(davCopyTask2);
|
|
checked { ++index; }
|
|
}
|
|
}
|
|
ProjectData.ClearProjectError();
|
|
return;
|
|
case ErrorAction.Retry:
|
|
namecount = 0;
|
|
ProjectData.ClearProjectError();
|
|
continue;
|
|
case ErrorAction.AutoRetry:
|
|
namecount = 0;
|
|
checked { retryminutes *= 2; }
|
|
ProjectData.ClearProjectError();
|
|
continue;
|
|
case ErrorAction.Cancel:
|
|
this.pCancelled = true;
|
|
ProjectData.ClearProjectError();
|
|
return;
|
|
default:
|
|
ProjectData.ClearProjectError();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Worker_Download_DownloadFile(AsyncCopy.DavCopyTask task)
|
|
{
|
|
int namecount = 0;
|
|
int retryminutes = 1;
|
|
while (true)
|
|
{
|
|
string path2 = task.CalcLocalPathForDownload(this.pDownloadFilenameNormalization, namecount);
|
|
string path = Path.Combine(task.BaseLocalPath, path2);
|
|
this.pCurrentState = AsyncCopy.DavCopyStateType.ConfirmFile;
|
|
this.pCurrentCost = -1L;
|
|
this.pCurrentProgress = 0L;
|
|
this.pCurrentDesc = task.GetDownloadFileName();
|
|
try
|
|
{
|
|
long start = 0;
|
|
SimpleResourceInfo localFileInfo = SimpleResourceInfo.CreateLocalFileInfo(path);
|
|
ConflictType type;
|
|
if (localFileInfo == null)
|
|
{
|
|
type = ConflictType.NoConfliction;
|
|
}
|
|
else
|
|
{
|
|
if (namecount > 0)
|
|
{
|
|
checked { ++namecount; }
|
|
continue;
|
|
}
|
|
type = !localFileInfo.IsCollection ? ConflictType.FileToFile : ConflictType.FileToFolder;
|
|
}
|
|
ConflictAction conflictAction;
|
|
if (type == ConflictType.NoConfliction)
|
|
{
|
|
conflictAction = ConflictAction.NoConfliction;
|
|
}
|
|
else
|
|
{
|
|
AsyncCopy.CopyConflictedEventArgs e = new AsyncCopy.CopyConflictedEventArgs(new SimpleResourceInfo(task.GetDownloadFileName(), task.Size, task.LastModifiedTime, false), localFileInfo, type, (this.pFS.Ability & FsAbility.PartialRead) != FsAbility.None, FsAbility.All, retryminutes);
|
|
EventHandler<AsyncCopy.CopyConflictedEventArgs> conflictionOccurredEvent = this.ConflictionOccurred;
|
|
if (conflictionOccurredEvent != null)
|
|
conflictionOccurredEvent((object) this, e);
|
|
conflictAction = e.Result.Action;
|
|
}
|
|
switch (conflictAction)
|
|
{
|
|
case ConflictAction.NoConfliction:
|
|
case ConflictAction.Overwrite:
|
|
task.LocalPath = path;
|
|
byte[] buffer = new byte[65536];
|
|
DateTime now = DateTime.Now;
|
|
this.pCurrentCost = task.Size;
|
|
this.pCurrentProgress = 0L;
|
|
this.pCurrentState = AsyncCopy.DavCopyStateType.DownloadFile;
|
|
CacheManager pCache = this.pCache;
|
|
FsBase pFs = this.pFS;
|
|
ResourceId remoteId = task.RemoteId;
|
|
long length = -1;
|
|
using (Stream stream1 = pCache.OpenRead(pFs, remoteId, ref start, ref length))
|
|
{
|
|
using (Stream stream2 = (Stream) File.OpenWrite(task.LocalPath))
|
|
{
|
|
if (start > 0L)
|
|
{
|
|
stream2.Seek(start, SeekOrigin.Begin);
|
|
if (task.Size >= 0L)
|
|
this.pCurrentCost = checked (task.Size - start);
|
|
}
|
|
while (true)
|
|
{
|
|
object pLock = this.pLock;
|
|
ObjectFlowControl.CheckForSyncLockOnValueType(pLock);
|
|
Monitor.Enter(pLock);
|
|
try
|
|
{
|
|
if (this.pWorkerState == 2)
|
|
{
|
|
this.pCancelled = true;
|
|
stream1.Close();
|
|
throw new Exception();
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
Monitor.Exit(pLock);
|
|
}
|
|
int count = stream1.Read(buffer, 0, buffer.Length);
|
|
if (count != 0)
|
|
{
|
|
stream2.Write(buffer, 0, count);
|
|
this.pCurrentProgress = checked (this.pCurrentProgress + (long) count);
|
|
this.pCurrentSeconds = DateTime.Now.Subtract(now).TotalSeconds;
|
|
}
|
|
else
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
this.SetTimes(task.LocalPath, task.LastModifiedTime, task.CreationDate, task.LastAccessTime);
|
|
if (this.pCurrentCost >= 0L)
|
|
{
|
|
if (this.pCurrentProgress < this.pCurrentCost)
|
|
throw new ApplicationException("Cannot receive whole contents. Resource may be changed.");
|
|
if (this.pCurrentProgress > this.pCurrentCost)
|
|
throw new ApplicationException("Received stream is too long. Resource may be changed.");
|
|
}
|
|
task.State = AsyncCopy.TaskStateType.Complete;
|
|
goto label_62;
|
|
case ConflictAction.OverwriteNewer:
|
|
if (DateTime.Compare(File.GetLastWriteTime(path), task.Info.LastModifiedTime) >= 0)
|
|
{
|
|
task.State = AsyncCopy.TaskStateType.Skipped;
|
|
goto label_62;
|
|
}
|
|
else
|
|
goto case ConflictAction.NoConfliction;
|
|
case ConflictAction.Resume:
|
|
if (localFileInfo.Size < 0L || task.Size < 0L)
|
|
throw new InvalidOperationException("Cannot Resume.");
|
|
if (localFileInfo.Size >= task.Size)
|
|
{
|
|
task.State = AsyncCopy.TaskStateType.Skipped;
|
|
goto label_62;
|
|
}
|
|
else
|
|
{
|
|
start = localFileInfo.Size;
|
|
goto case ConflictAction.NoConfliction;
|
|
}
|
|
case ConflictAction.DeleteTarget:
|
|
if (type == ConflictType.FileToFile)
|
|
{
|
|
File.Delete(path);
|
|
goto case ConflictAction.NoConfliction;
|
|
}
|
|
else
|
|
{
|
|
Directory.Delete(path, true);
|
|
goto case ConflictAction.NoConfliction;
|
|
}
|
|
case ConflictAction.Retry:
|
|
continue;
|
|
case ConflictAction.AutoRetry:
|
|
checked { retryminutes *= 2; }
|
|
continue;
|
|
case ConflictAction.ChangeName:
|
|
checked { ++namecount; }
|
|
continue;
|
|
case ConflictAction.Skip:
|
|
task.State = AsyncCopy.TaskStateType.Skipped;
|
|
goto label_62;
|
|
case ConflictAction.CancelAll:
|
|
this.pCancelled = true;
|
|
return;
|
|
default:
|
|
throw new InvalidOperationException();
|
|
}
|
|
}
|
|
catch (Exception ex1)
|
|
{
|
|
ProjectData.SetProjectError(ex1);
|
|
Exception ex2 = ex1;
|
|
this.pFS.ResetConnection();
|
|
if (this.pCancelled)
|
|
{
|
|
ProjectData.ClearProjectError();
|
|
return;
|
|
}
|
|
ExceptionOccurredEventArgs e = new ExceptionOccurredEventArgs("Error occurred during downloading file.", task.RemoteId.Uri, ErrorPromptType.IgnoreAllIgnoreRetryCancel, ex2, retryminutes);
|
|
EventHandler<ExceptionOccurredEventArgs> exceptionOccurredEvent = this.ExceptionOccurred;
|
|
if (exceptionOccurredEvent != null)
|
|
exceptionOccurredEvent((object) this, e);
|
|
switch (e.Result.Action)
|
|
{
|
|
case ErrorAction.Ignore:
|
|
task.State = AsyncCopy.TaskStateType.ErrorIgnore;
|
|
ProjectData.ClearProjectError();
|
|
return;
|
|
case ErrorAction.Retry:
|
|
ProjectData.ClearProjectError();
|
|
continue;
|
|
case ErrorAction.AutoRetry:
|
|
checked { retryminutes *= 2; }
|
|
ProjectData.ClearProjectError();
|
|
continue;
|
|
case ErrorAction.Cancel:
|
|
this.pCancelled = true;
|
|
ProjectData.ClearProjectError();
|
|
return;
|
|
default:
|
|
ProjectData.ClearProjectError();
|
|
goto label_62;
|
|
}
|
|
}
|
|
}
|
|
label_62:
|
|
task.TransferSeconds = this.pCurrentSeconds;
|
|
this.pTotalTransferSeconds = this.pTotalTransferSeconds + this.pCurrentSeconds;
|
|
this.pCurrentSeconds = 0.0;
|
|
if (task.State == AsyncCopy.TaskStateType.Skipped)
|
|
{
|
|
this.pCurrentProgress = 0L;
|
|
this.pCurrentCost = 0L;
|
|
}
|
|
else
|
|
{
|
|
if (this.pTotalProgress < 0L)
|
|
return;
|
|
this.pTotalProgress = checked (this.pTotalProgress + this.pCurrentProgress);
|
|
this.pCurrentProgress = 0L;
|
|
}
|
|
}
|
|
|
|
private void Worker_Download_SetFolderProperty(AsyncCopy.DavCopyTask task)
|
|
{
|
|
int retryminutes = 1;
|
|
this.pCurrentState = AsyncCopy.DavCopyStateType.SetFolderAttribute;
|
|
this.pCurrentCost = -1L;
|
|
this.pCurrentProgress = 0L;
|
|
this.pCurrentDesc = task.GetDownloadFileName();
|
|
while (true)
|
|
{
|
|
try
|
|
{
|
|
this.SetTimes(task.LocalPath, task.LastModifiedTime, task.CreationDate, task.LastAccessTime);
|
|
task.State = AsyncCopy.TaskStateType.Complete;
|
|
break;
|
|
}
|
|
catch (Exception ex1)
|
|
{
|
|
ProjectData.SetProjectError(ex1);
|
|
Exception ex2 = ex1;
|
|
ExceptionOccurredEventArgs e = new ExceptionOccurredEventArgs("Error occurred during updating folder property.", task.LocalPath, ErrorPromptType.IgnoreAllIgnoreRetryCancel, ex2, retryminutes);
|
|
EventHandler<ExceptionOccurredEventArgs> exceptionOccurredEvent = this.ExceptionOccurred;
|
|
if (exceptionOccurredEvent != null)
|
|
exceptionOccurredEvent((object) this, e);
|
|
switch (e.Result.Action)
|
|
{
|
|
case ErrorAction.Ignore:
|
|
task.State = AsyncCopy.TaskStateType.ErrorIgnore;
|
|
ProjectData.ClearProjectError();
|
|
return;
|
|
case ErrorAction.Retry:
|
|
ProjectData.ClearProjectError();
|
|
continue;
|
|
case ErrorAction.AutoRetry:
|
|
checked { retryminutes *= 2; }
|
|
ProjectData.ClearProjectError();
|
|
continue;
|
|
case ErrorAction.Cancel:
|
|
this.pCancelled = true;
|
|
ProjectData.ClearProjectError();
|
|
return;
|
|
default:
|
|
ProjectData.ClearProjectError();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Worker_Upload_GetProperty(AsyncCopy.DavCopyTask task)
|
|
{
|
|
int retryminutes = 1;
|
|
while (true)
|
|
{
|
|
this.pCurrentCost = -1L;
|
|
this.pCurrentProgress = 0L;
|
|
this.pCurrentState = AsyncCopy.DavCopyStateType.SearchDirectory;
|
|
this.pCurrentDesc = task.LocalPath;
|
|
try
|
|
{
|
|
if (task.VirtualFileInfo != null)
|
|
{
|
|
if ((task.VirtualFileInfo.Flags & FDFlags.FD_CREATETIME) != (FDFlags) 0)
|
|
task.CreationDate = task.VirtualFileInfo.CreationTime;
|
|
if ((task.VirtualFileInfo.Flags & FDFlags.FD_ACCESSTIME) != (FDFlags) 0)
|
|
task.LastAccessTime = task.VirtualFileInfo.LastAccessTime;
|
|
if ((task.VirtualFileInfo.Flags & FDFlags.FD_WRITESTIME) != (FDFlags) 0)
|
|
task.LastModifiedTime = task.VirtualFileInfo.LastWriteTime;
|
|
task.Size = (task.VirtualFileInfo.Flags & FDFlags.FD_FILESIZE) == (FDFlags) 0 ? -1L : checked ((long) task.VirtualFileInfo.FileSize);
|
|
task.IsCollection = task.VirtualFileInfo.IStreamCreator == null;
|
|
task.State = AsyncCopy.TaskStateType.PropertyAcquired;
|
|
break;
|
|
}
|
|
if (File.Exists(task.LocalPath))
|
|
{
|
|
System.IO.FileInfo fileInfo = new System.IO.FileInfo(task.LocalPath);
|
|
task.Size = fileInfo.Length;
|
|
task.LastModifiedTime = fileInfo.LastWriteTime;
|
|
task.IsCollection = false;
|
|
task.CreationDate = fileInfo.CreationTime;
|
|
task.LastAccessTime = fileInfo.LastAccessTime;
|
|
task.State = AsyncCopy.TaskStateType.PropertyAcquired;
|
|
break;
|
|
}
|
|
if (Directory.Exists(task.LocalPath))
|
|
{
|
|
DirectoryInfo directoryInfo = new DirectoryInfo(task.LocalPath);
|
|
task.Size = 0L;
|
|
task.LastModifiedTime = directoryInfo.LastWriteTime;
|
|
task.IsCollection = true;
|
|
task.CreationDate = directoryInfo.CreationTime;
|
|
task.LastAccessTime = directoryInfo.LastAccessTime;
|
|
task.State = AsyncCopy.TaskStateType.PropertyAcquired;
|
|
FileSystemInfo[] fileSystemInfos = directoryInfo.GetFileSystemInfos();
|
|
int index = 0;
|
|
while (index < fileSystemInfos.Length)
|
|
{
|
|
FileSystemInfo fileSystemInfo = fileSystemInfos[index];
|
|
object pLock = this.pLock;
|
|
ObjectFlowControl.CheckForSyncLockOnValueType(pLock);
|
|
Monitor.Enter(pLock);
|
|
try
|
|
{
|
|
this.pTaskList.AddLast(new AsyncCopy.DavCopyTask(task, fileSystemInfo.FullName));
|
|
}
|
|
finally
|
|
{
|
|
Monitor.Exit(pLock);
|
|
}
|
|
checked { ++index; }
|
|
}
|
|
break;
|
|
}
|
|
task.State = AsyncCopy.TaskStateType.Skipped;
|
|
break;
|
|
}
|
|
catch (Exception ex1)
|
|
{
|
|
ProjectData.SetProjectError(ex1);
|
|
Exception ex2 = ex1;
|
|
ExceptionOccurredEventArgs e = new ExceptionOccurredEventArgs("Error occurred during reading file property.", task.LocalPath, ErrorPromptType.IgnoreAllIgnoreRetryCancel, ex2, retryminutes);
|
|
EventHandler<ExceptionOccurredEventArgs> exceptionOccurredEvent = this.ExceptionOccurred;
|
|
if (exceptionOccurredEvent != null)
|
|
exceptionOccurredEvent((object) this, e);
|
|
switch (e.Result.Action)
|
|
{
|
|
case ErrorAction.Ignore:
|
|
task.State = AsyncCopy.TaskStateType.ErrorIgnore;
|
|
ProjectData.ClearProjectError();
|
|
return;
|
|
case ErrorAction.Retry:
|
|
ProjectData.ClearProjectError();
|
|
continue;
|
|
case ErrorAction.AutoRetry:
|
|
checked { retryminutes *= 2; }
|
|
ProjectData.ClearProjectError();
|
|
continue;
|
|
case ErrorAction.Cancel:
|
|
this.pCancelled = true;
|
|
ProjectData.ClearProjectError();
|
|
return;
|
|
default:
|
|
ProjectData.ClearProjectError();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Worker_Upload_ConfirmFolder(AsyncCopy.DavCopyTask task)
|
|
{
|
|
int namecount = 0;
|
|
int retryminutes = 1;
|
|
while (true)
|
|
{
|
|
string name = task.CalcRemoteUriForUpload(this.pUploadFilenameNormalization, namecount);
|
|
this.pCurrentCost = -1L;
|
|
this.pCurrentProgress = 0L;
|
|
this.pCurrentState = AsyncCopy.DavCopyStateType.MakingCollection;
|
|
this.pCurrentDesc = task.GetUploadFileName(name);
|
|
try
|
|
{
|
|
ResourceInfo ri;
|
|
try
|
|
{
|
|
ri = this.pCache.GetInfo(this.pFS, task.BaseRemoteId, name, false);
|
|
}
|
|
catch (RemoteResourceNotFoundException ex)
|
|
{
|
|
ProjectData.SetProjectError((Exception) ex);
|
|
ri = (ResourceInfo) null;
|
|
ProjectData.ClearProjectError();
|
|
}
|
|
ConflictType type;
|
|
ResourceId resourceId;
|
|
if (ri == null)
|
|
{
|
|
type = ConflictType.NoConfliction;
|
|
resourceId = (ResourceId) null;
|
|
}
|
|
else
|
|
{
|
|
if (namecount > 0)
|
|
{
|
|
checked { ++namecount; }
|
|
continue;
|
|
}
|
|
if (ri.IsCollection)
|
|
{
|
|
type = ConflictType.FolderToFolder;
|
|
resourceId = ri.Id;
|
|
}
|
|
else
|
|
{
|
|
type = ConflictType.FolderToFile;
|
|
resourceId = ri.Id;
|
|
}
|
|
}
|
|
ConflictAction conflictAction;
|
|
if (type == ConflictType.NoConfliction)
|
|
{
|
|
conflictAction = ConflictAction.NoConfliction;
|
|
}
|
|
else
|
|
{
|
|
AsyncCopy.CopyConflictedEventArgs e = new AsyncCopy.CopyConflictedEventArgs(new SimpleResourceInfo(task.LocalPath, task.Size, task.LastModifiedTime, true), new SimpleResourceInfo(ri), type, (this.pFS.Ability & FsAbility.PartialWrite) != FsAbility.None, this.pFS.Ability, retryminutes);
|
|
EventHandler<AsyncCopy.CopyConflictedEventArgs> conflictionOccurredEvent = this.ConflictionOccurred;
|
|
if (conflictionOccurredEvent != null)
|
|
conflictionOccurredEvent((object) this, e);
|
|
conflictAction = e.Result.Action;
|
|
}
|
|
switch (conflictAction)
|
|
{
|
|
case ConflictAction.NoConfliction:
|
|
ReturnedInfo collection1 = this.pCache.CreateCollection(this.pFS, task.BaseRemoteId, name);
|
|
ResourceInfo resourceInfo1 = collection1 as ResourceInfo;
|
|
resourceId = resourceInfo1 == null ? (ResourceId) collection1 : resourceInfo1.Id;
|
|
goto case ConflictAction.Integrate;
|
|
case ConflictAction.Integrate:
|
|
task.RemoteId = resourceId;
|
|
task.State = AsyncCopy.TaskStateType.FolderConfirmed;
|
|
return;
|
|
case ConflictAction.DeleteTarget:
|
|
this.pCache.Delete(this.pFS, ri.Id);
|
|
ReturnedInfo collection2 = this.pCache.CreateCollection(this.pFS, task.BaseRemoteId, name);
|
|
ResourceInfo resourceInfo2 = collection2 as ResourceInfo;
|
|
resourceId = resourceInfo2 == null ? (ResourceId) collection2 : resourceInfo2.Id;
|
|
goto case ConflictAction.Integrate;
|
|
case ConflictAction.Retry:
|
|
continue;
|
|
case ConflictAction.AutoRetry:
|
|
checked { retryminutes *= 2; }
|
|
continue;
|
|
case ConflictAction.ChangeName:
|
|
checked { ++namecount; }
|
|
continue;
|
|
case ConflictAction.Skip:
|
|
LinkedList<AsyncCopy.DavCopyTask> linkedList = new LinkedList<AsyncCopy.DavCopyTask>();
|
|
linkedList.AddLast(task);
|
|
while (linkedList.Count > 0)
|
|
{
|
|
AsyncCopy.DavCopyTask davCopyTask1 = linkedList.First.Value;
|
|
linkedList.RemoveFirst();
|
|
davCopyTask1.State = AsyncCopy.TaskStateType.Skipped;
|
|
AsyncCopy.DavCopyTask[] subTasks = davCopyTask1.SubTasks;
|
|
int index = 0;
|
|
while (index < subTasks.Length)
|
|
{
|
|
AsyncCopy.DavCopyTask davCopyTask2 = subTasks[index];
|
|
linkedList.AddLast(davCopyTask2);
|
|
checked { ++index; }
|
|
}
|
|
}
|
|
return;
|
|
case ConflictAction.CancelAll:
|
|
this.pCancelled = true;
|
|
return;
|
|
default:
|
|
throw new InvalidOperationException();
|
|
}
|
|
}
|
|
catch (Exception ex1)
|
|
{
|
|
ProjectData.SetProjectError(ex1);
|
|
Exception ex2 = ex1;
|
|
this.pFS.ResetConnection();
|
|
ExceptionOccurredEventArgs e = new ExceptionOccurredEventArgs("Error occurred during confirming collection.", task.GetUploadFileName(name), ErrorPromptType.IgnoreAllIgnoreRetryCancel, ex2, retryminutes);
|
|
EventHandler<ExceptionOccurredEventArgs> exceptionOccurredEvent = this.ExceptionOccurred;
|
|
if (exceptionOccurredEvent != null)
|
|
exceptionOccurredEvent((object) this, e);
|
|
switch (e.Result.Action)
|
|
{
|
|
case ErrorAction.Ignore:
|
|
LinkedList<AsyncCopy.DavCopyTask> linkedList = new LinkedList<AsyncCopy.DavCopyTask>();
|
|
linkedList.AddLast(task);
|
|
while (linkedList.Count > 0)
|
|
{
|
|
AsyncCopy.DavCopyTask davCopyTask1 = linkedList.First.Value;
|
|
linkedList.RemoveFirst();
|
|
davCopyTask1.State = AsyncCopy.TaskStateType.ErrorIgnore;
|
|
AsyncCopy.DavCopyTask[] subTasks = davCopyTask1.SubTasks;
|
|
int index = 0;
|
|
while (index < subTasks.Length)
|
|
{
|
|
AsyncCopy.DavCopyTask davCopyTask2 = subTasks[index];
|
|
linkedList.AddLast(davCopyTask2);
|
|
checked { ++index; }
|
|
}
|
|
}
|
|
ProjectData.ClearProjectError();
|
|
return;
|
|
case ErrorAction.Retry:
|
|
namecount = 0;
|
|
ProjectData.ClearProjectError();
|
|
continue;
|
|
case ErrorAction.AutoRetry:
|
|
namecount = 0;
|
|
checked { retryminutes *= 2; }
|
|
ProjectData.ClearProjectError();
|
|
continue;
|
|
case ErrorAction.Cancel:
|
|
this.pCancelled = true;
|
|
ProjectData.ClearProjectError();
|
|
return;
|
|
default:
|
|
ProjectData.ClearProjectError();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Worker_Upload_UploadFile(AsyncCopy.DavCopyTask task)
|
|
{
|
|
int namecount = 0;
|
|
int retryminutes = 1;
|
|
while (true)
|
|
{
|
|
string name = task.CalcRemoteUriForUpload(this.pUploadFilenameNormalization, namecount);
|
|
this.pCurrentCost = -1L;
|
|
this.pCurrentProgress = 0L;
|
|
this.pCurrentState = AsyncCopy.DavCopyStateType.UploadFile;
|
|
this.pCurrentDesc = task.GetUploadFileName(name);
|
|
try
|
|
{
|
|
long start = 0;
|
|
ResourceInfo ri;
|
|
try
|
|
{
|
|
ri = this.pCache.GetInfo(this.pFS, task.BaseRemoteId, name, false);
|
|
}
|
|
catch (RemoteResourceNotFoundException ex)
|
|
{
|
|
ProjectData.SetProjectError((Exception) ex);
|
|
ri = (ResourceInfo) null;
|
|
ProjectData.ClearProjectError();
|
|
}
|
|
ConflictType type;
|
|
if (ri == null)
|
|
{
|
|
type = ConflictType.NoConfliction;
|
|
}
|
|
else
|
|
{
|
|
if (namecount > 0)
|
|
{
|
|
checked { ++namecount; }
|
|
continue;
|
|
}
|
|
type = !ri.IsCollection ? ConflictType.FileToFile : ConflictType.FileToFolder;
|
|
}
|
|
ConflictAction conflictAction;
|
|
if (type == ConflictType.NoConfliction)
|
|
{
|
|
conflictAction = ConflictAction.NoConfliction;
|
|
}
|
|
else
|
|
{
|
|
AsyncCopy.CopyConflictedEventArgs e = new AsyncCopy.CopyConflictedEventArgs(new SimpleResourceInfo(task.LocalPath, task.Size, task.LastModifiedTime, true), new SimpleResourceInfo(ri), type, (this.pFS.Ability & FsAbility.PartialWrite) != FsAbility.None, this.pFS.Ability, retryminutes);
|
|
EventHandler<AsyncCopy.CopyConflictedEventArgs> conflictionOccurredEvent = this.ConflictionOccurred;
|
|
if (conflictionOccurredEvent != null)
|
|
conflictionOccurredEvent((object) this, e);
|
|
conflictAction = e.Result.Action;
|
|
}
|
|
switch (conflictAction)
|
|
{
|
|
case ConflictAction.NoConfliction:
|
|
case ConflictAction.Overwrite:
|
|
if (ri != null)
|
|
task.RemoteId = ri.Id;
|
|
byte[] buffer = new byte[131072];
|
|
DateTime now = DateTime.Now;
|
|
long size = task.Size;
|
|
while (true)
|
|
{
|
|
try
|
|
{
|
|
this.pCurrentCost = size;
|
|
this.pCurrentProgress = 0L;
|
|
this.pCurrentState = AsyncCopy.DavCopyStateType.UploadFile;
|
|
using (Stream stream1 = task.VirtualFileInfo == null ? (Stream) File.OpenRead(task.LocalPath) : task.VirtualFileInfo.ManageStream)
|
|
{
|
|
Stream st;
|
|
if (start == 0L)
|
|
{
|
|
st = (object) task.RemoteId == null ? this.pCache.OpenWrite(this.pFS, task.BaseRemoteId, name, size) : this.pCache.OpenWriteOver(this.pFS, task.RemoteId, size);
|
|
}
|
|
else
|
|
{
|
|
if (size >= 0L)
|
|
checked { size -= start; }
|
|
st = this.pCache.OpenWriteResume(this.pFS, task.RemoteId, ref start, ref size);
|
|
stream1.Seek(start, SeekOrigin.Begin);
|
|
this.pCurrentCost = size;
|
|
}
|
|
using (Stream stream2 = st)
|
|
{
|
|
while (true)
|
|
{
|
|
object pLock = this.pLock;
|
|
ObjectFlowControl.CheckForSyncLockOnValueType(pLock);
|
|
Monitor.Enter(pLock);
|
|
try
|
|
{
|
|
if (this.pWorkerState == 2)
|
|
{
|
|
this.pCancelled = true;
|
|
stream2.Close();
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
Monitor.Exit(pLock);
|
|
}
|
|
int count = stream1.Read(buffer, 0, buffer.Length);
|
|
if (count != 0)
|
|
{
|
|
stream2.Write(buffer, 0, count);
|
|
this.pCurrentProgress = checked (this.pCurrentProgress + (long) count);
|
|
this.pCurrentSeconds = DateTime.Now.Subtract(now).TotalSeconds;
|
|
}
|
|
else
|
|
break;
|
|
}
|
|
}
|
|
ReturnedInfo returnedInfo = this.pCache.CloseWrite(this.pFS, st);
|
|
ResourceInfo resourceInfo = returnedInfo as ResourceInfo;
|
|
task.RemoteId = resourceInfo == null ? returnedInfo as ResourceId : resourceInfo.Id;
|
|
break;
|
|
}
|
|
}
|
|
catch (UnauthorizedException ex)
|
|
{
|
|
ProjectData.SetProjectError((Exception) ex);
|
|
this.pFS.ResetConnection();
|
|
WebdavFs pFs = this.pFS as WebdavFs;
|
|
if (pFs == null)
|
|
throw;
|
|
else if (pFs.SendEmptyPUT)
|
|
{
|
|
throw;
|
|
}
|
|
else
|
|
{
|
|
pFs.SendEmptyPUT = true;
|
|
ProjectData.ClearProjectError();
|
|
}
|
|
}
|
|
}
|
|
if ((this.pFS.Ability & FsAbility.Times) != FsAbility.None)
|
|
{
|
|
DateTime lastmodifiedtime = DateTime.MinValue;
|
|
DateTime creationtime = DateTime.MinValue;
|
|
DateTime lastaccesstime = DateTime.MinValue;
|
|
if ((this.pFS.Ability & FsAbility.LastModifiedTime) != FsAbility.None)
|
|
lastmodifiedtime = task.LastModifiedTime;
|
|
if ((this.pFS.Ability & FsAbility.CreationTime) != FsAbility.None)
|
|
creationtime = task.CreationDate;
|
|
if ((this.pFS.Ability & FsAbility.LastAccessTime) != FsAbility.None)
|
|
lastaccesstime = task.LastAccessTime;
|
|
this.pCache.SetTimes(this.pFS, task.RemoteId, lastmodifiedtime, creationtime, lastaccesstime);
|
|
}
|
|
if (this.pCurrentCost >= 0L)
|
|
{
|
|
if (this.pCurrentProgress < this.pCurrentCost)
|
|
throw new ApplicationException("Cannot send whole contents. Resource may be changed.");
|
|
if (this.pCurrentProgress > this.pCurrentCost)
|
|
throw new ApplicationException("Send stream is too long. Resource may be changed.");
|
|
}
|
|
task.FinishTask();
|
|
goto label_83;
|
|
case ConflictAction.OverwriteNewer:
|
|
if (DateTime.Compare(ri.LastModifiedTime.AddSeconds(1.0), File.GetLastWriteTime(task.LocalPath)) >= 0)
|
|
{
|
|
task.State = AsyncCopy.TaskStateType.Skipped;
|
|
goto label_83;
|
|
}
|
|
else
|
|
goto case ConflictAction.NoConfliction;
|
|
case ConflictAction.Resume:
|
|
if (ri.Size < 0L || task.Size < 0L)
|
|
throw new InvalidOperationException("Cannot Resume.");
|
|
if (ri.Size >= task.Size)
|
|
{
|
|
task.State = AsyncCopy.TaskStateType.Skipped;
|
|
goto label_83;
|
|
}
|
|
else
|
|
{
|
|
start = ri.Size;
|
|
if (start < 0L)
|
|
{
|
|
start = 0L;
|
|
goto case ConflictAction.NoConfliction;
|
|
}
|
|
else
|
|
goto case ConflictAction.NoConfliction;
|
|
}
|
|
case ConflictAction.DeleteTarget:
|
|
this.pCache.Delete(this.pFS, ri.Id);
|
|
ri = (ResourceInfo) null;
|
|
goto case ConflictAction.NoConfliction;
|
|
case ConflictAction.Retry:
|
|
continue;
|
|
case ConflictAction.AutoRetry:
|
|
checked { retryminutes *= 2; }
|
|
continue;
|
|
case ConflictAction.ChangeName:
|
|
checked { ++namecount; }
|
|
continue;
|
|
case ConflictAction.Skip:
|
|
task.State = AsyncCopy.TaskStateType.Skipped;
|
|
goto label_83;
|
|
case ConflictAction.CancelAll:
|
|
this.pCancelled = true;
|
|
return;
|
|
default:
|
|
throw new InvalidOperationException();
|
|
}
|
|
}
|
|
catch (Exception ex1)
|
|
{
|
|
ProjectData.SetProjectError(ex1);
|
|
Exception ex2 = ex1;
|
|
this.pFS.ResetConnection();
|
|
if (this.pCancelled)
|
|
{
|
|
ProjectData.ClearProjectError();
|
|
return;
|
|
}
|
|
ExceptionOccurredEventArgs e = new ExceptionOccurredEventArgs("Error occurred during uploading resource.", task.GetUploadFileName(name), ErrorPromptType.IgnoreAllIgnoreRetryCancel, ex2, retryminutes);
|
|
EventHandler<ExceptionOccurredEventArgs> exceptionOccurredEvent = this.ExceptionOccurred;
|
|
if (exceptionOccurredEvent != null)
|
|
exceptionOccurredEvent((object) this, e);
|
|
switch (e.Result.Action)
|
|
{
|
|
case ErrorAction.Ignore:
|
|
task.State = AsyncCopy.TaskStateType.ErrorIgnore;
|
|
ProjectData.ClearProjectError();
|
|
return;
|
|
case ErrorAction.Retry:
|
|
namecount = 0;
|
|
ProjectData.ClearProjectError();
|
|
continue;
|
|
case ErrorAction.AutoRetry:
|
|
namecount = 0;
|
|
checked { retryminutes *= 2; }
|
|
ProjectData.ClearProjectError();
|
|
continue;
|
|
case ErrorAction.Cancel:
|
|
this.pCancelled = true;
|
|
ProjectData.ClearProjectError();
|
|
return;
|
|
default:
|
|
ProjectData.ClearProjectError();
|
|
goto label_83;
|
|
}
|
|
}
|
|
}
|
|
label_83:
|
|
task.TransferSeconds = this.pCurrentSeconds;
|
|
this.pTotalTransferSeconds = this.pTotalTransferSeconds + this.pCurrentSeconds;
|
|
this.pCurrentSeconds = 0.0;
|
|
if (task.State == AsyncCopy.TaskStateType.Skipped)
|
|
{
|
|
this.pCurrentProgress = 0L;
|
|
this.pCurrentCost = 0L;
|
|
}
|
|
else
|
|
{
|
|
if (this.pTotalProgress < 0L)
|
|
return;
|
|
this.pTotalProgress = checked (this.pTotalProgress + this.pCurrentProgress);
|
|
this.pCurrentProgress = 0L;
|
|
}
|
|
}
|
|
|
|
private void Worker_Upload_SetFolderProperty(AsyncCopy.DavCopyTask task)
|
|
{
|
|
int retryminutes = 1;
|
|
this.pCurrentCost = -1L;
|
|
this.pCurrentProgress = 0L;
|
|
this.pCurrentState = AsyncCopy.DavCopyStateType.UploadProperty;
|
|
this.pCurrentDesc = task.GetUploadFileName((string) null);
|
|
while (true)
|
|
{
|
|
try
|
|
{
|
|
if ((this.pFS.Ability & FsAbility.Times) != FsAbility.None)
|
|
{
|
|
DateTime lastmodifiedtime = DateTime.MinValue;
|
|
DateTime creationtime = DateTime.MinValue;
|
|
DateTime lastaccesstime = DateTime.MinValue;
|
|
if ((this.pFS.Ability & FsAbility.LastModifiedTime) != FsAbility.None)
|
|
lastmodifiedtime = task.LastModifiedTime;
|
|
if ((this.pFS.Ability & FsAbility.CreationTime) != FsAbility.None)
|
|
creationtime = task.CreationDate;
|
|
if ((this.pFS.Ability & FsAbility.LastAccessTime) != FsAbility.None)
|
|
lastaccesstime = task.LastAccessTime;
|
|
this.pCache.SetTimes(this.pFS, task.RemoteId, lastmodifiedtime, creationtime, lastaccesstime);
|
|
}
|
|
task.FinishTask();
|
|
break;
|
|
}
|
|
catch (Exception ex1)
|
|
{
|
|
ProjectData.SetProjectError(ex1);
|
|
Exception ex2 = ex1;
|
|
this.pFS.ResetConnection();
|
|
ExceptionOccurredEventArgs e = new ExceptionOccurredEventArgs("Error occurred during updating collection property.", task.GetUploadFileName((string) null), ErrorPromptType.IgnoreAllIgnoreRetryCancel, ex2, retryminutes);
|
|
EventHandler<ExceptionOccurredEventArgs> exceptionOccurredEvent = this.ExceptionOccurred;
|
|
if (exceptionOccurredEvent != null)
|
|
exceptionOccurredEvent((object) this, e);
|
|
switch (e.Result.Action)
|
|
{
|
|
case ErrorAction.Ignore:
|
|
task.State = AsyncCopy.TaskStateType.ErrorIgnore;
|
|
ProjectData.ClearProjectError();
|
|
return;
|
|
case ErrorAction.Retry:
|
|
ProjectData.ClearProjectError();
|
|
continue;
|
|
case ErrorAction.AutoRetry:
|
|
checked { retryminutes *= 2; }
|
|
ProjectData.ClearProjectError();
|
|
continue;
|
|
case ErrorAction.Cancel:
|
|
this.pCancelled = true;
|
|
ProjectData.ClearProjectError();
|
|
return;
|
|
default:
|
|
ProjectData.ClearProjectError();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ServerResourceChangedCallback(object state)
|
|
{
|
|
this.OnServerResourceChanged((ResourceChangedEventArgs) state);
|
|
}
|
|
|
|
private void DavCopyCompletedCallback(object state)
|
|
{
|
|
this.OnDavCopyCompleted((AsyncCompletedEventArgs) state);
|
|
}
|
|
|
|
private void AsyncCopy_Disposed(object sender, EventArgs e)
|
|
{
|
|
if (this.pFS == null)
|
|
return;
|
|
this.pFS.ResetConnection();
|
|
}
|
|
|
|
private void SetTimes(string path, DateTime lastmodifiedtime, DateTime creationtime, DateTime lastaccesstime)
|
|
{
|
|
FileSystem.SetFileTime(path, creationtime, lastaccesstime, lastmodifiedtime);
|
|
}
|
|
|
|
private delegate void DavCopyWorkerDelegate(AsyncOperation asyncop);
|
|
|
|
public class DavCopyCompletedEventArgs : AsyncCompletedEventArgs
|
|
{
|
|
private long pTotalBytes;
|
|
private TimeSpan pTotalTime;
|
|
private long pTransferBytes;
|
|
|
|
public DavCopyCompletedEventArgs(Exception error, bool cancelled, long total, long transfer, TimeSpan totaltime)
|
|
: base(error, cancelled, (object) null)
|
|
{
|
|
this.pTotalBytes = total;
|
|
this.pTransferBytes = transfer;
|
|
this.pTotalTime = this.pTotalTime;
|
|
}
|
|
|
|
public long TotalBytes
|
|
{
|
|
get
|
|
{
|
|
return this.pTotalBytes;
|
|
}
|
|
}
|
|
|
|
public long TransferBytes
|
|
{
|
|
get
|
|
{
|
|
return this.pTransferBytes;
|
|
}
|
|
}
|
|
|
|
public TimeSpan TotalTime
|
|
{
|
|
get
|
|
{
|
|
return this.pTotalTime;
|
|
}
|
|
}
|
|
}
|
|
|
|
public class CopyConflictedEventArgs : EventArgs
|
|
{
|
|
private SimpleResourceInfo pSource;
|
|
private SimpleResourceInfo pDestination;
|
|
private ConflictType pType;
|
|
private ConflictPromptFormResult pResult;
|
|
private bool pEnableResume;
|
|
private FsAbility pDestinationAbility;
|
|
private int pRetryMinutes;
|
|
|
|
public CopyConflictedEventArgs(SimpleResourceInfo source, SimpleResourceInfo destination, ConflictType type, bool enableresume, FsAbility destability, int retryminutes)
|
|
{
|
|
this.pSource = source;
|
|
this.pDestination = destination;
|
|
this.pType = type;
|
|
this.pResult = new ConflictPromptFormResult();
|
|
this.pResult.ToAll = false;
|
|
this.pResult.Action = ConflictAction.Skip;
|
|
this.pEnableResume = enableresume;
|
|
this.pDestinationAbility = destability;
|
|
this.pRetryMinutes = retryminutes;
|
|
}
|
|
|
|
public SimpleResourceInfo Source
|
|
{
|
|
get
|
|
{
|
|
return this.pSource;
|
|
}
|
|
}
|
|
|
|
public SimpleResourceInfo Destination
|
|
{
|
|
get
|
|
{
|
|
return this.pDestination;
|
|
}
|
|
}
|
|
|
|
public ConflictType Type
|
|
{
|
|
get
|
|
{
|
|
return this.pType;
|
|
}
|
|
}
|
|
|
|
public bool EnableResume
|
|
{
|
|
get
|
|
{
|
|
return this.pEnableResume;
|
|
}
|
|
}
|
|
|
|
public FsAbility DestinationAbility
|
|
{
|
|
get
|
|
{
|
|
return this.pDestinationAbility;
|
|
}
|
|
}
|
|
|
|
public ConflictPromptFormResult Result
|
|
{
|
|
get
|
|
{
|
|
return this.pResult;
|
|
}
|
|
set
|
|
{
|
|
this.pResult = value;
|
|
}
|
|
}
|
|
|
|
public int RetryMinutes
|
|
{
|
|
get
|
|
{
|
|
return this.pRetryMinutes;
|
|
}
|
|
}
|
|
}
|
|
|
|
public enum DavCopyStateType
|
|
{
|
|
DownloadProperty,
|
|
ConfirmFolder,
|
|
SetFolderAttribute,
|
|
ConfirmFile,
|
|
DownloadFile,
|
|
SearchDirectory,
|
|
MakingCollection,
|
|
UploadFile,
|
|
UploadProperty,
|
|
Finished,
|
|
}
|
|
|
|
public class StateContainer
|
|
{
|
|
public AsyncCopy.DavCopyStateType CurrentState;
|
|
public long TotalCost;
|
|
public long TotalProgress;
|
|
public double TotalSeconds;
|
|
public long CurrentCost;
|
|
public long CurrentProgress;
|
|
public double CurrentSeconds;
|
|
public string CurrentDesc;
|
|
public long TotalFiles;
|
|
public long TotalFolders;
|
|
public long CurrentFiles;
|
|
public long CurrentFolders;
|
|
}
|
|
|
|
private enum TaskType
|
|
{
|
|
Download,
|
|
Upload,
|
|
}
|
|
|
|
private enum TaskStateType
|
|
{
|
|
Initialized,
|
|
PropertyAcquired,
|
|
FolderConfirmed,
|
|
Complete,
|
|
Skipped,
|
|
ErrorIgnore,
|
|
}
|
|
|
|
private class DavCopyTask
|
|
{
|
|
private AsyncCopy.DavCopyTask pParentTask;
|
|
private List<AsyncCopy.DavCopyTask> pSubTasks;
|
|
private AsyncCopy.TaskType pTaskType;
|
|
private Dictionary<Uri, bool> pUriDic;
|
|
private string pLocalPath;
|
|
private VirtualFileInfo pvirtualfileinfo;
|
|
private ResourceId pRemoteId;
|
|
private string pBaseLocalPath;
|
|
private ResourceId pBaseRemoteId;
|
|
public AsyncCopy.TaskStateType State;
|
|
public double TransferSeconds;
|
|
public long Size;
|
|
public DateTime LastModifiedTime;
|
|
public bool IsCollection;
|
|
public DateTime CreationDate;
|
|
public DateTime LastAccessTime;
|
|
public ResourceInfo Info;
|
|
internal IDataObject DataObject;
|
|
internal DragDropEffects FinishEffect;
|
|
|
|
public AsyncCopy.TaskType TaskType
|
|
{
|
|
get
|
|
{
|
|
return this.pTaskType;
|
|
}
|
|
}
|
|
|
|
public AsyncCopy.DavCopyTask ParentTask
|
|
{
|
|
get
|
|
{
|
|
return this.pParentTask;
|
|
}
|
|
}
|
|
|
|
public AsyncCopy.DavCopyTask[] SubTasks
|
|
{
|
|
get
|
|
{
|
|
return this.pSubTasks.ToArray();
|
|
}
|
|
}
|
|
|
|
public bool IsRootTask
|
|
{
|
|
get
|
|
{
|
|
return this.pParentTask == null;
|
|
}
|
|
}
|
|
|
|
public Dictionary<Uri, bool> UriDic
|
|
{
|
|
get
|
|
{
|
|
return this.pUriDic;
|
|
}
|
|
}
|
|
|
|
public string LocalPath
|
|
{
|
|
get
|
|
{
|
|
return this.pLocalPath;
|
|
}
|
|
set
|
|
{
|
|
this.pLocalPath = value;
|
|
}
|
|
}
|
|
|
|
public ResourceId RemoteId
|
|
{
|
|
get
|
|
{
|
|
return this.pRemoteId;
|
|
}
|
|
set
|
|
{
|
|
this.pRemoteId = value;
|
|
}
|
|
}
|
|
|
|
public string BaseLocalPath
|
|
{
|
|
get
|
|
{
|
|
if (this.IsRootTask)
|
|
return this.pBaseLocalPath;
|
|
return this.pParentTask.pLocalPath;
|
|
}
|
|
}
|
|
|
|
public ResourceId BaseRemoteId
|
|
{
|
|
get
|
|
{
|
|
if (this.IsRootTask)
|
|
return this.pBaseRemoteId;
|
|
return this.pParentTask.pRemoteId;
|
|
}
|
|
}
|
|
|
|
public VirtualFileInfo VirtualFileInfo
|
|
{
|
|
get
|
|
{
|
|
return this.pvirtualfileinfo;
|
|
}
|
|
}
|
|
|
|
internal DavCopyTask(AsyncCopy.TaskType type, ResourceId remoteid, string localpath_1)
|
|
{
|
|
this.pSubTasks = new List<AsyncCopy.DavCopyTask>();
|
|
this.pParentTask = (AsyncCopy.DavCopyTask) null;
|
|
this.pTaskType = type;
|
|
this.pUriDic = new Dictionary<Uri, bool>();
|
|
this.State = AsyncCopy.TaskStateType.Initialized;
|
|
if (this.pTaskType == AsyncCopy.TaskType.Download)
|
|
{
|
|
this.pBaseLocalPath = localpath_1;
|
|
this.pRemoteId = remoteid;
|
|
this.pLocalPath = (string) null;
|
|
}
|
|
else
|
|
{
|
|
if (this.pTaskType != AsyncCopy.TaskType.Upload)
|
|
throw new Exception();
|
|
this.pBaseRemoteId = remoteid;
|
|
this.pLocalPath = localpath_1;
|
|
this.pRemoteId = (ResourceId) null;
|
|
this.pvirtualfileinfo = (VirtualFileInfo) null;
|
|
}
|
|
}
|
|
|
|
internal DavCopyTask(AsyncCopy.TaskType type, ResourceId remoteid, VirtualFileInfo vfinfo)
|
|
{
|
|
this.pSubTasks = new List<AsyncCopy.DavCopyTask>();
|
|
this.pParentTask = (AsyncCopy.DavCopyTask) null;
|
|
this.pTaskType = type;
|
|
this.pUriDic = new Dictionary<Uri, bool>();
|
|
this.State = AsyncCopy.TaskStateType.Initialized;
|
|
this.pBaseRemoteId = remoteid;
|
|
this.pLocalPath = vfinfo.FileName;
|
|
this.pvirtualfileinfo = vfinfo;
|
|
this.pRemoteId = (ResourceId) null;
|
|
}
|
|
|
|
internal DavCopyTask(AsyncCopy.DavCopyTask parenttask, ResourceId id)
|
|
{
|
|
this.pSubTasks = new List<AsyncCopy.DavCopyTask>();
|
|
this.pParentTask = parenttask;
|
|
this.pParentTask.pSubTasks.Add(this);
|
|
this.pTaskType = this.pParentTask.TaskType;
|
|
this.pUriDic = this.pParentTask.UriDic;
|
|
this.State = AsyncCopy.TaskStateType.Initialized;
|
|
this.pLocalPath = (string) null;
|
|
this.pRemoteId = id;
|
|
}
|
|
|
|
public string CalcLocalPathForDownload(UCSNormalization normalization, int namecount)
|
|
{
|
|
string path = UriUtil.GetLastName(this.pRemoteId.Uri);
|
|
if (namecount > 0)
|
|
path = Path.GetFileNameWithoutExtension(path) + " (" + namecount.ToString() + ")." + Path.GetExtension(path);
|
|
if (normalization != UCSNormalization.None)
|
|
path = path.Normalize((NormalizationForm) normalization);
|
|
return path;
|
|
}
|
|
|
|
internal DavCopyTask(AsyncCopy.DavCopyTask parenttask, string filepath)
|
|
{
|
|
this.pSubTasks = new List<AsyncCopy.DavCopyTask>();
|
|
this.pParentTask = parenttask;
|
|
this.pParentTask.pSubTasks.Add(this);
|
|
this.pTaskType = this.pParentTask.TaskType;
|
|
this.pUriDic = this.pParentTask.UriDic;
|
|
this.State = AsyncCopy.TaskStateType.Initialized;
|
|
this.pLocalPath = filepath;
|
|
this.pRemoteId = (ResourceId) null;
|
|
}
|
|
|
|
internal DavCopyTask(AsyncCopy.DavCopyTask parenttask, string filepath, VirtualFileInfo vfinfo)
|
|
{
|
|
this.pSubTasks = new List<AsyncCopy.DavCopyTask>();
|
|
this.pParentTask = parenttask;
|
|
this.pParentTask.pSubTasks.Add(this);
|
|
this.pTaskType = this.pParentTask.TaskType;
|
|
this.pUriDic = this.pParentTask.UriDic;
|
|
this.State = AsyncCopy.TaskStateType.Initialized;
|
|
this.pLocalPath = filepath;
|
|
this.pvirtualfileinfo = vfinfo;
|
|
this.pRemoteId = (ResourceId) null;
|
|
}
|
|
|
|
public string CalcRemoteUriForUpload(UCSNormalization normalization, int namecount)
|
|
{
|
|
string path = Path.GetFileName(this.pLocalPath);
|
|
if (namecount > 0)
|
|
path = Path.GetFileNameWithoutExtension(path) + " (" + namecount.ToString() + ")." + Path.GetExtension(path);
|
|
if (normalization != UCSNormalization.None)
|
|
path = path.Normalize((NormalizationForm) normalization);
|
|
return path;
|
|
}
|
|
|
|
public string GetDownloadFileName()
|
|
{
|
|
return this.RemoteId.Uri.ToString();
|
|
}
|
|
|
|
public string GetUploadFileName(string name = null)
|
|
{
|
|
if (string.IsNullOrEmpty(name))
|
|
return this.BaseRemoteId.Uri.ToString();
|
|
return UriUtil.CombineName(this.BaseRemoteId.Uri, name).ToString();
|
|
}
|
|
|
|
public void FinishTask()
|
|
{
|
|
this.State = AsyncCopy.TaskStateType.Complete;
|
|
if (this.DataObject != null)
|
|
{
|
|
DataObjectHelper.SetPerformedDragEffect(this.DataObject, this.FinishEffect);
|
|
DataObjectHelper.SetLogicalPerformedDragEffect(this.DataObject, this.FinishEffect);
|
|
if (this.FinishEffect == DragDropEffects.Move)
|
|
DataObjectHelper.SetPasteSucceeded(this.DataObject, this.FinishEffect);
|
|
DataObjectHelper.EndAsyncOperation(this.DataObject, this.FinishEffect);
|
|
this.DataObject = (IDataObject) null;
|
|
}
|
|
if (this.pvirtualfileinfo == null)
|
|
return;
|
|
if (this.pvirtualfileinfo.IStreamCreator != null)
|
|
{
|
|
this.pvirtualfileinfo.IStreamCreator.Dispose();
|
|
this.pvirtualfileinfo.IStreamCreator = (IStreamCreator) null;
|
|
}
|
|
if (this.pvirtualfileinfo.ManageStream != null)
|
|
{
|
|
this.pvirtualfileinfo.ManageStream.Dispose();
|
|
this.pvirtualfileinfo.ManageStream = (Stream) null;
|
|
}
|
|
this.pvirtualfileinfo = (VirtualFileInfo) null;
|
|
}
|
|
}
|
|
}
|
|
}
|