예제 #1
0
        public override void Render(ref XmlTree tree)
        {
            
            Dictionary.DictionaryItem[] tmp;
            if (this.id == this.StartNodeID)
                tmp = Dictionary.getTopMostItems;
            else
                tmp = new Dictionary.DictionaryItem(this.id).Children;

            foreach (Dictionary.DictionaryItem di in tmp)
            {
                XmlTreeNode xNode = XmlTreeNode.Create(this);
                xNode.NodeID = di.id.ToString(); //dictionary_ + id.. 
                xNode.Text = di.key;
                xNode.Action = string.Format("javascript:openDictionaryItem({0});", di.id);
                xNode.Icon = "settingDataType.gif";
                xNode.OpenIcon = "settingDataType.gif";
                xNode.NodeType = "DictionaryItem"; //this shouldn't be like this, it should be this.TreeAlias but the ui.config file points to this name.
                xNode.Source = this.GetTreeServiceUrl(di.id);
				xNode.HasChildren = di.hasChildren;

                OnBeforeNodeRender(ref tree, ref xNode, EventArgs.Empty);
                if (xNode != null)
                {
                    tree.Add(xNode);
                    OnAfterNodeRender(ref tree, ref xNode, EventArgs.Empty);
                }
                
            }
        }
예제 #2
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);
        }
예제 #3
0
        /// <summary>
        /// Gets the dictionary item for a specified language. Otherwise returns the fallback string.
        /// </summary>
        /// <param name="key">The dictionary key.</param>
        /// <param name="fallback">The fallback.</param>
        /// <param name="languageId">The language id.</param>
        /// <returns>
        /// Returns the value of a dictionary item from a language id, or the fallback string.
        /// </returns>
        public static string GetDictionaryItem(string key, string fallback, int languageId)
        {
            if (Dictionary.DictionaryItem.hasKey(key))
            {
                var item = new Dictionary.DictionaryItem(key);
                return item.Value(languageId);
            }

            return fallback;
        }
예제 #4
0
        public void Dictionary_IsTopMostItem()
        {
            var parent = CreateNew();

            //create a child
            var childId = Dictionary.DictionaryItem.addKey("Test" + Guid.NewGuid().ToString("N"), "", parent.key);
            Assert.IsTrue(childId > 0);
            var child = new Dictionary.DictionaryItem(childId);
			Assert.IsTrue(TypeHelper.IsTypeAssignableFrom<Dictionary.DictionaryItem>(child));

            Assert.IsTrue(parent.IsTopMostItem());
            Assert.IsFalse(child.IsTopMostItem());

            DeleteItem(child);
            DeleteItem(parent);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            int dictionaryItemId = int.TryParse(Request["nodeId"], out dictionaryItemId) ? dictionaryItemId : 0;

            //There is an issue in v6 with LocalizationService methods throwing "Sequence contains no elements"
            //var localizationService = UmbracoContext.Current.Application.Services.LocalizationService;

            var dicItems = new List<Dictionary.DictionaryItem>();

            if (dictionaryItemId > 0)
            {
                var dicItem = new Dictionary.DictionaryItem(dictionaryItemId);
                if (dicItem == null) return;

                dicItems.Add(dicItem);
            }
            else
            {
                //export all dictionary items
                foreach (var dicItem in Dictionary.getTopMostItems)
                {
                    dicItems.Add(dicItem);
                }
            }

            var fileName = dictionaryItemId == 0 ? "dictionaryitems" : dicItems.First().key;
            Path.GetInvalidFileNameChars().ToList().ForEach(c => fileName = fileName.Replace(c, '_'));

            Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName + ".dic");
            Response.ContentType = "application/octet-stream";

            var doc = new XmlDocument();
            var parent = doc.CreateElement("DictionaryItems");
            foreach (var dicItem in dicItems)
            {
                parent.AppendChild(dicItem.ToXml(doc));
            }

            doc.AppendChild(parent);

            var writerSettings = new XmlWriterSettings();
            writerSettings.Indent = true;

            var xmlWriter = XmlWriter.Create(Response.OutputStream, writerSettings);
            doc.Save(xmlWriter);
        }
예제 #6
0
        public void Dictionary_Attempt_Duplicate_Key()
        {
            var key = "Test" + Guid.NewGuid().ToString("N");
            var d1Id = Dictionary.DictionaryItem.addKey(key, "");
            Assert.IsTrue(d1Id > 0);
            var d1 = new Dictionary.DictionaryItem(d1Id);
            Assert.IsInstanceOfType(d1, typeof(Dictionary.DictionaryItem));

            var alreadyExists = false;
            try
            {
                var d2Id = Dictionary.DictionaryItem.addKey(key, "");
                Assert.IsTrue(d2Id > 0);
                var d2 = new Dictionary.DictionaryItem(d2Id);
            }
            catch (ArgumentException)
            {
                alreadyExists = true;
            }
            Assert.IsTrue(alreadyExists);

            DeleteItem(d1);
        }
예제 #7
0
        public void Dictionary_Delete_Parent_With_Children()
        {
            var parent = CreateNew();

            //create a child
            var childId1 = Dictionary.DictionaryItem.addKey("Test" + Guid.NewGuid().ToString("N"), "", parent.key);
            Assert.IsTrue(childId1 > 0);
            var child1 = new Dictionary.DictionaryItem(childId1);
			Assert.IsTrue(TypeHelper.IsTypeAssignableFrom<Dictionary.DictionaryItem>(child1));

            //create a child
            var childId2 = Dictionary.DictionaryItem.addKey("Test" + Guid.NewGuid().ToString("N"), "", parent.key);
            Assert.IsTrue(childId2 > 0);
            var child2 = new Dictionary.DictionaryItem(childId2);
			Assert.IsTrue(TypeHelper.IsTypeAssignableFrom<Dictionary.DictionaryItem>(child2));

            Assert.IsTrue(parent.hasChildren);
            Assert.AreEqual(2, parent.Children.Length);


            DeleteItem(parent);

            //make sure kids are gone
            var notFound = false;
            try
            {
                var check = new Dictionary.DictionaryItem(childId1);
            }
            catch (ArgumentException)
            {
                notFound = true;
            }
            Assert.IsTrue(notFound);

            notFound = false;
            try
            {
                var check = new Dictionary.DictionaryItem(childId2);
            }
            catch (ArgumentException)
            {
                notFound = true;
            }
            Assert.IsTrue(notFound);

        }
예제 #8
0
 public static String ItemForKeyAndLanguage(String key, String languageCode)
 {
     ILanguage language = ApplicationContext.Current.Services.LocalizationService.GetAllLanguages().First(x => x.IsoCode.Equals(languageCode));
     Dictionary.DictionaryItem dictionaryItem = new Dictionary.DictionaryItem(key);
     return dictionaryItem.Value(language.Id);
 }
예제 #9
0
        public void Dictionary_Parent_Child_Relationship()
        {
            var parent = CreateNew();

            //create a child
            var childId = Dictionary.DictionaryItem.addKey("Test" + Guid.NewGuid().ToString("N"), "", parent.key);
            Assert.IsTrue(childId > 0);
            var child = new Dictionary.DictionaryItem(childId);
			Assert.IsTrue(TypeHelper.IsTypeAssignableFrom<Dictionary.DictionaryItem>(child));

            //set the parent relationship
            Assert.AreEqual(parent.id, child.Parent.id);
            Assert.AreEqual(parent.key, child.Parent.key);
            Assert.AreEqual(parent.UniqueId, child.Parent.UniqueId);

            //test the child relationship
            Assert.IsTrue(parent.hasChildren);
            Assert.AreEqual(1, parent.Children.Length);
            Assert.AreEqual(child.id, parent.Children.First().id);
            Assert.AreEqual(child.key, parent.Children.First().key);
            Assert.AreEqual(child.UniqueId, parent.Children.First().UniqueId);

            DeleteItem(child);
            DeleteItem(parent);
        }
예제 #10
0
        private Dictionary.DictionaryItem CreateNew()
        {
            var id = Dictionary.DictionaryItem.addKey("Test" + Guid.NewGuid().ToString("N"), "");
            Assert.IsTrue(id > 0);

            var d = new Dictionary.DictionaryItem(id);
			Assert.IsTrue(TypeHelper.IsTypeAssignableFrom<Dictionary.DictionaryItem>(d));

            return d;
        }
예제 #11
0
        private void DeleteItem(Dictionary.DictionaryItem d)
        {
            var id = d.id;

            d.delete();

            var notFound = false;
            try
            {
                var check = new Dictionary.DictionaryItem(id);
            }
            catch (ArgumentException)
            {
                notFound = true;
            }
            Assert.IsTrue(notFound, "The item with key " + d.key + " still exists!");

            //check with sql that the language text is gone
            var count = Application.SqlHelper.ExecuteScalar<int>("SELECT COUNT(*) FROM cmsLanguageText WHERE uniqueId=@uniqueId",
                Application.SqlHelper.CreateParameter("@uniqueId", d.UniqueId));
            Assert.AreEqual(0, count);
        }
예제 #12
0
        public void Dictionary_IsTopMostItem()
        {
            var parent = CreateNew();

            //create a child
            var childId = Dictionary.DictionaryItem.addKey("Test" + Guid.NewGuid().ToString("N"), "", parent.key);
            Assert.IsTrue(childId > 0);
            var child = new Dictionary.DictionaryItem(childId);
            Assert.IsInstanceOfType(child, typeof(Dictionary.DictionaryItem));

            Assert.IsTrue(parent.IsTopMostItem());
            Assert.IsFalse(child.IsTopMostItem());

            DeleteItem(child);
            DeleteItem(parent);
        }
예제 #13
0
        public void Dictionary_ToXml()
        {
            var d = CreateNew();

            //create a child
            var childId = Dictionary.DictionaryItem.addKey("Test" + Guid.NewGuid().ToString("N"), "", d.key);
            Assert.IsTrue(childId > 0);
            var child = new Dictionary.DictionaryItem(childId);
			Assert.IsTrue(TypeHelper.IsTypeAssignableFrom<Dictionary.DictionaryItem>(child));
            
            var xml = new XmlDocument();

            var output = d.ToXml(xml);

            Assert.AreEqual("DictionaryItem", output.Name);
            Assert.IsTrue(output.HasChildNodes);
            Assert.IsNotNull(output.Attributes["Key"].Value);
            Assert.AreEqual(1, output.ChildNodes.OfType<XmlElement>().Where(x => x.Name == "DictionaryItem").Count());

            DeleteItem(child);
            DeleteItem(d);
        }
예제 #14
0
        private string dictinaryItem(string alias)
        {
            if (alias.Substring(1, 0) == "#")
            {

                if (Dictionary.DictionaryItem.hasKey(alias.Substring(1)))
                {

                    Dictionary.DictionaryItem di = new Dictionary.DictionaryItem(alias.Substring(1));

                    if (di != null && !string.IsNullOrEmpty(di.Value()))
                        return di.Value();
                }

            }

            return alias + " " + alias.Substring(1);
        }
예제 #15
0
        private Dictionary.DictionaryItem CreateNew()
        {
            var id = Dictionary.DictionaryItem.addKey("Test" + Guid.NewGuid().ToString("N"), "");
            Assert.IsTrue(id > 0);

            var d = new Dictionary.DictionaryItem(id);
            Assert.IsInstanceOfType(d, typeof(Dictionary.DictionaryItem));

            return d;
        }
예제 #16
0
파일: EazyD.ascx.cs 프로젝트: nikri/EazyD
        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);
                }

            }
        }
예제 #17
0
		static string DictionaryReplace(string text)
		{
			if (!text.StartsWith("#"))
				return text;
			else
			{
				Language lang = Language.GetByCultureCode(System.Threading.Thread.CurrentThread.CurrentCulture.Name);
				if (lang != null)
				{
					if (Dictionary.DictionaryItem.hasKey(text.Substring(1, text.Length - 1)))
					{
						Dictionary.DictionaryItem di = new Dictionary.DictionaryItem(text.Substring(1, text.Length - 1));
						return di.Value(lang.id);
					}
				}

				return "[" + text + "]";
			}
		}
예제 #18
0
        public ActionResult GetDictionaryItemKey(int id)
        {
            var d = new Dictionary.DictionaryItem(id);

            return Json(new { d = d.key});
        }
예제 #19
0
        /// <summary>
        /// Gets the dictionary item with the specified key and it's child dictionary items.
        /// The language version is based on the culture of the current Url.
        /// </summary>
        /// <param name="Key">The key.</param>
        /// <returns>A XpathNodeIterator in the format:
        /// <DictionaryItems>
        ///     <DictionaryItem key="[dictionaryItemKey]">[dictionaryItemValue]</DictionaryItem>
        /// </DictionaryItems>
        /// </returns>
        public static XPathNodeIterator GetDictionaryItems(string Key)
        {
            XmlDocument xd = new XmlDocument();
            xd.LoadXml("<DictionaryItems/>");

            try
            {
                //int languageId = GetCurrentLanguageId();
                int languageId = Language.GetByCultureCode(System.Threading.Thread.CurrentThread.CurrentUICulture.Name).id;

                Dictionary.DictionaryItem di = new Dictionary.DictionaryItem(Key);

                foreach (Dictionary.DictionaryItem item in di.Children)
                {
                    XmlNode xe;
                    try
                    {
                        if (languageId != 0)
                            xe = xmlHelper.addTextNode(xd, "DictionaryItem", item.Value(languageId));
                        else
                            xe = xmlHelper.addTextNode(xd, "DictionaryItem", item.Value());
                    }
                    catch
                    {
                        xe = xmlHelper.addTextNode(xd, "DictionaryItem", string.Empty);
                    }
                    xe.Attributes.Append(xmlHelper.addAttribute(xd, "key", item.key));
                    xd.DocumentElement.AppendChild(xe);
                }
            }
            catch (Exception ee)
            {
                xd.DocumentElement.AppendChild(
                    xmlHelper.addTextNode(xd, "Error", ee.ToString()));
            }

            XPathNavigator xp = xd.CreateNavigator();
            return xp.Select("/");
        }
예제 #20
0
        public void Dictionary_Contructor_Key()
        {
            var d = CreateNew();

            var same = new Dictionary.DictionaryItem(d.key);

            Assert.AreEqual(d.id, same.id);
            Assert.AreEqual(d.key, same.key);
            Assert.AreEqual(d.UniqueId, same.UniqueId);

            DeleteItem(d);
        }