Exemple #1
0
        public void Fluent_ConstructorFileNameVsWithFilenameComparison()
        {
            using (var f = new TempfileLife()) {
                var o = JsonSettings.Configure <CasualExampleSettings>(f.FileName).WithBase64().WithEncryption("SuperPassword").LoadNow();
                var n = JsonSettings.Configure <CasualExampleSettings>().WithFileName(f.FileName).WithBase64().WithEncryption("SuperPassword").LoadNow();

                //validate
                o.FileName.Should().Be(n.FileName);
                TestContext.Out.WriteLine($"{o.FileName} <-> {n.FileName}");
            }
        }
Exemple #2
0
 public JsonSettingsAutosaveInterceptor(JsonSettings settings)
 {
     _settings = settings;
     _settings.Modulation.Attach(_module = new AutosaveModule());
     //populate information
     _monitoredProperties = new HashSet <string>(_settings.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)
                                                 .Where(p => p.GetSetMethod()?.IsVirtual == true &&
                                                        p.GetCustomAttribute <JsonIgnoreAttribute>(true) == null && p.GetCustomAttribute <IgnoreAutosaveAttribute>(true) == null &&
                                                        AutosaveModule._frameworkParameters.All(f => f != p.Name))
                                                 .Select(prop => prop.Name));
 }
Exemple #3
0
            public JsonDecoder(string encoded, JsonSettings settings = null)
            {
                jsonSettings = (settings == null) ? new JsonSettings() : settings;

                this.encoded = encoded;
                if (encoded == null || encoded.Length == 0)
                {
                    return;
                }
                sb  = new StringBuilder();
                len = encoded.Length;
            }
        public static IServiceCollection AddJsonProvider(this IServiceCollection serviceCollection, Action <JsonSettings> jsonSettingsAction = null)
        {
            var jsonSettings = new JsonSettings();

            jsonSettingsAction?.Invoke(jsonSettings);
            serviceCollection.AddSingleton <JsonSettings>(jsonSettings);
            serviceCollection.TryAddSingleton <IContractResolver, DefaultResolver>();
            serviceCollection.TryAddSingleton <IJsonProvider, NewtonsoftJsonProvider>();
            serviceCollection.TryAddSingleton <IContentTypeProvider>(pr => pr.GetRequiredService <IJsonProvider>());
            serviceCollection.TryAddSingleton <JsonSerializer>(pr => pr.GetRequiredService <IJsonProvider>().GetSerializer());
            return(serviceCollection);
        }
Exemple #5
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
 }
Exemple #6
0
 public void SettingsBag_WithEncryption_Autosave()
 {
     using (var f = new TempfileLife()) {
         var o = JsonSettings.Configure <SettingsBag>().WithEncryption("swag").WithFileName(f.FileName).LoadNow().EnableAutosave();
         o.Autosave = true;
         o["lol"]   = "xoxo";
         o["loly"]  = 2;
         var x = JsonSettings.Configure <SettingsBag>().WithEncryption("swag").WithFileName(f.FileName).LoadNow();
         x["lol"].ShouldBeEquivalentTo("xoxo");
         x["loly"].ShouldBeEquivalentTo(2);
     }
 }
Exemple #7
0
        public async Task TestMethod3()
        {
            JsonSettings js = new JsonSettings();

            js.Format = FileFormat.JsonFormatPerLine;
            JsonFileLoader           fp      = new JsonFileLoader(js);
            CancellationTokenSource  ts      = new CancellationTokenSource();
            MessageHandlerForTesting handler = new MessageHandlerForTesting();
            var msgs = await fp.Process("icap_log_2020-06-04T16-16-29_2.json", ts.Token, handler);

            Assert.IsTrue(msgs.Count() == 2);
        }
Exemple #8
0
        public async Task TestMethod2()
        {
            JsonSettings js = new JsonSettings();

            js.Format = FileFormat.JsonFormatFile;
            JsonFileLoader           fp      = new JsonFileLoader(js);
            CancellationTokenSource  ts      = new CancellationTokenSource();
            MessageHandlerForTesting handler = new MessageHandlerForTesting();
            var msgs = await fp.Process("test2.json", ts.Token, handler);

            Assert.IsTrue(msgs.Count() == 1);
        }
