/// <summary> /// Read the clinical patient file and store the data into directory. The key is tumor type plus bar code. /// Also read the /// </summary> /// <param name="clinicalData"></param> /// <param name="tumorType"></param> /// <param name="queryHeaders"></param> private void ReadClinData(IDictionary <string, IAnnotation> clinicalData, string tumorType, ICollection <string> queryHeaders) { var clinfile = TCGAUtils.GetClinicPatientFile(_options.TCGADirectory, tumorType); if (!File.Exists(clinfile)) { return; } var data = new TCGAClinicalInformationFormat().ReadFromFile(clinfile); foreach (var entry in data) { clinicalData[GetSampleKey(tumorType, entry.BarCode())] = entry; } var configheader = TemplateDirectory + "/" + Path.GetFileNameWithoutExtension(clinfile) + ".header.xml"; if (!File.Exists(configheader)) { configheader = TemplateDirectory + "/clinical_patient_tcga.header.xml"; } var fd = HeaderDefinition.LoadFromFile(configheader); foreach (var line in fd.Properties) { if (!queryHeaders.Contains(line)) { queryHeaders.Add(line); } } }
public void ReplaceRootNode() { string path = Assembly.GetExecutingAssembly().Location; path = Path.GetDirectoryName(path); var root = new RootFolderDefinition(Path.Combine(path, "CppTestProject")); var header = new HeaderDefinition("header1.h"); root.AddChild(header); var @class = new ClassDefinition("CppClass"); header.AddNode(@class); var replacement = new RootFolderDefinition(Path.Combine(path, "CppTestProject2")); StructureNodeReplacer.Replace(root, replacement); Assert.IsNull(root.Parent); Assert.AreEqual(0, root.Children.Count); Assert.IsNull(replacement.Parent); Assert.AreEqual(1, replacement.Children.Count); Assert.AreEqual(replacement, header.Parent); }
public void Clone() { string path = Assembly.GetExecutingAssembly().Location; path = Path.GetDirectoryName(path); var root = new RootFolderDefinition(Path.Combine(path, "CppTestProject")); var header = new HeaderDefinition("header1.h"); var @namespace = new NamespaceDefinition(); var @class = new ClassDefinition("CppClass"); var @enum = new EnumDefinition("CppEnum"); root.AddChild(header); @namespace.AddChild(@class); header.AddNode(@class); @namespace.AddChild(@enum); header.AddNode(@enum); var cloner = new StructureCloner(); cloner.Clone(@namespace); var rootClone = cloner.RootFolderClone; var rootNamespaceClone = cloner.RootNamespaceClone; Assert.AreNotSame(root, rootClone); Assert.AreEqual(root.FullPath, rootClone.FullPath); Assert.AreEqual(root.Children.Count, rootClone.Children.Count); var headerClone = (HeaderDefinition)rootClone.Children.First(); Assert.AreNotSame(header, headerClone); Assert.AreSame(rootClone, headerClone.Parent); Assert.AreEqual(2, headerClone.Nodes.Count); var classClone = (ClassDefinition)headerClone.Nodes[0]; Assert.AreNotSame(@class, classClone); Assert.AreSame(headerClone, classClone.Header); Assert.AreEqual(@class.Name, classClone.Name); Assert.AreEqual(@class.Children.Count, classClone.Children.Count); Assert.AreSame(rootNamespaceClone, classClone.Parent); var enumClone = (EnumDefinition)headerClone.Nodes[1]; Assert.AreNotSame(@enum, enumClone); Assert.AreSame(headerClone, enumClone.Header); Assert.AreEqual(@enum.Name, enumClone.Name); Assert.AreEqual(@enum.Children.Count, enumClone.Children.Count); Assert.AreSame(rootNamespaceClone, enumClone.Parent); Assert.AreNotSame(@namespace, rootNamespaceClone); Assert.AreEqual(@namespace.Children.Count, rootNamespaceClone.Children.Count); }
public void Transform(NamespaceDefinition globalNamespace, RootFolderDefinition rootFolder) { var methodsHeader = new HeaderDefinition("UnsafeNativeMethods.cs"); var methodsClass = new ClassDefinition("UnsafeNativeMethods"); CreateExternMethods(globalNamespace, methodsClass); methodsHeader.AddNode(methodsClass); globalNamespace.AddChild(methodsClass); rootFolder.AddChild(methodsHeader); }
public TokenizerContext Tokenize(HeaderDefinition header) { _context = new TokenizerContext(); NamespaceTreeNode namespaceTree = HeaderNamespaceTree.GetTree(header); IToken namespaceToken = TokenizeNamespace(namespaceTree); _context.Add(namespaceToken); return(_context); }
public virtual void WriteSoapHeader(XmlWriter writer, IXRoadHeader header, HeaderDefinition definition, IEnumerable <XElement> additionalHeaders = null) { writer.WriteStartElement("Header", NamespaceConstants.SOAP_ENV); header?.WriteTo(writer, this, definition); foreach (var additionalHeader in additionalHeaders ?? Enumerable.Empty <XElement>()) { additionalHeader.WriteTo(writer); } writer.WriteEndElement(); }
public void Setup() { using (var memory = new MemoryStream(ExcelFiles.SamplePALM)) { var header = new HeaderDefinition<Sample>(); header.Skip(28); header.Register(x => x.DateProp); header.SkippingRows(7); data = WorkbookReader.Create(header) .Read(new HSSFWorkbook(memory)); } }
private string[] GetClangOptions() { var options = new List <string> { "-x", "c++-header" }; HeaderDefinition header = _context.Header; foreach (string includeFolder in GetItemIncludeFolders(header)) { options.Add("-I"); options.Add(includeFolder); } return(options.ToArray()); }
public void Setup() { using (var memory = new MemoryStream(ExcelFiles.FirstSample)) { var header = new HeaderDefinition<FirstSampleData>(); header.Skip(2); header.Register(x => x.ColunaC).Formatter("pt-BR"); header.Register(x => x.ColunaD); header.Register(x => x.ColunaE); data = WorkbookReader.Create(header) .Read(new HSSFWorkbook(memory)); } }
private void WriteHeader(HeaderDefinition header) { if (header.Nodes.Count == 0) { return; } var fileWriter = new CSharpFileTokenizer(); TokenizerContext context = fileWriter.Tokenize(header); var tokenWriter = new TokenWriter(); tokenWriter.Write(header.FullPath, context); }
public void CanStopWhenNoMoreLinesFound() { using (var memory = new MemoryStream(ExcelFiles.MultiSheetsSample)) { var header = new HeaderDefinition<FirstSampleData>(); header.Skip(2); header.Register(x => x.ColunaC).Formatter("pt-BR"); var data = WorkbookReader.Create(header, 2) .Read(new HSSFWorkbook(memory))["TestD"]; data.Records.Count().Should().Be(0); } }
private void ReadSourceItems(XmlReader reader, SourceItemDefinition parent) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "Folder": case "Header": { SourceItemDefinition item; var name = reader.GetAttribute("Name"); var isExcluded = "true".Equals(reader.GetAttribute("IsExcluded")); if (reader.Name.Equals("Folder")) { item = new FolderDefinition(name); } else // if (reader.Name.Equals("Header")) { item = new HeaderDefinition(name); } parent.AddChild(item); item.IsExcluded = isExcluded; if (item.IsFolder) { ReadSourceItems(reader, item); } } break; case "IncludeFolder": ReadIncludeFolder(reader, parent); break; default: throw new NotImplementedException(); } } else if (reader.NodeType == XmlNodeType.EndElement) { return; } } }
public void CanGetFormattingErrors() { using (var memory = new MemoryStream(ExcelFiles.FirstSample)) { var header = new HeaderDefinition<FirstSampleData>(); header.Skip(2); header.Register(x => x.ColunaC).Formatter("en-US"); var data = WorkbookReader.Create(header) .Read(new HSSFWorkbook(memory))[0]; data.Records.Count().Should().Be(4); data.Errors.Count().Should().Be(4); data.Errors.Select(x => x.Column).Should().Have.SameSequenceAs(2, 2, 2, 2); } }
public void CodeModelParse() { string path = Assembly.GetExecutingAssembly().Location; path = Path.GetDirectoryName(path); path = Path.Combine(path, "CppTestProject"); var rootFolder = new RootFolderDefinition(path); var header = new HeaderDefinition("header1.h"); rootFolder.AddChild(header); NamespaceDefinition globalNamespace = new CppParser().ParseRootFolder(rootFolder); Assert.AreEqual(1, globalNamespace.Children.Count); }
public void CanGetNonNullableColumnsError() { using (var memory = new MemoryStream(ExcelFiles.MultiSheetsSample)) { var header = new HeaderDefinition<FirstSampleData>(); header.Skip(2); header.Register(x => x.ColunaC).Formatter("pt-BR"); var data = WorkbookReader.Create(header) .Read(new HSSFWorkbook(memory))[1]; data.Records.Count().Should().Be(4); data.Errors.Count().Should().Be(1); data.Errors.Select(x => x.Column).Should().Have.SameSequenceAs(2); data.Errors.Select(x => x.Row).Should().Have.SameSequenceAs(3); } }
static void ReadHeaderDefinition(WrapperProject project, XmlReader reader) { string sourceRootFolder = project.SourceRootFoldersFull.Last(); string headerPath = Path.Combine(sourceRootFolder, reader.GetAttribute("Path")); headerPath = headerPath.Replace('\\', '/'); var header = new HeaderDefinition(headerPath); string isExcluded = reader.GetAttribute("IsExcluded"); if ("true".Equals(isExcluded)) { header.IsExcluded = true; } project.HeaderDefinitions.Add(headerPath, header); if (reader.IsEmptyElement) { return; } while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "Class": case "ClassTemplate": case "Enum": { var classes = ReadClassDefinition(project, reader, header).ToList(); foreach (var @class in classes) { project.ClassDefinitions.Add(@class.FullyQualifiedName, @class); } } break; } } else if (reader.NodeType == XmlNodeType.EndElement) { break; } } }
public static NamespaceTreeNode GetTree(HeaderDefinition header) { if (header.Nodes.Count == 0) { throw new InvalidOperationException("Header has no associated namespace"); } var firstNode = header.Nodes.First(); var global = GetNamespacePath((NamespaceDefinition)firstNode.Parent).First(); foreach (ModelNodeDefinition node in header.Nodes) { var @namespace = (NamespaceDefinition)node.Parent; var path = GetNamespacePath(@namespace).ToList(); global.Merge(node, path); } return(global); }
private void ParseHeader(HeaderDefinition header) { _context.Header = header; var unsavedFiles = new UnsavedFile[] { }; using (_context.TranslationUnit = _context.Index.CreateTranslationUnit( header.FullPath, GetClangOptions(), unsavedFiles, TranslationUnitFlags.SkipFunctionBodies)) { var tuCursor = _context.TranslationUnit.Cursor; tuCursor.VisitChildren(HeaderVisitor); _context.TranslationUnit = null; } _context.Header = null; }
private SourceItemDefinition CloneSourceItem(SourceItemDefinition item) { if (item == null) { return(null); } if (_oldToNewMapping.TryGetValue(item, out SourceItemDefinition clone)) { return(clone); } if (item is HeaderDefinition) { clone = new HeaderDefinition(item.Name); } else if (item is FolderDefinition) { clone = new FolderDefinition(item.Name); } else if (item is RootFolderDefinition) { clone = new RootFolderDefinition(item.Name); RootFolderClone = RootFolderClone ?? clone as RootFolderDefinition; } else { throw new NotSupportedException(); } _oldToNewMapping[item] = clone; clone.Parent = CloneSourceItem(item.Parent); foreach (SourceItemDefinition child in item.Children.Where(c => !c.IsExcluded)) { var childClone = CloneSourceItem(child); clone.Children.Add(childClone); } return(clone); }
static void ReadHeaderDefinition(WrapperProject project, XmlReader reader, string sourceRootFolder) { string headerPath = Path.Combine(sourceRootFolder, reader.GetAttribute("Path")); headerPath = headerPath.Replace('\\', '/'); HeaderDefinition header = new HeaderDefinition(headerPath); string isExcluded = reader.GetAttribute("IsExcluded"); if ("true".Equals(isExcluded)) { header.IsExcluded = true; } project.HeaderDefinitions.Add(headerPath, header); if (reader.IsEmptyElement) { return; } while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "ClassDefinition": case "ClassTemplateDefinition": case "EnumDefinition": { ReadClassDefinition(project, reader, header); } break; } } else if (reader.NodeType == XmlNodeType.EndElement) { break; } } }
public void CreatesNativeMethodImports() { var @namespace = new NamespaceDefinition(); var @class = new ClassDefinition("CppClass"); var method = new MethodDefinition("method"); @namespace.AddChild(@class); @class.AddChild(method); var rootFolder = new RootFolderDefinition("root"); var header = new HeaderDefinition("header.h"); rootFolder.AddChild(header); header.AddNode(@class); new DotNetTransformer().Transform(@namespace, rootFolder); var methodsHeader = rootFolder.Children.FirstOrDefault(c => c.Name == "UnsafeNativeMethods.cs"); Assert.IsNotNull(methodsHeader); var methodsClass = @namespace.Children.FirstOrDefault(c => c.Name == "UnsafeNativeMethods") as ClassDefinition; Assert.IsNotNull(methodsClass); Assert.That(methodsClass.Children, Has.Count.EqualTo(1)); var nativeMethod = methodsClass.Methods.First(); Assert.AreEqual("CppClass_method", nativeMethod.Name); Assert.IsTrue(nativeMethod.IsStatic); Assert.IsTrue(nativeMethod.IsExtern); Assert.That(nativeMethod.Parameters, Has.Length.EqualTo(1)); var objParameter = nativeMethod.Parameters[0]; Assert.AreEqual("obj", objParameter.Name); }
static void ReadClassDefinition(WrapperProject project, XmlReader reader, HeaderDefinition header, ClassDefinition parent = null) { string className = reader.GetAttribute("Name"); ClassDefinition @class; string classType = reader.Name; switch (classType) { case "ClassDefinition": @class = new ClassDefinition(className, header, parent); break; case "ClassTemplateDefinition": @class = new ClassTemplateDefinition(className, header, parent); break; case "EnumDefinition": @class = new EnumDefinition(className, header, parent); break; default: throw new NotImplementedException(); } string namespaceName = reader.GetAttribute("Namespace"); if (namespaceName != null) { @class.NamespaceName = namespaceName; } string isExcluded = reader.GetAttribute("IsExcluded"); if ("true".Equals(isExcluded)) { @class.IsExcluded = true; } project.ClassDefinitions.Add(@class.FullyQualifiedName, @class); if (reader.IsEmptyElement) { return; } while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "ClassDefinition": case "ClassTemplateDefinition": case "EnumDefinition": { ReadClassDefinition(project, reader, header, @class); } break; } } else if (reader.NodeType == XmlNodeType.EndElement) { break; } } }
static void ReadClassDefinition(WrapperProject project, XmlReader reader, HeaderDefinition header, ClassDefinition parent = null) { string className = reader.GetAttribute("Name"); ClassDefinition @class; string classType = reader.Name; switch (classType) { case "Class": @class = new ClassDefinition(className, header, parent); break; case "ClassTemplate": @class = new ClassTemplateDefinition(className, header, parent); break; case "Enum": @class = new EnumDefinition(className, header, parent); break; default: throw new NotImplementedException(); } string namespaceName = reader.GetAttribute("Namespace"); if (namespaceName != null) { @class.NamespaceName = namespaceName; } if ("true".Equals(reader.GetAttribute("IsExcluded"))) { @class.IsExcluded = true; } if ("true".Equals(reader.GetAttribute("HasPreventDelete"))) { @class.HasPreventDelete = true; } project.ClassDefinitions.Add(@class.FullyQualifiedName, @class); if (reader.IsEmptyElement) { return; } while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "Class": case "ClassTemplate": case "Enum": { ReadClassDefinition(project, reader, header, @class); } break; case "Method": { ReadMethodDefinition(reader, @class); } break; } } else if (reader.NodeType == XmlNodeType.EndElement) { break; } } }
static IEnumerable<ClassDefinition> ReadClassDefinition(WrapperProject project, XmlReader reader, HeaderDefinition header, ClassDefinition parent = null) { string className = reader.GetAttribute("Name"); ClassDefinition @class; string classType = reader.Name; switch (classType) { case "Class": @class = new ClassDefinition(className, header, parent); break; case "ClassTemplate": @class = new ClassTemplateDefinition(className, header, parent); break; case "Enum": @class = new EnumDefinition(className, header, parent); break; default: throw new NotImplementedException(); } string namespaceName = reader.GetAttribute("Namespace"); if (namespaceName != null) { @class.NamespaceName = namespaceName; } if ("true".Equals(reader.GetAttribute("IsExcluded"))) @class.IsExcluded = true; if ("true".Equals(reader.GetAttribute("HasPreventDelete"))) @class.HasPreventDelete = true; if ("true".Equals(reader.GetAttribute("MarshalAsStruct"))) @class.MarshalAsStruct = true; if (reader.IsEmptyElement) { yield return @class; yield break; } while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "Class": case "ClassTemplate": case "Enum": var classes = ReadClassDefinition(project, reader, header, @class); foreach (var c in classes) { yield return c; } break; case "Method": ReadMethodDefinition(reader, @class); break; case "TemplateParameter": (@class as ClassTemplateDefinition).TemplateParameters .Add(reader.ReadElementContentAsString()); break; } } else if (reader.NodeType == XmlNodeType.EndElement) { break; } } yield return @class; }
static IEnumerable <ClassDefinition> ReadClassDefinition(WrapperProject project, XmlReader reader, HeaderDefinition header, ClassDefinition parent = null) { string className = reader.GetAttribute("Name"); ClassDefinition @class; string classType = reader.Name; switch (classType) { case "Class": @class = new ClassDefinition(className, header, parent); break; case "ClassTemplate": @class = new ClassTemplateDefinition(className, header, parent); break; case "Enum": @class = new EnumDefinition(className, header, parent); break; default: throw new NotImplementedException(); } string namespaceName = reader.GetAttribute("Namespace"); if (namespaceName != null) { @class.NamespaceName = namespaceName; } if ("true".Equals(reader.GetAttribute("IsExcluded"))) { @class.IsExcluded = true; } if ("true".Equals(reader.GetAttribute("HasPreventDelete"))) { @class.HasPreventDelete = true; } if ("true".Equals(reader.GetAttribute("MarshalAsStruct"))) { @class.MarshalAsStruct = true; } if (reader.IsEmptyElement) { yield return(@class); yield break; } while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "Class": case "ClassTemplate": case "Enum": var classes = ReadClassDefinition(project, reader, header, @class); foreach (var c in classes) { yield return(c); } break; case "Method": ReadMethodDefinition(reader, @class); break; case "TemplateParameter": (@class as ClassTemplateDefinition).TemplateParameters .Add(reader.ReadElementContentAsString()); break; } } else if (reader.NodeType == XmlNodeType.EndElement) { break; } } yield return(@class); }
static void ReadHeaderDefinition(WrapperProject project, XmlReader reader) { string sourceRootFolder = project.SourceRootFoldersFull.Last(); string headerPath = Path.Combine(sourceRootFolder, reader.GetAttribute("Path")); headerPath = headerPath.Replace('\\', '/'); var header = new HeaderDefinition(headerPath); string isExcluded = reader.GetAttribute("IsExcluded"); if ("true".Equals(isExcluded)) { header.IsExcluded = true; } project.HeaderDefinitions.Add(headerPath, header); if (reader.IsEmptyElement) { return; } while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "Class": case "ClassTemplate": case "Enum": { ReadClassDefinition(project, reader, header); } break; } } else if (reader.NodeType == XmlNodeType.EndElement) { break; } } }
/// <inheritdoc /> public bool IsHeaderNamespace(string namespaceName) => HeaderDefinition.IsHeaderNamespace(namespaceName);
/// <summary> /// Initialize builder with contract details. /// <param name="protocol">X-Road protocol to use when generating service description.</param> /// <param name="schemaDefinitionProvider">Provides overrides for default presentation format.</param> /// <param name="version">Global version for service description (when versioning entire schema and operations using same version number).</param> /// </summary> public ProducerDefinition(IXRoadProtocol protocol, SchemaDefinitionProvider schemaDefinitionProvider, uint?version = null) { if (protocol == null) { throw new ArgumentNullException(nameof(protocol)); } this.protocol = protocol; if (schemaDefinitionProvider == null) { throw new ArgumentNullException(nameof(schemaDefinitionProvider)); } this.schemaDefinitionProvider = schemaDefinitionProvider; this.version = version; contractAssembly = schemaDefinitionProvider.ProtocolDefinition.ContractAssembly; portType = new PortType { Name = "PortTypeName" }; binding = new Binding { Name = "BindingName", Type = new XmlQualifiedName(portType.Name, protocol.ProducerNamespace) }; servicePort = new Port { Name = "PortName", Binding = new XmlQualifiedName(binding.Name, protocol.ProducerNamespace) }; service = new Service { Name = "ServiceName", Ports = { servicePort } }; CollectTypes(); var globalNamespaces = new Dictionary <string, string>(); addGlobalNamespace = (namespaceName) => { var prefix = NamespaceConstants.GetPreferredPrefix(namespaceName); if (string.IsNullOrEmpty(prefix)) { return(false); } globalNamespaces[prefix] = namespaceName; return(true); }; getGlobalNamespaces = () => globalNamespaces.Select(x => Tuple.Create(x.Key, x.Value)).ToList(); var requiredImports = new SortedSet <Tuple <string, string> >(); addRequiredImport = (schemaNamespace, typeNamespace, schemaExporter) => { if (typeNamespace == NamespaceConstants.XSD || typeNamespace == schemaNamespace) { return; } if (!schemaLocations.ContainsKey(typeNamespace)) { schemaLocations.Add(typeNamespace, schemaDefinitionProvider.GetSchemaLocation(typeNamespace, schemaExporter)); } requiredImports.Add(Tuple.Create(schemaNamespace, typeNamespace)); }; getRequiredImports = ns => requiredImports.Where(x => x.Item1 == ns).Select(x => x.Item2).ToList(); xRoadPrefix = schemaDefinitionProvider.GetXRoadPrefix(); xRoadNamespace = schemaDefinitionProvider.GetXRoadNamespace(); headerDefinition = schemaDefinitionProvider.GetXRoadHeaderDefinition(); addGlobalNamespace(NamespaceConstants.SOAP); addGlobalNamespace(NamespaceConstants.WSDL); addGlobalNamespace(NamespaceConstants.XSD); }
public override TableDefinition Content(ReportData reportData, Dictionary <string, string> options) { int nbLimit = options.GetIntOption("COUNT", reportData.Parameter.NbResultDefault); // Max number of rows; -1 correspond to all results bool perModule = options.GetBoolOption("MODULES"); // module or application mode bool showGrades = options.GetBoolOption("GRADE", true); // show/hide grades bool showCritical = options.GetBoolOption("CRITICAL", true); // show/hide critical rules bool showNonCritical = options.GetBoolOption("NONCRITICAL"); // show/hide critical rules bool showAddedRemoved = options.GetBoolOption("ADDEDREMOVED", true); // show/hide added/removed bool showTotal = options.GetBoolOption("TOTAL", true); // show/hide total bool showFailedChecks = options.GetBoolOption("FAILED"); // show/hide failed checks bool showSuccessfulChecks = options.GetBoolOption("SUCCESSFUL"); // show/hide successfull checks bool showCompliance = options.GetBoolOption("COMPLIANCE"); // show/hide compliance ration var headers = new HeaderDefinition(); headers.Append(Labels.ModuleName, perModule); headers.Append(Labels.RuleName); headers.Append(Labels.Grade, showGrades); headers.Append(Labels.ViolationsCount, showFailedChecks); headers.Append(Labels.TotalOk, showSuccessfulChecks); headers.Append(Labels.TotalChecks, showTotal); headers.Append(Labels.Compliance, showCompliance); headers.Append(Labels.ViolationsAdded, showAddedRemoved); headers.Append(Labels.ViolationsRemoved, showAddedRemoved); headers.Append(Labels.Critical); var dataRow = headers.CreateDataRow(); var data = new List <string>(); int nbRow = 0; if (reportData.CurrentSnapshot != null) { Dictionary <int, RuleDetails> targetRules = reportData.RuleExplorer .GetRulesDetails(reportData.CurrentSnapshot.DomainId, Constants.BusinessCriteria.TechnicalQualityIndex.GetHashCode(), reportData.CurrentSnapshot.Id) .Where(rd => rd.Key.HasValue && ((showCritical && rd.Critical) || (showNonCritical && rd.Critical == false))) .ToDictionary(rd => rd.Key.Value); var sourceResults = reportData.CurrentSnapshot.QualityRulesResults.Where(qr => targetRules.ContainsKey(qr.Reference.Key)).ToList(); var modules = (perModule ? reportData.CurrentSnapshot.Modules : new List <Module>(new Module[] { null }).AsEnumerable()).OrderBy(m => (m == null ? string.Empty : m.Name)); foreach (var module in modules) { if (perModule) { dataRow.Set(Labels.ModuleName, module.Name.NAIfEmpty()); } var query = sourceResults.Select(ar => new { ar.Reference, AppDetailResult = ar.DetailResult, ModDetailResult = GetModuleResult(ar, module) }); foreach (var result in query) { if ((nbLimit != -1) && (nbRow >= nbLimit)) { continue; } var detailResult = perModule ? result.ModDetailResult : result.AppDetailResult; if (detailResult != null && detailResult.Grade > 0) { dataRow.Set(Labels.RuleName, result.Reference?.Name.NAIfEmpty()); if (showGrades) { dataRow.Set(Labels.Grade, detailResult.Grade?.ToString("N2")); } if (showFailedChecks) { dataRow.Set(Labels.ViolationsCount, (bool)detailResult.ViolationRatio?.FailedChecks.HasValue ? detailResult.ViolationRatio?.FailedChecks.Value.ToString("N0") : Constants.No_Value); } if (showSuccessfulChecks) { dataRow.Set(Labels.TotalOk, (bool)detailResult.ViolationRatio?.SuccessfulChecks.HasValue ? detailResult.ViolationRatio?.SuccessfulChecks.Value.ToString("N0") : Constants.No_Value); } if (showTotal) { dataRow.Set(Labels.TotalChecks, (bool)detailResult.ViolationRatio?.TotalChecks.HasValue ? detailResult.ViolationRatio?.TotalChecks.Value.ToString("N0") : Constants.No_Value); } if (showCompliance) { dataRow.Set(Labels.Compliance, detailResult.ViolationRatio?.Ratio.FormatPercent(false)); } if (showAddedRemoved) { dataRow.Set(Labels.ViolationsAdded, detailResult.EvolutionSummary?.AddedViolations.NAIfEmpty()); dataRow.Set(Labels.ViolationsRemoved, detailResult.EvolutionSummary?.RemovedViolations.NAIfEmpty()); } var ruleId = result.Reference?.Key; dataRow.Set(Labels.Critical, (ruleId.HasValue && targetRules.ContainsKey(ruleId.Value) && targetRules[ruleId.Value].Critical) ? "X" : ""); data.AddRange(dataRow); } nbRow++; } } } if (data.Count == 0) { dataRow.Reset(); dataRow.Set(0, Labels.NoItem); data.AddRange(dataRow); } data.InsertRange(0, headers.Labels); return(new TableDefinition { Data = data, HasColumnHeaders = true, HasRowHeaders = false, NbColumns = headers.Count, NbRows = data.Count / headers.Count }); }
private static HeaderDefinition<BasicData> CreateHeader() { var header = new HeaderDefinition<BasicData>(); header.Register(x => x.ColunaA).Named("A"); header.Skip(1); header.Register(x => x.ColunaC).Formatter("pt-BR"); header.Skip(1); header.Register(x => x.ColunaE); header.SkippingRows(4); return header; }
public void WriteSoapHeader(XmlWriter writer, Style style, ISoapHeader header, HeaderDefinition definition, IEnumerable <XElement> additionalHeaders = null) { if (header == null) { return; } writer.WriteStartElement("Header", @namespace); header.WriteTo(writer, style, definition); foreach (var additionalHeader in additionalHeaders ?? Enumerable.Empty <XElement>()) { additionalHeader.WriteTo(writer); } writer.WriteEndElement(); }
public override TableDefinition Content(ReportData reportData, Dictionary <string, string> options) { string standard = options.GetOption("STD"); bool vulnerability = options.GetOption("LBL", "vulnerabilities").ToLower().Equals("vulnerabilities"); string lbltotal = vulnerability ? Labels.TotalVulnerabilities : Labels.TotalViolations; string lbladded = vulnerability ? Labels.AddedVulnerabilities : Labels.AddedViolations; string lblremoved = vulnerability ? Labels.RemovedVulnerabilities : Labels.RemovedViolations; // cellProps will contains the properties of the cell (background color) linked to the data by position in the list stored with cellidx. List <CellAttributes> cellProps = new List <CellAttributes>(); int cellidx = 0; var headers = new HeaderDefinition(); headers.Append(standard); cellidx++; headers.Append(lbltotal); cellidx++; headers.Append(lbladded); cellidx++; headers.Append(lblremoved); cellidx++; var dataRow = headers.CreateDataRow(); var data = new List <string>(); List <ApplicationResult> results = reportData.SnapshotExplorer.GetQualityStandardsTagsResults(reportData.CurrentSnapshot.Href, standard)?.FirstOrDefault()?.ApplicationResults?.ToList(); if (results?.Count > 0) { foreach (var result in results) { var detailResult = result.DetailResult; if (detailResult == null) { continue; } int? nbViolations = detailResult.EvolutionSummary?.TotalViolations; string stdTagName = result.Reference?.Name + " " + reportData.Application.StandardTags?.Where(_ => _.Key == result.Reference?.Name).FirstOrDefault()?.Name; dataRow.Set(standard, stdTagName); if (nbViolations > 0) { cellProps.Add(new CellAttributes(cellidx, Color.Beige)); } cellidx++; dataRow.Set(lbltotal, detailResult.EvolutionSummary?.TotalViolations.NAIfEmpty("N0")); if (nbViolations > 0) { cellProps.Add(new CellAttributes(cellidx, Color.Beige)); } cellidx++; dataRow.Set(lbladded, detailResult.EvolutionSummary?.AddedViolations.NAIfEmpty("N0")); if (nbViolations > 0) { cellProps.Add(new CellAttributes(cellidx, Color.Beige)); } cellidx++; dataRow.Set(lblremoved, detailResult.EvolutionSummary?.RemovedViolations.NAIfEmpty("N0")); if (nbViolations > 0) { cellProps.Add(new CellAttributes(cellidx, Color.Beige)); } cellidx++; data.AddRange(dataRow); } } if (data.Count == 0) { dataRow.Reset(); dataRow.Set(0, Labels.NoRules); data.AddRange(dataRow); } data.InsertRange(0, headers.Labels); return(new TableDefinition { Data = data, HasColumnHeaders = true, HasRowHeaders = false, NbColumns = headers.Count, NbRows = data.Count / headers.Count, CellsAttributes = cellProps }); }
protected override TableDefinition Content(ReportData reportData, Dictionary<string, string> options) { bool perModule = options.GetBoolOption("MODULES", false); // module or application mode bool showGrades = options.GetBoolOption("GRADE", true); // show/hide grades bool showCritical = options.GetBoolOption("CRITICAL", true); // show/hide critical rules bool showNonCritical = options.GetBoolOption("NONCRITICAL", false); // show/hide critical rules bool showAddedRemoved = options.GetBoolOption("ADDEDREMOVED", true); // show/hide added/removed bool showTotal = options.GetBoolOption("TOTAL", true); // show/hide total bool showFailedChecks = options.GetBoolOption("FAILED", false); // show/hide failed checks bool showSuccessfulChecks = options.GetBoolOption("SUCCESSFUL", false); // show/hide successfull checks bool showCompliance = options.GetBoolOption("COMPLIANCE", false); // show/hide compliance ration var headers = new HeaderDefinition(); headers.Append(Labels.ModuleName, perModule); headers.Append(Labels.RuleName); headers.Append(Labels.Grade, showGrades); headers.Append(Labels.ViolationsCount, showFailedChecks); headers.Append(Labels.TotalOk, showSuccessfulChecks); headers.Append(Labels.TotalChecks, showTotal); headers.Append(Labels.Compliance, showCompliance); headers.Append(Labels.ViolationsAdded, showAddedRemoved); headers.Append(Labels.ViolationsRemoved, showAddedRemoved); headers.Append(Labels.Critical); var dataRow = headers.CreateDataRow(); var data = new List<string>(); if (reportData != null && reportData.CurrentSnapshot != null) { Dictionary<int, RuleDetails> targetRules = reportData.RuleExplorer .GetRulesDetails(reportData.CurrentSnapshot.DomainId, Constants.BusinessCriteria.TechnicalQualityIndex.GetHashCode(), reportData.CurrentSnapshot.Id) .Where(rd => rd.Key.HasValue && ((showCritical && rd.Critical == true) || (showNonCritical && rd.Critical == false))) .ToDictionary(rd => rd.Key.Value); var sourceResults = reportData.CurrentSnapshot.QualityRulesResults.Where(qr => targetRules.ContainsKey(qr.Reference.Key)); var modules = (perModule ? reportData.CurrentSnapshot.Modules : new List<Module>(new Module[] { null }).AsEnumerable()).OrderBy(m => (m == null ? string.Empty : m.Name)); foreach (var module in modules) { if (perModule) { dataRow.Set(Labels.ModuleName, module.Name.DashIfEmpty()); } var query = sourceResults.Select(ar => new { Reference = ar.Reference, AppDetailResult = ar.DetailResult, ModDetailResult = GetModuleResult(ar, module) }); foreach (var result in query) { var detailResult = perModule ? result.ModDetailResult : result.AppDetailResult; if (detailResult != null && detailResult.Grade > 0) { dataRow.Set(Labels.RuleName, result.Reference?.Name.DashIfEmpty()); if (showGrades) { dataRow.Set(Labels.Grade, detailResult.Grade.ToString("N2")); } if (showFailedChecks) { dataRow.Set(Labels.ViolationsCount, detailResult.ViolationRatio?.FailedChecks.DashIfEmpty()); } if (showSuccessfulChecks) { dataRow.Set(Labels.TotalOk, detailResult.ViolationRatio?.SuccessfulChecks.DashIfEmpty()); } if (showTotal) { dataRow.Set(Labels.TotalChecks, detailResult.ViolationRatio?.TotalChecks.DashIfEmpty()); } if (showCompliance) { dataRow.Set(Labels.Compliance, detailResult.ViolationRatio?.Ratio.FormatPercent(false)); } if (showAddedRemoved) { dataRow.Set(Labels.ViolationsAdded, detailResult.EvolutionSummary.AddedViolations.DashIfEmpty()); dataRow.Set(Labels.ViolationsRemoved, detailResult.EvolutionSummary?.RemovedViolations.DashIfEmpty()); } var ruleId = result.Reference?.Key; dataRow.Set(Labels.Critical, (ruleId.HasValue && targetRules.ContainsKey(ruleId.Value) && targetRules[ruleId.Value].Critical) ? "X" : ""); data.AddRange(dataRow); } } } } if (data.Count == 0) { dataRow.Reset(); dataRow.Set(0, Labels.NoItem); data.AddRange(dataRow); } data.InsertRange(0, headers.Labels); return new TableDefinition { Data = data, HasColumnHeaders = true, HasRowHeaders = false, NbColumns = headers.Count, NbRows = data.Count / headers.Count }; }
private static HeaderDefinition<NullableData> CreateHeader() { var header = new HeaderDefinition<NullableData>(); header.Register(x => x.ColunaA).Named("A"); header.Register(x => x.ColunaB).Named("B"); header.Register(x => x.ColunaC).Formatter("pt-BR"); header.Register(x => x.ColunaD).Named("D"); header.Register(x => x.ColunaE); return header; }
private static HeaderDefinition<NullableData> CreateHeader() { var header = new HeaderDefinition<NullableData>(); header.Register(x => x.ColunaA).Named("A"); header.Register(x => x.ColunaD).Named("D"); header.Register(x => x.GetWhatever()[1].ToString()).Named("H"); header.Register(x => x.GetWhatever()[3].ToString()).Named("I"); return header; }
/// <summary> /// Serializes X-Road message SOAP headers to XML. /// </summary> public virtual void WriteTo(XmlWriter writer, Style style, HeaderDefinition definition) { if (writer.LookupPrefix(NamespaceConstants.XROAD_V4) == null) { writer.WriteAttributeString(PrefixConstants.XMLNS, PrefixConstants.XROAD, NamespaceConstants.XMLNS, NamespaceConstants.XROAD_V4); } if (writer.LookupPrefix(NamespaceConstants.XROAD_V4_ID) == null) { writer.WriteAttributeString(PrefixConstants.XMLNS, PrefixConstants.ID, NamespaceConstants.XMLNS, NamespaceConstants.XROAD_V4_ID); } if (definition.RequiredHeaders.Contains(XName.Get("client", NamespaceConstants.XROAD_V4)) || Client != null) { var element = new XElement(XName.Get("client", NamespaceConstants.XROAD_V4), new XAttribute(XName.Get("objectType", NamespaceConstants.XROAD_V4_ID), string.IsNullOrWhiteSpace(Client.SubsystemCode) ? "MEMBER" : "SUBSYSTEM"), new XElement(XName.Get("xRoadInstance", NamespaceConstants.XROAD_V4_ID), Client.XRoadInstance), new XElement(XName.Get("memberClass", NamespaceConstants.XROAD_V4_ID), Client.MemberClass), new XElement(XName.Get("memberCode", NamespaceConstants.XROAD_V4_ID), Client.MemberCode)); if (!string.IsNullOrWhiteSpace(Client.SubsystemCode)) { element.Add(new XElement(XName.Get("subsystemCode", NamespaceConstants.XROAD_V4_ID), Client.SubsystemCode)); } element.WriteTo(writer); } if (definition.RequiredHeaders.Contains(XName.Get("service", NamespaceConstants.XROAD_V4)) || Service != null) { var element = new XElement(XName.Get("service", NamespaceConstants.XROAD_V4), new XAttribute(XName.Get("objectType", NamespaceConstants.XROAD_V4_ID), "SERVICE"), new XElement(XName.Get("xRoadInstance", NamespaceConstants.XROAD_V4_ID), Service.XRoadInstance), new XElement(XName.Get("memberClass", NamespaceConstants.XROAD_V4_ID), Service.MemberClass), new XElement(XName.Get("memberCode", NamespaceConstants.XROAD_V4_ID), Service.MemberCode)); if (!string.IsNullOrWhiteSpace(Service.SubsystemCode)) { element.Add(new XElement(XName.Get("subsystemCode", NamespaceConstants.XROAD_V4_ID), Service.SubsystemCode)); } element.Add(new XElement(XName.Get("serviceCode", NamespaceConstants.XROAD_V4_ID), Service.ServiceCode)); if (!string.IsNullOrWhiteSpace(Service.ServiceVersion)) { element.Add(new XElement(XName.Get("serviceVersion", NamespaceConstants.XROAD_V4_ID), Service.ServiceVersion)); } element.WriteTo(writer); } if (definition.RequiredHeaders.Contains(XName.Get("centralService", NamespaceConstants.XROAD_V4)) || CentralService != null) { var element = new XElement(XName.Get("centralService", NamespaceConstants.XROAD_V4), new XAttribute(XName.Get("objectType", NamespaceConstants.XROAD_V4_ID), "CENTRALSERVICE"), new XElement(XName.Get("xRoadInstance", NamespaceConstants.XROAD_V4_ID), CentralService.XRoadInstance), new XElement(XName.Get("serviceCode", NamespaceConstants.XROAD_V4_ID), CentralService.ServiceCode)); element.WriteTo(writer); } void WriteHeaderValue(string elementName, object value, XName typeName) { var name = XName.Get(elementName, NamespaceConstants.XROAD_V4); if (definition.RequiredHeaders.Contains(name) || value != null) { style.WriteHeaderElement(writer, name, value, typeName); } } WriteHeaderValue("id", Id, XmlTypeConstants.String); WriteHeaderValue("userId", UserId, XmlTypeConstants.String); WriteHeaderValue("issue", Issue, XmlTypeConstants.String); WriteHeaderValue("protocolVersion", ProtocolVersion, XmlTypeConstants.String); }
public override TableDefinition Content(ReportData reportData, Dictionary <string, string> options) { List <string> metrics = options.GetOption("METRICS").Trim().Split('|').ToList(); bool critical; if (options == null || !options.ContainsKey("CRITICAL")) { critical = false; } else { critical = options.GetOption("CRITICAL").Equals("true"); } bool displayCompliance = options.GetBoolOption("COMPLIANCE"); bool sortedByCompliance = displayCompliance && options.GetOption("SORTED", "TOTAL").Equals("COMPLIANCE"); bool vulnerability = options.GetOption("LBL", "vulnerabilities").ToLower().Equals("vulnerabilities"); string lbltotal = vulnerability ? Labels.TotalVulnerabilities : Labels.TotalViolations; string lbladded = vulnerability ? Labels.AddedVulnerabilities : Labels.AddedViolations; string lblremoved = vulnerability ? Labels.RemovedVulnerabilities : Labels.RemovedViolations; // cellProps will contains the properties of the cell (background color) linked to the data by position in the list stored with cellidx. List <CellAttributes> cellProps = new List <CellAttributes>(); int cellidx = 0; var headers = new HeaderDefinition(); headers.Append(Labels.CASTRules); cellidx++; headers.Append(lbltotal); cellidx++; headers.Append(lbladded); cellidx++; headers.Append(lblremoved); cellidx++; headers.Append(Labels.ComplianceScorePercent, displayCompliance); if (displayCompliance) { cellidx++; } var dataRow = headers.CreateDataRow(); var data = new List <string>(); List <string> qualityRules = MetricsUtility.BuildRulesList(reportData, metrics, critical); List <ApplicationResult> results = sortedByCompliance ? reportData.CurrentSnapshot?.QualityRulesResults.Where(_ => qualityRules.Contains(_.Reference.Key.ToString())).OrderBy(_ => _.DetailResult.ViolationRatio.Ratio).ToList() : reportData.CurrentSnapshot?.QualityRulesResults.Where(_ => qualityRules.Contains(_.Reference.Key.ToString())).OrderByDescending(_ => _.DetailResult.ViolationRatio.FailedChecks).ToList(); if (results?.Count > 0) { foreach (var result in results) { var detailResult = result.DetailResult; if (detailResult == null) { continue; } int nbViolations = detailResult.ViolationRatio.FailedChecks ?? 0; dataRow.Set(Labels.CASTRules, (result.Reference?.Name + " (" + result.Reference?.Key + ")").NAIfEmpty()); if (nbViolations > 0) { cellProps.Add(new CellAttributes(cellidx, Color.Beige)); } cellidx++; dataRow.Set(lbltotal, detailResult.ViolationRatio.FailedChecks.HasValue ? detailResult.ViolationRatio?.FailedChecks.Value.ToString("N0") : Constants.No_Value); if (nbViolations > 0) { cellProps.Add(new CellAttributes(cellidx, Color.Beige)); } cellidx++; dataRow.Set(lbladded, detailResult.EvolutionSummary?.AddedViolations.NAIfEmpty("N0")); if (nbViolations > 0) { cellProps.Add(new CellAttributes(cellidx, Color.Beige)); } cellidx++; dataRow.Set(lblremoved, detailResult.EvolutionSummary?.RemovedViolations.NAIfEmpty("N0")); if (nbViolations > 0) { cellProps.Add(new CellAttributes(cellidx, Color.Beige)); } cellidx++; if (displayCompliance) { dataRow.Set(Labels.ComplianceScorePercent, detailResult.ViolationRatio?.Ratio.FormatPercent(false)); if (nbViolations > 0) { cellProps.Add(new CellAttributes(cellidx, Color.Beige)); } cellidx++; } data.AddRange(dataRow); } } if (data.Count == 0) { dataRow.Reset(); dataRow.Set(0, Labels.NoRules); data.AddRange(dataRow); } data.InsertRange(0, headers.Labels); return(new TableDefinition { Data = data, HasColumnHeaders = true, HasRowHeaders = false, NbColumns = headers.Count, NbRows = data.Count / headers.Count, CellsAttributes = cellProps }); }