public static DataContainer GetInstance() { return (instance==null)? (instance=load()): instance; }
private static DataContainer load() { DataContainer lInstance; var folder = Windows.Storage.ApplicationData.Current.LocalFolder; //if (File.Exists("data.xml")) try { var deserializer = new XmlSerializer(typeof(DataContainer)); var taskFile = Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync("data.xml", Windows.Storage.CreationCollisionOption.OpenIfExists).AsTask(); taskFile.Wait(); var task = taskFile.Result.OpenStreamForReadAsync(); //var task = folder.OpenStreamForReadAsync("ms-appdata:///local/data.xml"); ////task.RunSynchronously(); //task.Wait(); //File.OpenRead using (var fstream = task.Result) { lInstance = (DataContainer)deserializer.Deserialize(fstream); } } catch (FileNotFoundException fnfex) { lInstance = new DataContainer() { ItemList = new List<Item>(), //ItemList.Add(new Item() { ItemCode = "ABC", Description = "Alphabet soup", StandardPrice = 13.35M, UnitOfMeasure = "can(s)" }); //ItemList.Add(new Item() { ItemCode = "DEF", Description = "Soup station", StandardPrice = 10M, UnitOfMeasure = "bowl(s)" }); StockList = new List<Stock>(), //StockList.Add(new Stock() { ItemCode="ABC", StoreCode="DXB", Quantity=3m }); StoreList = new List<Store>(), //StoreList.Add(new Store() { StoreCode="DXB", Description="Dubai" }); TransactionList = new List<Transaction>() }; } catch (Exception ex) { lInstance = new DataContainer() { ItemList = new List<Item>(), StockList = new List<Stock>(), StoreList = new List<Store>(), TransactionList = new List<Transaction>() }; } return lInstance; }