protected BuildConfig GetBuildConfig(string projectDir) { if (!Directory.Exists(projectDir)) { _logger.Error($"Could not find the project directory {projectDir}", null); return(null); } var projectFile = Path.Combine(projectDir, "build.cfg"); if (!File.Exists(Path.Combine(projectDir, "build.cfg"))) { _logger.Error("Could not find build.cfg", null); return(null); } BuildConfig config = null; using (var sr = new StreamReader(projectFile)) { var cereal = new XmlSerializer(typeof(BuildConfig)); try { config = (BuildConfig)cereal.Deserialize(sr); } catch { _logger.Error("Could not deserialize build.cfg. Make sure the file is properly formatted.", null); return(null); } } return(config); }
/// <summary> /// Transforms some LESS source code (and any related files) to CSS. /// </summary> /// <param name="source">The LESS code to transform.</param> /// <param name="file">The context file system.</param> public string Compile(string source, IFile file) { var parser = new Parser { Importer = new Importer(new LessFileReader(file.Directory)) }; var engine = new LessEngine(parser, _logger, false, false); string css = null; try { css = engine.TransformToCss(source, file.Name); } catch (FileNotFoundException ex) { _logger.Error("The file you are trying to import '{0}' cannot be found.".FormatWith(ex.FileName)); } if (_logger.HasErrors) { throw new LessCompileException(_logger.ErrorMessage); } return(css); }
public static void ValidateEmployeeNr(string empNr, IErrorLogger errorLogger) { if (ValidateForUnwantedCharacters(empNr) && empNr.Length < 9) { return; } errorLogger.Error($"invalid employee number: {empNr}"); }
public static void ValidateDate(string day, IErrorLogger errorLogger) { if (DateTime.TryParse(day, out DateTime result)) { return; } errorLogger.Error($"invalid date: {day}"); }
public static void ValidateAsNonSpacedString(string projectName, IErrorLogger errorLogger) { if (ValidateForUnwantedCharacters(projectName)) { return; } errorLogger.Error($"Invalid string: {projectName}. It should be single word and no special characters."); }
public static void ValidateTimeLog(string timeLog, IErrorLogger errorLogger) { if (string.IsNullOrWhiteSpace(timeLog)) { return; } if (ValidateForUnwantedCharacters(timeLog) && int.TryParse(timeLog, out int result) && result >= 0) { return; } errorLogger.Error($"invalid hours: {timeLog}"); }
public MethodInfo GetInstanceMethod(ISymbol typeSymbol, string methodName, TokenPosition position) { var info = GetObjectInfo(typeSymbol, position); if (!info.Methods.TryGetValue(methodName, out var method)) { if (typeSymbol is ObjectSymbol obj) { if (obj.Children.ContainsKey(methodName)) { var builder = info.Type as TypeBuilder; method = builder.DefineMethod(methodName, MethodAttributes.Public | MethodAttributes.Static, typeof(TsObject), TsTypes.ArgumentTypes); } else if (obj.Inherits != null) { method = GetInstanceMethod(obj.Inherits, methodName, position); } else { _logger.Error("Tried to call script that does not exist", position); return(null); } } else { method = info.Type.GetMethod(methodName, BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static, null, TsTypes.ArgumentTypes, null); if (method is null) { _logger.Error("Tried to call script that doesn't exist", position); return(null); } } info.Methods.Add(methodName, method); } return(method); }
private void LogNewMethodsIfAny(object state) { lock (_persistLocker) { IEnumerable <MethodRow> rows = null; var methods = new List <string>(_config.ChunkSize); try { if (!_config.Enabled || _newMethods.IsEmpty) { return; } int cnt = Math.Min(_newMethods.Count, _config.ChunkSize); for (int i = 0; i < cnt; i++) { // doesn't really matter if the chunk will be less than cnt string method; if (_newMethods.TryDequeue(out method)) { methods.Add(method); } } if (methods.Count > 0) { rows = ComposeRows(methods.Distinct()).ToArray(); _repository.AddMethods(rows); if (AllNewMethodsLogged != null && _newMethods.Count == 0) { AllNewMethodsLogged(); } } } catch (Exception e) { // Put back all the non-saved methods into the queue. Let's try to save them next time. This integration test proves that it's possible: IntegrationTests.EnsureAllLoggableWeavedMethodsCanBeSavedIntoDbSuccessfully foreach (var method in methods) { _newMethods.Enqueue(method); } // _errorLogger.Error(string.Format("Method Logger Exception:\r\n\r\n{0}", rows == null ? null : string.Join("\r\n", rows.Select(r => r.ToString()))), e); _errorLogger.Error("Method Logger Exception:\r\n\r\n", e); } } }
private void UpdateValues(string filePath) { try { // todo: replace dynamic with simple XElement based parsing dynamic config = new DynamicXmlParser(filePath); Enabled = bool.Parse(config.Enabled.ToString().ToLower()); ConnectionString = config.ConnectionString.ToString(); PersistIntervalMs = int.Parse(config.PersistIntervalSec.ToString()) * 1000; ApproximateLoggersCount = int.Parse(config.ApproximateLoggersCount.ToString()); ChunkSize = int.Parse(config.ChunkSize.ToString()); } catch (Exception exc) { _errorLogger.Error("Config file parse or load error\r\n", exc); } }
private void ParseArguments(IEnumerable <ObjectImportArgument> arguments, IErrorLogger logger) { var set = new HashSet <string>(); foreach (var arg in arguments) { if (set.Contains(arg.Name)) { logger.Error("Tried to add the same impport argument multiple times", arg.Position); continue; } switch (arg.Name) { case "casing": switch (arg.Value) { case "pascal_case": Casing = ImportCasing.Pascal; break; case "snake_case": Casing = ImportCasing.Snake; break; case "camel_case": Casing = ImportCasing.Camel; break; case "native_case": Casing = ImportCasing.Native; break; default: logger.Error("Invalid case option: " + arg.Value, arg.Position); break; } break; case "typing": switch (arg.Value) { case "weak": WeaklyTyped = true; break; case "strong": WeaklyTyped = false; break; default: logger.Error("Invalid typing option: " + arg.Value, arg.Position); break; } break; case "include_std": if (bool.TryParse(arg.Value, out var include)) { IncludeStandard = include; } else { logger.Error("Invalid include_std option: " + arg.Value, arg.Position); } break; default: logger.Error("Invalid import argument: " + arg.Name, arg.Position); break; } } }
private Token InternalRead() { SkipWhitespace(); _start = _index; if (_index >= _source.Length) { return(MakeToken(TokenType.EoF)); } var c = Advance(); switch (c) { case '(': return(MakeToken(TokenType.OpenParen)); case ')': return(MakeToken(TokenType.CloseParen)); case '{': return(MakeToken(TokenType.OpenBrace)); case '}': return(MakeToken(TokenType.CloseBrace)); case '[': return(MakeToken(TokenType.OpenBracket)); case ']': return(MakeToken(TokenType.CloseBracket)); case '~': return(MakeToken(TokenType.Complement)); case ';': return(MakeToken(TokenType.SemiColon)); case ':': return(MakeToken(TokenType.Colon)); case ',': return(MakeToken(TokenType.Comma)); //<, <=, <<, <> case '<': return(MakeToken(Match('=') ? TokenType.LessThanOrEqual : Match('<') ? TokenType.ShiftLeft : Match('>') ? TokenType.NotEqual : TokenType.LessThan)); case '&': return(MakeToken(Match('=') ? TokenType.AndEquals : Match('&') ? TokenType.LogicalAnd : TokenType.BitwiseAnd)); case '|': return(MakeToken(Match('=') ? TokenType.OrEquals : Match('|') ? TokenType.LogicalOr : TokenType.BitwiseOr)); case '>': return(MakeToken(Match('=') ? TokenType.GreaterThanOrEqual : Match('>') ? TokenType.ShiftRight : TokenType.GreaterThan)); case '+': return(MakeToken(Match('=') ? TokenType.PlusEquals : Match('+') ? TokenType.Increment : TokenType.Plus)); case '-': return(MakeToken(Match('=') ? TokenType.SubEquals : Match('-') ? TokenType.Decrement : TokenType.Minus)); case '=': return(MakeToken(Match('=') ? TokenType.Equal : TokenType.Assign)); case '*': return(MakeToken(Match('=') ? TokenType.MulEquals : TokenType.Multiply)); case '/': return(MakeToken(Match('=') ? TokenType.DivEquals : TokenType.Divide)); case '%': return(MakeToken(Match('=') ? TokenType.ModEquals : TokenType.Modulo)); case '^': return(MakeToken(Match('=') ? TokenType.XorEquals : TokenType.Xor)); case '!': return(MakeToken(Match('=') ? TokenType.NotEqual : TokenType.Not)); case '\'': case '"': return(StringLiteral(c)); case '.': if (IsDigit(PeekChar())) { return(NumberLiteral(false)); } return(MakeToken(TokenType.Dot)); case '?': if (IsHex(PeekChar())) { Advance(); while (IsHex(PeekChar())) { Advance(); } return(MakeToken(TokenType.Number)); } else { return(MakeToken(TokenType.QuestionMark)); } case '0': if (Match('x')) { while (IsHex(PeekChar())) { Advance(); } return(MakeToken(TokenType.Number)); } else { return(NumberLiteral(true)); } default: if (IsAlpha(c)) { return(Identifier()); } if (IsDigit(c)) { return(NumberLiteral(true)); } break; } _logger.Error("Unexpected character", new TokenPosition(_index, _line, _column, _fname)); return(null); }