Example #1
0
        public static List <int> STAImportCSVDict(Meta meta, CVSDictItem[] items)
        {
            var ids = new List <int>();
            var ctx = new Fulltext.FulltextContext(); int count = 0;
            var dict = ctx.Dicts.Include(d => d.Phrases).FirstOrDefault(d => d.Name == meta.path);

            if (dict != null)
            {
                ctx.Dicts.Remove(dict); ctx.SaveChanges(); ctx = new Fulltext.FulltextContext();
            }
            ctx.Dicts.Add(dict = new Fulltext.Dict {
                Name = meta.path, Imported = DateTime.UtcNow, SrcLang = (byte)meta.src
            });
            foreach (var row in items)
            {
                var srcPhrase = Fulltext.FtxLib.STAInsert(ctx, row.Src, null, dict, new PhraseSide {
                    src = meta.src, dest = meta.src
                }, null);
                var destPhrase = Fulltext.FtxLib.STAInsert(ctx, row.Dest, null, dict, new PhraseSide {
                    src = meta.src, dest = meta.dest
                }, srcPhrase.Id);
                ids.Add(destPhrase.Id);
                if (count++ > 1000)
                {
                    ctx.SaveChanges(); ctx = new Fulltext.FulltextContext(); ctx.Dicts.Attach(dict); count = 0;
                }
            }
            ctx.SaveChanges();
            new Fulltext.FulltextContext().Database.ExecuteSqlCommand("DBCC SHRINKFILE (test_log, 0);");
            return(ids);
        }
Example #2
0
        public static void Duplicities()
        {
            var ctx   = new Fulltext.FulltextContext();
            var dupls = ctx.Phrases.Where(p => p.SrcRef != null).Select(p => new { destLang = p.DestLang, srcLang = p.Src.DestLang, text = p.Src.Text + " = " + p.Text, baseText = p.Src.Base + " = " + p.Base }).GroupBy(p => new { p.srcLang, p.destLang, p.baseText }).Where(g => g.Count() > 1).ToArray();

            new XElement("root", dupls.Select(d => new XElement("dupl", d.Select(e => new XElement("phrase", e.text))))).Save(@"d:\temp\dupls.xml");
        }
Example #3
0
        public static void importAll()
        {
            var ctx = new Fulltext.FulltextContext();

            //ctx.recreate();
            ctx.Database.ExecuteSqlCommand("ALTER DATABASE test SET RECOVERY SIMPLE");
            //ctx.Database.ExecuteSqlCommand("delete Dicts");
            ctx.Database.ExecuteSqlCommand("DBCC SHRINKDATABASE (test, 0);");
            ctx.Database.ExecuteSqlCommand("DBCC SHRINKFILE (test_log, 0);");
            importAll(ImportCSVDict);
        }