public bool SaveBizRuleCertMetadata(BizRuleCertMetadata bizRuleCertMetadata) { this.tableClient = account.CreateCloudTableClient(); this.tableClient.CreateTableIfNotExist(BizRuleCertTableName); this.tableContext = tableClient.GetDataServiceContext(); bizRuleCertMetadata.PartitionKey = bizRuleCertMetadata.TradingPartnerName; bizRuleCertMetadata.RowKey = bizRuleCertMetadata.RuleCertFileName; bizRuleCertMetadata.Timestamp = DateTime.UtcNow; if (BizRuleCerts.FirstOrDefault(t => t.PartitionKey == bizRuleCertMetadata.PartitionKey && t.RowKey == bizRuleCertMetadata.RowKey) == null) { BizRuleCerts.Add(bizRuleCertMetadata); } // We need upsert functionality here, hence removing AddObject call and adding UpdateObject // this.tableContext.AddObject(TradingPartnerSpecCertTableName, tradingPartnerSpecCert); // http://social.msdn.microsoft.com/Forums/windowsazure/en-US/892340f1-bfe1-4433-9246-b617abe6078c/upsert-operation-in-the-table // http://msdn.microsoft.com/en-us/library/windowsazure/hh452242.aspx // http://www.windowsazure.com/en-us/develop/net/how-to-guides/table-services/#replace-entity tableContext.AttachTo(BizRuleCertTableName, bizRuleCertMetadata); tableContext.UpdateObject(bizRuleCertMetadata); DataServiceResponse response = this.tableContext.SaveChangesWithRetries(SaveChangesOptions.Batch | SaveChangesOptions.ReplaceOnUpdate); return(response.BatchStatusCode == Http200 || response.BatchStatusCode == Http201 || response.BatchStatusCode == Http202); }
public void DeleteBizRuleCert(BizRuleCertMetadata bizRuleCertMetadata) { CloudBlobClient client = this.storageAccount.CreateCloudBlobClient(); CloudBlob blob = client.GetBlobReference(string.Format(CultureInfo.InvariantCulture, "{0}/{1}", this.container.Name, bizRuleCertMetadata.RuleCertFileName)); blob.DeleteIfExists(); }
public static Stream DownloadTradingPartnerSpecCert(BizRuleCertMetadata bizRuleCertMetadata, IDalManager dalManager) { if (GCValidatorHelper.AddDummyDataForCertValidation) { throw new NotImplementedException(); } return(dalManager.GetBizRuleCert(bizRuleCertMetadata)); }
public Stream GetBizRuleCert(BizRuleCertMetadata bizRuleCertMetadata) { CloudBlobClient client = this.storageAccount.CreateCloudBlobClient(); CloudBlob blob = client.GetBlobReference(string.Format(CultureInfo.InvariantCulture, "{0}/{1}", this.container.Name, bizRuleCertMetadata.RuleCertFileName)); MemoryStream ms = new MemoryStream(); blob.DownloadToStream(ms); ms.Position = 0; return(ms); }
public static void DeleteTradingPartnerSpecCertWithMetadata(BizRuleCertMetadata bizRuleCertMetadata, IDalManager dalManager) { if (GCValidatorHelper.AddDummyDataForCertValidation) { return; } // TODO: Ideally we should keep audit trail of delete // Following function will remove the table entry altogether. dalManager.DeleteBizRuleCertMetadata(bizRuleCertMetadata); dalManager.DeleteBizRuleCert(bizRuleCertMetadata); SchemaCache.RemoveBizRuleCert(bizRuleCertMetadata.RuleCertFileName); }
// Should we always overwrite the existing one? public static void UploadBizRuleCert(string certFileName, Stream certFileStream, string userName, IDalManager dalManager) { if (GCValidatorHelper.AddDummyDataForCertValidation) { return; } BizRuleCertMetadata bizRuleCertMetadata = new BizRuleCertMetadata(); // Purposely ignoring Initialize function return type (errors) since I don't expect errors here. bizRuleCertMetadata.Initialize(certFileName, userName, DateTime.UtcNow); dalManager.SaveBizRuleCert(certFileStream, bizRuleCertMetadata); dalManager.SaveBizRuleCertMetadata(bizRuleCertMetadata); SchemaCache.RemoveBizRuleCert(bizRuleCertMetadata.RuleCertFileName); }
public bool DeleteBizRuleCertMetadata(BizRuleCertMetadata bizRuleCertMetadata) { this.tableClient = account.CreateCloudTableClient(); this.tableClient.CreateTableIfNotExist(BizRuleCertTableName); this.tableContext = tableClient.GetDataServiceContext(); bizRuleCertMetadata.PartitionKey = bizRuleCertMetadata.TradingPartnerName; bizRuleCertMetadata.RowKey = bizRuleCertMetadata.RuleCertFileName; bizRuleCertMetadata.Timestamp = DateTime.UtcNow; BizRuleCerts.Remove(bizRuleCertMetadata); tableContext.AttachTo(BizRuleCertTableName, bizRuleCertMetadata, "*"); tableContext.DeleteObject(bizRuleCertMetadata); DataServiceResponse response = this.tableContext.SaveChangesWithRetries(SaveChangesOptions.Batch | SaveChangesOptions.ReplaceOnUpdate); return(response.BatchStatusCode == Http200 || response.BatchStatusCode == Http201 || response.BatchStatusCode == Http202); }
public static BizRuleSet GetBizRuleSet(BizRuleCertMetadata bizRuleCertMetadata, IDalManager dalManager) { BizRuleSet bizRuleSet = gcSpecCertCache.GetObject(bizRuleCertMetadata.RuleCertFileName) as BizRuleSet; if (bizRuleSet == null) { Stream bizRuleStream = dalManager.GetBizRuleCert(bizRuleCertMetadata); if (bizRuleStream == null) { throw new GCEdiValidatorException(string.Format("{0} BizRule not found.", bizRuleCertMetadata.RuleCertFileName)); } GCExcelToBizRuleSet gcExcelToBizRuleSet = new GCExcelToBizRuleSet(); bizRuleSet = gcExcelToBizRuleSet.GenerateBizRuleSet(bizRuleStream); gcBizRuleCertCache.AddObject(bizRuleCertMetadata.RuleCertFileName, bizRuleSet); } return(bizRuleSet); }
// This function is invoked from Ux public static BizRulesValidationResult ValidateBizRules(string userName, string homeOrg, ZipArchive zipArchive, BizRuleCertMetadata bizRuleCertMetadata, IDalManager dalManager) { if (zipArchive == null) { throw new ArgumentNullException("zipArchive", "zipFile cannot be empty"); } if (bizRuleCertMetadata == null) { throw new ArgumentNullException("bizRuleCertMetadata", "bizRuleCertMetadata cannot be empty"); } if (dalManager == null) { throw new ArgumentNullException("dalManager", "dalManager cannot be null"); } #region DummyCode if (GCValidatorHelper.AddDummyDataForInstanceValidation) { List <BizRuleInfo> ruleInfo1 = new List <BizRuleInfo>(); ruleInfo1.Add(new BizRuleInfo() { FileName = "Delphi Corp - Spec Cert - 810 - Send.dat", SegmentPath = "BIG->BIG03", Value = "1/2/2014" }); ruleInfo1.Add(new BizRuleInfo() { FileName = "Delphi Corporation - Spec Cert - 4010 - 856 - receive - Comments.dat", SegmentPath = "PRF->PRF04", Value = "1/3/2014" }); ruleInfo1.Add(new BizRuleInfo() { FileName = "Delphi Corporation - Spec Cert - 4010 - 850 - send - Comments.dat", SegmentPath = "BEG->BEG05", Value = "1/2/2014" }); List <BizRuleInfo> ruleInfo2 = new List <BizRuleInfo>(); ruleInfo2.Add(new BizRuleInfo() { FileName = "Delphi Corp - Spec Cert - 810 - Send", SegmentPath = "BIG->BIG04", Value = "122014" }); ruleInfo2.Add(new BizRuleInfo() { FileName = "Delphi Corporation - Spec Cert - 4010 - 856 - receive - Comments.dat", SegmentPath = "PRF->PRF01", Value = "122014" }); ruleInfo2.Add(new BizRuleInfo() { FileName = "Delphi Corporation - Spec Cert - 4010 - 850 - send - Comments.dat", SegmentPath = "BEG->BEG03", Value = "122014" }); List <BizRuleInfo> ruleInfo3 = new List <BizRuleInfo>(); ruleInfo3.Add(new BizRuleInfo() { FileName = "Delphi Corp - Spec Cert - 810 - Send.dat", SegmentPath = "IT1->IT101", Value = "123" }); ruleInfo3.Add(new BizRuleInfo() { FileName = "Delphi Corporation - Spec Cert - 4010 - 856 - receive - Comments.dat", SegmentPath = "LIN->LIN01", Value = "234" }); ruleInfo3.Add(new BizRuleInfo() { FileName = "Delphi Corporation - Spec Cert - 4010 - 850 - send - Comments.dat", SegmentPath = "PO1->PO1O1", Value = "345" }); BizRulesValidationResult bizRulesValidationResultDummy = new BizRulesValidationResult() { BizRuleCertName = "3M - Biz Rule - X12 810-856-850" }; bizRulesValidationResultDummy.BizRuleValidationResults = new List <BizRuleValidationResult>(); bizRulesValidationResultDummy.BizRuleValidationResults.Add(new BizRuleValidationResult() { RuleName = "Purchase Order Date", Type = ResultType.Error, RuleInfo = ruleInfo1 }); bizRulesValidationResultDummy.BizRuleValidationResults.Add(new BizRuleValidationResult() { RuleName = "Purchase Order Number", Type = ResultType.Success, RuleInfo = ruleInfo2 }); bizRulesValidationResultDummy.BizRuleValidationResults.Add(new BizRuleValidationResult() { RuleName = "Assigned Identification", Type = ResultType.Warning, RuleInfo = ruleInfo3 }); bizRulesValidationResultDummy.EdiValidationResults = new List <EDIValidationResult>(); List <SegmentValidationResult> segmentValidationResult = new List <SegmentValidationResult>(); segmentValidationResult.Add(new SegmentValidationResult() { Description = "Invalid Segment XYZ", Name = "XYZ", SequenceNumber = 5, Type = ResultType.Error, StartIndex = 300, EndIndex = 305, }); bizRulesValidationResultDummy.EdiValidationResults.Add(new EDIValidationResult() { BeautifiedOriginalPayload = "EDI File Contents", FileName = "Delphi Corp - Spec Cert - 810 - Send.dat", SchemaName = "Delphi Corp - Spec Cert - 810 - Send", SegmentValidationResults = new List <SegmentValidationResult>(), // No validation failures TransactionNumbers = new List <string> { "1" }, DisplayName = "Delphi Corp - 810 - Send", Type = "X12_810" }); bizRulesValidationResultDummy.EdiValidationResults.Add(new EDIValidationResult() { BeautifiedOriginalPayload = "EDI File Contents", FileName = "Delphi Corporation - Spec Cert - 4010 - 850 - send - Comments.dat", SchemaName = "Delphi Corporation - Spec Cert - 4010 - 850 - send", SegmentValidationResults = segmentValidationResult, TransactionNumbers = new List <string> { "1" }, DisplayName = "Delphi Corporation - 850 - send", Type = "X12_850" }); bizRulesValidationResultDummy.EdiValidationResults.Add(new EDIValidationResult() { BeautifiedOriginalPayload = "EDI File Contents", FileName = "Delphi Corporation - Spec Cert - 4010 - 856 - receive - Comments.dat", SchemaName = "Delphi Corporation - Spec Cert - 4010 - 856 - receive", SegmentValidationResults = new List <SegmentValidationResult>(), // No validation failures TransactionNumbers = new List <string> { "1" }, DisplayName = "Delphi Corporation - 856 - receive", Type = "X12_856" }); return(bizRulesValidationResultDummy); } #endregion BizRulesValidationResult bizRulesValidationResult = null; string errorMessage = null; try { BizRuleSet bizRuleSet = SchemaCache.GetBizRuleSet(bizRuleCertMetadata, dalManager); List <ZipFileEntry> fileEntries = ZipFileUtil.GetFileEntries(zipArchive); List <DocumentPlugValidationInfo> documentPlugValidationInfoList = new List <DocumentPlugValidationInfo>(); foreach (ZipFileEntry fileEntry in fileEntries) { documentPlugValidationInfoList.Add(GetDocumentPlugValidationInfo(fileEntry, dalManager)); } bizRulesValidationResult = ValidateBizRules(userName, homeOrg, bizRuleCertMetadata.RuleCertFileName, bizRuleSet, documentPlugValidationInfoList, dalManager); } catch (GCEdiValidatorException gcException) { errorMessage = gcException.Message; } catch (Exception) { errorMessage = "Internal error occurred, please contact Maarg"; } if (errorMessage != null) { // TODO: Add generic error } return(bizRulesValidationResult); }
public static BizRuleCertValidationResult ValidateBizRuleCert(string certFileName, Stream certFileStream, IDalManager dalManager) { if (GCValidatorHelper.AddDummyDataForCertValidation) { BizRuleCertValidationResult bizRuleCertValidationResult = new BizRuleCertValidationResult(); bizRuleCertValidationResult.RuleDefinitionValidationResults = new List <RuleDefinitionValidationResult>(); bizRuleCertValidationResult.RuleDefinitionValidationResults.Add(new RuleDefinitionValidationResult() { Type = ResultType.Warning, ColumnIndex = "D", RowIndex = 1, Description = "Invalid message domain id." }); bizRuleCertValidationResult.RuleDefinitionValidationResults.Add(new RuleDefinitionValidationResult() { Type = ResultType.Error, ColumnIndex = "B", RowIndex = 5, Description = "Invalid value for \"Rule Matching Option\"." }); return(bizRuleCertValidationResult); } GCExcelToBizRuleSet gcExcelToBizRuleSet = new GCExcelToBizRuleSet(); try { BizRuleCertMetadata bizRuleCertMetadata = new BizRuleCertMetadata(); List <string> errors = bizRuleCertMetadata.Initialize(certFileName); if (errors.Count == 0) { // Check if this cert file already exist List <BizRuleCertMetadata> bizRuleCertMetadataList = dalManager.GetBizRuleCertFileList(bizRuleCertMetadata.TradingPartnerName); if (bizRuleCertMetadataList.Any(t => t.TradingPartnerName == bizRuleCertMetadata.TradingPartnerName && t.RuleCertFileName == bizRuleCertMetadata.RuleCertFileName)) { gcExcelToBizRuleSet.BizRuleCertValidationResult.RuleDefinitionValidationResults.Add(new RuleDefinitionValidationResult() { ColumnIndex = "N/A", RowIndex = -1, Type = ResultType.Warning, Description = "Cert file already exist." }); } gcExcelToBizRuleSet.GenerateBizRuleSet(certFileStream); } else { foreach (string error in errors) { gcExcelToBizRuleSet.BizRuleCertValidationResult.RuleDefinitionValidationResults.Add(new RuleDefinitionValidationResult() { ColumnIndex = "N/A", RowIndex = -1, Type = ResultType.Error, Description = string.Format("Cert file name error: {0}", error) }); } } } catch (Exception ex) { gcExcelToBizRuleSet.BizRuleCertValidationResult.RuleDefinitionValidationResults.Add(new RuleDefinitionValidationResult() { ColumnIndex = "N/A", RowIndex = -1, Type = ResultType.Error, Description = string.Format("Unknown error occured ({0}), please contact Maarg", ex.Message) }); } return(gcExcelToBizRuleSet.BizRuleCertValidationResult); }
public Stream GetBizRuleCert(BizRuleCertMetadata bizRuleCertMetadata) { DALBizRuleCert dal = new DALBizRuleCert(this.storageAccount, this.container); return(dal.GetBizRuleCert(bizRuleCertMetadata)); }
public void DeleteBizRuleCert(BizRuleCertMetadata bizRuleCertMetadata) { DALBizRuleCert dal = new DALBizRuleCert(this.storageAccount, this.container); dal.DeleteBizRuleCert(bizRuleCertMetadata); }
public bool DeleteBizRuleCertMetadata(BizRuleCertMetadata bizRuleCertMetadata) { DALBizRuleCertMetadata dal = new DALBizRuleCertMetadata(this.storageAccount); return(dal.DeleteBizRuleCertMetadata(bizRuleCertMetadata)); }
public void SaveBizRuleCert(Stream bizRuleCertStream, BizRuleCertMetadata bizRuleCertMetadata) { DALBizRuleCert dal = new DALBizRuleCert(this.storageAccount, this.container); dal.SaveBizRuleCert(bizRuleCertStream, bizRuleCertMetadata); }