Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        public void Stop()
        {
            try
            {
                #region ApplicationLogEntries
                ApplicationEventMaster Event = unitOfWork.ApplicationEventMasterRepository
                                               .SelectByID(Constants.EventType.Validation_Engine_Stopped);

                ApplicationMaster Application = unitOfWork.ApplicationMasterRepository
                                                .SelectByID(Constants.ApplicationId);

                ApplicationLog obj = unitOfWork.CreateApplicationLogObject(Event, Application,
                                                                           "LoremIpsumMessage", "amjad.leghari");

                unitOfWork.ApplicationLogRepository.Insert(obj);
                unitOfWork.Save();
                #endregion
                this.unitOfWork.Dispose();
                this.Rules             = null;
                this.ConfigXmlDocument = null;
                this.config            = null;
            }
            catch (Exception ex)
            {
                Logger.Instance.GetLogInstance().Error(JsonConvert.SerializeObject(ex));
            }
        }
Ejemplo n.º 2
0
        //private bool validateConfigFile()
        //{

        //}

        /// <summary>
        ///
        /// </summary>
        public void Configure()
        {
            try
            {
                configureValidator();

                #region ApplicationLogEntries
                ApplicationEventMaster Event = unitOfWork.ApplicationEventMasterRepository
                                               .SelectByID(Constants.EventType.Validation_Engine_Configured);

                ApplicationMaster Application = unitOfWork.ApplicationMasterRepository
                                                .SelectByID(Constants.ApplicationId);

                ApplicationLog objApplicationLog = unitOfWork
                                                   .CreateApplicationLogObject(Event, Application, "LoremIpsumMessage",
                                                                               "amjad.leghari");

                unitOfWork.ApplicationLogRepository.Insert(objApplicationLog);
                unitOfWork.Save();
                #endregion
            }
            catch (Exception ex)
            {
                Logger.Instance.GetLogInstance().Error(JsonConvert.SerializeObject(ex));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        public Boolean StartValidation()
        {
            Boolean retVal = false;

            try
            {
                Console.WriteLine("Validation StartValidation Routine ===>");

                retVal = StartValidator();

                #region ApplicationLogEntries
                ApplicationEventMaster Event = unitOfWork.ApplicationEventMasterRepository
                                               .SelectByID(Constants.EventType.Validation_Engine_Started);

                ApplicationMaster application = unitOfWork.ApplicationMasterRepository
                                                .SelectByID(Constants.ApplicationId);

                ApplicationLog obj = unitOfWork.CreateApplicationLogObject(Event, application,
                                                                           "LoremIpsumMessage", "amjad.leghari");

                unitOfWork.ApplicationLogRepository.Insert(obj);
                unitOfWork.Save();
                #endregion

                Console.WriteLine("<=== Validation StartValidation routine ended.");
            }
            catch (Exception ex)
            {
                Logger.Instance.GetLogInstance().Error(JsonConvert.SerializeObject(ex));
            }
            return(retVal);
        }
Ejemplo n.º 4
0
 public void Create(ApplicationEventMaster obj)
 {
     try
     {
         db.ApplicationEventMasters.Add(obj);
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 5
0
 public void Delete(int Id)
 {
     try
     {
         ApplicationEventMaster aemObject = this.db.ApplicationEventMasters.FirstOrDefault(aem => aem.Id == Id);
         aemObject.IsActive = false;
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 6
0
 public void Update(ApplicationEventMaster obj)
 {
     try
     {
         ApplicationEventMaster aemObject = this.db.ApplicationEventMasters.FirstOrDefault(aem => aem.Id == obj.Id && aem.IsActive);
         aemObject = obj;
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="eventName"></param>
        /// <param name="createdBy"></param>
        /// <param name="LastUpdatedBy"></param>
        /// <returns></returns>
        public ApplicationEventMaster CreateApplicationEventMaster(string eventName,
                                                                   string createdBy, string LastUpdatedBy)
        {
            ApplicationEventMaster obj = new ApplicationEventMaster();

            obj.EventName       = eventName;
            obj.CreatedBy       = createdBy;
            obj.CreatedDate     = DateTime.Now;
            obj.LastUpdatedBy   = LastUpdatedBy;
            obj.LastUpdatedDate = DateTime.Now;
            obj.IsActive        = true;
            return(obj);
        }
Ejemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Event"></param>
        /// <param name="Application"></param>
        /// <param name="message"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public ApplicationLog CreateApplicationLogObject(ApplicationEventMaster Event, ApplicationMaster Application,
                                                         string message, string userId)
        {
            ApplicationLog obj = new ApplicationLog();

            obj.Id = Guid.NewGuid();
            obj.ApplicationEventMaster = Event;
            obj.ApplicationMaster      = Application;
            obj.Message   = message;
            obj.TimeStamp = DateTime.Now;
            obj.UserId    = userId;
            return(obj);
        }
Ejemplo n.º 9
0
        public ApplicationEventMaster SelectById(int Id)
        {
            ApplicationEventMaster retVal = null;

            try
            {
                retVal = this.db.ApplicationEventMasters.FirstOrDefault(aem => aem.Id == Id && aem.IsActive);
            }
            catch (Exception)
            {
                throw;
            }

            return(retVal);
        }
Ejemplo n.º 10
0
        /// <summary>
        ///
        /// </summary>
        public void Configure()
        {
            configureValidator();

            #region ApplicationLogEntries
            ApplicationEventMaster Event = unitOfWork.ApplicationEventMasterRepository
                                           .SelectByID(Constants.EventType.Validation_Engine_Configured);

            ApplicationMaster Application = unitOfWork.ApplicationMasterRepository
                                            .SelectByID(Constants.ApplicationId);

            ApplicationLog objApplicationLog = unitOfWork
                                               .CreateApplicationLogObject(Event, Application, "LoremIpsumMessage",
                                                                           "amjad.leghari");

            unitOfWork.ApplicationLogRepository.Insert(objApplicationLog);
            unitOfWork.Save();
            #endregion
        }
Ejemplo n.º 11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ValidationEventHandler(object sender, ValidationEventArgs e)
        {
            try
            {
                var dataType = "";
                if (e.Severity == XmlSeverityType.Warning)
                {
                    Console.Write("WARNING: ");
                    Console.WriteLine(e.Message);
                }
                else if (e.Severity == XmlSeverityType.Error)
                {
                    if (!errorDetected)
                    {
                        this.errorDetected = true;
                        #region ApplicationLogEntries DB Entry
                        ApplicationEventMaster Event = unitOfWork.ApplicationEventMasterRepository
                                                       .SelectByID(Constants.EventType.Standard_Xml_Validation_Failed);

                        ApplicationMaster Application = unitOfWork.ApplicationMasterRepository
                                                        .SelectByID(Constants.ApplicationId);

                        ApplicationLog objAppLog = unitOfWork.CreateApplicationLogObject(Event, Application,
                                                                                         "LoremIpsumMessage", "amjad.leghari");

                        unitOfWork.ApplicationLogRepository.Insert(objAppLog);
                        unitOfWork.Save();
                        #endregion
                    }

                    IXmlLineInfo node = sender as IXmlLineInfo;
                    if (node != null && node.HasLineInfo())
                    {
                        Console.WriteLine(node.LinePosition);
                        Console.WriteLine(node.LineNumber);
                    }

                    Console.Write("ERROR: ");
                    Console.WriteLine(e.Message);

                    Console.Write("DataKey: ");
                    var obj = sender as XmlReader;
                    Console.WriteLine(obj.Name);
                    Console.Write("DataValue: ");
                    Console.WriteLine(obj.Value);

                    if (obj.SchemaInfo.SchemaElement != null)
                    {
                        Console.Write("DataType: ");
                        dataType = obj.SchemaInfo.SchemaElement.ElementSchemaType.Datatype.TypeCode.ToString();
                        Console.WriteLine(dataType);
                    }
                    if (String.IsNullOrEmpty(dataType))
                    {
                        if (e.Message.Contains("cannot appear more than once"))
                        {
                            dataType = "duplicate elements";
                        }
                    }
                    var xPath = elementStack.Reverse().Aggregate(string.Empty, (x, y) => x + "/" + y);
                    if (!xPath.Contains(obj.Name))
                    {
                        xPath += String.Format("/{0}", obj.Name);
                    }
                    Console.Write("XPath: ");
                    Console.WriteLine(xPath);

                    #region ErrorXml DB Entry
                    if (currentErrorXml == null)
                    {
                        currentErrorXml = unitOfWork.CreateErrorXml(
                            clientCode,
                            warehouseCode,
                            String.IsNullOrEmpty(orderNumber)
                                    ? "dummy order number"
                                    : orderNumber,
                            this.varDocumentType,
                            orderDate,
                            DateTime.Now, this.inProcessXML);

                        unitOfWork.ErrorXmlRepository.Insert(currentErrorXml);
                        unitOfWork.Save();
                    }
                    #endregion
                    //Attribute temp = this.LocalAttributes.Where(attr => attr.name.Equals(obj.Name)).First<Attribute>();

                    bool IsRectifiable = /*(temp!=null) ? temp.is_rectifiable : */ false;
                    if (obj.SchemaInfo != null)
                    {
                        if (obj.SchemaInfo.SchemaElement != null)
                        {
                            if (obj.SchemaInfo.SchemaElement.UnhandledAttributes != null)
                            {
                                //if (obj.SchemaInfo.SchemaElement.moreAttributes.Count > 0)
                                if (obj.SchemaInfo.SchemaElement.UnhandledAttributes.Count() > 0)
                                {
                                    if (obj.SchemaInfo.SchemaElement.UnhandledAttributes
                                        .Where(attr => attr.Name.Equals("")).Count() > 0)
                                    {
                                        IsRectifiable = Convert.ToBoolean(obj.SchemaInfo
                                                                          .SchemaElement.UnhandledAttributes
                                                                          .Where(attr => attr.Name.Equals("")).First <XmlAttribute>().Value);
                                    }
                                }
                            }
                        }
                    }

                    #region ErrorInboundData DB Entry
                    ErrorInboundData objErrInbound = unitOfWork.CreateErrorInboundData(obj.Name,
                                                                                       xPath, dataType, obj.Value, this.validator_type, e.Message, "not available",
                                                                                       unitOfWork.ErrorXmlRepository.SelectByID(currentErrorXml.Id), IsRectifiable);

                    unitOfWork.ErrorInboundRepository.Insert(objErrInbound);
                    unitOfWork.Save();
                    #endregion

                    #region ErrorSuggestion DB Entry

                    Error_Suggestion_InboundData_Mapper esidmapObj = new Error_Suggestion_InboundData_Mapper();
                    esidmapObj.Id = Guid.NewGuid();
                    switch (objErrInbound.DataType.ToLower())
                    {
                    case "integer":
                        esidmapObj.ErrorSuggestionId = Constants.Suggestions.XSD_Invalid_Integer;
                        break;

                    case "float":
                        esidmapObj.ErrorSuggestionId = Constants.Suggestions.XSD_Invalid_Float;
                        break;

                    case "datetime":
                        esidmapObj.ErrorSuggestionId = Constants.Suggestions.XSD_Invalid_DateTime;
                        break;

                    case "boolean":
                        esidmapObj.ErrorSuggestionId = Constants.Suggestions.XSD_Invalid_Boolean;
                        break;

                    case "duplicate elements":
                        esidmapObj.ErrorSuggestionId = Constants.Suggestions.XSD_Duplicate_Element;
                        break;

                    case "string":
                        esidmapObj.ErrorSuggestionId = Constants.Suggestions.XSD_Invalid_String;
                        break;

                    default:        break;
                    }

                    esidmapObj.ErrorInboundDataId = objErrInbound.Id;
                    esidmapObj.DateTime           = DateTime.Now;
                    unitOfWork.ErrorSuggestion_InboundDataRepository.Insert(esidmapObj);
                    unitOfWork.Save();
                    #endregion
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.GetLogInstance().Error(JsonConvert.SerializeObject(ex));
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override bool Validate()
        {
            try
            {
                XmlReaderSettings settings = new XmlReaderSettings();

                settings.Schemas.Add(
                    this.LocalAttributes
                    .Where(item => item.name == Constants.XsdValidator_CustomFields.xsd_ns)
                    .First <ValidationRuleEngine.Configuration.Attribute>().value,
                    this.LocalAttributes
                    .Where(item => item.name == Constants.XsdValidator_CustomFields.xsd_file_path)
                    .First <ValidationRuleEngine.Configuration.Attribute>().value);
                settings.ValidationType          = ValidationType.Schema;
                settings.ValidationEventHandler += new ValidationEventHandler(ValidationEventHandler);

                XmlReader reader = XmlReader.Create(this.currentXml.CreateReader(), settings);

                #region ApplicationLogEntries DB Entry
                ApplicationEventMaster Event = unitOfWork.ApplicationEventMasterRepository
                                               .SelectByID(Constants.EventType.Standard_Xml_Validation_Started);

                ApplicationMaster Application = unitOfWork.ApplicationMasterRepository
                                                .SelectByID(Constants.ApplicationId);

                ApplicationLog objApplicationLog = unitOfWork.CreateApplicationLogObject(Event,
                                                                                         Application, "LoremIpsumMessage", "amjad.leghari");

                unitOfWork.ApplicationLogRepository.Insert(objApplicationLog);
                unitOfWork.Save();
                #endregion

                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        elementStack.Push(reader.Name);
                    }
                    if (reader.NodeType == XmlNodeType.EndElement ||
                        (reader.NodeType == XmlNodeType.Element && reader.IsEmptyElement))
                    {
                        elementStack.Pop();
                    }
                }

                if (!errorDetected)
                {
                    #region ApplicationLogEntries DB Entry
                    Event       = unitOfWork.ApplicationEventMasterRepository.SelectByID(Constants.EventType.Standard_Xml_Validation_Succeeded);
                    Application = unitOfWork.ApplicationMasterRepository.SelectByID(Constants.ApplicationId);

                    objApplicationLog = unitOfWork.CreateApplicationLogObject(Event, Application,
                                                                              "LoremIpsumMessage", "amjad.leghari");

                    unitOfWork.ApplicationLogRepository.Insert(objApplicationLog);
                    unitOfWork.Save();
                    #endregion
                }

                currentErrorXml = null;
            }
            catch (Exception ex)
            {
                errorDetected = true;
                Logger.Instance.GetLogInstance().Error(JsonConvert.SerializeObject(ex));
            }
            return(!errorDetected);
        }