Exemple #1
0
        private PreferenceData Migrate()
        {
            Logger.Info("Attempting to migrate from user settings...");

            PreferenceData data = null;

            try
            {
                data = MigrateFromUserSettings.Execute();
                if (data != null)
                {
                    Write(data);
                }
            }
            catch (Exception ex)
            {
                Logger.Warn(ex.Message, ex);
            }

            if (data != null)
            {
                Logger.InfoFormat("Migration from version {0} user settings complete.", data.ApplicationVersion);
            }
            else
            {
                Logger.Info("Could not migrate from user settings.  Default settings will be applied.");
            }
            return(data);
        }
Exemple #2
0
 private static void ExecuteVersionUpgrades(Version settingsVersion, PreferenceData data)
 {
     foreach (var upgrade in CreateVersionUpgrades().Where(upgrade => settingsVersion < upgrade.Version))
     {
         upgrade.Action(data);
     }
 }
        public void SavePreferenceData(PreferenceData preferenceData)
        {
            try
            {
                IAsyncResult device = StorageDevice.BeginShowSelector(PlayerIndex.One, null, null);
                device.AsyncWaitHandle.WaitOne();
                StorageDevice storageDevice = StorageDevice.EndShowSelector(device);

                if (storageDevice.IsConnected && storageDevice != null)
                {
                    IAsyncResult result = storageDevice.BeginOpenContainer("A Troll in the Hay Data", null, null);
                    result.AsyncWaitHandle.WaitOne();
                    StorageContainer container = storageDevice.EndOpenContainer(result);
                    result.AsyncWaitHandle.Close();

                    if (container.FileExists(""))//come edit the file name
                    {
                        container.DeleteFile("");
                    }

                    Stream        stream     = container.CreateFile("");
                    XmlSerializer serializer = new XmlSerializer(typeof(PreferenceData));
                    serializer.Serialize(stream, preferenceData);
                    stream.Close();
                    container.Dispose();
                }
                Console.WriteLine("Preference data save complete!");
            }
            catch
            {
                Console.WriteLine("ERROR! PREFERENCE SAVE FAILED!!!");
            }
        }
        public void XmlPreferencesProvider_Load_FromConfigFile_Test()
        {
            // Arrange
            using (var artifacts = new ArtifactFolder())
            {
                const string applicationVersion = "1.0.0.0";
                string       configPath         = Path.Combine(artifacts.Path, "config.xml");

                // write a config.xml file
                var data = new PreferenceData {
                    ApplicationVersion = applicationVersion
                };
                data.ApplicationSettings.CacheFolder = "foo";
                using (var fileStream = new FileStream(Path.Combine(artifacts.Path, "config.xml"), FileMode.Create, FileAccess.Write))
                    using (var xmlWriter = XmlWriter.Create(fileStream, new XmlWriterSettings {
                        Indent = true
                    }))
                    {
                        var serializer = new DataContractSerializer(typeof(PreferenceData));
                        serializer.WriteObject(xmlWriter, data);
                    }

                var prefs = Create(artifacts.Path, applicationVersion);
                // Act
                prefs.Load();
                // Assert
                Assert.IsTrue(File.Exists(configPath));
                Assert.AreEqual(applicationVersion, prefs.ApplicationVersion);
                Assert.AreEqual(applicationVersion, prefs.Get <string>(Preference.ApplicationVersion));
                Assert.AreEqual("foo", prefs.Get <string>(Preference.CacheFolder));
            }
        }
Exemple #5
0
 private void ExecuteUpgrades(Version settingsVersion, PreferenceData data)
 {
     foreach (var upgrade in EnumerateUpgrades().Where(upgrade => settingsVersion < upgrade.Version))
     {
         upgrade.Action(data);
     }
 }
Exemple #6
0
        public void Save(PreferenceData data)
        {
            string json = serializer.Serialize(data, true);

            File.WriteAllText(data.PreferenceLocation, json);
            data.IsDirty = false;
        }
            protected override PreferenceData OnMigrateFromUserSettings()
            {
                var data = new PreferenceData();

                data.UserSettings.StanfordId = "Foo";
                return(data);
            }
            protected override PreferenceData OnRead()
            {
                var data = new PreferenceData();

                data.ApplicationVersion = "0.0.0.0";
                data.ApplicationSettings.ProjectDownloadUrl = String.Empty;
                return(data);
            }
 public void AddPreferenceRequest(PreferenceData data)
 {
     lock (_preferenceRequests)
     {
         _preferenceRequests.Clear();
         _preferenceRequests.Add(data); // this might not be correct? maybe only take last one?
     }
 }
