📄 sqldataprovider.cs
字号:
using System;
using System.Data;
using System.Collections;
using System.Configuration;
using System.Data.SqlClient;
using DotNetNuke;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Framework.Providers;
using DotNetNuke.Services.Log.EventLog.DBLoggingProvider;
using Microsoft.ApplicationBlocks.Data;
//
// DotNetNuke - http://www.dotnetnuke.com
// Copyright (c) 2002-2005
// by Shaun Walker ( sales@perpetualmotion.ca ) of Perpetual Motion Interactive Systems Inc. ( http://www.perpetualmotion.ca )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
namespace DotNetNuke.Services.Log.EventLog.DBLoggingProvider.Data
{
public class SqlDataProvider : DataProvider
{
#region "Private Members"
private const string providerType = "data";
private ProviderConfiguration providerConfiguration;
private string connectionString;
private string providerPath;
private string objectQualifier;
private string databaseOwner;
#endregion
#region "Constructors"
public SqlDataProvider()
{
// Read the configuration specific information for this provider
providerConfiguration = ProviderConfiguration.GetProviderConfiguration(providerType);
Provider provider = ((Provider) providerConfiguration.Providers[providerConfiguration.DefaultProvider]);
string connectionStringName = provider.Attributes["connectionStringName"];
// Read the attributes for this provider
if (connectionStringName != null && connectionStringName.Length > 0)
{
connectionString = ConfigurationSettings.AppSettings[connectionStringName];
}
if (connectionString == null || connectionString.Length == 0)
{
connectionString = provider.Attributes["connectionString"];
}
providerPath = provider.Attributes["providerPath"];
objectQualifier = provider.Attributes["objectQualifier"];
if (objectQualifier.Length > 0 && !objectQualifier.EndsWith("_"))
{
objectQualifier += "_";
}
databaseOwner = provider.Attributes["databaseOwner"];
if (databaseOwner.Length > 0 && !databaseOwner.EndsWith("."))
{
databaseOwner += ".";
}
}
#endregion
#region "Properties"
public string ConnectionString
{
get { return this.connectionString; }
}
public string ProviderPath
{
get { return this.providerPath; }
}
public string ObjectQualifier
{
get { return this.objectQualifier; }
}
public string DatabaseOwner
{
get { return this.databaseOwner; }
}
#endregion
#region "General Public Methods"
private object GetNull(object field)
{
return Null.GetNull(field, DBNull.Value);
}
#endregion
#region "DBLoggingProviderSqlDataProvider Methods"
//---------------------------------------------------------------------
// TODO Implement DAL methods.
// Use CodeSmith templates to generate this code
//---------------------------------------------------------------------
public override void AddLog (string guid, string logTypeKey, int userID, string userName, int portalID,
string portalName, DateTime createDate, string serverName, string properties, int configID)
{
SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "AddEventLog", guid, logTypeKey,
GetNull(userID), GetNull(userName), GetNull(portalID), GetNull(portalName), createDate, serverName, properties, configID);
}
public override void AddLogTypeConfigInfo (bool loggingIsActive, string logTypeKey, string logTypePortalID, int keepMostRecent, bool emailNotificationIsActive,
int threshold, int notificationThresholdTime, int notificationThresholdTimeType, string mailFromAddress, string mailToAddress)
{
int portalID;
if (logTypeKey == "*")
{
logTypeKey = "";
}
if (logTypePortalID == "*")
{
portalID = - 1;
}
else
{
portalID = Convert.ToInt32(logTypePortalID);
}
SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "AddEventLogConfig", GetNull(logTypeKey), GetNull(portalID),
loggingIsActive, keepMostRecent, emailNotificationIsActive, GetNull(threshold), GetNull(notificationThresholdTime),
GetNull(notificationThresholdTimeType), mailFromAddress, mailToAddress);
}
public override void UpdateLogTypeConfigInfo (string id, bool loggingIsActive, string logTypeKey, string logTypePortalID,
int keepMostRecent, string logFileName, bool emailNotificationIsActive, int threshold, int notificationThresholdTime,
int notificationThresholdTimeType, string mailFromAddress, string mailToAddress)
{
int portalID;
if (logTypeKey == "*")
{
logTypeKey = "";
}
if (logTypePortalID == "*")
{
portalID = - 1;
}
else
{
portalID = Convert.ToInt32(logTypePortalID);
}
SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "UpdateEventLogConfig",
id, GetNull(logTypeKey), GetNull(portalID), loggingIsActive, keepMostRecent, emailNotificationIsActive,
GetNull(threshold), GetNull(notificationThresholdTime), GetNull(notificationThresholdTimeType), mailFromAddress, mailToAddress);
}
public override void ClearLog ()
{
SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "DeleteEventLog", DBNull.Value);
}
public override void DeleteLog (string guid)
{
SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "DeleteEventLog", guid);
}
public override void DeleteLogTypeConfigInfo (string id)
{
SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "DeleteEventLogConfig", id);
}
public override IDataReader GetLog()
{
return ((IDataReader) SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner + ObjectQualifier + "GetEventLog", DBNull.Value, DBNull.Value));
}
public override IDataReader GetSingleLog(string guid)
{
return ((IDataReader) SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner + ObjectQualifier + "GetEventLogByLogGUID", guid));
}
public override IDataReader GetLog(int portalID)
{
return ((IDataReader) SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner + ObjectQualifier + "GetEventLog", portalID, DBNull.Value));
}
public override IDataReader GetLog(int portalID, string logType)
{
return ((IDataReader) SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner + ObjectQualifier + "GetEventLog", portalID, logType));
}
public override IDataReader GetLog(string logType)
{
return ((IDataReader) SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner + ObjectQualifier + "GetEventLog", DBNull.Value, logType));
}
public override IDataReader GetLog(int pageSize, int pageIndex)
{
return (IDataReader) SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner + ObjectQualifier + "GetEventLog",
DBNull.Value, DBNull.Value, pageSize, pageIndex);
}
public override IDataReader GetLog(int portalID, int pageSize, int pageIndex)
{
return (IDataReader) SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner + ObjectQualifier + "GetEventLog",
portalID, DBNull.Value, pageSize, pageIndex);
}
public override IDataReader GetLog(int portalID, string logType, int pageSize, int pageIndex)
{
return (IDataReader) SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner + ObjectQualifier + "GetEventLog",
portalID, logType, pageSize, pageIndex);
}
public override IDataReader GetLog(string logType, int pageSize, int pageIndex)
{
return (IDataReader) SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner + ObjectQualifier + "GetEventLog",
DBNull.Value, logType, pageSize, pageIndex);
}
public override IDataReader GetLogTypeConfigInfo()
{
return ((IDataReader) SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner + ObjectQualifier + "GetEventLogConfig", DBNull.Value));
}
public override IDataReader GetLogTypeConfigInfoByID(int id)
{
return ((IDataReader) SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner + ObjectQualifier + "GetEventLogConfig", id));
}
public override IDataReader GetLogTypeInfo()
{
return ((IDataReader) SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner + ObjectQualifier + "GetEventLogType", null));
}
public override void PurgeLog ()
{
SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "PurgeEventLog", null);
}
public override void AddLogType (string logTypeKey, string logTypeFriendlyName, string logTypeDescription, string logTypeCSSClass, string logTypeOwner)
{
SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "AddEventLogType", logTypeKey, logTypeFriendlyName, logTypeDescription, logTypeOwner, logTypeCSSClass);
}
public override void UpdateLogType (string logTypeKey, string logTypeFriendlyName, string logTypeDescription, string logTypeCSSClass, string logTypeOwner)
{
SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "UpdateEventLogType", logTypeKey, logTypeFriendlyName, logTypeDescription, logTypeOwner, logTypeCSSClass);
}
public override void DeleteLogType (string logTypeKey)
{
SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "DeleteEventLogType", logTypeKey);
}
public override IDataReader GetEventLogPendingNotifConfig()
{
return ((IDataReader) SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner + ObjectQualifier + "GetEventLogPendingNotifConfig", null));
}
public override IDataReader GetEventLogPendingNotif(int logConfigID)
{
return ((IDataReader) SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner + ObjectQualifier + "GetEventLogPendingNotif", logConfigID));
}
public override void UpdateEventLogPendingNotif (int logConfigID)
{
SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "UpdateEventLogPendingNotif", logConfigID);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -