Ejemplo n.º 1
0
        internal void Update(string uid, string propertyName, string value)
        {
            if (!_elementLookupTable.ContainsKey(uid))
            {
                // Add new element
                Element element = new Element();
                element.UId = uid;
                Property property = new Property();
                property.Name = propertyName;
                property.Value = value;
                element.Properties.Add(property);
                // Update the state
                _state.Elements.Add(element);
                // Update the lookup table
                _elementLookupTable.Add(element.UId, element);
                return;
            }

            Element foundElement = _elementLookupTable[uid];
            if (!Contains(foundElement, propertyName))
            {
                // Add new property
                Property property = new Property();
                property.Name = propertyName;
                property.Value = value;
                foundElement.Properties.Add(property);
                return;
            }

            // Update or remove existing property.
            Property foundProperty = GetProperty(foundElement, propertyName);
            if (value == null)
                foundElement.Properties.Remove(foundProperty);
            else
                foundProperty.Value = value;
        }
Ejemplo n.º 2
0
 private string GetValue(Element element, string propertyName)
 {
     foreach (Property property in element.Properties)
     {
         if (property.Name == propertyName)
         {
             return property.Value;
         }
     }
     return string.Empty;
 }
Ejemplo n.º 3
0
 private Property GetProperty(Element element, string propertyName)
 {
     foreach (Property property in element.Properties)
     {
         if (property.Name == propertyName)
         {
             return property;
         }
     }
     return null;
 }
Ejemplo n.º 4
0
 private bool Contains(Element element, string propertyName)
 {
     foreach (Property property in element.Properties)
     {
         if (property.Name == propertyName)
         {
             return true;
         }
     }
     return false;
 }