public Fields Read(AbstractConnection connection, string process, string prefix, string name, string schema, bool isMaster = false) { var fields = new Fields(); using (var cn = connection.GetConnection()) { cn.Open(); var sql = PrepareSql(); connection.Logger.EntityDebug(name, sql); var results = cn.Query(sql, new { name, schema }); foreach (var result in results) { var columnName = result.COLUMN_NAME; var type = GetSystemType(result.DATA_TYPE); var length = result.CHARACTER_MAXIMUM_LENGTH == "0" || result.CHARACTER_MAXIMUM_LENGTH == "-1" ? "64" : result.CHARACTER_MAXIMUM_LENGTH; var fieldType = (bool)result.IS_PRIMARY_KEY ? (isMaster ? FieldType.MasterKey : FieldType.PrimaryKey) : FieldType.NonKey; var field = new Field(type, length, fieldType, true, string.Empty) { Name = columnName, Entity = name, Process = process, Index = Convert.ToInt16(result.ORDINAL_POSITION - 1), Schema = schema, Input = true, Precision = result.NUMERIC_PRECISION, Scale = result.NUMERIC_SCALE, Alias = prefix + columnName }; fields.Add(field); } } return fields; }
public Fields Fields() { var fields = new Fields(); foreach (var join in Join) { fields.Add(join.Fields()); } return fields; }
public LuceneKeysExtractAll(LuceneConnection luceneConnection, Entity entity, bool input = false) { _luceneConnection = luceneConnection; _entity = entity; _input = input; _fields = entity.PrimaryKey; if (entity.Version != null && !_fields.HaveField(entity.Version.Alias)) { _fields.Add(entity.Version); } _selected = _fields.Select(f => input ? f.Name : f.Alias).ToArray(); }
protected Fields GetRelationshipFields(IEnumerable<Relationship> rel, Entity entity) { var relationships = rel.Where(r => r.LeftEntity.Alias != entity.Alias && r.RightEntity.Alias != entity.Alias).ToArray(); var fields = new Fields(); if (relationships.Any()) { foreach (var relationship in relationships) { var leftSide = relationship.LeftEntity.RelationshipToMaster.Count(); var rightSide = relationship.RightEntity.RelationshipToMaster.Count(); if (leftSide <= rightSide) { foreach (var join in relationship.Join) { fields.Add(join.LeftField); } } else { foreach (var join in relationship.Join) { fields.Add(join.RightField); } } } } return fields; }
public Fields Read(string name, string schema) { var result = new Fields(); using (var cn = _connection.GetConnection()) { cn.Open(); var cmd = cn.CreateCommand(); cmd.CommandText = string.Format("select * from {0}{1} where 1=2;", schema.Equals(string.Empty) ? string.Empty : _connection.Enclose(schema) + ".", _connection.Enclose(name)); var reader = cmd.ExecuteReader(CommandBehavior.KeyInfo | CommandBehavior.SchemaOnly); var table = reader.GetSchemaTable(); if (table != null) { var keys = table.PrimaryKey.Any() ? table.PrimaryKey.Select(c => c.ColumnName).ToArray() : Enumerable.Empty<string>().ToArray(); foreach (DataRow row in table.Rows) { var columnName = row["ColumnName"].ToString(); var field = new Field(keys.Contains(columnName) ? FieldType.PrimaryKey : FieldType.NonKey) { Name = columnName, Type = Common.ToSimpleType(row["DataType"].ToString()) }; if (field.Type.Equals("string")) { field.Length = row["ColumnSize"].ToString(); } else { field.Precision = Convert.ToInt32(row["NumericPrecision"]); field.Scale = Convert.ToInt32(row["NumericScale"]); } if (Convert.ToBoolean(row["IsRowVersion"])) { field.Length = "8"; field.Type = "rowversion"; } result.Add(field); } } }; return result; }
public override Fields GetEntitySchema(Process process, Entity entity, bool isMaster = false) { var fields = new Fields(); var solr = GetReadonlyOperations(process, entity.OutputName()); var solrSchema = solr.GetSchema(_schemaFile); foreach (var solrField in solrSchema.SolrFields) { string type; var searchType = "default"; if (SolrTypeMap.ContainsKey(solrField.Type.Name)) { type = SolrTypeMap[solrField.Type.Name]; searchType = solrField.Type.Name; } else { type = solrField.Type.Name; } var field = new Field(type, "64", FieldType.None, true, string.Empty) { Name = solrField.Name, Entity = entity.Name, Input = solrField.IsStored, SearchTypes = new List<SearchType>() { new SearchType() { Name = searchType, Analyzer = searchType } } }; fields.Add(field); } return fields; }
/// <summary> /// Execute a command to insert or update data from source to destination table /// </summary> /// <param name="fromTable">Source table</param> /// <param name="toTable">Destination table</param> private void ExecuteInserts(Table fromTable, Table toTable) { Table sourceTable = (m_useFromSchemaRI ? fromTable : toTable); Field autoIncField = null; Field lookupField; Field commonField; bool usingIdentityInsert; // Progress process variables int progressIndex = 0; int progressTotal; // Bulk insert variables bool useBulkInsert = false; string bulkInsertFile = ""; string fieldTerminator = ""; string rowTerminator = ""; FileStream bulkInsertFileStream = null; // Create a field list of all of the common fields in both tables Fields fieldCollection = new Fields(toTable); foreach (Field field in fromTable.Fields) { // Lookup field name in destination table lookupField = toTable.Fields[field.Name]; if ((object)lookupField != null) { // We currently don't handle binary fields... if (!(field.Type == OleDbType.Binary || field.Type == OleDbType.LongVarBinary || field.Type == OleDbType.VarBinary) & !(lookupField.Type == OleDbType.Binary || lookupField.Type == OleDbType.LongVarBinary || lookupField.Type == OleDbType.VarBinary)) { // Copy field information from destination field if (m_useFromSchemaRI) { commonField = new Field(fieldCollection, field.Name, field.Type); commonField.AutoIncrement = field.AutoIncrement; } else { commonField = new Field(fieldCollection, lookupField.Name, lookupField.Type); commonField.AutoIncrement = lookupField.AutoIncrement; } fieldCollection.Add(commonField); } } } // Exit if no common field names were found if (fieldCollection.Count == 0) { m_overallProgress += fromTable.RowCount; return; } progressTotal = fromTable.RowCount; OnRowProgress(fromTable.Name, 0, progressTotal); OnOverallProgress((int)m_overallProgress, (int)m_overallTotal); // Setup to track to and from auto-inc values if table has an identity field if (sourceTable.HasAutoIncField) { foreach (Field field in fieldCollection) { lookupField = sourceTable.Fields[field.Name]; if ((object)lookupField != null) { // We need only track auto inc translations when field is referenced by foreign keys if (lookupField.AutoIncrement & lookupField.ForeignKeys.Count > 0) { // Create a new hash-table to hold auto-inc translations lookupField.AutoIncrementTranslations = new Hashtable(); // Create a new auto-inc field to hold source value autoIncField = new Field(toTable.Fields, field.Name, lookupField.Type); autoIncField.AutoIncrementTranslations = lookupField.AutoIncrementTranslations; break; } } } } // See if this table is a candidate for bulk inserts if (m_attemptBulkInsert || m_forceBulkInsert) useBulkInsert = SetupBulkInsert(toTable, autoIncField, ref bulkInsertFile, ref fieldTerminator, ref rowTerminator, ref bulkInsertFileStream); string selectString = "SELECT " + fieldCollection.GetList(sqlEscapeFunction: m_fromSchema.SQLEscapeName) + " FROM " + fromTable.SQLEscapedName; bool skipKeyValuePreservation = false; // Handle special case of self-referencing table if (sourceTable.IsReferencedBy(sourceTable)) { // We need a special order-by for this scenario to make sure referenced rows are inserted before other rows - this also // means no auto-inc preservation is possible on this table skipKeyValuePreservation = true; selectString += " ORDER BY "; int index = 0; foreach (Field field in sourceTable.Fields) { foreach (ForeignKeyField foreignKey in field.ForeignKeys) { if (string.Compare(sourceTable.Name, foreignKey.ForeignKey.Table.Name, StringComparison.OrdinalIgnoreCase) == 0) { // If Oracle, force it to sort NULLs at a higher level - note coalesce may fail for non-integer based primary keys for self-referencing tables if (m_fromSchema.DataSourceType == DatabaseType.Oracle) selectString += (index > 0 ? ", " : "") + "COALESCE(" + m_fromSchema.SQLEscapeName(foreignKey.ForeignKey.Name) + ", 0)"; else selectString += (index > 0 ? ", " : "") + m_fromSchema.SQLEscapeName(foreignKey.ForeignKey.Name); index++; } } } } else { // Order by auto increment field to help preserve the original value while transferring data to destination table if ((object)autoIncField != null) selectString += " ORDER BY " + m_fromSchema.SQLEscapeName(autoIncField.Name); } // We use an optimization available to some databases when we are preserving the original primary key values if (!skipKeyValuePreservation && m_preserveAutoIncValues && (object)autoIncField != null) { switch (m_toSchema.DataSourceType) { case DatabaseType.SQLServer: try { toTable.Connection.ExecuteNonQuery("SET IDENTITY_INSERT " + toTable.SQLEscapedName + " ON", Timeout); usingIdentityInsert = true; } catch { // This may fail if connected user doesn't have alter rights to destination connection or has // selected the wrong destination database type, in these cases we just fall back on the // brute force method of auto-inc identity synchronization usingIdentityInsert = false; } break; case DatabaseType.MySQL: case DatabaseType.SQLite: usingIdentityInsert = true; break; default: usingIdentityInsert = false; break; } } else { usingIdentityInsert = false; } string insertSQLStub = "INSERT INTO " + toTable.SQLEscapedName + " (" + fieldCollection.GetList(usingIdentityInsert) + ") VALUES ("; string updateSQLStub = "UPDATE " + toTable.SQLEscapedName + " SET "; string countSQLStub = "SELECT COUNT(*) AS Total FROM " + toTable.SQLEscapedName; // Execute source query using (IDataReader fromReader = fromTable.Connection.ExecuteReader(selectString, CommandBehavior.SequentialAccess, Timeout)) { // Read source records and write each to destination while (fromReader.Read()) { if (useBulkInsert) WriteBulkInsertRecord(toTable, fieldCollection, sourceTable, fieldTerminator, rowTerminator, bulkInsertFileStream, fromReader); else InsertDestinationRecord(toTable, fieldCollection, insertSQLStub, updateSQLStub, countSQLStub, usingIdentityInsert, sourceTable, autoIncField, skipKeyValuePreservation, fromReader); progressIndex++; m_overallProgress++; OnRowProgress(fromTable.Name, progressIndex, progressTotal); if (progressIndex % RowReportInterval == 0) OnOverallProgress((int)m_overallProgress, (int)m_overallTotal); } } // Turn off identity inserts and reset auto-inc values if needed if (usingIdentityInsert) { if (m_toSchema.DataSourceType == DatabaseType.SQLServer) { string setIndentityInsertSQL = "SET IDENTITY_INSERT " + toTable.SQLEscapedName + " OFF"; try { // Turn off identity inserts toTable.Connection.ExecuteNonQuery(setIndentityInsertSQL, Timeout); } catch (Exception ex) { OnSQLFailure(setIndentityInsertSQL, new InvalidOperationException(string.Format("Failed to turn off identity inserts on table \"{0}\": {1}", toTable.Name, ex.Message), ex)); } } ResetAutoIncValues(toTable); } if (useBulkInsert & (object)bulkInsertFileStream != null) CompleteBulkInsert(toTable, progressIndex, bulkInsertFile, bulkInsertFileStream); OnRowProgress(fromTable.Name, progressTotal, progressTotal); OnOverallProgress((int)m_overallProgress, (int)m_overallTotal); }
private void SetFields(TableData tableData) { Fields.Clear(); tableData.Columns.ForEach(c => Fields.Add(new TableField(tableData, c, this))); }
private void ProcessNode(XmlNode xmlNode, Fields fields) { if (xmlNode.NodeType != XmlNodeType.Text) { foreach (XmlNode xmlNestedNode in xmlNode.ChildNodes) { ProcessNode(xmlNestedNode, fields); } } else { fields.Add(xmlNode.ParentNode.Name, xmlNode.InnerText); } }
public override Fields GetEntitySchema(Process process, Entity entity, bool isMaster = false) { var client = new ElasticSearchClientFactory().CreateNest(this, entity); var mapping = client.Client.GetMapping<dynamic>(m => m .Index(client.Index) .Type(client.Type) ); if (!mapping.IsValid) { throw new TransformalizeException(Logger, "Trouble getting mapping for {0}:{1} {2}", client.Index, client.Type, mapping.ServerError.Error); } var fields = new Fields(); foreach (var pair in mapping.Mapping.Properties) { fields.Add(new Field(pair.Value.Type.Name, "64", FieldType.None, true, "") { Name = pair.Key.Name }); } return fields; }
void InitMembers(Type type) { foreach (Type nestedType in type.GetNestedTypes(flags)) { // We cannot use nestedType.IsVisible - that only checks for public types, // but we also need to load protected types. if (nestedType.IsNestedPublic || nestedType.IsNestedFamily || nestedType.IsNestedFamORAssem) { string name = this.FullyQualifiedName + "." + nestedType.Name; InnerClasses.Add(new ReflectionClass(CompilationUnit, nestedType, name, this)); } } foreach (FieldInfo field in type.GetFields(flags)) { if (!field.IsPublic && !field.IsFamily && !field.IsFamilyOrAssembly) { continue; } if (!field.IsSpecialName) { Fields.Add(new ReflectionField(field, this)); } } foreach (PropertyInfo propertyInfo in type.GetProperties(flags)) { ReflectionProperty prop = new ReflectionProperty(propertyInfo, this); if (prop.IsPublic || prop.IsProtected) { Properties.Add(prop); } } foreach (ConstructorInfo constructorInfo in type.GetConstructors(flags)) { if (!constructorInfo.IsPublic && !constructorInfo.IsFamily && !constructorInfo.IsFamilyOrAssembly) { continue; } Methods.Add(new ReflectionMethod(constructorInfo, this)); } foreach (MethodInfo methodInfo in type.GetMethods(flags)) { if (!methodInfo.IsPublic && !methodInfo.IsFamily && !methodInfo.IsFamilyOrAssembly) { continue; } if (!methodInfo.IsSpecialName) { Methods.Add(new ReflectionMethod(methodInfo, this)); } } this.AddDefaultConstructorIfRequired = (this.ClassType == ClassType.Struct || this.ClassType == ClassType.Enum); foreach (EventInfo eventInfo in type.GetEvents(flags)) { Events.Add(new ReflectionEvent(eventInfo, this)); } }
public ColladaBoolArray() : base(Enums.ColladaElementType.Core_BoolArray) { Fields.Add(_id = new ColladaObjectAttribute <string>("")); Fields.Add(_name = new ColladaObjectAttribute <string>("")); }
/// <summary> /// Execute a command to insert or update data from source to destination table /// </summary> /// <param name="FromTable">Source table</param> /// <param name="ToTable">Destination table</param> private void ExecuteInserts(Table FromTable, Table ToTable) { Fields colFields = default(Fields); //Field fld = default(Field); Field fldLookup = null; Field fldCommon = null; string InsertSqlStub = null; StringBuilder InsertSql = null; string UpdateSqlStub = null; StringBuilder UpdateSql = null; string CountSqlStub = null; StringBuilder CountSql = null; StringBuilder WhereSql = null; string strValue = null; bool AddedFirstInsert = false; bool AddedFirstUpdate = false; bool IsPrimary = false; //Dim flgRecordExists As Boolean int ProgressIndex = 0; int Total = 0; Table tblSource = (flgUseFromSchemaRI ? FromTable : ToTable); Field fldAutoInc = null; bool UseBulkInsert = false; StringBuilder BulkInsertRow = null; string BulkInsertFile = ""; string FieldTerminator = ""; string RowTerminator = ""; FileStream fsBulkInsert = null; byte[] bytDataRow = null; // Create a field list of all of the common fields in both tables colFields = new Fields(ToTable); foreach (Field fld in FromTable.Fields) { // Lookup field name in destination table fldLookup = ToTable.Fields[fld.Name]; if (fldLookup != null) { //var _with1 = fldLookup; // We currently don't handle binary fields... if (!(fld.Type == OleDbType.Binary | fld.Type == OleDbType.LongVarBinary | fld.Type == OleDbType.VarBinary) & !(fldLookup.Type == OleDbType.Binary | fldLookup.Type == OleDbType.LongVarBinary | fldLookup.Type == OleDbType.VarBinary)) { // Copy field information from destination field if (flgUseFromSchemaRI) { fldCommon = new Field(colFields, fld.Name, fld.Type); fldCommon.AutoIncrement = fld.AutoIncrement; } else { fldCommon = new Field(colFields, fldLookup.Name, fldLookup.Type); fldCommon.AutoIncrement = fldLookup.AutoIncrement; } colFields.Add(fldCommon); } } } // Exit if no common field names were found if (colFields.Count == 0) { intOverallProgress += FromTable.RowCount; return; } Total = FromTable.RowCount; RaiseEvent_RowProgress(FromTable.Name, 0, Total); RaiseEvent_OverallProgress((int)intOverallProgress, (int)intOverallTotal); // Setup to track to and from autoinc values if table has an identity field if (tblSource.HasAutoIncField) { foreach (Field fld in colFields) { fldLookup = tblSource.Fields[fld.Name]; if ((fldLookup != null)) { //var _with2 = fldLookup; // We need only track autoinc translations when field is referenced by foreign keys if (fldLookup.AutoIncrement & fldLookup.ForeignKeys.Count > 0) { // Create a new hashtable to hold autoinc translations fldLookup.AutoIncrementTranslations = new Hashtable(); // Create a new autoinc field to hold source value fldAutoInc = new Field(tblSource.Fields, fld.Name, fldLookup.Type); fldAutoInc.AutoIncrementTranslations = fldLookup.AutoIncrementTranslations; break; } } } } // See if this table is a candidate for bulk inserts if (m_attemptBulkInsert | m_forceBulkInsert) { //var _with3 = ToTable.Parent.Parent; Schema parentSchema = ToTable.Parent.Parent; // We only attempt a bulk insert if the destination data source type is Sql Server and we are inserting // fields into a table that has no auto-incs with foreign key dependencies (or user forces procedure) UseBulkInsert = m_forceBulkInsert | (parentSchema.DataSourceType == DatabaseType.SqlServer & (fldAutoInc == null | colTables.Count == 1)); if (UseBulkInsert) { ParseBulkInsertSettings(ref FieldTerminator, ref RowTerminator); if (m_bulkInsertFilePath.Substring(m_bulkInsertFilePath.Length - 1) != "\\") m_bulkInsertFilePath += "\\"; BulkInsertFile = m_bulkInsertFilePath + (new Guid()).ToString() + ".tmp"; fsBulkInsert = File.Create(BulkInsertFile); } } string selectString = "SELECT " + colFields.GetList() + " FROM " + FromTable.FullName; bool skipKeyValuePreservation = false; // Handle special case of self-referencing table if (tblSource.IsReferencedBy(tblSource)) { // We need a special order-by for this scenario to make sure referenced rows are inserted before other rows - this also // means no auto-inc preservation is possible on this table skipKeyValuePreservation = true; selectString += " ORDER BY "; int index = 0; foreach (Field field in tblSource.Fields) { foreach (ForeignKeyField foreignKey in field.ForeignKeys) { if (string.Compare(tblSource.Name, foreignKey.ForeignKey.Table.Name, true) == 0) { selectString += (index > 0 ? ", " : "") + foreignKey.ForeignKey.Name; index++; } } } } else { // Order by auto increment field to help preserve the original value while transfering data to destination table if (fldAutoInc != null) selectString += " ORDER BY " + fldAutoInc.Name; } // Execute source query using (OleDbDataReader fromReader = FromTable.Connection.ExecuteReader(selectString, CommandBehavior.SequentialAccess, Timeout)) { InsertSqlStub = "INSERT INTO " + ToTable.FullName + " (" + colFields.GetList(false) + ") VALUES ("; UpdateSqlStub = "UPDATE " + ToTable.FullName + " SET "; CountSqlStub = "SELECT COUNT(*) AS Total FROM " + ToTable.FullName; while (fromReader.Read()) { if (UseBulkInsert) { // Handle creating bulk insert file data for each row... BulkInsertRow = new StringBuilder(); AddedFirstInsert = false; // Get all field data to create row for bulk insert foreach (Field fld in ToTable.Fields) { try { // Lookup field in common field list fldCommon = colFields[fld.Name]; if ((fldCommon != null)) { // Found it, so use it... fldCommon.Value = fromReader[fld.Name]; } else { // Otherwise just use existing destination field fldCommon = fld; fldCommon.Value = ""; } } catch (Exception ex) { fldCommon.Value = ""; RaiseEvent_SqlFailure("Failed to get field value for [" + tblSource.Name + "." + fldCommon.Name + "]", ex); } // Get translated auto-inc value for field if possible... fldCommon.Value = DereferenceValue(tblSource, fldCommon.Name, fldCommon.Value); // Get field value strValue = Convert.ToString(Common.NotNull(fldCommon.Value)).Trim(); // We manually parse data type here instead of using SqlEncodedValue because data inserted // into bulk insert file doesn't need Sql encoding... switch (fldCommon.Type) { case OleDbType.Boolean: if (strValue.Length > 0) { int tempValue; if (int.TryParse(strValue, out tempValue)) //if (Information.IsNumeric(strValue)) { if (Convert.ToInt32(tempValue) == 0) { strValue = "0"; } else { strValue = "1"; } } else if (Convert.ToBoolean(strValue)) { strValue = "1"; } else { switch (strValue.Substring(0, 1).ToUpper()) { case "Y": case "T": strValue = "1"; break; case "N": case "F": strValue = "0"; break; default: strValue = "0"; break; } } } break; case OleDbType.DBTimeStamp: case OleDbType.DBDate: case OleDbType.Date: if (strValue.Length > 0) { DateTime tempValue; if (DateTime.TryParse(strValue, out tempValue)) //if (Information.IsDate(strValue)) { strValue = tempValue.ToString("MM/dd/yyyy HH:mm:ss"); //strValue = Strings.Format((DateTime)strValue, "MM/dd/yyyy HH:mm:ss"); } } break; case OleDbType.DBTime: if (strValue.Length > 0) { DateTime tempValue; if (DateTime.TryParse(strValue, out tempValue)) //if (Information.IsDate(strValue)) { strValue = tempValue.ToString("HH:mm:ss"); //Strings.Format((DateTime)strValue, "HH:mm:ss"); } } break; } // Make sure field value does not contain field terminator or row terminator strValue = strValue.Replace(FieldTerminator, m_delimeterReplacement); strValue = strValue.Replace(RowTerminator, m_delimeterReplacement); // Construct bulk insert row if (AddedFirstInsert) { BulkInsertRow.Append(FieldTerminator); } else { AddedFirstInsert = true; } BulkInsertRow.Append(strValue); } BulkInsertRow.Append(RowTerminator); // Add new row to temporary bulk insert file bytDataRow = m_bulkInsertEncoding.GetBytes(BulkInsertRow.ToString()); fsBulkInsert.Write(bytDataRow, 0, bytDataRow.Length); } else { // Handle creating Sql for inserts or updates for each row... InsertSql = new StringBuilder(InsertSqlStub); UpdateSql = new StringBuilder(UpdateSqlStub); CountSql = new StringBuilder(CountSqlStub); WhereSql = new StringBuilder(); AddedFirstInsert = false; AddedFirstUpdate = false; // Coerce all field data into proper Sql formats foreach (Field fld in colFields) { try { fld.Value = fromReader[fld.Name]; } catch (Exception ex) { fld.Value = ""; RaiseEvent_SqlFailure("Failed to get field value for [" + tblSource.Name + "." + fld.Name + "]", ex); } // Get translated auto-inc value for field if necessary... fld.Value = DereferenceValue(tblSource, fld.Name, fld.Value); // We don't attempt to insert values into auto-inc fields if (fld.AutoIncrement) { if ((fldAutoInc != null)) { // Even if database supports multiple autoinc fields, we can only support automatic // ID translation for one because the identity Sql can only return one value... if (String.Compare(fld.Name, fldAutoInc.Name) == 0) //, CompareMethod.Text) == 0) { // Track original autoinc value fldAutoInc.Value = fld.Value; } } } else { // Get Sql encoded field value strValue = fld.SqlEncodedValue; // Construct Sql statements if (AddedFirstInsert) { InsertSql.Append(", "); } else { AddedFirstInsert = true; } InsertSql.Append(strValue); // Check to see if this is a key field fldLookup = tblSource.Fields[fld.Name]; if ((fldLookup != null)) { IsPrimary = fldLookup.IsPrimaryKey; } else { IsPrimary = false; } if (String.Compare(strValue, "NULL") != 0)//(Strings.StrComp(strValue, "NULL", CompareMethod.Text) != 0) { if (IsPrimary) { if (WhereSql.Length == 0) { WhereSql.Append(" WHERE "); } else { WhereSql.Append(" AND "); } WhereSql.Append("["); WhereSql.Append(fld.Name); WhereSql.Append("] = "); WhereSql.Append(strValue); } else { if (AddedFirstUpdate) { UpdateSql.Append(", "); } else { AddedFirstUpdate = true; } UpdateSql.Append("["); UpdateSql.Append(fld.Name); UpdateSql.Append("] = "); UpdateSql.Append(strValue); } } } } InsertSql.Append(")"); if ((fldAutoInc != null) | WhereSql.Length == 0) { // For tables with autoinc fields that are referenced by foreign keys or // tables that have no primary key fields defined, we can only do inserts... try { // Insert record into destination table if (AddedFirstInsert | (fldAutoInc != null)) { // Added check to preserve ID number for auto-inc fields if (!skipKeyValuePreservation && m_preservePrimaryKeyValue && fldAutoInc != null) { //Commented Auto increment field for Primary key because if field is auto increment but not primary key then still need to preserve value before it insert to table //if (ToTable.Fields[fldAutoInc.Name].IsPrimaryKey) //{ //if (ToTable.Name.ToString().ToUpper().Trim() == "Device".ToUpper()) //{ //Check Record Count for destination table before insert and auto increment field value OleDbCommand oCMD = ToTable.Connection.CreateCommand(); oCMD.CommandText = "SELECT MAX(" + fldAutoInc.Name + ") from " + ToTable.Name; oCMD.CommandTimeout = Timeout; oCMD.CommandType = CommandType.Text; int ToTableRowCount = int.Parse(Common.NotNull(oCMD.ExecuteScalar(), "0")) + 1; int SourceTablePrimaryFldValue = int.Parse(Common.NotNull(fldAutoInc.Value, "0")); for (int i = ToTableRowCount; i < SourceTablePrimaryFldValue; i++) { // Insert record into destination table upto Identity Field Value ToTable.Connection.ExecuteNonQuery(InsertSql.ToString(), Timeout); int currentIdentityValue = int.Parse(Common.NotNull(ToTable.Connection.ExecuteScalar(ToTable.IdentitySql, Timeout), "0")); // Delete record which was just inserted ToTable.Connection.ExecuteNonQuery("DELETE FROM " + ToTable.Name + " WHERE " + fldAutoInc.Name + "=" + currentIdentityValue, Timeout); } //} //} //else //{ // //Just reset my auto increment number for Measuremnt Table Point ID currently because it is very importent field in system to keep value // OleDbCommand oCMD = ToTable.Connection.CreateCommand(); // oCMD.CommandText = "SELECT MAX(" + fldAutoInc.Name + ") from " + ToTable.Name; // oCMD.CommandTimeout = Timeout; // oCMD.CommandType = CommandType.Text; // int ToTableRowCount = int.Parse(Common.NotNull(oCMD.ExecuteScalar(), "0")) + 1; // int SourceTablePrimaryFldValue = int.Parse(Common.NotNull(fldAutoInc.Value, "0")); // for (int i = ToTableRowCount; i < SourceTablePrimaryFldValue; i++) // { // // Insert record into destination table upto Identity Field Value // ToTable.Connection.ExecuteNonQuery(InsertSql.ToString(), Timeout); // int currentIdentityValue = int.Parse(Common.NotNull(ToTable.Connection.ExecuteScalar(ToTable.IdentitySql, Timeout), "0")); // //Delete record which is just inserted // ToTable.Connection.ExecuteNonQuery("DELETE FROM " + ToTable.Name + " WHERE " + fldAutoInc.Name + "=" + currentIdentityValue, Timeout); // //RaiseEvent_SqlFailure(ToTable.Name, new Exception("Data value set to table " + ToTable.Name + " for field " + fldAutoInc.Name)); // } //} } // Insert record into destination table ToTable.Connection.ExecuteNonQuery(InsertSql.ToString(), Timeout); } // Save new destination autoinc value if ((fldAutoInc != null)) { try { fldAutoInc.AutoIncrementTranslations.Add(Convert.ToString(fldAutoInc.Value), ToTable.Connection.ExecuteScalar(ToTable.IdentitySql, Timeout)); } catch (Exception ex) { RaiseEvent_SqlFailure(tblSource.IdentitySql, ex); } } } catch (Exception ex) { RaiseEvent_SqlFailure(InsertSql.ToString(), ex); } } else { // Add where criteria to Sql count statement CountSql.Append(WhereSql.ToString()); // Make sure record doesn't already exist try { // If record already exists due to triggers or other means we must update it instead of inserting it OleDbCommand oCMD = ToTable.Connection.CreateCommand(); oCMD.CommandText = CountSql.ToString(); oCMD.CommandTimeout = Timeout; oCMD.CommandType = CommandType.Text; //if (Common.NotNull(ToTable.Connection.ExecuteScalar(CountSql.ToString(), Timeout), "0") > 0) { if (int.Parse(Common.NotNull(oCMD.ExecuteScalar(), "0")) > 0) { // Add where criteria to Sql update statement UpdateSql.Append(WhereSql.ToString()); try { // Update record in destination table if (AddedFirstUpdate) ToTable.Connection.ExecuteNonQuery(UpdateSql.ToString(), Timeout); } catch (Exception ex) { RaiseEvent_SqlFailure(UpdateSql.ToString(), ex); } } else { try { // Insert record into destination table if (AddedFirstInsert) ToTable.Connection.ExecuteNonQuery(InsertSql.ToString(), Timeout); } catch (Exception ex) { RaiseEvent_SqlFailure(InsertSql.ToString(), ex); } } } catch (Exception ex) { RaiseEvent_SqlFailure(CountSql.ToString(), ex); } } } ProgressIndex += 1; intOverallProgress += 1; //Raise event to check status of each row RaiseEvent_RowProgress(FromTable.Name, ProgressIndex, Total); if (ProgressIndex % RowReportInterval == 0) { RaiseEvent_RowProgress(FromTable.Name, ProgressIndex, Total); RaiseEvent_OverallProgress((int)intOverallProgress, (int)intOverallTotal); } } fromReader.Close(); } if (UseBulkInsert & (fsBulkInsert != null)) { string BulkInsertSql = "BULK INSERT " + ToTable.FullName + " FROM '" + BulkInsertFile + "'" + (m_bulkInsertSettings.Length > 0 ? " WITH (" + m_bulkInsertSettings + ")" : ""); double dblStartTime = 0; double dblStopTime = 0; DateTime dtTodayMidNight = new System.DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0); //DateTime dtYestMidnight = new System.DateTime(2006, 9, 12, 0, 0, 0); // Close bulk insert file stream fsBulkInsert.Close(); fsBulkInsert = null; if (BulkInsertExecuting != null) { BulkInsertExecuting(ToTable.Name); } try { // Give system a few seconds to close bulk insert file (might have been real big) TVA.IO.FilePath.WaitForReadLock(BulkInsertFile, 15); TimeSpan diffResult = DateTime.Now - dtTodayMidNight; dblStartTime = diffResult.TotalSeconds; //VB.DateAndTime.Timer; ToTable.Connection.ExecuteNonQuery(BulkInsertSql, Timeout); } catch (Exception ex) { if (BulkInsertException != null) { BulkInsertException(ToTable.Name, BulkInsertSql, ex); } } finally { TimeSpan diffResult = DateTime.Now - dtTodayMidNight; dblStopTime = diffResult.TotalSeconds; // VB.DateAndTime.Timer; if (Convert.ToInt32(dblStartTime) == 0) dblStartTime = dblStopTime; } try { TVA.IO.FilePath.WaitForWriteLock(BulkInsertFile, 15); File.Delete(BulkInsertFile); } catch (Exception ex) { if (BulkInsertException != null) { BulkInsertException(ToTable.Name, BulkInsertSql, new InvalidOperationException("Failed to delete temporary bulk insert file \"" + BulkInsertFile + "\" due to exception [" + ex.Message + "], file will need to be manually deleted.", ex)); } } if (BulkInsertCompleted != null) { BulkInsertCompleted(ToTable.Name, ProgressIndex, Convert.ToInt32(dblStopTime - dblStartTime)); } } RaiseEvent_RowProgress(FromTable.Name, Total, Total); RaiseEvent_OverallProgress((int)intOverallProgress, (int)intOverallTotal); }
public static Dictionary <TKeyType, T> Load <TKeyType, T>(string csvName, string key, Func <T, string, CsvReader, string, bool> onParseEx = null) where T : new() { Dictionary <TKeyType, T> l = new Dictionary <TKeyType, T>();//用反射设置每个字段 Type type = typeof(T); //string csvName = type.Name + "Config"; CsvReader r = LoadReader(csvName); if (r == null) { return(l); } Fields.Clear(); FieldInfos.Clear(); bool endOfRow = true; //第一行为描述,不解析 while (r.Read() && !r.IsEndOfRow) { } //第二行为字段名 while (r.Read()) { Fields.Add(r.Value); if (r.IsEndOfRow) { break; } } if (Fields.Count == 0) { Debuger.LogError(string.Format("{0}.csv解析不到列名", csvName)); return(l); } //找到csv字段对应的类的字段 FieldInfo keyField = null; foreach (FieldInfo info in type.GetFields()) { FieldInfos[info.Name] = info; if (key == info.Name) { keyField = info; } } if (keyField == null) { Debuger.LogError(string.Format("{0}.csv 类找不到对应的键值字段:{1}", csvName, key)); return(l); } if (!keyField.FieldType.Equals(typeof(TKeyType))) { Debuger.LogError(string.Format("{0}.csv 键值字段的类型和Dictionary不一致:{1}", csvName, key)); return(l); } if (!Fields.Contains(key)) { Debuger.LogError(string.Format("{0}.csv 不包含键值列:{1} 是否被删除?", csvName, key)); return(l); } T row = default(T); FieldInfo fieldInfo; string val; object outVal; TKeyType k = default(TKeyType); //剩下的行数据 while (r.Read()) { if (endOfRow) { if (row != null) { if (l.ContainsKey(k)) { Debuger.LogError(string.Format("{0}.csv 行:{1} 键值({2})重复 是不是没有填 ", csvName, r.Row, key)); } l[k] = row; } row = new T(); } endOfRow = r.IsEndOfRow; val = r.Value; if (r.Col >= Fields.Count) { continue; } fieldInfo = FieldInfos.Get(Fields[r.Col]); if (onParseEx != null) { if (!onParseEx(row, Fields[r.Col], r, val))//如果扩展解析出错了,那么这一行不算 { continue; } } if (fieldInfo == null || string.IsNullOrEmpty(val))//空字符的话算默认值 { continue; } if (StringUtil.TryParse(val, fieldInfo.FieldType, out outVal)) { fieldInfo.SetValue(row, outVal); if (fieldInfo.Name == key) { k = (TKeyType)outVal; } } else { Debuger.LogError(string.Format("{0}.csv解析出错 行:{1} 列:{2} 列名:{3} ", csvName, r.Row, r.Col, Fields[r.Col])); } } if (row != null && !l.ContainsKey(k))//最后一行补上 { l[k] = row; } return(l); }
public void AddField([NotNull] string name, SqliteDataType datatype) { Fields.Add(new FieldDefinition(name, datatype)); }
//注意fields是共用的,要确保在下次load之后不使用 public static bool Load(string path, out List <Dictionary <string, string> > l, out List <string> fields, out List <string> descs) { l = new List <Dictionary <string, string> >();//用反射设置每个字段 Fields.Clear(); Descs.Clear(); fields = Fields; descs = Descs; CsvReader r = LoadReader(path); if (r == null) { return(false); } Dictionary <string, string> d = null; bool endOfRow = true; //第一行为描述,不解析 while (r.Read()) { Descs.Add(r.Value); if (r.IsEndOfRow) { break; } } //第二行为字段名 while (r.Read()) { Fields.Add(r.Value); if (r.IsEndOfRow) { break; } } if (Fields.Count == 0) { Debuger.LogError(string.Format("{0}.csv解析不到列名", path)); return(false); } //剩下的行数据 while (r.Read()) { if (endOfRow) { d = new Dictionary <string, string>(); l.Add(d); } endOfRow = r.IsEndOfRow; if (r.Col >= Fields.Count || string.IsNullOrEmpty(Fields[r.Col])) { continue; } if (d.ContainsKey(Fields[r.Col])) { Debuger.LogError(string.Format("{0}.csv解析出错 字段名重复", path, Fields[r.Col])); continue; } d[Fields[r.Col]] = r.Value; } if (r.IsError) { Debuger.LogError(string.Format("{0}.csv解析出错 行:{1} 列:{2}", path, r.Row, r.Col)); } return(!r.IsError); }
private void rptInvoice_DataInitialize(object sender, System.EventArgs eArgs) { #region TARAKESHWAR DATE 31-JAN-2006 RecordSet rsSupplier = Company.GetCompanyData(System.Convert.ToInt32(rsInvoiceHeader["SupplierCompanyID"])); RecordSet rsBuyer = Company.GetCompanyData(System.Convert.ToInt32(rsInvoiceHeader["BuyerCompanyID"])); Fields.Add("SupplierComapany"); Fields.Add("BuyerComapany"); #endregion Fields.Add("New_InvoiceName"); Fields.Add("InvoiceID"); Fields.Add("InvoiceNo"); Fields.Add("PaymentDueDate"); // Fields.Add("New_PaymentDate"); Fields.Add("New_PaymentMethod"); Fields.Add("New_DiscountGiven"); // Fields.Add("DiscountPercent"); Fields.Add("CustomerAccNo"); Fields.Add("InvoiceDate"); Fields.Add("PaymentTerm"); Fields.Add("NetTotal"); Fields.Add("VATAmt"); Fields.Add("TotalAmt"); Fields.Add("InvoiceAddress"); Fields.Add("DeliveryAddress"); Fields.Add("SupplierAddress"); Fields.Add("SellerVATNo"); Fields.Add("TaxPointDate"); Fields.Add("New_InvoiceContact"); Fields.Add("New_OverallDiscountPercent"); Fields.Add("New_SettlementDays1"); Fields.Add("New_SettlementDays2"); Fields.Add("New_SettlementPercent2"); Fields.Add("PurOrderNo"); Fields.Add("PurOrderLineNo"); Fields.Add("PurOrderDate"); Fields.Add("PurInfo"); Fields.Add("Quantity"); Fields.Add("Description"); Fields.Add("New_DiscountPercent2"); Fields.Add("UOM"); Fields.Add("VATRate"); Fields.Add("Discount"); Fields.Add("Rate"); Fields.Add("BuyersProdCode"); Fields.Add("SuppliersProdCode"); Fields.Add("New_DespatchNoteNumber"); Fields.Add("New_DespatchDate"); Fields.Add("New_Type"); Fields.Add("New_Definable1"); Fields.Add("New_NettValue"); Fields.Add("H_VATAmt"); Fields.Add("H_TotalAmt"); Fields["InvoiceID"].Value = rsInvoiceHeader["InvoiceID"]; Fields["InvoiceNo"].Value = rsInvoiceHeader["InvoiceNo"]; Fields["PaymentDueDate"].Value = rsInvoiceHeader["PaymentDueDate"]; Fields["DiscountPercent"].Value = rsInvoiceHeader["DiscountPercent"]; Fields["New_SettlementPercent2"].Value = rsInvoiceHeader["New_SettlementPercent2"]; Fields["CustomerAccNo"].Value = rsInvoiceHeader["CustomerAccNo"]; Fields["New_InvoiceContact"].Value = rsInvoiceHeader["New_InvoiceContact"]; Fields["New_OverallDiscountPercent"].Value = rsInvoiceHeader["New_OverallDiscountPercent"]; Fields["New_SettlementDays1"].Value = rsInvoiceHeader["New_SettlementDays1"]; Fields["New_SettlementDays2"].Value = rsInvoiceHeader["New_SettlementDays2"]; Fields["InvoiceDate"].Value = rsInvoiceHeader["InvoiceDate"]; Fields["PaymentTerm"].Value = rsInvoiceHeader["PaymentTerm"]; Fields["NetTotal"].Value = rsInvoiceHeader["NetTotal"]; Fields["H_VATAmt"].Value = rsInvoiceHeader["VATAmt"]; Fields["H_TotalAmt"].Value = rsInvoiceHeader["TotalAmt"]; Fields["New_DiscountGiven"].Value = rsInvoiceHeader["New_DiscountGiven"]; Fields["New_PaymentMethod"].Value = rsInvoiceHeader["New_PaymentMethod"]; Fields["New_PaymentDate"].Value = rsInvoiceHeader["New_PaymentDate"]; if (rsInvoiceHeader["TaxPointDate"] != DBNull.Value) { Fields["TaxPointDate"].Value = rsInvoiceHeader["TaxPointDate"]; } #region TARAKESHWAR DATE 31-JAN-2006 GET COMPANY NAME Fields["SupplierComapany"].Value = rsSupplier["CompanyName"]; Fields["BuyerComapany"].Value = rsBuyer["CompanyName"]; rsSupplier = null; rsBuyer = null; #endregion Fields["New_InvoiceName"].Value = rsInvoiceHeader["New_InvoiceName"]; Invoice objInvoice = new Invoice(); if (rsInvoiceHeader["CurrencyTypeID"] != DBNull.Value) { TextBox9.Text = objInvoice.GetCurrencyCode(Convert.ToInt32(rsInvoiceHeader["CurrencyTypeID"])); } Double dGBPEquivalentAmount = 0; dGBPEquivalentAmount = objInvoice.GetGBPEquivalentAmount(Convert.ToInt32(rsInvoiceHeader["InvoiceID"])); if (dGBPEquivalentAmount > 0) { lblGBPEquivalentAmount.Visible = true; tblGBPEquivalentAmount.Text = dGBPEquivalentAmount.ToString(); } string s = GetAddressLine(rsInvoiceHeader["DeliveryAddress1"].ToString()); s += GetAddressLine(rsInvoiceHeader["DeliveryAddress2"].ToString()); s += GetAddressLine(rsInvoiceHeader["DeliveryAddress3"].ToString()); s += GetAddressLine(rsInvoiceHeader["DeliveryAddress4"].ToString()); s += GetAddressLine(rsInvoiceHeader["DeliveryAddress5"].ToString()); s += GetAddressLine(rsInvoiceHeader["DeliveryCountry"].ToString()); s += GetAddressLine(rsInvoiceHeader["DeliveryZIP"].ToString()); Fields["DeliveryAddress"].Value = s; s = GetAddressLine(rsInvoiceHeader["InvoiceAddress1"].ToString()); s += GetAddressLine(rsInvoiceHeader["InvoiceAddress2"].ToString()); s += GetAddressLine(rsInvoiceHeader["InvoiceAddress3"].ToString()); s += GetAddressLine(rsInvoiceHeader["InvoiceAddress4"].ToString()); s += GetAddressLine(rsInvoiceHeader["InvoiceAddress5"].ToString()); s += GetAddressLine(rsInvoiceHeader["InvoiceCountry"].ToString()); s += GetAddressLine(rsInvoiceHeader["InvoiceZIP"].ToString()); Fields["InvoiceAddress"].Value = s; s = GetAddressLine(rsInvoiceHeader["SupplierAddress1"].ToString()); s += GetAddressLine(rsInvoiceHeader["SupplierAddress2"].ToString()); s += GetAddressLine(rsInvoiceHeader["SupplierAddress3"].ToString()); s += GetAddressLine(rsInvoiceHeader["SupplierAddress4"].ToString()); s += GetAddressLine(rsInvoiceHeader["SupplierAddress5"].ToString()); s += GetAddressLine(rsInvoiceHeader["SupplierCountry"].ToString()); s += GetAddressLine(rsInvoiceHeader["SupplierZIP"].ToString()); Fields["SupplierAddress"].Value = s; Fields["SellerVATNo"].Value = rsInvoiceHeader["SellerVATNo"]; }
public CustomExposedField Expose(CustomExposedField field) { Fields.Add(field); return(field); }
public void AddField(Field field) { Fields.Add(field); }
public Fields InitialFieldTypes() { var fields = new Fields(); var delimiter = FindDelimiter(); if (_storage.Count == 0) { _logger.EntityWarn(_fileInfo.Name, "No lines in file."); return fields; } var firstLine = _storage[0]; if (delimiter == default(char)) { var field = new Field("string", _request.DefaultLength, FieldType.NonKey, true, string.Empty) { Name = firstLine.Content }; fields.Add(field); return fields; } var names = firstLine.Values[delimiter].Select(n=>n.Trim(firstLine.Quote)).ToArray(); for (var i = 0; i < names.Length; i++) { var name = names[i]; var field = new Field(_request.DefaultType, _request.DefaultLength, FieldType.NonKey, true, string.Empty) { Name = name, QuotedWith = firstLine.Quote }; fields.Add(field); } return fields; }
public Fields Fields() { var fields = new Fields(); foreach (var entity in Entities) { fields.Add(entity.Fields); fields.Add(entity.CalculatedFields); } fields.Add(CalculatedFields); return fields; }
protected override IEnumerator <AsyncStep> GetAsyncSteps() { string address = CbsConstants.CbsAddress; while (this.RemainingTime() > TimeSpan.Zero) { try { AmqpSessionSettings sessionSettings = new AmqpSessionSettings() { Properties = new Fields() }; this.session = new AmqpSession(this.connection, sessionSettings, this); connection.AddSession(session, null); } catch (InvalidOperationException exception) { this.Complete(exception); yield break; } yield return(this.CallAsync( (thisPtr, t, c, s) => thisPtr.session.BeginOpen(t, c, s), (thisPtr, r) => thisPtr.session.EndOpen(r), ExceptionPolicy.Continue)); Exception lastException = this.LastAsyncStepException; if (lastException != null) { AmqpTrace.Provider.AmqpOpenEntityFailed(this.connection, this.session, string.Empty, address, lastException.Message); this.session.Abort(); this.Complete(lastException); yield break; } Fields properties = new Fields(); properties.Add(CbsConstants.TimeoutName, (uint)this.RemainingTime().TotalMilliseconds); this.Link = new RequestResponseAmqpLink("cbs", this.session, address, properties); yield return(this.CallAsync( (thisPtr, t, c, s) => thisPtr.Link.BeginOpen(t, c, s), (thisPtr, r) => thisPtr.Link.EndOpen(r), ExceptionPolicy.Continue)); lastException = this.LastAsyncStepException; if (lastException != null) { AmqpTrace.Provider.AmqpOpenEntityFailed(this.connection, this.Link, this.Link.Name, address, lastException.Message); this.session.SafeClose(); this.Link = null; this.Complete(lastException); yield break; } AmqpTrace.Provider.AmqpOpenEntitySucceeded(this.connection, this.Link, this.Link.Name, address); yield break; } if (this.session != null) { this.session.SafeClose(); } this.Complete(new TimeoutException(AmqpResources.GetString(AmqpResources.AmqpTimeout, this.OriginalTimeout, address))); }
public static List <T> Load <T>(string csvName) where T : new() { List <T> l = new List <T>();//用反射设置每个字段 Type type = typeof(T); //string csvName = type.Name+"Config"; CsvReader r = LoadReader(csvName); if (r == null) { return(l); } Fields.Clear(); FieldInfos.Clear(); bool endOfRow = true; //第一行为描述,不解析 while (r.Read() && !r.IsEndOfRow) { } //第二行为字段名 while (r.Read()) { if (!string.IsNullOrEmpty(r.Value)) { Fields.Add(r.Value); } if (r.IsEndOfRow) { break; } } if (Fields.Count == 0) { Debuger.LogError(string.Format("{0}.csv解析不到列名", csvName)); return(l); } //找到csv字段对应的类的字段 foreach (FieldInfo info in type.GetFields()) { FieldInfos[info.Name] = info; } foreach (string f in Fields) { if (!FieldInfos.ContainsKey(f)) { Debuger.LogError(string.Format("{0}.csv 不包含列名:{1}", csvName, f)); } } T row = default(T); FieldInfo fieldInfo; string val; object outVal; //剩下的行数据 while (r.Read()) { if (endOfRow) { row = new T(); l.Add(row); } endOfRow = r.IsEndOfRow; if (r.Col >= Fields.Count) { continue; } val = r.Value; fieldInfo = FieldInfos.Get(Fields[r.Col]); if (fieldInfo == null || string.IsNullOrEmpty(val))//空字符的话算默认值 { continue; } if (StringUtil.TryParse(val, fieldInfo.FieldType, out outVal)) { fieldInfo.SetValue(row, outVal); } else { Debuger.LogError(string.Format("{0}.csv解析出错 行:{1} 列:{2} 列名:{3} ", csvName, r.Row, r.Col, Fields[r.Col])); } } return(l); }
/// <summary> /// Adds the specified field. /// </summary> /// <param name="field">The field to consider.</param> /// <returns>Returns this instance.</returns> public IDbSingleQuery AddField(DbField field) { Fields?.Add(field); return(this); }
protected override void RefreshFields() { Type type = typeof(Camera); Fields.Add(new InspectorField(type, Instances, type.GetProperty("clearFlags"), new DescriptorAttribute("Clear Flag", "How the camera clears the background.", "http://docs.unity3d.com/ScriptReference/Camera-clearFlags.html"))); Fields.Add(new InspectorField(type, Instances, type.GetProperty("backgroundColor"), new InspectAttribute(new InspectAttribute.InspectDelegate(ShowBackground)), new DescriptorAttribute("Background Color", "The color with which the screen will be cleared.", "http://docs.unity3d.com/ScriptReference/Camera-backgroundColor.html"))); Fields.Add(new InspectorField(type, Instances, type.GetProperty("cullingMask"), new FieldEditorAttribute("LayerMaskEditor"), new DescriptorAttribute("Culling Mask", "This is used to render parts of the scene selectively.", "http://docs.unity3d.com/ScriptReference/Camera-cullingMask.html"))); Fields.Add(new InspectorField(type, Instances, type.GetProperty("orthographic"), new RestrictAttribute(new RestrictAttribute.RestrictDelegate(Projection)), new DescriptorAttribute("Orthographic", "Is the camera orthographic (true) or perspective (false)?", "http://docs.unity3d.com/ScriptReference/Camera-orthographic.html"))); Fields.Add(new InspectorField(type, Instances, type.GetProperty("orthographicSize"), new InspectAttribute(new InspectAttribute.InspectDelegate(IsOrthographic)), new DescriptorAttribute("Size", "Camera's half-size when in orthographic mode.", "http://docs.unity3d.com/ScriptReference/Camera-orthographicSize.html"))); Fields.Add(new InspectorField(type, Instances, type.GetProperty("fieldOfView"), new InspectAttribute(new InspectAttribute.InspectDelegate(IsFieldOfView)), new RangeValueAttribute(1, 179), new DescriptorAttribute("Field Of View", "The field of view of the camera in degrees.", "http://docs.unity3d.com/ScriptReference/Camera-fieldOfView.html"))); Fields.Add(new InspectorField(type, Instances, type.GetProperty("nearClipPlane"), new DescriptorAttribute("Near Clip", "The near clipping plane distance.", "http://docs.unity3d.com/ScriptReference/Camera-nearClipPlane.html"))); Fields.Add(new InspectorField(type, Instances, type.GetProperty("farClipPlane"), new DescriptorAttribute("Far Clip", "The far clipping plane distance.", "http://docs.unity3d.com/ScriptReference/Camera-farClipPlane.html"))); Fields.Add(new InspectorField(type, Instances, type.GetProperty("rect"), new DescriptorAttribute("Viewport Rect", "Where on the screen is the camera rendered in normalized coordinates.", "http://docs.unity3d.com/ScriptReference/Camera-rect.html"))); Fields.Add(new InspectorField(type, Instances, type.GetProperty("depth"), new DescriptorAttribute("Depth", "Camera's depth in the camera rendering order.", "http://docs.unity3d.com/ScriptReference/Camera-depth.html"))); Fields.Add(new InspectorField(type, Instances, type.GetProperty("renderingPath"), new HelpAttribute(new HelpAttribute.HelpDelegate(RenderingHelp)), new DescriptorAttribute("Rendering Path", "Rendering path.", "http://docs.unity3d.com/ScriptReference/Camera-renderingPath.html"))); Fields.Add(new InspectorField(type, Instances, type.GetProperty("targetTexture"), new DescriptorAttribute("Render Texture", "Destination render texture (Unity Pro only).", "http://docs.unity3d.com/ScriptReference/Camera-targetTexture.html"))); Fields.Add(new InspectorField(type, Instances, type.GetProperty("useOcclusionCulling"), new DescriptorAttribute("Occlusion Culling", "Whether or not the Camera will use occlusion culling during rendering.", "http://docs.unity3d.com/ScriptReference/Camera-useOcclusionCulling.html"))); #if UNITY_5_6 || UNITY_2017 Fields.Add(new InspectorField(type, Instances, type.GetProperty("allowHDR"), new DescriptorAttribute("HDR", "High dynamic range rendering.", "http://docs.unity3d.com/ScriptReference/Camera-hdr.html"))); #else Fields.Add(new InspectorField(type, Instances, type.GetProperty("hdr"), new DescriptorAttribute("HDR", "High dynamic range rendering.", "http://docs.unity3d.com/ScriptReference/Camera-hdr.html"))); #endif Fields.Add(new InspectorField(null, new UnityEngine.Object[] { this }, new object[] { this }, this.GetType().GetMethod("TakeScreenshot"), new Attribute[] { new InspectAttribute(InspectorLevel.Advanced) })); Fields.Add(new InspectorField(null, new UnityEngine.Object[] { this }, new object[] { this }, null, this.GetType().GetField("screenshotResolution"), false, new Attribute[] { new InspectAttribute(InspectorLevel.Advanced) })); // Debug InspectorField debug = new InspectorField("Debug"); Fields.Add(debug); debug.Fields.Add(new InspectorField(type, Instances, type.GetProperty("aspect"), new InspectAttribute(InspectorLevel.Debug), new ReadOnlyAttribute(), new DescriptorAttribute("Aspect Ratio", "The aspect ratio (width divided by height).", "http://docs.unity3d.com/ScriptReference/Camera-aspect.html"))); debug.Fields.Add(new InspectorField(type, Instances, type.GetProperty("clearStencilAfterLightingPass"), new InspectAttribute(InspectorLevel.Debug), new DescriptorAttribute("Clear Stencil After Lighting", "Clear Stencil After Lighting Pass."))); debug.Fields.Add(new InspectorField(type, Instances, type.GetProperty("depthTextureMode"), new InspectAttribute(InspectorLevel.Debug), new DescriptorAttribute("Depth Texture Mode", "How and if camera generates a depth texture.", "http://docs.unity3d.com/ScriptReference/Camera-depthTextureMode.html"))); debug.Fields.Add(new InspectorField(type, Instances, type.GetProperty("eventMask"), new InspectAttribute(InspectorLevel.Debug), new DescriptorAttribute("Event Mask", "Mask to select which layers can trigger events on the camera.", "http://docs.unity3d.com/ScriptReference/Camera-eventMask.html"))); debug.Fields.Add(new InspectorField(type, Instances, type.GetProperty("layerCullDistances"), new InspectAttribute(InspectorLevel.Debug), new CollectionAttribute(0), new DescriptorAttribute("Layer Cull Distances", "Per-layer culling distances.", "http://docs.unity3d.com/ScriptReference/Camera-layerCullDistances.html"))); debug.Fields.Add(new InspectorField(type, Instances, type.GetProperty("layerCullSpherical"), new InspectAttribute(InspectorLevel.Debug), new DescriptorAttribute("Layer Cull Spherical", "How to perform per-layer culling for a Camera.", "http://docs.unity3d.com/ScriptReference/Camera-layerCullSpherical.html"))); debug.Fields.Add(new InspectorField(type, Instances, type.GetProperty("pixelRect"), new InspectAttribute(InspectorLevel.Debug), new DescriptorAttribute("Pixel Rect", "Where on the screen is the camera rendered in pixel coordinates.", "http://docs.unity3d.com/ScriptReference/Camera-pixelRect.html"))); debug.Fields.Add(new InspectorField(type, Instances, type.GetProperty("transparencySortMode"), new InspectAttribute(InspectorLevel.Debug), new DescriptorAttribute("Transparency Sort Mode", "Transparent object sorting mode.", "http://docs.unity3d.com/ScriptReference/Camera-transparencySortMode.html"))); if (camera == null) { camera = EditorUtility.CreateGameObjectWithHideFlags("Preview Camera", HideFlags.HideAndDontSave, new Type[] { typeof(Camera) }).GetComponent <Camera>(); camera.enabled = false; } rects = new Rect[Instances.Length]; for (int i = 0; i < Instances.Length; i++) { rects[i] = new Rect(25, 25, 0, 0); } }
public Field(Fields fields, String sequence) { this.sequence = sequence; fields.Add(this); }
public void addField(DetectionField f) { Fields.Add(f); }
/// <summary> /// Execute a command to update data from source to destination table /// </summary> /// <param name="fromTable">Source table</param> /// <param name="toTable">Destination table</param> private void ExecuteUpdates(Table fromTable, Table toTable) { Table sourceTable = m_useFromSchemaRI ? fromTable : toTable; Field lookupField; Field commonField; // Progress process variables int progress = 0; int totalProgress; // Bulk update variables string updateSQLStub; StringBuilder updateSQL; StringBuilder whereSQL; string value; bool isPrimary; bool addedFirstUpdate; // Create a field list of all of the common fields in both tables // Use toTable as the parent to retrieve the appropriate SQLEncodedValues Fields fieldsCollection = new Fields(toTable); foreach (Field fld in fromTable.Fields) { // Lookup field name in destination table lookupField = toTable.Fields[fld.Name]; if ((object)lookupField != null) { // We currently don't handle binary fields... if (!(fld.Type == OleDbType.Binary || fld.Type == OleDbType.LongVarBinary || fld.Type == OleDbType.VarBinary) && !(lookupField.Type == OleDbType.Binary || lookupField.Type == OleDbType.LongVarBinary || lookupField.Type == OleDbType.VarBinary)) { // Copy field information from destination field if (m_useFromSchemaRI) { commonField = new Field(fld.Name, fld.Type); commonField.AutoIncrement = fld.AutoIncrement; } else { commonField = new Field(lookupField.Name, lookupField.Type); commonField.AutoIncrement = lookupField.AutoIncrement; } fieldsCollection.Add(commonField); } } } // Exit if no common field names were found if (fieldsCollection.Count == 0) { m_overallProgress += fromTable.RowCount; return; } totalProgress = fromTable.RowCount; OnRowProgress(fromTable.Name, 0, totalProgress); OnOverallProgress((int)m_overallProgress, (int)m_overallTotal); // Execute source query using (IDataReader fromReader = fromTable.Connection.ExecuteReader("SELECT " + fieldsCollection.GetList(sqlEscapeFunction: fromTable.Parent.Parent.SQLEscapeName) + " FROM " + fromTable.SQLEscapedName, CommandBehavior.SequentialAccess, Timeout)) { // Create Sql update stub updateSQLStub = "UPDATE " + toTable.SQLEscapedName + " SET "; // Insert data for each row... while (fromReader.Read()) { updateSQL = new StringBuilder(updateSQLStub); whereSQL = new StringBuilder(); addedFirstUpdate = false; // Coerce all field data into proper Sql format foreach (Field fld in fieldsCollection) { try { fld.Value = fromReader[fld.Name]; } catch (Exception ex) { fld.Value = ""; OnSQLFailure("Failed to get field value for [" + sourceTable.Name + "." + fld.Name + "]", ex); } // Check to see if this is a key field lookupField = sourceTable.Fields[fld.Name]; if ((object)lookupField != null) { isPrimary = lookupField.IsPrimaryKey; } else { isPrimary = false; } value = fld.SQLEncodedValue; if (!value.Equals("NULL", StringComparison.CurrentCultureIgnoreCase)) { if (isPrimary) { if (whereSQL.Length == 0) { whereSQL.Append(" WHERE "); } else { whereSQL.Append(" AND "); } whereSQL.Append(fld.SQLEscapedName); whereSQL.Append(" = "); whereSQL.Append(value); } else { if (addedFirstUpdate) { updateSQL.Append(", "); } else { addedFirstUpdate = true; } updateSQL.Append(fld.SQLEscapedName); updateSQL.Append(" = "); updateSQL.Append(value); } } } if (whereSQL.Length > 0) { // Add where criteria to Sql update statement updateSQL.Append(whereSQL.ToString()); try { // Update record in destination table if (addedFirstUpdate) { toTable.Connection.ExecuteNonQuery(updateSQL.ToString(), Timeout); } } catch (Exception ex) { OnSQLFailure(updateSQL.ToString(), ex); } } else { OnSQLFailure(updateSQL.ToString(), new DataException("ERROR: No \"WHERE\" criteria was generated for Sql update statement, primary key value missing? Update not performed")); } progress += 1; m_overallProgress += 1; if (progress % RowReportInterval == 0) { OnRowProgress(fromTable.Name, progress, totalProgress); OnOverallProgress((int)m_overallProgress, (int)m_overallTotal); } } fromReader.Close(); } OnRowProgress(fromTable.Name, totalProgress, totalProgress); OnOverallProgress((int)m_overallProgress, (int)m_overallTotal); }
/// <summary> /// Event arguments for CanRead events. /// </summary> /// <param name="ProvisioningClient">XMPP Provisioning Client used.</param> /// <param name="e">Message with request.</param> public CanReadEventArgs(ProvisioningClient ProvisioningClient, MessageEventArgs e) : base(ProvisioningClient, e) { this.provisioningClient = ProvisioningClient; this.fieldTypes = (FieldType)0; foreach (XmlAttribute Attr in e.Content.Attributes) { switch (Attr.LocalName) { case "all": if (CommonTypes.TryParse(Attr.Value, out bool b)) { this.fieldTypes |= FieldType.All; } break; case "m": if (CommonTypes.TryParse(Attr.Value, out b)) { this.fieldTypes |= FieldType.Momentary; } break; case "p": if (CommonTypes.TryParse(Attr.Value, out b)) { this.fieldTypes |= FieldType.Peak; } break; case "s": if (CommonTypes.TryParse(Attr.Value, out b)) { this.fieldTypes |= FieldType.Status; } break; case "c": if (CommonTypes.TryParse(Attr.Value, out b)) { this.fieldTypes |= FieldType.Computed; } break; case "i": if (CommonTypes.TryParse(Attr.Value, out b)) { this.fieldTypes |= FieldType.Identity; } break; case "h": if (CommonTypes.TryParse(Attr.Value, out b)) { this.fieldTypes |= FieldType.Historical; } break; } } List <string> Fields = null; foreach (XmlNode N in e.Content.ChildNodes) { if (N is XmlElement E && E.LocalName == "f") { if (Fields is null) { Fields = new List <string>(); } Fields.Add(XML.Attribute(E, "n")); } } if (Fields != null) { this.fields = Fields.ToArray(); } else { this.fields = null; } }
public Fields SearchFields() { var fields = new Fields(); foreach (var pair in new StarFields(this).TypedFields()) { fields.Add(pair.Value.WithSearchType()); } return fields; }
public void AddField(Field field) { AddToDictionary(field); Fields.Add(field); }