Exemple #1
0
        public static void AddAttributes(string @event, AttributeCollection attributes)
        {
            HttpBrowserCapabilities client      = HttpContext.Current.Request.Browser;
            BrowserType             browserType = _userAgentParser.Parse(client);

            switch (browserType)
            {
            case BrowserType.IE5Up:
            case BrowserType.IE6Up:
            case BrowserType.IE7Up:
                attributes.Add(@event, IEHomepageAction);
                break;

            case BrowserType.FireFox2:
            case BrowserType.Mozilla:
            case BrowserType.WebKit:
                attributes.Add(@event, MozHomepageAction);
                break;

            case BrowserType.Netscape:
                attributes.Add(@event, NSHomepageAction);
                break;

            default:
                attributes.Add(@event, DefaultHomepageAction);
                break;
            }

            return;
        }
Exemple #2
0
    public void TestGetFromGlobalCollection()
    {
        float experienceValue = 10.0f;
        float levelValue      = 3.0f;

        // Create test incoming attribute dictionary
        var incomingAttributeDictionary = new Dictionary <AttributeEnums.AttributeType, float> ()
        {
            { _experienceType, experienceValue },
            { _levelType, levelValue }
        };

        // Create "Global" dictionary
        _collection = new AttributeCollection();
        _collection.Add(_a1);
        _collection.Add(_a2);

        // Create new local collection
        AttributeCollection localCollection = new AttributeCollection();

        // Populate local collection with values from global one
        localCollection = AttributeCollection.GetFromGlobalCollection(incomingAttributeDictionary, _collection, localCollection);

        Attribute localExperienceAttribute = localCollection.Get(_experienceType);
        Attribute localLevelAttribute      = localCollection.Get(_levelType);

        // Verify that the deep copy worked
        Assert.AreNotSame(localExperienceAttribute, _collection.Get(_experienceType));
        Assert.AreNotSame(localLevelAttribute, _collection.Get(_levelType));

        // Verify the current values
        Assert.AreEqual(experienceValue, localExperienceAttribute.CurrentValue);
        Assert.AreEqual(levelValue, localLevelAttribute.CurrentValue);
    }
Exemple #3
0
        public void TestAddingExistingAttribute()
        {
            bool exceptionThrown;
            AttributeCollection attributes        = new AttributeCollection();
            AttributeValue      newAttributeValue = new AttributeValue("Test Value");

            // Add attribute and attribute value
            attributes.Add("Test", newAttributeValue);

            Assert.AreEqual <string>(newAttributeValue.Value, attributes["Test"].Value);

            AttributeValue existingAttributeValue = new AttributeValue("Test Value");

            try
            {
                attributes.Add("Test", existingAttributeValue);
                exceptionThrown = false;
            }
            catch (ArgumentException)
            {
                exceptionThrown = true;
            }

            Assert.IsTrue(exceptionThrown);
        }
        //--------------------------------------------------------------------------------------------------------------------------------------------------------------
        /// <summary>
        ///     22-Mar-2016 - DEPRECATED - Checked and no longer used ...
        /// </summary>
        public static void AddMouseOverEvents(AttributeCollection atts, string imageID, string srcImgPath, string imageFileName)
        {
            // check for tildas and default if found them
            if (srcImgPath != null && srcImgPath.Contains("~"))
            {
                srcImgPath = ImageRootDirectory;
            }

            // see if there is an attribute there already - if so, then append it
            if (atts["onmouseout"] != null && atts["onmouseout"] != "")
            {
                atts["onmouseout"] = atts["onmouseout"] + "document.getElementById('" + imageID + "').src='" + srcImgPath + imageFileName + "';";
            }
            else
            {
                atts.Add("onmouseout", "javascript:document.getElementById('" + imageID + "').src='" + srcImgPath + imageFileName + "';");
            }

            if (atts["onmouseover"] != null && atts["onmouseover"] != "")
            {
                atts["onmouseover"] = atts["onmouseover"] + "document.getElementById('" + imageID + "').src='" + srcImgPath + HTMLUtilities.GetHoverImageName(imageFileName) + "';";
            }
            else
            {
                atts.Add("onmouseover", "javascript:document.getElementById('" + imageID + "').src='" + srcImgPath + HTMLUtilities.GetHoverImageName(imageFileName) + "';");
            }
        }
        public void TestAddingExistingAttribute()
        {
            bool exceptionThrown;
            AttributeCollection attributes = new AttributeCollection();
            AttributeValue newAttributeValue = new AttributeValue("Test Value");

            // Add attribute and attribute value
            attributes.Add("Test", newAttributeValue);

            Assert.AreEqual<string>(newAttributeValue.Value, attributes["Test"].Value);

            AttributeValue existingAttributeValue = new AttributeValue("Test Value");

            try
            {
                attributes.Add("Test", existingAttributeValue);
                exceptionThrown = false;
            }
            catch (ArgumentException)
            {
                exceptionThrown = true;
            }

            Assert.IsTrue(exceptionThrown);
        }
Exemple #6
0
    public void TestDeepCopy()
    {
        _collection = new AttributeCollection();
        _collection.Add(_a1.Type, _a1);
        _collection.Add(_a2);

        // Make sure shallow copies are the same
        AttributeCollection shallowCopy = _collection;

        Assert.AreSame(_collection, shallowCopy);

        foreach (var attribute in _collection.GetAttributes())
        {
            Assert.AreEqual(attribute.Value.CurrentValue, shallowCopy.Get(attribute.Key).CurrentValue);
        }

        // Make sure deep copies are different
        AttributeCollection deepCopy = _collection.DeepCopy();

        deepCopy.Get(_a1.Type).CurrentValue = 40;
        deepCopy.Get(_a2.Type).CurrentValue = 4;

        Assert.AreNotSame(_collection, deepCopy);

        foreach (var attribute in _collection.GetAttributes())
        {
            Assert.AreNotEqual(attribute.Value.CurrentValue, deepCopy.Get(attribute.Key).CurrentValue);
        }
    }
