public IParameterProcessor GetProcessor(string key) { IParameterProcessor result = null; _processors.TryGetValue(key, out result); return(result); }
public void Process(ParameterParser parameters, bool throwOnUnknownParameter) { foreach (Parameter parameter in parameters.Parameters) { IParameterProcessor parameterProcessor = GetProcessor(parameter.Name); if (parameterProcessor != null) { parameterProcessor.SetParameter(parameter.Name, parameter.Value); } else if (throwOnUnknownParameter) { throw new SmtpServerException( new SmtpResponse(StandardSmtpResponseCode.SyntaxErrorInCommandArguments, "Parameter {0} is not recognised", parameter.Name)); } } }
public Task ProcessAsync(IConnection connection, ParameterParser parameters, bool throwOnUnknownParameter) { foreach (Parameter parameter in parameters.Parameters) { IParameterProcessor parameterProcessor = GetProcessor(parameter.Name); if (parameterProcessor != null) { parameterProcessor.SetParameter(connection, parameter.Name, parameter.Value); } else if (throwOnUnknownParameter) { throw new SmtpServerException( new SmtpResponse(StandardSmtpResponseCode.SyntaxErrorInCommandArguments, "Parameter {0} is not recognised", parameter.Name)); } } return(Task.CompletedTask); }
public void SetProcessor(string key, IParameterProcessor connection) { _processors[key] = connection; }
public static IDictionary <string, string> ProcessParameters(IEnumerable <Parameter> parameters, string path, IParameterProcessor parameterProcessor) { return(parameters .Where(parameter => parameterProcessor.IncludeParameter(parameter, path)) .Select(parameter => new { Key = parameterProcessor.GetKey(parameter, path), Value = parameterProcessor.GetValue(parameter, path) }) .ToDictionary(parameter => parameter.Key, parameter => parameter.Value, StringComparer.OrdinalIgnoreCase)); }
public void SetProcessor(string key, IParameterProcessor processor) { _processors[key] = processor; }
public void SetProcessor(string key, IParameterProcessor connection) { _processors[key] = connection; }
public void SetProcessor(string key, IParameterProcessor processor) { _processors[key] = processor; }
public JsonParameterProcessorTests() { _parameterProcessor = new JsonParameterProcessor(); }
public int Run(string[] args) { Dictionary <string, string> DOfParameters = new Dictionary <string, string>(); IParameterProcessor IPP = LogDeleterFactory.GetParameterProcessorImplementation('='); // '=' is the splitter try { DOfParameters = IPP.ParseParameters(args); } catch (System.ArgumentException) { Console.WriteLine("Some parameters were used more than once!"); return(1); } catch (Exception e) { Console.WriteLine(e.Message); return(1); } if (DOfParameters.Count == 0) { return(1); } bool pathFlag = false; bool extensionFlag = false; bool loggingFlag = true; // Logging of processed files is enabled by default. foreach (KeyValuePair <string, string> keyValuePair in DOfParameters) { switch (keyValuePair.Key) { case "-p": pathFlag = true; if (keyValuePair.Value == string.Empty) { Console.WriteLine("Path parameter can not be empty!"); return(1); } break; case "-e": extensionFlag = true; if (keyValuePair.Value == string.Empty) { Console.WriteLine("Extension parameter can not be empty!"); return(1); } break; case "--NoLogging": loggingFlag = false; break; default: Console.WriteLine("Wrong parameters insertion."); return(1); // break; } } if ((pathFlag == true) && (extensionFlag == true)) { IFileProcessor IFP = LogDeleterFactory.GetFileProcessorImplementation(); string givenFolder = DOfParameters["-p"]; if (IFP.GivendDirectoryExists(givenFolder) == false) { Console.WriteLine("Given folder (" + givenFolder + ") doesn't exist."); return(1); } IFP.DeleteFiles(givenFolder, IPP.SeparateRightSideValues(DOfParameters["-e"]), loggingFlag); return(0); } Console.WriteLine("Wrong parameter insertion! Use -p= with combination of -e=."); return(1); }
public DefaultParameterProcessorTests() { _parameterProcessor = new DefaultParameterProcessor(); }