Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Diagnostics;
- namespace EventHoc
- {
- public class EventSession
- {
- public IEventStorage Storage { get; private set; }
- public Guid SessionID { get; set; }
- public string SessionIdentifier { get; private set; }
- public DateTime SessionStart { get; private set; }
- public DateTime SessionEnd { get; private set; }
- private bool? _isOpen;
- private List<EventCache> _cachedEvents;
- public EventSession(string identifier = "")
- {
- SessionID = Guid.NewGuid();
- SessionIdentifier = identifier;
- _cachedEvents = new List<EventCache>();
- }
- public EventSession(IEventStorage storage)
- {
- Storage = storage;
- }
- public void Open()
- {
- if (_isOpen.HasValue)
- {
- logMessage("session already opened or closed");
- return;
- }
- SessionStart = DateTime.UtcNow;
- _isOpen = true;
- }
- public void Close()
- {
- if (_isOpen.HasValue)
- {
- logMessage("session already opened or closed");
- return;
- }
- SessionEnd = DateTime.UtcNow;
- _isOpen = false;
- }
- public void Flush()
- {
- //save events
- }
- public void Log(string eventName, Dictionary<string, string> attributes = null)
- {
- if(attributes == null)
- attributes = new Dictionary<string,string>();
- var e = new EventCache()
- {
- EventName = eventName,
- Attributes = attributes
- };
- _cachedEvents.Add(e);
- }
- private void logMessage(string message)
- {
- Debug.WriteLine("eventHOC - " + message);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement