//save sessin to file: public static async void SaveSession() { if (InstaApi == null) { return; } if (!InstaApi.IsUserAuthenticated) { return; } _lastUser = _user; // Create file; replace if exists. Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder; // mage mikhai chand ta id azash login koni hamzaman? are // bish az 5 ta bashe block mishi, dah ta 1a dare // dah ta yeka dare yani che:| 10 ta ja dare, bedone moshkel Windows.Storage.StorageFile File = await storageFolder.CreateFileAsync(_user + ".txt", Windows.Storage.CreationCollisionOption.ReplaceExisting); await Windows.Storage.FileIO.WriteTextAsync(File, InstaApi.GetStateDataAsString()); localSettings.Values["ihaveaaccount"] = "yes"; localSettings.Values["LastUser"] = _lastUser; }
/// <summary> /// Save InstaApi session /// </summary> async void SaveSession() { if (InstaApi == null) { return; } if (!InstaApi.IsUserAuthenticated) { return; } try { // ReplaceExisting must be set!!!! var file = await LocalFolder.CreateFileAsync(StateFileName, CreationCollisionOption.ReplaceExisting); // Get state as string (note: in net core you can't get as Stream) var json = InstaApi.GetStateDataAsString(); await FileIO.WriteTextAsync(file, json, Windows.Storage.Streams.UnicodeEncoding.Utf8); //// OR //byte[] fileBytes = Encoding.UTF8.GetBytes(json); //using (var stream = await file.OpenStreamForWriteAsync()) //{ // stream.Write(fileBytes, 0, fileBytes.Length); //} } catch { } }
public async Task SaveLoginData() { var fileStream = File.Create(Path.GetFullPath(SESSION_FILE_NAME)); var sessiondata = instaApi.GetStateDataAsString(); var bytesToSave = UTF8Encoding.UTF8.GetBytes(sessiondata); await fileStream.WriteAsync(bytesToSave, 0, bytesToSave.Length); fileStream.Close(); }
private async Task SaveSessionStateAsync() { var stateData = _instaApi.GetStateDataAsString(); var user = await _repository.GetUserByNameAsync(_userName); int userId; if (user == null) { var newUser = new User(); newUser.Name = _userName; userId = await _repository.AddUserAsync(newUser); } else { userId = user.Id; } await _repository.SaveSessionStateAsync(userId, stateData); }