public static void SaveUserServer(User user) { MemoryStream stream1 = new MemoryStream(); DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(User)); ser.WriteObject(stream1, user); stream1.Position = 0; StreamReader sr = new StreamReader(stream1); WebClient webClient = new WebClient(); webClient.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; var uri = new Uri("http://54.204.10.235:8080/save_user/", UriKind.Absolute); StringBuilder postData = new StringBuilder(); postData.AppendFormat("{0}={1}", "user_json", HttpUtility.UrlEncode(sr.ReadToEnd())); webClient.Headers[HttpRequestHeader.ContentLength] = postData.Length.ToString(); webClient.UploadStringCompleted += new UploadStringCompletedEventHandler(SaveUserServerCompleted); webClient.UploadStringAsync(uri, "POST", postData.ToString()); }
/// <summary> /// Saves the user object to local storage /// </summary> /// <param name="city"></param> public static void SaveUserToIsolatedStorage(User user) { // persist the data using isolated storage using (var store = IsolatedStorageFile.GetUserStoreForApplication()) using (var stream = new IsolatedStorageFileStream("data_user.txt", FileMode.Create, FileAccess.Write, store)) { var serializer = new XmlSerializer(typeof(User)); serializer.Serialize(stream, user); } }
// <summary> /// Saves the state of the app by storing the user object /// </summary> /// <param name="city"></param> public static void SaveUserToAppState(User user) { PhoneApplicationService.Current.State[User.KEY] = user; }