Beispiel #1
0
        public void ResolvesMergedGenericType()
        {
            ManagedDictionary parent = new ManagedDictionary();

            parent.Add("one", 1);
            parent.Add("two", 2);
            parent.KeyTypeName   = "string";
            parent.ValueTypeName = "int";

            ManagedDictionary child = new ManagedDictionary();

            child.MergeEnabled = true;
            child.Add("one", -1);
            child.Add("three", 3);

            ManagedDictionary merged = (ManagedDictionary)child.Merge(parent);

            IDictionary resolved = (IDictionary)merged.Resolve("somename", new RootObjectDefinition(typeof(object)), "prop",
                                                               (name, definition, argumentName, element) => element);

            Assert.IsInstanceOf <IDictionary <string, int> >(resolved);
            Assert.AreEqual(3, resolved.Count);
            Assert.AreEqual(typeof(int), resolved["two"].GetType());
            Assert.AreEqual(-1, resolved["one"]);
        }
Beispiel #2
0
        protected override void PostProcessHeaders(XmlElement element, ManagedDictionary headers, ParserContext parserContext)
        {
            XmlNodeList childNodes = element.ChildNodes;

            for (int i = 0; i < childNodes.Count; i++)
            {
                XmlNode node = childNodes.Item(i);
                if (node.NodeType == XmlNodeType.Element && node.LocalName.Equals("header"))
                {
                    XmlElement headerElement = (XmlElement)node;
                    string     name          = headerElement.GetAttribute("name");
                    string     value         = headerElement.GetAttribute("value");
                    string     refatr        = headerElement.GetAttribute("ref");
                    bool       isValue       = StringUtils.HasText(value);
                    bool       isRef         = StringUtils.HasText(refatr);
                    if (!(isValue ^ isRef))
                    {
                        parserContext.ReaderContext.ReportException(headerElement, headerElement.Name, "Exactly one of the 'value' or 'ref' attributes is required.");
                    }
                    if (isValue)
                    {
                        headers.Add(name, value);
                    }
                    else
                    {
                        headers.Add(name, new RuntimeObjectReference(refatr));
                    }
                }
            }
        }
Beispiel #3
0
        public void MergeEmptyChild()
        {
            ManagedDictionary parent = new ManagedDictionary();

            parent.Add("one", "one");
            parent.Add("two", "two");
            ManagedDictionary child = new ManagedDictionary();

            child.MergeEnabled = true;
            IDictionary mergedMap = (IDictionary)child.Merge(parent);

            Assert.AreEqual(2, mergedMap.Count);
        }
Beispiel #4
0
        public void MergeSunnyDay()
        {
            ManagedDictionary parent = new ManagedDictionary();

            parent.Add("one", "one");
            parent.Add("two", "two");
            ManagedDictionary child = new ManagedDictionary();

            child.Add("three", "three");
            child.MergeEnabled = true;
            IDictionary mergedList = (IDictionary)child.Merge(parent);

            Assert.AreEqual(3, mergedList.Count);
        }
