summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Tizen/Deserializer.cs
diff options
context:
space:
mode:
authorKangho Hur <kangho.hur@samsung.com>2016-12-16 02:00:07 (GMT)
committerKangho Hur <kangho.hur@samsung.com>2017-10-23 04:34:24 (GMT)
commita2e67107402bc5a49d73cee9062bcd7dbe4069e7 (patch)
treeea6c6606567e8440397de192d47195194c0266dd /Xamarin.Forms.Platform.Tizen/Deserializer.cs
parent509954d0a013acdf7508644c1fb394bea626e587 (diff)
downloadxamarin-forms-a2e67107402bc5a49d73cee9062bcd7dbe4069e7.zip
xamarin-forms-a2e67107402bc5a49d73cee9062bcd7dbe4069e7.tar.gz
xamarin-forms-a2e67107402bc5a49d73cee9062bcd7dbe4069e7.tar.bz2
Add Tizen backend renderer
- Xamarin.Forms.Platform.Tizen has been added - Xamarin.Forms.Maps.Tizen has been added - RPM build spec has been added Change-Id: I0021e0f040d97345affc87512ee0f6ce437f4e6d
Diffstat (limited to 'Xamarin.Forms.Platform.Tizen/Deserializer.cs')
-rw-r--r--Xamarin.Forms.Platform.Tizen/Deserializer.cs106
1 files changed, 106 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.Tizen/Deserializer.cs b/Xamarin.Forms.Platform.Tizen/Deserializer.cs
new file mode 100644
index 0000000..8335840
--- /dev/null
+++ b/Xamarin.Forms.Platform.Tizen/Deserializer.cs
@@ -0,0 +1,106 @@
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using System.Runtime.Serialization;
+using System.Xml;
+using System.Diagnostics;
+using System.IO;
+
+namespace Xamarin.Forms.Platform.Tizen
+{
+ internal class Deserializer : IDeserializer
+ {
+ const string PropertyStoreFile = "PropertyStore.forms";
+
+ public Task<IDictionary<string, object>> DeserializePropertiesAsync()
+ {
+ // Deserialize property dictionary to local storage
+ // Make sure to use Internal
+ return Task.Run(() =>
+ {
+ var store = new TizenIsolatedStorageFile();
+ Stream stream = null;
+ try
+ {
+ stream = store.OpenFile(PropertyStoreFile, System.IO.FileMode.OpenOrCreate);
+ if (stream.Length == 0)
+ {
+ return null;
+ }
+ using (XmlDictionaryReader reader = XmlDictionaryReader.CreateBinaryReader(stream, XmlDictionaryReaderQuotas.Max))
+ {
+ stream = null;
+ var dcs = new DataContractSerializer(typeof(Dictionary<string, object>));
+ return (IDictionary<string, object>)dcs.ReadObject(reader);
+ }
+ }
+ catch (Exception e)
+ {
+ Debug.WriteLine("Could not deserialize properties: " + e.Message);
+ Xamarin.Forms.Log.Warning("Xamarin.Forms PropertyStore", $"Exception while reading Application properties: {e}");
+ }
+ finally
+ {
+ if (stream != null)
+ {
+ stream.Dispose();
+ }
+ }
+
+ return null;
+ });
+ }
+
+ public Task SerializePropertiesAsync(IDictionary<string, object> properties)
+ {
+ properties = new Dictionary<string, object>(properties);
+ // Serialize property dictionary to local storage
+ // Make sure to use Internal
+ return Task.Run(() =>
+ {
+ var success = false;
+ var store = new TizenIsolatedStorageFile();
+ Stream stream = null;
+ try
+ {
+ stream = store.OpenFile(PropertyStoreFile + ".tmp", System.IO.FileMode.OpenOrCreate);
+ using (XmlDictionaryWriter writer = XmlDictionaryWriter.CreateBinaryWriter(stream))
+ {
+ stream = null;
+ var dcs = new DataContractSerializer(typeof(Dictionary<string, object>));
+ dcs.WriteObject(writer, properties);
+ writer.Flush();
+ success = true;
+ }
+ }
+ catch (Exception e)
+ {
+ Debug.WriteLine("Could not serialize properties: " + e.Message);
+ Xamarin.Forms.Log.Warning("Xamarin.Forms PropertyStore", $"Exception while writing Application properties: {e}");
+ }
+ finally
+ {
+ if (stream != null)
+ {
+ stream.Dispose();
+ }
+ }
+
+ if (!success)
+ return;
+
+ try
+ {
+ if (store.FileExists(PropertyStoreFile))
+ store.DeleteFile(PropertyStoreFile);
+ store.MoveFile(PropertyStoreFile + ".tmp", PropertyStoreFile);
+ }
+ catch (Exception e)
+ {
+ Debug.WriteLine("Could not move new serialized property file over old: " + e.Message);
+ Xamarin.Forms.Log.Warning("Xamarin.Forms PropertyStore", $"Exception while writing Application properties: {e}");
+ }
+ });
+ }
+ }
+}