private async Task ReportIdentityEvent() { LiteMetricaCore liteMetricaCore = this; if (!liteMetricaCore.IsActivated) { return; } bool flag; lock (liteMetricaCore.ActiveSessionLock) { if (liteMetricaCore.ActiveSession == null || liteMetricaCore.ActiveSession.EventCounter == 0UL) { return; } flag = DateTime.UtcNow - Config.Global.IdentityTimestamp >= Config.Global.IdentitySendInterval; if (flag) { Config.Global.IdentityTimestamp = DateTime.UtcNow; } } if (!flag) { return; } await ServiceData.WaitExposeAsync(); byte[] bytes = Encoding.UTF8.GetBytes(ServiceData.DeviceFingerprint); liteMetricaCore.Report(EventFactory.Create(ReportMessage.Session.Event.EventType.EVENT_IDENTITY, bytes, (string)null, (string)null)); liteMetricaCore.TriggerForcedSend(); }
private bool?FlushCompletedSessions(SessionModel sourceSession) { lock (this.CompletedSessions) { if (sourceSession.events.Count > 0) { this.CompletedSessions.Add(sourceSession); } this.CompletedSessions.Where <SessionModel>((Func <SessionModel, bool>)(s => s.ReportParameters == null)).ForEach <SessionModel>((Action <SessionModel>)(async s => { SessionModel sessionModel = s; Dictionary <string, object> reportParameters = await ServiceData.GetReportParameters(); sessionModel.ReportParameters = "".GlueGetList(reportParameters, true); sessionModel = (SessionModel)null; })); List <SessionModel> list = this.CompletedSessions.Where <SessionModel>((Func <SessionModel, bool>)(s => !s.AsyncLocationLock)).ToList <SessionModel>(); this.ReportPackages.AddRange((IEnumerable <ReportPackage>)list.ToReportPackages()); list.ForEach((Action <SessionModel>)(s => this.CompletedSessions.Remove(s))); if (this.ReportPackages.Count == 0) { return(new bool?(false)); } foreach (ReportPackage package in this.ReportPackages.ToArray()) { if (!Config.Global.OfflineMode && LiteMetricaCore.TryPostOrIgnore(package)) { this.ReportPackages.Remove(package); package.Fade(); } } this.RemoveOverflowedPackages(this.ReportPackages); this.ReportPackages.Where <ReportPackage>((Func <ReportPackage, bool>)(p => !p.Exists())).ForEach <ReportPackage>((Action <ReportPackage>)(p => p.Keep())); return(new bool?(this.ReportPackages.Count == 0)); } }
private static bool TryPostOrIgnore(ReportPackage package) { try { if (package.Length <= 0L) { throw new Exception("Empty package"); } HttpResponseMessage result = package.PostAsync().Result; return(result != null && (result.IsSuccessStatusCode || !LiteMetricaCore.IsValidRequestByStatusCode(result.StatusCode))); } catch (Exception) { return(true); } }
public virtual async void Expose() { this.ActiveSessionLock = new object(); this.PauseLock = new object(); this.ActiveSession = this.ActiveSession ?? LiteMetricaCore.CreateSession(); this.ReportPackages = this.ReportPackages ?? new List <ReportPackage>(); this.CompletedSessions = this.CompletedSessions ?? new List <SessionModel>(); SessionModel sessionModel = this.ActiveSession; string str = this.ActiveSession.ReportParameters; if (str == null) { str = "".GlueGetList(await ServiceData.GetReportParameters(), true); } sessionModel.ReportParameters = str; #pragma warning disable IDE0059 // Ненужное присваивание значения sessionModel = (SessionModel)null; #pragma warning restore IDE0059 // Ненужное присваивание значения this.IsPaused = true; }
private SessionModel StartSession(bool isFirstSession = false) { SessionModel activeSession; lock (this.ActiveSessionLock) { this.EnsureActiveSessionFinished(); if (this.ActiveSession != null && this.ActiveSession.EventCounter > 0UL) { lock (this.CompletedSessions) this.CompletedSessions.Add(this.ActiveSession); } this.ActiveSession = LiteMetricaCore.CreateSession(); ReportMessage.Session.Event[] eventArray; if (!isFirstSession) { eventArray = new ReportMessage.Session.Event[1] { EventFactory.Create(ReportMessage.Session.Event.EventType.EVENT_START, (byte[])null, (string)null, (string)null) } } ; else { eventArray = new ReportMessage.Session.Event[3] { EventFactory.Create(ReportMessage.Session.Event.EventType.EVENT_FIRST, (byte[])null, (string)null, (string)null), EventFactory.Create(ReportMessage.Session.Event.EventType.EVENT_START, (byte[])null, (string)null, (string)null), EventFactory.Create(Config.Global.HandleFirstActivationAsUpdate ? ReportMessage.Session.Event.EventType.EVENT_UPDATE : ReportMessage.Session.Event.EventType.EVENT_INIT, (byte[])null, (string)null, (string)null) } }; this.Report(eventArray); Config.Global.LastWakeTime = new DateTime?(DateTime.UtcNow); activeSession = this.ActiveSession; } this.TriggerForcedSend(); return(activeSession); }