public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string key = context.Request.Form["content"]; try { DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(PerfData)); MemoryStream mStream = new MemoryStream(Encoding.UTF8.GetBytes(key)); PerfData data = serializer.ReadObject(mStream) as PerfData; data.Id = Guid.NewGuid().ToString(); data.LogDate = DateTime.Now; DbEx.SavePerf(data); } catch (Exception ex) { ex.ToString(); } }
internal static void SavePerf(PerfData perf) { string dbtype = ConfigurationManager.AppSettings["dbtype"].ToUpper().Trim(); string connstr = ConfigurationManager.ConnectionStrings["connstr"].ConnectionString; if (dbtype == "MSSQL") { using (SqlConnection conn = new SqlConnection(connstr)) { object tableInited = conn.ExecuteScalar("select 1 from sys.tables t where t.name = 'TEMP_TKK_PerfData0719'"); if (tableInited == null || tableInited == DBNull.Value) { conn.Execute(@"CREATE TABLE TEMP_TKK_PerfData0719( code varchar(36) NOT NULL, LogDate datetime not null, ClientName varchar(100) null, ClientDuration int NULL, AppDuration int NULL, DbDuration int NULL, ClientRequests int NULL, AppResponds int NULL, AppRequests int NULL, DbResponds int null, ReadClob int null, ReadBlob int null, WriteClob int null, WriteBlob int null, ClobMax int null, BlobMax int null, RandomLob int null, CONSTRAINT PK__TEMP_TKK_PerfData0719 PRIMARY KEY (code) )"); conn.Execute("create index idx1_TEMP_TKK_PerfData0719 on TEMP_TKK_PerfData0719(LogDate)"); conn.Execute("create index idx2_TEMP_TKK_PerfData0719 on TEMP_TKK_PerfData0719(ClientName)"); } string sql = "insert into TEMP_TKK_PerfData0719 (code, LogDate, ClientName, ClientDuration, AppDuration, DbDuration" + ", clientrequests, appresponds, apprequests, dbresponds, readclob, readblob, writeclob, writeblob, clobmax, blobmax, randomlob)" + " values(@Id, @LogDate, @ClientName, @ClientDuration, @AppDuration, @DbDuration" + " , @ClientRequests, @AppResponds, @AppRequests, @DbResponds, @ReadClob, @ReadBlob, @WriteClob, @WriteBlob" + " , @MaxClobLength, @MaxBlobLength, @RandomLobLength)"; conn.Execute(sql, perf); } } else { IDbConnection conn; switch (dbtype) { case "ODAC": conn = new ManagedOralceConnection(connstr); break; case "ODP.NET": conn = ODPClientFactory.CreateConnection(); conn.ConnectionString = connstr; break; default: conn = new OracleConnection(connstr); break; } try { object tableInited = conn.ExecuteScalar("select 1 from user_tables t where t.table_name = upper('TEMP_TKK_PerfData0719')"); if (tableInited == null || tableInited == DBNull.Value) { conn.Execute(@"CREATE TABLE TEMP_TKK_PerfData0719( code varchar2(36) NOT NULL, LogDate timestamp not null, ClientName varchar2(100) null, ClientDuration int NULL, AppDuration int NULL, DbDuration int NULL, ClientRequests int NULL, AppResponds int NULL, AppRequests int NULL, DbResponds int null, ReadClob int null, ReadBlob int null, WriteClob int null, WriteBlob int null, ClobMax int null, BlobMax int null, RandomLob int null, CONSTRAINT PK__TEMP_TKK_PerfData0719 PRIMARY KEY (code) )"); conn.Execute("create index idx1_TEMP_TKK_PerfData0719 on TEMP_TKK_PerfData0719(LogDate)"); conn.Execute("create index idx2_TEMP_TKK_PerfData0719 on TEMP_TKK_PerfData0719(ClientName)"); } string sql = "insert into TEMP_TKK_PerfData0719 (code, LogDate, ClientName, ClientDuration, AppDuration, DbDuration" + ", clientrequests, appresponds, apprequests, dbresponds, readclob, readblob, writeclob, writeblob, clobmax, blobmax, randomlob)" + " values(:Id, :LogDate, :ClientName, :ClientDuration, :AppDuration, :DbDuration" + " , :ClientRequests, :AppResponds, :AppRequests, :DbResponds, :ReadClob, :ReadBlob, :WriteClob, :WriteBlob" + " , :MaxClobLength, :MaxBlobLength, :RandomLobLength)"; conn.Execute(sql, perf); } finally { if (conn != null) { conn.Close(); } } } }