public Schema Read() { if (_cache.ContainsKey(Process.Name)) { return(_cache[Process.Name]); } var schema = _schemaReader.Read(); _cache[Process.Name] = schema; return(schema); }
/// <summary> /// If any entity schema's are helped, this should return true so the consumer knows he/she ought to check process.Errors(). /// </summary> /// <returns>true if any schema has been helped, false if no help provided</returns> public bool Help(Process process) { var helped = false; foreach (var entity in process.Entities) { if (entity.Fields.Any(f => f.Input)) { continue; } _schemaReader.Process = process; var schema = _schemaReader.Read(entity); if (!schema.Entities.Any()) { _context.Warn($"Could not detect {entity.Alias} fields."); continue; } var e = schema.Entities.First(); var fields = e.Fields; foreach (var field in fields.Where(field => Constants.InvalidFieldNames.Contains(field.Name) && Constants.InvalidFieldNames.Contains(field.Alias))) { field.Alias = e.Alias + field.Name; } var add = e.Fields.Where(f => !f.System).ToList(); var processKeys = new HashSet <string>(process.GetAllFields().Select(f => f.Alias), System.StringComparer.OrdinalIgnoreCase); if (add.Any()) { _context.Debug(() => $"Detected {add.Count} field{add.Count.Plural()} in {entity.Alias}."); var entityKeys = new HashSet <string>(entity.GetAllFields().Select(f => f.Alias), System.StringComparer.OrdinalIgnoreCase); foreach (var field in add) { if (!entityKeys.Contains(field.Alias)) { if (!field.PrimaryKey && processKeys.Contains(field.Alias)) { field.Alias = entity.Alias + field.Alias; } entity.Fields.Add(field); } } process.Connections.First(c => c.Name == e.Connection).Delimiter = schema.Connection.Delimiter; helped = true; } else { _context.Warn($"Could not detect {entity.Alias} fields."); } } return(helped); }