コード例 #1
0
 public void SaveAll()
 {
     lock (saveQueue)
     {
         using (LogEventDataContext logDBContext = new LogEventDataContext(MainPage.ConnectionString))
         {
             logDBContext.addEvents(saveQueue.ToList().AsReadOnly());
             saveQueue = new Queue<LogEvent>();
         }
     }
 }
コード例 #2
0
 private void deleteFromDB(LogEvent logevent)
 {
     using (LogEventDataContext logDb = new LogEventDataContext(LogEventDataContext.ConnectionString))
     {
         if (!logDb.DatabaseExists())
         {
             System.Diagnostics.Debug.WriteLine(this.GetType().Name + ": DB does not exist");
             return;
         }
         logDb.DeleteLogEvent(logevent.EventId);
     }
 }
コード例 #3
0
        private void SendMessages()
        {
            System.Diagnostics.Debug.WriteLine(this.GetType().Name +  ".SendMessages");

            using (LogEventDataContext logDb = new LogEventDataContext(LogEventDataContext.ConnectionString))
            {
                if (!logDb.DatabaseExists())
                {
                    System.Diagnostics.Debug.WriteLine(this.GetType().Name + ": DB does not exist");
                    return;
                }
                List<LogEvent> events = logDb.GetLogEvents();
                foreach (LogEvent e in events)
                {
                    SendMessage(e);
                }
            }
            System.Diagnostics.Debug.WriteLine(this.GetType().Name + ".AsyncSendMessages event handler finished");
        }
コード例 #4
0
ファイル: LogDatabase.cs プロジェクト: WinToosa/mobilelogger
 public List<LogEvent> GetLogEvents()
 {
     List<LogEvent> logEventList = null;
     using (LogEventDataContext context = new LogEventDataContext(ConnectionString))
     {
         IQueryable<LogEvent> query =
             from le in context.LogEvents
             select le;
         try
         {
             logEventList = query.ToList();
         }
         catch (Exception e)
         {
             System.Diagnostics.Debug.WriteLine("At LogDatabase: " + e.Message);
         }
     }
     return logEventList;
 }
コード例 #5
0
ファイル: LogDatabase.cs プロジェクト: WinToosa/mobilelogger
        public void DeleteLogEvent(int id)
        {
            //LogEventDataContext context;
            using (LogEventDataContext context = new LogEventDataContext(ConnectionString))
            {
                IQueryable<LogEvent> query =
                            from le in context.LogEvents
                            where le.EventId == id
                            select le;

                LogEvent leToDelete = query.FirstOrDefault();

                //context.LogEvents.Attach(leToDelete);
                context.LogEvents.DeleteOnSubmit(leToDelete);
                context.SubmitChanges();
            }
        }
コード例 #6
0
ファイル: LogDatabase.cs プロジェクト: WinToosa/mobilelogger
        public void addEvents(IList<LogEvent> events)
        {
            using (LogEventDataContext context = new LogEventDataContext(ConnectionString))
            {
                foreach (LogEvent e in events)
                {
                    LogEvent le = new LogEvent();
                    e.Time = DeviceTools.GetUnixTime(DateTime.Now);

                    // add the new logEvent to the context
                    context.LogEvents.InsertOnSubmit(e);
                }

                context.SubmitChanges();
            }
        }
コード例 #7
0
ファイル: LogDatabase.cs プロジェクト: WinToosa/mobilelogger
        public void addEvent(JObject sensorEvent, String url)
        {
            using (LogEventDataContext context = new LogEventDataContext(ConnectionString))
            {
                // create a new LogEvent instance
                LogEvent le = new LogEvent();
                le.sensorEvent = sensorEvent.ToString();
                le.Time = DeviceTools.GetUnixTime(DateTime.Now);
                le.relativeUrl = url;

                // add the new logEvent to the context
                context.LogEvents.InsertOnSubmit(le);
                try
                {
                    // save changes to the database
                    context.SubmitChanges();
                }
                catch (System.SystemException e)
                {
                    System.Diagnostics.Debug.WriteLine("SQLException" + e);
                }
            }
        }
コード例 #8
0
        /// <summary>
        /// Creates and adds a few ItemViewModel objects into the Items collection.
        /// </summary>
        public void GetLogData()
        {
            const string ConnectionString = @"Data Source = 'isostore:/LogEventDB.sdf';";

            using (LogEventDataContext logDBContext = new LogEventDataContext(ConnectionString))
            {
                if (!logDBContext.DatabaseExists())
                {
                    // create database if it does not exist
                    try
                    {
                        logDBContext.CreateDatabase();
                    }
                    catch (InvalidOperationException ioe)
                    {
                        System.Diagnostics.Debug.WriteLine("InvalidOperationException while creating database..." + ioe);
                    }
                }
                GetLogEvents(logDBContext);
            }
        }
コード例 #9
0
        private void GetLogEvents(LogEventDataContext logDBContext)
        {
            List<LogEvent> list = logDBContext.GetLogEvents();

            if (list != null)
            {
                LogData.Clear();
                int listCount = list.Count;

                for (int i = listCount - 1; i >= 0; i--)
                {
                    LogEvent e = list[i];
                    LogData.Add(new LogData()
                    {
                        LogDataHeading = DeviceTools.GetDateTime(e.Time).ToString(),
                        LogDataContent = e.sensorEvent.ToString()
                    });
                }
            }
        }