Exemple #1
0
 private static void writePersonTableCount(List <TableCount> data)
 {
     try
     {
         DatabaseContext.Entry(data[0]).State = EntityState.Modified;
         DatabaseContext.SaveChanges();
     }
     catch (Exception Ex)
     {
         LogWriterExtended.ExceptionDisplay("Error writing to database. What did you do?", Ex, true);
     }
 }
Exemple #2
0
        // Verifies the count data.
        public static void ValidateCount()
        {
            List <TableCount> data = readTableCountTable();

            if (data == null)
            {
                // Nothing we can do as the database is likely jacked up.
                return;
            }

            try
            {
                int hardCount = DatabaseContext.PersonData.Count();
                if (data.Count < 1)
                {
                    data.Add(new TableCount()
                    {
                        PersonCount = hardCount
                    });
                    writePersonTableCount(data);
                    return;
                }

                if (data[0] == null)
                {
                    data[0] = new TableCount()
                    {
                        PersonCount = hardCount
                    };
                    writePersonTableCount(data);
                    return;
                }

                if (readPersonTableCount(data) != hardCount)
                {
                    data[0].PersonCount = hardCount;
                    writePersonTableCount(data);
                    return;
                }
            }
            catch (Exception Ex)
            {
                LogWriterExtended.ExceptionDisplay("Error running count update.", Ex, true);
            }
        }
Exemple #3
0
        private static int readPersonTableCount(List <TableCount> data)
        {
            if (data.Count < 1 || data[0] == null)
            {
                ValidateCount();
            }

            try
            {
                int tableCount = (int)data[0].PersonCount;
                return(tableCount);
            }
            catch (Exception Ex)
            {
                LogWriterExtended.ExceptionDisplay("Error reading count data from list record.", Ex, true);
                return(-1);
            }
        }
Exemple #4
0
        // Saves a connection to the static DatabaseContext object.
        public static bool Initialize(string path)
        {
            if (System.IO.File.Exists(path) == false)
            {
                return(false);
            }

            // The database is being reinitialized.
            if (DatabaseContext != null)
            {
                DatabaseContext.Dispose();
            }

            int timeout;

            if (int.TryParse(Config.Read("database_timeout"), out timeout) == false)
            {
                timeout = 60;
            }

            SQLiteConnection connection = connect(path, timeout);

            if (connection == null)
            {
                return(false);
            }

            try
            {
                DatabaseContext = new Context(connection, timeout);
                ValidateCount();
                return(true);
            }
            catch (Exception Ex)
            {
                LogWriterExtended.ExceptionDisplay("Error making SQLite connection.", Ex, true);
                return(false);
            }
        }
Exemple #5
0
        private static List <TableCount> readTableCountTable()
        {
            try
            {
                List <TableCount> tableCountList =
                    (from tableCountData in DatabaseContext.TableCount
                     select tableCountData).ToList();

                if (tableCountList == null)
                {
                    LogWriter.LogEntry("Null data for TableCount of PersonData. This should not happen and your database is probably all sorts of jacked up.");
                    return(null);
                }

                return(tableCountList);
            }
            catch (Exception Ex)
            {
                LogWriterExtended.ExceptionDisplay("Error get count list data.", Ex, true);
                return(null);
            }
        }