Example #1
0
        /// <summary>
        /// Retrieves all stored data as XML text.
        /// </summary>
        /// <exception cref="IncompatibleDatabaseException">The database version is not compatible with this
        /// version of the AnalyticsSessionWriter.</exception>
        public string GetTextForStoredData()
        {
            lock (lockObj) {
                if (session != null)
                {
                    session.Flush();
                }
            }
            UsageDataUploader uploader = new UsageDataUploader(dbFileName, ProductName);

            return(uploader.GetTextForStoredData());
        }
Example #2
0
        /// <summary>
        /// Opens the database connection, updates the database if required.
        /// Will start an upload to the server, if required.
        /// </summary>
        public void OpenSession()
        {
            IEnumerable <UsageDataEnvironmentProperty> appEnvironmentProperties = GetAppProperties();
            bool sessionOpened = false;

            lock (lockObj) {
                if (session == null)
                {
                    try {
                        session = new UsageDataSessionWriter(dbFileName, FindUserId);
                    } catch (IncompatibleDatabaseException ex) {
                        if (ex.ActualVersion < ex.ExpectedVersion)
                        {
                            LoggingService.Info("AnalyticsMonitor: " + ex.Message + ", removing old database");
                            Guid?oldUserId = UsageDataSessionWriter.RetrieveUserId(dbFileName);
                            // upgrade database by deleting the old one
                            TryDeleteDatabase();
                            try {
                                session = new UsageDataSessionWriter(dbFileName, () => (oldUserId ?? FindUserId()));
                            } catch (IncompatibleDatabaseException ex2) {
                                LoggingService.Warn("AnalyticsMonitor: Could not upgrade database: " + ex2.Message);
                            }
                        }
                        else
                        {
                            LoggingService.Warn("AnalyticsMonitor: " + ex.Message);
                        }
                    }

                    if (session != null)
                    {
                        session.OnException = MessageService.ShowException;
                        session.AddEnvironmentData(appEnvironmentProperties);

                        sessionOpened = true;
                    }
                }
            }
            if (sessionOpened)
            {
                UsageDataUploader uploader = new UsageDataUploader(dbFileName, ProductName);
                uploader.EnvironmentDataForDummySession = appEnvironmentProperties;
                ThreadPool.QueueUserWorkItem(delegate { uploader.StartUpload(UploadUrl); });
            }
        }
        /// <summary>
        /// Opens the database connection, updates the database if required.
        /// Will start an upload to the server, if required.
        /// </summary>
        public void OpenSession()
        {
            IEnumerable<UsageDataEnvironmentProperty> appEnvironmentProperties = GetAppProperties();
            bool sessionOpened = false;
            lock (lockObj) {
                if (session == null) {
                    try {
                        session = new UsageDataSessionWriter(dbFileName, FindUserId);
                    } catch (IncompatibleDatabaseException ex) {
                        if (ex.ActualVersion < ex.ExpectedVersion) {
                            LoggingService.Info("AnalyticsMonitor: " + ex.Message + ", removing old database");
                            Guid? oldUserId = UsageDataSessionWriter.RetrieveUserId(dbFileName);
                            // upgrade database by deleting the old one
                            TryDeleteDatabase();
                            try {
                                session = new UsageDataSessionWriter(dbFileName, () => (oldUserId ?? FindUserId()));
                            } catch (IncompatibleDatabaseException ex2) {
                                LoggingService.Warn("AnalyticsMonitor: Could not upgrade database: " + ex2.Message);
                            }
                        } else {
                            LoggingService.Warn("AnalyticsMonitor: " + ex.Message);
                        }
                    }

                    if (session != null) {
                        session.OnException = ex => MessageService.ShowException(ex);
                        session.AddEnvironmentData(appEnvironmentProperties);

                        sessionOpened = true;
                    }
                }
            }
            if (sessionOpened) {
                UsageDataUploader uploader = new UsageDataUploader(dbFileName, ProductName);
                uploader.EnvironmentDataForDummySession = appEnvironmentProperties;
                ThreadPool.QueueUserWorkItem(delegate { uploader.StartUpload(UploadUrl); });
            }
        }
 /// <summary>
 /// Retrieves all stored data as XML text.
 /// </summary>
 /// <exception cref="IncompatibleDatabaseException">The database version is not compatible with this
 /// version of the AnalyticsSessionWriter.</exception>
 public string GetTextForStoredData()
 {
     lock (lockObj) {
         if (session != null)
             session.Flush();
     }
     UsageDataUploader uploader = new UsageDataUploader(dbFileName, ProductName);
     return uploader.GetTextForStoredData();
 }