public Event DictionaryInsert() { //perform association var associatedSet = AssociateForDictionaryEvents(); if (associatedSet == null) { ResetIdle(); return(null); } Event e = associatedSet[0]; //key EventValues idt = associatedSet[1]; //value try { // if an event is already in the table, update timespan and idle time if (Global.dictionaryEvents.ContainsKey(e)) { Global.dictionaryEvents[e].ts = Global.dictionaryEvents[e].ts + _ts; if (_idleFreeze > 0) { Global.dictionaryEvents[e].idle = Global.dictionaryEvents[e].idle + TimeSpan.FromSeconds(_idleFreeze); } var oldActive = Global.dictionaryEvents[e].active; //old active time Global.dictionaryEvents[e].active = Global.dictionaryEvents[e].ts - Global.dictionaryEvents[e].idle; //new active time Global.dictionaryEvents[e].activeDelta = Global.dictionaryEvents[e].active - oldActive; //get differences of active times StoreGlobal(0, e); TaskTimeLogUpdate(e); } else { Global.dictionaryEvents.Add(e, idt); StoreGlobal(1, e); TaskTimeLogUpdate(e); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } ResetIdle(); return(e); }
public Report(Event e, EventValues idt, string title, string screenShot) { // todo: dynamic OS TimeStamp = DateTime.Now.ToString(CultureInfo.InvariantCulture); Id = idt.entryId ?? ""; OS = "Windows"; Process = e.process ?? ""; Url = e.url ?? ""; Title = title ?? ""; Duration = $"{idt.ts.Hours:00}:{idt.ts.Minutes:00}:{idt.ts.Seconds:00}"; Idle = $"{idt.idle.Hours:00}:{idt.idle.Minutes:00}:{idt.idle.Seconds:00}"; Active = $"{idt.active.Hours:00}:{idt.active.Minutes:00}:{idt.active.Seconds:00}"; ScreenShot = screenShot ?? ""; }
public Report(Event e, EventValues idt, string title, ScreenshotStruct screenshotStruct) { // todo: dynamic OS TimeStamp = DateTime.Now.ToString(CultureInfo.InvariantCulture); Id = idt.entryId ?? ""; UserName = Environment.UserName; MacAddress = ( from nic in NetworkInterface.GetAllNetworkInterfaces() where nic.OperationalStatus == OperationalStatus.Up select nic.GetPhysicalAddress().ToString() ).FirstOrDefault(); IPHostName = Dns.GetHostName(); // get all ip addresses IPAddress[] addresses = Dns.GetHostAddresses(IPHostName); ArrayList addressStrings = new ArrayList(); foreach (IPAddress ip in addresses) { addressStrings.Add(ip.ToString()); } var ocrResult = Task <string> .Run(() => OcrEngine.asyncReadFromImage(screenshotStruct.ScreenshotFilePath)); var base64Screenshot = Task <string> .Run(() => ScreenshotBase64Generator.JpegToBase64(screenshotStruct.ScreenshotFilePath)); screenshotStruct.ScreenshotBase64String = base64Screenshot.Result; OS = "Windows"; Process = e.process ?? ""; IPAddress = JsonConvert.SerializeObject(addressStrings); Url = e.url ?? ""; Title = title ?? ""; Duration = $"{idt.ts.Hours:00}:{idt.ts.Minutes:00}:{idt.ts.Seconds:00}"; Idle = $"{idt.idle.Hours:00}:{idt.idle.Minutes:00}:{idt.idle.Seconds:00}"; Active = $"{idt.active.Hours:00}:{idt.active.Minutes:00}:{idt.active.Seconds:00}"; ScreenShotFileName = screenshotStruct.ScreenshotFileName ?? ""; ScreenShotBase64String = screenshotStruct.ScreenshotBase64String ?? ""; ScreenShotOcrResult = ocrResult.Result ?? ""; }
//associate event to task ID and names for 'dictionaryEvent public List <dynamic> AssociateForDictionaryEvents() { var e = new Event(); var idt = new EventValues(); var associatedSet = new List <dynamic>(); e.winTitle = _prevTitle; e.process = _prevPs; e.url = _prevUrl; if (!Global.Filter(e)) { return(null); } idt.ts = _ts; idt.entryId = ""; UpdateInvoke(label28, delegate() { label28.Text = _idleSeconds.ToString(CultureInfo.InvariantCulture); }); _idleFreeze = Math.Floor(_idleSeconds); if (_idleFreeze > 0) { UpdateInvoke(label19, delegate() { label19.Text = _prevPs; }); UpdateInvoke(label20, delegate() { label20.Text = idt.ts.TotalSeconds.ToString(CultureInfo.InvariantCulture); }); UpdateInvoke(label21, delegate() { label21.Text = _idleFreeze.ToString(CultureInfo.InvariantCulture); }); if ((idt.ts.TotalSeconds - _idleFreeze) < 0) //error, when idle time is more than duration { ProcessInfo.GetAll(out _, out var ps, out _); UpdateInvoke(label24, delegate() { label24.Text = ps; }); _k++; UpdateInvoke(label29, delegate() { label29.Text = "Idle error occured# " + _k; }); idt.idle = TimeSpan.FromSeconds(0.0); } else { idt.idle = TimeSpan.FromSeconds(_idleFreeze); } } idt.active = idt.ts - idt.idle; idt.activeDelta = idt.active; //activeDelta is same as active from the very beginning, since it starts from zero //associate task by URL or process name based on if URL is empty try { if (e.url.Equals("")) //empty, it's a non-chrome event { idt.taskId = Global.associations[_prevPs].id; idt.taskName = Global.associations[_prevPs].name; } else //not empty, it's a chrome event { idt.taskId = Global.associations[_prevUrl].id; idt.taskName = Global.associations[_prevUrl].name; } } catch //non associated events will be marked as undefined { idt.taskId = ""; idt.taskName = "*No association*"; } associatedSet.Add(e); associatedSet.Add(idt); return(associatedSet); }