Exemplo n.º 1
0
 public void ClassWithoutInterfacesOrVirtuals()
 {
     using (var f = new TempfileLife()) {
         var o = JsonSettings.Load <InvalidSettings>(f.FileName);
         new Action(() => o.EnableAutosave()).ShouldThrow <JsonSettingsException>();
     }
 }
Exemplo n.º 2
0
        public void Saving_Example()
        {
            using (var f = new TempfileLife()) {
                var rpath = JsonSettings.ResolvePath(f);

                StrongBox <int> saved = new StrongBox <int>(0);
                var             o     = JsonSettings.Load <ExampleNotifyingSettings>(f).EnableAutosave();
                saved.Value.Should().Be(0);
                o.AfterSave += (s, destinition) => { saved.Value++; };
                o.Residents.Add("Cookie Monster");                             //Boom! saves.
                saved.Value.Should().Be(1);
                o.Residents = new ObservableCollection <string>();             //Boom! saves.
                saved.Value.Should().Be(2);
                o.Residents.Add("Cookie Monster");                             //Boom! saves.
                saved.Value.Should().Be(3);
                o.NonAutosavingProperty = new ObservableCollection <object>(); //doesn't save
                o.NonAutosavingProperty.Add("Jim");                            //doesn't save
                saved.Value.Should().Be(3);
                o.Street += "-1";                                              //Boom! saves.
                saved.Value.Should().Be(4);
                o.AutoProperty = "Hello";                                      //Boom! saves.
                saved.Value.Should().Be(5);
                o.IgnoredFromAutosaving = "Hello";                             //doesn't save
                saved.Value.Should().Be(5);
            }
        }
Exemplo n.º 3
0
    public void Case2()
    {
        using (var f = new TempfileLife()) {
            StrongBox <bool> saved = new StrongBox <bool>(false);
            var o = JsonSettings.Load <AutosaveTests.Settings>(f.FileName)
                    .EnableAutosave();
            o.AfterSave += (s, destinition) => { saved.Value = true; };
            var module = o.Modulation.GetModule <AutosaveModule>();

            //act
            module.AutosavingState.Should().Be(AutosavingState.Running);

            var suspender = o.SuspendAutosave();
            module.AutosavingState.Should().Be(AutosavingState.Suspended);

            saved.Value.ShouldBeEquivalentTo(false);
            o.property = "hi";
            saved.Value.ShouldBeEquivalentTo(false);
            module.AutosavingState.Should().Be(AutosavingState.SuspendedChanged);
            suspender.Resume();

            //resuming/disposing twice should have any effect
            saved.Value.ShouldBeEquivalentTo(true);
            saved.Value = false;
            suspender.Resume();
            saved.Value.ShouldBeEquivalentTo(false);
        }
    }
Exemplo n.º 4
0
 public void ClassWithInterfacesOrVirtuals()
 {
     using (var f = new TempfileLife()) {
         var o = JsonSettings.Load <Settings>(f.FileName).EnableAutosave();
         o.GetType().Namespace.Should().Be("Castle.Proxies");
     }
 }
Exemplo n.º 5
0
            public void test()
            {
                var settings = JsonSettings.Load <MySettings>("C:/folder/somefile.extension"); //Load from specific location.

                settings.SomeProperty = "somevalue";
                settings.Save();
            }
Exemplo n.º 6
0
            public void test()
            {
                var settings1 = JsonSettings.Load <MySettings>();                               //Load from FileName value in a newly constructed MySettings.
                var settings  = JsonSettings.Load <MySettings>("C:/folder/somefile.extension"); //Load from specific location.

                settings.SomeProperty = "somevalue";
                settings.Save();
            }
Exemplo n.º 7
0
 public void AccessingAfterLoadingAndMarkingAutosave()
 {
     using (var f = new TempfileLife()) {
         var o = JsonSettings.Load <Settings>(f.FileName).EnableAutosave();
         o.property.ShouldBeEquivalentTo(null);
         o.property = "test";
         var o2 = JsonSettings.Load <Settings>(f.FileName).EnableAutosave();
         o2.property.ShouldBeEquivalentTo("test");
     }
 }
