SQLiteWebEventProvider.cs :  » Content-Management-Systems-CMS » Kooboo » System » Web » Management » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Content Management Systems CMS » Kooboo 
Kooboo » System » Web » Management » SQLiteWebEventProvider.cs
/*
Kooboo is a content management system based on ASP.NET MVC framework. Copyright 2009 Yardi Technology Limited.

This program is free software: you can redistribute it and/or modify it under the terms of the
GNU General Public License version 3 as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.kooboo.com/gpl3/.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using System.Data.SQLite;
using System.Globalization;

namespace System.Web.Management{
    public class SQLiteWebEventProvider : BufferedWebEventProvider
    {
        private DateTime _retryDate;
        private string connectionString;
        int _maxEventDetailsLength;
        private int _commandTimeout;

        public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
        {
            connectionString = ConfigurationManager.ConnectionStrings[config["connectionStringName"]].ConnectionString;


            int.TryParse(config["maxEventDetailsLength"], out _maxEventDetailsLength);

            if (this._maxEventDetailsLength == 0x7fffffff)
            {
                this._maxEventDetailsLength = -1;
            }
            int.TryParse(config["commandTimeout"], out _commandTimeout);

            config.Remove("connectionStringName");
            config.Remove("maxEventDetailsLength");
            config.Remove("commandTimeout");

            base.Initialize(name, config);
        }
        public override void ProcessEvent(WebBaseEvent eventRaised)
        {
            if (base.UseBuffering)
            {
                base.ProcessEvent(eventRaised);
            }
            else
            {
                this.WriteToSQL(new WebBaseEventCollection(new WebBaseEvent[] { eventRaised }), 0, new DateTime(0L));
            }

        }
        public override void ProcessEventFlush(WebEventBufferFlushInfo flushInfo)
        {
            this.WriteToSQL(flushInfo.Events, flushInfo.EventsDiscardedSinceLastNotification, flushInfo.LastNotificationUtc);

        }


        private void PrepareParams(SQLiteCommand command)
        {
            command.Parameters.Add(new SQLiteParameter("$EventId", DbType.String, 0x20));
            command.Parameters.Add(new SQLiteParameter("$EventTimeUtc", DbType.DateTime));
            command.Parameters.Add(new SQLiteParameter("$EventTime", DbType.DateTime));
            command.Parameters.Add(new SQLiteParameter("$EventType", DbType.String, 0x100));
            command.Parameters.Add(new SQLiteParameter("$EventSequence", DbType.Decimal));
            command.Parameters.Add(new SQLiteParameter("$EventOccurrence", DbType.Decimal));
            command.Parameters.Add(new SQLiteParameter("$EventCode", DbType.Int32));
            command.Parameters.Add(new SQLiteParameter("$EventDetailCode", DbType.Int32));
            command.Parameters.Add(new SQLiteParameter("$Message", DbType.String, 0x400));
            command.Parameters.Add(new SQLiteParameter("$ApplicationPath", DbType.String, 0x100));
            command.Parameters.Add(new SQLiteParameter("$ApplicationVirtualPath", DbType.String, 0x100));
            command.Parameters.Add(new SQLiteParameter("$MachineName", DbType.String, 0x100));
            command.Parameters.Add(new SQLiteParameter("$RequestUrl", DbType.String, 0x400));
            command.Parameters.Add(new SQLiteParameter("$ExceptionType", DbType.String, 0x100));
            command.Parameters.Add(new SQLiteParameter("$Details", DbType.String));
        }
        private void FillParams(SQLiteCommand command, WebBaseEvent eventRaised)
        {
            Exception errorException = null;
            WebRequestInformation requestInformation = null;
            string str = null;
            WebApplicationInformation applicationInformation = WebBaseEvent.ApplicationInformation;
            int num = 0;
            command.Parameters[num++].Value = eventRaised.EventID.ToString("N", CultureInfo.InstalledUICulture);
            command.Parameters[num++].Value = eventRaised.EventTimeUtc;
            command.Parameters[num++].Value = eventRaised.EventTime;
            command.Parameters[num++].Value = eventRaised.GetType().ToString();
            command.Parameters[num++].Value = eventRaised.EventSequence;
            command.Parameters[num++].Value = eventRaised.EventOccurrence;
            command.Parameters[num++].Value = eventRaised.EventCode;
            command.Parameters[num++].Value = eventRaised.EventDetailCode;
            command.Parameters[num++].Value = eventRaised.Message;
            command.Parameters[num++].Value = applicationInformation.ApplicationPath;
            command.Parameters[num++].Value = applicationInformation.ApplicationVirtualPath;
            command.Parameters[num++].Value = applicationInformation.MachineName;
            if (eventRaised is WebRequestEvent)
            {
                requestInformation = ((WebRequestEvent)eventRaised).RequestInformation;
            }
            else if (eventRaised is WebRequestErrorEvent)
            {
                requestInformation = ((WebRequestErrorEvent)eventRaised).RequestInformation;
            }
            else if (eventRaised is WebErrorEvent)
            {
                requestInformation = ((WebErrorEvent)eventRaised).RequestInformation;
            }
            else if (eventRaised is WebAuditEvent)
            {
                requestInformation = ((WebAuditEvent)eventRaised).RequestInformation;
            }
            command.Parameters[num++].Value = (requestInformation != null) ? requestInformation.RequestUrl : Convert.DBNull;
            if (eventRaised is WebBaseErrorEvent)
            {
                errorException = ((WebBaseErrorEvent)eventRaised).ErrorException;
            }
            command.Parameters[num++].Value = (errorException != null) ? errorException.GetType().ToString() : Convert.DBNull;
            str = eventRaised.ToString();
            if ((this._maxEventDetailsLength != -1) && (str.Length > this._maxEventDetailsLength))
            {
                str = str.Substring(0, this._maxEventDetailsLength);
            }
            command.Parameters[num++].Value = str;
        }



        private void WriteToSQL(WebBaseEventCollection events, int eventsDiscardedByBuffer, DateTime lastNotificationUtc)
        {
            if (this._retryDate <= DateTime.UtcNow)
            {
                try
                {
                    var connection = new SQLiteConnection(connectionString);
                    var command = new SQLiteCommand(@"insert into aspnet_WebEvent_Events(EventId,EventTimeUtc,EventTime,EventType,EventSequence,EventOccurrence,
EventCode,EventDetailCode,Message,ApplicationPath,ApplicationVirtualPath,
MachineName,RequestUrl,ExceptionType,Details)
values($EventId,$EventTimeUtc,$EventTime,$EventType,$EventSequence,$EventOccurrence,
$EventCode,$EventDetailCode,$Message,$ApplicationPath,$ApplicationVirtualPath,
$MachineName,$RequestUrl,$ExceptionType,$Details)", connection);

                    this.PrepareParams(command);
                    try
                    {
                        connection.Open();
                        foreach (WebBaseEvent event3 in events)
                        {
                            this.FillParams(command, event3);
                            command.ExecuteNonQuery();
                        }
                    }
                    finally
                    {
                        connection.Close();
                    }
                    try
                    {
                        //this.EventProcessingComplete(events);
                    }
                    catch
                    {
                    }
                }
                catch
                {
                    double num = 30.0;
                    if (this._commandTimeout > -1)
                    {
                        num = this._commandTimeout;
                    }
                    this._retryDate = DateTime.UtcNow.AddSeconds(num);
                    throw;
                }
            }
        }

    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.