private MethodInfo GetMethod(string method, ref object instance) { result = new IdpeMessage(IdpeMessageCodes.IDPE_PLUGIN_METHOD_EXECUTION_FAILED); MethodInfo thisMethod = null; Type thisType = this.GetType(); Type[] types = new Type[1]; types[0] = typeof(Job); ConstructorInfo constructor = thisType.GetConstructor(BindingFlags.Instance | BindingFlags.Public, null, CallingConventions.HasThis, types, null); if (constructor == null) { goto Error; } instance = constructor.Invoke(new object[] { _Job }); thisMethod = thisType.GetMethod(method); Error: if (thisMethod == null) { result = new IdpeMessage(IdpeMessageCodes.IDPE_PLUGIN_METHOD_EXECUTION_FAILED_METHOD_NOT_DEFINED); string traceErrMsg = string.Format("'{0}' is not implemented in {1}", method, thisType.FullName); if (_Job != null) { traceErrMsg += string.Format(". Job Id = '{0}'", _Job.JobIdentifier); traceErrMsg += string.Format(". Data Source Id = '{0}'", _Job.DataSource.Name); } traceErrMsg += Environment.NewLine + new StackTrace().ToString(); _Job.TraceError(traceErrMsg); return(null); } return(thisMethod); }
public override void CheckConstraints() { long min = 0; long max = 0; if (!string.IsNullOrEmpty(Minimum)) { min = (long)Minimum.ParseLong(); } if (!string.IsNullOrEmpty(Maximum)) { max = (long)Maximum.ParseLong(); } IdpeMessage result = null; if ((!string.IsNullOrEmpty(Minimum)) && (ValueInt < min)) { this._ParseResult = new IdpeMessage(IdpeMessageCodes.IDPE_TYPE_DATA_VALIDATION_FAILED_MINIMUM); this._ParseResult.Message = string.Format(this._ParseResult.Message, PrintRowColPosition(), ColumnName, Minimum); } else if ((!string.IsNullOrEmpty(Maximum)) && (ValueInt > max)) { this._ParseResult = new IdpeMessage(IdpeMessageCodes.IDPE_TYPE_DATA_VALIDATION_FAILED_MAXIMUM); this._ParseResult.Message = string.Format(result.Message, PrintRowColPosition(), ColumnName, Maximum); } }
public void Assign(Attribute attribute) { //do not put this statement, let the error get thrown //if (attribute == null) return; this.Value = attribute.Value; this.IsNull = attribute.IsNull; this.Error = attribute.Error; this._Result = attribute._Result; this._ValueEnumCode = attribute.ValueEnumCode; this._ValueEnumValue = attribute.ValueEnumValue; }
public SreType(string columnName, string value, AttributeTypes type, string formula, string minimum, string maximum, bool isAssociatedWithSystemRow, int recordPosition) { _ConnectionStringKeyName = Constants.DefaultConnectionStringKeyName; bool result = Init(columnName, value, type, formula, minimum, maximum, isAssociatedWithSystemRow, recordPosition); if (result) { _ParseResult = new IdpeMessage(IdpeMessageCodes.IDPE_SUCCESS); } else { _ParseResult = new IdpeMessage(IdpeMessageCodes.IDPE_FAILED); } }
bool IsSreMessage(string str) { if (string.IsNullOrEmpty(str)) { return(false); } if (str.Contains(typeof(IdpeMessage).ToString())) { string[] sreMsgInfo = str.Split("|".ToCharArray()); IdpeMessageCodes msgCode = (IdpeMessageCodes)Enum.Parse(typeof(IdpeMessageCodes), sreMsgInfo[1], true); _Result = new IdpeMessage(msgCode); _Result.Message = sreMsgInfo[2]; return(true); } return(false); }
public SreType(string columnName, string value, AttributeTypes type, string formula, string minimum, string maximum, bool isAssociatedWithSystemRow, int recordPosition, SqlClientManager sqlClientManager, List <IdpeKey> dataSourceKeys) { _ConnectionStringKeyName = Constants.DefaultConnectionStringKeyName; SqlClientManager = sqlClientManager; _DataSourceKeys = dataSourceKeys; _ConnectionString = DataSourceKeys.GetDefaultConnectionString(); bool result = Init(columnName, value, type, formula, minimum, maximum, isAssociatedWithSystemRow, recordPosition); if (result) { _ParseResult = new IdpeMessage(IdpeMessageCodes.IDPE_SUCCESS); } else { _ParseResult = new IdpeMessage(IdpeMessageCodes.IDPE_FAILED); } }
public bool PrepareInput() { //int dataSourceId = 0; //int.TryParse(e.ApplicationParameters["DataSourceId"].ToString(), out dataSourceId); //if (dataSourceId == 0) // return; InputFileNameOnly = Path.GetFileNameWithoutExtension(InputFileName); //string InputFileExtension = Path.GetExtension(InputFileName); Keys = Cache.Instance.Bag[DataSourceId + ".keys"] as List <IdpeKey>; if (Keys == null) { Keys = DataSource.LoadKeys(DataSourceId); } OutputFolder = DataSource.GetOutputFolder(DataSourceId, Keys); ActualOutputFolder = OutputFolder; OutputFileName = DataSource.GetOutputFileName(DataSourceId, Keys, OutputFolder, InputFileNameOnly); string appWatchFilter = Keys.GetKeyValue(IdpeKeyTypes.WatchFilter); ZipInterfaceName = Keys.GetKeyValue(IdpeKeyTypes.ZipInterfaceName); if ((InputFileExtension.ToLower() == ".zip") || (InputFileExtension.ToLower() == ".rar") || (InputFileExtension.ToLower() == ".tar")) { OutputFolder = Path.Combine(EyediaCoreConfigurationSection.CurrentConfig.TempDirectory, Constants.IdpeBaseFolderName); OutputFolder = Path.Combine(OutputFolder, "RedirectedOutput"); OutputFolder = Path.Combine(OutputFolder, DateTime.Now.ToDBDateFormat()); OutputFolder = Path.Combine(OutputFolder, DataSourceId.ToString()); } if ((!string.IsNullOrEmpty(appWatchFilter)) && (appWatchFilter != Pullers.FileExtensionSupportAll)) { List <string> filters = new List <string>(); if (appWatchFilter.Contains("|")) { filters.AddRange(appWatchFilter.ToLower().Split("|".ToCharArray())); } else { filters.Add(appWatchFilter.ToLower()); } var filterOrNot = (from f in filters where f == InputFileExtension.ToLower() select f).SingleOrDefault(); if (filterOrNot == null) { if (!InputFileNameOnly.StartsWith(Constants.UnzippedFilePrefix)) { IdpeMessage warn = new IdpeMessage(IdpeMessageCodes.IDPE_FILE_TYPE_NOT_SUPPORTED); DataSource dataSource = new DataSource(DataSourceId, string.Empty); WithWarning = string.Format(warn.Message, dataSource.Name, appWatchFilter, Path.GetFileName(InputFileName)); ExtensionMethods.TraceInformation(WithWarning); new PostMan(dataSource).Send(PostMan.__warningStartTag + WithWarning + PostMan.__warningEndTag, "File Ignored"); return(false); } } } if (InputFileNameOnly.StartsWith(Constants.WCFFilePrefix)) { IsRequestFromWCF = true; JobId = InputFileNameOnly.Replace(Constants.WCFFilePrefix, ""); JobId = JobId.Replace(InputFileExtension, ""); } else if (InputFileNameOnly.StartsWith(Constants.UnzippedFilePrefix)) { ZipUniuqeId = ZipFileWatcher.ExtractUniqueId(InputFileNameOnly); OutputFolder = Path.Combine(OutputFolder, ZipUniuqeId); if (!Directory.Exists(OutputFolder)) { Directory.CreateDirectory(OutputFolder); } OutputFileName = Path.Combine(OutputFolder, InputFileNameOnly + Path.GetExtension(OutputFileName)); OutputFileName = ZipFileWatcher.ExtractActualFileName(OutputFileName); } return(true); }
protected override void Execute(CodeActivityContext context) { WorkerData data = context.GetValue(this.Data); int originalPosition = context.GetValue(this.OriginalPostion); SreTraceLogWriter traceLog = data.CurrentRow.TraceLog; data.Job.PerformanceCounter.Start(data.Job.JobIdentifier, RowPerformanceTaskNames.ParseDataTypes_ParseAgain, originalPosition); data.ValueUpdationNotPermitted = true; for (int c = 0; c < data.CurrentRow.Columns.Count; c++) { //if (data.CurrentRow.Columns[c].Name == "AssetId") // Debugger.Break(); if (data.CurrentRow.Columns[c].HasBusinessError) { continue; } IdpeMessage sreMsg = data.CurrentRow.Columns[c].Type.Parse(true); if (data.CurrentRow.Columns[c].Type is SreCodeset) { SreCodeset sreCodeset = data.CurrentRow.Columns[c].Type as SreCodeset; data.CurrentRow.Columns[c].ValueEnumCode = sreCodeset.ValueEnumCode; data.CurrentRow.Columns[c].ValueEnumValue = sreCodeset.ValueEnumValue; data.CurrentRow.Columns[c].ValueEnumReferenceKey = sreCodeset.ReferenceKey; } if ((sreMsg.Code != IdpeMessageCodes.IDPE_SUCCESS) && (sreMsg.Code != data.CurrentRow.Columns[c].Error.Code)) { string oldMsg = data.CurrentRow.Columns[c].Error.Message; data.CurrentRow.Columns[c].Error = sreMsg; data.CurrentRow.Columns[c].Error.Message = string.Format("{0},{1}", oldMsg, data.CurrentRow.Columns[c].Error.Message); } else { data.CurrentRow.Columns[c].Error = sreMsg; } } for (int c = 0; c < data.CurrentRow.ColumnsSystem.Count; c++) { if ((data.CurrentRow.ColumnsSystem[c].Name == "IsValid") || (data.CurrentRow.ColumnsSystem[c].Value == "NULL") || (data.CurrentRow.ColumnsSystem[c].IsNull)) { data.CurrentRow.ColumnsSystem[c].Error.Message = string.Empty; //Clear error when INT type updated with using 'lookup' and it returned 'NULL' continue; } //if (data.CurrentRow.ColumnsSystem[c].Name == "AssetId") // Debugger.Break(); IdpeMessage sreMsg = data.CurrentRow.ColumnsSystem[c].Type.Parse(true); if (data.CurrentRow.ColumnsSystem[c].Type is SreCodeset) { SreCodeset sreCodeset = data.CurrentRow.ColumnsSystem[c].Type as SreCodeset; data.CurrentRow.ColumnsSystem[c].ValueEnumCode = sreCodeset.ValueEnumCode; data.CurrentRow.ColumnsSystem[c].ValueEnumValue = sreCodeset.ValueEnumValue; data.CurrentRow.ColumnsSystem[c].ValueEnumReferenceKey = sreCodeset.ReferenceKey; } if ((data.CurrentRow.ColumnsSystem[c].HasBusinessError) && (sreMsg.Code != IdpeMessageCodes.IDPE_SUCCESS)) { //has business error, parsing failed string oldMsg = data.CurrentRow.ColumnsSystem[c].Error.Message; data.CurrentRow.ColumnsSystem[c].Error = sreMsg; data.CurrentRow.ColumnsSystem[c].Error.Message = string.Format("{0},{1}", oldMsg, data.CurrentRow.ColumnsSystem[c].Error.Message); } else if ((data.CurrentRow.ColumnsSystem[c].HasBusinessError) && (sreMsg.Code == IdpeMessageCodes.IDPE_SUCCESS)) { //has business error, parsing passed //don't do anything, let the error continue } else { data.CurrentRow.ColumnsSystem[c].Error = sreMsg; } } data.Job.PerformanceCounter.Stop(data.Job.JobIdentifier, RowPerformanceTaskNames.ParseDataTypes_ParseAgain, originalPosition); }
/// <summary> /// Parses attributes /// </summary> /// <param name="attributes">Master attribute list</param> /// <param name="column">A column(Attributes) to be parsed</param> /// <param name="isSystemRow">true if processing system row</param> /// <param name="rowPosition">Row position, used only in error information, to identify row. 0(Zero) in case of system attributes.</param> /// <param name="doNotWriteErrorInTraceFile">To avoid confusion, if this is true, it wont write sql query formatting errors into trace file. /// (in case of first attempt, values may not be ready to replace in queries, which is absolutely a valid scenario)</param> internal void Parse(List <IdpeAttribute> attributes, Column column, bool isSystemRow, int rowPosition, bool doNotWriteErrorInTraceFile) { try { List <SreType> sqlQueryTypes = new List <SreType>(); for (int a = 0; a < attributes.Count; a++) { string value = string.Empty; if (column[attributes[a].Name].IsNull == true) { value = "NULL"; column[a].Error = new IdpeMessage(IdpeMessageCodes.IDPE_SUCCESS); } else { value = column[attributes[a].Name].Value; } //if (attributes[a].Name == "AssetId") // Debugger.Break(); SreType SREType = SreTypeFactory.GetInstance(attributes[a].Name, value, attributes[a].Type, attributes[a].Formula, attributes[a].Minimum, attributes[a].Maximum, isSystemRow, rowPosition, this._SQLClientManager, this._DataSourceKeys); column[a].Type = SREType; if (column[attributes[a].Name].IgnoreParsing) { column[a].Error = new IdpeMessage(IdpeMessageCodes.IDPE_SUCCESS); continue; } if ((SREType.Type != AttributeTypes.Referenced) && (SREType.Type != AttributeTypes.NotReferenced) && (SREType.Type != AttributeTypes.Generated)) { //parse rightway...We dont have SQL Queries to fire //we can override errors for all except 'IsValid'...because if rule fails, we manually override its error msgs //and if IsValid.err msg already populated, we will lose that... if (attributes[a].Name == "IsValid") { IdpeMessage errMsg = SREType.Parse(false); if (column[a].Error == null) { column[a].Error = errMsg; } else { column[a].Error.Message += column[a].Error.Message; } } else { IdpeMessage thisResult = SREType.Parse(false); if (column[a].Error == null) { column[a].Error = thisResult; } else { if (thisResult.Code != IdpeMessageCodes.IDPE_SUCCESS) { string oldErrorMsg = column[a].Error.Message; column[a].Error = thisResult; column[a].Error.Message = string.Format("{0},{1}", column[a].Error.Message, oldErrorMsg); } } } //if codeset type, store enum value and code as well if (SREType.Type == AttributeTypes.Codeset) { SreCodeset sreCodeset = SREType as SreCodeset; //if (string.IsNullOrEmpty(column[attributes[a].Name].ValueEnumValue)) // column[attributes[a].Name].ValueEnumValue = column[attributes[a].Name].Value; column[attributes[a].Name].ValueEnumCode = sreCodeset.ValueEnumCode; column[attributes[a].Name].ValueEnumValue = sreCodeset.ValueEnumValue; column[attributes[a].Name].ValueEnumReferenceKey = sreCodeset.ReferenceKey; } else { column[a].Value = SREType.Value; //in case anything updated after parse(at this moment, formatted datetime) } } else { //to be parsed once all others are parsed. sqlQueryTypes.Add(SREType); } column[a].IsNull = SREType.IsNull; } //we have parsed all other values except with sql queries, lets parse those. foreach (SreType item in sqlQueryTypes) { //if (item.ColumnName == "OldInvoiceNumber") // Debugger.Break(); Attribute currentAttribute = column[item.ColumnName]; //efficient, instead of calling string indxr multiple times. if ((item.Type == AttributeTypes.Generated) && (!item.IsHavingSqlQuery)) { if (string.IsNullOrEmpty(currentAttribute.Value)) { currentAttribute.Value = GetFormulaResult(item.Formula); } IdpeMessage thisResult = item.Parse(false); if (currentAttribute.Error == null) { currentAttribute.Error = thisResult; } else { if (thisResult.Code != IdpeMessageCodes.IDPE_SUCCESS) { string oldErrorMsg = currentAttribute.Error.Message; currentAttribute.Error = thisResult; currentAttribute.Error.Message = string.Format("{0},{1}", currentAttribute.Error.Message, oldErrorMsg); } } } else if ((item.Type == AttributeTypes.NotReferenced) && (string.IsNullOrEmpty(currentAttribute.Value))) { //NotReferenced can not be empty at least. currentAttribute.Error = new IdpeMessage(IdpeMessageCodes.IDPE_REFERENCED_TYPE_DATA_CAN_NOT_BE_NULL); currentAttribute.Error.Message = string.Format(currentAttribute.Error.Message, PrintRowColPosition(item.RecordPosition, item.ColumnName, isSystemRow), currentAttribute.Value, item.ColumnName); continue; } else { string errorMessage = string.Empty; string value = currentAttribute.Value; SqlCommandTypes sqlCommandTypes = SqlCommandTypes.Unknown; string connectionStringKeyName = string.Empty; string SQLQuery = FormatSQLFormula(item.Formula, ref sqlCommandTypes, ref connectionStringKeyName, ref errorMessage); string FormattedSQLQuery = string.Empty; if (errorMessage == string.Empty) { if (connectionStringKeyName != Constants.DefaultConnectionStringKeyName) { item.ConnectionStringKeyName = connectionStringKeyName; //string k_n_type = _ApplicationKeys.GetKeyValue(connectionStringKeyName); IdpeKey key = _DataSourceKeys.GetKey(connectionStringKeyName); item.ConnectionString = key.Value; item.DatabaseType = (IdpeKeyTypes)key.Type; } if (sqlCommandTypes == SqlCommandTypes.SqlCommand) { FormattedSQLQuery = FormatSQLParameters(SQLQuery, value, column, ref errorMessage); } else if (sqlCommandTypes == SqlCommandTypes.StoreProcedure) { //todo //FormattedSQLQuery = } } if (errorMessage != string.Empty) { //Prepare return error message (and not the technical exception) IdpeMessage returnMessage = new IdpeMessage(IdpeMessageCodes.IDPE_TYPE_DATA_VALIDATION_FAILED_GENERIC); //Write the error into trace with mapId. Guid detailesMapId = Guid.NewGuid(); //Do not write in trace, as it is actually not an error, tried first attempt if (!doNotWriteErrorInTraceFile) { ExtensionMethods.TraceError(string.Format("{0}:{1}", detailesMapId.ToString(), errorMessage)); } //set mapId in client error msg returnMessage.Message = string.Format("{0}. Map Id:{1}", returnMessage.Message, detailesMapId.ToString()); if (currentAttribute.Error == null) { //send the generic error with mapId currentAttribute.Error = returnMessage; } else { if (currentAttribute.Error.Code != IdpeMessageCodes.IDPE_SUCCESS) { string oldErrorMsg = currentAttribute.Error.Message; currentAttribute.Error = returnMessage; currentAttribute.Error.Message = string.Format("{0},{1}", currentAttribute.Error.Message, oldErrorMsg); } } } else { item.OverrideFormula(FormattedSQLQuery); currentAttribute.Error = item.Parse(false); //SQL Query results are always overridden. currentAttribute.Value = item.Value; } } } //Parsing done, as we have more data (SQL Parameters) now, lets just format all queries one more time, there might be few more parameters in context. FormatAllSQLQueries(column); } catch (Exception ex) { Trace.Write(string.Format("Attribute parsing error, row position = {0}{1}{2}", rowPosition, Environment.NewLine, ex.ToString())); } }