Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Diagnostics;
  6.  
  7. namespace EventHoc
  8. {
  9.     public class EventSession
  10.     {
  11.         public IEventStorage Storage { get; private set; }
  12.  
  13.         public Guid SessionID { get; set; }
  14.         public string SessionIdentifier { get; private set; }
  15.  
  16.         public DateTime SessionStart { get; private set; }
  17.         public DateTime SessionEnd { get; private set; }
  18.  
  19.         private bool? _isOpen;
  20.         private List<EventCache> _cachedEvents;
  21.  
  22.         public EventSession(string identifier = "")
  23.         {
  24.             SessionID = Guid.NewGuid();
  25.             SessionIdentifier = identifier;
  26.             _cachedEvents = new List<EventCache>();
  27.         }
  28.  
  29.         public EventSession(IEventStorage storage)
  30.         {
  31.             Storage = storage;
  32.         }
  33.  
  34.         public void Open()
  35.         {
  36.             if (_isOpen.HasValue)
  37.             {
  38.                 logMessage("session already opened or closed");
  39.                 return;
  40.             }
  41.  
  42.             SessionStart = DateTime.UtcNow;
  43.             _isOpen = true;
  44.         }
  45.  
  46.         public void Close()
  47.         {
  48.             if (_isOpen.HasValue)
  49.             {
  50.                 logMessage("session already opened or closed");
  51.                 return;
  52.             }
  53.  
  54.             SessionEnd = DateTime.UtcNow;
  55.             _isOpen = false;
  56.         }
  57.  
  58.         public void Flush()
  59.         {
  60.             //save events
  61.         }
  62.  
  63.         public void Log(string eventName, Dictionary<string, string> attributes = null)
  64.         {
  65.             if(attributes == null)
  66.                 attributes = new Dictionary<string,string>();
  67.  
  68.             var e = new EventCache()
  69.             {
  70.                 EventName = eventName,
  71.                 Attributes = attributes
  72.             };
  73.  
  74.             _cachedEvents.Add(e);
  75.         }
  76.  
  77.         private void logMessage(string message)
  78.         {
  79.             Debug.WriteLine("eventHOC - " + message);
  80.         }
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement