Ejemplo n.º 1
0
        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));
            }
        }
Ejemplo n.º 2
0
        /// <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));
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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();
        }
Ejemplo n.º 9
0
        /// <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));
        }
Ejemplo n.º 10
0
        public async Task <T> SendAsync <T>(HttpRequestMessage request, IDeserializer deserializer)
        {
            var response = await SendAsync(request);

            return(await deserializer.DeserializeAsync <T>(response.Content));
        }
Ejemplo n.º 11
0
 public async Task <CompanyProfile> GetCompanyProfileBySymbol(string symbol)
 {
     return(await _deserializer.DeserializeAsync <CompanyProfile>(await _client.GetRawDataAsync("stock/profile2", new Field(FieldKeys.Symbol, symbol))));
 }