Exemplo n.º 1
0
 public void Validate()
 {
     if (DatabaseFilePath.IsNullOrWhiteSpace())
     {
         throw new ArgumentNullException("DatabaseFilePath");
     }
 }
Exemplo n.º 2
0
        private void SelectDBComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            selectedFile = SelectDBComboBox.SelectedItem as DatabaseFilePath;

            if (SelectDBComboBox.SelectedIndex < 0)
            {
                return;
            }

            var dbFilePath = (SelectDBComboBox.SelectedItem as DatabaseFilePath);

            YearTextBox.Text   = dbFilePath.Year;
            NumberTextBox.Text = dbFilePath.Number;

            //ParseSummonNumbers();
        }
Exemplo n.º 3
0
        private void Init()
        {
            string generalDBConnectionString = ConfigurationManager
                                               .ConnectionStrings["EntityContextGeneral"]
                                               .ConnectionString;

            string dbPair;
            string dbPath;

            try
            {
                dbPair = Regex.Match(generalDBConnectionString, @"(?:database=).+?(?=;)").Value;
                dbPath = dbPair.Split('=')[1];
            }
            catch (Exception ex)
            {
                MessageBox.Show(String.Format(
                                    "В строке подключения не найден путь к базе данных ('database=DatabaseAddressHere')\nТекст ошибки:\n{0}",
                                    ex.Message));
                return;
            }

            generalDBFile         = new DatabaseFilePath(dbPath);
            GeneralDBTextBox.Text = generalDBFile.FileName;

            var fs = Directory.GetFiles(generalDBFile.ExternalDirectory);

            newDBFiles = fs
                         .Reverse()
                         .Select(f => new DatabaseFilePath(f))
                         .ToList();

            string curYear = newDBFiles[0].Year;
            int    fCnt    = newDBFiles.Count();

            for (int i = 0; i < fCnt; i++)
            {
                if (newDBFiles[i].Year != curYear)
                {
                    var separator = new DatabaseFilePath()
                    {
                        Path = "-"
                    };
                    newDBFiles.Insert(i, separator);

                    i++;
                    curYear = newDBFiles[i].Year;
                    fCnt++;
                }
            }

            SelectDBComboBox.ItemsSource = newDBFiles;

            var defaultSeason = newDBFiles.First(f => f.Year.Equals(defaultYear) && f.Number.Equals(defaultNumber));

            if (defaultSeason != null)
            {
                SelectDBComboBox.SelectedItem = defaultSeason;
            }

            FillExistingSeasons();
        }
Exemplo n.º 4
0
        public static void Migrate()
        {
            try
            {
                                #if WINDOWS_PHONE
                FoodJournalDB db = new FoodJournalDB(false);
                                #else
                FoodJournalDB db = new FoodJournalDB(true);
                                #endif

                if (!db.DatabaseExists())
                {
                    return;
                }

                if (db.Table <FoodItemDO>().Count() == 0 && db.Table <EntryDO>().Count() == 0)
                {
#if !WINDOWS_PHONE
                    db.Close();
#endif
                    Logging.SessionLog.RecordMilestone("Deleting Legacy FoodItem DB", "");
                    db.DeleteDatabase();
                    return;
                }

                                #if !WINDOWS_PHONE
                if (System.IO.File.Exists(DatabaseFilePath))
                {
                    db.Close();
                    System.IO.File.Copy(DatabaseFilePath, DatabaseFilePath.Replace(".db3", ".bak"));
                    db = new FoodJournalDB(true);
                }
                                #endif

                DateTime start = DateTime.Now;

                int ExceptionCount            = 0;
                Dictionary <int, int> itemmap = new Dictionary <int, int>();

                Logging.SessionLog.RecordTraceValue("Database migration - item count", db.Table <FoodItemDO>().Count().ToString());
                Logging.SessionLog.RecordTraceValue("Database migration - selection count", db.Table <EntryDO>().Count().ToString());

                var AllItems      = db.Table <FoodItemDO>().ToList();
                var AllSelections = db.Table <EntryDO>().ToList();

                List <FoodItemDO> ToDeleteItems      = new List <FoodItemDO>();
                List <EntryDO>    ToDeleteSelections = new List <EntryDO>();

                Dictionary <int, String> items     = new Dictionary <int, string>();
                List <DateTime>          savedates = new List <DateTime>();

                foreach (FoodItemDO item in AllItems)
                {
                    try
                    {
                        items.Add(item.Id, item.TextDB);

                        var NewItem = new FoodJournal.Model.FoodItem(item.TextDB, false);

                        NewItem.Culture        = item.Culture;
                        NewItem.DescriptionDB  = item.DescriptionDB;
                        NewItem.LastAmountDB   = item.LastAmountDB;
                        NewItem.NutritionDB    = item.NutritionDB;
                        NewItem.ServingSizesDB = item.ServingSizesDB;
                        NewItem.SourceID       = item.SourceID;

                        Cache.MergeItem(NewItem);

                        ToDeleteItems.Add(item);
                    }
                    catch (Exception ex) { ExceptionCount++; LittleWatson.ReportException(ex); }
                }

                foreach (EntryDO entry in AllSelections)
                {
                    try
                    {
                        var entryDate = DateTime.Parse(entry.Date);

                        var NewSelection = new FoodJournal.Model.Entry(entryDate, entry.Period, items[entry.FoodItemId]);
                        NewSelection.AmountScaleDB    = entry.AmountScaleDB;
                        NewSelection.AmountSelectedDB = entry.AmountSelectedDB;

                        Cache.AddEntry(NewSelection);

                        ToDeleteSelections.Add(entry);

                        if (!savedates.Contains(entryDate))
                        {
                            savedates.Add(entryDate);
                        }
                    }
                    catch (Exception ex) { ExceptionCount++; LittleWatson.ReportException(ex); }
                }

                foreach (Period period in PeriodList.All)
                {
                    foreach (DateTime date in savedates)
                    {
                        FoodJournalNoSQL.StartSaveDay(date, period);
                    }
                }

                int i = 120;
                while (i-- > 0 && FoodJournalNoSQL.IsSaving())
                {
                    System.Threading.Thread.Sleep(500);
                }

                if (i == 0)
                {
                    SessionLog.RecordMilestone("Upgrade failed in 1 minute", AllSelections.Count.ToString());
                    throw new Exception("Upgrade failed in 1 minute");
                }

                foreach (EntryDO Selection in ToDeleteSelections)
                {
                    try
                    {
                                                #if WINDOWS_PHONE
                        db.Table <EntryDO>().DeleteOnSubmit(Selection);
                        db.SubmitChanges();
                                                #else
                        db.Delete <EntryDO>(Selection.Id);
                                                #endif
                    }
                    catch (Exception ex) { db = new FoodJournalDB(false); ExceptionCount++; LittleWatson.ReportException(ex); }
                }

                foreach (FoodItemDO Item in ToDeleteItems)
                {
                    try
                    {
                                                #if WINDOWS_PHONE
                        db.Table <FoodItemDO>().DeleteOnSubmit(Item);
                        db.SubmitChanges();
                                                #else
                        db.Delete <FoodItemDO>(Item.Id);
                                                #endif
                    }
                    catch (Exception ex) { db = new FoodJournalDB(false); ExceptionCount++; LittleWatson.ReportException(ex); }
                }

                Logging.SessionLog.RecordMilestone("Database migration - exception count", ExceptionCount.ToString());
                Logging.SessionLog.RecordMilestone("Database migration - duration", string.Format("{0} s", DateTime.Now.Subtract(start).TotalSeconds));
            }
            catch (Exception ex) { LittleWatson.ReportException(ex); }
        }