public override async Task ResetAsync() { await MyLogger.Alert("FolderUploader currently not support Reset()"); //await Task.Delay(1000); //throw new NotImplementedException(); }
public async Task DownloadFileOnWindowsAsync(Windows.Storage.StorageFile file) { try { MyLogger.Assert(!this.IsFolder); MyLogger.Assert(this.Name == file.Name); var downloader = new CloudFile.Downloaders.FileDownloader(this, file); downloader.MessageAppended += new MessageAppendedEventHandler((msg) => { MyLogger.Log(msg); }); downloader.StatusChanged += new Networker.NetworkStatusChangedEventHandler(async() => { if (downloader.Status == Networker.NetworkStatus.Completed) { MyLogger.Log($"File download succeeded!\r\nName: {file.Name}\r\nPath: {file.Path}\r\nID: {this.Id}\r\nSize: {(await file.GetBasicPropertiesAsync()).Size} bytes"); } }); await downloader.StartAsync(); } catch (Exception error) { MyLogger.Log(error.ToString()); await MyLogger.Alert(error.ToString()); } }
public async Task <CloudFile> UploadFileAsync(Windows.Storage.StorageFile file) { try { var fileSize = (await file.GetBasicPropertiesAsync()).Size; if (fileSize == 0) { var uploadedFile = await CreateEmptyFileAsync(file.Name); MyLogger.Log($"File upload succeeded!\r\nName: {uploadedFile.Name}\r\nParent: {this.FullName}\r\nID: {uploadedFile.Id}\r\nSize: {fileSize} bytes"); MyLogger.Assert(uploadedFile.Name == file.Name); return(uploadedFile); } MyLogger.Assert(this.IsFolder); var uploader = new Uploaders.FileUploader(this, file, file.Name); indexRetry :; await uploader.StartAsync(); switch (uploader.Status) { case Networker.NetworkStatus.Completed: { MyLogger.Log($"File upload succeeded!\r\nName: {file.Name}\r\nParent: {this.FullName}\r\nID: {uploader.UploadedCloudFile.Id}\r\nSize: {fileSize} bytes"); var ans = new CloudFile(uploader.UploadedCloudFile.Id, file.Name, false, this); return(ans); } case Networker.NetworkStatus.Paused: { MyLogger.Log("Upload paused"); return(null); } default: { if (await MyLogger.Ask("Upload failed, try again?")) { await uploader.StartAsync(); goto indexRetry; } else { MyLogger.Log("Upload canceled"); return(null); } } } } catch (Exception error) { MyLogger.Log(error.ToString()); await MyLogger.Alert(error.ToString()); return(null); } }
static Libraries() { MyLogger.AddTestMethod("Generate Guid String", new Func <Task>(async() => { var guid = Guid.NewGuid(); string s = ""; foreach (var b in guid.ToByteArray()) { s += (char)b; } // s會變成亂碼 await MyLogger.Alert($"{guid.ToByteArray().Length}\r\n{guid}\r\n{s}\r\n{guid}"); // guid.ToString() 的形式: xxxxxxxx-xxxx-xxxx-xxxx-xxxx-xxxxxxxx (x是小寫英文or數字) })); }