当前位置: 首页>>代码示例>>C#>>正文


C# StorageFolder.CopyDirContentsAsync方法代码示例

本文整理汇总了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;
		}
开发者ID:lolluslollus,项目名称:UniFiler10,代码行数:27,代码来源:Briefcase.cs

示例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
			});
		}
开发者ID:lolluslollus,项目名称:UniFiler10,代码行数:71,代码来源:Binder.cs

示例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;
		}
开发者ID:lolluslollus,项目名称:UniFiler10,代码行数:36,代码来源:Briefcase.cs


注:本文中的Windows.Storage.StorageFolder.CopyDirContentsAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。