/// function needed by BObservable interface
 public void MessageArrived(BMessage aMessage)
 {
     switch (aMessage.Template)
       {
     case "run.msg":
       // I have no parameters so only return measured values
       BSlaveServiceManager.GetInstance().SendReturn(0, CreateReturnMessage());
       break;
     case "getstatus.msg":
       BSlaveServiceManager.GetInstance().SendStatus(100, "");
       break;
     case "end.msg":
       // should not arrive
       break;
     case "alive.msg":
     case "stop.msg":
     default:
       // nothing to do - ignore
       break;
       }
 }
 /// <summary>
 /// Overrided. Physically send a message.
 /// </summary>
 /// <param name="message">Message to send.</param>
 public override void Send(BMessage message)
 {
     throw new System.Exception ("Not implemented yet!");
 }
        /// this method parse LibBeline Question message, show dialog and create reply message
        /// from users response
        /// <exception>XmlException</exception>
        public static BMessage ShowDialog(BMessage aMessage)
        {
            if (aMessage.Template != "question.msg")
            // return error message
            return BMessage.CreateException("This is not valid LibBeline Question message");

              BMessageQuestion messageQuestion = (BMessageQuestion)aMessage;
              XmlDocument question = new XmlDocument();
              question.LoadXml(messageQuestion.InnerMessage); // load dialog part of message
              string dialogType = question.FirstChild.LocalName;
              Gtk.Dialog dialog;

              switch (dialogType.ToLower())
              {
            case "string":
              XmlElement element = (XmlElement)question.SelectSingleNode("//text[@lang='cz']");
              if (element == null)
              {
            element = (XmlElement)question.SelectSingleNode("//text[@lang='en']");
            // if czech and english string not found quit
            if (element == null) return BMessage.CreateException("Bad format of LibBeline Question message");
              }

              dialog = new BQuestionDialog("Otázka", null,  element.InnerText);
              dialog.ShowAll();
              dialog.Run();
              dialog.Destroy();

              // finished good, return
              return BMessage.CreateReturn(0, "");
            case "dialogyesno":
              XmlElement elementyesno = (XmlElement)question.SelectSingleNode("//text[@lang='cz']");
              if (elementyesno == null)
              {
            elementyesno = (XmlElement)question.SelectSingleNode("//text[@lang='en']");
            // if czech and english string not found quit
            if (elementyesno == null) return BMessage.CreateException("Bad format of LibBeline Question message");
              }

              dialog = new BQuestionDialog("Otázka", null,  elementyesno.InnerText);
              dialog.ShowAll();
              int answer = dialog.Run();
              dialog.Destroy();

              // finished good, return
              return BMessage.CreateReturn(0, "<retval><item description=\"answer\"><int value=\"" + answer +
            "\"</int></bretval></retval>");
            case "dialoginfo":
              XmlElement dialogInfo = (XmlElement)question.FirstChild;
              string level = dialogInfo.GetAttribute("severity");

              XmlElement elementInfo = (XmlElement)dialogInfo.SelectSingleNode("//text[@lang='cz']");
              if (elementInfo == null)
              {
            elementInfo = (XmlElement)dialogInfo.SelectSingleNode("//text[@lang='en']");
            // if czech and english string not found quit
            if (elementInfo == null) return BMessage.CreateException("Bad format of LibBeline Question message");
              }

              dialog = new BInfoDialog("Informace", null,  elementInfo.InnerText, level);
              dialog.ShowAll();
              dialog.Run();
              dialog.Destroy();

              // finished good, return
              return BMessage.CreateReturn(0, "");
            case "dialog":
              XmlElement xmlDialog = (XmlElement)question.FirstChild;
              string caption = xmlDialog.GetAttribute("caption");
              string text = xmlDialog.GetAttribute("string");
              dialog = new BDialog(caption, null, text);
              int i=0;
              foreach (XmlNode button in xmlDialog.SelectNodes("/button"))
              {
            if (button.NodeType != XmlNodeType.Element) continue; // if it isn't valid element don't bother with him
            XmlElement buttonElement = (XmlElement)button;
            switch (buttonElement.GetAttribute("type").ToLower())
            {
              case "yes":
                dialog.AddButton(Gtk.Stock.Yes, i);
                break;
              case "no":
                dialog.AddButton(Gtk.Stock.No, i);
                break;
              case "ok":
                dialog.AddButton(Gtk.Stock.Ok, i);
                break;
              case "cancel":
                dialog.AddButton(Gtk.Stock.Cancel, i);
                break;
              case "close":
                dialog.AddButton(Gtk.Stock.Close, i);
                break;
              case "delete":
                dialog.AddButton(Gtk.Stock.Delete, i);
                break;
              case "execute":
                dialog.AddButton(Gtk.Stock.Execute, i);
                break;
              case "goback":
                dialog.AddButton(Gtk.Stock.GoBack, i);
                break;
              case "goforward":
                dialog.AddButton(Gtk.Stock.GoForward, i);
                break;
              case "godown":
                dialog.AddButton(Gtk.Stock.GoDown, i);
                break;
              case "goup":
                dialog.AddButton(Gtk.Stock.GoUp, i);
                break;
              case "golast":
                dialog.AddButton(Gtk.Stock.GotoLast, i);
                break;
              case "gofirst":
                dialog.AddButton(Gtk.Stock.GotoFirst, i);
                break;
              case "help":
                dialog.AddButton(Gtk.Stock.Help, i);
                break;
              case "new":
                dialog.AddButton(Gtk.Stock.New, i);
                break;
              default:
                return BMessage.CreateException("Bad format of LibBeline Question message");
            } // switch
              } // foreach

              dialog.ShowAll();
              answer = dialog.Run();
              dialog.Destroy();

              // finished good, return
              return BMessage.CreateReturn(0, "<retval><item description=\"answer\"><int value=\"" + answer +
            "\"</int></bretval></retval>");
            default:
              return BMessage.CreateException("This is not valid LibBeline Question message. Dialog type should be one of string, dialog, dialogyesno or dialoginfo.");
              }
        }
 /// <summary>
 /// Physically send a message.
 /// </summary>
 /// <param name="message">Message to send.</param>
 public abstract void Send(BMessage message);
        /// signal from BusManager that some message arrived
        public void ArrivedMessage(BMessage aMessage)
        {
            try
              {
            BMessage tmpMessage;  // prepared return message
            switch (aMessage.Template)
            {
              case "alive.msg":
            // tell everybody that the message arrived
            try
            {
              foreach (BObservable observer in observers)
              {
                observer.MessageArrived(aMessage);
              }
            }
            catch (Exception e)
            { // error in parameters
              System.Console.WriteLine("Exception " + e.Message);
              tmpMessage = BMessage.CreateStatus(0, e.Message);
              // send error message
              busManager.Send(tmpMessage);
              throw;  // log it and finish
            }

            // send acknowledgement
            tmpMessage = BMessage.CreateStatus(100, "");
            busManager.Send(tmpMessage);
            break;
              case "run.msg":
              case "getstatus.msg":
              case "stop.msg":
            // tell everybody that the message arrived
            foreach (BObservable observer in observers)
            {
              observer.MessageArrived(aMessage);
            }
            break;
              case "end.msg":
            // stop the module
            messageHandlerFinish = true;
            break;
              default:
            // ignore another messages
            break;
            } // switch
              }
              catch (Exception e)
              { // log all top level errors
            LibBeline.GetInstance().LogManager.Log(e);
            throw;
              }
        }
 //
 public void SendCommand(BMessage message)
 {
     try
       {
     busManager.Send(message);
       }
       catch (Exception e)
       { // log all top level errors
     LibBeline.GetInstance().LogManager.Log(e);
     throw;
       }
 }