//Extract and store valid trailing arguments private void ExtractAndStoreTrailingArguments(string[] trailingArguments) { //Collect all valid trailing commands from an embedded json file //validTrailingCommands are valid trailing commands the application will accept string validTrailingCommandsResourceContents = EmbeddedResourceHandler.GetAssemblyResourceAsString($"{Properties.AppSettings.Default.ResourceManifestPath}{Properties.AppSettings.Default.ValidCommandsResourceFileName}"); List <string> validTrailingCommands = JsonHandler.JsonToStringList(validTrailingCommandsResourceContents); //Validate and store all valid trailing arguments, all provided trailing arguments should be valid foreach (string trailingArgument in trailingArguments) { //Split and store the name and value of the trailing argument string trailingArgumentName = string.Empty; string trailingArgumentValue = string.Empty; string[] argumentValuePair = trailingArgument?.Split(new string[] { Separators.SpaceSeparator }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < argumentValuePair.Length; i++) { if (i == 0) { trailingArgumentName = argumentValuePair[i]?.Trim(); } else if (i == 1) { trailingArgumentValue = argumentValuePair[i]?.Trim(); } } //Check if this is a valid trailing argument if (string.IsNullOrEmpty(trailingArgumentName)) { break; } //Check if the provided trailing argument name is valid if (!validTrailingCommands.Contains(trailingArgumentName)) { IsUserInputValid = false; throw new Exception(UserInputProcessorErrorMessage.InvalidArgumentDetected); } //Ensure no duplicate arguments are added if (TrailingArguments.Keys.Contains(trailingArgumentName)) { IsUserInputValid = false; throw new Exception(UserInputProcessorErrorMessage.DuplicateArgumentDetected); } //Store valid trailing argument name and value pair TrailingArguments.Add(trailingArgumentName, trailingArgumentValue); } }
public override void Configure(Funq.Container container) { JsConfig.DateHandler = JsonDateHandler.ISO8601; Plugins.Add(new SwaggerFeature()); // register our custom exception handling this.ExceptionHandler = Rainy.ErrorHandling.ExceptionHandler.CustomExceptionHandler; this.ServiceExceptionHandler = Rainy.ErrorHandling.ExceptionHandler.CustomServiceExceptionHandler; var swagger_path = Path.Combine(Path.GetDirectoryName(this.GetType().Assembly.Location), "../../swagger-ui/"); var swagger_handler = new FilesystemHandler("/swagger-ui/", swagger_path); var embedded_handler = new EmbeddedResourceHandler("/srv/", this.GetType().Assembly, "Rainy.WebService.Admin.UI"); // BUG HACK // GlobalResponseHeaders are not cleared between creating instances of a new config // this will be fatal (duplicate key error) for unit tests so we clear the headers EndpointHostConfig.Instance.GlobalResponseHeaders.Clear(); SetConfig(new EndpointHostConfig { // not all tomboy clients send the correct content-type // so we force application/json DefaultContentType = ContentType.Json, RawHttpHandlers = { swagger_handler.CheckAndProcess, embedded_handler.CheckAndProcess }, // enable cors GlobalResponseHeaders = { { "Access-Control-Allow-Origin", "*" }, { "Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS" }, // time in seconds preflight responses can be cached by the client { "Access-Control-Max-Age", "1728000" }, // { "Access-Control-Max-Age", "1" }, // the Authority header must be whitelisted; it is sent be the rainy-ui // for authentication { "Access-Control-Allow-Headers", "Content-Type, Authority" }, }, }); }