Exemple #10
0
        public override void EnterMenu(MenuPageNames name, PreferenceData data)
        {
            UnhideAllButtons();
            UpdateWithPreferenceData(data);

            _currentButton = _titleButton;
            _currentButton.Highlight();
        }
 // Start is called before the first frame update
 void Start()
 {
     foreach (int i in playing)
     {
         CreatePlayer(i, PreferenceData.GetLoc(i));
         lives[i] = PreferenceData.GetMaxLives();
     }
 }
Exemple #12
0
        public void Reset()
        {
            var data = new PreferenceData {
                ApplicationVersion = ApplicationVersion
            };

            Write(data);
            _prefs = CreateDictionary(data);
        }
        private void ExecutePreferenceRequest(PreferenceData data)
        {
            if (data == null)
            {
                return;
            }

            _saveLoadHandler.SavePreferenceData(data);
        }
Exemple #14
0
 void Awake()
 {
     //setting basic things, "Hide" disables the object (game not started yet)
     MAX_HEALTH           = PreferenceData.GetMaxHealth();
     rigidBody            = GetComponent <Rigidbody>();
     playerDeathEventArgs = new PlayerDeathEventArgs();
     ALIVE = false;
     Hide();
 }
 public ExpressionMetadata(PreferenceData data, Expression <Func <PreferenceData, T> > propertyExpression, bool readOnly)
 {
     _data   = data;
     _getter = propertyExpression.Compile();
     if (!readOnly)
     {
         _setter = propertyExpression.ToSetter();
     }
 }
 public void ResetGame()
 {
     winScreen.enabled = false;
     foreach (int i in playing)
     {
         lives[i] = PreferenceData.GetMaxLives();
         players[i].GetComponent <PlayerControl>().ResetPlayer();
         Update_text_lives();
     }
 }
Exemple #17
0
        private void CacheFilePreference(string filePath)
        {
            string         content     = File.ReadAllText(filePath);
            PreferenceData preferences = serializer.Deserialize(content);

            if (preferences != null)
            {
                cache.Set(preferences.GetType(), preferences);
            }
        }
Exemple #18
0
        public void PreferenceSet_Set_StringAsEnum_Test()
        {
            // Arrange
            var data  = new PreferenceData();
            var prefs = new InMemoryPreferenceSet(data);

            // Act
            prefs.Set(Preference.BonusCalculation, BonusCalculation.Default);
            // Assert
            Assert.AreEqual("Default", data.ApplicationSettings.BonusCalculation);
        }
        public void PreferencesProvider_Set_Int32AsEnum_Test()
        {
            // Arrange
            var data  = new PreferenceData();
            var prefs = new MockPreferencesProvider(data);

            // Act
            prefs.Set(Preference.MessageLevel, LoggerLevel.Debug);
            // Assert
            Assert.AreEqual((int)LoggerLevel.Debug, data.ApplicationSettings.MessageLevel);
        }
        protected PreferencesProvider(string applicationPath, string applicationDataFolderPath, string applicationVersion)
        {
            ApplicationPath           = applicationPath;
            ApplicationDataFolderPath = applicationDataFolderPath;
            ApplicationVersion        = applicationVersion;

            var data = new PreferenceData {
                ApplicationVersion = ApplicationVersion
            };

            _prefs = CreateDictionary(data);
        }
Exemple #21
0
    //Using the ID, reads appropriate key names from "PreferenceData" and sets own parts (jets/sword) to respond to those keys.
    public void  UpdateKeys()
    {
        keyLeft  = PreferenceData.GetLeft(playerID);
        keyRight = PreferenceData.GetRight(playerID);
        keyUp    = PreferenceData.GetUp(playerID);
        jetLeftobj.GetComponent <JetControl>().SetKey(keyRight);
        jetRightobj.GetComponent <JetControl>().SetKey(keyLeft);
        swordobj.GetComponent <SwordControl>().SetKey(keyUp);

        //sets the color (in the future- skin/color/etc.) of this player by ID
        eggShellobj.GetComponent <EggControl>().setMat(playerID);
    }