Exemple #7
0
        /// <summary>
        /// Renders the beginning tag that wraps around the rendered HTML.
        /// This method uses the <see cref="OuterTag"/> property to determine the tag name.
        /// </summary>
        /// <returns>The beginning tag HTML code.</returns>
        public override string RenderBeginTag()
        {
            HtmlTextWriter      writer     = CreateHtmlTextWriter();
            AttributeCollection attributes = new AttributeCollection(new StateBag(true));

            string cssClass                = Settings.RadioButtonList.CssClass;
            string disabledCssClass        = Settings.RadioButtonList.DisabledCssClass;
            string repeatDirectionCssClass = Control.RepeatDirection.ToString().ToLowerInvariant();

            string allClasses = ConcatenateCssClasses(cssClass, repeatDirectionCssClass,
                                                      (Control.Enabled ? String.Empty : disabledCssClass), Control.CssClass);

            writer.WriteBeginTag(this.OuterTag);
            attributes.Add("id", Control.ClientID);

            if (!String.IsNullOrEmpty(allClasses))
            {
                attributes.Add("class", allClasses);
            }

            AddDefautAttributesToCollection(Control, attributes);
            WriteAttributes(writer, attributes);

            writer.WriteLine(HtmlTextWriter.TagRightChar);

            return(writer.InnerWriter.ToString());
        }
    public void TestLoadData()
    {
        // Setup attributes
        Attribute a1 = new Attribute(AttributeEnums.AttributeType.EXPERIENCE, "EXP", "EXP", "", 50, 0, 100);
        Attribute a2 = new Attribute(AttributeEnums.AttributeType.LEVEL, "LVL", "LVL", "", 5, 1, 10);

        _ac.Add(a1);
        _ac.Add(a2);

        // Setup inventory slots
        Item i1 = new Item(0, Item.ItemType.WEAPON, "weapon", "weapon description", "weapon", _ac, InventorySlots.SlotType.RIGHT_HAND, Item.ItemTier.TIER_5, "weapon.jpg", "swordSFX", "swordVFX");
        Item i2 = new Item(1, Item.ItemType.ARMOR, "armor", "aermor description", "armor", _ac, InventorySlots.SlotType.BODY, Item.ItemTier.TIER_3, "armor.jpg", "swordSFX", "swordVFX");

        _slots.Add(i1);
        _slots.Add(i2);

        // Setup abiltiies
        Ability ability1 = new Ability(0, Ability.AbilityType.ATTACK, "attack", "attack_description", "attackTooltop", "attackIconPath", "attackVfxPath", 0, 0, Ability.TargetTypeEnum.DEFAULT, null);
        Ability ability2 = new Ability(1, Ability.AbilityType.LAST_RESORT, "lr", "lrDescription", "lrTooltop", "lrIconPath", "lrVfxPath", 0, 0, Ability.TargetTypeEnum.DEFAULT, null);

        _abilityCollection.Add(ability1);
        _abilityCollection.Add(ability2);

        // Setup units
        _u1.FirstName           = "Leonard";
        _u1.LastName            = "Bedner";
        _u1.AttributeCollection = _ac;
        _u1.Class             = "Developer";
        _u1.InventorySlots    = _slots;
        _u1.AbilityCollection = _abilityCollection;
    }
        /// <summary>
        /// Removes references fields for pass 1 and all the others for pass 2.
        /// </summary>
        /// <param name="entity">Entity to process.</param>
        /// <param name="passNumber">Pass Number.</param>
        private void ProcessReferenceFields(EntityWrapper entity, int passNumber)
        {
            // Don't process manyTomany in pass 2
            if (entity.IsManyToMany && passNumber == (int)PassType.UpdateLookups)
            {
                return;
            }

            AttributeCollection newCollection = new AttributeCollection();

            foreach (KeyValuePair <string, object> item in entity.OriginalEntity.Attributes)
            {
                var idAliasKey = metCache.GetIdAliasKey(entity.OriginalEntity.LogicalName);

                if (item.Value != null && (item.Value is EntityReference || item.Value is EntityCollection || item.Value is AliasedValue))
                {
                    // For pass 2(Update Lookups) don't filter, add all attributes
                    if (passNumber == (int)PassType.UpdateLookups)
                    {
                        newCollection.Add(item);
                    }

                    // For pass 1 (CreateEntity) EntityReference and Alias
                    AddEntityReferenceAndAliasAttributesToCollection(passNumber, newCollection, item, idAliasKey);
                }
                else if ((passNumber == (int)PassType.CreateRequiredEntity) ||
                         (passNumber == (int)PassType.CreateEntity) ||
                         item.Key.StartsWith(idAliasKey, StringComparison.InvariantCulture))
                {
                    newCollection.Add(item);
                }
            }

            entity.OriginalEntity.Attributes = newCollection;
        }
Exemple #10
0
        /// <summary>
        /// Renders the beginning tag that wraps around the rendered HTML.
        /// </summary>
        /// <returns>The beginning tag HTML code.</returns>
        public override string RenderBeginTag()
        {
            HtmlTextWriter      writer     = CreateHtmlTextWriter();
            AttributeCollection attributes = new AttributeCollection(new StateBag(true));

            string cssClass         = Settings.Wizard.CssClass;
            string disabledCssClass = Settings.CheckBoxList.DisabledCssClass;

            string allClasses = ConcatenateCssClasses(
                cssClass,
                (Control.Enabled ? String.Empty : disabledCssClass),
                Control.CssClass);

            writer.WriteBeginTag("div");

            attributes.Add("id", Control.ClientID);
            if (!String.IsNullOrEmpty(allClasses))
            {
                attributes.Add("class", allClasses);
            }
            if (Control.TabIndex > 0)
            {
                attributes.Add("tabindex", Control.TabIndex.ToString());
            }

            AddDefautAttributesToCollection(Control, attributes);
            WriteAttributes(writer, attributes);

            writer.WriteLine(HtmlTextWriter.TagRightChar);

            return(writer.InnerWriter.ToString());
        }