Exemple #9
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);
     }
 }
        /// <summary>
        /// Log to MDS when installation/uninstallation finishes
        /// </summary>
        private void LogEndEvent(string id, TimeSpan duration, ITracer tracer, string defaultResult = null)
        {
            SiteExtensionStatus armStatus = new SiteExtensionStatus(_environment.SiteExtensionSettingsPath, id, tracer);
            string filePath    = Path.Combine(_environment.RootPath, "SiteExtensions", id, "SiteExtensionSettings.json");
            var    jsonSetting = new JsonSettings(filePath);

            _analytics.SiteExtensionEvent(
                Request.Method.Method,
                Request.RequestUri.AbsolutePath,
                armStatus.ProvisioningState ?? defaultResult,
                duration.TotalMilliseconds.ToString(),
                jsonSetting.ToString());
        }
        public void IgnoreSavingWhenAbstractPropertyChanges()
        {
            using (var f = new TempfileLife()) {
                bool saved = false;
                var  o     = JsonSettings.Load <Settings>(f.FileName).EnableAutosave();
                o.AfterSave += destinition => {
                    saved = true;
                };

                o.FileName = "test.jsn";
                saved.Should().BeFalse();
            }
        }
        public void NullOrEmptyTest()
        {
            var key      = Guid.NewGuid().ToString();
            var settings = new JsonSettings(GetMockFileSystem(SettingsPath), SettingsPath);

            Assert.Equal(null, settings.GetValue(key));

            settings.SetValue(key, String.Empty);
            Assert.Equal(String.Empty, settings.GetValue(key));

            settings.SetValue(key, null);
            Assert.Equal(null, settings.GetValue(key));
        }
Exemple #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);
     }
 }
Exemple #14
0
 public virtual void Attach(JsonSettings socket)
 {
     if (socket == null)
     {
         throw new ArgumentNullException(nameof(socket));
     }
     if (_isattached)
     {
         throw new ModularityException("The module is already attached.");
     }
     Socket      = new WeakReference <JsonSettings>(socket);
     _isattached = true;
 }
Exemple #15
0
        internal static void smethod_1(object object_0)
        {
            IConfigurable configurable = object_0 as IConfigurable;

            if (configurable != null)
            {
                JsonSettings settings = configurable.Settings;
                if (settings != null)
                {
                    Configuration.Instance.RemoveSettings(settings);
                }
            }
        }
Exemple #16
0
        public void ConstructorTest()
        {
            IFileSystem fileSystem = GetMockFileSystem(SettingsPath);

            var settings = new JsonSettings(SettingsPath);

            Assert.Equal(null, settings.GetValue("non_existing"));

            Assert.Equal(0, settings.GetValues().Count());

            Assert.False(settings.DeleteValue("non_existing"));

            Assert.False(FileSystemHelpers.FileExists(SettingsPath));
        }
        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;
            }
        }
        public void JsonSettings_CreateDefault_Has_Expected_Settings()
        {
            var settings = JsonSettings.CreateDefaults();

            Assert.Equal(settings.NullValueHandling, Newtonsoft.Json.NullValueHandling.Include);
            Assert.Equal(settings.MissingMemberHandling, Newtonsoft.Json.MissingMemberHandling.Ignore);
            Assert.Equal(settings.TypeNameHandling, Newtonsoft.Json.TypeNameHandling.None);
            Assert.Equal(settings.ReferenceLoopHandling, Newtonsoft.Json.ReferenceLoopHandling.Error);
            Assert.Equal(settings.PreserveReferencesHandling, Newtonsoft.Json.PreserveReferencesHandling.None);
            Assert.NotNull(settings.Converters);
            Assert.Equal(2, settings.Converters.Count);
            Assert.IsType <IsoDateTimeConverter>(settings.Converters[0]);
            Assert.IsType <JsonSafeInt64Converter>(settings.Converters[1]);
        }
Exemple #19
0
        public DiagnosticsController(IEnvironment environment, IFileSystem fileSystem)
        {
            // Setup the diagnostics service to collect information from the following paths:
            // 1. The deployments folder
            // 2. The profile dump
            // 3. The npm log
            _paths = new[] {
                environment.DeploymentsPath,
                Path.Combine(environment.RootPath, Constants.LogFilesPath),
                Path.Combine(environment.WebRootPath, Constants.NpmDebugLogFile),
            };

            _settings = new JsonSettings(fileSystem, Path.Combine(environment.DiagnosticsPath, Constants.SettingsJsonFile));
        }
Exemple #20
0
 public void SettingsBag_Passless()
 {
     using (var f = new TempfileLife()) {
         var o = JsonSettings.Configure <SettingsBag>().WithEncryption((string)null).WithFileName(f.FileName).LoadNow();
         ((RijndaelModule)o.Modulation.Modules[0]).Password.ShouldBeEquivalentTo(SecureStringExt.EmptyString);
         o.Autosave = false;
         o["lol"]   = "xoxo";
         o["loly"]  = 2;
         o.Save();
         var x = JsonSettings.Configure <SettingsBag>().WithEncryption((string)null).WithFileName(f.FileName).LoadNow();
         x["lol"].ShouldBeEquivalentTo("xoxo");
         x["loly"].ShouldBeEquivalentTo(2);
     }
 }
