Ejemplo n.º 1
0
        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);
        }
        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);
        }