Exemple #11
0
        private static AttributeCollection GetAttributes(CrmEntityBase crmEntity, PropertyHelper[] helpers)
        {
            var attributes      = new AttributeCollection();
            var relevantHelpers = helpers.Where(ph => ph.CRMFieldBaseAttribute != null);

            foreach (var helper in relevantHelpers)
            {
                var key        = helper.CRMFieldBaseAttribute.AttributeName;
                var modelValue = helper.GetValue(crmEntity);
                var value      = modelValue;

                if (helper.CRMFieldBaseAttribute.Type != CRMFieldType.Basic)
                {
                    value = GetCrmValue(helper.CRMFieldBaseAttribute, modelValue);
                }

                if (!ignoreNulls)
                {
                    attributes.Add(key, value);
                }
                else if (value != null)
                {
                    attributes.Add(key, value);
                }
            }
            return(attributes);
        }
Exemple #12
0
        /// <summary>
        /// Prepares the entity.
        /// </summary>
        /// <returns>Entity.</returns>
        public override AttributeCollection PrepareEntity()
        {
            AttributeCollection ac = new AttributeCollection();

            ac.Add("mwns_name", Name);
            ac.Add("mwns_identifier", Identifier);
            return(ac);
        }
Exemple #13
0
        /// <summary>
        /// Renders a menu item. Is used recursively to handle child menu items.
        /// </summary>
        /// <param name="writer">The <see cref="HtmlTextWriter"/> to use to generate HTML.</param>
        /// <param name="item">The menu item to render.</param>
        /// <param name="level">The level of this menu item (hierarchical level).</param>
        protected void RenderMenuItem(HtmlTextWriter writer, MenuItem item, int level)
        {
            bool   enabled  = (item.Enabled && Control.Enabled);
            string cssClass = (enabled ? String.Empty : Settings.Menu.DisabledCssClass);

            writer.Write("\t");
            writer.WriteBeginTag("li");
            if (!String.IsNullOrEmpty(cssClass))
            {
                writer.WriteAttribute("class", cssClass);
            }
            writer.Write(HtmlTextWriter.TagRightChar);

            AttributeCollection attributes = new AttributeCollection(new StateBag(true));

            writer.WriteBeginTag("a");

            if (!String.IsNullOrEmpty(item.ToolTip))
            {
                attributes.Add("title", item.ToolTip);
            }
            if (enabled && item.Selectable && Control.Page != null)
            {
                string href = this.Control.Page.ClientScript.GetPostBackClientHyperlink(Control, item.Value);
                attributes.Add("href", href);
            }
            WriteAttributes(writer, attributes);
            writer.Write(HtmlTextWriter.TagRightChar);
            writer.Write((String.IsNullOrEmpty(item.Text) ? item.Value : item.Text));

            writer.WriteEndTag("a");

            if (item.ChildItems != null && item.ChildItems.Count > 0 && level < (Control.StaticDisplayLevels + Control.MaximumDynamicDisplayLevels))
            {
                writer.WriteBeginTag("ul");
                if (level >= Control.StaticDisplayLevels)
                {
                    writer.WriteAttribute("class", "dynamic");
                }
                writer.Write(HtmlTextWriter.TagRightChar);
                writer.WriteLine();
                writer.Indent++;

                foreach (MenuItem innerItem in item.ChildItems)
                {
                    RenderMenuItem(writer, innerItem, level + 1);
                }

                writer.Indent--;
                writer.WriteEndTag("ul");
                writer.WriteLine();
            }

            writer.WriteEndTag("li");
            writer.WriteLine();
        }
        /// <summary>
        /// Prepares the entity.
        /// </summary>
        /// <returns>Entity.</returns>
        public override AttributeCollection PrepareEntity()
        {
            AttributeCollection ac = new AttributeCollection();

            ac.Add("mwns_name", Name);
            ac.Add("mwns_value", Value);
            ac.Add("mwns_securevalue", SecureValue);
            ac.Add("mwns_mawenssolutionid", new EntityReference("mwns_mawenssolution", SolutionId));
            return(ac);
        }
        public void Add_Duplicates_MixedCase_OneAttribute()
        {
            var attributes = new AttributeCollection();

            attributes.Add("assembly", "A");
            attributes.Add("ASSEMBLY", "a");

            Assert.Single(attributes);
            Assert.Single(attributes.First().Value);
        }
Exemple #16
0
        public void TestRemovingInvalidAttribute()
        {
            AttributeCollection attributes = new AttributeCollection();

            attributes.Add("Test1", new AttributeValue("Test Value1"));
            attributes.Add("Test2", new AttributeValue("Test Value2"));
            attributes.Add("Test3", new AttributeValue("Test Value3"));
            attributes.Add("Test4", new AttributeValue("Test Value4"));

            Assert.IsFalse(attributes.Remove("Test5"));
        }
    public void Setup()
    {
        Attribute range    = new Attribute(AttributeEnums.AttributeType.RANGE, "range", "rng", "range", 4.0f, 1.0f, 100.0f);
        Attribute aoeRange = new Attribute(AttributeEnums.AttributeType.AOE_RANGE, "aoeRange", "aoerng", "aoerange", 1.0f, 1.0f, 100.0f);

        _attributeCollection = new AttributeCollection();
        _attributeCollection.Add(range);
        _attributeCollection.Add(aoeRange);

        _ability1 = new Ability(0, Ability.AbilityType.MAGIC, "test_magic", "test_magic", "test_magic", "iconPath", "vfxPath", 1, 0, Ability.TargetTypeEnum.DEFAULT, _attributeCollection);
    }
        public void Add_Multiple_MultipleAttributes()
        {
            const int ExpectedAttributeCount = 2;

            var attributes = new AttributeCollection();

            attributes.Add("Assembly", "A");
            attributes.Add("Parameter", "B");

            Assert.Equal(ExpectedAttributeCount, attributes.Count);
        }
