Пример #1
0
    public static void oper1NewTradosPages(tradosPage[] pages, bool isFakeRussian) {
      TradosDT.TradosDB db = TradosDT.TradosDB.getTradosContext(); 
      //insert pages
      foreach (var page in pages) {
        //kontrola jednoznacnosti sentence name
        var dupls = page.sentences.GroupBy(s => s.Name).Where(g => g.Select(s => s.Value).Distinct().Count() > 1).ToArray();
        if (dupls.Length > 0) throw new Exception(@"d:\LMCom\rew\LMComLib\Framework\TradosLib.cs, oper1NewTradosPages");
        var delDb = TradosDT.TradosDB.getTradosContext();
        delDb.Pages.RemoveRange(delDb.Pages.Where(p => p.FileName == page.FileName));
        delDb.SaveChanges();

        var pg = new TradosDT.Page { FileName = page.FileName, PageGroup = (short)(isFakeRussian ? LocPageGroup.fakeRussian : LocPageGroup.newEA), SeeUrl = page.FileName };
        foreach (var s in page.sentences.GroupBy(s => s.Name).Select(g => g.First()))
          TradosDT.Sentence.insert(db, pg, s.Name, null, Langs.no, s.Value, page.srcLang);
      }
      db.SaveChanges();
    }
Пример #2
0
    //public class tradosSents {
    //  public string Name; //Sentence.Name, cesta od "level" (bez) 
    //  public string TransText; //obsah
    //}

    //pageFilter a sentFilter slouzi pro hromadne delete.
    //sentFilter muze byt not null pouze tehdy, obsahuje-li pageFilter uplnou cestu k urovni (napr. lm/oldea/data/english1). Toto se ale v oper1New nekontroluje
    //pages jsou data pro Insert.
    public static void oper1NewTradosPagePart(string sentFilter, tradosPage page, bool isFakeRussian) {
      TradosDT.TradosDB db = TradosDT.TradosDB.getTradosContext(); 
      var singlePage = db.Pages.FirstOrDefault(p => p.FileName == page.FileName);
      var emptyData = page.sentences == null || page.sentences.Length == 0;
      if (singlePage == null && emptyData) return; //nothing todo
      //delete sentences na zaklade sentFilter
      if (singlePage != null) { //stranka existuje
        var delDb = TradosDT.TradosDB.getTradosContext();
        delDb.Sentences.RemoveRange(delDb.Sentences.Where(s => s.PageId == singlePage.Id && s.Name.StartsWith(sentFilter)));
        delDb.SaveChanges();
      }
      //chybi data => delete page
      if (emptyData && singlePage != null) { db.Pages.Remove(singlePage); return; }
      if (!emptyData && singlePage == null) db.Pages.Add(singlePage = new TradosDT.Page { FileName = page.FileName, PageGroup = (short)(isFakeRussian ? LocPageGroup.fakeRussian : LocPageGroup.newEA), Langs = null /*TODO*/ });
      else {
        //kontrola zdrojoveho jazyka stranky - nesmi se zmenit
        var actSrcLang = (Langs)db.Sentences.Where(s => s.PageId == singlePage.Id).Select(s => s.TransLang).FirstOrDefault();
        if (actSrcLang != Langs.no && page.srcLang != actSrcLang) throw new Exception("single page TransLang mishmash");
      }
      //insert sentences pod singlePage stranku, sentences !=null && singlePage!=null
      foreach (var s in page.sentences)
        TradosDT.Sentence.insert(db, singlePage, s.Name, null, Langs.no, s.Value, page.srcLang);
      db.SaveChanges();
    }