public void AttributeDictionary_Add_DuplicateKey() { // Arrange var attributes = new AttributeDictionary(); attributes.Add("zero", "0"); attributes.Add("one", "1"); attributes.Add("two", "2"); // Act & Assert Assert.Throws<InvalidOperationException>(() => attributes.Add("one", "15")); }
public void AttributeDictionary_Clear() { // Arrange var attributes = new AttributeDictionary(); attributes.Add(new KeyValuePair<string, string>("zero", "0")); attributes.Add(new KeyValuePair<string, string>("one", "1")); attributes.Add(new KeyValuePair<string, string>("two", "2")); // Act attributes.Clear(); // Assert Assert.Equal(0, attributes.Count); Assert.Empty(attributes); }
public void AttributeDictionary_AddItems_AsKeyValuePairs() { // Arrange var attributes = new AttributeDictionary(); // Act attributes.Add(new KeyValuePair<string, string>("zero", "0")); attributes.Add(new KeyValuePair<string, string>("one", "1")); attributes.Add(new KeyValuePair<string, string>("two", "2")); // Assert Assert.Equal(3, attributes.Count); Assert.Collection( attributes, kvp => Assert.Equal(new KeyValuePair<string, string>("one", "1"), kvp), kvp => Assert.Equal(new KeyValuePair<string, string>("two", "2"), kvp), kvp => Assert.Equal(new KeyValuePair<string, string>("zero", "0"), kvp)); }
public void AttributeDictionary_CaseInsensitive() { // Arrange var attributes = new AttributeDictionary(); attributes.Add(new KeyValuePair<string, string>("zero", "0")); attributes.Add(new KeyValuePair<string, string>("one", "1")); attributes.Add(new KeyValuePair<string, string>("two", "2")); // Act attributes["oNe"] = "1!"; // Assert Assert.Equal(3, attributes.Count); Assert.Collection( attributes, kvp => Assert.Equal(new KeyValuePair<string, string>("oNe", "1!"), kvp), kvp => Assert.Equal(new KeyValuePair<string, string>("two", "2"), kvp), kvp => Assert.Equal(new KeyValuePair<string, string>("zero", "0"), kvp)); }
public void AttributeDictionary_Remove_Failure() { // Arrange var attributes = new AttributeDictionary(); attributes.Add(new KeyValuePair <string, string>("zero", "0")); attributes.Add(new KeyValuePair <string, string>("one", "1")); attributes.Add(new KeyValuePair <string, string>("two", "2")); // Act var result = attributes.Remove("nada"); // Assert Assert.False(result); Assert.Equal(3, attributes.Count); Assert.Collection( attributes, kvp => Assert.Equal(new KeyValuePair <string, string>("one", "1"), kvp), kvp => Assert.Equal(new KeyValuePair <string, string>("two", "2"), kvp), kvp => Assert.Equal(new KeyValuePair <string, string>("zero", "0"), kvp)); }
public override AttributeDictionary Convert(string value, AttributeDictionary attributes, XmlElement xmlElement) { var result = new AttributeDictionary(); // if allowDragging has been set, then raycastTarget must also be true (unless specified otherwise by the user) if (value.ToBoolean() && !attributes.ContainsKey("raycastTarget")) { result.Add("raycastTarget", "true"); } return(result); }
public void AttributeDictionary_Indexer_Insert() { // Arrange var attributes = new AttributeDictionary(); attributes.Add(new KeyValuePair <string, string>("zero", "0")); attributes.Add(new KeyValuePair <string, string>("one", "1")); attributes.Add(new KeyValuePair <string, string>("two", "2")); // Act attributes["exciting!"] = "1!"; // Assert Assert.Equal(4, attributes.Count); Assert.Collection( attributes, kvp => Assert.Equal(new KeyValuePair <string, string>("exciting!", "1!"), kvp), kvp => Assert.Equal(new KeyValuePair <string, string>("one", "1"), kvp), kvp => Assert.Equal(new KeyValuePair <string, string>("two", "2"), kvp), kvp => Assert.Equal(new KeyValuePair <string, string>("zero", "0"), kvp)); }
protected override void InitOperationResults() { AttributeDictionary dictionary = or; dictionary.selfEnumName = "DistributedAlgorithms.Algorithms.Snapshots.ChandyLamport_NewStyle.p+ork"; dictionary.Add(p.ork.Weight, new Attribute { Value = 0, Changed = false }); dictionary.Add(p.ork.Results, new Attribute { Value = Init_ork_Results(), Changed = false }); dictionary.Add(p.ork.ReceivedMessageFrom, new Attribute { Value = Init_ork_ReceivedMessageFrom(), Changed = false }); dictionary.Add(p.ork.Snapshot, new Attribute { Value = "", Changed = false }); dictionary.Add(p.ork.StatusColor, new Attribute { Value = "Not Set", Changed = false }); dictionary.Add(p.ork.Recorderd, new Attribute { Value = false, Changed = false }); base.InitOperationResults(); }
public void AttributeDictionary_CopyTo() { // Arrange var attributes = new AttributeDictionary(); attributes.Add(new KeyValuePair <string, string>("zero", "0")); attributes.Add(new KeyValuePair <string, string>("one", "1")); attributes.Add(new KeyValuePair <string, string>("two", "2")); var array = new KeyValuePair <string, string> [attributes.Count + 1]; // Act attributes.CopyTo(array, 1); // Assert Assert.Collection( array, kvp => Assert.Equal(default(KeyValuePair <string, string>), kvp), kvp => Assert.Equal(new KeyValuePair <string, string>("one", "1"), kvp), kvp => Assert.Equal(new KeyValuePair <string, string>("two", "2"), kvp), kvp => Assert.Equal(new KeyValuePair <string, string>("zero", "0"), kvp)); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public static Attribute EmptyMessageData() /// /// \brief Empty message data. /// /// \par Description. /// - This method is used to add an empty message to the list (with default values) /// - This method is used by the GUI to create an empty entry to the list /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 09/05/2018 /// /// \return An Attribute. //////////////////////////////////////////////////////////////////////////////////////////////////// public static Attribute EmptyMessageData() { AttributeDictionary messageData = new AttributeDictionary(); Type messageTypeEnum = ClassFactory.GenerateMessageTypeEnum(); dynamic type = Enum.ToObject(messageTypeEnum, 0); messageData.Add(Comps.Type, new Attribute { Value = type }); messageData.Add(Comps.Name, new Attribute { Value = "BaseMessage" }); messageData.Add(Comps.Fields, new Attribute { Value = new AttributeDictionary() }); messageData.Add(Comps.Targets, new Attribute { Value = new AttributeList(), ElementWindowPrmsMethod = IntListPrms }); return(new Attribute { Value = messageData, Editable = false }); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public void RecordOrderChange(List<int> permutations, int sourceProcess) /// /// \brief Record order change. /// /// \par Description. /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 27/05/2018 /// /// \param permutations (List<int>) - The permutations. /// \param sourceProcess (int) - Source process. //////////////////////////////////////////////////////////////////////////////////////////////////// public void RecordOrderChange(List <int> permutations, int sourceProcess) { // Extract messages of the channel from the messageQ MessageQ messageQ = Element.or[bp.ork.MessageQ]; AttributeList channelMessages; messageQ.ExstractChannelMessages(sourceProcess, out channelMessages); AttributeDictionary changeRecord = new AttributeDictionary(); changeRecord.Add(Comps.SourceProcess, new Attribute { Value = sourceProcess, Editable = false }); changeRecord.Add(Comps.MessageQ, new Attribute { Value = channelMessages, Editable = false }); changeRecord.Add(Comps.Permutations, new Attribute { Value = permutations.ToAttributeList(), Editable = false }); Add(new Attribute { Value = changeRecord, Editable = false }); }
public AttributeDictionary MessageDataFor_Marker(bm.PrmSource prmSource = bm.PrmSource.Default, AttributeDictionary dictionary = null, System.Double weight = 0) { if (prmSource == bm.PrmSource.MainPrm) { return(dictionary); } dictionary = new AttributeDictionary(); if (prmSource == bm.PrmSource.Default) { dictionary.Add(m.marker.Weight, new Attribute { Value = 0, Changed = false }); return(dictionary); } dictionary.Add(m.marker.Weight, new Attribute { Value = weight, Changed = false }); return(dictionary); }
public AttributeDictionary MessageDataFor_Wave(bm.PrmSource prmSource, AttributeDictionary dictionary = null, System.Int32 parent = 0) { if (prmSource == bm.PrmSource.MainPrm) { return(dictionary); } dictionary = new AttributeDictionary(); if (prmSource == bm.PrmSource.Default) { dictionary.Add(m.wave.Parent, new Attribute { Value = 0 }); return(dictionary); } dictionary.Add(m.wave.Parent, new Attribute { Value = parent }); return(dictionary); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public void AddMessage(dynamic type, string name, AttributeDictionary fields, AttributeList targets) /// /// \brief Adds a message. /// /// \par Description. /// - Add a new message containing message data /// - This method is used to add message from the code /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 09/05/2018 /// /// \param type (dynamic) - The type. /// \param name (string) - The name. /// \param fields (AttributeDictionary) - The fields. /// \param targets (AttributeList) - The targets. //////////////////////////////////////////////////////////////////////////////////////////////////// public void AddMessage(dynamic type, string name, AttributeDictionary fields, AttributeList targets) { AttributeDictionary messageData = new AttributeDictionary(); messageData.Add(Comps.Type, new Attribute { Value = type }); messageData.Add(Comps.Name, new Attribute { Value = name }); messageData.Add(Comps.Fields, new Attribute { Value = fields }); messageData.Add(Comps.Targets, new Attribute { Value = targets, ElementWindowPrmsMethod = IntListPrms }); Add(new Attribute { Value = messageData, Editable = false }); }
public static AttributeDictionary ToAttributeDictionary(this IDictionary <string, string>?dictionary) { var attributeDictionary = new AttributeDictionary(); if (dictionary != null) { foreach (var kvp in dictionary) { attributeDictionary.Add(kvp.Key, kvp.Value); } } return(attributeDictionary); }
public AttributeDictionary MessageDataFor_Presnp(bm.PrmSource prmSource = bm.PrmSource.Default, AttributeDictionary dictionary = null, System.Double numMsg = 0) { if (prmSource == bm.PrmSource.MainPrm) { return(dictionary); } dictionary = new AttributeDictionary(); dictionary.selfEnumName = "DistributedAlgorithms.Algorithms.Snapshots.LaiYoung_OneRound.m+ork_presnp"; if (prmSource == bm.PrmSource.Default) { dictionary.Add(m.presnp.NumMsg, new Attribute { Value = 0, Changed = false }); return(dictionary); } dictionary.Add(m.presnp.NumMsg, new Attribute { Value = numMsg, Changed = false }); return(dictionary); }
public static AttributeDictionary ToAttributesDictionary( this IDictionary <string, object> attributes) { var attributeDictionary = new AttributeDictionary(); if (attributes != null) { foreach (var kvp in attributes) { attributeDictionary.Add(kvp.Key, AttributeValueToString(kvp.Value)); } } return(attributeDictionary); }
public static AttributeDictionary ToAttributeDictionary(this TagHelperAttributeList?list) { var attributeDictionary = new AttributeDictionary(); if (list != null) { foreach (var attribute in list) { attributeDictionary.Add( attribute.Name, attribute.ValueStyle == HtmlAttributeValueStyle.Minimized ? string.Empty : (attribute.Value ?? string.Empty).ToString()); } } return(attributeDictionary); }
internal protected override bool TryAddOrIgnoreAttribute(string name, string value, out string errorDescription) { errorDescription = ""; bool result = true; FtMetaSequenceRedirect.PropertyId id; if (SequenceRedirectPropertyIdFormatter.TryParseAttributeName(name, out id)) { switch (id) { case FtMetaSequenceRedirect.PropertyId.Index: int parsedIndex; if (FtStandardText.TryParse(value, out parsedIndex)) { explicitIndex = parsedIndex; } else { errorDescription = string.Format(Properties.Resources.SequenceRedirectReadElement_TryAddOrIgnoreAttribute_InvalidIndex, value); result = false; } break; case FtMetaSequenceRedirect.PropertyId.Type: int parsedType; if (SequenceRedirectTypeFormatter.TryParseAttributeValue(value, out parsedType)) { redirectType = parsedType; } else { errorDescription = string.Format(Properties.Resources.SequenceRedirectReadElement_TryAddOrIgnoreAttribute_InvalidType, value); result = false; } break; default: attributeDictionary.Add(id, value); break; } } return(result); }
public override void ApplyAttributes(AttributeDictionary attributesToApply) { if (currentXmlElement.HasAttribute("image") && !currentXmlElement.HasAttribute("raycastTarget")) { attributesToApply.Add("raycastTarget", "true"); currentXmlElement.SetAttribute("raycastTarget", "true"); } base.ApplyAttributes(attributesToApply); var padding = attributesToApply.GetValue <RectOffset>("padding"); if (padding != null) { var layoutGroup = primaryComponent as SimpleLayoutGroup; layoutGroup.padding = padding; layoutGroup.enabled = true; } }
public override AttributeDictionary Convert(string value, AttributeDictionary elementAttributes, XmlElement xmlElement) { var result = new AttributeDictionary() { { "sprite", value.Replace(".png", "") .Replace(".jpg", "") .Replace(".jpeg", "") .Replace(".bmp", "") .Replace(".psd", "") } }; if (!elementAttributes.ContainsKey("color")) { result.Add("color", "white"); } return(result); }
public static void MergeCssClass(this AttributeDictionary attributeDictionary, string value) { Guard.ArgumentNotNull(nameof(attributeDictionary), attributeDictionary); if (string.IsNullOrEmpty(value)) { return; } if (attributeDictionary.TryGetValue("class", out var currentValue)) { var classes = currentValue !.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (!classes.Contains(value, StringComparer.OrdinalIgnoreCase)) { attributeDictionary["class"] = value + " " + currentValue; } } else { attributeDictionary.Add("class", value); } }
public static AttributeDictionary <string, T> ToAttributeDictionary <T>(this MiniYaml yml, Func <string, string> keySelector, Func <MiniYaml, T> elementSelector) { var ret = new AttributeDictionary <string, T>(); foreach (var y in yml.Nodes) { var key = keySelector(y.Key); if (!String.IsNullOrEmpty(key)) { var element = elementSelector(y.Value); try { ret.Add(key, element); } catch (ArgumentException ex) { throw new InvalidDataException("Duplicate key '{0}' in {1}".F(y.Key, y.Location), ex); } } } return(ret); }
public AttributeDictionary MessageDataFor_Report(bm.PrmSource prmSource = bm.PrmSource.Default, AttributeDictionary dictionary = null, System.Double id = 0, System.String snapshot = "", System.Double weight = 0) { if (prmSource == bm.PrmSource.MainPrm) { return(dictionary); } dictionary = new AttributeDictionary(); if (prmSource == bm.PrmSource.Default) { dictionary.Add(m.report.Id, new Attribute { Value = 0, Changed = false }); dictionary.Add(m.report.Snapshot, new Attribute { Value = "", Changed = false }); dictionary.Add(m.report.Weight, new Attribute { Value = 0, Changed = false }); return(dictionary); } dictionary.Add(m.report.Id, new Attribute { Value = id, Changed = false }); dictionary.Add(m.report.Snapshot, new Attribute { Value = snapshot, Changed = false }); dictionary.Add(m.report.Weight, new Attribute { Value = weight, Changed = false }); return(dictionary); }
public void AttributeDictionary_Indexer_Success() { // Arrange var attributes = new AttributeDictionary(); attributes.Add(new KeyValuePair<string, string>("zero", "0")); attributes.Add(new KeyValuePair<string, string>("one", "1")); attributes.Add(new KeyValuePair<string, string>("two", "2")); // Act var value = attributes["two"]; // Assert Assert.Equal("2", value); }
public static void Add(this AttributeDictionary attributes, string key) => attributes.Add(key, key);
public void AttributeDictionary_ContainsKey_Failure() { // Arrange var attributes = new AttributeDictionary(); attributes.Add(new KeyValuePair<string, string>("zero", "0")); attributes.Add(new KeyValuePair<string, string>("one", "1")); attributes.Add(new KeyValuePair<string, string>("two", "2")); // Act var result = attributes.ContainsKey("one!"); // Assert Assert.False(result); }
public void AttributeDictionary_CopyTo() { // Arrange var attributes = new AttributeDictionary(); attributes.Add(new KeyValuePair<string, string>("zero", "0")); attributes.Add(new KeyValuePair<string, string>("one", "1")); attributes.Add(new KeyValuePair<string, string>("two", "2")); var array = new KeyValuePair<string, string>[attributes.Count + 1]; // Act attributes.CopyTo(array, 1); // Assert Assert.Collection( array, kvp => Assert.Equal(default(KeyValuePair<string, string>), kvp), kvp => Assert.Equal(new KeyValuePair<string, string>("one", "1"), kvp), kvp => Assert.Equal(new KeyValuePair<string, string>("two", "2"), kvp), kvp => Assert.Equal(new KeyValuePair<string, string>("zero", "0"), kvp)); }
public void AttributeDictionary_Contains_Success() { // Arrange var attributes = new AttributeDictionary(); attributes.Add(new KeyValuePair<string, string>("zero", "0")); attributes.Add(new KeyValuePair<string, string>("one", "1")); attributes.Add(new KeyValuePair<string, string>("two", "2")); // Act var result = attributes.Contains(new KeyValuePair<string, string>("zero", "0")); // Assert Assert.True(result); }
public void AttributeDictionary_Remove_KeyValuePair_Failure() { // Arrange var attributes = new AttributeDictionary(); attributes.Add(new KeyValuePair<string, string>("zero", "0")); attributes.Add(new KeyValuePair<string, string>("one", "1")); attributes.Add(new KeyValuePair<string, string>("two", "2")); // Act var result = attributes.Remove(new KeyValuePair<string, string>("one", "0")); // Assert Assert.False(result); Assert.Equal(3, attributes.Count); Assert.Collection( attributes, kvp => Assert.Equal(new KeyValuePair<string, string>("one", "1"), kvp), kvp => Assert.Equal(new KeyValuePair<string, string>("two", "2"), kvp), kvp => Assert.Equal(new KeyValuePair<string, string>("zero", "0"), kvp)); }
public override void ApplyAttributes(AttributeDictionary attributesToApply) { base.ApplyAttributes(attributesToApply); var inputField = primaryComponent as InputField; var textComponents = new List <Text> { inputField.textComponent }; if (inputField.placeholder != null) { var placeholderText = inputField.placeholder.GetComponent <Text>(); if (placeholderText != null) { textComponents.Add(placeholderText); } if (attributesToApply.ContainsKey("placeholdertext")) { placeholderText.text = StringExtensions.DecodeEncodedNonAsciiCharacters(attributesToApply["placeholdertext"]); } } foreach (var textComponent in textComponents) { var tagHandler = XmlLayoutUtilities.GetXmlTagHandler("Text"); tagHandler.SetInstance(textComponent.rectTransform, this.currentXmlLayoutInstance); var textAttributes = new AttributeDictionary( attributesToApply.Where(a => TextTagHandler.TextAttributes.Contains(a.Key, StringComparer.OrdinalIgnoreCase)) .ToDictionary(a => a.Key, b => b.Value)); if (attributesToApply.ContainsKey("textshadow")) { textAttributes.Add("shadow", attributesToApply["textshadow"]); } if (attributesToApply.ContainsKey("textoutline")) { textAttributes.Add("outline", attributesToApply["textoutline"]); } if (attributesToApply.ContainsKey("textcolor")) { textAttributes.Add("color", attributesToApply["textcolor"]); } if (attributesToApply.ContainsKey("textalignment")) { textAttributes.Add("alignment", attributesToApply["textalignment"]); } textAttributes.Remove("text"); if (attributesToApply.ContainsKey("textoffset")) { var offset = attributesToApply["textoffset"].ToRectOffset(); textAttributes.Add("offsetMin", String.Format("{0} {1}", offset.left, offset.bottom)); textAttributes.Add("offsetMax", String.Format("-{0} -{1}", offset.right, offset.top)); } tagHandler.ApplyAttributes(textAttributes); } }
public void AttributeDictionary_TryGetValue_Success() { // Arrange var attributes = new AttributeDictionary(); attributes.Add(new KeyValuePair<string, string>("zero", "0")); attributes.Add(new KeyValuePair<string, string>("one", "1")); attributes.Add(new KeyValuePair<string, string>("two", "2")); string value; // Act var result = attributes.TryGetValue("two", out value); // Assert Assert.True(result); Assert.Equal("2", value); }
public override void ApplyAttributes(AttributeDictionary attributes) { var pagedRectTagHandler = PagedRectTagHandler.CurrentPagedRectTagHandler; if (pagedRectTagHandler == null) { Debug.Log("[XmlLayout] Error: Pagination: Unable to locate PagedRect instance."); } else { var pagedRectInstance = pagedRectTagHandler.currentInstanceTransform.GetComponent <PagedRect>(); var sizeAttributes = new string[] { "width", "height" }; if (attributes.Any(a => sizeAttributes.Contains(a.Key))) { // try and preserve default positioning of the pagination container if width or height attributes are provided if (!attributes.ContainsKey("rectAlignment")) { if (pagedRectTagHandler.tagType.Contains("Vertical")) { attributes.Add("rectAlignment", "MiddleLeft"); } else { attributes.Add("rectAlignment", "LowerCenter"); } } var viewportRectTransform = (RectTransform)pagedRectInstance.GetComponentInChildren <Viewport>().transform; // try and resize the viewport if the pagination container size changes if (pagedRectTagHandler.tagType.Contains("Vertical")) { if (attributes.ContainsKey("width")) { var rectAlignment = attributes.GetValue("rectAlignment") ?? "MiddleLeft"; if (rectAlignment.Contains("Left")) { viewportRectTransform.offsetMin = new Vector2(attributes.GetValue <float>("width"), viewportRectTransform.offsetMin.y); viewportRectTransform.offsetMax = new Vector2(0, viewportRectTransform.offsetMax.y); } else if (rectAlignment.Contains("Right")) { viewportRectTransform.offsetMin = new Vector2(0, viewportRectTransform.offsetMin.y); viewportRectTransform.offsetMax = new Vector2(-attributes.GetValue <float>("width"), viewportRectTransform.offsetMax.y); } } } else { if (attributes.ContainsKey("height")) { var rectAlignment = attributes.GetValue("rectAlignment") ?? "LowerCenter"; if (rectAlignment.Contains("Lower")) { viewportRectTransform.offsetMin = new Vector2(viewportRectTransform.offsetMin.x, attributes.GetValue <float>("height")); viewportRectTransform.offsetMax = new Vector2(viewportRectTransform.offsetMax.x, 0); } else if (rectAlignment.Contains("Upper")) { viewportRectTransform.offsetMin = new Vector2(viewportRectTransform.offsetMin.x, 0); viewportRectTransform.offsetMax = new Vector2(viewportRectTransform.offsetMax.x, -attributes.GetValue <float>("height")); } } } } var pagination = pagedRectInstance.Pagination; var backupTransform = this.currentInstanceTransform; this.SetInstance(pagination.transform as RectTransform, this.currentXmlLayoutInstance); base.ApplyAttributes(attributes); this.SetInstance(backupTransform, this.currentXmlLayoutInstance); } }
public void AttributeDictionary_TryGetValue_Failure() { // Arrange var attributes = new AttributeDictionary(); attributes.Add(new KeyValuePair<string, string>("zero", "0")); attributes.Add(new KeyValuePair<string, string>("one", "1")); attributes.Add(new KeyValuePair<string, string>("two", "2")); string value; // Act var result = attributes.TryGetValue("nada", out value); // Assert Assert.False(result); Assert.Null(value); }
public override void ApplyAttributes(AttributeDictionary attributesToApply) { base.ApplyAttributes(attributesToApply); var dropdown = primaryComponent as Dropdown; var templateComponent = dropdown.template.GetComponent <Image>(); var itemTemplateComponent = dropdown.template.GetComponentInChildren <Toggle>(); var textComponent = dropdown.captionText; var textTagHandler = XmlLayoutUtilities.GetXmlTagHandler("Text"); textTagHandler.SetInstance(textComponent.rectTransform, this.currentXmlLayoutInstance); var textAttributes = new AttributeDictionary( attributesToApply.Where(a => TextTagHandler.TextAttributes.Contains(a.Key, StringComparer.OrdinalIgnoreCase)) .ToDictionary(a => a.Key, b => b.Value)); if (attributesToApply.ContainsKey("textshadow")) { textAttributes.Add("shadow", attributesToApply["textshadow"]); } if (attributesToApply.ContainsKey("textoutline")) { textAttributes.Add("outline", attributesToApply["textoutline"]); } if (attributesToApply.ContainsKey("textcolor")) { textAttributes.Add("color", attributesToApply["textcolor"]); } if (attributesToApply.ContainsKey("textalignment")) { textAttributes.Add("alignment", attributesToApply["textalignment"]); } textTagHandler.ApplyAttributes(textAttributes); // disable the XmlElement component, it can interfere with mouse clicks/etc. textComponent.GetComponent <XmlElement>().enabled = false; var xmlLayoutDropdown = dropdown.GetComponent <XmlLayoutDropdown>(); var arrow = xmlLayoutDropdown.Arrow; if (attributesToApply.ContainsKey("arrowimage")) { arrow.sprite = attributesToApply["arrowimage"].ToSprite(); } if (attributesToApply.ContainsKey("arrowcolor")) { arrow.color = attributesToApply["arrowcolor"].ToColor(); } // dropdownHeight property if (attributesToApply.ContainsKey("dropdownheight")) { dropdown.template.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, float.Parse(attributesToApply["dropdownheight"])); } // Apply text attributes to the item template var itemTemplate = xmlLayoutDropdown.ItemTemplate; var itemTagHandler = XmlLayoutUtilities.GetXmlTagHandler("Toggle"); var itemAttributes = attributesToApply.Clone(); if (attributesToApply.ContainsKey("itemheight")) { var itemHeight = float.Parse(attributesToApply["itemheight"]); (itemTemplate.transform as RectTransform).SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, itemHeight); // it's also necessary to set the height of the content transform, otherwise we end up with weird issues var contentTransform = templateComponent.GetComponentInChildren <ScrollRect>().content; contentTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, itemHeight); } if (attributesToApply.ContainsKey("checkcolor")) { itemAttributes.Add("togglecheckmarkcolor", attributesToApply["checkcolor"]); } if (attributesToApply.ContainsKey("checksize")) { itemAttributes.Add("togglecheckmarksize", attributesToApply["checksize"]); } if (attributesToApply.ContainsKey("checkimage")) { itemAttributes.Add("togglecheckmarkimage", attributesToApply["checkimage"]); } if (attributesToApply.ContainsKey("checkimagepreserveaspect")) { itemAttributes.Add("togglecheckmarkimagepreserveaspect", attributesToApply["checkimagepreserveaspect"]); } // don't attempt to apply data source attributes to the item template itemAttributes.Remove("vm-dataSource"); itemAttributes.Remove("vm-options"); itemAttributes.Remove("color"); itemAttributes.Remove("colors"); // this attribute is checked by the Toggle to see if changes to the background should be permitted // (used by regular toggles to center the background if there is no text) itemAttributes.Add("dontModifyBackground", ""); var itemXmlElement = itemTemplate.transform.GetComponent <XmlElement>(); if (itemXmlElement == null) { itemTagHandler.SetInstance(itemTemplate.transform as RectTransform, this.currentXmlLayoutInstance); itemTagHandler.ApplyAttributes(itemAttributes); itemXmlElement = itemTemplate.transform.GetComponent <XmlElement>(); } else { itemXmlElement.ApplyAttributes(itemAttributes); } if (itemXmlElement != null) { itemXmlElement.enabled = false; } if (attributesToApply.ContainsKey("itembackgroundcolors")) { itemTemplateComponent.colors = attributesToApply["itembackgroundcolors"].ToColorBlock(); } if (attributesToApply.ContainsKey("dropdownbackgroundcolor")) { dropdown.template.GetComponent <Image>().color = attributesToApply["dropdownbackgroundcolor"].ToColor(); } if (attributesToApply.ContainsKey("dropdownbackgroundimage")) { dropdown.template.GetComponent <Image>().sprite = attributesToApply["dropdownbackgroundimage"].ToSprite(); } if (attributesToApply.ContainsKey("itemtextcolor")) { var itemTextComponent = dropdown.itemText; itemTextComponent.color = attributesToApply["itemtextcolor"].ToColor(); } if (attributesToApply.ContainsKey("scrollbarcolors")) { xmlLayoutDropdown.DropdownScrollbar.colors = attributesToApply["scrollbarcolors"].ToColorBlock(); } if (attributesToApply.ContainsKey("scrollbarimage")) { xmlLayoutDropdown.DropdownScrollbar.image.sprite = attributesToApply["scrollbarimage"].ToSprite(); } if (attributesToApply.ContainsKey("scrollbarbackgroundcolor")) { xmlLayoutDropdown.DropdownScrollbar.GetComponent <Image>().color = attributesToApply["scrollbarbackgroundcolor"].ToColor(); } if (attributesToApply.ContainsKey("scrollbarbackgroundimage")) { xmlLayoutDropdown.DropdownScrollbar.GetComponent <Image>().sprite = attributesToApply["scrollbarbackgroundimage"].ToSprite(); } foreach (var attribute in attributesToApply) { SetPropertyValue(templateComponent, attribute.Key, attribute.Value); } // data source #if !ENABLE_IL2CPP if (attributesToApply.ContainsKey("vm-options")) { xmlLayoutDropdown.optionsDataSource = attributesToApply["vm-options"]; } if (attributesToApply.ContainsKey("vm-dataSource")) { HandleDataSourceAttribute(attributesToApply.GetValue("vm-dataSource"), attributesToApply.GetValue("vm-options")); } #endif }
public void AttributeDictionary_Indexer_Fails() { // Arrange var attributes = new AttributeDictionary(); attributes.Add(new KeyValuePair<string, string>("zero", "0")); attributes.Add(new KeyValuePair<string, string>("one", "1")); attributes.Add(new KeyValuePair<string, string>("two", "2")); // Act & Assert Assert.Throws<KeyNotFoundException>(() => attributes["nada"]); }
public override void ApplyAttributes(AttributeDictionary attributesToApply) { base.ApplyAttributes(attributesToApply); var toggle = primaryComponent as Toggle; var checkMark = toggle.graphic as Image; var textComponent = currentXmlElement.GetComponentInChildren <Text>(); if (textComponent != null && currentXmlElement.childElements.Count > 0) { var childAttributes = new AttributeDictionary(); var child = currentXmlElement.childElements.First(); if (child.tagType == "Text") { if (textComponent.gameObject != child.gameObject) { // Replace the original text component with the child element child.rectTransform.SetParent(textComponent.rectTransform.parent); if (Application.isPlaying) { GameObject.Destroy(textComponent.gameObject); } else { GameObject.DestroyImmediate(textComponent.gameObject); } textComponent = child.GetComponent <Text>(); if (!child.HasAttribute("alignment")) { childAttributes.Add("alignment", "MiddleLeft"); } } } #if TEXTMESHPRO_PRESENT else if (child.tagType == "TextMeshPro") { // Replace the original text component with the child element child.rectTransform.SetParent(textComponent.rectTransform.parent); if (Application.isPlaying) { GameObject.Destroy(textComponent.gameObject); } else { GameObject.DestroyImmediate(textComponent.gameObject); } if (!child.HasAttribute("alignment")) { childAttributes.Add("alignment", "Left"); } } #endif if (!child.HasAttribute("text")) { if (attributesToApply.ContainsKey("text")) { childAttributes.Add("text", attributesToApply["text"]); } else { // if the child has no text, and the parent has no text, disable the text component if (!currentXmlElement.HasAttribute("text")) { childAttributes.Add("active", "false"); } } } else { // override the parent value if need be attributesToApply.SetValue("text", child.GetAttribute("text")); } // default padding value as per standard toggle element if (!child.HasAttribute("padding")) { childAttributes.Add("padding", "23 5 2 1"); } if (!child.HasAttribute("flexibleWidth")) { childAttributes.Add("flexibleWidth", "1"); } if (childAttributes.Count > 0) { child.ApplyAttributes(childAttributes); } } if (attributesToApply.ContainsKey("checkcolor")) { checkMark.color = attributesToApply["checkcolor"].ToColor(currentXmlLayoutInstance); } var targetGraphic = toggle.targetGraphic as Image; if (attributesToApply.ContainsKey("togglewidth")) { var width = float.Parse(attributesToApply["togglewidth"]); /*targetGraphic.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width); * checkMark.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width); * * if (textComponent != null) * { * textComponent.rectTransform.localPosition = new Vector2(width, textComponent.rectTransform.localPosition.y); * }*/ var toggleLayoutElement = targetGraphic.GetComponent <LayoutElement>() ?? targetGraphic.gameObject.AddComponent <LayoutElement>(); toggleLayoutElement.preferredWidth = width; toggleLayoutElement.minWidth = width; } if (attributesToApply.ContainsKey("toggleheight")) { var height = float.Parse(attributesToApply["toggleheight"]); /*targetGraphic.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height); * checkMark.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height);*/ var toggleLayoutElement = targetGraphic.GetComponent <LayoutElement>() ?? targetGraphic.gameObject.AddComponent <LayoutElement>(); toggleLayoutElement.preferredHeight = height; toggleLayoutElement.minHeight = height; } if (ToggleGroupTagHandler.CurrentToggleGroupInstance != null) { var xmlLayoutToggleGroupInstance = ToggleGroupTagHandler.CurrentToggleGroupInstance; xmlLayoutToggleGroupInstance.AddToggle(toggle); xmlLayoutToggleGroupInstance.UpdateToggleElement(toggle); toggle.onValueChanged.AddListener((e) => { if (e) { var value = xmlLayoutToggleGroupInstance.GetValueForElement(toggle); xmlLayoutToggleGroupInstance.SetSelectedValue(value); } }); } // Text attributes if (textComponent != null) { var tagHandler = XmlLayoutUtilities.GetXmlTagHandler("Text"); tagHandler.SetInstance(textComponent.rectTransform, this.currentXmlLayoutInstance); var textAttributes = new AttributeDictionary( attributesToApply.Where(a => TextTagHandler.TextAttributes.Contains(a.Key, StringComparer.OrdinalIgnoreCase)) .ToDictionary(a => a.Key, b => b.Value)); if (attributesToApply.ContainsKey("textshadow")) { textAttributes.Add("shadow", attributesToApply["textshadow"]); } if (attributesToApply.ContainsKey("textoutline")) { textAttributes.Add("outline", attributesToApply["textoutline"]); } if (attributesToApply.ContainsKey("textcolor")) { textAttributes.Add("color", attributesToApply["textcolor"]); } tagHandler.ApplyAttributes(textAttributes); // disable the XmlElement component, it can interfere with mouse clicks/etc. textComponent.GetComponent <XmlElement>().enabled = false; // disable the text component if there is no text textComponent.gameObject.SetActive(!String.IsNullOrEmpty(textComponent.text)); } if (!attributesToApply.ContainsKey("text") && !currentXmlElement.attributes.ContainsKey("text")) { var background = (Image)toggle.targetGraphic; var backgroundTransform = background.rectTransform; if (!attributesToApply.ContainsKey("dontModifyBackground")) { backgroundTransform.anchorMin = new Vector2(0.5f, 0.5f); backgroundTransform.anchorMax = new Vector2(0.5f, 0.5f); backgroundTransform.anchoredPosition3D = new Vector3(0, 0, 0); } } if (attributesToApply.ContainsKey("togglebackgroundimage")) { targetGraphic.sprite = attributesToApply["togglebackgroundimage"].ToSprite(); } if (attributesToApply.ContainsKey("togglecheckmarkimage")) { checkMark.sprite = attributesToApply["togglecheckmarkimage"].ToSprite(); } if (attributesToApply.ContainsKey("togglecheckmarkimagepreserveaspect")) { checkMark.preserveAspect = attributesToApply["togglecheckmarkimagepreserveaspect"].ToBoolean(); } if (attributesToApply.ContainsKey("togglecheckmarksize")) { float checkSize = float.Parse(attributesToApply["togglecheckmarksize"]); //var checkMarkLayoutElement = checkMark.GetComponent<LayoutElement>(); //checkMarkLayoutElement.preferredWidth = checkSize; //checkMarkLayoutElement.preferredHeight = checkSize; checkMark.rectTransform.anchorMin = new Vector2(0.5f, 0.5f); checkMark.rectTransform.anchorMax = new Vector2(0.5f, 0.5f); checkMark.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, checkSize); checkMark.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, checkSize); } }
public void AttributeDictionary_Indexer_Insert() { // Arrange var attributes = new AttributeDictionary(); attributes.Add(new KeyValuePair<string, string>("zero", "0")); attributes.Add(new KeyValuePair<string, string>("one", "1")); attributes.Add(new KeyValuePair<string, string>("two", "2")); // Act attributes["exciting!"] = "1!"; // Assert Assert.Equal(4, attributes.Count); Assert.Collection( attributes, kvp => Assert.Equal(new KeyValuePair<string, string>("exciting!", "1!"), kvp), kvp => Assert.Equal(new KeyValuePair<string, string>("one", "1"), kvp), kvp => Assert.Equal(new KeyValuePair<string, string>("two", "2"), kvp), kvp => Assert.Equal(new KeyValuePair<string, string>("zero", "0"), kvp)); }
public override void ApplyAttributes(AttributeDictionary attributesToApply) { base.ApplyAttributes(attributesToApply); var xmlLayoutButton = currentInstanceTransform.GetComponent <XmlLayoutButton>(); var textComponent = currentInstanceTransform.GetComponentInChildren <Text>(true); bool applyTextAttributesFromButton = true; ColorBlock textColors = new ColorBlock() { normalColor = Color.black, highlightedColor = Color.black, disabledColor = Color.black, pressedColor = Color.black, colorMultiplier = 1 }; if (attributesToApply.ContainsKey("textcolors")) { textColors = attributesToApply["textcolors"].ToColorBlock(currentXmlLayoutInstance); } else if (attributesToApply.ContainsKey("textcolor") || attributesToApply.ContainsKey("deselectedtextcolor")) { // draw the text colors from the textColor attribute var textColor = (attributesToApply.ContainsKey("textcolor") ? attributesToApply["textcolor"] : attributesToApply["deselectedtextcolor"]).ToColor(currentXmlLayoutInstance); SetColorBlockColor(ref textColors, textColor); } if (currentXmlElement.childElements.Count > 0) { var child = currentXmlElement.childElements.First(); if (child.tagType == "Text") { if (child.gameObject != textComponent.gameObject) { // Replace the original text component with the child element child.rectTransform.SetParent(textComponent.rectTransform.parent); if (Application.isPlaying) { GameObject.Destroy(textComponent.gameObject); } else { GameObject.DestroyImmediate(textComponent.gameObject); } textComponent = child.GetComponent <Text>(); } applyTextAttributesFromButton = false; if (child.attributes.ContainsKey("color")) { SetColorBlockColor(ref textColors, textComponent.color); } xmlLayoutButton.TextComponent = new TextComponentWrapper(textComponent); } #if TEXTMESHPRO_PRESENT else if (child.tagType == "TextMeshPro") { if (textComponent != null && child.gameObject != textComponent.gameObject) { // Replace the original text component with the child element child.rectTransform.SetParent(textComponent.rectTransform.parent); if (Application.isPlaying) { GameObject.Destroy(textComponent.gameObject); } else { GameObject.DestroyImmediate(textComponent.gameObject); } } var textMeshPro = child.GetComponent <TextMeshProUGUI>(); applyTextAttributesFromButton = false; if (child.attributes.ContainsKey("color")) { SetColorBlockColor(ref textColors, textMeshPro.color); } xmlLayoutButton.TextComponent = new TextComponentWrapper(textMeshPro); } #endif if (!child.attributes.ContainsKey("text") && attributesToApply.ContainsKey("text")) { child.SetAndApplyAttribute("text", attributesToApply["text"]); } child.rectTransform.localScale = Vector3.one; } else { xmlLayoutButton.TextComponent = new TextComponentWrapper(textComponent); } if (applyTextAttributesFromButton) { var tagHandler = XmlLayoutUtilities.GetXmlTagHandler("Text"); tagHandler.SetInstance(textComponent.rectTransform, this.currentXmlLayoutInstance); var textAttributes = new AttributeDictionary( attributesToApply.Where(a => TextTagHandler.TextAttributes.Contains(a.Key, StringComparer.OrdinalIgnoreCase)) .ToDictionary(a => a.Key, b => b.Value)); if (attributesToApply.ContainsKey("textshadow")) { textAttributes.Add("shadow", attributesToApply["textshadow"]); } if (attributesToApply.ContainsKey("textoutline")) { textAttributes.Add("outline", attributesToApply["textoutline"]); } if (attributesToApply.ContainsKey("textcolor")) { textAttributes.Add("color", attributesToApply["textcolor"]); } if (attributesToApply.ContainsKey("textalignment")) { textAttributes.Add("alignment", attributesToApply["textalignment"]); } tagHandler.ApplyAttributes(textAttributes); } // preserve aspect for button background var imageComponent = currentInstanceTransform.GetComponent <Image>(); if (attributesToApply.ContainsKey("preserveaspect")) { imageComponent.preserveAspect = attributesToApply["preserveaspect"].ToBoolean(); } // Button image if (attributesToApply.ContainsKey("icon") || this.currentXmlElement.attributes.ContainsKey("icon")) { var cell = xmlLayoutButton.IconCell; // position the cell on the left or the right var alignmentParameter = attributesToApply.ContainsKey("iconAlignment") ? attributesToApply["iconAlignment"] : (currentXmlElement.attributes.ContainsKey("iconAlignment") ? currentXmlElement.attributes["iconAlignment"] : "Left"); var imageAlignment = (ButtonIconAlignment)Enum.Parse(typeof(ButtonIconAlignment), alignmentParameter); var buttonImageWidth = attributesToApply.ContainsKey("iconwidth") ? attributesToApply["iconwidth"].ToFloat() : currentXmlElement.attributes.ContainsKey("iconwidth") ? currentXmlElement.attributes["iconwidth"].ToFloat() : 0; xmlLayoutButton.ButtonTableLayout.ColumnWidths = new List <float>() { 0, 0 }; if (imageAlignment == ButtonIconAlignment.Left) { cell.transform.SetAsFirstSibling(); xmlLayoutButton.ButtonTableLayout.ColumnWidths[0] = buttonImageWidth; } else { cell.transform.SetAsLastSibling(); xmlLayoutButton.ButtonTableLayout.ColumnWidths[1] = buttonImageWidth; } xmlLayoutButton.IconComponent.preserveAspect = true; if (attributesToApply.ContainsKey("icon")) { xmlLayoutButton.IconComponent.sprite = attributesToApply["icon"].ToSprite(); } if (attributesToApply.ContainsKey("iconcolor")) { xmlLayoutButton.IconColor = attributesToApply["iconcolor"].ToColor(currentXmlLayoutInstance); } if (attributesToApply.ContainsKey("iconhovercolor")) { xmlLayoutButton.IconHoverColor = attributesToApply["iconhovercolor"].ToColor(currentXmlLayoutInstance); } if (attributesToApply.ContainsKey("icondisabledcolor")) { xmlLayoutButton.IconDisabledColor = attributesToApply["icondisabledcolor"].ToColor(currentXmlLayoutInstance); } if (attributesToApply.ContainsKey("iconimagetype")) { xmlLayoutButton.IconComponent.type = (Image.Type)Enum.Parse(typeof(Image.Type), attributesToApply["iconimagetype"]); } cell.gameObject.SetActive(true); // show or hide the text cell if there is (or is not) any text if ((!attributesToApply.ContainsKey("text") || String.IsNullOrEmpty(attributesToApply["text"])) && !currentXmlElement.attributes.ContainsKey("text")) { xmlLayoutButton.TextCell.gameObject.SetActive(false); } else { xmlLayoutButton.TextCell.gameObject.SetActive(true); } } if (attributesToApply.ContainsKey("padding")) { xmlLayoutButton.ButtonTableLayout.padding = attributesToApply["padding"].ToRectOffset(); } xmlLayoutButton.TextColors = textColors; XmlLayoutTimer.DelayedCall(0, () => { if (xmlLayoutButton.mouseIsOver) { xmlLayoutButton.OnPointerEnter(null); } else { xmlLayoutButton.OnPointerExit(null); } }, xmlLayoutButton); }
private void ReportArrived(BaseMessage report) { // Get attributes of the process AttributeDictionary receivedReportFrom = OperationResults.Value[OperationResultKeys.ReceivedReportFrom].Value; bool initiator = ElementAttributes.Value[BaseProcess.ElementAttributeKeys.Initiator].Value; int maxRound = PrivateAttributes.Value[PrivateAttributeKeys.NumberOfRounds].Value; int processId = ElementAttributes.Value[NetworkElement.ElementAttributeKeys.Id].Value; int processSnapshot = OperationResults.Value[OperationResultKeys.Snapshot].Value; int processRound = OperationResults.Value[OperationResultKeys.RoundNum].Value; double processWeight = OperationResults.Value[OperationResultKeys.Weight].Value; AttributeDictionary processMessagesArived = OperationResults.Value[OperationResultKeys.MessagesReceived].Value; // Get attributes of the message double messageWeight = report.GetField(ChandyLamportMessage.FieldKeys.Weight).Value; int messageId = report.GetField(ChandyLamportMessage.FieldKeys.Id).Value; int messageSnapshot = report.GetField(ChandyLamportMessage.FieldKeys.Snapshots).Value; int messageRound = report.GetHeaderField(BaseMessage.HeaderFieldKeys.Round).Value; AttributeList listOfMessagesArrived = report.GetField(ChandyLamportMessage.FieldKeys.MessageSnapshot).Value; // The algorithm // If a message from the process arrived (in this round) // or the round advanced (which mees that the initiator got report from al the processor // throw the message if (!receivedReportFrom.Keys.Any(key => key == messageId) && processRound == messageRound) { receivedReportFrom.Add(messageId, new Attribute { Value = messageSnapshot }); processMessagesArived.Add(messageId, new Attribute { Value = listOfMessagesArrived }); if (initiator) { processWeight += messageWeight; if (processWeight == 1) { // Add the initiator's snapshot to the snapshot list receivedReportFrom.Add(processId, new Attribute { Value = processSnapshot }); // Collect the messages from the channels AttributeList messages = new AttributeList(); foreach (ChandyLamportChannel channel in InChannels()) { messages.Concat(channel.ReportChannelMessages()); } processMessagesArived.Add(processId, new Attribute { Value = messages }); // Report the snapshots PrintSnapshot(processRound, receivedReportFrom, processMessagesArived); // Start a new round processRound++; if (processRound < maxRound) { InitNewRound(processRound); } else { Terminate(); } } else { // Set the attributes for the initiator OperationResults.Value[OperationResultKeys.Weight].Value = processWeight; OperationResults.Value[OperationResultKeys.ReceivedReportFrom].Value = receivedReportFrom; } } else { SendToNeighbours(report, null); OperationResults.Value[OperationResultKeys.ReceivedReportFrom].Value = receivedReportFrom; } } }
public void AttributeDictionary_Values() { // Arrange var attributes = new AttributeDictionary(); attributes.Add(new KeyValuePair<string, string>("zero", "0")); attributes.Add(new KeyValuePair<string, string>("one", "1")); attributes.Add(new KeyValuePair<string, string>("two", "2")); // Act var values = attributes.Values; // Assert Assert.Equal(3, values.Count); Assert.Collection( values, key => Assert.Equal("1", key), key => Assert.Equal("2", key), key => Assert.Equal("0", key)); }
public static void Add(this AttributeDictionary attributes, string key, bool value) => attributes.Add(key, value.ToString().ToLower());