43 Star 88 Fork 41

飞来的钥匙 / stwhCMS_BootStrap

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
SessionStateProvider.cs 32.87 KB
一键复制 编辑 原始数据 按行查看 历史
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
#region [License]
/**
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
2. Grant of Copyright License.
Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
3. Grant of Patent License.
Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
4. Redistribution.
You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
1. You must give any other recipients of the Work or Derivative Works a copy of this License; and
2. You must cause any modified files to carry prominent notices stating that You changed the files; and
3. You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
4. If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
5. Submission of Contributions.
Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
6. Trademarks.
This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty.
Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
8. Limitation of Liability.
In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability.
While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration.Provider;
using System.Web.SessionState;
using System.IO;
using System.Web;
using System.Web.Configuration;
using System.Configuration;
using System.Diagnostics;
using MemcachedProviders.Session.Memcached;
using MemcachedProviders.Session.Db;
using MemcachedProviders.Session;
using MemcachedProviders.Common;
using Enyim.Caching;
using Enyim.Caching.Memcached;
namespace MemcachedProviders.Session
{
public class SessionStateProvider : SessionStateStoreProviderBase
{
#region Membership Variables
private string _strApplicationName;
private string _strConn;
private string _strDbType;
//private ConnectionStringSettings _objConnectionStringSettings;
private SessionStateSection _objConfig = null;
private bool _objWriteExceptionsToEventLog = false;
private bool _bIsDbNone = false;
//private string _strSessionProviderCat = "Memcached Session Provider";
//private string _strTotalOperName = "# operations executed";
//private string _strOperPerSecName = "# operations / sec";
//private string _strMemcachedOp = "# of memcached operations executed";
//private string _strMemcachedOpPerSec = "# of memcached operations / sec";
//private string _strDbOp = "# of database operations executed";
//private string _strDbOpPerSec = "# of database operations / sec";
//private PerformanceCounter _objTotalOperations;
//private PerformanceCounter _objOperationsPerSecond;
//private PerformanceCounter _objMemcachedOperations;
//private PerformanceCounter _objMemcachedOperPerSec;
//private PerformanceCounter _objDbOperations;
//private PerformanceCounter _objDbOperationsPerSec;
// Memcached variables
private MemcachedClient _client = MemcachedClientService.Instance.Client;
private long _lTimeoutInMilliSec = 20000; // default Expire Time
#endregion
public bool WriteExceptionsToEventLog
{
get { return _objWriteExceptionsToEventLog; }
set { _objWriteExceptionsToEventLog = value; }
}
public string ApplicationName
{
get { return this._strApplicationName; }
set { this._strApplicationName = value; }
}
public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
{
// Initialize values from web.config.
if (config == null)
throw new ArgumentNullException("config");
if (name == null || name.Length == 0)
name = "MemcachedSessionStateStore";
if (String.IsNullOrEmpty(config["description"]))
{
config.Remove("description");
config.Add("description", "Memcached Session Provider");
}
// Initialize the abstract base class.
base.Initialize(name, config);
// Initialize the ApplicationName property.
ApplicationName = System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath;
// Get <sessionState> configuration element.
Configuration cfg = WebConfigurationManager.OpenWebConfiguration(ApplicationName);
_objConfig = (SessionStateSection)cfg.GetSection("system.web/sessionState");
if (!string.IsNullOrEmpty(config["dbType"]))
{
if (config["dbType"].ToLower() == "none")
{
this._strDbType = Common.DbType.None;
this._bIsDbNone = true;
}
else
{
this._strDbType = Common.DbType.SQLServer;
this._bIsDbNone = false;
#region 未修改
//// Initialize connection string.
//_objConnectionStringSettings = ConfigurationManager.ConnectionStrings[config["connectionStringName"]];
//if (_objConnectionStringSettings == null || _objConnectionStringSettings.ConnectionString.Trim() == "")
// throw new ProviderException("Connection string cannot be blank.");
//_strConn = _objConnectionStringSettings.ConnectionString;
#endregion
#region 修改
_strConn = ConfigurationManager.AppSettings["ConnectionString"];
string ConStringEncrypt = ConfigurationManager.AppSettings["ConStringEncrypt"];
if (ConStringEncrypt == "true") _strConn = Common.Decrypt(_strConn, "keyname");
#endregion
}
}
// Initialize Memcached Values
_lTimeoutInMilliSec = (long)_objConfig.Timeout.TotalMilliseconds;
//Initialize Performance Counter
//this.CheckPerformanceCounterCategories();
// Initialize WriteExceptionsToEventLog
_objWriteExceptionsToEventLog = false;
if (config["writeExceptionsToEventLog"] != null)
{
if (config["writeExceptionsToEventLog"].ToUpper() == "TRUE")
_objWriteExceptionsToEventLog = true;
}
}
public override SessionStateStoreData CreateNewStoreData(System.Web.HttpContext context, int timeout)
{
//this.IncrementTotalOperPC();
return Common.CreateNewStoreData(context, timeout);
}
public override void CreateUninitializedItem(System.Web.HttpContext context, string id,int timeout)
{
//this.IncrementTotalOperPC();
DateTime dSetTime = DateTime.Now;
if (this._bIsDbNone == false)
{
#region Setting it in Db
//this.IncrementDbPC();
using (IDbOperations objDb = DbFactory.CreateDbOperations(_strDbType, _strConn))
{
objDb.Add(id, ApplicationName, dSetTime,dSetTime.AddMinutes((double)timeout),dSetTime, 0, timeout, false, null, 1);
}
#endregion
}
#region Updating item in memcached
//this.IncrementMemcachedPC();
MemcachedHolder objHolder = new MemcachedHolder(null, false, dSetTime, 0, 1);
this._client.Store(StoreMode.Set, id, objHolder, new TimeSpan(0, timeout, 0));
#endregion
}
public override void Dispose()
{
}
public override void EndRequest(System.Web.HttpContext context)
{
// leave empty
}
public override SessionStateStoreData GetItem(System.Web.HttpContext context, string id,out bool locked, out TimeSpan lockAge, out object lockId, out SessionStateActions actions)
{
//this.IncrementTotalOperPC();
SessionStateStoreData objItem = null;
//this.IncrementMemcachedPC();
MemcachedHolder objHolder = this._client.Get<MemcachedHolder>(id);
DateTime dSetTime = DateTime.Now;
#region Initialized
lockAge = TimeSpan.Zero;
lockId = null;
locked = false;
actions = 0;
#endregion
if (objHolder != null)
{
if (objHolder.Locked == false)
{
#region
objHolder.LockId++;
objHolder.SetTime = dSetTime;
this._client.Store(StoreMode.Set,id, objHolder, new TimeSpan(0, 0, 0, 0, _objConfig.Timeout.Milliseconds));
actions = (SessionStateActions)objHolder.ActionFlag;
lockId = objHolder.LockId;
lockAge = objHolder.LockAge;
if (this._bIsDbNone == false) // Saving to Db
{
//this.IncrementDbPC();
using (IDbOperations objDb = DbFactory.CreateDbOperations(_strDbType, _strConn))
{
objDb.LockItem(id, ApplicationName, objHolder.LockId);
}
}
if (actions == SessionStateActions.InitializeItem)
{
objItem = Common.CreateNewStoreData(context, _objConfig.Timeout.Minutes);
}
else
{
objItem = Common.Deserialize(context, objHolder.Content, _objConfig.Timeout.Minutes);
}
return objItem;
#endregion
}
else
{
lockAge = objHolder.LockAge;
locked = true;
lockId = objHolder.LockId;
actions = (SessionStateActions)objHolder.ActionFlag;
return objItem;
}
}
else
{
if (this._bIsDbNone == false)
{
//this.IncrementDbPC();
using (IDbOperations objDb = DbFactory.CreateDbOperations(_strDbType, _strConn))
{
return objDb.GetItem(id, ApplicationName, _objConfig.Timeout.Minutes,context, false, out locked, out lockAge, out lockId, out actions);
}
}
else
{
return objItem;
}
}
}
public override SessionStateStoreData GetItemExclusive(System.Web.HttpContext context, string id,out bool locked, out TimeSpan lockAge, out object lockId, out SessionStateActions actions)
{
//this.IncrementTotalOperPC();
//this.IncrementMemcachedPC();
SessionStateStoreData objItem = null;
MemcachedHolder objHolder = this._client.Get<MemcachedHolder>(id);
DateTime dSetTime = DateTime.Now;
#region Initialized
lockAge = TimeSpan.Zero;
lockId = null;
locked = false;
actions = 0;
#endregion
if (objHolder != null)
{
if (objHolder.Locked == false)
{
#region
objHolder.LockId++;
objHolder.SetTime = dSetTime;
// Locking Item for memcached
objHolder.Locked = true;
//this.IncrementMemcachedPC();
this._client.Store(StoreMode.Set, id, objHolder,new TimeSpan(0, 0, 0, 0, _objConfig.Timeout.Milliseconds));
actions = (SessionStateActions)objHolder.ActionFlag;
lockId = objHolder.LockId;
lockAge = objHolder.LockAge;
if (this._bIsDbNone == false) // Saving to Db
{
//this.IncrementDbPC();
using (IDbOperations objDb = DbFactory.CreateDbOperations(_strDbType, _strConn))
{
locked = objDb.LockItemWithoutLockId(id, ApplicationName);
objDb.LockItem(id, ApplicationName, objHolder.LockId);
}
}
if (actions == SessionStateActions.InitializeItem)
{
objItem = Common.CreateNewStoreData(context, _objConfig.Timeout.Minutes);
}
else
{
objItem = Common.Deserialize(context, objHolder.Content, _objConfig.Timeout.Minutes);
}
return objItem;
#endregion
}
else
{
lockAge = objHolder.LockAge;
locked = true;
lockId = objHolder.LockId;
actions = (SessionStateActions)objHolder.ActionFlag;
return objItem;
}
}
else
{
if (this._bIsDbNone == false) // Saving to Db
{
//this.IncrementDbPC();
using (IDbOperations objDb = DbFactory.CreateDbOperations(_strDbType, _strConn))
{
return objDb.GetItem(id, ApplicationName, _objConfig.Timeout.Minutes,context, true, out locked, out lockAge, out lockId, out actions);
}
}
else
{
return objItem;
}
}
}
public override void InitializeRequest(System.Web.HttpContext context)
{
//leave empty
}
public override void ReleaseItemExclusive(System.Web.HttpContext context, string id, object lockId)
{
//this.IncrementTotalOperPC();
#region Updating item in memcached
//this.IncrementMemcachedPC();
MemcachedHolder objHolder = this._client.Get<MemcachedHolder>(id);
if (objHolder != null)
{
objHolder.Locked = false;
objHolder.LockId = (int)lockId;
//this.IncrementMemcachedPC();
this._client.Store(StoreMode.Set, id, objHolder);
}
#endregion
if (this._bIsDbNone == false)
{
#region Updating Database
//this.IncrementDbPC();
using (IDbOperations objDb = DbFactory.CreateDbOperations(_strDbType, _strConn))
{
objDb.ReleaseItem(id, ApplicationName, (int)lockId, _objConfig.Timeout.Minutes);
}
#endregion
}
}
public override void RemoveItem(System.Web.HttpContext context, string id, object lockId, SessionStateStoreData item)
{
//this.IncrementTotalOperPC();
#region Removing Item from memcached
//this.IncrementMemcachedPC();
this._client.Remove(id);
#endregion
if (this._bIsDbNone == false) // Saving to Db
{
#region Removing item from db
//this.IncrementDbPC();
using (IDbOperations objDb = DbFactory.CreateDbOperations(_strDbType, _strConn))
{
objDb.RemoveItem(id, ApplicationName);
}
#endregion
}
}
public override void ResetItemTimeout(System.Web.HttpContext context, string id)
{
//this.IncrementTotalOperPC();
#region Reset Item Timeout in Memcached
//this.IncrementMemcachedPC();
object obj = this._client.Get(id);
if (obj != null)
{
//this.IncrementMemcachedPC();
this._client.Store(StoreMode.Set, id, obj,new TimeSpan(0,_objConfig.Timeout.Minutes,0));
}
#endregion
if (this._bIsDbNone == false) // Saving to Db
{
#region Reset Item Timeout in db
//this.IncrementDbPC();
using (IDbOperations objDb = DbFactory.CreateDbOperations(_strDbType, _strConn))
{
objDb.ResetItemTimeout(id, ApplicationName, _objConfig.Timeout.Minutes);
}
#endregion
}
}
public override void SetAndReleaseItemExclusive(System.Web.HttpContext context,string id, SessionStateStoreData item, object lockId, bool newItem)
{
//this.IncrementTotalOperPC();
if (this._bIsDbNone == false)
{
#region Db option
using (IDbOperations objDb = DbFactory.CreateDbOperations(_strDbType, _strConn))
{
byte[] objContent = null;
DateTime dSetTime = DateTime.Now;
objContent = Common.Serialize((SessionStateItemCollection)item.Items);
if (newItem == true)
{
//this.IncrementDbPC();
objDb.Add(id, ApplicationName, dSetTime,dSetTime.AddMinutes((Double)item.Timeout), dSetTime,0, item.Timeout, false,objContent, 0);
// Setting it up in memcached
MemcachedHolder objHolder = new MemcachedHolder(objContent, false, dSetTime, 0, 0);
//this.IncrementMemcachedPC();
this._client.Store(StoreMode.Set,id, objHolder, new TimeSpan(0, item.Timeout, 0));
}
else
{
//this.IncrementDbPC();
objDb.Update(id, ApplicationName, (int)lockId,dSetTime.AddMinutes((Double)item.Timeout),objContent, false);
// Setting it up in memcached
MemcachedHolder objHolder = new MemcachedHolder(objContent, false, dSetTime, 0, 0);
//this.IncrementMemcachedPC();
this._client.Store(StoreMode.Set,id, objHolder, new TimeSpan(0, item.Timeout, 0));
}
}
#endregion
}
else // Just memcached version
{
byte[] objContent = null;
DateTime dSetTime = DateTime.Now;
objContent = Common.Serialize((SessionStateItemCollection)item.Items);
if (newItem == true)
{
// Setting it up in memcached
MemcachedHolder objHolder = new MemcachedHolder(objContent, false, dSetTime, 0, 0);
//this.IncrementMemcachedPC();
this._client.Store(StoreMode.Set,id, objHolder, new TimeSpan(0, item.Timeout, 0));
}
else
{
// Setting it up in memcached
MemcachedHolder objHolder = new MemcachedHolder(objContent, false, dSetTime, 0, 0);
//this.IncrementMemcachedPC();
this._client.Store(StoreMode.Set,id, objHolder, new TimeSpan(0, item.Timeout, 0));
}
}
}
public override bool SetItemExpireCallback(SessionStateItemExpireCallback expireCallback)
{
//this.IncrementTotalOperPC();
return false;
}
#region Performance Counter Methods
//internal void CheckPerformanceCounterCategories()
//{
// if (!PerformanceCounterCategory.Exists(_strSessionProviderCat))
// {
// CounterCreationDataCollection counters = new CounterCreationDataCollection();
// CounterCreationData totalOps = new CounterCreationData();
// totalOps.CounterName = _strTotalOperName;
// totalOps.CounterHelp = "Total number of operations executed";
// totalOps.CounterType = PerformanceCounterType.NumberOfItems32;
// counters.Add(totalOps);
// CounterCreationData opsPerSecond = new CounterCreationData();
// opsPerSecond.CounterName = _strOperPerSecName;
// opsPerSecond.CounterHelp = "Number of operations executed per second";
// opsPerSecond.CounterType = PerformanceCounterType.RateOfCountsPerSecond32;
// counters.Add(opsPerSecond);
// CounterCreationData memcachedOps = new CounterCreationData();
// memcachedOps.CounterName = _strMemcachedOp;
// memcachedOps.CounterHelp = "Number of Memcached operations execution";
// memcachedOps.CounterType = PerformanceCounterType.NumberOfItems32;
// counters.Add(memcachedOps);
// CounterCreationData memcachedOpsPerSec = new CounterCreationData();
// memcachedOpsPerSec.CounterName = _strMemcachedOpPerSec;
// memcachedOpsPerSec.CounterHelp = "Number of Memcached operations per second";
// memcachedOpsPerSec.CounterType = PerformanceCounterType.RateOfCountsPerSecond32;
// counters.Add(memcachedOpsPerSec);
// CounterCreationData dbOps = new CounterCreationData();
// dbOps.CounterName = _strDbOp;
// dbOps.CounterHelp = "Number of database operations execution";
// dbOps.CounterType = PerformanceCounterType.NumberOfItems32;
// counters.Add(dbOps);
// CounterCreationData dbOpsPerSec = new CounterCreationData();
// dbOpsPerSec.CounterName = _strDbOpPerSec;
// dbOpsPerSec.CounterHelp = "Number of database operations execution";
// dbOpsPerSec.CounterType = PerformanceCounterType.RateOfCountsPerSecond32;
// counters.Add(dbOpsPerSec);
// // create new category with the counters above
// PerformanceCounterCategory.Create(_strSessionProviderCat,"Memcached Session Provider Performance Counter",PerformanceCounterCategoryType.SingleInstance, counters);
// }
// #region create counters to work with
// _objTotalOperations = new PerformanceCounter();
// _objTotalOperations.CategoryName = _strSessionProviderCat;
// _objTotalOperations.CounterName = _strTotalOperName;
// _objTotalOperations.MachineName = ".";
// _objTotalOperations.ReadOnly = false;
// _objTotalOperations.RawValue = 0;
// _objOperationsPerSecond = new PerformanceCounter();
// _objOperationsPerSecond.CategoryName = _strSessionProviderCat;
// _objOperationsPerSecond.CounterName = _strOperPerSecName;
// _objOperationsPerSecond.MachineName = ".";
// _objOperationsPerSecond.ReadOnly = false;
// _objOperationsPerSecond.RawValue = 0;
// _objMemcachedOperations = new PerformanceCounter();
// _objMemcachedOperations.CategoryName = _strSessionProviderCat;
// _objMemcachedOperations.CounterName = _strMemcachedOp;
// _objMemcachedOperations.MachineName = ".";
// _objMemcachedOperations.ReadOnly = false;
// _objMemcachedOperations.RawValue = 0;
// _objMemcachedOperPerSec = new PerformanceCounter();
// _objMemcachedOperPerSec.CategoryName = _strSessionProviderCat;
// _objMemcachedOperPerSec.CounterName = _strMemcachedOpPerSec;
// _objMemcachedOperPerSec.MachineName = ".";
// _objMemcachedOperPerSec.ReadOnly = false;
// _objMemcachedOperPerSec.RawValue = 0;
// _objDbOperations = new PerformanceCounter();
// _objDbOperations.CategoryName = _strSessionProviderCat;
// _objDbOperations.CounterName = _strDbOp;
// _objDbOperations.MachineName = ".";
// _objDbOperations.ReadOnly = false;
// _objDbOperations.RawValue = 0;
// _objDbOperationsPerSec = new PerformanceCounter();
// _objDbOperationsPerSec.CategoryName = _strSessionProviderCat;
// _objDbOperationsPerSec.CounterName = _strDbOpPerSec;
// _objDbOperationsPerSec.MachineName = ".";
// _objDbOperationsPerSec.ReadOnly = false;
// _objDbOperationsPerSec.RawValue = 0;
// #endregion
//}
//internal void IncrementTotalOperPC()
//{
// this._objTotalOperations.Increment();
// this._objOperationsPerSecond.Increment();
//}
//internal void IncrementMemcachedPC()
//{
// this._objMemcachedOperations.Increment();
// this._objMemcachedOperPerSec.Increment();
//}
//internal void IncrementDbPC()
//{
// this._objDbOperations.Increment();
// this._objDbOperationsPerSec.Increment();
//}
#endregion
}
}
C#
1
https://gitee.com/zj_admin/stwhCMS_BootStrap.git
git@gitee.com:zj_admin/stwhCMS_BootStrap.git
zj_admin
stwhCMS_BootStrap
stwhCMS_BootStrap
master

搜索帮助