Пример #1
0
        public ActionResult CreateDictionaryItem(DictionaryItemViewModel model)
        {
            int id;
            if (model.Parent != string.Empty && int.TryParse(model.Parent, out id))
            {
                Session["parentId"] = model.Parent;

                var p = new Dictionary.DictionaryItem(id);

                Dictionary.DictionaryItem.addKey(model.Key, model.Value, p.key);
            }
            else
            {
                Session["parentId"] = null;
                Dictionary.DictionaryItem.addKey(model.Key, model.Value);
            }

            var d = new Dictionary.DictionaryItem(model.Key);

            foreach (var lang in Language.GetAllAsList())
            {
                d.setValue(lang.id,model.Value);
                d.Save();
            }

            TempData["success"] = true;

            return View(Config.DialogViewPath, model);
        }
Пример #2
0
        private void Gen(bool saveTemplateChanges)
        {
            var dir = new DirectoryInfo(Server.MapPath("~/Views"));

            foreach (var file in dir.GetFiles("*.cshtml"))
            {
                var replace = new System.Collections.Generic.Dictionary<string, string>();

                var changes = false;
                var doc = new HtmlDocument();
                doc.Load(file.FullName);

                foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//text()[normalize-space(.) != '']"))
                {
                    if (!node.InnerText.Contains("@") && !node.InnerText.Contains("{") && !node.InnerText.Contains("}")
                        && !node.InnerText.Contains("<") && !node.InnerText.Contains(">") &&
                        !node.InnerText.Contains("(")
                        && !node.InnerText.Contains("("))
                    {

                        var staticVal = node.InnerText.Trim();

                        // create dic item
                        var m = new DictionaryItemViewModel { Value = staticVal };

                        if (Settings.GetSetting("autoGenerateKey") == true.ToString())
                        {
                            var prov = (IAutoGenKey)Activator.CreateInstance(Type.GetType(Settings.GetSetting("autoGenerateKeyProvider")));
                            var key = prov.Generate(staticVal);

                            var newKey = key;
                            var c = 1;
                            while (Dictionary.DictionaryItem.hasKey(newKey))
                            {
                                newKey = key + c;
                                c++;
                            }
                            m.Key = newKey;
                        }

                        if (!Dictionary.DictionaryItem.hasKey(file.Name))
                            Dictionary.DictionaryItem.addKey(file.Name, "");

                        Dictionary.DictionaryItem.addKey(m.Key, m.Value, file.Name);
                        var d = new Dictionary.DictionaryItem(m.Key);

                        foreach (var lang in Language.GetAllAsList())
                        {
                            d.setValue(lang.id, m.Value);
                            d.Save();
                        }

                        replace.Add(m.Key, staticVal);

                        if (!changes)
                            changes = true;
                    }

                }

                if (changes && saveTemplateChanges)
                {
                    var contents = File.ReadAllText(file.FullName);
                    var newcontents = contents;
                    foreach (var item in replace)
                        newcontents = newcontents.Replace(item.Value, "@Umbraco.GetDictionaryValue(\"" + item.Key + "\")");

                    File.WriteAllText(file.FullName, newcontents);
                }

            }
        }