Ejemplo n.º 1
0
 public void RecreateDB()
 {
     Startup.InitDB(config, null, false);
     DB.CreateTables();
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Import dictionary data including version history.
        /// Only used to initialize from scratch.
        /// </summary>
        public void ImportDict(string dictPath, string workingFolder)
        {
            Startup.InitDB(config, null, false);
            SqlDict             dict = new SqlDict(null, mut);
            List <EntryVersion> vers = new List <EntryVersion>();

            using (FileStream fs = new FileStream(dictPath, FileMode.Open, FileAccess.Read))
                using (StreamReader sr = new StreamReader(fs))
                {
                    EntryBlockParser ebp = new EntryBlockParser(sr);
                    // Two passes. In the first we collect user names and bulk changes.
                    var users = new HashSet <string>();
                    var bulks = new Dictionary <int, SqlDict.ImportBuilder.BulkChangeInfo>();
                    while (true)
                    {
                        vers.Clear();
                        int id = ebp.ReadBlock(vers);
                        if (id == -1)
                        {
                            break;
                        }
                        for (int i = 0; i != vers.Count; ++i)
                        {
                            var ver = vers[i];
                            users.Add(ver.User);
                            // First change referencing this bulk
                            if (ver.BulkRef != -1 && !bulks.ContainsKey(ver.BulkRef))
                            {
                                SqlDict.ImportBuilder.BulkChangeInfo bci = new SqlDict.ImportBuilder.BulkChangeInfo
                                {
                                    Timestamp      = ver.Timestamp,
                                    UserName       = ver.User,
                                    Comment        = ver.Comment,
                                    NewEntries     = i == 0 ? 1 : 0,
                                    ChangedEntries = i != 0 ? 1 : 0,
                                };
                                bulks[ver.BulkRef] = bci;
                            }
                            // Bulk, and seen before
                            else if (ver.BulkRef != -1)
                            {
                                if (i == 0)
                                {
                                    ++bulks[ver.BulkRef].NewEntries;
                                }
                                else
                                {
                                    ++bulks[ver.BulkRef].ChangedEntries;
                                }
                            }
                        }
                    }
                    // Enrich known built-in user names with "about"
                    HashSet <string> richUsers = new HashSet <string>();
                    foreach (string x in users)
                    {
                        if (x == "HanDeDict")
                        {
                            richUsers.Add(x + "\t" + "Platzhalter für das ursprüngliche HanDeDict-Team");
                        }
                        if (x == "zydeo-robot")
                        {
                            richUsers.Add(x + "\t" + "Platzhalter für automatische Datenverarbeitung");
                        }
                        else
                        {
                            richUsers.Add(x + "\t");
                        }
                    }
                    // Second pass. Actual import.
                    fs.Position = 0;
                    using (SqlDict.ImportBuilder builder = dict.GetBulkBuilder(richUsers, bulks))
                    {
                        while (true)
                        {
                            vers.Clear();
                            int id = ebp.ReadBlock(vers);
                            if (id == -1)
                            {
                                break;
                            }
                            builder.AddEntry(id, vers);
                        }
                        builder.CommitRest();
                    }
                }
        }