Exemplo n.º 1
0
        public override async Task <TResult> ReadFromApplicationPackage <TResult>(string filePath)
        {
            var documentPath = NSFileManager.DefaultManager.GetUrls(NSSearchPathDirectory.ApplicationDirectory, NSSearchPathDomain.User)[0].Path;
            var fullFilePath = Path.Combine(documentPath, filePath);
            await Task.Delay(1);

            var content = File.ReadAllText(fullFilePath);

            return(DataAccessUtil.DeserializeObject <TResult>(content));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get a list of objectes based on given contract
        /// </summary>
        /// <returns>If the status of the response is not correct, return the default value of the generic</returns>
        public async Task <TContract[]> GetResponseList <TContract>()
        {
            if (this.IsSuccessStatusCode)
            {
                // DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(List<TContract>), new[]{typeof(TContract)});
                string content = await ResponseMessage.Content.ReadAsStringAsync();

                // Deserialize response
                XRMMessage <TContract> message = DataAccessUtil.DeserializeObject <XRMMessage <TContract> >(content);
                return(message.getResult());
            }
            return(null);
        }
        /// <summary>
        /// Read from local folder the specified file and deserialze the object before return
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="filename"></param>
        /// <returns></returns>
        public override async Task <TResult> ReadFromLocal <TResult>(string filename)
        {
            StorageFile file;
            TResult     result = default(TResult);

            if (!string.IsNullOrEmpty(filename))
            {
                try
                {
                    file = await localFolder.GetFileAsync(filename);

                    string data = await FileIO.ReadTextAsync(file);

                    result = DataAccessUtil.DeserializeObject <TResult>(data);
                }
                catch
                {
                    return(result);
                }
            }
            return(result);
        }