Exemple #19
0
        private Entity CreateCurrencyEntity(string currencyCode, Guid currencyId)
        {
            var attributes = new AttributeCollection();

            attributes.Add(CurrencyAttribute.CurrencyCode, currencyCode);
            attributes.Add(CurrencyAttribute.ExchangeRate, 1M);
            return(new Entity(CurrencyAttribute.EntityName)
            {
                Id = currencyId,
                Attributes = attributes
            });
        }
 protected override void OnPreRender(EventArgs e)
 {
     if (!string.IsNullOrEmpty(this.ViewModel))
     {
         if (this.ServiceUrl != null)
         {
             this["ServiceUrl"] = EcpUrl.ProcessUrl(this.ServiceUrl.ServiceUrl);
         }
         AttributeCollection bindingContextAttributes = this.GetBindingContextAttributes();
         bindingContextAttributes.Add("data-type", this.ViewModel);
         foreach (KeyValuePair <string, object> keyValuePair in this.dataContextProperties)
         {
             object value = keyValuePair.Value;
             string value2;
             if (value is string)
             {
                 value2 = (string)value;
             }
             else if (value is bool)
             {
                 value2 = value.ToString().ToLower();
             }
             else if (value is int || value is uint || value is long || value is ulong || value is float || value is double)
             {
                 value2 = value.ToString();
             }
             else
             {
                 value2 = "json:" + keyValuePair.Value.ToJsonString(DDIService.KnownTypes.Value);
             }
             bindingContextAttributes.Add("vm-" + keyValuePair.Key, value2);
         }
         if (bindingContextAttributes != base.Attributes)
         {
             List <string> list = new List <string>(base.Attributes.Count);
             foreach (object obj in base.Attributes.Keys)
             {
                 string text = obj as string;
                 if (text != null && text.StartsWith("vm-"))
                 {
                     bindingContextAttributes.Add(text, base.Attributes[text]);
                     list.Add(text);
                 }
             }
             foreach (string key in list)
             {
                 base.Attributes.Remove(key);
             }
         }
     }
     base.OnPreRender(e);
 }
Exemple #21
0
        public void TestCountingCollectionItems()
        {
            AttributeCollection attributes = new AttributeCollection();

            Assert.AreEqual <int>(0, attributes.Count);

            attributes.Add("Test1", new AttributeValue("Test Value1"));
            attributes.Add("Test2", new AttributeValue("Test Value2"));
            attributes.Add("Test3", new AttributeValue("Test Value3"));
            attributes.Add("Test4", new AttributeValue("Test Value4"));

            Assert.AreEqual <int>(4, attributes.Count);
        }
Exemple #22
0
    public void Setup()
    {
        Attribute range    = new Attribute(AttributeEnums.AttributeType.RANGE, "range", "rng", "range", 4.0f, 1.0f, 100.0f);
        Attribute aoeRange = new Attribute(AttributeEnums.AttributeType.AOE_RANGE, "aoeRange", "aoerng", "aoerange", 1.0f, 1.0f, 100.0f);

        _attributeCollection = new AttributeCollection();
        _attributeCollection.Add(range);
        _attributeCollection.Add(aoeRange);

        _ability1 = new Ability(0, Ability.AbilityType.MAGIC, "test_magic", "test_magic", "test_magic", "iconPath", "vfxPath", 1, 0, Ability.TargetTypeEnum.DEFAULT, _attributeCollection);
        _ability2 = new Ability(1, Ability.AbilityType.TALENT, "testTalent", "testTalent", "testTalent", "iconPath", "vfxPath", 1, 0, Ability.TargetTypeEnum.DEFAULT, _attributeCollection);
        _ability3 = new Ability(2, Ability.AbilityType.ATTACK, "testAttack", "testAttack", "testAttack", "iconPath", "vfxPath", 1, 0, Ability.TargetTypeEnum.DEFAULT, _attributeCollection);
        _ability4 = new Ability(3, Ability.AbilityType.MAGIC, "testMagic2", "testMagic2", "testMagic2", "iconPath", "vfxPath", 1, 0, Ability.TargetTypeEnum.DEFAULT, _attributeCollection);
        _ability5 = new Ability(4, Ability.AbilityType.TALENT, "testTalent2", "testTalent2", "testTalent2", "iconPath", "vfxPath", 1, 0, Ability.TargetTypeEnum.DEFAULT, _attributeCollection);
    }
Exemple #23
0
        protected override void CreateChildControls()
        {
            this.Controls.Clear();
            WebControl webControl = new WebControl(HtmlTextWriterTag.Input);

            if (!string.IsNullOrEmpty(base.CssClass))
            {
                webControl.Attributes.Add("class", base.CssClass);
            }
            if (!string.IsNullOrEmpty(this.BoxStyle))
            {
                webControl.Attributes.Add("style", this.BoxStyle);
            }
            webControl.Attributes.Add("id", "buyAmount");
            webControl.Attributes.Add("type", "text");
            AttributeCollection attributes = webControl.Attributes;
            int quantity = this.Quantity;

            attributes.Add("value", quantity.ToString(CultureInfo.InvariantCulture));
            WebControl webControl2 = new WebControl(HtmlTextWriterTag.Input);

            webControl2.Attributes.Add("id", "oldBuyNumHidden");
            webControl2.Attributes.Add("type", "hidden");
            AttributeCollection attributes2 = webControl2.Attributes;

            quantity = this.Quantity;
            attributes2.Add("value", quantity.ToString(CultureInfo.InvariantCulture));
            this.Controls.Add(webControl);
            this.Controls.Add(webControl2);
        }
Exemple #24
0
 /// <summary>
 /// Adds the confirm message JS.
 /// </summary>
 /// <param name="jsEvent">The js event.</param>
 /// <param name="attributeCollection">The attribute collection.</param>
 /// <param name="chekMessage">The chek message.</param>
 public static void AddConfirmMessageJS(string jsEvent, AttributeCollection attributeCollection, string chekMessage)
 {
     if (attributeCollection != null)
     {
         attributeCollection.Add(jsEvent, "return confirm('" + chekMessage + "');");
     }
 }