Exemplo n.º 8
0
 public void JsonSettings_ModuleLoader()
 {
     using (var f = new TempfileLife()) {
         var o = JsonSettings.Load <ModuleLoadingSttings>(f);
         o.someprop = "1";
         o.Save();
         var x = JsonSettings.Load <ModuleLoadingSttings>(f);
         x.someprop.ShouldBeEquivalentTo("1");
     }
 }
Exemplo n.º 9
0
        public Settings()
        {
            string localAppData   = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            string roamingAppData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

            string localPath   = Path.Combine(localAppData, Core.Name, "LocalSettings.json");
            string roamingPath = Path.Combine(roamingAppData, Core.Name, "RoamingSettings.json");

            Local   = JsonSettings.Load <LocalSettings>(localPath, ConfigSettings);
            Roaming = JsonSettings.Load <RoamingSettings>(roamingPath, ConfigSettings);
        }
Exemplo n.º 10
0
        public void IgnoreSavingWhenAbstractPropertyChanges()
        {
            using (var f = new TempfileLife()) {
                bool saved = false;
                var  o     = JsonSettings.Load <Settings>(f.FileName).EnableAutosave();
                o.AfterSave += (s, destinition) => { saved = true; };

                o.FileName = "test.jsn";
                saved.ShouldBeEquivalentTo(false);
            }
        }
Exemplo n.º 11
0
 public void SettingsBag_Autosave()
 {
     using (var f = new TempfileLife()) {
         var o = JsonSettings.Load <SettingsBag>(f);
         o.Autosave = true;
         o["lol"]   = "xoxo";
         o["loly"]  = 2;
         var x = JsonSettings.Load <SettingsBag>(f);
         x["lol"].ShouldBeEquivalentTo("xoxo");
         x["loly"].ShouldBeEquivalentTo(2);
     }
 }
Exemplo n.º 12
0
 public static void Run(string[] args)
 {
     Settings = JsonSettings.Load <NotifyingSettings>("observable.jsn").EnableAutosave();
     Settings.Residents.Add("Cookie Monster");                             //Boom! saves.
     Settings.Residents = new ObservableCollection <string>();             //Boom! saves.
     Settings.Residents.Add("Cookie Monster");                             //Boom! saves.
     Settings.NonAutosavingProperty = new ObservableCollection <object>(); //doesn't save
     Settings.NonAutosavingProperty.Add("Jim");                            //doesn't save
     Settings.Street               += "-1";                                //Boom! saves.
     Settings.AutoProperty          = "Hello";                             //Boom! saves.
     Settings.IgnoredFromAutosaving = "Hello";                             //doesn't save
 }
Exemplo n.º 13
0
 public void SettingsBag_RegularSave()
 {
     using (var f = new TempfileLife()) {
         var o = JsonSettings.Load <SettingsBag>(f);
         o.Autosave = false;
         o["lol"]   = "xoxo";
         o["loly"]  = 2;
         o.Save();
         var x = JsonSettings.Load <SettingsBag>(f);
         x["lol"].Should().BeEquivalentTo("xoxo");
         x["loly"].Should().BeEquivalentTo(2);
     }
 }
Exemplo n.º 14
0
        private void LoadAppSettings()
        {
            Settings = JsonSettings.Load <SettingsBag>("config.json").EnableAutosave();

            textBoxApiKey.Text      = Settings["key"] as String;
            textBoxServer.Text      = Settings["server"] as String;
            textBoxCutCommand.Text  = Settings.Get("cutcommand", "27.105");
            textBoxOpenCommand.Text = Settings.Get("opencommand", "27.112.48");

            if (Settings.Get("printer", "") != "")
            {
                printersDropdown.SelectedKey = Settings["printer"] as String;
            }
        }