Beispiel #5
0
        public void MergeChildValueOverrideTheParents()
        {
            ManagedDictionary parent = new ManagedDictionary();

            parent.Add("one", "one");
            parent.Add("two", "two");
            ManagedDictionary child = new ManagedDictionary();

            child.Add("one", "fork");
            child.MergeEnabled = true;
            IDictionary mergedMap = (IDictionary)child.Merge(parent);

            Assert.AreEqual(2, mergedMap.Count);
            Assert.AreEqual("fork", mergedMap["one"]);
        }
        protected override void ParseTransformer(XmlElement element, ParserContext parserContext, ObjectDefinitionBuilder builder)
        {
            ManagedDictionary      headers    = new ManagedDictionary();
            XmlAttributeCollection attributes = element.Attributes;

            for (int i = 0; i < attributes.Count; i++)
            {
                XmlNode node = attributes.Item(i);
                String  name = node.LocalName;
                if (IsEligibleHeaderName(name))
                {
                    name = Conventions.AttributeNameToPropertyName(name);
                    object value;
                    if (ReferenceAttributesContains(name))
                    {
                        value = new RuntimeObjectReference(node.Value);
                    }
                    else
                    {
                        value = node.Value;
                    }

                    if (_prefix != null)
                    {
                        name = _prefix + name;
                    }
                    headers.Add(name, value);
                }
            }
            PostProcessHeaders(element, headers, parserContext);
            builder.AddConstructorArg(headers);
            builder.AddPropertyValue("overwrite", ShouldOverwrite(element));
        }
        /// <summary>The convert to managed dictionary.</summary>
        /// <param name="dictionary">The dictionary.</param>
        /// <typeparam name="TKey"></typeparam>
        /// <typeparam name="TValue"></typeparam>
        /// <returns>The Spring.Objects.Factory.Config.ManagedDictionary.</returns>
        public ManagedDictionary ConvertToManagedDictionary <TKey, TValue>(IDictionary dictionary)
        {
            var result = new ManagedDictionary();

            result.KeyTypeName   = typeof(TKey).FullName;
            result.ValueTypeName = typeof(TValue).FullName;

            foreach (DictionaryEntry entry in dictionary)
            {
                result.Add(entry.Key, entry.Value);
            }

            return(result);
        }
Beispiel #8
0
        public void ResolvesInternalGenericTypes()
        {
            ManagedDictionary dict2 = new ManagedDictionary();

            dict2.Add("1", "stringValue");
            dict2.KeyTypeName   = "int";
            dict2.ValueTypeName = typeof(InternalType).FullName;

            IDictionary resolved = (IDictionary)dict2.Resolve("other", new RootObjectDefinition(typeof(object)), "prop",
                                                              delegate(string name, IObjectDefinition definition, string argumentName, object element)
            {
                if ("stringValue".Equals(element))
                {
                    return(new InternalType());
                }
                return(element);
            }
                                                              );

            Assert.AreEqual(typeof(InternalType), resolved[1].GetType());
        }
Beispiel #9
0
        public void ResolvesGenericTypeNames()
        {
            ManagedDictionary dict = new ManagedDictionary();

            dict.Add("key", "value");
            dict.KeyTypeName = "string";

            dict.ValueTypeName = "System.Collections.Generic.List<[string]>";
            IDictionary resolved = (IDictionary)dict.Resolve("somename", new RootObjectDefinition(typeof(object)), "prop",
                                                             delegate(string name, IObjectDefinition definition, string argumentName, object element)
            {
                if ("value".Equals(element))
                {
                    return(new List <string>());
                }
                return(element);
            }
                                                             );

            Assert.AreEqual(1, resolved.Count);
            Assert.AreEqual(typeof(List <string>), resolved["key"].GetType());
        }