Exemple #25
0
    public void TestAddAndCount()
    {
        _collection = new AttributeCollection();

        // Test adding separate attributes
        _collection.Add(_a1.Type, _a1);
        _collection.Add(_a2);

        Assert.AreEqual(2, _collection.Count());

        // Test that you cannot add the same attributes more than once
        _collection.Add(_a1.Type, _a1);
        _collection.Add(_a2.Type, _a2);

        Assert.AreEqual(2, _collection.Count());
    }
Exemple #26
0
 public void AddAttribute(Attribute attribute)
 {
     _attributes.Add(attribute);
     //KeyedCollection will throw an exception
     //if there is already an attribute with
     //the same (case insensitive) name.
 }
Exemple #27
0
        public void AttributeCollectionCanBeSerializedAndDeserialized()
        {
            AttributeCollection attributeCollection = new AttributeCollection();

            attributeCollection.Add("Test", "test");

            JsonSerializer serializer = new JsonSerializer();

            serializer.TypeNameHandling = TypeNameHandling.Objects;
            serializer.Converters.Add(new AttributeCollectionConverter());
            MemoryStream memoryStream = new MemoryStream(new byte[9000], true);

            using (StreamWriter writer = new StreamWriter(memoryStream))
            {
                serializer.Serialize(new JsonTextWriter(writer), attributeCollection);
            }

            AttributeCollection deserializedAttributeCollection;

            memoryStream = new MemoryStream(memoryStream.ToArray());
            using (StreamReader reader = new StreamReader(memoryStream))
            {
                deserializedAttributeCollection = (AttributeCollection)serializer.Deserialize(new JsonTextReader(reader), typeof(AttributeCollection));
            }

            Assert.Equal(attributeCollection.GetType(), deserializedAttributeCollection.GetType());
            Assert.Equal(attributeCollection.Count, deserializedAttributeCollection.Count);
            Assert.Equal(attributeCollection.Keys.First(), deserializedAttributeCollection.Keys.First());
            Assert.Equal(attributeCollection.Values.First(), deserializedAttributeCollection.Values.First());
        }
        public static AttributeCollection Map(this PatientAddress patientAddress)
        {
            AttributeCollection attrCol = new AttributeCollection();

            if (patientAddress.StreetAddressLine != "" && patientAddress.State != "" && patientAddress.City != "" && patientAddress.State != "" && patientAddress.PostalCode != "")
            {
                attrCol.Add("crme_fulladdress", patientAddress.StreetAddressLine + " " + patientAddress.City + " " + patientAddress.State + " " + patientAddress.PostalCode);
            }

            attrCol.Add("crme_address1", patientAddress.StreetAddressLine);
            attrCol.Add("crme_city", patientAddress.City);
            attrCol.Add("crme_addressstate", patientAddress.State);
            attrCol.Add("crme_addresszip", patientAddress.PostalCode);

            return(attrCol);
        }
Exemple #29
0
        public virtual AttributeCollection CreateAttributeCollection(SlpReader reader)
        {
            var tmp = reader.ReadRawString();

            var result = new AttributeCollection();

            foreach (var item in tmp.Split(','))
            {
                var    pair = item.Split('=');
                string key = null, value = null;
                if (pair.Length == 1)
                {
                    key = reader.Unescape(pair[0]);
                }
                else if (pair.Length == 2)
                {
                    key   = reader.Unescape(pair[0]);
                    value = reader.Unescape(pair[1]);
                }
                else
                {
                    throw new ServiceProtocolException(ServiceErrorCode.ParseError);
                }

                result.Add(key, value);
            }

            return(result);
        }
Exemple #30
0
    public void TestGetSuccess()
    {
        _collection = new AttributeCollection();

        // Add some test attributes
        _collection.Add(_a1);
        _collection.Add(_a2.Type, _a2);

        // Fetch attributes
        Attribute actual1 = _collection.Get(_experienceType);
        Attribute actual2 = _collection.Get(_levelType);

        // Make sure attributes are the same
        Assert.AreEqual(_a1, actual1);
        Assert.AreEqual(_a2, actual2);
    }
