public async Task <IList <FileStorages.IFileStorageItem> > LoadDirectory() { List <FileStorages.IFileStorageItem> result = new List <FileStorages.IFileStorageItem>(); DeserializedItemList deserializedItemList = new DeserializedItemList(); string path = string.IsNullOrEmpty(Path) ? "/drive/root" : String.Concat("{0}{1}:", Path, Name); var httpClient = new System.Net.Http.HttpClient(); var request = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Get, "https://graph.microsoft.com/v1.0/me" + path + "/children"); request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", Account.Token); System.Net.Http.HttpResponseMessage response = await httpClient.SendAsync(request); if (response.StatusCode != HttpStatusCode.OK) { throw new InvalidOperationException("Item did not copy"); } using (var stream = await response.Content.ReadAsStreamAsync()) { DataContractJsonSerializer ser = new DataContractJsonSerializer(deserializedItemList.GetType()); deserializedItemList = ser.ReadObject(stream) as DeserializedItemList; } if (deserializedItemList == null) { throw new NullReferenceException("Couldn't deserialized the data"); } foreach (var item in deserializedItemList.Value) { FileStorages.IFileStorageItem storageItem; if (item.Folder != null) { storageItem = new FileStorageFolder(new FolderBuilder(item)); } else { storageItem = new FileStorageFile(new FileBuilder(item)); } result.Add(storageItem); } return(result); }
/// <summary> /// Импортирует данные из строки /// </summary> /// <param name="data">Данные в строковом виде</param> /// <returns>Объект полученный после анализа строки</returns> public static OneDrive.IFileStorageFile Parse(String data) { var anonymClass = new { This = "", Login = "" }; anonymClass = JsonConvert.DeserializeAnonymousType(data, anonymClass); FileStorageFile thisClass = JsonConvert.DeserializeObject <FileStorageFile>(anonymClass.This); var file = new FileStorageFile(new FileBuilder() { Name = thisClass.Name, DownloadUrl = thisClass.DownloadUrl, Id = thisClass.Id, Path = thisClass.Path, PublicUrl = thisClass.PublicUrl, Size = thisClass.Size, Type = thisClass.Type }); IUnityContainer container = UnityDisk.ContainerConfiguration.GetContainer().Container; var accountRegistry = container.Resolve <UnityDisk.Accounts.Registry.IAccountRegistry>(); file.Account = accountRegistry.Find(anonymClass.Login); return(file); }