public bool DatabaseExists()
 {
     using (TranslationStorage context = new TranslationStorage(getConnectionString()))
     {
         return context.DatabaseExists();
     }
 }
Exemple #2
0
 public bool DatabaseExists()
 {
     using (TranslationStorage context = new TranslationStorage(getConnectionString()))
     {
         return(context.DatabaseExists());
     }
 }
Exemple #3
0
 public IEnumerable <TranslationText> Search(ResourceDataBase source, CultureInfo targetCulture)
 {
     using (TranslationStorage context = new TranslationStorage(getConnectionString()))
     {
         return(context.SearchTranslation(source.Value, source.ResxFile.Culture.Name, targetCulture.Name)
                .ToList());
     }
 }
        public void CreateDatabase()
        {
            using (TranslationStorage context = new TranslationStorage(getConnectionString()))
            {
                if (!context.DatabaseExists())
                    context.CreateDatabase();
            }
            using (var connection = new SqlConnection(GetConnectionSetting().ProviderConnectionString))
            {
                connection.Open();
                var transaction = connection.BeginTransaction();

                ExecuteSQLFile(transaction, "ResourceManager.Storage.Sql.StoredProcedures1.sql");

                transaction.Commit();
            }
        }
Exemple #5
0
        public void CreateDatabase()
        {
            using (TranslationStorage context = new TranslationStorage(getConnectionString()))
            {
                if (!context.DatabaseExists())
                {
                    context.CreateDatabase();
                }
            }
            using (var connection = new SqlConnection(GetConnectionSetting().ProviderConnectionString))
            {
                connection.Open();
                var transaction = connection.BeginTransaction();

                // If DataBase exists, context.CreateDatabase() does not create tables.
                ExecuteSQLFile(transaction, "ResourceManager.Storage.Sql.Tables1.sql");
                ExecuteSQLFile(transaction, "ResourceManager.Storage.Sql.StoredProcedures1.sql");

                transaction.Commit();
            }
        }
Exemple #6
0
 private Culture GetCulture(CultureInfo culture, TranslationStorage storage)
 {
     return(storage.GetCulture(culture.Name).First());
 }
Exemple #7
0
        public void Store(VSSolution solution)
        {
            using (TranslationStorage store = new TranslationStorage(getConnectionString()))
            {
                foreach (var project in solution.Projects.Values)
                {
                    foreach (var fileGroup in project.ResxGroups.Values)
                    {
                        foreach (var dataGroup in fileGroup.AllData.Values)
                        {
                            var existingTranslationTexts = new List <TranslationText>();
                            foreach (var data in dataGroup.ResxData.Values)
                            {
                                existingTranslationTexts.AddRange(store.FindTranslations(data.Value, data.ResxFile.Culture.Name));
                            }

                            if (existingTranslationTexts.Count == 0)
                            {
                                var t = new Translation();

                                foreach (var data in dataGroup.ResxData.Values)
                                {
                                    var text = new TranslationText();
                                    text.Text         = data.Value;
                                    text.Culture      = GetCulture(data.ResxFile.Culture, store);
                                    text.CreatedDate  = DateTime.Now;
                                    text.ModifiedDate = DateTime.Now;
                                    t.Translations.Add(text);
                                }

                                store.Translations.AddObject(t);
                                store.SaveChanges();
                            }
                            else
                            {
                                var list = from transText in existingTranslationTexts
                                           join data in dataGroup.ResxData.Values
                                           on transText.Text.ToLowerInvariant() equals data.Value.ToLowerInvariant()
                                           group transText by transText.Translation into translation
                                           select new { Translation = translation.Key, Count = translation.Count() };

                                var topCandidate = list.OrderByDescending(t => t.Count)
                                                   .FirstOrDefault();

                                if (topCandidate != null)
                                {
                                    var notExistingCultures = from data in dataGroup.ResxData
                                                              where (topCandidate.Translation.Translations.Where(t => t.Text == data.Value.Value)).Count() == 0
                                                              select data.Key;

                                    //var notExistingCultures = (from c in dataGroup.ResxData.Keys select c)
                                    //    .Except(from cn in topCandidate.Translation.Translations select CultureInfo.GetCultureInfo(cn.Culture.CultureName));

                                    if (notExistingCultures.Count() > 0)
                                    {
                                        foreach (var culture in notExistingCultures)
                                        {
                                            var text = new TranslationText();
                                            text.Text         = dataGroup.ResxData[culture].Value;
                                            text.Culture      = GetCulture(culture, store);
                                            text.CreatedDate  = DateTime.Now;
                                            text.ModifiedDate = DateTime.Now;

                                            topCandidate.Translation.Translations.Add(text);
                                        }
                                        store.SaveChanges();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        public void Store(VSSolution solution)
        {
            using (TranslationStorage store = new TranslationStorage(getConnectionString()))
            {
                foreach (var project in solution.Projects.Values)
                {
                    foreach (var fileGroup in project.ResxGroups.Values)
                    {
                        foreach (var dataGroup in fileGroup.AllData.Values)
                        {
                            var existingTranslationTexts = new List<TranslationText>();
                            foreach (var data in dataGroup.ResxData.Values)
                            {
                                existingTranslationTexts.AddRange(store.FindTranslations(data.Value, data.ResxFile.Culture.Name));
                            }

                            if (existingTranslationTexts.Count == 0)
                            {
                                var t = new Translation();

                                foreach (var data in dataGroup.ResxData.Values)
                                {
                                    var text = new TranslationText();
                                    text.Text = data.Value;
                                    text.Culture = GetCulture(data.ResxFile.Culture, store);
                                    text.CreatedDate = DateTime.Now;
                                    text.ModifiedDate = DateTime.Now;
                                    t.Translations.Add(text);
                                }

                                store.Translations.AddObject(t);
                                store.SaveChanges();
                            }
                            else
                            {
                                var list = from transText in existingTranslationTexts
                                           join data in dataGroup.ResxData.Values
                                           on transText.Text.ToLowerInvariant() equals data.Value.ToLowerInvariant()
                                           group transText by transText.Translation into translation
                                           select new { Translation = translation.Key, Count = translation.Count() };

                                var topCandidate = list.OrderByDescending(t => t.Count)
                                    .FirstOrDefault();

                                if (topCandidate == null)
                                    throw new Exception("TODO: Error");

                                var notExistingCultures = (from c in dataGroup.ResxData.Keys select c)
                                    .Except(from cn in topCandidate.Translation.Translations select CultureInfo.GetCultureInfo(cn.Culture.CultureName));

                                foreach (var culture in notExistingCultures)
                                {
                                    var text = new TranslationText();
                                    text.Text = dataGroup.ResxData[culture].Value;
                                    text.Culture = GetCulture(culture, store);
                                    text.CreatedDate = DateTime.Now;
                                    text.ModifiedDate = DateTime.Now;

                                    topCandidate.Translation.Translations.Add(text);
                                }
                                store.SaveChanges();
                            }
                        }
                    }
                }
            }
        }
 public IEnumerable<TranslationText> Search(ResourceDataBase source, CultureInfo targetCulture)
 {
     using (TranslationStorage context = new TranslationStorage(getConnectionString()))
     {
         return context.SearchTranslation(source.Value, source.ResxFile.Culture.Name, targetCulture.Name)
             .ToList();
     }
 }
 private Culture GetCulture(CultureInfo culture, TranslationStorage storage)
 {
     return storage.GetCulture(culture.Name).First();
 }