public void DownloadCacheDirPersistsNull() { string tmpFile1 = Path.GetTempFileName(); var reg = new JsonConfiguration(tmpFile1); reg.DownloadCacheDir = null; string tmpFile2 = Path.GetTempFileName(); File.Copy(tmpFile1, tmpFile2, true); reg = new JsonConfiguration(tmpFile2); Assert.AreEqual(JsonConfiguration.DefaultDownloadCacheDir, reg.DownloadCacheDir); File.Delete(tmpFile1); File.Delete(tmpFile2); }
public void DownloadCacheDirPersistsUnrooted() { string tmpFile1 = Path.GetTempFileName(); var reg = new JsonConfiguration(tmpFile1); reg.DownloadCacheDir = "file"; string tmpFile2 = Path.GetTempFileName(); File.Copy(tmpFile1, tmpFile2, true); reg = new JsonConfiguration(tmpFile2); Assert.AreEqual(Path.GetFullPath("file"), reg.DownloadCacheDir); File.Delete(tmpFile1); File.Delete(tmpFile2); }
public static void Main() { AppDomain.CurrentDomain.UnhandledException += (sender, e) => _log.Error(e.ExceptionObject as Exception); var app = new App(); Configuration = new JsonConfiguration("appsettings.json"); // check if BoxVRExePath is already set, if not try to locate it via registry or Steam if (string.IsNullOrWhiteSpace(Configuration.BoxVRExePath)) { _log.Debug("Starting search for BoxVR install location"); var location = LocateBoxVRExe(); _log.Debug($"Automatic search for BoxVR install location complete: {location}"); if (!string.IsNullOrWhiteSpace(location)) { _log.Debug("Saving BoxVRExePath setting"); Configuration.BoxVRExePath = location; //BoxVRPlaylistManagerNETCore.Properties.Settings.Default.Save(); } } _log.Debug($"BoxVRExePath setting: {Configuration.BoxVRExePath}"); // check if BoxVRAppDataPath is already set, if not set to default if (string.IsNullOrWhiteSpace(Configuration.BoxVRAppDataPath)) { _log.Debug("BoxVRAppDataPath not set, setting default"); if (Directory.Exists(Environment.ExpandEnvironmentVariables(DEFAULT_BOXVR_APPDATA))) { Configuration.BoxVRAppDataPath = DEFAULT_BOXVR_APPDATA; //BoxVRPlaylistManagerNETCore.Properties.Settings.Default.Save(); } else { _log.Debug($"Directory does not exist: {DEFAULT_BOXVR_APPDATA}"); } } _log.Debug($"BoxVRAppDataPath setting: {Configuration.BoxVRAppDataPath}"); var mainWindow = new MainWindow(); app.Run(mainWindow); }
public void LoadsGoodConfig() { string tmpFile = Path.GetTempFileName(); File.WriteAllText(tmpFile, TestData.GoodJsonConfig()); var reg = new JsonConfiguration(tmpFile); CollectionAssert.AreEquivalent(new List <Tuple <string, string> >() { new Tuple <string, string>("instance1", "instance1_path"), new Tuple <string, string>("instance2", "instance2_path") }, reg.GetInstances()); CollectionAssert.AreEquivalent(new List <string>() { "host1", "host2", "host3" }, reg.GetAuthTokenHosts()); var token = ""; Assert.IsTrue(reg.TryGetAuthToken("host1", out token)); Assert.AreEqual("token1", token); Assert.IsTrue(reg.TryGetAuthToken("host2", out token)); Assert.AreEqual("token2", token); Assert.IsTrue(reg.TryGetAuthToken("host3", out token)); Assert.AreEqual("token3", token); Assert.AreEqual("asi", reg.AutoStartInstance); Assert.AreEqual("dci", reg.DownloadCacheDir); Assert.AreEqual(2, reg.CacheSizeLimit); Assert.AreEqual(4, reg.RefreshRate); CollectionAssert.AreEquivalent(new Dictionary <string, string>() { { "build1", "version1" }, { "build2", "version2" } }, reg.GetKSPBuilds().Builds); File.Delete(tmpFile); }
private void InitConfig() { var path = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var configPath = System.IO.Path.Combine(path, "config", "AppConfig.json"); if (!System.IO.File.Exists(configPath)) { WpfUtils.DialogUtils.Alert("Configurare il path del file .json"); } else { config = ExternalConfig.GetConfig <JsonConfiguration>(configPath); if (string.IsNullOrEmpty(config.QuartzConfigPath) || !System.IO.File.Exists(config.QuartzConfigPath)) { WpfUtils.DialogUtils.Alert("Configurare il path del file .json"); config = null; } } }
public void SetConfig(JsonData data) { int index = -1; int.TryParse(data ["index"].ToString(), out index); if (index >= containor.Count) { ResourceGroup rg = new ResourceGroup(manager); rg.LoadConfig(data["data"]); AddResourceGroup(rg); Data["list"].Add(data ["data"]); } else { Data ["list"][index] = data ["data"]; } Debug.Log(Data.ToJson()); JsonConfiguration.WriteData(Data, Paths.RESOURCE_GROUP); }
public void should_inject_key_for_encryption() { // given var configuration = new JsonConfiguration() { EncryptionKey = "my-password" }; var configStore = new ConfigurationStoreMock(); configStore.Configuration = configuration; IContainer container = GetContainer(configStore); // when var encryptionInstance = container.GetInstance <IEncryption>() as AesEncryption; // then Assert.That(encryptionInstance, Is.Not.Null); Assert.That(encryptionInstance.Password, Is.EqualTo("my-password")); }
public void TestJsonLoading() { JsonConfiguration config = (JsonConfiguration)GetConfig(); string json = "{" + "\"Test1\": \"A\"," + "\"NestedObjectTest\": {" + "\"NestedStringValue\": \"B\"," + "\"NestedNumberValue\": 4," + "\"VeryNestedObject\": {" + "\"Value\": \"3\"" + "}" + "}" + "}"; config.LoadFromJson(json); AssertConfigEquality(config); AssertSaveException(config); }
public void should_read_text_file() { // given string typeDirectory = Path.Combine(_snippetDirectory, ScriptSnippetType.BeforeExecute.ToString().ToLower()); string filename1 = Path.Combine(typeDirectory, "snippet1.snippet"); File.WriteAllText(filename1, "snippet 1"); var config = new JsonConfiguration(); config.ScriptSnippetDirectory = _snippetDirectory; var snippetReader = new SnippetFileReader(config); // when string snippetText = snippetReader.ReadFile(filename1); // then Assert.That(snippetText, Is.EqualTo("snippet 1")); }
/// <summary> /// Get the Configuration of a selected database with the selected parameters. /// </summary> /// <returns></returns> private IConfiguration GetConfiguration() { IConfiguration extractConf; if (Constants.DatabaseTypeStrings[(int)DatabaseType.JsonExample] == cbDatabaseType.Text) { if (string.IsNullOrWhiteSpace(_jsonFileContent)) { extractConf = new JsonConfiguration(); } else { extractConf = new JsonConfiguration(_jsonFileContent); } } else if (Constants.DatabaseTypeStrings[(int)DatabaseType.MongoDb] == cbDatabaseType.Text) { extractConf = new MondoDbConfiguration(txtMongodbConnectionString.Text, txtMongodbDatabase.Text); } else if (Constants.DatabaseTypeStrings[(int)DatabaseType.DocumentDb] == cbDatabaseType.Text) { extractConf = new DocumentDbConfiguration(txtDocumentdbEndPoint.Text, txtDocumentdbAuthKey.Text, txtDocumentDbDatabase.Text); } else if (Constants.DatabaseTypeStrings[(int)DatabaseType.DynamoDb] == cbDatabaseType.Text) { extractConf = new DynamoDbConfiguration(txtDynamoDbAccessKey.Text, txtDynamoDbSecretKey.Text, txtDynamoDbRegion.Text); } else { MessageBox.Show("Invalid selected database", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); extractConf = null; } return(extractConf); }
public void EvaluateBeforeExecute_should_call_read_with_snippet_type_in_the_path() { // given var snippetReader = new Mock <ISnippetFileReader>(); var configuration = new JsonConfiguration(); configuration.ScriptSnippetDirectory = @"C:\foo"; var evaluator = new TestFileScriptEvaluator(configuration, snippetReader.Object); var test = new Test(); test.ScriptSnippets.BeforeExecuteFilename = "path-doesnt-matter.snippet"; string typeName = ScriptSnippetType.BeforeExecute.ToString().ToLower(); string expectedPath = Path.Combine(configuration.ScriptSnippetDirectory, typeName, test.ScriptSnippets.BeforeExecuteFilename); // when evaluator.EvaluateBeforeExecute(test, new RestRequest()); // then snippetReader.Verify(x => x.ReadFile(expectedPath)); }
public static void StartSelfHostedOwin() { var jsonConfiguration = new JsonConfiguration() { MongoDbDatabaseName = MongodbDatabaseName, TestFilesBaseDirectory = TestFilesDirectoryPath, ScriptSnippetDirectory = ScriptSnippetDirectoryPath, ServiceUrl = BaseUrl }; StopSelfHostedOwin(); // Use the service's IoC container Container = IoC.Initialize(); Container.Configure(x => x.For <IConfiguration>().Use(jsonConfiguration)); // Inject instances into it var service = new Startup(Container.GetInstance <IDependencyResolver>(), jsonConfiguration, Container.GetInstance <IJob>()); // Start it up OwinServer = WebApp.Start(BaseUrl, service.Configuration); }
public void LoadsMissingJsonConfig() { string tmpFile = Path.GetTempFileName(); File.WriteAllText(tmpFile, TestData.MissingJsonConfig()); var reg = new JsonConfiguration(tmpFile); CollectionAssert.AreEquivalent(new List <Tuple <string, string, string> >() { new Tuple <string, string, string>("instance1", "instance1_path", "KSP"), new Tuple <string, string, string>("instance2", "instance2_path", "KSP") }, reg.GetInstances()); CollectionAssert.AreEquivalent(new List <string>(), reg.GetAuthTokenHosts()); Assert.AreEqual("", reg.AutoStartInstance); Assert.AreEqual(JsonConfiguration.DefaultDownloadCacheDir, reg.DownloadCacheDir); Assert.AreEqual(null, reg.CacheSizeLimit); Assert.AreEqual(4, reg.RefreshRate); File.Delete(tmpFile); }
public void should_return_empty_list_when_snippet_sub_directory_does_not_exist() { // given string typeDirectory = Path.Combine(_snippetDirectory, ScriptSnippetType.BeforeExecute.ToString().ToLower()); try { Directory.Delete(typeDirectory); } catch (IOException) { } var config = new JsonConfiguration(); config.ScriptSnippetDirectory = _snippetDirectory; var snippetReader = new SnippetFileReader(config); // when IEnumerable <string> files = snippetReader.GetSnippetFilenames(ScriptSnippetType.BeforeExecute); // then Assert.That(files.Count(), Is.EqualTo(0)); }
public void should_get_snippet_filenames_from_directory() { // given string typeDirectory = Path.Combine(_snippetDirectory, ScriptSnippetType.BeforeExecute.ToString().ToLower()); string filename1 = Path.Combine(typeDirectory, "snippet1.snippet"); string filename2 = Path.Combine(typeDirectory, "snippet2.snippet"); File.WriteAllText(filename1, "snippet 1"); File.WriteAllText(filename2, "snippet 2"); var config = new JsonConfiguration(); config.ScriptSnippetDirectory = _snippetDirectory; var snippetReader = new SnippetFileReader(config); // when IEnumerable <string> files = snippetReader.GetSnippetFilenames(ScriptSnippetType.BeforeExecute); // then Assert.That(files.Count(), Is.EqualTo(2)); Assert.That(files, Contains.Item("snippet1.snippet")); Assert.That(files, Contains.Item("snippet2.snippet")); }
public ClinicasController() { this.clinica = new Repository.Clinicas.Clinicas(); this.jsonConfig = new JsonConfiguration(); }
public void CreateDefault() { Provider.AppendProvider(JsonConfiguration.Prototype()); }
public SexoController() { this.sexo = new Sexo(); this.jsonConfig = new JsonConfiguration(); }
private static void _setup() { _configuration = Json.ConfigurationFor<Book>() .MapType<Book>(map => map .AllFields() .Field<DateTime>(field => field.pubDate, pubDate => pubDate .EncodeAs<string>(value => value.ToShortDateString()) .DecodeAs<string>(value => DateTime.Parse(value)) ) .Field<BookType>(field => field.type, type => type .EncodeAs<int>(value => (int)value) .DecodeAs<int>(value => (BookType)Enum.ToObject(typeof(BookType), value)) ) ) .MapType<Author>(map => map .AllFields() ); }
/// <summary> /// Initializes the NInject kernel. /// </summary> /// <param name="kernel">The dependency injection container.</param> /// <param name="settings">The settings of the application.</param> private static async Task PrepareDIContainer(IKernel kernel, JsonConfiguration settings) { // Add ranked theorem writing and reading kernel.AddRankedTheoremIO(); #region Local dependencies // Add local dependencies kernel.Bind <IBatchRunner>().To <BatchRunner>(); kernel.Bind <IProblemGenerationRunner>().To <ProblemGenerationRunner>().WithConstructorArgument(settings.GetSettings <ProblemGenerationRunnerSettings>()); kernel.Bind <ITheoremSorterTypeResolver>().To <TheoremSorterTypeResolver>().WithConstructorArgument(settings.GetSettings <TheoremSorterTypeResolverSettings>()); #endregion #region Providers // Add inference rule provider kernel.AddInferenceRuleProvider(settings.GetSettings <InferenceRuleProviderSettings>()) // Add object introduction rule provider .AddObjectIntroductionRuleProvider(settings.GetSettings <ObjectIntroductionRuleProviderSettings>()) // Add problem generator input provider .AddProblemGeneratorInputProvider(settings.GetSettings <ProblemGeneratorInputProviderSettings>()); #endregion // Load the inference rules var managerData = new InferenceRuleManagerData(await kernel.Get <IInferenceRuleProvider>().GetInferenceRulesAsync()); // Use them to bind the tracker kernel.Bind <IInferenceRuleUsageTracker>().To <InferenceRuleUsageTracker>().WithConstructorArgument(managerData); #region Algorithm // Add the configuration generator with its settings kernel.AddConfigurationGenerator(settings.GetSettings <GenerationSettings>()) // And the constructor .AddConstructor() // And the theorem finder .AddTheoremFinder(settings.GetSettings <TheoremFindingSettings>()) // And the theorem ranker .AddTheoremRanker(settings.GetSettings <TheoremRankerSettings>()) // And the theorem prover and with its settings .AddTheoremProver(new TheoremProvingSettings ( // Set the loaded manager data inferenceRuleManagerData: managerData, // Load the object introduction data as well objectIntroducerData: new ObjectIntroducerData(await kernel.Get <IObjectIntroductionRuleProvider>().GetObjectIntroductionRulesAsync()), // Set the prover's settings theoremProverSettings: settings.GetSettings <TheoremProverSettings>() )) // And the problem generator and with its settings .AddProblemGenerator(settings.GetSettings <ProblemGeneratorSettings>()) // And the problem analyzer .AddProblemAnalyzer() // And the sorter .AddTheoremSorter(); #endregion #region Tracers // Rebind Constructor Failure Tracer only if we're supposed be tracing if (settings.GetSettings <bool>("TraceConstructorFailures")) { kernel.Rebind <IConstructorFailureTracer>().To <ConstructorFailureTracer>().WithConstructorArgument(settings.GetSettings <ConstructorFailureTracerSettings>()); } // Rebind Geometry Failure Tracer only if we're supposed be tracing if (settings.GetSettings <bool>("TraceGeometryFailures")) { kernel.Rebind <IGeometryFailureTracer>().To <GeometryFailureTracer>().WithConstructorArgument(settings.GetSettings <GeometryFailureTracerSettings>()); } // Rebind Invalid Inference Tracer only if we're supposed be tracing if (settings.GetSettings <bool>("TraceInvalidInferences")) { kernel.Rebind <IInvalidInferenceTracer>().To <InvalidInferenceTracer>().WithConstructorArgument(settings.GetSettings <InvalidInferenceTracerSettings>()); } // Rebind Sorting Geometry Failure Tracer only if we're supposed be tracing if (settings.GetSettings <bool>("TraceSortingGeometryFailures")) { kernel.Rebind <ISortingGeometryFailureTracer>().To <SortingGeometryFailureTracer>().WithConstructorArgument(settings.GetSettings <SortingGeometryFailureTracerSettings>()); } #endregion }
void LoadSavedAuthentication() { if (QuizletAPI.Default.Credentials == null) { // Try to load from transient storage. object accessToken, userName, expiry; PhoneApplicationService.Current.State.TryGetValue("quizletAccessToken", out accessToken); PhoneApplicationService.Current.State.TryGetValue("quizletUserName", out userName); PhoneApplicationService.Current.State.TryGetValue("quizletExpiry", out expiry); var q = new JsonConfiguration(); if (accessToken is string && userName is string && expiry is DateTime) { QuizletAPI.Default.Authenticate(new Credentials((string)accessToken, (string)userName, (DateTime)expiry)); } else { // Not found in transient storage, load from JSON configuration. if (Configuration.AccessToken != null && Configuration.UserName != null) QuizletAPI.Default.Authenticate(new Credentials(Configuration.AccessToken, Configuration.UserName, Configuration.AccessTokenExpiry)); } } }
public void Initialize() { IJsonConfiguration config = new JsonConfiguration(); _repo = new Repository(config.ConnectionString); }
internal void Flush() { lock (this) { _storeConfigurationTask = null; if (_configuration == null) { return; } var algorithm = SecurityAlgorithm ?? _configuration.security; if (!SkipSecurity && ConfigurationProtection != null && !string.IsNullOrEmpty(algorithm)) { var protector = ConfigurationProtection.Resolve(algorithm); if (protector != null) { _configuration.security = algorithm; if (_configuration.devices != null) { foreach (var device in _configuration.devices) { if (string.IsNullOrEmpty(device.privateKey)) { continue; } try { var encryptedPrivateKey = protector.Obscure(device.privateKey); device.privateKey = encryptedPrivateKey; device.secured = true; } catch (Exception e) { Debug.WriteLine(e); } } } if (_configuration.users != null) { foreach (var user in _configuration.users) { if (string.IsNullOrEmpty(user.user_password)) { continue; } try { string encryptedPassword = null; if (!string.IsNullOrEmpty(user.user_password)) { encryptedPassword = protector.Obscure(user.user_password); } user.user_password = encryptedPassword; user.secured = true; } catch (Exception e) { Debug.WriteLine(e); } } } } } _loader.StoreJson(JsonUtils.DumpJson(_configuration)); _configuration = null; } }
public TipoSangreController() { this.tipoSangre = new TipoSangre(); this.jsonConfig = new JsonConfiguration(); }
public ConsultasController() { this.consulta = new Consulta(); this.jsonConfig = new JsonConfiguration(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { /* * Repositories */ services.AddSingleton <IRepository <string, PartyEntity>, PartyRepository>(); services.AddSingleton <IRepository <char, TableEntity>, TableRepository>(); /* * Services */ services.AddSingleton <IPartyService, PartyService>(); services.AddSingleton <ITableService, TableService>(); services.AddSingleton <IArrangerService, ArrangerService>(); services .AddCors(options => { options.AddPolicy("AllowAll", builder => { builder.AllowAnyHeader(); builder.AllowAnyMethod(); builder.AllowAnyOrigin(); builder.AllowCredentials(); }); }) .AddMvc() .SetCompatibilityVersion(CompatibilityVersion.Version_2_1) .AddJsonOptions(options => { var settings = JsonConfiguration.GetSerializerSettings(); foreach (var converter in settings.Converters) { options.SerializerSettings.Converters.Add(converter); } options.SerializerSettings.DateFormatHandling = settings.DateFormatHandling; options.SerializerSettings.NullValueHandling = settings.NullValueHandling; options.SerializerSettings.Formatting = settings.Formatting; options.SerializerSettings.ContractResolver = settings.ContractResolver; }); services.AddSwaggerGen(c => { c.DescribeAllEnumsAsStrings(); c.DescribeAllParametersInCamelCase(); c.SwaggerDoc("v1", new Info { Version = "v1", Title = "Seat Arranger", Description = "A code demonstration for ByteCubed", License = new License { Name = "The Unlicense", Url = "http://bytecubed.com/" }, Contact = new Contact { Name = "Erik Zettersten", Email = "*****@*****.**", Url = "http://bytecubed.com/" } }); //Set the comments path for the swagger json and ui. var xmlPath = Path.Combine("wwwroot", "seatarranger.com.xml"); c.IncludeXmlComments(xmlPath); }); // In production, the Angular files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; }); }
public ConfigurationServiceMock() { Configuration = new JsonConfiguration(); SystemVariables = new List <Variable>(); SnippetFilenames = new List <string>(); }
static void Main(string[] args) { IConfiguration configuration = JsonConfiguration.FetchFromJsonFile(); var lasFilesSourceFolder = configuration.LasFilesConfiguration.SourceFolder; if (string.IsNullOrWhiteSpace(lasFilesSourceFolder)) { Console.WriteLine($"LAS file folder is not provided ('LasFiles' property) in the settings file located at '{JsonConfiguration.SuggestJsonFilePath()}'"); return; } var lasFilesDirectory = new DirectoryInfo(Path.GetFullPath(lasFilesSourceFolder)); if (!lasFilesDirectory.Exists) { Console.WriteLine($"LAS file folder cannot be found at '{lasFilesDirectory.FullName}'"); Console.WriteLine($"The folder location can be changed in the settings file located at '{JsonConfiguration.SuggestJsonFilePath()}'"); return; } var fileStorage = new LasFileStorage(lasFilesDirectory, new LasFileReader(configuration.LasFilesConfiguration.LogTypeField)); var currentDirectory = Directory.GetCurrentDirectory(); var indexLocation = new DirectoryInfo(Path.Combine(currentDirectory, "Index", "Lucene")); using (var fileIndexedStorage = new LuceneLasFileStorage(indexLocation)) { new ConsoleApplication(fileIndexedStorage, fileStorage, configuration).Run(); } }
/// <summary> /// Initializes a new instance of the <see cref="DefaultJsonSerializer"/> class, /// with the provided <see cref="INancyEnvironment"/>. /// </summary> /// <param name="environment">An <see cref="INancyEnvironment"/> instance.</param> public DefaultJsonSerializer(INancyEnvironment environment) { this.jsonConfiguration = environment.GetValue <JsonConfiguration>(); this.traceConfiguration = environment.GetValue <TraceConfiguration>(); }
/// <summary> /// Reload the QQConfiguration file /// </summary> public QQConfigurationFile Reload() { lock (this) return(_config = JsonConfiguration.Load <QQConfigurationFile>(File.FullName)); }
public static string ToJson(this object entity) { return(JsonConvert.SerializeObject(entity, JsonConfiguration.GetSerializerSettings())); }
public void TearDown() { _ = new JsonConfiguration(configFileLoc); }