Ejemplo n.º 1
0
        public static string ExportJson(string project, string module, List<string> languages, string exportPath)
        {
            using (var fastZip = new ZipFile())
            {
                var filter = new ResCurrent
                    {
                        Project = new ResProject {Name = project},
                        Module = new ResModule {Name = module}
                    };

                var zipDirectory = Directory.CreateDirectory(exportPath + module);
                foreach (var language in languages)
                {
                    filter.Language = new ResCulture {Title = language};

                    var words = GetResource.GetListResWords(filter, string.Empty).GroupBy(x => x.ResFile.FileID).ToList();
                    if (!words.Any())
                    {
                        Console.WriteLine("Error!!! Can't find appropriate project and module. Possibly wrong names!");
                        return null;
                    }

                    foreach (var fileWords in words)
                    {
                        var wordsDictionary = new Dictionary<string, string>();
                        foreach (var word in fileWords.OrderBy(x=>x.Title).Where(word => !wordsDictionary.ContainsKey(word.Title)))
                        {
                            wordsDictionary[word.Title] = word.ValueTo ?? word.ValueFrom;
                        }

                        var firstWord = fileWords.FirstOrDefault();
                        var fileName = firstWord == null ? module : Path.GetFileNameWithoutExtension(firstWord.ResFile.FileName);

                        var zipFileName = zipDirectory.FullName + "\\" + fileName
                                          + (language == "Neutral" ? string.Empty : "." + language) + ".json";
                        using (TextWriter writer = new StreamWriter(zipFileName))
                        {
                            var obj = JsonConvert.SerializeObject(wordsDictionary, Formatting.Indented);
                            writer.Write(obj);
                        }
                    }
                }

                var zipPath = exportPath + "\\" + module + ".zip";
                fastZip.AddDirectory(zipDirectory.FullName);
                fastZip.Save(zipPath);

                zipDirectory.Delete(true);
                return zipPath;
            }
        }
Ejemplo n.º 2
0
        public static void GetListModules(ResCurrent currentData)
        {
            using (var dbManager = new DbManager("tmresource"))
            {
                var exist = new SqlQuery("res_data rd1")
                    .Select("rd1.title")
                    .Where("rd1.fileid = rd.fileid")
                    .Where("rd1.title = concat('del_', rd.title)")
                    .Where("rd1.cultureTitle = rd.cultureTitle");

                var sql = new SqlQuery("res_files rf").Select("rf.moduleName",
                                                              string.Format("sum(case rd.cultureTitle when '{0}' then (case rd.flag when 3 then 0 else 1 end) else 0 end)", currentData.Language.Title),
                                                              string.Format("sum(case rd.cultureTitle when '{0}' then (case rd.flag when 3 then 1 else 0 end) else 0 end)", currentData.Language.Title),
                                                              string.Format("sum(case rd.cultureTitle when '{0}' then 1 else 0 end)", "Neutral"))
                                                      .InnerJoin("res_data rd", Exp.EqColumns("rd.fileid", "rf.id"))
                                                      .Where("rf.projectName", currentData.Project.Name)
                                                      .Where("rd.resourceType", "text")
                                                      .Where(!Exp.Like("rd.title", @"del\_", SqlLike.StartWith) & !Exp.Exists(exist))
                                                      .GroupBy("moduleName");


                dbManager.ExecuteList(sql).ForEach(r =>
                    {
                        var module = currentData.Project.Modules.Find(mod => mod.Name == r[0].ToString());
                        if (module == null) return;
                        module.Counts[WordStatusEnum.Translated] = Convert.ToInt32(r[1]);
                        module.Counts[WordStatusEnum.Changed] = Convert.ToInt32(r[2]);
                        module.Counts[WordStatusEnum.All] = Convert.ToInt32(r[3]);
                        module.Counts[WordStatusEnum.Untranslated] = module.Counts[WordStatusEnum.All] - module.Counts[WordStatusEnum.Changed] - module.Counts[WordStatusEnum.Translated];
                    });
            }
        }
Ejemplo n.º 3
0
        public static IEnumerable<ResWord> GetListResWords(ResCurrent current, string search)
        {
            using (var dbManager = new DbManager("tmresource"))
            {
                var exist = new SqlQuery("res_data rd3")
                    .Select("rd3.title")
                    .Where("rd3.fileid = rd1.fileid")
                    .Where("rd3.title = concat('del_', rd1.title)")
                    .Where("rd3.cultureTitle = rd1.cultureTitle");

                var sql = new SqlQuery("res_data rd1")
                    .Select("rd1.title", "rd1.fileid", "rd1.textValue", "rd1.description", "rd1.flag", "rd1.link", "rf.resName", "rd2.id", "rd2.flag", "rd2.textValue")
                    .LeftOuterJoin("res_data rd2", Exp.EqColumns("rd1.fileid", "rd2.fileid") & Exp.EqColumns("rd1.title", "rd2.title") & Exp.Eq("rd2.cultureTitle", current.Language.Title))
                    .InnerJoin("res_files rf", Exp.EqColumns("rf.ID", "rd1.fileID"))
                    .Where("rf.moduleName", current.Module.Name)
                    .Where("rf.projectName", current.Project.Name)
                    .Where("rd1.cultureTitle", "Neutral")
                    .Where("rd1.flag != 4")
                    .Where("rd1.resourceType", "text")
                    .Where(!Exp.Like("rd1.title", @"del\_", SqlLike.StartWith) & !Exp.Exists(exist))
                    .OrderBy("rd1.id", true);

                if (!String.IsNullOrEmpty(search))
                    sql.Where(Exp.Like("rd1.textvalue", search));

                return dbManager.ExecuteList(sql).ConvertAll(r =>
                    {
                        var word = GetWord(r);
                        word.ResFile.FileName = Convert.ToString(r[6]);

                        if (r[7] != null)
                        {
                            word.Status = (int)r[8] == 3 ? WordStatusEnum.Changed : WordStatusEnum.Translated;
                            word.ValueTo = Convert.ToString(r[9]);
                        }
                        else
                        {
                            word.Status = WordStatusEnum.Untranslated;
                        }

                        return word;
                    }).OrderBy(r => r.ValueFrom);
            }
        }