async Task CreateLog(string NFCtag, int Inout, int Lognum) //Set Lognum to 0 if entry { EntryLog Elog = new EntryLog(); newlog.ReferenceNFC = NFCtag; newlog.TimeLog = DateTime.Now; newlog.VesselName = currentvessel; newlog.UnitName = currentunit; AnalyticsLog Alog = new AnalyticsLog(); Alog.ReferenceNFC = NFCtag; Alog.InOut = Inout; Alog.TimeLog = DateTime.Now; Alog.VesselName = currentvessel; Alog.UnitName = currentunit; if (Inout == -1) { await App.Database.DeleteLog(Lognum); await App.Database.AddAnalyticsLog(Alog); } if (Inout == 1) { await App.Database.AddLog(newlog); await App.Database.AddAnalyticsLog(Alog); } }
static void Send(EventName eventName, object eventData) { if (!RegisterEvents()) { AnalyticsLog.Debug("Disabled: event='{0}', time='{1}', payload={2}", eventName, DateTime.Now, JsonUtility.ToJson(eventData)); return; } try { var result = Analytics.Analytics.SendEvent(eventName.ToString(), eventData); if (result == Analytics.AnalyticsResult.Ok) { AnalyticsLog.Debug("Event sent: event='{0}', time='{1}', payload={2}", eventName, DateTime.Now, JsonUtility.ToJson(eventData)); } else { AnalyticsLog.Debug("Failed to send event {0}. Result: {1}", eventName, result); } } catch (Exception ex) { AnalyticsLog.Debug("Failed to send event {0}. Result: {1}", eventName, ex); } }
public async Task <IActionResult> Edit(Guid id, [Bind("Id,Description,timeStamp")] AnalyticsLog analyticsLog) { if (id != analyticsLog.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(analyticsLog); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AnalyticsLogExists(analyticsLog.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(analyticsLog)); }
static async public Task <int> AddRecord(AnalyticsLog newdata) { string payload = JsonConvert.SerializeObject(newdata); int newID = await AddAPI("PostRecord", payload); return(newID); }
public async Task <IActionResult> Create([Bind("Id,Description,timeStamp")] AnalyticsLog analyticsLog) { if (ModelState.IsValid) { analyticsLog.Id = Guid.NewGuid(); _context.Add(analyticsLog); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(analyticsLog)); }
static bool RegisterEvent(string eventName) { var result = Analytics.Analytics.RegisterEvent(eventName, k_MaxEventsPerHour, k_MaxNumberOfElementsInStruct, k_VendorKey); switch (result) { case Analytics.AnalyticsResult.Ok: AnalyticsLog.Debug("Registered event: {0}", eventName); return(true); case Analytics.AnalyticsResult.TooManyRequests: // this is fine - event registration survives domain reload (native) return(true); default: AnalyticsLog.Debug("Failed to register event {0}. Result: {1}", eventName, result); return(false); } }
protected void ReloadData() { if (!AnalyticsHelper.DebugAnalytics) { this.lblInfo.Text = GetString("DebugAnalytics.NotConfigured"); } else { this.plcLogs.Controls.Clear(); for (int i = AnalyticsHelper.LastLogs.Count - 1; i >= 0; i--) { try { // Get the log RequestLog log = (RequestLog)AnalyticsHelper.LastLogs[i]; if (log != null) { // Load the table DataTable dt = log.LogTable; if (!DataHelper.DataSourceIsEmpty(dt)) { // Load the control AnalyticsLog logCtrl = (AnalyticsLog)LoadControl("~/CMSAdminControls/Debug/AnalyticsLog.ascx"); logCtrl.ID = "anLog_" + i; logCtrl.EnableViewState = false; logCtrl.Log = log; logCtrl.LogStyle = ""; logCtrl.ShowCompleteContext = this.chkCompleteContext.Checked; // Add to the output this.plcLogs.Controls.Add(new LiteralControl("<div>‎<strong> " + GetRequestLink(log.RequestURL, log.RequestGUID) + "</strong> (" + log.RequestTime.ToString("hh:mm:ss") + ")‎<br /><br />")); this.plcLogs.Controls.Add(logCtrl); this.plcLogs.Controls.Add(new LiteralControl("</div><br /><br />")); } } } catch { } } } }
async public Task <int> AddAnalyticsLog(AnalyticsLog analyticlog) { if (Globals.OfflineMode == false) { //Determine max ID already pulled from server var internalcount = _connection.Table <AnalyticsLog>().ToListAsync().Result; int maxID; if (internalcount.Count == 0) { maxID = 0; } else { maxID = internalcount.Select(c => c.EntryID).Max(); } //Add unit and retrieve assigned ID int newID = await APIServer.AddRecord(analyticlog); if (newID == maxID + 1) //New ID is provided by Db, no error handling similar to worker flags. { //Add worker to local database analyticlog.EntryID = newID; await _connection.InsertAsync(analyticlog); } if (newID > maxID + 1) //Missing entries added by another user { IEnumerable <EntryLog> tempE = await APIServer.GetAllEntryLogs(maxID.ToString()); await _connection.InsertAllAsync(tempE); } return(newID); } else { analyticlog.EntryID = -1; await _connection.InsertAsync(analyticlog); return(1); } }
//Refresh and Seed entire database async public Task RefreshDatabase() { Unit unit = new Unit(); Vessel vessel = new Vessel(); Worker worker = new Worker(); EntryLog newlog = new EntryLog(); AnalyticsLog Alog = new AnalyticsLog(); Random rnd = new Random(); //Add list of workers List <string> workerfirst = new List <string> { "Carl", "Sam", "Nisbit", "Johnny", "Earl", "Pete", "Douglas", "Cara", "Avril", "Betty-Sue", "Dougy", "Alex", "Tom", "Tara", "Indy", "Brad", "Stu", "Eddy", "Nero", "Carl", "Sam", "Nisbit", "Johnny", "Earl", "Pete", "Douglas", "Cara", "Avril", "Betty-Sue", "Dougy", "Alex", "Tom", "Tara", "Indy", "Brad", "Stu", "Eddy", "Nero" }; List <string> workerlast = new List <string> { "Johnson", "Black", "Trout", "Smith", "Rogers", "Jury", "Slick", "Salty", "Hardy", "Bolton", "Carter", "Silversmith", "Snake", "Black", "White", "Wattson", "Ericson", "Edge", "Winter", "Ruderson-Jergen", "Johnson", "Black", "Trout", "Smith", "Rogers", "Jury", "Slick", "Salty", "Hardy", "Bolton", "Carter", "Silversmith", "Snake", "Black", "White", "Wattson", "Ericson", "Edge" }; List <string> companyname = new List <string> { "IOL", "IOL", "IOL", "IOL", "CEDA", "CEDA", "TEAM", "TEAM", "TEAM", "TAMS", "TAMS", "TAMS", "TAMS", "Curren", "Curren", "Curren", "Safway", "Safway", "Safway", "IOL", "IOL", "IOL", "IOL", "CEDA", "CEDA", "TEAM", "TEAM", "TEAM", "TAMS", "TAMS", "TAMS", "TAMS", "Curren", "Curren", "Curren", "Safway", "Safway", "Safway" }; List <string> nfclist = new List <string> { "101", "102", "103", "104", "105", "106", "107", "108", "109", "110", "111", "112", "113", "114", "115", "116", "117", "118", "119", "120", "121", "122", "123", "124", "125", "126", "127", "128", "129", "130", "131", "132", "133", "134", "135", "136", "137", "138" }; string DB = "QQQ"; for (int i = 0; i <= workerfirst.Count - 1; i++) { worker.FirstName = workerfirst[i]; worker.LastName = workerlast[i]; worker.Company = companyname[i]; worker.CreatedTime = DateTime.Now; worker.Activated = 1; Globals.NFCtempcount++; worker.ReferenceNFC = DB + "_" + nfclist[i]; await AddWorker(worker); } string[] unitname = new string[] { "Office Building", "Plant 1", "Construction Site" }; foreach (string t in unitname) { //Add Unit from unitname list unit.Name = t; await App.Database.AddUnit(unit); //Add a random vessel tag for each unit (x3-6) int VperU = rnd.Next(3, 7); for (int i = 1; i <= VperU; i++) { int VorT = (int)rnd.Next(1, 3); string Vtype; if (VorT == 1) { Vtype = "Entrance"; } else { Vtype = "Checkpoint"; } int Vnum = rnd.Next(100, 400); vessel.Name = Vtype + "-" + Vnum; vessel.Unitname = t; await AddVessel(vessel); //50% Chance for active entry to be present on added vessel int status = rnd.Next(0, 2); if (status == 1) { int Logs = 6; int EntriesV = rnd.Next(0, Logs + 1); //Random number of entries per vessel //Create worker name temp lists to allow temporary removal as 'workers enter vessels' List <string> Ctemp = new List <string>(); Ctemp.AddRange(companyname); List <string> Ftemp = new List <string>(); Ftemp.AddRange(workerfirst); List <string> Ltemp = new List <string>(); Ltemp.AddRange(workerlast); List <string> Ntemp = new List <string>(); Ntemp.AddRange(nfclist); for (int k = 0; k < EntriesV; k++) { //Randomize worker selection and datetime stamp int W = rnd.Next(0, workerfirst.Count - k); int timestamp = rnd.Next(1, 10); /* //Create workerID Redundent due to NFC tie to worker * newlog.WorkerID = W+1; * newlog.Company = Ctemp[W]; * newlog.FirstName = Ftemp[W]; * newlog.LastName = Ltemp[W];*/ newlog.ReferenceNFC = DB + "_" + Ntemp[W]; newlog.TimeLog = DateTime.Now.AddHours(-timestamp); newlog.VesselName = vessel.Name; newlog.UnitName = vessel.Unitname; await AddLog(newlog); //Create analytics log (z days of data) for (int z = 1; z < 4; z++) { //adding time randomizers int xhour = rnd.Next(1, 8); int xhour2 = rnd.Next(1, 8); int xmin = rnd.Next(0, 59); int xmin2 = rnd.Next(0, 59); DateTime xtime = new DateTime(); //Create entry log Alog.ReferenceNFC = DB + "_" + Ntemp[W]; Alog.InOut = 1; xtime = DateTime.Now.AddHours(-(24 * z + xhour)); xtime = xtime.AddMinutes(-xmin); Alog.TimeLog = xtime; Alog.VesselName = vessel.Name; Alog.UnitName = vessel.Unitname; await APIServer.AddRecord(Alog); //create exit log Alog.ReferenceNFC = DB + "_" + Ntemp[W]; Alog.InOut = -1; xtime = DateTime.Now.AddHours(-(24 * z - xhour2)); xtime = xtime.AddMinutes(+xmin2); Alog.TimeLog = xtime; Alog.VesselName = vessel.Name; Alog.UnitName = vessel.Unitname; await APIServer.AddRecord(Alog); } // matching most recent entry of Entrylog Alog.ReferenceNFC = DB + "_" + Ntemp[W]; Alog.InOut = 1; Alog.TimeLog = DateTime.Now.AddHours(-timestamp); Alog.VesselName = vessel.Name; Alog.UnitName = vessel.Unitname; await APIServer.AddRecord(Alog); //Removing worker from list to avoid duplication Ctemp.RemoveAt(W); Ftemp.RemoveAt(W); Ltemp.RemoveAt(W); Ntemp.RemoveAt(W); } //Populate analytics list with database IEnumerable <AnalyticsLog> tempA = await APIServer.GetAllAnalyticsLogs("0"); _connection.DropTableAsync <AnalyticsLog>().Wait(); _connection.CreateTableAsync <AnalyticsLog>().Wait(); await _connection.InsertAllAsync(tempA); } } } return;// Task.CompletedTask; }