Exemplo n.º 1
0
        public static void GetListModules(ResCurrent currentData)
        {
            using (var dbManager = new DbManager(Dbid))
            {
                var exist = new SqlQuery(ResDataTable + " 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(ResFilesTable + " 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(ResDataTable + "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];
                });
            }
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
0
        public static IEnumerable <ResWord> GetListResWords(ResCurrent current, string search)
        {
            using (var dbManager = new DbManager(Dbid))
            {
                var exist = new SqlQuery(ResDataTable + " 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(ResDataTable + " rd1")
                          .Select("rd1.title", "rd1.fileid", "rd1.textValue", "rd1.description", "rd1.flag", "rd1.link", "rf.resName", "rd2.id", "rd2.flag", "rd2.textValue")
                          .LeftOuterJoin(ResDataTable + " rd2", Exp.EqColumns("rd1.fileid", "rd2.fileid") & Exp.EqColumns("rd1.title", "rd2.title") & Exp.Eq("rd2.cultureTitle", current.Language.Title))
                          .InnerJoin(ResFilesTable + " 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));
            }
        }
Exemplo n.º 4
0
        public static IEnumerable <ResWord> GetListResWords(ResCurrent current, string search)
        {
            using (var dbManager = new DbManager("tmresource"))
            {
                var sql = new SqlQuery("res_data rd1")
                          .Select("rd1.title", "rd1.fileid", "rd1.textValue", "rd1.description", "rd1.flag", "rd1.link", "rd2.id", "rd2.flag")
                          .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")
                          .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);

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

                    return word;
                }).OrderBy(r => r.ValueFrom));
            }
        }
Exemplo n.º 5
0
        public static string ExportJson(string project, string module, List <string> languages, string exportPath,
                                        bool withDefaultValue = true, bool withStructurJson = true)
        {
            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 =
                    ResourceData.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)))
                    {
                        if (string.IsNullOrEmpty(word.ValueTo) && !withDefaultValue)
                        {
                            continue;
                        }

                        wordsDictionary[word.Title] = word.ValueTo ?? word.ValueFrom;
                        if (!string.IsNullOrEmpty(wordsDictionary[word.Title]))
                        {
                            wordsDictionary[word.Title] = wordsDictionary[word.Title].TrimEnd('\n').TrimEnd('\r');
                        }
                    }

                    if (!wordsDictionary.Any())
                    {
                        continue;
                    }

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

                    var zipFileName = zipDirectory.FullName + "\\" + fileName +
                                      (language == "Neutral" ? string.Empty : "." + language) + ext;
                    using (TextWriter writer = new StreamWriter(zipFileName))
                    {
                        if (ext == ".json")
                        {
                            if (withStructurJson)
                            {
                                var     collectionNames = new List <string>();
                                var     wrOrder         = 0;
                                JObject jObject         = null;
                                var     writeJtoken     = new JTokenWriter();

                                writeJtoken.WriteStartObject();
                                foreach (var vordsKV in wordsDictionary)
                                {
                                    var strNameSplit = vordsKV.Key.Split('.');

                                    for (var a = 0; a < strNameSplit.Length; a++)
                                    {
                                        while (collectionNames.Count < a + 1)
                                        {
                                            collectionNames.Add("");
                                        }

                                        if (collectionNames[a] != null && collectionNames[a] == strNameSplit[a])
                                        {
                                            continue;
                                        }
                                        if (wrOrder > a)
                                        {
                                            for (var b = a; b < collectionNames.Count; b++)
                                            {
                                                collectionNames[b] = null;
                                            }
                                            while (wrOrder > a)
                                            {
                                                writeJtoken.WriteEndObject();
                                                wrOrder--;
                                            }
                                        }
                                        writeJtoken.WritePropertyName(strNameSplit[a]);
                                        if (a < strNameSplit.Length - 1)
                                        {
                                            writeJtoken.WriteStartObject();
                                            wrOrder++;
                                            collectionNames[a] = strNameSplit[a];
                                        }
                                        else
                                        {
                                            writeJtoken.WriteValue(vordsKV.Value);
                                        }
                                    }
                                }
                                jObject = (JObject)writeJtoken.Token;
                                writer.Write(jObject);
                            }
                            else
                            {
                                var obj = JsonConvert.SerializeObject(wordsDictionary, Formatting.Indented);
                                writer.Write(obj);
                            }
                        }
                        else
                        {
                            var data      = new XmlDocument();
                            var resources = data.CreateElement("resources");

                            foreach (var ind in wordsDictionary)
                            {
                                var stringAttr = data.CreateAttribute("name");
                                stringAttr.Value = ind.Key;

                                var child = data.CreateElement("string");
                                child.Attributes.Append(stringAttr);
                                child.InnerText = ind.Value;

                                resources.AppendChild(child);
                            }

                            data.AppendChild(resources);

                            var settings = new XmlWriterSettings
                            {
                                Indent             = true,
                                IndentChars        = "  ",
                                NewLineChars       = Environment.NewLine,
                                NewLineHandling    = NewLineHandling.Replace,
                                OmitXmlDeclaration = false,
                                ConformanceLevel   = ConformanceLevel.Fragment
                            };

                            using (var xmlTextWriter = XmlWriter.Create(writer, settings))
                            {
                                data.WriteTo(xmlTextWriter);
                                xmlTextWriter.Flush();
                            }
                        }
                    }
                }
            }

            var zipPath = zipDirectory.FullName + ".zip";
            var fastZip = new FastZip();

            fastZip.CreateEmptyDirectories = true;
            fastZip.CreateZip(zipPath, zipDirectory.FullName, true, null);
            zipDirectory.Delete(true);

            return(zipPath);
        }
Exemplo n.º 6
0
        public static string ExportJson(string project, string module, List <string> languages, string exportPath,
                                        bool withDefaultValue = true)
        {
            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 =
                        ResourceData.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)))
                        {
                            if (string.IsNullOrEmpty(word.ValueTo) && !withDefaultValue)
                            {
                                continue;
                            }

                            wordsDictionary[word.Title] = word.ValueTo ?? word.ValueFrom;
                            if (!string.IsNullOrEmpty(wordsDictionary[word.Title]))
                            {
                                wordsDictionary[word.Title] = wordsDictionary[word.Title].TrimEnd('\n').TrimEnd('\r');
                            }
                        }

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

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

                                foreach (var ind in wordsDictionary)
                                {
                                    var stringAttr = data.CreateAttribute("name");
                                    stringAttr.Value = ind.Key;

                                    var child = data.CreateElement("string");
                                    child.Attributes.Append(stringAttr);
                                    child.InnerText = ind.Value;

                                    resources.AppendChild(child);
                                }

                                data.AppendChild(resources);

                                var settings = new XmlWriterSettings
                                {
                                    Indent             = true,
                                    IndentChars        = "  ",
                                    NewLineChars       = Environment.NewLine,
                                    NewLineHandling    = NewLineHandling.Replace,
                                    OmitXmlDeclaration = false,
                                    ConformanceLevel   = ConformanceLevel.Fragment
                                };

                                using (var xmlTextWriter = XmlWriter.Create(writer, settings))
                                {
                                    data.WriteTo(xmlTextWriter);
                                    xmlTextWriter.Flush();
                                }
                            }
                        }
                    }
                }

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

                zipDirectory.Delete(true);
                return(zipPath);
            }
        }