/// <summary> /// Додає характеристику /// </summary> /// <param name="parameterDto">Екземпляр характеристики</param> public void AddParameter(ParametersDtoModel parameterDto) { var mapper = new MapperConfiguration(cfg => cfg.CreateMap <ParametersDtoModel, ParametersModel>()).CreateMapper(); ParametersModel parameter = mapper.Map <ParametersModel>(parameterDto); var results = parametersValidator.Validate(parameter); if (results.IsValid) { parametersRepository.Add(parameter); } else { throw new Exception("Помилка валідації характеристики: " + Environment.NewLine + ValidationResultsHelper.GetValidationErrors(results)); } }
public static ParametersValidationResult CreateSession(ISessionParameters parameters, out ISession session) { ParametersValidator validator = new ParametersValidator(parameters); var validationResult = validator.Validate(); if (validationResult == ParametersValidationResult.Valid) { session = new Session(parameters); System.Diagnostics.Debug.WriteLine("validtionResult: {0}", validationResult); } else { session = null; } return(validationResult); }
public override Filter Preprocess() { Filter delegateFilter; if (string.IsNullOrEmpty(this.SqlExpression)) { throw new FilterException(SRClient.PropertyIsNullOrEmpty("SqlExpression")); } if (this.SqlExpression.Length > 1024) { throw new FilterException(SRClient.SqlFilterStatmentTooLong(this.SqlExpression.Length, 1024)); } this.EnsureCompatibilityLevel(); try { SqlFilter.CompiledItem compiledItem = (SqlFilter.CompiledItem)SqlFilter.compiledDelegateCache.Get(this.SqlExpression, null); if (compiledItem == null) { SqlFilterParserOutput sqlFilterParserOutput = SqlFilterParser.Parse(this.SqlExpression); (new SqlFilter.ExpressionValidator()).Validate(sqlFilterParserOutput.ExpressionTree); Func <BrokeredMessage, IDictionary <string, object>, bool?> func = sqlFilterParserOutput.ExpressionTree.Compile(); compiledItem = new SqlFilter.CompiledItem(func, sqlFilterParserOutput.RequiredParameters); SqlFilter.CompiledItem compiledItem1 = (SqlFilter.CompiledItem)SqlFilter.compiledDelegateCache.AddOrGetExisting(this.SqlExpression, compiledItem, SqlFilter.defaultCachePolicy, null); if (compiledItem1 != null) { compiledItem = compiledItem1; } } ParametersValidator.Validate(true, compiledItem.RequiredParameters, this.Parameters); delegateFilter = new DelegateFilter(compiledItem.Delegate, this.Parameters); } catch (FilterException filterException) { throw; } catch (Exception exception1) { Exception exception = exception1; if (!Fx.IsFatal(exception)) { throw new FilterException(exception.Message, exception); } throw; } return(delegateFilter); }
static void Main(string[] args) { var parametersValidator = new ParametersValidator(); var parametersAreValid = parametersValidator.Validate(args); if (parametersAreValid) { string nameOfFile; var parameters = CommandLineParser.Parse(args); if (parameters.TryGetValue("nameoffile", out nameOfFile)) { string analyzerType, startDate, finishDate; parameters.TryGetValue("analyzer", out analyzerType); parameters.TryGetValue("startdate", out startDate); parameters.TryGetValue("finishdate", out finishDate); var logReader = new LogFileReader(); var records = logReader.GiveAllRecordsInFile(nameOfFile); var dateFilter = new DateFilter { Records = records }; records = dateFilter.Filtrate(startDate, finishDate); var analyzerByType = new FileAnalyzer { Records = records }; Console.WriteLine(analyzerByType.AnalyzeByType(analyzerType)); } else { Console.WriteLine("Входные параметры не соответствуют шаблону."); } } else { Console.WriteLine(parametersValidator.ValidationInformation); } Console.ReadKey(); }
public override RuleAction Preprocess() { RuleAction delegateRuleAction; this.EnsureCompatibilityLevel(); try { SqlRuleAction.CompiledItem compiledItem = (SqlRuleAction.CompiledItem)SqlRuleAction.compiledCache.Get(this.SqlExpression, null); if (compiledItem == null) { SqlActionParserOutput sqlActionParserOutput = SqlActionParser.Parse(this.SqlExpression); Action <BrokeredMessage, IDictionary <string, object> > action = sqlActionParserOutput.ExpressionTree.Compile(); compiledItem = new SqlRuleAction.CompiledItem(action, sqlActionParserOutput.RequiredParameters); SqlRuleAction.CompiledItem compiledItem1 = (SqlRuleAction.CompiledItem)SqlRuleAction.compiledCache.AddOrGetExisting(this.SqlExpression, compiledItem, SqlRuleAction.defaultCachePolicy, null); if (compiledItem1 != null) { compiledItem = compiledItem1; } } ParametersValidator.Validate(false, compiledItem.RequiredParameters, this.Parameters); delegateRuleAction = new DelegateRuleAction(compiledItem.Delegate, this.Parameters); } catch (RuleActionException ruleActionException) { throw; } catch (Exception exception1) { Exception exception = exception1; if (!Fx.IsFatal(exception)) { throw new RuleActionException(exception.Message, exception); } throw; } return(delegateRuleAction); }
static void Main(string[] args) { var parametersValidator = new ParametersValidator(); var parametersAreValid = parametersValidator.Validate(args); if (parametersAreValid) { string nameOfFile; string numberOfLines; string numberOfUniqueIp; var parametersDictionary = CommandLineParser.Parse(args); if (parametersDictionary.TryGetValue("nameoffile", out nameOfFile) && parametersDictionary.TryGetValue("numberoflines", out numberOfLines) && parametersDictionary.TryGetValue("numberofuniqueip", out numberOfUniqueIp)) { var uniqueIpCount = Convert.ToInt32(numberOfUniqueIp); var linesLength = Convert.ToInt32(numberOfLines); var configFileReader = new Settings.ConfigFileReader(@"D:\Univercity\Univercity\3курс-лабы\config.yaml"); string[] methods = { "POST", "LINK", "DELETE", "PUT", "PATCH", "GET", "OPTIONS", "HEAD", "TRACE", "UNLINK", "CONNECT" }; string[] extensions = { "txt", "pdf", "doc", "exe", "jmp", "cpp", "obj", "iso" }; string[] protocols = { "http", "https" }; string[] serverResponseCodes = { "200", "401", "204", "404", "501" }; const int minIntervalInMilliseconds = 100; const int maxIntervalInMilliseconds = 100000; const int minNumberOfFolders = 3; const int maxNumberOfFolders = 7; const int minNumberOfCharacters = 3; const int maxNumberOfCharacters = 7; const int minSizeOfResponse = 100; const int maxSizeOfResponse = 10000; var recordFormat = new RecordFormat { IpIsPresent = true, QueryTimeIsPresent = true, QueryMethodIsPresent = true, FileNameIsPresent = true, ExtensionIsPresent = true, ProtocolIsPresent = true, ServerResponseCodeIsPresent = true, SizeOfTheResponseIsPresent = true }; var generator = new Generator { Extensions = extensions, Protocols = protocols, Methods = methods, Settings = configFileReader.Settings, ServerResponseCodes = serverResponseCodes, MinIntervalInMilliseconds = minIntervalInMilliseconds, MaxIntervalInMilliseconds = maxIntervalInMilliseconds, MinNumberOfCharacters = minNumberOfCharacters, MaxNumberOfCharacters = maxNumberOfCharacters, MinNumberOfFolders = minNumberOfFolders, MaxNumberOfFolders = maxNumberOfFolders, MinSizeOfResponse = minSizeOfResponse, MaxSizeOfResponse = maxSizeOfResponse, NumberOfUniqueIp = uniqueIpCount }; var allRecords = generator.GenerateRecords(linesLength); var rows = ApacheLogFormat.RecordsToString(allRecords, recordFormat); SaveToFile.SaveRowsToFile(nameOfFile, rows); Console.WriteLine("Save succesed!"); } else { Console.WriteLine("Входные параметры не соответствуют шаблону."); } } else { Console.WriteLine(parametersValidator.ValidationInformation); } Console.ReadKey(); }