public MigrationService() { var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly()); XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config")); adB2CUsersAll = new List <User>(); config = AppSettingsFile.ReadFromJsonFile(); var subscriptions = config.APIMSubscriptionIds == null ? new String[] { } : config.APIMSubscriptionIds.Split(";"); var serviceNames = config.APIMApiManagementNames == null ? new String[] { } : config.APIMApiManagementNames.Split(";"); var resourceGroups = config.APIMResourceGroups == null ? new String[] { } : config.APIMResourceGroups.Split(";"); if (subscriptions.Length > 0 && subscriptions.Length.Equals(serviceNames.Length) && subscriptions.Length.Equals(resourceGroups.Length)) { apims = new APIMService[serviceNames.Length]; apimUserCollections = new UserCollection[serviceNames.Length]; for (int i = 0; i < serviceNames.Length; i++) { apims[i] = new APIMService(serviceNames[i], resourceGroups[i], config.APIMTenantId, subscriptions[i]); } } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Error on Configuration:"); Console.WriteLine(" API Mgmt Services : " + serviceNames.Length); Console.WriteLine(" API Mgmt RGs : " + resourceGroups.Length); Console.WriteLine(" API Mgmt Subscrpitions : " + subscriptions.Length); Console.ForegroundColor = ConsoleColor.White; } }
/// <summary> /// Application Settings Class, creates an AppSettings object. This is called on application startup. /// <para>If there is an existing config file, it will parse the data from it.</para> /// <para>If there is not an existing config file, or a TelltaleModLauncher directory, create a new one.</para> /// </summary> public AppSettings() { if (File.Exists(configFile_file_location)) { ReadConfigFile(); } else { appSettingsFile = new AppSettingsFile(); New_GameVersionSettingsList(); if (!Directory.Exists(configFile_directory_location)) { IOManagement.CreateDirectory(configFile_directory_location); } WriteToFile(); } }
/// <summary> /// Reads and parses the data from the app config file. /// </summary> public void ReadConfigFile() { appSettingsFile = new AppSettingsFile(); GameVersionSettings = new List <GameVersionSettings>(); //read the data from the config file string jsonText = File.ReadAllText(configFile_file_location); //parse the data into a json array JArray array; try { array = JArray.Parse(jsonText); } catch (Exception e) { MessageBox.Show(e.ToString(), e.Message, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } JObject AppSettingsFile_fromJson = array[0] as JObject; JArray GameVersionSettings_fromJson = array[1] as JArray; //loop through each property to get the data foreach (JProperty property in AppSettingsFile_fromJson.Properties()) { string name = property.Name; if (name.Equals(nameof(appSettingsFile.Default_Game_Version))) { appSettingsFile.Default_Game_Version = (GameVersion)(int)property.Value; } if (name.Equals(nameof(appSettingsFile.UI_LightMode))) { appSettingsFile.UI_LightMode = (bool)property.Value; } if (name.Equals(nameof(appSettingsFile.UI_WindowDefocusing))) { appSettingsFile.UI_WindowDefocusing = (bool)property.Value; } } //loop through each property to get the data foreach (JObject obj in GameVersionSettings_fromJson.Children <JObject>()) { GameVersionSettings new_gameVersionSettings = new GameVersionSettings(); //loop through each property to get the data foreach (JProperty property in obj.Properties()) { string name = property.Name; if (name.Equals(nameof(current_GameVersionSettings.Game_Location))) { new_gameVersionSettings.Game_Location = (string)property.Value; } if (name.Equals(nameof(current_GameVersionSettings.Game_LocationExe))) { new_gameVersionSettings.Game_LocationExe = (string)property.Value; } if (name.Equals(nameof(current_GameVersionSettings.Game_Version))) { new_gameVersionSettings.Game_Version = (GameVersion)(int)property.Value; } } GameVersionSettings.Add(new_gameVersionSettings); } foreach (GameVersionSettings version in GameVersionSettings) { if (appSettingsFile.Default_Game_Version.Equals(version.Game_Version)) { current_GameVersionSettings = version; } } }