Exemple #31
0
        public void DbItem_As_Media_Test()
        {
            var created = new DateTime(2012, 01, 01, 0, 0, 0, DateTimeKind.Utc);

            var item = new AttributeCollection {
                { "Transformation", "resize:500x500.jpeg" },
                { "Duration", 30000 },
                { "Created", new DateTimeOffset(created).ToUnixTimeSeconds() }
            };

            item.Add("Hash", new DbValue("FHX8PLDaGoI2hSlwjI1yFvqWTcQ=", DbValueType.B));

            var media = item.As <Media>();

            Assert.Equal("resize:500x500.jpeg", media.Transformation);
            Assert.Equal(TimeSpan.FromSeconds(30), media.Duration);
            Assert.Equal(Convert.FromBase64String("FHX8PLDaGoI2hSlwjI1yFvqWTcQ="), media.Hash);
            Assert.Equal(created, media.Created);

            var attributes = AttributeCollection.FromObject(media);

            Assert.Equal("resize:500x500.jpeg", attributes["Transformation"].Value.ToString());
            Assert.Equal(DbValueType.N, attributes["Duration"].Kind);
            Assert.Equal(DbValueType.N, attributes["Created"].Kind);
        }
        public void TestParse()
        {
            var saxHandler = new Mock<ISaxHandler>();

              using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
              {
            memoryStream.Write(new System.Text.UTF8Encoding().GetBytes(_xmlToParse), 0, _xmlToParse.Length);
            memoryStream.Position = 0;

            SaxReaderImpl saxReaderImpl = new SaxReaderImpl();
            saxReaderImpl.Parse(new System.IO.StreamReader(memoryStream), saxHandler.Object);
              }

              AttributeCollection element3Attributes = new AttributeCollection();
              Attribute attr1Attribute = new Attribute();
              attr1Attribute.LocalName = "attr1";
              attr1Attribute.QName = "attr1";
              attr1Attribute.Uri = string.Empty;
              attr1Attribute.Value = "val1";
              element3Attributes.Add("attr1", attr1Attribute);

              saxHandler.Verify(c => c.StartDocument(), Times.Exactly(1));
              saxHandler.Verify(c => c.EndDocument(), Times.Exactly(1));
              saxHandler.Verify(c => c.StartElement(string.Empty, "root", "root", new AttributeCollection()));
              saxHandler.Verify(c => c.StartElement(string.Empty, "element1", "element1", new AttributeCollection()));
              saxHandler.Verify(c => c.StartElement(string.Empty, "element2", "element2", new AttributeCollection()));
              saxHandler.Verify(c => c.StartElement(string.Empty, "element3", "element3", element3Attributes));
              saxHandler.Verify(c => c.EndElement(string.Empty, "root", "root"));
              saxHandler.Verify(c => c.EndElement(string.Empty, "element1", "element1"));
              saxHandler.Verify(c => c.EndElement(string.Empty, "element2", "element2"));
              saxHandler.Verify(c => c.EndElement(string.Empty, "element3", "element3"));
              saxHandler.Verify(c => c.Characters(It.IsAny<char[]>(), It.IsAny<int>(), It.IsAny<int>()));
        }
        public void TestAddingAttributeWithValue()
        {
            AttributeCollection attributes = new AttributeCollection();
            AttributeValue comparisonAttributeValue = new AttributeValue("Value");

            attributes.Add("Name", comparisonAttributeValue);

            Assert.AreEqual<string>(comparisonAttributeValue.Value, attributes["Name"].Value);
        }
Exemple #34
0
        public static void CreateStateFriendlyNameMetaField()
        {
            using (MetaClassManagerEditScope scope = DataContext.Current.MetaModel.BeginEdit())
            {
                MetaClass timeTrackingEntry = TimeTrackingEntry.GetAssignedMetaClass();

                AttributeCollection attr = new AttributeCollection();
                attr.Add(McDataTypeAttribute.StringMaxLength, 255);
                attr.Add(McDataTypeAttribute.StringIsUnique, false);
                attr.Add(McDataTypeAttribute.Expression,
                        @"SELECT TOP 1 TTBS.FriendlyName FROM cls_TimeTrackingBlock_State TTBS" + Environment.NewLine +
                        @"	JOIN cls_TimeTrackingBlock TTB ON " + Environment.NewLine +
                        @"	TTB.mc_StateId = TTBS.TimeTrackingBlock_StateId" + Environment.NewLine +
                        @"	AND" + Environment.NewLine +
                        @"	TTB.[TimeTrackingBlockId] = AAA.[ParentBlockId]");

                MetaField retVal = timeTrackingEntry.CreateMetaField("StateFriendlyName",
                    "State", MetaFieldType.Text, true, "''", attr);

                scope.SaveChanges();
            }
        }
        public void TestAddingWithNullAttribute()
        {
            bool exceptionThrown;
            AttributeCollection attributes = new AttributeCollection();
            AttributeValue comparisonAttributeValue = new AttributeValue("Value");

            try
            {
                attributes.Add(null, comparisonAttributeValue);
                exceptionThrown = false;
            }
            catch (ArgumentNullException)
            {
                exceptionThrown = true;
            }

            Assert.IsTrue(exceptionThrown);
        }
Exemple #36
0
        public virtual AttributeCollection CreateAttributeCollection(SlpReader reader)
        {
            var tmp = reader.ReadRawString();

            var result = new AttributeCollection();
            foreach (var item in tmp.Split(','))
            {
                var pair = item.Split('=');
                string key = null, value = null;
                if (pair.Length == 1)
                    key = reader.Unescape(pair[0]);
                else if (pair.Length == 2)
                {
                    key = reader.Unescape(pair[0]);
                    value = reader.Unescape(pair[1]);
                }
                else
                    throw new ServiceProtocolException(ServiceErrorCode.ParseError);

                result.Add(key, value);
            }

            return result;
        }
        public void TestUpdatingIdenticalAttribute()
        {
            AttributeCollection attributes = new AttributeCollection();
            AttributeValue newAttributeValue = new AttributeValue("Test Value");

            // Add attribute and attribute value
            attributes.Add("Test", newAttributeValue);

            Assert.AreEqual<string>(newAttributeValue.Value, attributes["Test"].Value);

            // Try updating the attribute with the same value
            attributes.Update("Test", newAttributeValue);

            // Ensure that the attribute has an updated value
            Assert.AreEqual<string>(newAttributeValue.Value, attributes["Test"].Value);
        }
        public void TestEnumeratingCollections()
        {
            AttributeCollection attributes = new AttributeCollection();

            Assert.AreEqual<int>(0, attributes.Count);

            attributes.Add("Test1", new AttributeValue("Test Value1"));
            attributes.Add("Test2", new AttributeValue("Test Value2"));
            attributes.Add("Test3", new AttributeValue("Test Value3"));
            attributes.Add("Test4", new AttributeValue("Test Value4"));

            int counter = 0;
            foreach (KeyValuePair<string, AttributeValue> kv in attributes)
            {
                System.Diagnostics.Debug.WriteLine(kv.ToString());
                counter++;
            }

            Assert.IsTrue(counter == 4);
        }
