public override bool Run(WorkInfo workInfo) { NodeIndexer indexer = null; bool bStatus = false; try { logger.Info("Running_workflow"); workInfo.Log(this.DisplayName, NLog.LogLevel.Info, "Running Module"); if (this.OutputNode.State == null) { workInfo.Log(this.DisplayName, NLog.LogLevel.Error, "XML Module OutputNode.State is null"); return(false); } if (this.OutputNode.State.Schema == null) { workInfo.Log(this.DisplayName, NLog.LogLevel.Error, "OutputNode.State.Schema is null"); return(false); } if (this.OutputNode.State.DataFilePath == null) { workInfo.Log(this.DisplayName, NLog.LogLevel.Error, "XML Input module OutputNode.State.DataFilePath is null"); return(false); } // if input file doesn't exists or differ from loaded we need to load it if (this.OutputNode.State.DataFile == null || this.OutputNode.State.DataFile.FilePath != this.OutputNode.State.DataFilePath) { this.OutputNode.State.DataFile = WorkflowFileFactory.LoadFromXmlFile(this.OutputNode.State.DataFilePath); } Field.SetParent(this.OutputNode.State.Schema); Field.ComputeXPath(this.OutputNode.State.Schema); workInfo.Schema = this.OutputNode.State.Schema; bool isValid = false; indexer = new NodeIndexer(); /* * indexer.OnProgressChange += (object sender, float p) => * { * workInfo.UpdateProgress(this, p); * }; * * indexer.OnIndexingCompleted += (object sender, EventArgs e) => * { * workInfo.Log(this.DisplayName, NLog.LogLevel.Info, "Node indexing completed"); * }; * * indexer.OnError = (string err) => * { * workInfo.Log(this.DisplayName, NLog.LogLevel.Info, err); * }; */ workInfo.Log(this.DisplayName, NLog.LogLevel.Info, "Starting indexing process, please wait...."); indexer.LoadData(this.OutputNode.State.DataFilePath, this.OutputNode.State.Schema); workInfo.Indexer = indexer; workInfo.Log(this.DisplayName, NLog.LogLevel.Info, "Indexing process completed"); //string fieldXPath= FirstLevelSchemaNode.GetXPath(FirstLevelSchemaNode.Parent); workInfo.Log(this.DisplayName, NLog.LogLevel.Info, "Starting optionality validation process, please wait...."); foreach (var nodeName in indexer.GetFirstLevelNodes()) { int Count = indexer.GetNodeCount(nodeName); workInfo.Log(this.DisplayName, NLog.LogLevel.Info, $"[{nodeName}].Count = {Count} Nodes"); } this.OutputNode.State.DataFile.OnValidationProgressChange += (s, e) => { workInfo.UpdateProgress(this, e); }; var validationErrors = new List <string>(); isValid = this.OutputNode.State.DataFile.ValidateUsingSchema(this.OutputNode.State.Schema, indexer.GetTotalNodeCount(), out validationErrors); this.OutputNode.State.DataFile.OnValidationProgressChange = null; foreach (var message in validationErrors) { workInfo.Log(this.DisplayName, NLog.LogLevel.Error, message); } /* * indexer.NodeParsed += (object sender, NodeIndexEventArgs e) => * { * isValid = validator.Validate(RootSchemaNode, indexer.GetXMLNode(e.CurrentNode.Id)); * if (isValid == false) * { * foreach (var message in validator.ErrorList) * { * workInfo.Log(this.DisplayName, NLog.LogLevel.Info, message); * } * indexer.StopIndexing = true; * } * }; */ /* * foreach (var node in indexer.NodeMap) * { * isValid = validator.Validate(this.OutputNode.State.Schema.ChildNodes[0], indexer.GetXMLNode(node.Key, true)); * if (isValid == false) * { * foreach (var message in validator.ErrorList) * { * workInfo.Log(this.DisplayName, NLog.LogLevel.Info, message); * } * break; * } * } */ //isValid = true; if (isValid == false) { workInfo.Log(this.DisplayName, NLog.LogLevel.Error, $"Halting workflow execution due to xml validation error"); return(false); } if (indexer.ItemCount <= 0) { workInfo.Log(this.DisplayName, NLog.LogLevel.Error, $"Halting workflow execution as there are no xml nodes in xml file"); return(false); } bStatus = true; } catch (Exception ex) { workInfo.Log(this.DisplayName, NLog.LogLevel.Error, $"Fatal error occured in {this.DisplayName}"); workInfo.Log(this.DisplayName, NLog.LogLevel.Error, ex.Message); logger.Error(ex, "Workflow_excution_error"); bStatus = false; } finally { if (indexer != null) { indexer.ClearEvents(); indexer.CloseFileStream(); } } workInfo.Log(this.DisplayName, NLog.LogLevel.Info, $"Module completed processing with Status: {bStatus}"); logger.Info($"{this.DisplayName} module completed processing with status:{bStatus}"); return(bStatus); }
private bool CanRun(WorkInfo workInfo) { if (InputNode.IsConnected() == false) { workInfo.Log(this.DisplayName, NLog.LogLevel.Error, $"{this.DisplayName} input node is not connected with any other module"); return(false); } if (this.InputNode.State == null) { workInfo.Log(this.DisplayName, NLog.LogLevel.Error, $"Halting execution as InputNode.State is null"); return(false); } this.InputNode.State.DataFilePath = ((OutputNode)this.InputNode.Connector).State.DataFilePath; this.InputNode.State.DataFile = ((OutputNode)this.InputNode.Connector).State.DataFile; this.InputNode.State.Schema = ((OutputNode)this.InputNode.Connector).State.Schema; if (this.InputNode.State.DataFilePath == null) { workInfo.Log(this.DisplayName, NLog.LogLevel.Error, $"Halting execution as InputNode.State.DataFilePath is null"); return(false); } if (this.InputNode.State.DataFile == null) { this.InputNode.State.DataFile = WorkflowFileFactory.LoadFromXmlFile(this.InputNode.State.DataFilePath); //workInfo.Log(this.DisplayName, NLog.LogLevel.Error, $"Halting execution as InputNode.State.DataFile is null"); //return false; } if (!File.Exists(this.InputNode.State.DataFilePath)) { workInfo.Log(this.DisplayName, NLog.LogLevel.Error, $"Halting execution as {InputNode.State.DataFilePath} does not exist "); return(false); } string prevModuleName = workInfo.NextModuleRTL(this).DisplayName; if (InputNode.State.Schema == null) { workInfo.Log(this.DisplayName, NLog.LogLevel.Error, $"Halting execution as Previous Module {prevModuleName} dis not pass Schema"); return(false); } if (OutputNode.IsConnected() == false) { workInfo.Log(this.DisplayName, NLog.LogLevel.Error, $"Halting execution as OutputNode is not connected"); return(false); } if (OutputNode.State == null) { workInfo.Log(this.DisplayName, NLog.LogLevel.Error, $"Halting execution as OutputNode.State is null"); return(false); } if (string.IsNullOrEmpty(OutputNode.State.DataFilePath)) { workInfo.Log(this.DisplayName, NLog.LogLevel.Error, $"Halting execution as OutputNode.DataFilePath is not set"); return(false); } this.OutputNode.State.Schema = this.InputNode.State.Schema; this.OutputNode.State.DataFile = this.InputNode.State.DataFile; string msg = ""; if (SortingFields.Count <= 0) { msg = string.Format("Halting execution as as sorting fields are not provided"); logger.Warn(msg); workInfo.Log(this.DisplayName, NLog.LogLevel.Error, msg); return(false); } return(true); }