private static ManagementController CreateAction(HttpContext context, string name) { name = name.ToUpper(); CacheTable <Type> cache = new CacheTable <Type>(Utility.ActionTypeCacheName); Type type = cache[name]; if (type == null) { int index; string asm; DirectoryInfo dir = new DirectoryInfo(context.Server.MapPath("~/Bin")); foreach (FileInfo file in dir.GetFiles("*.dll", SearchOption.TopDirectoryOnly)) { index = file.Name.LastIndexOf('.'); asm = file.Name.Substring(0, index); type = Type.GetType(string.Concat(asm, ".Management.", name, ",", asm), false, true); if (type != null) { cache[name] = type; break; } } } if (type != null) { return(Activator.CreateInstance(type) as ManagementController); } return(null); }
private T GetDotNetPropertyImpl <T>(object obj, string propertyName, MemberNamePredicate predicate = null) where T : PSMemberInfo { bool lookingForProperties = typeof(T).IsAssignableFrom(typeof(PSProperty)); bool lookingForParameterizedProperties = IsTypeParameterizedProperty(typeof(T)); if (!lookingForProperties && !lookingForParameterizedProperties) { return(null); } CacheTable typeTable = _isStatic ? GetStaticPropertyReflectionTable((Type)obj) : GetInstancePropertyReflectionTable(obj.GetType()); object entry = typeTable[propertyName]; return(entry switch { null => null, PropertyCacheEntry cacheEntry when lookingForProperties => new PSProperty( cacheEntry.member.Name, this, obj, cacheEntry) as T, ParameterizedPropertyCacheEntry paramCacheEntry when lookingForParameterizedProperties => new PSParameterizedProperty( paramCacheEntry.propertyName, this, obj, paramCacheEntry) as T, _ => null, });
public Printer(Cache shared_data, Printer configuration) : base(shared_data, configuration) { Name = configuration.Name; PrinterName = configuration.PrinterName; FileName = configuration.FileName; SourceModule = new CacheTable(SharedData, DrivingData, configuration.SourceModule); }
public void Setup() { this.cacheTable = new CacheTable <WrappedInt, int>(10, this.N); for (int i = 0; i < this.N; i++) { this.cacheTable[i] = i; } this.i = this.N; }
public void AddTable(SqlCommand command, string tableNames, int expireTime, DataTable table, int organizationID) { if (!GlobalCacheEnabled) { return; } CacheTable item = new CacheTable(); item.Table = table; AddItem(item, command, tableNames, expireTime, organizationID); }
public override bool InitializeOutputFields() { CacheTable = PrimaryTransform.CacheTable.Copy(); //add the operation type, which indicates whether record is rejected 'R' or 'C/U/D' create/update/delete if (CacheTable.Columns.SingleOrDefault(c => c.DeltaType == TableColumn.EDeltaType.DatabaseOperation) == null) { CacheTable.Columns.Insert(0, new TableColumn("Operation", ETypeCode.Byte) { DeltaType = TableColumn.EDeltaType.DatabaseOperation }); } //add the rejection reason, which details the reason for a rejection. if (CacheTable.Columns.SingleOrDefault(c => c.DeltaType == TableColumn.EDeltaType.RejectedReason) == null) { CacheTable.Columns.Add(new TableColumn("RejectReason", ETypeCode.String) { DeltaType = TableColumn.EDeltaType.RejectedReason }); } //add the rejection reason, which details the reason for a rejection. if (CacheTable.Columns.SingleOrDefault(c => c.DeltaType == TableColumn.EDeltaType.ValidationStatus) == null) { CacheTable.Columns.Add(new TableColumn("ValidationStatus", ETypeCode.String) { DeltaType = TableColumn.EDeltaType.ValidationStatus }); } //store reject column details to improve performance. _rejectReasonOrdinal = CacheTable.GetDeltaColumnOrdinal(TableColumn.EDeltaType.RejectedReason); if (_rejectReasonOrdinal >= 0) { _rejectReasonColumnName = CacheTable.Columns[_rejectReasonOrdinal].Name; } _operationOrdinal = CacheTable.GetDeltaColumnOrdinal(TableColumn.EDeltaType.DatabaseOperation); _validationStatusOrdinal = CacheTable.GetDeltaColumnOrdinal(TableColumn.EDeltaType.ValidationStatus); _primaryFieldCount = PrimaryTransform.FieldCount; _columnCount = CacheTable.Columns.Count; _mapFieldOrdinals = new List <int>(); for (var i = 0; i < _primaryFieldCount; i++) { _mapFieldOrdinals.Add(GetOrdinal(PrimaryTransform.GetName(i))); } return(true); }
public RestService(Cache shared_data, RestService configuration) : base(shared_data, configuration) { Name = configuration.Name; Endpoint = TextParser.Parse(configuration.Endpoint, DrivingData, SharedData, ModuleCommands); Verb = configuration.Verb; ParameterCollection = configuration.ParameterCollection; if (configuration.DrivingModule != null) { DrivingModule = new CacheTable(SharedData, DrivingData, configuration.DrivingModule); } }
public LanPoster(Cache shared_data, LanPoster configuration) : base(shared_data, configuration) { ErrorOnFileNotFound = configuration.ErrorOnFileNotFound; ZipFile = configuration.ZipFile; MinFileSizeToZip = configuration.MinFileSizeToZip; DestinationContainer = configuration.DestinationContainer; OverWrite = configuration.OverWrite; MaxDocuments = configuration.MaxDocuments; FileName = configuration.FileName; DrivingModule = new CacheTable(SharedData, DrivingData, configuration.DrivingModule); }
public DataTable GetTable(SqlCommand command) { CacheTable item = GetCacheItem(GetIndexString(command)) as CacheTable; if (item != null) { return(item.Table); } else { return(null); } }
protected override void OnProcess(object sender, EventArgs e) { // Check to see if the writer has a driving table defined. When a driving table is // used against the writer, a transform is created for EACH item in the driving table. if (!string.IsNullOrEmpty(DrivingTableName)) { // A driving table is defined in the config. Make sure it exists in the global dataset. if (SharedData.Data.Contains(DrivingTableName)) { if (SharedData.Data.Tables(DrivingTableName).Rows.Count > 0) { // Loop through the driving table and create a transform based on each row of the driving table. foreach (DataRow row in SharedData.Data.Tables(DrivingTableName).Rows) { DrivingData = row; // Re-initialize the source data table so it will use the current driving data. if (SourceDataTable != null) { SourceDataTable = new CacheTable(SharedData, DrivingData, SourceDataTable); } TransformData(); DrivingData = null; } } else { Logger.WriteLine("XsltWriter.TransformData", "", TraceEventType.Information, 2, 0, SharedData.LogCategory); Logger.WriteLine("XsltWriter.TransformData", "DISCARDING TRANSFORM: NO DATA", TraceEventType.Information, 2, 0, SharedData.LogCategory); GoToModule = GoToModuleOnNoData; } } else { throw new Exception("Driving data table " + DrivingTableName + " is missing from the global dataset."); } } else { TransformData(); } }
/// <summary> /// 表说明 /// </summary> /// <returns></returns> public static void InitTable(Data_Source item, bool IsLoad) { var key = string.Format(AppEtl.CacheKey.Table, item.Host); if (RedisInfo.Exists(key, AppEtl.CacheDb) && IsLoad) { return; } var list = new List <CacheTable>(); var dt = new DataTable(); using (var conn = DbProviderFactories.GetFactory(item.Type).CreateConnection()) { conn.ConnectionString = AppCommon.GetConnStr(item); conn.Open(); var cmd = conn.CreateCommand(); cmd.CommandText = TableSql(item); if (cmd.CommandText == "") { return; } var rd = cmd.ExecuteReader(); dt.Load(rd); rd.Close(); } foreach (DataRow row in dt.Rows) { var table = new CacheTable(); table.Comments = row.ItemArray[1] == DBNull.Value ? "" : row.ItemArray[1].ToString(); table.Name = row.ItemArray[0] == DBNull.Value ? "" : row.ItemArray[0].ToString(); list.Add(table); Parallel.Invoke(() => { InitColumn(item, IsLoad, table.Name); }); } RedisInfo.Set <List <CacheTable> >(key, list, 8640, AppEtl.CacheDb); }
private object[] GetRow(DynamicTableEntity currentEntity) { var row = new object[CacheTable.Columns.Count]; var partitionKeyOrdinal = CacheTable.GetDeltaColumnOrdinal(TableColumn.EDeltaType.AzurePartitionKey); if (partitionKeyOrdinal >= 0) { row[partitionKeyOrdinal] = currentEntity.PartitionKey; } var rowKeyOrdinal = CacheTable.GetDeltaColumnOrdinal(TableColumn.EDeltaType.AzureRowKey); if (rowKeyOrdinal >= 0) { row[rowKeyOrdinal] = currentEntity.RowKey; } var timestampOrdinal = CacheTable.GetDeltaColumnOrdinal(TableColumn.EDeltaType.TimeStamp); if (timestampOrdinal >= 0) { row[timestampOrdinal] = currentEntity.Timestamp; } foreach (var value in currentEntity.Properties) { var returnValue = value.Value.PropertyAsObject; if (returnValue == null) { row[CacheTable.GetOrdinal(value.Key)] = DBNull.Value; } else { row[CacheTable.GetOrdinal(value.Key)] = _connection.ConvertEntityProperty(CacheTable[value.Key].DataType, returnValue); } } return(row); }
public Worksheet(Cache shared_data, DataRow driving_data, List <StringCommand> commands, CacheTableCollection conditional_tables, Worksheet configuration) { SharedData = shared_data; DrivingData = driving_data; ModuleCommands = commands; ConditionalTables = conditional_tables; SheetNumber = configuration.SheetNumber; NewSheetName = configuration.NewSheetName; AutoFitColumns = configuration.AutoFitColumns; MaxColumnWidth = configuration.MaxColumnWidth; StartColumn = configuration.StartColumn; StartRow = configuration.StartRow; MaxRows = configuration.MaxRows; RowToDelete = configuration.RowToDelete; IgnoreContent = configuration.IgnoreContent; Header = configuration.Header; Footer = configuration.Footer; Formatting = configuration.Formatting; ColumnNumberToWrap = configuration.ColumnNumberToWrap; SourceDataTable = new CacheTable(SharedData, DrivingData, configuration.SourceDataTable); }
public XsltWriter(Cache sharedData, XsltWriter configuration) : base(sharedData, configuration) { TemplateName = configuration.TemplateName; TemplateBody = configuration.TemplateBody; FileName = configuration.FileName; Overwrite = configuration.Overwrite; AllowEmptyReport = configuration.AllowEmptyReport; Method = configuration.Method; OutputType = configuration.OutputType; ArgumentContainer = configuration.ArgumentContainer; DrivingTableName = configuration.DrivingTableName; EmptyMessage = configuration.EmptyMessage; DestinationDataTable = new CacheTable(SharedData, DrivingData, configuration.DestinationDataTable); GoToModuleOnNoData = configuration.GoToModuleOnNoData; ModuleCommands = new List <StringCommand>(); if (configuration.SourceDataTable != null) { SourceDataTable = new CacheTable(SharedData, DrivingData, configuration.SourceDataTable); } }
public override async Task <bool> Open(long auditKey, SelectQuery query, CancellationToken cancellationToken) { try { AuditKey = auditKey; if (_isOpen) { throw new ConnectionException("The reader is already open."); } _sqlConnection = await((ConnectionSql)ReferenceConnection).NewConnection(); _sqlReader = await ReferenceConnection.GetDatabaseReader(CacheTable, _sqlConnection, query, cancellationToken); _fieldCount = _sqlReader.FieldCount; _fieldOrdinals = new List <int>(); for (var i = 0; i < _sqlReader.FieldCount; i++) { var fieldName = _sqlReader.GetName(i); var ordinal = CacheTable.GetOrdinal(fieldName); if (ordinal < 0) { throw new ConnectionException($"The reader could not be opened as column {fieldName} could not be found in the table {CacheTable.Name}."); } _fieldOrdinals.Add(ordinal); } _sortFields = query?.Sorts; _isOpen = true; return(true); } catch (Exception ex) { throw new ConnectionException($"Open reader failed. {ex.Message}", ex); } }
private string GetMaxValueMultiRowCumulative(int targetId, MetricGroup metricGroup, string metric, string[] keysToReturn) { object[] keys; string maxValue = string.Empty; if (!InMemoryCache.ContainsKey(InMemoryCache.GetCacheKey(targetId, metricGroup, CacheType.Data))) { InMemoryCache.LoadDataIntoCache(targetId, metricGroup, false); } CacheTable dataCache = Configuration.inMemoryCache[InMemoryCache.GetCacheKey(targetId, metricGroup, CacheType.Data)]; int id = dataCache.GetIdOfMaxValue(metric, metricGroup.metrics[metricGroup.GetMetricIdByName(metric)].type); if (id == -1) { return(maxValue); } if (!InMemoryCache.ContainsKey(InMemoryCache.GetCacheKey(targetId, metricGroup, CacheType.Dictionary))) { InMemoryCache.LoadDictionaryIntoCache(targetId, metricGroup, false); } CacheTable dictCache = Configuration.inMemoryCache[InMemoryCache.GetCacheKey(targetId, metricGroup, CacheType.Dictionary)]; int keyId; foreach (string keyName in keysToReturn) { keyId = metricGroup.GetKeyIdByName(keyName); if (keyId != -1) { keys = dictCache[id]; if (keys == null || keys[keyId] == null) { maxValue += " / "; } else { maxValue += String.Format("{0} / ", keys[keyId]); } } else { keyId = metricGroup.GetKeyAttributeIdByName(keyName); keys = dictCache[id]; if (keys == null || keys[metricGroup.NumberOfMultiRowKeys + keyId] == null) { maxValue += " / "; } else { maxValue += String.Format("{0} / ", keys[metricGroup.NumberOfMultiRowKeys + keyId]); } } } maxValue = maxValue.Remove(maxValue.Length - 3); return(maxValue); }
/// <summary> /// Gets the caching table. /// </summary> /// <returns></returns> public static CacheTable GetTable() { CacheTable cTable; if (HttpContext.Current != null) // We are in WEB app { HttpApplicationState CurrApp = HttpContext.Current.Application; if (CurrApp[Configuration.DefaultCacheTableName] != null) cTable = (CacheTable)CurrApp[Configuration.DefaultCacheTableName]; else { CurrApp.Lock(); CurrApp[Configuration.DefaultCacheTableName] = new CacheTable(); CurrApp.UnLock(); cTable = (CacheTable)CurrApp[Configuration.DefaultCacheTableName]; } } else // We are in DESKTOP app { if (CacheHelper.WinAppTable == null) CacheHelper.WinAppTable = new CacheTable(); cTable = CacheHelper.WinAppTable; } return cTable; }
static void Main(string[] args) { var path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); Appconfig.Initialize(path, ConfigurationManager.AppSettings, null); #region Logger log4net.GlobalContext.Properties["LOG4NET_ERROR"] = Appconfig.LOG4NET_ERROR; //log file path log4net.GlobalContext.Properties["LOG4NET_DEBUG"] = Appconfig.LOG4NET_DEBUG; //log file path log4net.Config.XmlConfigurator.Configure(); #endregion #region Cache Appconfig to memory List <string> tableoptions = Appconfig.TableOptions; Dictionary <string, string> TableOptionPair = new Dictionary <string, string>(); tableoptions.ForEach(x => { string tablename = x.SubstringUntil("["); string tableOption = x.SubstringBetween('[', ']'); TableOptionPair.Add(tablename, tableOption); }); #endregion #region setting sap DestinationRegister.RegistrationDestination(new SAPDestinationSetting { AppServerHost = Appconfig.SAPServerHost, Client = Appconfig.SAPClient, SystemNumber = Appconfig.SAPSystemNumber, SystemID = Appconfig.SAPSystemID, User = Appconfig.SAPUser, Password = Appconfig.SAPPassword }); #endregion /*** * Step to cache new table * 1.defined model/model manager and add to intramartdbcontext * 2.put option/table to app config * 3.register table in program class * */ #region RegisteringTable and Type Dictionary <string, Type> tableDict = new Dictionary <string, Type>(); tableDict.Add("KNA1", typeof(KNA1Manger)); tableDict.Add("COAS", typeof(COASManager)); tableDict.Add("V_AUART", typeof(V_AUARTManager)); tableDict.Add("LFA1", typeof(LFA1Manager)); tableDict.Add("KNVV", typeof(KNVVManager)); tableDict.Add("TVV1T", typeof(TVV1TManager)); tableDict.Add("TVV2T", typeof(TVV2TManager)); tableDict.Add("TVV3T", typeof(TVV3TManager)); tableDict.Add("TVKOV", typeof(TVKOVManager)); tableDict.Add("TVKBZ", typeof(TVKBZManager)); tableDict.Add("TVTWT", typeof(TVTWTManager)); tableDict.Add("TVKBT", typeof(TVKBTManager)); tableDict.Add("TVBVK", typeof(TVBVKManager)); tableDict.Add("TVGRT", typeof(TVGRTManager)); tableDict.Add("T171T", typeof(T171TManager)); tableDict.Add("TVKOT", typeof(TVKOTManager)); tableDict.Add("MARA", typeof(MARAManager)); tableDict.Add("MAKT", typeof(MAKTManager)); tableDict.Add("SKA1", typeof(SKA1Manager)); tableDict.Add("SKAT", typeof(SKATManager)); tableDict.Add("MVKE", typeof(MVKEManager)); tableDict.Add("T179", typeof(T179Manager)); tableDict.Add("T179T", typeof(T179TManager)); tableDict.Add("TVM1T", typeof(TVM1TManager)); tableDict.Add("TVM2T", typeof(TVM2TManager)); tableDict.Add("TVM3T", typeof(TVM3TManager)); tableDict.Add("TVM4T", typeof(TVM4TManager)); tableDict.Add("T134T", typeof(T134TManager)); tableDict.Add("T006A", typeof(T006AManager)); tableDict.Add("T001K", typeof(T001KManager)); tableDict.Add("T190ST", typeof(T190STManager)); tableDict.Add("TWSPR", typeof(TWSPRManager)); tableDict.Add("T023T", typeof(T023TManager)); tableDict.Add("TSPAT", typeof(TSPATManager)); tableDict.Add("TVSMT", typeof(TVSMTManager)); tableDict.Add("TVKMT", typeof(TVKMTManager)); tableDict.Add("TMVFT", typeof(TMVFTManager)); tableDict.Add("TTGRT", typeof(TTGRTManager)); tableDict.Add("TLGRT", typeof(TLGRTManager)); tableDict.Add("T024", typeof(T024Manager)); tableDict.Add("T438X", typeof(T438XManager)); tableDict.Add("T438T", typeof(T438TManager)); tableDict.Add("T439T", typeof(T439TManager)); tableDict.Add("T024D", typeof(T024DManager)); tableDict.Add("T001L", typeof(T001LManager)); tableDict.Add("TQ30T", typeof(TQ30TManager)); tableDict.Add("TQ08T", typeof(TQ08TManager)); tableDict.Add("TQ05T", typeof(TQ05TManager)); tableDict.Add("T025", typeof(T025Manager)); tableDict.Add("T025T", typeof(T025TManager)); tableDict.Add("TCK14", typeof(TCK14Manager)); tableDict.Add("TCK15", typeof(TCK15Manager)); tableDict.Add("CEPCT", typeof(CEPCTManager)); tableDict.Add("MBEW", typeof(MBEWManager)); tableDict.Add("T077X", typeof(T077XManager)); tableDict.Add("T151T", typeof(T151TManager)); tableDict.Add("TZONT", typeof(TZONTManager)); tableDict.Add("T005U", typeof(T005UManager)); tableDict.Add("T052U", typeof(T052UManager)); tableDict.Add("PA0001", typeof(PA0001Manager)); tableDict.Add("T005T", typeof(T005TManager)); tableDict.Add("T014T", typeof(T014TManager)); tableDict.Add("ADRC", typeof(ADRCManager)); tableDict.Add("ADR2", typeof(ADR2Manager)); tableDict.Add("ADR6", typeof(ADR6Manager)); tableDict.Add("KNVP", typeof(KNVPManager)); tableDict.Add("KNKK", typeof(KNKKManager)); tableDict.Add("TVSBT", typeof(TVSBTManager)); #endregion log.Debug("-----------------------------------------------------------------------------------------"); log.Debug("Sync Begin"); log.Debug("-----------------------------------------------------------------------------------------"); #region startSync foreach (var tablename in Appconfig.TableToSync) { var option = new List <string>(); if (TableOptionPair.ContainsKey(tablename)) { option.Add(TableOptionPair[tablename]); } if (tableDict.ContainsKey(tablename)) { var targetClass = tableDict[tablename]; CacheTable instance = (CacheTable)Activator.CreateInstance(targetClass, option); var syncComplete = instance.SyncStart(); if (syncComplete) { Console.WriteLine("Table [" + instance._tableName + "] has been synced."); log.Debug("Table [" + instance._tableName + "] has been synced."); } else { Console.WriteLine("Table [" + instance._tableName + "] ERROR occured."); log.Error("Table [" + instance._tableName + "] ERROR occured."); } } } #endregion log.Debug("-----------------------------------------------------------------------------------------"); log.Debug("Sync End"); log.Debug("-----------------------------------------------------------------------------------------"); log.Debug(Environment.NewLine); }
} // end of GenerateSqlStaticDict method // Generates UPDATE statement for closing records and INSERT statement for openning records private static string GenerateSqlSlowDict(int targetId, MetricGroup metricGroup, ProbeResultingData data, List <Tuple <int, int> > rowsChanged, List <int> rowsNotInDict) { CacheTable dict = Configuration.inMemoryCache[InMemoryCache.GetCacheKey(targetId, metricGroup, CacheType.Dictionary)]; string sqlStmt = string.Empty; // old rows where endDate need to be updated if (rowsChanged.Count > 0) { sqlStmt = "UPDATE " + SqlServerProbe.DictTableName(targetId, metricGroup) + Environment.NewLine; sqlStmt += "SET endDate = '" + SqlServerProbe.DateTimeToString(data.probeDateTime) + "'" + Environment.NewLine; sqlStmt += "WHERE"; foreach (Tuple <int, int> ids in rowsChanged) { sqlStmt += Environment.NewLine + "(id = " + ids.Item2.ToString() + " AND "; sqlStmt += "startDate = '" + SqlServerProbe.DateTimeToString((DateTime)dict[ids.Item2][metricGroup.NumberOfMultiRowKeys + metricGroup.NumberOfMultiRowKeyAttributes]) + "')"; sqlStmt += " OR "; } sqlStmt = sqlStmt.Remove(sqlStmt.Length - 4); // remove last ' OR ' sqlStmt += ";" + Environment.NewLine; // new records for changed rows sqlStmt += "INSERT INTO " + SqlServerProbe.DictTableName(targetId, metricGroup) + " (id,"; for (int i = 0; i < metricGroup.NumberOfMultiRowKeys; i++) { sqlStmt += Environment.NewLine + metricGroup.multiRowKeys[i].name.Replace(' ', '_') + ","; } for (int i = 0; i < metricGroup.NumberOfMultiRowKeyAttributes; i++) { sqlStmt += Environment.NewLine + metricGroup.multiRowKeyAttributes[i].name.Replace(' ', '_') + ","; } sqlStmt += "startDate,endDate)" + Environment.NewLine; sqlStmt += "VALUES " + Environment.NewLine; foreach (Tuple <int, int> ids in rowsChanged) { sqlStmt += "(" + ids.Item2.ToString() + ","; for (int j = 0; j < metricGroup.NumberOfMultiRowKeys; j++) { sqlStmt += SqlServerProbe.DataValueToString(metricGroup.multiRowKeys[j].type, data.values[ids.Item1, j]) + ","; } for (int j = 0; j < metricGroup.NumberOfMultiRowKeyAttributes; j++) { sqlStmt += SqlServerProbe.DataValueToString(metricGroup.multiRowKeyAttributes[j].type, data.values[ids.Item1, metricGroup.NumberOfMultiRowKeys + j]) + ","; } // add startDate and endDate sqlStmt += "'" + SqlServerProbe.DateTimeToString(data.probeDateTime) + "',NULL),"; } sqlStmt = sqlStmt.Remove(sqlStmt.Length - 1); // remove last comma } // new rows if (rowsNotInDict.Count > 0) { sqlStmt += "INSERT INTO " + SqlServerProbe.DictTableName(targetId, metricGroup) + " (id,"; for (int i = 0; i < metricGroup.NumberOfMultiRowKeys; i++) { sqlStmt += Environment.NewLine + metricGroup.multiRowKeys[i].name.Replace(' ', '_') + ","; } for (int i = 0; i < metricGroup.NumberOfMultiRowKeyAttributes; i++) { sqlStmt += Environment.NewLine + metricGroup.multiRowKeyAttributes[i].name.Replace(' ', '_') + ","; } sqlStmt += "startDate,endDate)" + Environment.NewLine; sqlStmt += "VALUES " + Environment.NewLine; foreach (int i in rowsNotInDict) { sqlStmt += "(NEXT VALUE FOR " + SqlServerProbe.SchemaName(targetId) + ".seq_" + metricGroup.dictTableName + ","; for (int j = 0; j < metricGroup.NumberOfMultiRowKeys; j++) { sqlStmt += SqlServerProbe.DataValueToString(metricGroup.multiRowKeys[j].type, data.values[i, j]) + ","; } for (int j = 0; j < metricGroup.NumberOfMultiRowKeyAttributes; j++) { sqlStmt += SqlServerProbe.DataValueToString(metricGroup.multiRowKeyAttributes[j].type, data.values[i, metricGroup.NumberOfMultiRowKeys + j]) + ","; } // add startDate and endDate sqlStmt += "'" + SqlServerProbe.DateTimeToString(data.probeDateTime) + "',NULL),"; } sqlStmt = sqlStmt.Remove(sqlStmt.Length - 1); // remove last comma } return(sqlStmt); } // end of GenerateSqlSlowDict method
protected override async Task <object[]> ReadRecord(CancellationToken cancellationToken) { //the saved reject row is when a validation outputs two rows (pass & fail). if (_savedRejectRow != null) { var row = _savedRejectRow; _savedRejectRow = null; return(row); } if (_lastRecord) { return(null); } while (await PrimaryTransform.ReadAsync(cancellationToken)) { var rejectReason = new StringBuilder(); var finalInvalidAction = TransformFunction.EInvalidAction.Pass; //copy row data. var passRow = new object[_columnCount]; for (var i = 0; i < _primaryFieldCount; i++) { passRow[_mapFieldOrdinals[i]] = PrimaryTransform[i]; } if (passRow[_operationOrdinal] == null) { passRow[_operationOrdinal] = 'C'; } object[] rejectRow = null; //run the validation functions if (Validations != null) { foreach (var validation in Validations) { //set inputs for the validation function foreach (var input in validation.Inputs.Where(c => c.IsColumn)) { try { input.SetValue(PrimaryTransform[input.Column]); } catch (Exception ex) { throw new TransformException($"The validation transform {Name} failed setting input parameters on the function {validation.FunctionName} parameter {input.Name} for column {input.Column.TableColumnName()}. {ex.Message}", ex, PrimaryTransform[input.Column.TableColumnName()]); } } bool validationResult; try { var invokeresult = validation.Invoke(); validationResult = (bool)invokeresult; } catch (FunctionIgnoreRowException) { validationResult = false; } catch (Exception ex) { throw new TransformException($"The validation transform {Name} failed on the function {validation.FunctionName}. {ex.Message}", ex); } //if the validation is false. apply any output columns, and set a reject status if (!validationResult) { rejectReason.AppendLine("function: " + validation.FunctionName + ", parameters: " + string.Join(",", validation.Inputs.Select(c => c.Name + "=" + (c.IsColumn ? c.Column.TableColumnName() : c.Value.ToString())).ToArray()) + "."); // fail job immediately. if (validation.InvalidAction == TransformFunction.EInvalidAction.Abend) { var reason = $"The validation rule abended as the invalid action is set to abend. " + rejectReason.ToString(); throw new Exception(reason); } //if the record is to be discarded, continue the loop and get the next source record. if (validation.InvalidAction == TransformFunction.EInvalidAction.Discard) { continue; } //set the final invalidation action based on priority order of other rejections. finalInvalidAction = finalInvalidAction < validation.InvalidAction ? validation.InvalidAction : finalInvalidAction; if (validation.InvalidAction == TransformFunction.EInvalidAction.Reject || validation.InvalidAction == TransformFunction.EInvalidAction.RejectClean) { //if the row is rejected, copy unmodified row to a reject row. if (rejectRow == null) { rejectRow = new object[CacheTable.Columns.Count]; passRow.CopyTo(rejectRow, 0); rejectRow[_operationOrdinal] = 'R'; TransformRowsRejected++; } //add a reject reason if it exists if (_rejectReasonOrdinal >= 0) { if (validation.Outputs != null) { var param = validation.Outputs.SingleOrDefault(c => c.Column.TableColumnName() == _rejectReasonColumnName); if (param != null) { rejectReason.Append(" Reason: " + (string)param.Value); } } } } if (validation.InvalidAction == TransformFunction.EInvalidAction.Clean || validation.InvalidAction == TransformFunction.EInvalidAction.RejectClean) { validation.ReturnValue(); if (validation.Outputs != null) { foreach (var output in validation.Outputs) { if (output.Column.TableColumnName() != "") { var ordinal = CacheTable.GetOrdinal(output.Column); var col = CacheTable.Columns[ordinal]; if (ordinal >= 0) { try { var parseresult = TryParse(col.DataType, output.Value, col.MaxLength); passRow[ordinal] = parseresult; } catch (Exception ex) { throw new TransformException($"The validation transform {Name} failed parsing output values on the function {validation.FunctionName} parameter {output.Name} column {col.Name}. {ex.Message}", ex, output.Value); } } } } } } } } } if (ValidateDataTypes && (finalInvalidAction == TransformFunction.EInvalidAction.Pass || finalInvalidAction == TransformFunction.EInvalidAction.Clean)) { for (var i = 0; i < _columnCount; i++) { var value = passRow[i]; var col = CacheTable.Columns[i]; if (col.DeltaType == TableColumn.EDeltaType.TrackingField || col.DeltaType == TableColumn.EDeltaType.NonTrackingField) { if (value == null || value is DBNull) { if (col.AllowDbNull == false) { if (rejectRow == null) { rejectRow = new object[_columnCount]; passRow.CopyTo(rejectRow, 0); rejectRow[_operationOrdinal] = 'R'; TransformRowsRejected++; } rejectReason.AppendLine("Column:" + col.Name + ": Tried to insert null into non-null column."); finalInvalidAction = TransformFunction.EInvalidAction.Reject; } passRow[i] = DBNull.Value; } else { try { var parseresult = TryParse(col.DataType, value, col.MaxLength); passRow[i] = parseresult; } catch (Exception ex) { // if the parse fails on the column, then write out a reject record. if (rejectRow == null) { rejectRow = new object[_columnCount]; passRow.CopyTo(rejectRow, 0); rejectRow[_operationOrdinal] = 'R'; TransformRowsRejected++; } rejectReason.AppendLine(ex.Message); finalInvalidAction = TransformFunction.EInvalidAction.Reject; } } } } } switch (finalInvalidAction) { case TransformFunction.EInvalidAction.Pass: passRow[_validationStatusOrdinal] = "passed"; return(passRow); case TransformFunction.EInvalidAction.Clean: passRow[_validationStatusOrdinal] = "cleaned"; return(passRow); case TransformFunction.EInvalidAction.RejectClean: passRow[_validationStatusOrdinal] = "rejected-cleaned"; rejectRow[_validationStatusOrdinal] = "rejected-cleaned"; rejectRow[_rejectReasonOrdinal] = rejectReason.ToString(); _savedRejectRow = rejectRow; return(passRow); case TransformFunction.EInvalidAction.Reject: passRow[_validationStatusOrdinal] = "rejected"; rejectRow[_validationStatusOrdinal] = "rejected"; rejectRow[_rejectReasonOrdinal] = rejectReason.ToString(); return(rejectRow); } //should never get here. throw new TransformException("Validation failed due to an unknown error."); } return(null); }