Example #1
0
 public async Task <HttpResponseMessage> PutAsync <T>(Uri path, T payload, int?timeoutMillis = null, string token = null)
 {
     try
     {
         using (var http = GetClient(token))
         {
             var data    = _serializationService.SerializeJson(payload);
             var content = new HttpStringContent(data, Encoding, HttpConstants.APPLICATION_JSON);
             if (timeoutMillis != null)
             {
                 var cancelation = new CancellationTokenSource(timeoutMillis.Value);
                 return(await http.PutAsync(path, content).AsTask(cancelation.Token));
             }
             else
             {
                 return(await http.PutAsync(path, content));
             }
         }
     }
     catch (TaskCanceledException)
     {
         // timeout
         return(null);
     }
     catch (Exception)
     {
         // server error, offline, ...
         return(null);
     }
 }
        public override Task OnNavigatedFromAsync(IDictionary <string, object> state, bool suspending)
        {
            var serializedTempItem = _serializationService.SerializeJson(TemporaryItem.Model);

            state[TEMPORARY_ITEM_KEY] = serializedTempItem;

            return(base.OnNavigatedFromAsync(state, suspending));
        }
        /// <summary>
        /// Save specific data.
        /// </summary>
        /// <param name="guid">Id of data to save.</param>
        /// <returns>Returns save state.</returns>
        public virtual async Task <bool> SaveAsync(Guid guid)
        {
            // save all in dictionary
            if (!cache.ContainsKey(guid))
            {
                return(false);
            }

            var json = serializationService.SerializeJson <T>(cache[guid]);

            return(await storageService.WriteFile(Path.Combine("Data", $"{guid}.json"), json));
        }