Example #1
0
 private static void ScanEvents(ElementDef elementDef)
 {
     foreach (var eventInfo in elementDef.Type.GetEvents().Where(ei => ei.IsDefined(typeof(XmlEventAttribute), false)))
     {
         elementDef.AddAttribute(eventInfo.Name, eventInfo);
     }
 }
Example #2
0
 internal override AssignmentInfo GetAssignment(ElementDef childDef)
 {
     if (childDef != maDef.memberDef)
     {
         throw new Exception($"Element {childDef.name} is not supported.");
     }
     return(new AssignmentInfo()
     {
         index = internalElements.Count
     });
 }
Example #3
0
        /// <summary>
        /// Parse element and call it's handler.
        /// </summary>
        /// <param name="parent">Parent control.</param>
        /// <returns>Control.</returns>
        public Gwen.Net.Control.ControlBase ParseElement(Gwen.Net.Control.ControlBase parent)
        {
            ElementDef elementDef;

            if (m_ElementHandlers.TryGetValue(m_Reader.Name, out elementDef))
            {
                m_CurrentElement = elementDef;

                return(elementDef.Handler(this, elementDef.Type, parent));
            }

            return(null);
        }
Example #4
0
 private static void ScanProperties(ElementDef elementDef)
 {
     foreach (var propertyInfo in elementDef.Type.GetProperties().Where(pi => pi.IsDefined(typeof(XmlPropertyAttribute), false)))
     {
         if (m_AttributeValueConverters.ContainsKey(propertyInfo.PropertyType))
         {
             elementDef.AddAttribute(propertyInfo.Name, propertyInfo);
         }
         else
         {
             throw new XmlException(String.Format("No converter found for an attribute '{0}' value type '{1}'.", propertyInfo.Name, propertyInfo.PropertyType.Name));
         }
     }
 }
Example #5
0
        internal void ParseComponentAttributes(Component component)
        {
            Type componentType = component.GetType();
            Type viewType      = component.View.GetType();

            ElementDef componentDef = null;
            ElementDef viewDef      = null;

            foreach (ElementDef elementDef in m_ElementHandlers.Values)
            {
                if (elementDef.Type == componentType)
                {
                    componentDef = elementDef;
                }
                else if (elementDef.Type == viewType)
                {
                    viewDef = elementDef;
                }
            }

            if (componentDef == null)
            {
                throw new XmlException("Component is not registered.");
            }
            if (viewDef == null)
            {
                throw new XmlException("Component view is not registered.");
            }

            if (m_Reader.HasAttributes)
            {
                while (m_Reader.MoveToNextAttribute())
                {
                    if (!SetAttributeValue(componentDef, component, m_Reader.Name, m_Reader.Value))
                    {
                        if (!SetAttributeValue(viewDef, component.View, m_Reader.Name, m_Reader.Value))
                        {
                            if (!SetComponentAttribute(component, m_Reader.Name, m_Reader.Value))
                            {
                                throw new XmlException(String.Format("Attribute '{0}' not found.", m_Reader.Name));
                            }
                        }
                    }
                }

                m_Reader.MoveToElement();
            }
        }
Example #6
0
        /// <summary>
        /// Register a XML element. All XML elements must be registered before usage.
        /// </summary>
        /// <param name="name">Name of the element.</param>
        /// <param name="type">Type of the control or component.</param>
        /// <param name="handler">Handler function for creating the control or component.</param>
        /// <returns>True if registered successfully or false is already registered.</returns>
        public static bool RegisterElement(string name, Type type, ElementHandler handler)
        {
            if (!m_ElementHandlers.ContainsKey(name))
            {
                ElementDef elementDef = new ElementDef(type, handler);

                m_ElementHandlers[name] = elementDef;

                ScanProperties(elementDef);
                ScanEvents(elementDef);

                return(true);
            }

            return(false);
        }