Exemplo n.º 15
0
        public Bot(MainForm form)
        {
            this.IsRunning = false;
            clickPoint     = new Point(0, 0);
            fishCount      = 0;
            this.form      = form;

            Settings = JsonSettings.Load <SettingsManager>();

            Process[] plist = Process.GetProcessesByName("Wow-64");
            if (plist.Length > 0)
            {
                SelectedProcess = plist[0];
            }
        }
Exemplo n.º 16
0
        public void SavingInterface()
        {
            using (var f = new TempfileLife()) {
                var       rpath = JsonSettings.ResolvePath(f);
                ISettings o     = JsonSettings.Load <InterfacedSettings>(f.FileName).EnableIAutosave <InterfacedSettings, ISettings>();

                Console.WriteLine(File.ReadAllText(rpath));
                o.property.ShouldBeEquivalentTo(null);
                o.property = "test";
                var o2 = JsonSettings.Load <InterfacedSettings>(f.FileName);
                o2.property.ShouldBeEquivalentTo("test");

                var jsn = File.ReadAllText(rpath);
                jsn.Contains("\"test\"").Should().BeTrue();
                Console.WriteLine(jsn);
            }
        }
Exemplo n.º 17
0
        public void SettingsBag_List()
        {
            using (var f = new TempfileLife()) {
                var o = JsonSettings.Load <SettingsBag>(f.FileName);

                o["prop"] = new List <string>()
                {
                    "swag", "lol"
                };
                o.Save();
                Console.WriteLine(File.ReadAllText(o.FileName));
                var o2  = JsonSettings.Load <SettingsBag>(f.FileName);
                var ret = o2["prop"];
                ret.Should().BeOfType <List <string> >();
                ((List <string>)ret).Count.Should().Be(2);
            }
        }
Exemplo n.º 18
0
        public void CreateNonExistingSettings()
        {
            var path = JsonSettings.ResolvePath(new Settings(), "swag.json", true);

            using (var f = new TempfileLife(path)) {
                if (File.Exists(f))
                {
                    File.Delete(f);
                }
                File.Exists(f).Should().BeFalse();
                var o = JsonSettings.Load <Settings>(f);
                o.Str = "lol";
                File.Exists(f).Should().BeTrue();
                o.Save();
                File.Exists(f).Should().BeTrue();
            }
        }
        public void DynamicSettingsBag_DynamicAccess_Index()
        {
            using (var f = new TempfileLife()) {
                var     o = JsonSettings.Load <SettingsBag>(f);
                dynamic d = o.AsDynamic();
                d.SomeProp = "Works";
                Assert.True(d["SomeProp"] == "Works");
                d.Num = 1;
                Assert.True(d.Num == 1);
                SettingsBag bag = d.AsBag();
                bag.Save();

                o = JsonSettings.Load <SettingsBag>(f);
                o["SomeProp"].Should().Be("Works");
                o["Num"].Should().Be(1L); //newtonsoft deserializes numbers as long.
            }
        }
Exemplo n.º 20
0
        public void Use_Configure_CasualSettingsExample_LoadSelf()
        {
            using (var f = new TempfileLife()) {
                //load using Load      with configuration and custom constructor and password fetcher from one of the class's property.
                var o = JsonSettings.Load <CasualExampleSettings>(f.FileName, s => s.WithBase64().WithEncryption(set => set.SomeProperty), new object[] { "SuperPassword" });
                o.SomeNumeralProperty = 1;
                o.SomeClassProperty   = new SmallClass()
                {
                    Name = "Small", Value = "Class"
                };
                o.Save();

                //validate
                o = JsonSettings.Load <CasualExampleSettings>(f.FileName, s => s.WithBase64().WithEncryption(set => set.SomeProperty), new object[] { "SuperPassword" });
                o.SomeProperty.Should().Be("SuperPassword");
                o.SomeNumeralProperty.ShouldBeEquivalentTo(1);
                o.SomeClassProperty.Should().BeOfType(typeof(SmallClass)).And.Match(obj => (obj as SmallClass).Name == "Small");
            }
        }
