public static void UploadJson(string fileName, Stream fileStream, string projectName, string moduleName) { var culture = GetCultureFromFileName(fileName); string jsonString; using (var reader = new StreamReader(fileStream)) { jsonString = reader.ReadToEnd(); } var jsonObj = JsonConvert.DeserializeObject <Dictionary <string, string> >(jsonString); var fileID = ResourceData.AddFile(fileName, projectName, moduleName); const string resourceType = "text"; foreach (var key in jsonObj.Keys) { var word = new ResWord { Title = key, ValueFrom = jsonObj[key], ResFile = new ResFile { FileID = fileID } }; ResourceData.AddResource(culture, resourceType, DateTime.UtcNow, word, true, "Console"); } }
public static void GetResWordByKey(ResWord word, string to) { using (var dbManager = new DbManager(Dbid)) { var sql = new SqlQuery(ResDataTable) .Select("textvalue", "description", "link") .Where("fileID", word.ResFile.FileID) .Where("cultureTitle", "Neutral") .Where("title", word.Title); dbManager.ExecuteList(sql).ForEach(r => GetValue(word, to, r)); GetValueByKey(word, to); sql = new SqlQuery(ResDataTable + " as res1").Select("res1.textvalue").Distinct() .InnerJoin(ResDataTable + " as res2", Exp.EqColumns("res1.title", "res2.title") & Exp.EqColumns("res1.fileid", "res2.fileid")) .Where("res1.cultureTitle", to) .Where("res2.cultureTitle", "Neutral") .Where("res2.textvalue", word.ValueFrom); word.Alternative = new List <string>(); dbManager.ExecuteList(sql).ForEach(r => word.Alternative.Add((string)r[0])); word.Alternative.Remove(word.ValueTo); sql = new SqlQuery(ResFilesTable) .Select("resname") .Where("id", word.ResFile.FileID); word.ResFile.FileName = dbManager.ExecuteScalar <string>(sql); } }
private static SqlQuery GetQuery(string table, string cultureTitle, ResWord word) { return(new SqlQuery(table) .Select("textvalue") .Where("fileID", word.ResFile.FileID) .Where("cultureTitle", cultureTitle) .Where("title", word.Title)); }
private static SqlUpdate Update(string table, string cultureTitle, ResWord word) { return(new SqlUpdate(table) .Set("flag", 2) .Set("textvalue", word.ValueFrom) .Where("fileID", word.ResFile.FileID) .Where("title", word.Title) .Where("cultureTitle", cultureTitle)); }
public static void AddComment(ResWord word) { using (var dbManager = new DbManager(Dbid)) { var sqlUpdate = new SqlUpdate(ResDataTable); sqlUpdate.Set("description", word.TextComment).Where("title", word.Title).Where("fileID", word.ResFile.FileID).Where("cultureTitle", "Neutral"); dbManager.ExecuteNonQuery(sqlUpdate); } }
public static void EditEnglish(ResWord word) { using (var dbManager = new DbManager(Dbid)) { var update = new SqlUpdate(ResDataTable); update.Set("textvalue", word.ValueFrom).Where("fileID", word.ResFile.FileID).Where("title", word.Title).Where("cultureTitle", "Neutral"); dbManager.ExecuteNonQuery(update); } }
private static void GetValue(ResWord word, string to, IList <object> r) { word.ValueFrom = (string)r[0] ?? ""; word.TextComment = (string)r[1] ?? ""; var langs = (ConfigurationManager.AppSettings["resources.com-lang"] ?? string.Empty).Split(';').ToList(); var dom = langs.Exists(lang => lang == to) ? ".info" : ".com"; word.Link = !String.IsNullOrEmpty((string)r[2]) ? String.Format("http://{0}-translator.teamlab{1}{2}", to, dom, r[2]) : ""; }
public static void GetValueByKey(ResWord word, string to) { using (var dbManager = new DbManager(Dbid)) { var sql = new SqlQuery(ResDataTable); sql.Select("textvalue") .Where("fileID", word.ResFile.FileID) .Where("cultureTitle", to) .Where("title", word.Title); word.ValueTo = dbManager.ExecuteScalar <string>(sql) ?? ""; } }
public static void GetValueByKey(ResWord word, string to) { using (var dbManager = new DbManager("tmresource")) { var sql = new SqlQuery("res_data"); sql.Select(new[] { "textvalue" }) .Where("fileID", word.ResFile.FileID) .Where("cultureTitle", to) .Where("title", word.Title); word.ValueTo = (string)dbManager.ExecuteScalar(sql) ?? ""; } }
public static void UploadJson(string fileName, Stream fileStream, string projectName, string moduleName) { var culture = GetCultureFromFileName(fileName); string jsonString; using (var reader = new StreamReader(fileStream)) { jsonString = reader.ReadToEnd(); } var jsonObj = new Dictionary <string, string>(); if (Path.GetExtension(fileName) == ".xml") { var doc = new XmlDocument(); doc.LoadXml(jsonString); var list = doc.SelectNodes("//resources//string"); if (list != null) { try { var nodes = list.Cast <XmlNode>().ToList(); jsonObj = nodes.ToDictionary(r => r.Attributes["name"].Value, r => r.InnerText); } catch (Exception e) { LogManager.GetLogger("ASC").ErrorFormat("parse xml " + fileName, e); } } } else { var reader = JObject.Parse(jsonString).CreateReader(); while (reader.Read()) { if (reader.TokenType == JsonToken.String) { var key = reader.Path; key = Regex.Replace(Regex.Replace(key, @"\[\'(\s)*", ".$1"), @"(\s)*\'\]", "$1").TrimStart('.').TrimEnd('.'); if (reader.Value != null) { var value = reader.Value.ToString(); jsonObj.Add(key, value); } } } } var fileID = ResourceData.AddFile(fileName, projectName, moduleName); const string resourceType = "text"; foreach (var key in jsonObj.Keys) { var word = new ResWord { Title = key, ValueFrom = jsonObj[key], ResFile = new ResFile { FileID = fileID } }; if (culture != "Neutral") { var neutralKey = new ResWord { Title = key, ValueFrom = jsonObj[key], ResFile = new ResFile { FileID = fileID } }; ResourceData.GetValueByKey(neutralKey, "Neutral"); if (string.IsNullOrEmpty(neutralKey.ValueTo)) { continue; } } ResourceData.AddResource(culture, resourceType, DateTime.UtcNow, word, true, "Console"); } }
private static SqlInsert Insert(string table, string cultureTitle, ResWord word) { return(new SqlInsert(table, true) .InColumns("title", "textvalue", "cultureTitle", "fileID") .Values(word.Title, word.ValueFrom, cultureTitle, word.ResFile.FileID)); }
public static void AddResource(string cultureTitle, string resType, DateTime date, ResWord word, bool isConsole, string authorLogin, bool updateIfExist = true) { using (var db = new DbManager(Dbid)) { var resData = db.ExecuteScalar <string>(GetQuery(ResDataTable, cultureTitle, word)); var resReserve = db.ExecuteScalar <string>(GetQuery(ResReserveTable, cultureTitle, word)); //нет ключа if (string.IsNullOrEmpty(resData)) { //добавляем в основную таблицу db.ExecuteNonQuery(Insert(ResDataTable, cultureTitle, word) .InColumnValue("resourceType", resType) .InColumnValue("timechanges", date) .InColumnValue("flag", 2) .InColumnValue("authorLogin", authorLogin)); //добавляем в резервную таблицу if (isConsole) { db.ExecuteNonQuery(Insert(ResReserveTable, cultureTitle, word)); } } else { if (cultureTitle == "Neutral" && isConsole) { updateIfExist = db.ExecuteScalar <int>(new SqlQuery(ResDataTable) .SelectCount() .Where("fileID", word.ResFile.FileID) .Where(!Exp.Eq("cultureTitle", cultureTitle)) .Where("title", word.Title)) == 0; } var isChangeResData = resData != word.ValueFrom; var isChangeResReserve = resReserve != word.ValueFrom; if (!updateIfExist) { return; } //при работе с консолью изменилось по сравнению с res_data и res_reserve, либо при работе с сайтом изменилось по сравнению с res_reserve if ((isConsole && isChangeResData && isChangeResReserve) || !isConsole) { // изменилась нейтральная культура - выставлен флаг у всех ключей из выбранного файла с выбранным title if (cultureTitle == "Neutral") { var update = new SqlUpdate(ResDataTable) .Set("flag", 3) .Where("fileID", word.ResFile.FileID) .Where("title", word.Title); db.ExecuteNonQuery(update); } // изменилась не нейтральная культура db.ExecuteNonQuery(Insert(ResDataTable, cultureTitle, word) .InColumnValue("resourceType", resType) .InColumnValue("timechanges", date) .InColumnValue("flag", 2) .InColumnValue("authorLogin", authorLogin)); if (isConsole) { db.ExecuteNonQuery(Update(ResReserveTable, cultureTitle, word)); } } else if (isChangeResData) { db.ExecuteNonQuery(Update(ResReserveTable, cultureTitle, word)); } } } }
public static void AddResource(string cultureTitle, string resType, DateTime date, ResWord word, bool isConsole, string authorLogin) { using (var db = new DbManager("tmresource")) { var resData = db.ExecuteScalar <string>(GetQuery("res_data", cultureTitle, word)); var resReserve = db.ExecuteScalar <string>(GetQuery("res_reserve", cultureTitle, word)); if (string.IsNullOrEmpty(resData)) { db.ExecuteNonQuery(Insert("res_data", cultureTitle, word) .InColumnValue("resourceType", resType) .InColumnValue("timechanges", date) .InColumnValue("flag", 2) .InColumnValue("authorLogin", authorLogin)); if (isConsole) { db.ExecuteNonQuery(Insert("res_reserve", cultureTitle, word)); } } else { var isChangeResData = resData != word.ValueFrom; var isChangeResReserve = resReserve != word.ValueFrom; if ((isConsole && isChangeResData && isChangeResReserve) || !isConsole) { if (cultureTitle == "Neutral") { var update = new SqlUpdate("res_data") .Set("flag", 3) .Where("fileID", word.ResFile.FileID) .Where("title", word.Title); db.ExecuteNonQuery(update); } db.ExecuteNonQuery(Insert("res_data", cultureTitle, word) .InColumnValue("resourceType", resType) .InColumnValue("timechanges", date) .InColumnValue("flag", 2) .InColumnValue("authorLogin", authorLogin)); if (isConsole) { db.ExecuteNonQuery(Update("res_reserve", cultureTitle, word)); } } else if (isConsole && isChangeResData && !isChangeResReserve) { db.ExecuteNonQuery(Update("res_reserve", cultureTitle, word)); } } } }
public static void UploadJson(string fileName, Stream fileStream, string projectName, string moduleName) { var culture = GetCultureFromFileName(fileName); string jsonString; using (var reader = new StreamReader(fileStream)) { jsonString = reader.ReadToEnd(); } var jsonObj = new Dictionary <string, string>(); if (Path.GetExtension(fileName) == ".xml") { var doc = new XmlDocument(); doc.LoadXml(jsonString); var list = doc.SelectNodes("//resources//string"); if (list != null) { try { var nodes = list.Cast <XmlNode>().ToList(); jsonObj = nodes.ToDictionary(r => r.Attributes["name"].Value, r => r.InnerText); } catch (Exception e) { log4net.LogManager.GetLogger("ASC").ErrorFormat("parse xml " + fileName, e); } } } else { jsonObj = JsonConvert.DeserializeObject <Dictionary <string, string> >(jsonString); } var fileID = ResourceData.AddFile(fileName, projectName, moduleName); const string resourceType = "text"; foreach (var key in jsonObj.Keys) { var word = new ResWord { Title = key, ValueFrom = jsonObj[key], ResFile = new ResFile { FileID = fileID } }; if (culture != "Neutral") { var neutralKey = new ResWord { Title = key, ValueFrom = jsonObj[key], ResFile = new ResFile { FileID = fileID } }; ResourceData.GetValueByKey(neutralKey, "Neutral"); if (string.IsNullOrEmpty(neutralKey.ValueTo)) { continue; } } ResourceData.AddResource(culture, resourceType, DateTime.UtcNow, word, true, "Console"); } }