//Loads the authentication information on startup if exists public static async Task LoadLocalAuthenticaionInformation() { try { StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync(fileName); using (IInputStream inStream = await file.OpenSequentialReadAsync()) { DataContractSerializer serializer = new DataContractSerializer(typeof(DonorProfile)); var data = (DonorProfile)serializer.ReadObject(inStream.AsStreamForRead()); if (data != null) user = data; } } catch { } }
//Saves locally the authentication information after successful sign in public static async Task SetLocalAuthenticationInformation (DonorProfile User) { user = User; try { MemoryStream sessionData = new MemoryStream(); DataContractSerializer serializer = new DataContractSerializer(typeof(DonorProfile)); serializer.WriteObject(sessionData, user); StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync(fileName); using (Stream fileStream = await file.OpenStreamForWriteAsync()) { sessionData.Seek(0, SeekOrigin.Begin); await sessionData.CopyToAsync(fileStream); await fileStream.FlushAsync(); } } catch { } }
//Signout locally from this phone public static void Signout() { user = null; DeleteLocalAuthenticationInformation(); FollowedCharities.ClearCart(); }