Exemplo n.º 21
0
        public void Use_SettingsBag_AutoSave()
        {
            using (var f = new TempfileLife()) {
                //used for autodelete file after test ends
                var o = JsonSettings.Load <SettingsBag>(f.FileName).EnableAutosave();
                o["somekey"]         = "with some value";
                o["someotherkey"]    = 1;
                o["somekeyforclass"] = new SmallClass()
                {
                    Name = "Small", Value = "Class"
                };

                //validate
                o = JsonSettings.Load <SettingsBag>(f.FileName);
                o["somekey"].Should().Be("with some value");
                o["someotherkey"].ShouldBeEquivalentTo(1);
                o["somekeyforclass"].Should().BeOfType(typeof(SmallClass)).And.Match(obj => (obj as SmallClass).Name == "Small");
            }
        }
Exemplo n.º 22
0
        private void ReloadSpeakers()
        {
            //string sp = bot.GetSpeakers();

            bot.GetSpeakers();

            speakers = JsonSettings.Load <Speakers>();
            speakers.Save();

            speakersCB.Items.Clear();
            speakersCB.ResetText();
            speakersCB.SelectedItem  = null;
            speakersCB.SelectedIndex = -1;

            if (speakers.DeviceList.Count > 0)
            {
                LoadSpeakers();
            }
        }
Exemplo n.º 23
0
        public void Use_Configure_CasualSettingsExample_Load()
        {
            using (var f = new TempfileLife()) {
                //load using Load      with configuration
                var o = JsonSettings.Load <CasualExampleSettings>(f.FileName, s => s.WithBase64().WithEncryption("SuperPassword"));
                o.SomeNumeralProperty = 1;
                o.SomeProperty        = "with some value";
                o.SomeClassProperty   = new SmallClass()
                {
                    Name = "Small", Value = "Class"
                };
                o.Save();

                //validate
                o = JsonSettings.Load <CasualExampleSettings>(f.FileName, s => s.WithBase64().WithEncryption("SuperPassword"));
                o.SomeProperty.Should().Be("with some value");
                o.SomeNumeralProperty.ShouldBeEquivalentTo(1);
                o.SomeClassProperty.Should().BeOfType(typeof(SmallClass)).And.Match(obj => (obj as SmallClass).Name == "Small");
            }
        }
Exemplo n.º 24
0
        public void Use_MostBasic()
        {
            using (var f = new TempfileLife()) {
                //used for autodelete file after test ends
                var o = JsonSettings.Load <CasualExampleSettings>(f.FileName);
                o.SomeNumeralProperty = 1;
                o.SomeProperty        = "with some value";
                o.SomeClassProperty   = new SmallClass()
                {
                    Name = "Small", Value = "Class"
                };
                o.Save();

                //validate
                o = JsonSettings.Load <CasualExampleSettings>(f.FileName);
                o.SomeProperty.Should().Be("with some value");
                o.SomeNumeralProperty.ShouldBeEquivalentTo(1);
                o.SomeClassProperty.Should().BeOfType(typeof(SmallClass)).And.Match(obj => (obj as SmallClass).Name == "Small");
            }
        }
Exemplo n.º 25
0
        static void Main(string[] args)
        {
            try
            {
                var parsed = Args.Parse <UserArgs>(args);
            }
            catch (ArgException ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ArgUsage.GenerateUsageFromTemplate <UserArgs>());
                return;
            }

            var settings = JsonSettings.Load <RulesConfig>();

            foreach (var rule in settings.Rules)
            {
                HandleRule(rule);
            }
        }