Beispiel #10
0
        /// <summary>
        /// Destruye todo el modelo y lo deja limpio
        /// </summary>
        /// <TODO>Modified, Save, Load</TODO>
        public void Reset()
        {
            try
            {
                this.undoManager = new UndoManager(this);
                undoManager.Enabled = false;
                this.abstractCases = new ManagedList<Canguro.Model.Load.AbstractCase>();
                abstractCases.ElementRemoved += new ManagedList<AbstractCase>.ListChangedEventHandler(abstractCases_ElementRemoved);
                this.activeLoadCase = null;
                this.areaList = new ItemList<AreaElement>();
                this.constraintList = new ManagedList<Constraint>();
                this.isLocked = false;
                this.jointList = new ItemList<Joint>();
                this.layers = new ItemList<Layer>();
                layers.ElementRemoved += new ManagedList<Layer>.ListChangedEventHandler(layers_ElementRemoved);
                this.lineList = new ItemList<LineElement>();
                this.loadCases = new ManagedDictionary<string, LoadCase>();
                loadCases.ElementRemoved += new ManagedDictionary<string, LoadCase>.ListChangedEventHandler(loadCases_ElementRemoved);
                this.summary = new ModelSummary(this);

                this.designOptions = new List<DesignOptions>();
                designOptions.Add(NoDesign.Instance);
                designOptions.Add(new LRFD99());
                designOptions.Add(new ACI318_02());
                designOptions.Add(new ASD01());
                designOptions.Add(new RCDF2001());
                designOptions.Add(new UBC97_ASD());
                designOptions.Add(new UBC97_LRFD());
                designOptions.Add(new UBC97_Conc());
                steelDesignOptions = NoDesign.Instance;
                concreteDesignOptions = NoDesign.Instance;
                coldFormedDesignOptions = NoDesign.Instance;
                aluminumDesignOptions = NoDesign.Instance;

                this.results = new Canguro.Model.Results.Results(0);

                // Layer es un Item y todos los Items asignan su propiedad layer
                // de acuerdo a ActiveLayer, por lo que hay que asignarla en null
                // antes de crear el primer Layer, root de todos los demás
                activeLayer = null;
                Layer rootLayer = new Layer(Culture.Get("defaultLayerName"));
                ActiveLayer = rootLayer;

                activeLoadCase = new LoadCase(Culture.Get("defaultLoadCase"), LoadCase.LoadCaseType.Dead);
                activeLoadCase.SelfWeight = 1.0f;
                loadCases.Add(activeLoadCase.Name, activeLoadCase);

                AnalysisCase anc = new Canguro.Model.Load.AnalysisCase(Culture.Get("defaultLoadCase"));
                AbstractCases.Add(anc);
                if (anc != null)
                {
                    StaticCaseProps props = anc.Properties as StaticCaseProps;
                    if (props != null)
                    {
                        List<StaticCaseFactor> list = props.Loads;
                        list.Add(new StaticCaseFactor(ActiveLoadCase));
                        props.Loads = list;
                    }
                }

                MaterialManager.Instance.Initialize();
                SectionManager.Instance.Initialize(ref sections);
                sections.ElementRemoved += new Catalog<Canguro.Model.Section.Section>.ListChangedEventHandler(sections_ElementRemoved);
                this.currentPath = "";
                foreach (Canguro.Model.UnitSystem.UnitSystem us in UnitSystemsManager.Instance.UnitSystems)
                    if (Properties.Settings.Default.UnitSystem.Equals(us.GetType().Name))
                        UnitSystemsManager.Instance.CurrentSystem = us;

                viewManager = Canguro.View.GraphicViewManager.Instance;
                modified = false;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
                throw e;
            }
            finally
            {
                if (ModelReset != null)
                    ModelReset(this, EventArgs.Empty);
                undoManager.Enabled = true;
            }
        }
        /// <summary>The parse map element.</summary>
        /// <param name="mapEle">The map ele.</param>
        /// <param name="bd">The bd.</param>
        /// <returns>The System.Collections.IDictionary.</returns>
        public IDictionary ParseMapElement(XmlElement mapEle, IObjectDefinition bd)
        {
            string defaultKeyType   = mapEle.GetAttribute(KEY_TYPE_ATTRIBUTE);
            string defaultValueType = mapEle.GetAttribute(VALUE_TYPE_ATTRIBUTE);

            XmlNodeList entryEles = mapEle.GetElementsByTagName(ENTRY_ELEMENT, OBJECTS_NAMESPACE_URI);
            var         map       = new ManagedDictionary(entryEles.Count);

            map.KeyTypeName   = defaultKeyType;
            map.ValueTypeName = defaultValueType;
            map.MergeEnabled  = this.ParseMergeAttribute(mapEle);

            foreach (XmlNode entryEle in entryEles)
            {
                // Should only have one value child element: ref, value, list, etc.
                // Optionally, there might be a key child element.
                XmlNodeList entrySubNodes = entryEle.ChildNodes;
                XmlElement  keyEle        = null;
                XmlElement  valueEle      = null;
                for (int j = 0; j < entrySubNodes.Count; j++)
                {
                    XmlNode node = entrySubNodes.Item(j);
                    if (node is XmlElement)
                    {
                        var candidateEle = (XmlElement)node;
                        if (this.NodeNameEquals(candidateEle, KEY_ELEMENT))
                        {
                            if (keyEle != null)
                            {
                                this.Error("<entry> element is only allowed to contain one <key> sub-element", entryEle);
                            }
                            else
                            {
                                keyEle = candidateEle;
                            }
                        }
                        else
                        {
                            // Child element is what we're looking for.
                            if (valueEle != null)
                            {
                                this.Error("<entry> element must not contain more than one value sub-element", entryEle);
                            }
                            else
                            {
                                valueEle = candidateEle;
                            }
                        }
                    }
                }

                // Extract key from attribute or sub-element.
                object key                = null;
                bool   hasKeyAttribute    = this.HasAttribute(entryEle, KEY_ATTRIBUTE);
                bool   hasKeyRefAttribute = this.HasAttribute(entryEle, KEY_REF_ATTRIBUTE);
                if ((hasKeyAttribute && hasKeyRefAttribute) ||
                    (hasKeyAttribute || hasKeyRefAttribute) && keyEle != null)
                {
                    this.Error(
                        "<entry> element is only allowed to contain either " +
                        "a 'key' attribute OR a 'key-ref' attribute OR a <key> sub-element",
                        entryEle);
                }

                if (hasKeyAttribute)
                {
                    key = this.buildTypedStringValueForMap(entryEle.Attributes[KEY_ATTRIBUTE].Value, defaultKeyType);
                }
                else if (hasKeyRefAttribute)
                {
                    string refName = entryEle.Attributes[KEY_REF_ATTRIBUTE].Value;
                    if (!StringUtils.HasText(refName))
                    {
                        this.Error("<entry> element contains empty 'key-ref' attribute", entryEle);
                    }

                    var reference = new RuntimeObjectReference(refName);
                    key = reference;
                }
                else if (keyEle != null)
                {
                    key = this.parseKeyElement(keyEle, bd, defaultKeyType);
                }
                else
                {
                    this.Error("<entry> element must specify a key", entryEle);
                }

                // Extract value from attribute or sub-element.
                object value                = null;
                bool   hasValueAttribute    = this.HasAttribute(entryEle, VALUE_ATTRIBUTE);
                bool   hasValueRefAttribute = this.HasAttribute(entryEle, VALUE_REF_ATTRIBUTE);
                if ((hasValueAttribute && hasValueRefAttribute) ||
                    (hasValueAttribute || hasValueRefAttribute) && valueEle != null)
                {
                    this.Error(
                        "<entry> element is only allowed to contain either " +
                        "'value' attribute OR 'value-ref' attribute OR <value> sub-element",
                        entryEle);
                }

                if (hasValueAttribute)
                {
                    value = this.buildTypedStringValueForMap(entryEle.Attributes[VALUE_ATTRIBUTE].Value, defaultValueType);
                }
                else if (hasValueRefAttribute)
                {
                    string refName = entryEle.Attributes[VALUE_REF_ATTRIBUTE].Value;
                    if (!StringUtils.HasText(refName))
                    {
                        this.Error("<entry> element contains empty 'value-ref' attribute", entryEle);
                    }

                    var reference = new RuntimeObjectReference(refName);
                    value = reference;
                }
                else if (valueEle != null)
                {
                    value = this.parsePropertySubElement(valueEle, bd, defaultValueType);
                }
                else
                {
                    this.Error("<entry> element must specify a value", entryEle);
                }

                // Add final key and value to the Map.
                map.Add(key, value);
            }

            return(map);
        }