StorageBusLoggingService.cs :  » Bloggers » dasBlog » newtelligence » DasBlog » Runtime » 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 » Bloggers » dasBlog 
dasBlog » newtelligence » DasBlog » Runtime » StorageBusLoggingService.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using newtelligence.DasBlog.Runtime;
using dasBlog.Storage;

namespace dasBlog.Services.Interop{
    class StorageBusLoggingService : ILoggingDataService, ILoggingDataServiceInitialize
    {
        private Moniker scopeUri;
        private Moniker eventsUri;
        private Moniker logUri;

        public StorageBusLoggingService()
        {
         
        }

        public StorageBusLoggingService(string scopeName)
        {
            Initialize(scopeName);
        }

        public void Initialize(string scopeName)
        {
            this.scopeUri = Moniker.FromScopeName(scopeName);
            this.eventsUri = new Moniker(scopeName, PathSegmentName.Events);
            this.logUri = new Moniker(scopeName, PathSegmentName.Trackings);
        }


        public LogDataItemCollection GetReferralsForDay(DateTime date)
        {
            return GetLogItems(date, "Referral");
        }
        
        public void AddReferral(LogDataItem logItem)
        {
            AddLogItem(logItem, "Referral");
        }
                
        public LogDataItemCollection GetClickThroughsForDay(DateTime date)
        {
            return GetLogItems(date, "Clickthrough");
        }

        public void AddClickThrough(LogDataItem logItem)
        {
            AddLogItem(logItem, "Clickthrough");
        }

        public LogDataItemCollection GetAggregatorBugHitsForDay(DateTime date)
        {
            return GetLogItems(date, "Aggbug");
        }

        public void AddAggregatorBugHit(LogDataItem logItem)
        {
            AddLogItem(logItem, "Aggbug");
        }

        public LogDataItemCollection GetCrosspostReferrersForDay(DateTime date)
        {
            return GetLogItems(date, "Crosspost");
        }

        public void AddCrosspostReferrer(LogDataItem logItem)
        {
            AddLogItem(logItem, "Crosspost");
        }

        public EventDataItemCollection GetEventsForDay(DateTime date)
        {
            return new EventDataItemCollection(
                (from entry in 
                      eventsUri.Select<EventEntry>(
                                        MonikerMatch.Exact,
                                        new DateRangeQueryDescription(date.Date, date.Date.AddDays(1).AddMilliseconds(-1)))
                 orderby entry.Time ascending
                 select new EventDataItem
                 {
                      EventCode = int.Parse(entry.Code),
                      EventTimeUtc = entry.Time,
                      HtmlMessage = entry.Message
                 }).ToArray());
        }

        public void AddEvent(EventDataItem eventData)
        {
            EventEntry logEntry = new EventEntry
            {
                 Code = eventData.EventCode.ToString(),
                 Message = eventData.HtmlMessage,
                 Time = eventData.EventTimeUtc
            };
            eventsUri.Store<EventEntry>(logEntry);
        }

        private void AddLogItem(LogDataItem logItem, string type)
        {
            LogEntry logEntry = new LogEntry
            {
                TrackingType = type,
                ReferrerUrl = logItem.UrlReferrer,
                UserAgent = logItem.UserAgent,
                UserDomain = logItem.UserDomain,
                UrlRequested = logItem.UrlRequested,
                RequestTime = logItem.RequestedUtc
            };
            logUri.Store<LogEntry>(logEntry);
        }

        private LogDataItemCollection GetLogItems(DateTime date, string type)
        {
            return new LogDataItemCollection(
                (from entry in 
                      logUri.Select<LogEntry>(
                                        MonikerMatch.Exact,
                                        new DateRangeAndTagQueryDescription(date.Date, date.Date.AddDays(1).AddMilliseconds(-1), type))
                 orderby entry.RequestTime ascending
                 select new LogDataItem
                 {
                      RequestedUtc = entry.RequestTime,
                      UrlReferrer = entry.ReferrerUrl,
                      UrlRequested = entry.UrlRequested,
                      UserAgent = entry.UserAgent,
                      UserDomain = entry.UserDomain
                 }).ToArray());
        }


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