/// <summary> /// Will preform the given query on the and call the CB supplied. The app must call this.CheckCache before it /// usies teh cache to make sure its is up to date. Default behavior is to exception if there are no rows returned. /// Use AllowNoRows property to change that /// </summary> /// <param name="db"></param> /// <param name="query"></param> /// <param name="Expiration">Minues to wait inbetween refreshes value of 0 - cache never expires</param> /// <param name="cb">Delagate to process the Query's result. BE careful in multiclient mode to insure you /// dont mix up data for two different clients in the same cache. This may require your app to rebuild its /// internal data structres it uses for the cache each time the delagte is called.</param> public CachedQuery(TDatabase db, string query, int Expiration, CacheUpdatedDelegate cb) { mCB = cb; mExpire = Expiration; mQuery = query; mDB = db; }
public SMNatives(NativeData nativeData) { Globals = new TGlobals(nativeData); Application = new TApplication(nativeData); Control = new TControl(nativeData); ElWind = new TElWind(nativeData); SMMain = new TSMMain(nativeData); Database = new TDatabase(nativeData); Registry = new TRegistry(Database, nativeData); }
public async Task <int> AddAsync(string accountId, string name, string code, ProviderType provider, string connectionString) { if (await _repository.ExistsCodeAsync(code)) { throw new BusiException("编码已存在"); } var model = new TDatabase { Id = IdentityHelper.Guid32, AccountId = accountId, Name = name, Code = code, Provider = (byte)provider, ConnectionString = connectionString, CreateTime = Clock.Now, Status = (byte)CommonStatus.Normal }; return(await _repository.InsertAsync(model)); }
public TFileSpace(TDatabase db, NativeData nativeData) { InstancePtr = new ObjPtr(db.InstancePtr, nativeData.Pointers[NativePointer.Registry_FileSpaceInstance]); EmptySlotsPtr = new ObjPtr(InstancePtr, nativeData.Pointers[NativePointer.FileSpace_EmptySlotsOffset]); AllocatedSlotsPtr = new ObjPtr(InstancePtr, nativeData.Pointers[NativePointer.FileSpace_AllocatedSlotsOffset]); GetTopSlotCallSig = nativeData.GetMemoryPattern(NativeMethod.FileSpace_GetTopSlot); IsSlotOccupiedCallSig = nativeData.GetMemoryPattern(NativeMethod.FileSpace_IsSlotOccupied); GetTopSlot = new Procedure <Func <IntPtr, bool, int> >( "GetTopSlot", CallingConventions.Register, GetTopSlotCallSig ); IsSlotOccupied = new Procedure <Func <IntPtr, int, bool> >( "IsSlotOccupied", CallingConventions.Register, IsSlotOccupiedCallSig ); }
public TRegistry(TDatabase db, NativeData nativeData) { TextRegistryInstance = new ObjPtr(db.InstancePtr, nativeData.Pointers[NativePointers.Registry_TextRegistryInstance]); ImageRegistryInstance = new ObjPtr(db.InstancePtr, nativeData.Pointers[NativePointers.Registry_ImageRegistryInstance]); SoundRegistryInstance = new ObjPtr(db.InstancePtr, nativeData.Pointers[NativePointers.Registry_SoundRegistryInstance]); VideoRegistryInstance = new ObjPtr(db.InstancePtr, nativeData.Pointers[NativePointers.Registry_VideoRegistryInstance]); BinaryRegistryInstance = new ObjPtr(db.InstancePtr, nativeData.Pointers[NativePointers.Registry_BinaryRegistryInstance]); TemplateRegistryInstance = new ObjPtr(db.InstancePtr, nativeData.Pointers[NativePointers.Registry_TemplateRegistryInstance]); ConceptRegistryInstance = new ObjPtr(db.InstancePtr, nativeData.Pointers[NativePointers.Registry_ConceptRegistryInstance]); AddMemberCallSig = nativeData.GetMemoryPattern(NativeMethod.TRegistry_AddMember); ImportFileCallSig = nativeData.GetMemoryPattern(NativeMethod.TRegistry_ImportFile); AddMember = new Procedure <Func <IntPtr, DelphiUTF16String, int> >( "AddMember", CallingConventions.Register, AddMemberCallSig ); ImportFile = new Procedure <Func <IntPtr, DelphiUTF16String, DelphiUTF16String, int> >( "ImportFile", CallingConventions.Register, ImportFileCallSig ); }
protected GenericTable(TDatabase db) : this("", db) { }
public SqlUtil(TDatabase Database) : this(Database, null) { }
// TODO: MULTI: decision on what db to use can be used here and only here. /// <summary> /// Initializes this object instance by creating an instance of the Internal SqlConnection object. /// </summary> /// <param name="Database" >The Associated Database Name that this Data Service instance will be communicating with</param> /// <value>void</value> private void ConstructMe(TDatabase db, string DBName, string ServerName) { byte minConnect; byte maxConnect; //this call will do lots of cool things, but will give us back the name of the server that the caller needs. //it will also change the DBName if it is mapped to another actual name mDatabaseName = (db == TDatabase.Unknown ? DBName : db.ToString()); mDatabase = db; if (ServerName != null) msDatabaseServer = ServerName; else msDatabaseServer = DBLocator.getDatabaseServer(ref mDatabaseName); DBLocator.getConnectionPoolMinMax(mDatabaseName, out minConnect, out maxConnect); try { msActiveConnectionString = "Application Name=" + this.ApplicationName + ";" + "server=" + msDatabaseServer + ";" + "trusted_Connection=yes;" + "Database=" + mDatabaseName + ";" + "connection reset=false;" + "enlist=true;" + "min pool size=" + minConnect + ";" + "max pool size=" + maxConnect; msActiveConnectionString = FixConnectionString(msActiveConnectionString); moDBConn = new SqlConnection(msActiveConnectionString); } catch (Exception ex) { //Lets Use The MS Application Block here w/a custom publisher that sends out an eMail & Publishes exception data to a structure in the Shared Database. //If Shared DB is not available then publish exception data to the event log. throw new Exception(ex.Message, ex); } }
public AuditLog(long correspondence_id, string datatype, long dataid, string EventDescript, long eid, AuditFields changeList, TDatabase Database) { mDataType = datatype; mCorrespondenceID = correspondence_id; mDataID = dataid; mFieldChanges = changeList; mEventID = eid; mEventDescription = EventDescript; mDatabase = Database; }
public GenericTable(string TableName, TDatabase db, string IdColumn) { ConstructMe(TableName, db, IdColumn, null); }
public static GenericTable GetFromHistoryOrCurrent(string TableName, TDatabase db, long id) { GenericTable gt = new GenericTable(TableName, db); if (gt.ReadRecord(id) > 0) return gt; gt = new GenericTable("History" + TableName, db); if (gt.ReadRecord(id) > 0) return gt; return null; }
public SqlUtil(TDatabase Database, string appName) : this(Database, Database.ToString(), appName) { }
/// <summary> /// Returns a fully qualified path to the specified table. /// </summary> /// <param name="LogicalDBName"></param> /// <param name="tableName"></param> /// <returns></returns> public static string getTablePath(TDatabase db, string tableName) { string ActualDBName = db.ToString(); string dbServer = getDatabaseServer(ref ActualDBName); if (tableName.Substring(0, 1) != "[") tableName = "[" + tableName + "]"; if (dbServer.Substring(0, 1) != "[") dbServer = "[" + dbServer + "]"; return string.Format("{0}.{1}.dbo.{2}", dbServer, ActualDBName, tableName); }
private static List<AuditLog> GetAuditList(string Q, SqlParameterCollection oParams, SqlUtil sql, TDatabase AuditDB) { if (sql == null) sql = SqlUtil.Get(AuditDB); List<AuditLog> headers = new List<AuditLog>(); if ((long)oParams["@ID"].Value == 0) return headers; DataTable oTable = sql.ExecuteSingleResultSetSQLQuery(Q, oParams); if (oTable.Rows.Count == 0) return headers; //each unique header has a list of the details long CurrId = -1; long id; AuditFields fields = null; foreach (DataRow r in oTable.Rows) { id = DataUtils.LongZeroIfNull(r["ID"]); if (id != CurrId) { AuditLog a = new AuditLog(r, false); headers.Add(a); fields = a.mFieldChanges; CurrId = id; } fields.Add(r); } return headers; }
/// <summary> /// get the audit list for datatypes supplied and optionaly adds in the audits for any correspondeces /// </summary> /// <param name="type"></param> /// <param name="DataId"></param> /// <param name="IncludeCorrespondenceLog"></param> /// <param name="NoErrors">do not include audit errors</param> /// <param name="SourceDB">The database that conatin the audit table you want to search since audit exists in almost every DB</param> /// <returns></returns> public static List<AuditLog> GetAuditListByDataType(string[] type, long DataId, bool IncludeCorrespondenceLog, bool NoErrors, TDatabase SourceDB) { return GetAuditListByDataType(type, DataId, IncludeCorrespondenceLog, NoErrors, SqlUtil.Get(SourceDB)); }
public static List<AuditLog> GetAuditListByAuditID(long AuditID, TDatabase AuditDB) { SqlParameterCollection oParameters = new SqlCommand().Parameters; oParameters.AddWithValue("@ID", AuditID); string query = "select * from auditheader h with (readpast)" + "left join auditdetail d on h.id = d.auditid where " + "h.id = @ID order by id asc"; return GetAuditList(query, oParameters, null, AuditDB); }
public static void AuditException(TDatabase db, Exception x, string msg, MethodBase ErrorOriginatingMethod) { try { if (bRecursiveCall) return; bRecursiveCall = true; AuditFields changelist = new AuditFields(); AddExceptionInfo(x, ErrorOriginatingMethod, changelist); string EventSrc = Environment.MachineName; long EventID = 0; AuditLog l = new AuditLog(0, "Exception", 0, EventSrc, EventID, changelist, db); l.Recover = true; l.Save(AuditLog.CompletionStatus.Exception, msg, true); } catch { } finally { bRecursiveCall = false; } }
protected GenericTable(TDatabase db, string IdColumn) : this("", db, IdColumn) { }
//get any record from a any database and returns ToString on it public static string AnyTableToString(string tablename, TDatabase db, long uid) { string DispString; if ((tablename == null)) { DispString = "unknown data type"; } else { try { GenericTable gt = new GenericTable(tablename, db); gt.ReadRecord(uid); DispString = gt.ToString(); } catch (Exception x) { DispString = "Error getting record " + x.Message; } } return DispString; }
private SqlUtil(TDatabase Database, string DBName, string appName) { if (appName != null) { this.ApplicationName = appName; } else { this.ApplicationName = Process.GetCurrentProcess().ProcessName; } ConstructMe(Database, DBName, null); }
public GenericTable(string TableName, TDatabase db) : this(TableName, db, null) { }
public static string BuildTablePath(TDatabase db, string table) { return DBLocator.getTablePath(db, table); }
private void ConstructMe(string tableName, TDatabase db, string IdColumn, SqlUtil sql) { if (db == TDatabase.Unknown) db = this.DefaultDatabase; if (string.IsNullOrEmpty(tableName)) tableName = this.DefaultTableName; // allows a subclass to define a tablename by method rather than passing in the constructor. if (IdColumn == null) IdColumn = "ID"; mIdColumn = IdColumn; if (sql != null) mSqlUtil = sql; else mSqlUtil = SqlUtil.Get(db); if (tableName.StartsWith("[")) mTableName = tableName; else mTableName = "[" + tableName + "]"; mFullTablePath = mSqlUtil.FullTablePath(tableName); mTableDef = GetTableDef(); mChangeList = new Dictionary<string, object>(); if (mTableDef == null) { Exception x = new Exception("no ID field"); throw x; } if (mIdColumn != (string)mIdColumnHash[mFullTablePath]) { Exception x = new Exception("cant redefined id column"); throw x; } mHasIdentity = (bool)mHasIdentityCache[mFullTablePath]; mData = new Dictionary<string, object>(mTableDef.Count + 3); //init all fields to null foreach (string f in mTableDef.Keys) mData[f] = System.DBNull.Value; mNewRecord = true; }
public static SqlUtil Get(TDatabase Database, string appName) { bool NoCaching = true; if (NoCaching) { return new SqlUtil(Database, appName); } //save a copy of original for later use, in case first call to getDatabaseServer modifies it string db = Database.ToString(); string svr = DBLocator.getDatabaseServer(ref db); string k = string.Format("{0}:{1}:{2}", Process.GetCurrentProcess().Id, svr, db); lock (xDBLock) { if (mRegisteredConnection[k] == null) { mRegisteredConnection[k] = new SqlUtil(Database, appName); } return (SqlUtil)mRegisteredConnection[k]; } }
//this is really a constructor for all those class that cant //change and add a new local variable //MULTI SAFE //TODO: In the future we may eliminate unspec as well public static SqlUtil Get(TDatabase Database) { return Get(Database, null); }
public AuditLog(DataRow r, bool FillDetails, TDatabase Database) { mID = DataUtils.LongZeroIfNull(r["ID"]); mDataType = (string)DataUtils.BlankIfNull(r["DataType"]); mEventDescription = (string)DataUtils.BlankIfNull(r["EventDescription"]); mCompletionMsg = (string)DataUtils.BlankIfNull(r["CompletionMsg"]); mCorrespondenceID = DataUtils.LongZeroIfNull(r["CorrespondenceID"]); mDataID = DataUtils.LongZeroIfNull(r["DataID"]); mCompletionStatus = (AuditLog.CompletionStatus)DataUtils.LongZeroIfNull(r["CompletionStatus"]); mLogTime = (DateTime)r["LogTime"]; mDatabase = Database; mFieldChanges = new AuditFields(); if (FillDetails) { SqlParameterCollection oParameters = new SqlCommand().Parameters; oParameters.AddWithValue("@ID", mID); string query = "select * from AuditDetail where AuditID = @ID"; DataTable oTable = SqlUtil.Get(mDatabase).ExecuteSingleResultSetSQLQuery(query, oParameters); if (oTable.Rows.Count == 0) return; foreach (DataRow r2 in oTable.Rows) { mFieldChanges.Add(r2); } } }