// 使用者帳號與密碼可以使用 user1~user50 / password1~password50 public async Task LoginAsync(string account, string password) { string url = "https://lobworkshop.azurewebsites.net/api/Login"; LoginRequestDTO loginRequestDTO = new LoginRequestDTO() { Account = account, Password = password }; var httpJsonPayload = JsonConvert.SerializeObject(loginRequestDTO); HttpClient client = new HttpClient(); HttpResponseMessage response = await client.PostAsync(url, new StringContent(httpJsonPayload, System.Text.Encoding.UTF8, "application/json")); if (response.IsSuccessStatusCode) { String strResult = await response.Content.ReadAsStringAsync(); APIResult apiResult = JsonConvert.DeserializeObject <APIResult>(strResult, new JsonSerializerSettings { MetadataPropertyHandling = MetadataPropertyHandling.Ignore }); if (apiResult.Status == true) { string itemJsonContent = apiResult.Payload.ToString(); item = JsonConvert.DeserializeObject <LoginResponseDTO>(itemJsonContent, new JsonSerializerSettings { MetadataPropertyHandling = MetadataPropertyHandling.Ignore }); string content = JsonConvert.SerializeObject(item); await StorageUtility.WriteToDataFileAsync(Constants.DataFolder, Constants.LoginServiceFilename, content); } } }
private static async Task <bool> AsyncFileWriteText(string path, string text) { StorageFile file = StorageUtility.GetFile(path, FileOperationMode.Append); await FileIO.WriteTextAsync(file, text); return(true); }
public async Task <string> SendFileToServerAsync(string url, string filePath, string name, Request request, CallbackOnFinished callbackOnFinish = null) { InitHttpClient(); this.ConvertRequestToJson(request); MultipartFormDataContent form = new MultipartFormDataContent(); IFile fileToSend = await FileSystem.Current.GetFileFromPathAsync(filePath); Stream fileToSendStream = await fileToSend.OpenAsync(FileAccess.Read); byte[] fileToSendBytesArray = StorageUtility.ConvertStreamInBytesArray(fileToSendStream); form.Add(new StringContent(API_KEY), "apikey"); form.Add(new StringContent(JsonRequest), "data"); form.Add(new ByteArrayContent(fileToSendBytesArray, 0, fileToSendBytesArray.Length), name, filePath); Debug.WriteLine("Sending json : " + JsonRequest); HttpResponseMessage response = await httpClient.PostAsync(url, form); response.EnsureSuccessStatusCode(); httpClient.Dispose(); string serverResponse = response.Content.ReadAsStringAsync().Result; Debug.WriteLine("Server response = " + serverResponse); callbackOnFinish?.Invoke(serverResponse); return(serverResponse); }
private static string GetJson(string structRootPath) { Impersonator imp = null; if (StorageUtility.NeedImpersonation(structRootPath)) { imp = StorageUtility.GetImpersonator(); } try { var structXml = Path.Combine(structRootPath, @"Metadata\Structure.xml"); var structure = MetadataStructure.GetFromFile(structXml); //var dir = Path.GetDirectoryName(structXml); //var jsonFile = Path.Combine(dir, "metadataAlias.json"); //structure.ToFile(jsonFile, false, true); var jsonFile = JsonConvert.SerializeObject(structure.GetAliases(), Formatting.None); return(jsonFile); } finally { if (imp != null) { imp.Dispose(); } } }
public static StorageFile GetFile(string path, FileOperationMode mode) { path = StorageUtility.ConvertPathSeparators(path); StorageFile storageFile; try { storageFile = StorageUtility.GetFileFromPath(path); } catch (Exception ex) { if (mode == FileOperationMode.Append || mode == FileOperationMode.Create) { return(StorageUtility.CreateFile(path)); } throw ex; } if (mode == FileOperationMode.Create) { StorageFile storageFile2 = StorageUtility.CreateFileAtPath(StorageUtility.ConvertPathSeparators(Application.temporaryCachePath), "temp", 0); StorageUtility.MoveAndReplaceFile(storageFile2, storageFile); storageFile = storageFile2; } return(storageFile); }
public static void FileDelete(string path) { path = StorageUtility.ConvertPathSeparators(path); Task <bool> task = StorageUtility.FileDeleteAsync(path); task.Wait(); }
private async void StartRecording(Callback callback) { bool result = true; string message = null; string fileExtension = ".3gp"; int counter = 0; string audioFileName = StorageUtility.UpdateFilename(audioDefaultFileName, counter) + fileExtension; bool fileExists = await StorageUtility.IsFileExistAsync(audioFileName, localFolderName); while (fileExists) { counter++; audioFileName = StorageUtility.UpdateFilename(audioFileName, counter) + fileExtension; fileExists = await StorageUtility.IsFileExistAsync(audioFileName, localFolderName); } string currentFilePath = StorageUtility.GetAppLocalPath() + "/" + localFolderName + "/" + audioFileName; result = result && await StorageUtility.CreateEmptyFileInFolder(localFolderName, audioFileName); result = result && _recorder.StartRecording(currentFilePath, out message); callback?.Invoke(result, message, currentFilePath); }
private VaultAppModel ToModel(VaultApp app, bool needImpersonate, bool isUpdate = false) { if (app == null) { throw new ArgumentNullException("app"); } var vam = new VaultAppModel { AppId = app.Id, Guid = app.Guid, //CloudAppEnabled = app.CloudAppEnabled, IsUpdate = isUpdate, Version = app.Version }; try { if (needImpersonate) { using (StorageUtility.GetImpersonator()) { vam.ZipFile = File.ReadAllBytes(app.Filepath); } } else { vam.ZipFile = File.ReadAllBytes(app.Filepath); } } catch (Exception ex) { Log.Info(app.Filepath + ex.Message); } return(vam); }
public static byte[] FileReadAllBytes(string file) { Task <byte[]> task = StorageUtility.ReadBytesAsync(file); task.Wait(); return(task.Result); }
public static StorageFolder GetFolder(StorageFolder folder, string name) { Task <StorageFolder> task = StorageUtility.AsyncGetFolder(folder, name); task.Wait(); return(task.Result); }
public static string GetAssetBundleOutputPath() { TestResourcesEditorSettingsData data = Settings.GetData(); string path = StorageUtility.GetPath(data.AssetBundleOutputDirectory, data.AssetBundleOutputPath); return(path); }
private static async Task <byte[]> ReadBytesAsync(string path) { byte[] result; if (path == null) { result = null; } else { path = StorageUtility.ConvertPathSeparators(path); StorageFile storageFile = await StorageFile.GetFileFromPathAsync(path); StorageFile storageFile2 = storageFile; IBuffer buffer = await FileIO.ReadBufferAsync(storageFile2); DataReader var_10 = DataReader.FromBuffer(buffer); try { byte[] var_11_128 = new byte[var_10.get_UnconsumedBufferLength()]; var_10.ReadBytes(var_11_128); result = var_11_128; } finally { int num; if (num < 0 && var_10 != null) { var_10.Dispose(); } } } return(result); }
public static string FileReadAllText(string file) { Task <string> task = StorageUtility.AsyncReadTextAsync(file); task.Wait(); return(task.Result); }
public static string GetAssetBundlePath() { TestResourcesSettingsAsset data = Settings.GetData(); string path = StorageUtility.GetPath(data.AssetBundleDirectory, data.AssetBundlePath); return(path); }
public ActionResult Download(FileGetModel model) { var sharedFile = _shareService.GetByUrlHash(model.Item, model.Key); if (sharedFile == null) { return(RedirectToAction("Index", "Files", new { id = model.Item })); } var urlPart = Utility.FromHexStr(sharedFile.UrlPart);//Utility.DecryptFromHex(model.Item, sharedFile.UrlKey); urlPart = urlPart.Replace(@"\", "/"); //var filePath = GetHost() + "/" + StorageUtility.VaultSharedPath + "/" + urlPart; //return Redirect(filePath); var sharedRootPath = StorageUtility.GetVaultSharedRootPath(); var filePath = Path.Combine(sharedRootPath, urlPart); //var filePath = Path.Combine(Server.MapPath("~"), StorageUtility.VaultSharedPath + "\\" + urlPart); var downloadName = Path.GetFileName(filePath); if (!StorageUtility.NeedImpersonation(filePath)) { return(File(filePath, "application/octet-stream", downloadName)); } using (StorageUtility.GetImpersonator()) { var bytes = System.IO.File.ReadAllBytes(filePath); var fcr = new FileContentResult(bytes, "application/octet-stream") { FileDownloadName = downloadName }; return(fcr); //return File(filePath, "application/octet-stream", downloadName); } }
public static void FileWriteText(string path, string text) { path = StorageUtility.ConvertPathSeparators(path); Task <bool> task = StorageUtility.AsyncFileWriteText(path, text); task.Wait(); }
public static void FileWriteLines(string path, string[] contents) { path = StorageUtility.ConvertPathSeparators(path); Task <bool> task = StorageUtility.AsyncFileWriteLines(path, contents); task.Wait(); }
public static StorageFile CreateFile(StorageFolder folder, string name, CreationCollisionOption collisionOption) { Task <StorageFile> task = StorageUtility.AsyncCreateFile(folder, name, collisionOption); task.Wait(); return(task.Result); }
public static StorageFile CreateFileAtPath(string path, string name, CreationCollisionOption collisionOption) { Task <StorageFile> task = StorageUtility.AsyncCreateFileAtPath(path, name, collisionOption); task.Wait(); return(task.Result); }
public static StorageFolder GetFolderFromPath(string path) { path = StorageUtility.ConvertPathSeparators(path); Task <StorageFolder> task = StorageUtility.AsyncGetFolderFromPath(path); task.Wait(); return(task.Result); }
public static void FileRename(string sourcePath, string destPath) { sourcePath = StorageUtility.ConvertPathSeparators(sourcePath); destPath = StorageUtility.ConvertPathSeparators(destPath); Task <bool> task = StorageUtility.FileRenameAsync(sourcePath, destPath); task.Wait(); }
public static string[] FileReadLines(string path) { path = StorageUtility.ConvertPathSeparators(path); Task <IEnumerable <string> > task = StorageUtility.AsyncFileReadLines(path); task.Wait(); return(task.Result.Cast <string>().ToArray <string>()); }
public static IBuffer FileReadBuffer(string path) { path = StorageUtility.ConvertPathSeparators(path); Task <IBuffer> task = StorageUtility.AsyncFileReadBuffer(path); task.Wait(); return(task.Result); }
private static async Task <string> AsyncReadTextAsync(string path) { path = StorageUtility.ConvertPathSeparators(path); StorageFile storageFile = await StorageFile.GetFileFromPathAsync(path); StorageFile storageFile2 = storageFile; return(await FileIO.ReadTextAsync(storageFile2)); }
private static async Task <bool> FileRenameAsync(string sourcePath, string destPath) { StorageFile storageFile = await StorageFile.GetFileFromPathAsync(sourcePath); StorageFile storageFile2 = storageFile; int pathSeparatorIndex = StorageUtility.GetPathSeparatorIndex(destPath, false); await storageFile2.RenameAsync(destPath.Substring(pathSeparatorIndex + 1)); return(true); }
public async Task Read() { string content = await StorageUtility.ReadFromDataFileAsync(Constants.DataFolder, Constants.LoginServiceFilename); item = JsonConvert.DeserializeObject <LoginResponseDTO>(content); if (item == null) { item = new LoginResponseDTO(); } }
private static void StoreCommunication(bool StoreResults, bool StoreUntaggedCommunication, List <string> Tags, EmailSearch Search) { //If we should be storing the results by request, and we have tags or a directive to store untagged communications if (StoreResults && ((Tags != null && Tags.Count > 0) || StoreUntaggedCommunication)) { Search.ServiceAPIVersion = Properties.Resources.ServiceVersion; StorageUtility.GetInstance().StoreEmailToTableStorage(Search); StorageUtility.GetInstance().StoreEmailToGraphStorage(Search); } }
/// <summary> /// 將資料讀取出來 /// </summary> /// <returns></returns> public async Task<List<LAFAgentReslut>> ReadAsync() { string data = ""; data = await StorageUtility.ReadFromDataFileAsync("", MainHelper.資料主目錄, MainHelper.LeaveAppFormAgentAPIName); Items = JsonConvert.DeserializeObject<List<LAFAgentReslut>>(data); if (Items == null) { Items = new List<LAFAgentReslut>(); } return Items; }
public static bool FolderExists(string path) { if (path == null) { return(false); } path = StorageUtility.ConvertPathSeparators(path); Task <bool> task = StorageUtility.FolderExistsAsync(path); task.Wait(); return(task.Result); }
/// <summary> /// 將資料讀取出來 /// </summary> /// <returns></returns> public async Task <UserLoginResultModel> ReadAsync() { string data = ""; data = await StorageUtility.ReadFromDataFileAsync("", MainHelper.資料主目錄, MainHelper.UserLoginAPIName); Item = JsonConvert.DeserializeObject <UserLoginResultModel>(data); if (Item == null) { Item = new UserLoginResultModel(); } return(Item); }