/// <summary> /// Events the specified device id. /// </summary> /// <param name="deviceId">The device id.</param> /// <param name="eventItem">The event item.</param> /// <returns></returns> public WebServiceResponseCodeType Event(Guid deviceId, EventItem eventItem) { KeyValuePair<string, string>[] keyValuePairs = new KeyValuePair<string, string>[] { new KeyValuePair<string, string>(QueryStringKeyType.DEVICE_GUID, deviceId.ToString()), new KeyValuePair<string, string>(QueryStringKeyType.APPLICATION_GUID, eventItem.ApplicationId.ToString()), new KeyValuePair<string, string>(QueryStringKeyType.DATE_CREATED, eventItem.DateCreatedFormatted), new KeyValuePair<string, string>(QueryStringKeyType.DATA, eventItem.Data), new KeyValuePair<string, string>(QueryStringKeyType.EVENT_TYPE, ((int)eventItem.EventType).ToString()), new KeyValuePair<string, string>(QueryStringKeyType.EVENT_NAME, eventItem.EventName), new KeyValuePair<string, string>(QueryStringKeyType.LENGTH, eventItem.Length.ToString()), new KeyValuePair<string, string>(QueryStringKeyType.SCREEN_NAME, eventItem.ScreenName), new KeyValuePair<string, string>(QueryStringKeyType.SESSION_ID, eventItem.SessionId.ToString()), new KeyValuePair<string, string>(QueryStringKeyType.VERSION, eventItem.Version) }; return this.webServiceCall(this.baseUrl, WebServiceType.Event, keyValuePairs); }
/// <summary> /// Contents the loaded. /// </summary> /// <param name="screenName">Name of the screen.</param> /// <param name="contentName">Name of the content.</param> public void ContentLoaded(String screenName, string contentName) { if(this.started && this.databaseExists && this.optStatusType == OptStatusType.OptIn) { try { long miliSeconds = 0; int index = -1; lock(this.sessionsContentLoading) { string sessionName = string.Concat(screenName, contentName); for (int i = 0; i < this.sessionsContentLoading.Count; i++) { Session session = (Session)this.sessionsContentLoading[i]; if (session.Name == sessionName) { index = i; miliSeconds = session.End(); break; } } if(index != -1) { this.sessionsContentLoading.RemoveAt(index); EventItem eventItem = new EventItem(this.applicationId, screenName, null, EventType.ContentLoaded, contentName, miliSeconds, this.sessionId, this.applicationVersion); this.iStorageDal.Save(eventItem); this.setItemsWaitingToBeUploaded(); if(this.uploadType == UploadType.WhileUsingAsync) { this.uploadIntelligent(); } } } } catch(ExceptionDatabaseLayer ex) { this.logSystemError(ex); } } }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> public void Stop() { if (this.started) { try { this.threadUploadInterrupted = true; NetworkChange.NetworkAddressChanged -= this.networkChanged; this.iUploadDal.Dispose(); this.iDeviceDynamicInformation.Dispose(); } catch (Exception) { } if (this.databaseExists) { try { EventItem eventItem = new EventItem(this.applicationId, null, null, EventType.ApplicationClose, null, this.session.End(), this.sessionId, this.applicationVersion); this.iStorageDal.Save(eventItem); AppactsPlugin.Data.Model.ApplicationMeta application = this.iStorageDal.GetApplication(this.applicationId); application.State = ApplicationStateType.Close; this.iStorageDal.Update(application); } catch (ExceptionDatabaseLayer ex) { this.logSystemError(ex); } try { lock (this.threadIsUploadingLock) { if (this.threadIsUploading) { while (this.threadIsUploading) { Monitor.Wait(this.threadIsUploadingLock); } } } } catch (Exception) { } finally { System.Diagnostics.Debug.WriteLine("analytics stop"); this.iStorageDal.Dispose(); } } this.stopped = true; this.started = false; } }
/// <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); } } }
/// <summary> /// Logs the event. /// </summary> /// <param name="screenName">Name of the screen.</param> /// <param name="eventName">Name of the event.</param> /// <param name="data">The data.</param> public void LogEvent(string screenName, string eventName, string data) { if (this.started && this.databaseExists && this.optStatusType == OptStatusType.OptIn) { try { EventItem eventItem = new EventItem(this.applicationId, screenName, data, EventType.Event, eventName, 0, this.sessionId, this.applicationVersion); this.iStorageDal.Save(eventItem); this.setItemsWaitingToBeUploaded(); if (this.uploadType == UploadType.WhileUsingAsync) { this.uploadIntelligent(); } } catch (ExceptionDatabaseLayer ex) { this.logSystemError(ex); } } }
/// <summary> /// Saves the specified event item. /// </summary> /// <param name="eventItem">The event item.</param> public void Save(EventItem eventItem) { try { threadQueue.WaitOne(); this.EventItem.InsertOnSubmit(eventItem); this.SubmitChanges(); } catch (Exception ex) { throw new ExceptionDatabaseLayer(ex); } finally { threadQueue.Set(); } }