///Start new transaction of module if it is possible
        ///<param name="aOID">Module's OID</param>
        public BTransactionItem Start(string aOID)
        {
            if (transactions.Count == transactionsCapacity) throw new Exception ("Maximum running transactions reached!");

            // get instance of module
            BModuleItem module = modManager[aOID];
            if (module == null) throw new Exception("Module with OID " + aOID + " not found.");

            // read configuration from module
            XmlNode config;
            try
            {
              config = module.GetConfig().GetXmlNode("/beline/conf/module/configuration");
              // if this is not Xml element, configuration file is bad
              if (config.NodeType != XmlNodeType.Element) throw new Exception();
            }
            catch (Exception)
            {
              throw new Exception("Error in configuration file. It does't contain \"/beline/conf/module/configuration\" branch");
            }

            ArrayList configItems = new ArrayList(config.ChildNodes.Count);
            foreach (XmlNode element in config.ChildNodes)
            {
              // if another child than element "bcfgitem" do not parse him
            if (element.NodeType != XmlNodeType.Element || element.LocalName != "bcfgitem") continue;

            BValueType hodnota = BValueType.Deserialize(element.FirstChild);
            if (hodnota != null) configItems.Add(hodnota);
            }

            BValueType[] configArray = new BValueType[configItems.Count];
            configItems.CopyTo(configArray);

            // create transaction
            BTransactionItem transaction = new BTransactionItem(module, configArray);

            // save transaction to inner ArrayList
            transactions.Add(transaction.OID, transaction);

            return transaction;
        }
 /// <summary>Constructor of alive message</summary>
 /// <param name="aConfiguration">Configuration items"</param>
 public static BMessage CreateAlive(BValueType[] aConfiguration)
 {
     return new BMessageAlive(aConfiguration);
 }
        /// <summary>Convert value of BValueType object (some of its children) to xml document.</summary>
        /// <param name="aValue">Value to serialize.</param>
        /// <exception>XmlException</exception>
        public static XmlNode Serialize(BValueType aValue)
        {
            // pokud je hloubka zanoreni prilis velika ukonci zanorovani, aby nedoslo k preteceni
              if (Deep >= 100) return null;
              Deep++;

              XmlDocument retval = new XmlDocument();
              switch (aValue.GetBType())
              {
            case BEnumType.BBool:
              retval.LoadXml("<bool name=\"" + aValue.Name + "\" value=\"" + aValue.ToString() + "\" />");
              break;
            case BEnumType.BFloat:
              retval.LoadXml("<float name=\"" + aValue.Name + "\" value=\"" + aValue.ToString() + "\" />");
              break;
            case BEnumType.BInteger:
              retval.LoadXml("<int name=\"" + aValue.Name + "\" value=\"" + aValue.ToString() + "\" />");
              break;
            case BEnumType.BString:
              string tmpStr = String.Format(@"<bool name=""{1}""><text lang=""en""><![CDATA[{2}]]></text></string>",
                                        aValue.Name, aValue.ToString());
              retval.LoadXml(tmpStr);
              break;
            case BEnumType.BVersion:
              retval.LoadXml("<version name=\"" + aValue.Name + "\" value=\"" + aValue.ToString() + "\" />");
              break;
            case BEnumType.BObject:
              // create this element
              retval.LoadXml("<object/>");
              XmlAttribute attribute = retval.CreateAttribute("name");
              attribute.Value = aValue.Name;
              retval.DocumentElement.Attributes.Append(attribute);

              foreach (BValueType innerValue in ((BObject)aValue).GetValue())
              {
            XmlNode node = Serialize(innerValue);
            if (node != null) retval.ImportNode(node, true);
              }
              break;
            default:
              // BNull
              retval = null;
              break;
              }

              Deep--;
              return retval.DocumentElement;
        }
        public static BMessage LoadFromXml(XmlNode runNode)
        {
            XmlElement element;   // working variable
              XmlAttribute attribute; // working variable
              string tmpProcedure = "";
              BValueType[] tmpParameters = new BValueType[runNode.ChildNodes.Count];
              int i=0;  // iterator

              element = (XmlElement)runNode;
              attribute = element.Attributes["procedure"];
              tmpProcedure = (attribute != null ? attribute.Value : "");
              foreach (XmlNode node in element.ChildNodes)
            // convert childs of "run" node to
            tmpParameters[i++] = BValueType.Deserialize(node);

              return new BMessageRun(tmpProcedure, tmpParameters);
        }
 public BMessageRun(string procedure, BValueType[] parameters)
     : base("run.msg", BEnumCommands.BCommDefault)
 {
     this.procedure = procedure;
       this.parameters = parameters;
 }
        public static BMessage LoadFromXml(XmlNode aliveNode)
        {
            BValueType[] tmpConfiguration = new BValueType[aliveNode.ChildNodes.Count];
              int i = 0;  // iterator

              foreach (XmlNode node in aliveNode.ChildNodes)
            // convert childs of "alive" node to
            tmpConfiguration[i++] = BValueType.Deserialize(node);

              return new BMessageAlive(tmpConfiguration);
        }
 /// Create new instance of Alive message
 public BMessageAlive(BValueType[] configuration)
     : base("alive.msg", BEnumCommands.BCommDefault)
 {
     this.configuration = configuration;
 }
 /// <summary>
 /// Constructor of run message
 /// </summary>
 /// <param name="procedure">Name of procedure to run.</param>
 /// <param name="parameters">Array of parameters.</param>
 /// <returns></returns>
 public static BMessage CreateRun(string procedure, BValueType[] parameters)
 {
     return new BMessageRun(procedure, parameters);
 }