Task <Addresses> ReadAddressesAsync() { string filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), BuildingsFile); if (!File.Exists(filePath)) { return(Task.FromResult <Addresses>(null)); } else { var serBuildings = File.OpenRead(filePath); return(deserializer.DeserializeAsync <Addresses>(serBuildings)); } }
/// <summary> /// Reads the encrypted content of a file and parses it to an object. TODO exceptions /// </summary> /// <typeparam name="T">Type to parse the content to.</typeparam> /// <param name="path">Path to the file to read the json from.</param> /// <param name="deserializer"> /// Deserializer to deserialize the content of the file. If this parameter is null, the /// property value is used. /// </param> /// <param name="cryptoTransform"> /// Transformer that is use to decrypt the data. If this parameter is null, the property /// value is used. /// </param> /// <returns>The parsed value.</returns> public async Task <T> ReadEncryptedAsync <T>(string path = null, IDeserializer deserializer = null, ICryptoTransform cryptoTransform = null) { if (path == null) { try { path = _settings.FilePaths[typeof(T)]; } catch (KeyNotFoundException e) { throw new KeyNotFoundException($"There was no path found for type {typeof(T).Name}", e); } } if (deserializer == null) { deserializer = Deserializer; } if (cryptoTransform == null) { cryptoTransform = CryptoTransform; } using var fileStream = File.OpenRead(path); using var cryptoStream = new CryptoStream(fileStream, cryptoTransform, CryptoStreamMode.Read); using var streamReader = new StreamReader(cryptoStream); return(await deserializer.DeserializeAsync <T>(streamReader)); }
public async Task <T> SendAsync <T>(HttpRequestMessage request, object content, ISerializer serializer, IDeserializer deserializer) { request.Content = await serializer.SerializeAsync(content); var response = await SendAsync(request); return(await deserializer.DeserializeAsync <T>(response.Content)); }
public async Task <ServiceConfiguration[]> GetConfigurationsFromFileAsync(StorageFile file) { Stream fileStream = await file.OpenStreamForReadAsync(); string data = await _zipper.GetDataFromCompressedStreamAsync(fileStream); return(await _deserializer.DeserializeAsync(data)); }
public Task <T> DeserializeAsync <T>() { if (_stream.CanSeek) { _stream.Seek(0, SeekOrigin.Begin); } return(_deserializer.DeserializeAsync <T>(_stream)); }
public async Task <ResponseModel> GetSimple(int id, string name) { var baseUrl = "http://api.domain.com"; var path = "api/v1/some/{id}/{name}"; path = path.Replace("{id}", id.ToString()) .Replace("{name}", name); var uri = new Uri(new Uri(baseUrl), path); var httpMethod = HttpMethod.Get; var request = new HttpRequestMessage(httpMethod, uri); var client = new HttpClient(); var response = await client.SendAsync(request); var result = _deserializer.DeserializeAsync(response); return(result); }
public async Task <ResponseModel> AnnotatedHeader() { var baseUrl = "http://api.domain.com"; var path = $"api/v1/some"; var headerKey = "X-Name"; var headerValue = "Hasan"; var uri = new Uri(new Uri(baseUrl), path); var httpMethod = HttpMethod.Get; var request = new HttpRequestMessage(httpMethod, uri); request.Headers.Add(headerKey, headerValue); var client = new HttpClient(); var response = await client.SendAsync(request); var result = _deserializer.DeserializeAsync(response); return(result); }
/// <summary> /// Re-publishes commands from unpublished queue. /// Uses <paramref name="formatter"/> to deserialize commands from store. /// </summary> /// <param name="formatter">The command deserializer.</param> /// <returns>The continuation task.</returns> public async Task RecoverAsync(IDeserializer formatter) { Ensure.NotNull(store, "store"); Ensure.NotNull(formatter, "formatter"); IEnumerable <CommandModel> models = await store.GetAsync(); foreach (CommandModel model in models) { Type envelopeType = EnvelopeFactory.GetType(Type.GetType(model.CommandKey.Type)); Envelope envelope = (Envelope)await formatter.DeserializeAsync(envelopeType, model.Payload); await HandleAsync(envelope, false); } await store.ClearAsync(); }
/// <summary>Reads the content of a file and parses it to an object. TODO exceptions</summary> /// <typeparam name="T">Type to parse the content to.</typeparam> /// <param name="path">Path to the file to read the json from.</param> /// <param name="deserializer"> /// Deserializer to deserialize the content of the file. If this parameter is null, the /// property value is used. /// </param> /// <returns>The parsed value.</returns> public async Task <T> ReadAsync <T>(string path = null, IDeserializer deserializer = null) { if (path == null) { try { path = _settings.FilePaths[typeof(T)]; } catch (KeyNotFoundException e) { throw new KeyNotFoundException($"There was no path found for type {typeof(T).Name}", e); } } if (deserializer == null) { deserializer = Deserializer; } using var fileStream = File.OpenText(path); return(await deserializer.DeserializeAsync <T>(fileStream)); }
public async Task <T> SendAsync <T>(HttpRequestMessage request, IDeserializer deserializer) { var response = await SendAsync(request); return(await deserializer.DeserializeAsync <T>(response.Content)); }
public async Task <CompanyProfile> GetCompanyProfileBySymbol(string symbol) { return(await _deserializer.DeserializeAsync <CompanyProfile>(await _client.GetRawDataAsync("stock/profile2", new Field(FieldKeys.Symbol, symbol)))); }