private DataRow GetRow(Document runningAsset) { var r = AttributesGrid.NewRow(); var isInserting = FillRow(runningAsset, r); if (!isInserting) return null; r[DpowDocName] = runningAsset.Name; return r; }
private bool FillRow(Document doc, DataRow r) { var isInserting = true; foreach (var attribute in doc.Attributes) { var vA = new ValidatedAttribute(attribute); if (attribute.ExternalEntity != "DPoW Attributes") continue; // check for table columns var sName = attribute.Name; if (!AttributesGrid.Columns.Contains(sName)) { isInserting = false; AttributesGrid.Columns.Add(new DataColumn(attribute.Name, typeof(ValidatedAttribute)) { Namespace = attribute.PropertySetName }); } if (!isInserting || attribute.Value == null) continue; r[sName] = vA; } if (!AttributesGrid.Columns.Contains("DPoW_Directory")) { AttributesGrid.Columns.Add(new DataColumn("DPoW_Directory", typeof(VisualValue))); AttributesGrid.Columns.Add(new DataColumn("DPoW_File", typeof(VisualValue))); return false; } var status = doc.ValidationResult() == StatusOptions.Passed ? VisualAttentionStyle.Green : VisualAttentionStyle.Red; var vDir = new VisualValue(doc.Directory) {AttentionStyle = status}; var vFile = new VisualValue(doc.File) { AttentionStyle = status }; r["DPoW_Directory"] = vDir; r["DPoW_File"] = vFile; return isInserting; }
private bool IsValid(Document submitted) { if (submitted == null) return false; if (IsInvalid(submitted.Directory) && IsInvalid(submitted.File)) return false; return true; }
internal IEnumerable<Document> ValidatedDocs(List<Document> list) { var dicDocs = new Dictionary<string, Document>(); if (list != null) { try { dicDocs = list.ToDictionary(doc => doc.Name, doc => doc); } catch { // creates a dictionary with first values, but also presents a document error. HasFailures = true; foreach (var document in list.Where(document => !dicDocs.ContainsKey(document.Name))) { dicDocs.Add(document.Name, document); } } if (HasFailures) // it must be because of the try/catch earlier { var d = new Document { Name = @"DPoW Validation Error", CreatedBy = new ContactKey {Email = "Validation@DPoW"}, CreatedOn = DateTime.Now, Categories = new List<Category>() { new Category() {Classification = "DPoW", Code = "Test Reports"}, FacilityValidator.FailedCat }, Directory = "n/a", File = "n/a", Description = "Document names are not unique in submission.", }; yield return d; } } foreach (var requiredDocument in _requiredDocuments) { if (TerminationMode == TerminationMode.StopOnFirstFail) yield break; Document submitted = null; if (dicDocs.ContainsKey(requiredDocument.Name)) { submitted = dicDocs[requiredDocument.Name]; } Document tmp; if (IsValid(submitted)) { tmp = _destinationFacility.Clone(submitted); tmp.Categories = new List<Category> { FacilityValidator.PassedCat }; tmp.Attributes = _destinationFacility.Clone(requiredDocument.Attributes as IEnumerable<Attribute>) .ToList(); } else { tmp = _destinationFacility.Clone(requiredDocument); tmp.Directory = submitted != null ? submitted.Directory : ""; tmp.File = submitted != null ? submitted.File : ""; tmp.Categories = new List<Category> { FacilityValidator.FailedCat }; HasFailures = true; } tmp.SetRequirementExternalSystem(requiredDocument.ExternalSystem); tmp.SetRequirementExternalId(requiredDocument.ExternalId); yield return tmp; } }