/// <summary> /// Inits this instance. /// </summary> private void init(Guid applicationId, UploadType uploadType, string applicationVersion) { this.applicationId = applicationId; this.applicationVersion = applicationVersion; this.sessionId = Guid.NewGuid(); this.iStorageDal = new StorageSql(connectonString); this.iUploadDal = new UploadWS(baseUrl); this.iDeviceInformation = new DeviceInformation(); this.iDeviceDynamicInformation = new DeviceDynamicInformation(); this.iPlatform = new Platform(); try { this.initDatabase(); this.databaseExists = true; } catch (ExceptionDatabaseLayer) { } if (this.databaseExists) { AppactsPlugin.Data.Model.ApplicationMeta applicationMeta = null; bool applicationInitialSetup = false; try { applicationMeta = this.iStorageDal.GetApplication(this.applicationId); if (applicationMeta == null) { applicationMeta = new ApplicationMeta(this.applicationId, ApplicationStateType.Close, DateTime.Now, OptStatusType.OptIn); this.iStorageDal.Save(applicationMeta); applicationInitialSetup = true; } } catch (ExceptionDatabaseLayer ex) { this.logSystemError(ex); } try { this.optStatusType = applicationMeta.OptStatus; if (applicationMeta.State == ApplicationStateType.Open) { this.iStorageDal.Save(new Crash(this.applicationId, applicationMeta.SessionId, this.applicationVersion)); } this.iStorageDal.Save(new EventItem(this.applicationId, null, null, EventType.ApplicationOpen, 0, this.sessionId, this.applicationVersion)); applicationMeta.SessionId = this.sessionId; applicationMeta.State = ApplicationStateType.Open; if (applicationMeta.Version == null || applicationMeta.Version != this.applicationVersion) { applicationMeta.Version = this.applicationVersion; applicationMeta.Upgraded = !applicationInitialSetup; } this.iStorageDal.Update(applicationMeta); //#if DEBUG // throw new ExceptionDatabaseLayer(new Exception("Random test")); //#endif } catch (ExceptionDatabaseLayer exceptionDatabaseLayer) { this.logSystemError(exceptionDatabaseLayer); } } this.session = new Session(); }
/// <summary> /// Screens the open. /// </summary> /// <param name="screenName">Name of the screen.</param> public void ScreenOpen(string screenName) { if(this.started && this.databaseExists && this.optStatusType == OptStatusType.OptIn) { try { Session session = new Session(screenName); lock(this.sessionsScreenOpen) { if (!this.sessionsScreenOpen.Contains(session)) { this.sessionsScreenOpen.Add(session); EventItem eventItem = new EventItem(this.applicationId, screenName, null, EventType.ScreenOpen, 0, this.sessionId, this.applicationVersion); this.iStorageDal.Save(eventItem); this.setItemsWaitingToBeUploaded(); if(this.uploadType == UploadType.WhileUsingAsync) { this.uploadIntelligent(); } } } } catch(ExceptionDatabaseLayer ex) { this.logSystemError(ex); } } }