//stores datapack as xml public static void ExportDataPack(Classes.Data ObjectToStore) { CheckAppdataFolder(); XmlSerializer ser = new XmlSerializer(typeof(Data)); using (Stream str = File.Create(Application.StartupPath + "/Appdata/DataPacks/" + ObjectToStore.PackName + ".DataPack")) ser.Serialize(str, ObjectToStore); }
/// <summary> /// Запись информации приложения /// </summary> /// <returns></returns> public static bool WriteData(bool users = false) { string path = $"{Environment.CurrentDirectory}\\Data.txt"; Classes.Data toWrite = new Classes.Data(); toWrite.LastChoise = new Classes.Data.LastChoiseClass[LastChoise.Count()]; var urls = LastChoise.GetAll(); for (int i = 0; i < urls.Count; i++) { toWrite.LastChoise[i] = new Classes.Data.LastChoiseClass() { url = urls.ElementAt(i).Key, name = urls.ElementAt(i).Value } } ; for (int i = 0; i < LastChoise.Count(); i++) { toWrite.LastChoise[i] = new Classes.Data.LastChoiseClass() { url = LastChoise.Get(i).Key, name = LastChoise.Get(i).Value }; } var FavoriteData = JsonConvert.SerializeObject(toWrite, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); File.WriteAllText(path, FavoriteData, Encoding.UTF8); if (users) { WriteUsers(); } return(true); }
async System.Threading.Tasks.Task LoadPlayerAsync() { //we create a proxy to access the db Final_Project.Player_ServiceRef.SavePlayer_ServiceClient proxy = new Final_Project.Player_ServiceRef.SavePlayer_ServiceClient(); var resultUsername = await proxy.IsUsernameExistsAsync(UsernameText.Text); // we check first if the username exists if (resultUsername) // if he exists we check for the password { var result = await proxy.IsPlayerExistsAsync(UsernameText.Text, PasswordText.Text); // we check if the player exists (with the password if (result) // if he does exist { //we dont know which hearts images to load to so we check var playerResult = await proxy.LoadPlayerAsync(UsernameText.Text, PasswordText.Text); // we load him List <double> ShieldHp = new List <double>() { playerResult.Shield1_HP, playerResult.Shield2_HP, playerResult.Shield3_HP }; // init array of 3 shield hp Image shield_Image_1 = new Image(); // we load the images of the shields //if any things doesnt work create 3 objects shield_Image_1.Source = new BitmapImage(new Uri("ms-appx:///Assets/SpaceShip/Shield.png")); // we load shield images List <Image> Shields_Images = new List <Image>() { shield_Image_1, shield_Image_1, shield_Image_1 }; // to pass for (int i = 0; i < 3; i++) // check for missing shield { if (ShieldHp[i] <= 0) // if shield hp is less then 0 or 0 { Shields_Images[i] = null; // we delete its image } } List <Image> Shields_hp_Images; // we load the hp images of the shields Shields_hp_Images = LoadShieldImages(playerResult.Shield1_Image, playerResult.Shield2_Image, playerResult.Shield3_Image); // we dont know which images to load so we send the number of the image of each shield to load Classes.Data player_data = new Classes.Data(playerResult.Current_Level, playerResult.Coins, playerResult.HP, playerResult.SpaceShip_Level, (Final_Project.Classes.Bullets)playerResult.Bullet_Level, Shields_Images, Shields_hp_Images, ShieldHp, UsernameText.Text, PasswordText.Text, true); Frame.Navigate(typeof(GamePage), player_data); // pass to page after got all data } else // if he doesnt exist - we let him enter new password or create new player { var dialog = new MessageDialog("You have entered a wrong password!\nPlease enter a correct password or create a new player"); dialog.Title = "Couldn't Login!"; dialog.Commands.Add(new UICommand { Label = "OK", Id = 0 }); var ans = await dialog.ShowAsync(); } } else // if the username doesnt exist there is no need to check the password - we just start new game with the given info { Classes.Data player_data = new Classes.Data(); player_data.username = UsernameText.Text; // we only pass username and password player_data.password = PasswordText.Text; player_data.isExitingInDB = false; // but he doesnt exist in the db so we will need to add him player_data.Level = 1; Frame.Navigate(typeof(GamePage), player_data); // we send that he has no data and the data will be create thoughout the game } }