Example #7
0
        private bool SetAttributeValue(ElementDef elementDef, object element, string attribute, string value)
        {
            MemberInfo memberInfo = elementDef.GetAttribute(attribute);

            if (memberInfo != null)
            {
                if (memberInfo is PropertyInfo)
                {
                    return(SetPropertyValue(element, memberInfo as PropertyInfo, value));
                }
                else if (memberInfo is EventInfo)
                {
                    return(SetEventValue(element, memberInfo as EventInfo, value));
                }
            }

            return(false);
        }
Example #8
0
        internal override AssignmentInfo GetAssignment(ElementDef childDef)
        {
            AssignmentInfo info     = new AssignmentInfo();
            var            newOrder = msDef.GetInternalOrder(childDef);

            while (info.index < internalElements.Count)
            {
                var e     = internalElements[index];
                var order = msDef.GetInternalOrder(e.def);
                if (order == newOrder)
                {
                    info.assigned = true;
                }
                if (order >= newOrder)
                {
                    return(info);
                }
                info.index++;
            }
            return(info);
        }
Example #9
0
        private void  LogCommon(string direction, log4net.ILog log)
        {
            System.Text.StringBuilder b = new System.Text.StringBuilder(direction);
            b.Append(ElementDef.Tag(SifVersion));
            b.Append(" (Status = ");

            SIF_Status stat = this.SIF_Status;

            if (stat != null)
            {
                b.Append(stat.SIF_Code);
            }
            else
            {
                b.Append("none");
            }

            SIF_Error err = this.SIF_Error;

            if (err != null)
            {
                b.Append("; 1 Error");
            }

            b.Append(")");
            log.Debug(b.ToString());

            if (err != null && (Adk.Debug & AdkDebugFlags.Messaging) != 0)
            {
                log.Debug(err.ToString());
            }

            if ((Adk.Debug & AdkDebugFlags.Messaging_Detailed) != 0)
            {
                string id = MsgId;
                log.Debug("  MsgId: " + (id == null?"<none>":id));
                id = SIF_OriginalMsgId;
                log.Debug("  OrgId: " + (id == null?"<none>":id));
            }
        }
Example #10
0
        /// <summary>
        /// Parse typed element and call it's handler.
        /// </summary>
        /// <typeparam name="T">Control type to be created.</typeparam>
        /// <param name="parent">Parent control.</param>
        /// <returns>Control.</returns>
        public T ParseElement <T>(Gwen.Net.Control.ControlBase parent) where T : Gwen.Net.Control.ControlBase
        {
            Type type = typeof(T);
            XmlControlAttribute attrib = null;

            object[] attribs = type.GetCustomAttributes(typeof(XmlControlAttribute), false);
            if (attribs.Length > 0)
            {
                attrib = attribs[0] as XmlControlAttribute;
            }

            ElementDef elementDef;

            if (m_ElementHandlers.TryGetValue(attrib != null && attrib.ElementName != null ? attrib.ElementName : type.Name, out elementDef))
            {
                if (elementDef.Type == type)
                {
                    m_CurrentElement = elementDef;
                    return(elementDef.Handler(this, elementDef.Type, parent) as T);
                }
            }

            return(null);
        }
Example #11
0
 internal override AssignmentInfo GetAssignment(ElementDef childDef)
 {
     throw new Exception("Cannot create union child.");
 }
Example #12
0
 public UnionValueElement(
     Container container, ElementDef def, UnionDef unionDef
     ) : base(container, def)
 {
     this.unionDef = unionDef;
 }
Example #13
0
 internal override AssignmentInfo GetAssignment(ElementDef childDef)
 {
     throw new Exception("Cannot create MemberUnionElement child");
 }
Example #14
0
 public MemberArrayElement(Container container, ElementDef def)
     : base(container, def)
 {
 }
Example #15
0
 public MemberUnionElement(Container container, ElementDef def, bool skipInit = false)
     : base(container, def)
 {
 }
Example #16
0
 public MemberStructElement(Container container, ElementDef def)
     : base(container, def)
 {
 }
Example #17
0
 public UnionElement(Container container, ElementDef def)
     : base(container, def)
 {
 }