Exemple #39
0
        /// <summary>
        /// Creates the new meta field.
        /// </summary>
        /// <param name="column">The column.</param>
        /// <returns></returns>
        public static MetaField CreateNewMetaField(DataColumn column)
        {
            if (column == null)
                throw new ArgumentNullException("column");

            MetaField retVal = null;

            string name = GetFieldName(column);
            string friendlyName = string.IsNullOrEmpty(column.ColumnName) ? name : column.ColumnName; // TODO:
            bool isNullable = column.AllowDBNull;// true;

            if (column.DataType == typeof(Int32) ||
                column.DataType == typeof(Int16))
            {
                #region MetaFieldType.Integer
                AttributeCollection attr = new AttributeCollection();
                string strDefaultValue = "0";

                retVal = CreateNewMetaField(name, friendlyName, MetaFieldType.Integer, isNullable, strDefaultValue, attr);

                #endregion
            }
            else if (column.DataType == typeof(Double) ||
                column.DataType == typeof(Single))
            {
                #region MetaFieldType.Float
                AttributeCollection attr = new AttributeCollection();
                string strDefaultValue = "0";

                attr.Add(McDataTypeAttribute.DecimalPrecision, 18);
                attr.Add(McDataTypeAttribute.DecimalScale, 4);

                retVal = CreateNewMetaField(name, friendlyName, MetaFieldType.Decimal, isNullable, strDefaultValue, attr);

                #endregion
            }
            else if (column.DataType == typeof(DateTime))
            {
                #region MetaFieldType.DateTime
                AttributeCollection attr = new AttributeCollection();
                string defaultValue = isNullable ? string.Empty : "getutcdate()";

                //Attr.Add(McDataTypeAttribute.DateTimeMinValue, minValue);
                //Attr.Add(McDataTypeAttribute.DateTimeMaxValue, maxValue);
                //attr.Add(McDataTypeAttribute.DateTimeUseUserTimeZone, useUserTimeZone);

                retVal = CreateNewMetaField(name, friendlyName, MetaFieldType.DateTime, isNullable, defaultValue, attr);

                #endregion
            }
            else if (column.DataType == typeof(Boolean))
            {
                #region MetaFieldType.CheckboxBoolean
                AttributeCollection attr = new AttributeCollection();
                string strDefaultValue = "0";

                attr.Add(McDataTypeAttribute.BooleanLabel, friendlyName);

                retVal = CreateNewMetaField(name, friendlyName, MetaFieldType.CheckboxBoolean, isNullable, strDefaultValue, attr);

                #endregion
            }
            else if (column.DataType == typeof(Guid))
            {
                #region MetaFieldType.Guid
                AttributeCollection attr = new AttributeCollection();
                string defaultValue = isNullable ? string.Empty : "newid()";

                retVal = CreateNewMetaField(name, friendlyName, MetaFieldType.Guid, isNullable, defaultValue, attr);

                #endregion
            }
            else // if (column.DataType == typeof(String))
            {
                if (column.MaxLength != -1) // Text
                {
                    #region MetaFieldType.Text
                    AttributeCollection attr = new AttributeCollection();
                    string strDefaultValue = isNullable ? string.Empty : "''";

                    attr.Add(McDataTypeAttribute.StringMaxLength, column.MaxLength);
                    attr.Add(McDataTypeAttribute.StringIsUnique, column.Unique);

                    retVal = CreateNewMetaField(name, friendlyName, MetaFieldType.Text, isNullable, strDefaultValue, attr);

                    #endregion
                }
                //else if (column.MaxLength == -1)
                //{
                //    #region MetaFieldType.Text 255 Length
                //    AttributeCollection attr = new AttributeCollection();
                //    string strDefaultValue = isNullable ? string.Empty : "''";

                //    attr.Add(McDataTypeAttribute.StringMaxLength, 255);
                //    attr.Add(McDataTypeAttribute.StringIsUnique, false);

                //    retVal = CreateNewMetaField(name, friendlyName, MetaFieldType.Text, isNullable, strDefaultValue, attr);

                //    #endregion
                //}
                else // LongText (Default)
                {
                    #region MetaFieldType.LongText
                    AttributeCollection attr = new AttributeCollection();
                    string strDefaultValue = isNullable ? string.Empty : "''";

                    attr.Add(McDataTypeAttribute.StringLongText, true);

                    retVal = CreateNewMetaField(name, friendlyName, MetaFieldType.LongText, isNullable, strDefaultValue, attr);

                    #endregion
                }
            }

            return retVal;
        }
        public void TestCollectionChangedWithUpdatee()
        {
            AttributeCollection attributes = new AttributeCollection();

            bool eventRaised = false;
            NotifyCollectionChangedAction action = NotifyCollectionChangedAction.Reset;
            int newIndex = -1;
            string newAttributeName = string.Empty;
            AttributeValue newAttributeValue = null;
            int oldIndex = -1;
            string oldAttributeName = string.Empty;
            AttributeValue oldAttributeValue = null;

            attributes.Add("Test1", new AttributeValue("Test Value1"));

            // Setup the event handler
            attributes.CollectionChanged += (object sender, NotifyCollectionChangedEventArgs e) =>
            {
                action = e.Action;
                newAttributeName = e.NewItems != null ? ((KeyValuePair<string, AttributeValue>)e.NewItems[0]).Key : string.Empty;
                newAttributeValue = e.NewItems != null ? ((KeyValuePair<string, AttributeValue>)e.NewItems[0]).Value : null;
                newIndex = e.NewStartingIndex;
                oldAttributeName = e.OldItems != null ? ((KeyValuePair<string, AttributeValue>)e.OldItems[0]).Key : string.Empty;
                oldAttributeValue = e.OldItems != null ? ((KeyValuePair<string, AttributeValue>)e.OldItems[0]).Value : null;
                oldIndex = e.OldStartingIndex;

                eventRaised = true;
            };

            // Make change to property
            EnqueueCallback(() => attributes.Update("Test1", new AttributeValue("Updated Value1")));

            // Wait for event to complete
            EnqueueConditional(() => eventRaised != false);

            // Test that event was appropriately fires and handled
            EnqueueCallback(() => Assert.AreEqual<string>("Test1", oldAttributeName));
            EnqueueCallback(() => Assert.AreEqual<string>("Test1", newAttributeName));
            EnqueueCallback(() => Assert.AreEqual<string>("Test Value1", oldAttributeValue.Value));
            EnqueueCallback(() => Assert.AreEqual<string>("Updated Value1", newAttributeValue.Value));
            EnqueueCallback(() => Assert.AreEqual<NotifyCollectionChangedAction>(action, NotifyCollectionChangedAction.Replace));

            // Reset testing fields
            EnqueueCallback(() => action = NotifyCollectionChangedAction.Reset);
            EnqueueCallback(() => newAttributeName = string.Empty);
            EnqueueCallback(() => newAttributeValue = null);
            EnqueueCallback(() => newIndex = -1);
            EnqueueCallback(() => oldAttributeName = string.Empty);
            EnqueueCallback(() => oldAttributeValue = null);
            EnqueueCallback(() => oldIndex = -1);
            EnqueueCallback(() => eventRaised = false);

            EnqueueTestComplete();
        }
        public void TestAttributePropertyChangedEvent()
        {
            AttributeCollection attributes = new AttributeCollection();

            object oldValue = null;
            object newValue = null;
            string propertyChanged = string.Empty;

            // Setup the event handler
            attributes.AttributeValuePropertyChanged += (object sender, Berico.Common.Events.PropertyChangedEventArgs<object> e) =>
                {
                    oldValue = e.OldValue;
                    newValue = e.NewValue;
                    propertyChanged = e.PropertyName;
                };

            // Add some attributes to the collection
            attributes.Add("Test1", new AttributeValue("Test Value1"));
            attributes.Add("Test2", new AttributeValue("Test Value2"));
            attributes.Add("Test3", new AttributeValue("Test Value3"));
            attributes.Add("Test4", new AttributeValue("Test Value4"));

            // Retrieve one of the attributes to test
            AttributeValue testAttributeValue = attributes.GetAttributeValue("Test3");

            // Make change to property
            EnqueueCallback(() => testAttributeValue.Value = "New Value");

            // Wait for event to complete
            EnqueueConditional(() => propertyChanged != string.Empty);

            // Test that event was appropriately fires and handled
            EnqueueCallback(() => Assert.AreEqual<string>("Value", propertyChanged));
            EnqueueCallback(() => Assert.AreEqual<string>("New Value", newValue as string));
            EnqueueCallback(() => Assert.AreEqual<string>("Test Value3", oldValue as string));

            // Reset testing fields
            EnqueueCallback(() => propertyChanged = string.Empty);
            EnqueueCallback(() => oldValue = null);
            EnqueueCallback(() => newValue = null);

            EnqueueTestComplete();
        }
        public void TestEnumeratingAttributeValues()
        {
            AttributeCollection attributes = new AttributeCollection();

            Assert.AreEqual<int>(0, attributes.Count);

            attributes.Add("Test1", new AttributeValue("Test Value1"));
            attributes.Add("Test2", new AttributeValue("Test Value2"));
            attributes.Add("Test3", new AttributeValue("Test Value3"));
            attributes.Add("Test4", new AttributeValue("Test Value4"));

            List<AttributeValue> attributeValues = new List<AttributeValue>(attributes.AttributeValues);
            for (int i = 1; i <= attributeValues.Count; i++)
            {
                Assert.AreEqual<string>(attributeValues[i - 1].Value, "Test Value" + i);
            }
        }
        public void TestUpdatingAttribute()
        {
            AttributeCollection attributes = new AttributeCollection();
            AttributeValue newAttributeValue = new AttributeValue("Test Value");

            // Add attribute and attribute value
            attributes.Add("Test", newAttributeValue);

            Assert.AreEqual<string>(newAttributeValue.Value, attributes["Test"].Value);

            AttributeValue updatedAttributeValue = new AttributeValue("New Test Value");

            // Add attribute and attribute value
            attributes.Update("Test", updatedAttributeValue);

            // Ensure that the attribute has an updated value
            Assert.AreEqual<string>(updatedAttributeValue.Value, attributes["Test"].Value);
        }
        public void TestSuccessfullCheckIfAttributeExists()
        {
            AttributeCollection attributes = new AttributeCollection();
            AttributeValue newAttributeValue = new AttributeValue("Test Value");

            // Add the attribute
            attributes.Add("Test", newAttributeValue);

            Assert.IsTrue(attributes.ContainsAttribute("Test"));
        }
        public void TestRemovingInvalidAttribute()
        {
            AttributeCollection attributes = new AttributeCollection();

            attributes.Add("Test1", new AttributeValue("Test Value1"));
            attributes.Add("Test2", new AttributeValue("Test Value2"));
            attributes.Add("Test3", new AttributeValue("Test Value3"));
            attributes.Add("Test4", new AttributeValue("Test Value4"));

            Assert.IsFalse(attributes.Remove("Test5"));
        }
        public void TestCountingCollectionItems()
        {
            AttributeCollection attributes = new AttributeCollection();

            Assert.AreEqual<int>(0, attributes.Count);

            attributes.Add("Test1", new AttributeValue("Test Value1"));
            attributes.Add("Test2", new AttributeValue("Test Value2"));
            attributes.Add("Test3", new AttributeValue("Test Value3"));
            attributes.Add("Test4", new AttributeValue("Test Value4"));

            Assert.AreEqual<int>(4, attributes.Count);
        }
        public void TestGettingAnAttributeThatExists()
        {
            AttributeCollection attributes = new AttributeCollection();
            AttributeValue newAttributeValue = new AttributeValue("Test Value");

            // Add the attribute
            attributes.Add("Test", newAttributeValue);

            // Check if the attribute exists (by name)
            Assert.AreEqual<AttributeValue>(attributes.GetAttributeValue("Test"), newAttributeValue);
            Assert.AreEqual<AttributeValue>(attributes["Test"], newAttributeValue);

            // Check if the attribute exists (by attribute)
            Assert.AreEqual<AttributeValue>(attributes.GetAttributeValue("Test"), newAttributeValue);
            Assert.AreEqual<AttributeValue>(attributes["Test"], newAttributeValue);
        }