本文整理汇总了C#中Windows.Storage.StorageFolder.CopyDirContentsAsync方法的典型用法代码示例。如果您正苦于以下问题:C# StorageFolder.CopyDirContentsAsync方法的具体用法?C# StorageFolder.CopyDirContentsAsync怎么用?C# StorageFolder.CopyDirContentsAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Storage.StorageFolder
的用法示例。
在下文中一共展示了StorageFolder.CopyDirContentsAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImportBinderFilesAsync
private async Task<bool> ImportBinderFilesAsync(StorageFolder fromDirectory)
{
if (fromDirectory != null)
{
try
{
// Check if you are restoring a Binder or something completely unrelated, which may cause trouble.
// Make sure you restore a Binder and not just any directory!
var srcFiles = await fromDirectory.GetFilesAsync().AsTask().ConfigureAwait(false);
bool isSrcOk = srcFiles.Any(file => file.Name == DBManager.DB_FILE_NAME)
&& srcFiles.Any(file => file.Name == Binder.FILENAME);
if (!isSrcOk) return false;
var toDirectory = await BindersDirectory
.CreateFolderAsync(fromDirectory.Name, CreationCollisionOption.ReplaceExisting)
.AsTask().ConfigureAwait(false);
await fromDirectory.CopyDirContentsAsync(toDirectory, CancToken).ConfigureAwait(false);
return true;
}
catch (OperationCanceledException) { }
catch (Exception ex)
{
Logger.Add_TPL(ex.ToString(), Logger.ForegroundLogFilename);
}
}
return false;
}
示例2: ImportFoldersAsync
public Task<bool> ImportFoldersAsync(StorageFolder fromDirectory)
{
return RunFunctionIfOpenAsyncTB(async delegate
{
if (fromDirectory == null) return false;
bool isOk = false;
bool isDeleteTempDir = false;
MergingBinder mergingBinder = null;
StorageFolder tempDirectory = null;
try
{
// I can only import from the app local folder, otherwise sqlite says "Cannot open", even in read-only mode.
// So I copy the source files into the temp directory.
if (fromDirectory.Path.Contains(ApplicationData.Current.LocalCacheFolder.Path) || fromDirectory.Path.Contains(ApplicationData.Current.LocalFolder.Path))
{
tempDirectory = fromDirectory;
}
else
{
tempDirectory = await ApplicationData.Current.LocalCacheFolder
.CreateFolderAsync(Guid.NewGuid().ToString(), CreationCollisionOption.ReplaceExisting)
.AsTask().ConfigureAwait(false);
await fromDirectory.CopyDirContentsAsync(tempDirectory, CancToken).ConfigureAwait(false);
isDeleteTempDir = true;
}
if (CancToken.IsCancellationRequested) return false;
mergingBinder = MergingBinder.CreateInstance(DBName, tempDirectory);
await mergingBinder.OpenAsync().ConfigureAwait(false);
var sw0 = new Stopwatch(); sw0.Start();
// parallelisation here seems ideal, but it screws with SQLite.
// The following works but:
// 1 it does not preserve the folder sequence and I think it causes dumps.
// 2 it dumps sometimes
//var tasks = new List<Task>();
//foreach (var fol in mergingBinder.Folders)
//{
// tasks.Add(Task.Run(() => Import1FolderAsync(fol, fromDirectory), CancToken));
//}
//await Task.WhenAll(tasks).ConfigureAwait(false);
foreach (var fol in mergingBinder.Folders)
{
await Import1FolderAsync(fol, fromDirectory).ConfigureAwait(false);
}
sw0.Stop();
Debug.WriteLine("Binder merge took " + sw0.ElapsedMilliseconds + " msec");
isOk = true;
}
catch (OperationCanceledException) { }
catch (Exception ex)
{
await Logger.AddAsync(ex.ToString(), Logger.FileErrorLogFilename).ConfigureAwait(false);
}
if (mergingBinder != null)
{
await mergingBinder.CloseAsync().ConfigureAwait(false);
mergingBinder.Dispose();
}
mergingBinder = null;
if (isDeleteTempDir && tempDirectory != null) await tempDirectory.DeleteAsync(StorageDeleteOption.PermanentDelete).AsTask().ConfigureAwait(false);
return isOk; // LOLLO sometimes it dumps after this,
// it looks like http://stackoverflow.com/questions/4532457/program-and-debugger-quit-without-indication-of-problem
});
}
示例3: ExportBinderAsync
public async Task<bool> ExportBinderAsync(string dbName, StorageFolder fromDirectory, StorageFolder toRootDirectory)
{
try
{
if (string.IsNullOrWhiteSpace(dbName) /*|| _dbNames?.Contains(dbName) == false */ || fromDirectory == null || toRootDirectory == null) return false;
//var fromDirectory = await BindersDirectory
// .GetFolderAsync(dbName)
// .AsTask().ConfigureAwait(false);
//if (fromDirectory == null) return false;
//// what if you copy a directory to an existing one? Shouldn't you delete the contents first? No! But then, shouldn't you issue a warning?
//var toDirectoryTest = await toRootDirectory.TryGetItemAsync(dbName).AsTask().ConfigureAwait(false);
//if (toDirectoryTest != null)
//{
// var confirmation = await UserConfirmationPopup.GetInstance().GetUserConfirmationBeforeExportingBinderAsync().ConfigureAwait(false);
// if (confirmation == null || confirmation.Item1 == false || confirmation.Item2 == false) return false;
//}
var toDirectory = await toRootDirectory
.CreateFolderAsync(dbName, CreationCollisionOption.ReplaceExisting)
.AsTask().ConfigureAwait(false);
if (toDirectory == null) return false;
Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.AddOrReplace("PickedFolderToken", toDirectory);
await fromDirectory.CopyDirContentsAsync(toDirectory, CancToken).ConfigureAwait(false);
return true;
}
catch (OperationCanceledException) { }
catch (Exception ex)
{
Logger.Add_TPL(ex.ToString(), Logger.FileErrorLogFilename);
}
return false;
}