private static void Main(string[] args) { if (args.Length != 4) { if (args.Length > 0 && args[0].Equals("protect")) { Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ConfigurationSection section = config.GetSection("connectionStrings"); { if (!section.SectionInformation.IsProtected) { if (!section.ElementInformation.IsLocked) { section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider"); section.SectionInformation.ForceSave = true; config.Save(ConfigurationSaveMode.Full); Console.WriteLine(); Console.WriteLine("Encrypted Configuration File"); } } } } else { Console.WriteLine("Missing Required arguments"); Console.WriteLine("<cluster> bucket <bucket name> <mapping File>"); Console.WriteLine("Examples:"); Console.WriteLine("localhost bucket beer-sample basic"); } Environment.Exit(2); } if (!args[1].Equals("bucket", StringComparison.OrdinalIgnoreCase)) { Console.Write("Only Bucket view is currently supported."); Environment.Exit(2); } try { var location = Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(Program)).Location); // Remove anything that may have been put in the file name that shouldn't be there. // The configuration file must be in the same folder as the .exe, and be a json files. var configurationFile = Path.Combine(location, Path.GetFileNameWithoutExtension(args[3] + ".json")); _mappings = JsonConvert.DeserializeObject <StatsMappings>(File.ReadAllText(configurationFile)); var connectionString = new DbConnectionStringBuilder { ConnectionString = ConfigurationManager.ConnectionStrings[args[0]].ConnectionString }; var result = Read(new RequestPrams { ServerAndPort = connectionString["servers"].ToString().Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList(), BucketName = args[2], User = connectionString["user"].ToString(), Password = connectionString["password"].ToString(), }).Result; result.WriteToConsole(); } catch (Exception ex) { var baseException = ex.GetBaseException(); new Prtg { Error = 1, Text = baseException.Message }.WriteToConsole(); } if (Debugger.IsAttached) { Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } }
private static void Main(string[] args) { if (args.Length != 4) { if (args.Length > 0 && args[0].Equals("protect")) { Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ConfigurationSection section = config.GetSection("connectionStrings"); { if (!section.SectionInformation.IsProtected) { if (!section.ElementInformation.IsLocked) { section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider"); section.SectionInformation.ForceSave = true; config.Save(ConfigurationSaveMode.Full); Console.WriteLine(); Console.WriteLine("Encrypted Configuration File"); } } } } else { Console.WriteLine("Missing Required arguments"); Console.WriteLine("<cluster> bucket <bucket name> <mapping File>"); Console.WriteLine("Examples:"); Console.WriteLine("localhost bucket beer-sample basic"); } Environment.Exit(2); } if (!args[1].Equals("bucket", StringComparison.OrdinalIgnoreCase)) { Console.Write("Only Bucket view is currently supported."); Environment.Exit(2); } try { var location = Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(Program)).Location); // Remove anything that may have been put in the file name that shouldn't be there. // The configuration file must be in the same folder as the .exe, and be a json files. var configurationFile = Path.Combine(location, Path.GetFileNameWithoutExtension(args[3] + ".json")); _mappings = JsonConvert.DeserializeObject<StatsMappings>(File.ReadAllText(configurationFile)); var connectionString = new DbConnectionStringBuilder { ConnectionString = ConfigurationManager.ConnectionStrings[args[0]].ConnectionString }; var result = Read(new RequestPrams { ServerAndPort = connectionString["servers"].ToString().Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList(), BucketName = args[2], User = connectionString["user"].ToString(), Password = connectionString["password"].ToString(), }).Result; result.WriteToConsole(); } catch (Exception ex) { var baseException = ex.GetBaseException(); new Prtg { Error = 1, Text = baseException.Message }.WriteToConsole(); } if (Debugger.IsAttached) { Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } }