コード例 #1
0
 public async void Save()
 {
     await Task.Run(async() =>
     {
         // Create sample file; replace if exists.
         Windows.Storage.StorageFolder storageFolder =
             Windows.Storage.ApplicationData.Current.LocalFolder;
         Windows.Storage.StorageFile sampleFile =
             await storageFolder.CreateFileAsync(FileName + ".mport",
                                                 Windows.Storage.CreationCollisionOption.ReplaceExisting);
         JsonSerializerSettings settings = new JsonSerializerSettings
         {
             TypeNameHandling = TypeNameHandling.All
         };
         string fileserial             = Serialize.Xml_Serialize_Object <Experiment>((Experiment)this);
         Dictionary <string, object> o = new Dictionary <string, object>();
         o.Add("usertoken", Windows.Storage.ApplicationData.Current.LocalSettings.Values["usertoken"]);
         o.Add("experiment", this);
         try
         {
             try
             {
                 await Windows.Storage.FileIO.WriteBytesAsync(sampleFile, Encoding.UTF8.GetBytes(fileserial));
                 Dictionary <string, object> d = await HttpHelpers.Put <Dictionary <string, object> >(o, "experiment");
                 if ((bool)d["success"] == true)
                 {
                     Debug.WriteLine("Yay!");
                 }
             }
             catch
             {
                 Debug.WriteLine("Failed to Save Experiment");
             }
         }
         catch (Exception e)
         {
             Debug.WriteLine(e.Message);
         }
     });
 }