Exemple #21
0
        public void Dispose()
        {
            if (_isdisposed)
            {
                return;
            }
            _isdisposed = true;
            foreach (var module in _modules.ToArray())
            {
                module.Dispose();
            }

            _settings = null;
        }
Exemple #22
0
        public async Task DownloadChromium()
        {
            if (File.Exists(_settings.ChromiumPath))
            {
                return;
            }
            Console.WriteLine(MessageResources.DownloadChromiumStart);

            var fetcher = new BrowserFetcher();
            var result  = await fetcher.DownloadAsync(BrowserFetcher.DefaultRevision);

            _settings.ChromiumPath = result.ExecutablePath;
            JsonSettings.Save(_settings, SettingsPath);
        }
Exemple #23
0
        public void Save(JsonSettings settings)
        {
            var json = JsonConvert.SerializeObject(settings, new JsonSerializerSettings
            {
                ContractResolver = new DefaultContractResolver
                {
                    NamingStrategy = new CamelCaseNamingStrategy()
                },
                Formatting = Formatting.Indented
            });

            File.WriteAllText(Path, json);
            Get();
        }
Exemple #24
0
 public static Dictionary <Type, IJsonConverter> GetPrimitiveConverters(JsonSettings settings)
 {
     return(new Dictionary <Type, IJsonConverter>()
     {
         { typeof(int), new IntConverter() },
         { typeof(bool), new BooleanConverter() },
         { typeof(float), new FloatConverter(settings) },
         { typeof(double), new DoubleConverter(settings) },
         { typeof(string), new StringConverter() },
         { typeof(DateTime), new DateTimeConverter(settings) },
         { typeof(Enum), new EnumConverter(settings) },
         { typeof(decimal), new DecimalConverter(settings) }
     });
 }
        public ActionResult Index()
        {
            var results = _confService.GetConfiguraciones().ToList();

            if (!Request.IsAjaxRequest())
            {
                var models = Mapper.Map <List <ConfiguracionSistemaViewModel> >(results);
                return(View(models));
            }
            else
            {
                return(JsonSettings.BuildJsonResult(results));
            }
        }
Exemple #26
0
 public MainSettings() : base(JsonSettings.GetSettingsFilePath(textArray1))
 {
     string[] textArray1 = new string[] { Configuration.Instance.Name, string.Format("{0}.json", "Main") };
     if (this.list_0 == null)
     {
         List <string> list1 = new List <string> {
             "Stats"
         };
         this.list_0 = list1;
     }
     if (this.observableCollection_0 == null)
     {
         this.observableCollection_0 = new ObservableCollection <CustomDeckCache>();
     }
 }
Exemple #27
0
        public static T Unwrap <T>(string jsonString, string propertyToUnwrap = "", bool ignoreCase = true)
        {
            WrapTo <T> data = null;

            if (string.IsNullOrEmpty(propertyToUnwrap))
            {
                data = DN.JsonSerializer.Deserialize <WrapTo <T> >(jsonString, JsonSettings.DotNetJsonSettings(ignoreCase));
                return(data.Result);
            }
            else
            {
                data = NS.JsonConvert.DeserializeObject <WrapTo <T> >(jsonString, JsonSettings.NewtonsoftJsonSettings <WrapTo <T> >(propertyToUnwrap));
                return(data.Result);
            }
        }
        public void Converter_OnFoundCustomData()
        {
            var settings = new JsonSettings {
                TypeConverters = new JsonTypeConverter[] { new CustomDataConverter() }
            };
            var doodle = new Doodle {
                x = 5, y = 7, z = 9
            };
            var json = Json.ToJson(doodle, settings);

            var newDoodle = Json.FromJson <Doodle>(json, settings);

            Assert.AreEqual(2, newDoodle.totalOrphanedKeys);
            Assert.AreNotEqual(doodle.totalOrphanedKeys, newDoodle.totalOrphanedKeys);
        }
Exemple #29
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];
            }
        }
        public static ISettings EnableIAutosave <ISettings>(this JsonSettings settings) where ISettings : class
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }
            _generator = _generator ?? new ProxyGenerator();

            if (!(settings is ISettings))
            {
                throw new InvalidCastException($"Settings class '{settings.GetType().FullName}' does not implement interface '{typeof(ISettings).FullName}'");
            }

            return(_generator.CreateInterfaceProxyWithTarget <ISettings>((ISettings)(object)settings, new JsonSettingsInterceptor(settings)));
        }