Exemplo n.º 26
0
        public void Saving()
        {
            using (var f = new TempfileLife()) {
                var rpath = JsonSettings.ResolvePath(f);

                bool saved = false;
                var  o     = JsonSettings.Load <Settings>(f.FileName).EnableAutosave();
                o.AfterSave += (s, destinition) => { saved = true; };
                o.property.ShouldBeEquivalentTo(null);
                Console.WriteLine(File.ReadAllText(rpath));

                o.property = "test";
                saved.ShouldBeEquivalentTo(true);
                var o2 = JsonSettings.Load <Settings>(f.FileName).EnableAutosave();
                o2.property.ShouldBeEquivalentTo("test");
                var jsn = File.ReadAllText(rpath);
                jsn.Contains("\"test\"").Should().BeTrue();
                Console.WriteLine(jsn);
            }
        }
Exemplo n.º 27
0
        public void OverrideExistingBySmallerSettingsFile()
        {
            var path = JsonSettings.ResolvePath(new SettingsLarger(), "swaggy.json", true);

            using (var f = new TempfileLife(path)) {
                if (File.Exists(f))
                {
                    File.Delete(f);
                }
                File.Exists(f).Should().BeFalse();

                var o = JsonSettings.Load <SettingsLarger>(f);
                o.Str = o.Str2 = o.Str3 = "lol";
                o.Save();

                File.Exists(f).Should().BeTrue();
                var o2 = JsonSettings.Load <Settings>(f);
                o2.Str.ShouldBeEquivalentTo("lol");
            }
        }
Exemplo n.º 28
0
        public void SuspendAutosaving_Case1()
        {
            using (var f = new TempfileLife()) {
                var o = JsonSettings.Load <SettingsBag>(f);

                dynamic d = o.AsDynamic();

                d.SomeProp = "Works";
                d.Num      = 1;
                Assert.IsTrue(d["SomeProp"] == "Works");
                Assert.IsTrue(d.Num == 1);

                o.Save();
                o = JsonSettings.Configure <SettingsBag>(f)
                    .LoadNow()
                    .EnableAutosave();

                o["SomeProp"].Should().Be("Works");
                o["Num"].Should().Be(1L); //newtonsoft deserializes numbers as long.
                StrongBox <int> a = new StrongBox <int>();
                o.AfterSave += (sender, destinition) => { a.Value++; };

                using (o.SuspendAutosave()) {
                    o["SomeProp"] = "Works2";
                    o["Num"]      = 2;
                    a.Value.Should().Be(0);
                    var k = JsonSettings.Load <SettingsBag>(f);
                    k["SomeProp"].Should().Be("Works");
                    k["Num"].Should().Be(1L); //newtonsoft deserializes numbers as long.
                    a.Value.Should().Be(0);
                }

                a.Value.Should().Be(1);

                var kk = JsonSettings.Load <SettingsBag>(f);
                kk["SomeProp"].Should().Be("Works2");
                kk["Num"].Should().Be(2L); //newtonsoft deserializes numbers as long.
            }
        }
Exemplo n.º 29
0
        public MainForm()
        {
            InitializeComponent();

            red      = Color.FromArgb(231, 76, 60);
            green    = Color.FromArgb(39, 174, 96);
            blue     = Color.FromArgb(41, 128, 185);
            disabled = Color.FromArgb(127, 140, 141);

            processes = new List <Process>();
            bot       = new Bot(this);
            speakers  = JsonSettings.Load <Speakers>();

            if (bot.Settings.FishingKey != Keys.None)
            {
                keyTB.Text         = bot.Settings.FishingKey.ToString();
                startBtn.Enabled   = true;
                startBtn.BackColor = blue;
            }

            LoadProcesses();
            LoadSpeakers();
        }
Exemplo n.º 30
0
        public DataManager(IGameDataRepository gameDataRepository, IMapper mapper)
        {
            _gameDataRepository = gameDataRepository;
            _mapper             = mapper;

            string path = $"{AppDomain.CurrentDomain.BaseDirectory}{_settings.FileName}";

            if (!File.Exists(path))
            {
                _settings = JsonSettings.Construct <Settings>();
                _settings.SetDefaultValues();
                _settings.Save();
            }

            try
            {
                _settings = JsonSettings.Load <Settings>(_settings.FileName);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
        }