Exemple #22
0
        public void PreferenceSet_Set_String_Test()
        {
            var data  = new PreferenceData();
            var prefs = new InMemoryPreferenceSet(data);

            prefs.Set(Preference.EmailReportingFromAddress, (string)null);
            Assert.AreEqual(null, data.Email.FromAddress);
            prefs.Set(Preference.EmailReportingFromAddress, "*****@*****.**");
            Assert.AreEqual("*****@*****.**", data.Email.FromAddress);
            prefs.Set(Preference.EmailReportingFromAddress, "*****@*****.**");
            Assert.AreEqual("*****@*****.**", data.Email.FromAddress);
        }
        public void PreferencesProvider_Get_StringAsEnum_ReturnsEnumDefaultWhenParsingFails_Test()
        {
            // Arrange
            var data = new PreferenceData();

            data.ApplicationSettings.BonusCalculation = "Foo";
            var prefs = new MockPreferencesProvider(data);
            // Act
            var value = prefs.Get <BonusCalculation>(Preference.BonusCalculation);

            // Assert
            Assert.AreEqual(BonusCalculation.Default, value);
        }
        public void PreferencesProvider_RoundTripEncryptedPreference_Test()
        {
            // Arrange
            const string value = "fizzbizz";
            var          data  = new PreferenceData();
            var          prefs = new MockPreferencesProvider(data);

            // Act
            prefs.Set(Preference.WebGenPassword, value);
            // Assert
            Assert.AreNotEqual(value, data.WebDeployment.FtpServer.Password);
            Assert.AreEqual(value, prefs.Get <string>(Preference.WebGenPassword));
        }
Exemple #25
0
        private static void Write(PreferenceData data)
        {
            string path = Path.Combine(ApplicationDataFolderPath, "config.xml");

            using (var fileStream = new FileStream(path, FileMode.Create, FileAccess.Write))
                using (var xmlWriter = XmlWriter.Create(fileStream, new XmlWriterSettings {
                    Indent = true
                }))
                {
                    var serializer = new DataContractSerializer(typeof(PreferenceData));
                    serializer.WriteObject(xmlWriter, data);
                }
        }
        public void PreferencesProvider_Get_NullStringAsEnum_ReturnsEnumDefaultWhenValueIsNull_Test()
        {
            // Arrange
            var data = new PreferenceData();

            data.WebDeployment.FtpMode = null;
            var prefs = new MockPreferencesProvider(data);
            // Act
            var value = prefs.Get <FtpMode>(Preference.WebGenFtpMode);

            // Assert
            Assert.AreEqual(FtpMode.Default, value);
        }
Exemple #27
0
        private void StringPreference_Click(object sender, RoutedEventArgs e)
        {
            MenuItem                 callingMenu    = sender as MenuItem;
            PreferenceData           preferenceData = callingMenu.CommandParameter as PreferenceData;
            StringPreferenceDelegate callback       = preferenceData.Callback;
            string selectedOption = callingMenu.Header.ToString();

            callback(selectedOption);

            //Store the preference
            settingsDictionary[preferenceData.Name] = selectedOption;
            settingsDictionary.Save();
        }
        public void PreferencesProvider_Get_Int32AsEnum_Test()
        {
            // Arrange
            var data = new PreferenceData();

            data.ApplicationSettings.MessageLevel = (int)LoggerLevel.Info;
            var prefs = new MockPreferencesProvider(data);
            // Act
            var value = prefs.Get <LoggerLevel>(Preference.MessageLevel);

            // Assert
            Assert.AreEqual(LoggerLevel.Info, value);
        }
        public void PreferencesProvider_Get_StringAsEnum_Test()
        {
            // Arrange
            var data = new PreferenceData();

            data.ApplicationSettings.BonusCalculation = "DownloadTime";
            var prefs = new MockPreferencesProvider(data);
            // Act
            var value = prefs.Get <BonusCalculation>(Preference.BonusCalculation);

            // Assert
            Assert.AreEqual(BonusCalculation.DownloadTime, value);
        }
        public void PreferenceSet_Get_NullStringAsEnum_ReturnsEnumDefaultWhenParsingFails_Test()
        {
            // Arrange
            var data = new PreferenceData();

            data.WebDeployment.FtpMode = null;
            var prefs = new InMemoryPreferenceSet(data);
            // Act
            var value = prefs.Get <FtpMode>(Preference.WebGenFtpMode);

            // Assert
            Assert.AreEqual(FtpMode.Default, value);
        }
        void flickrUserName_PreferenceChanged(PreferenceData preferenceData)
        {
            // set the properties internally
            if (preferenceData.GetType() == typeof(FlickrUsernameData))
            {
                FlickrUsernameData flickrUsernameData = preferenceData as FlickrUsernameData;
                this.CurrentFlickrEmail = flickrUsernameData.FlickrUsername;
            }

            // send a message to clients
            if (this.PreferenceChanged != null)
            {
                this.PreferenceChanged(preferenceData);
            }
        }