Ejemplo n.º 1
0
        /// <exception>FileNotFoundException, XmlException</exception>
        public BModuleItem(string aFileName)
        {
            oid = BItem.GenerateID();

              // create instance of configuration item
              try
              {
            BConfigManager configManager = BConfigManager.GetInstance();
            BConfigItem configItem = configManager.LoadModuleConfig(aFileName);
            // store some frequently used properties
            configOID = configItem.OID;
            name = configItem["/beline/conf/module[@name]"].ToString();
            version = new BVersion(configItem["/beline/conf/module[@version]"].ToString());
            author = configItem["/beline/conf/module/author[@name]"].ToString() + " <" +
                 configItem["/beline/conf/module/author[@email]"].ToString() + ">";
            description = configItem["/beline/conf/module[@description]"].ToString();
              }
              catch (System.Xml.XmlException e)
              {
            throw new System.Xml.XmlException("Bad XML file " + aFileName + ": " + e.Message);
              }
        }
Ejemplo n.º 2
0
        /// <summary>Convert value serialized in XML to BValueType object (some of its children)</summary>
        /// <param name="aValue">Value to deserialize.</param>
        /// <exception>XmlException</exception>
        public static BValueType Deserialize(XmlNode aValue)
        {
            // pokud je hloubka zanoreni prilis velika ukonci zanorovani, aby nedoslo k preteceni
              if (Deep >= 100) return null;
              Deep++;

              BValueType retval;
              XmlAttribute name = aValue.Attributes["name"];
              XmlAttribute hodn;
              switch (aValue.LocalName)
              {
            case "bool":
              hodn = aValue.Attributes["value"];
              retval = new BBool(name.Value, hodn.Value);
              break;
            case "float":
              hodn = aValue.Attributes["value"];
              try
              {
            retval = new BFloat(name.Value, hodn.Value);
              }
              catch (Exception e)
              {
            throw new XmlException("Error in XML document in tag \"" + aValue.Name + "\" : \n" + e.Message);
              }
              break;
            case "int":
              hodn = aValue.Attributes["value"];
              try
              {
            retval = new BInteger(name.Value, hodn.Value);
              }
              catch (Exception e)
              {
            throw new XmlException("Error in XML document in tag \"" + aValue.Name + "\" : \n" + e.Message);
              }
              break;
            case "string":
              XmlNode text = aValue.FirstChild;
              if (text == null || text.LocalName.ToLower() != "text" || text.NodeType != XmlNodeType.Element)
            throw new XmlException("Error in XML document in tag \"" + aValue.Name +
                                  "\" : \nElement string does not contain element text.");

              XmlNode cdata = text.FirstChild;
              if (cdata == null || cdata.NodeType != XmlNodeType.CDATA)
            throw new XmlException("Error in XML document in tag \"" + aValue.Name +
                                  "\" : \nElement string does not contain CDATA value.");

              retval = new BString(name.Value, cdata.Value);
              break;
            case "version":
              hodn = aValue.Attributes["value"];
              try
              {
            retval = new BVersion(name.Value, hodn.Value);
              }
              catch (Exception e)
              {
            throw new XmlException("Error in XML document in tag \"" + aValue.Name + "\" : \n" + e.Message);
              }
              break;
            case "object":
              System.Collections.ArrayList innerRetVal = new System.Collections.ArrayList(aValue.ChildNodes.Count);
              foreach (XmlNode node in aValue.ChildNodes)
              {
            BValueType objekt = Deserialize(node);
            if (objekt != null) innerRetVal.Add(objekt);
              }

              retval = new BObject(name.Value, innerRetVal);
              break;
            default:
              // something wrong
              retval=null;
              break;
              }

              Deep--;
              return retval;
        }