Пример #1
0
        public bool Erase(string key, string qos)
        {
            string me = "Erase()";

            logger.Debug(me);
            try
            {
                string[] results = xmlBlasterClientProxy.Erase(this.sessionId, key, qos);

                if (logger.IsDebug)
                {
                    logger.Debug("{0} Results:", me);
                    foreach (string s in results)
                    {
                        logger.Debug("\tEraseQosResult: {0}", s);
                    }
                }

                // TODO: Erase Qos Result
                return(true);
            }
            catch (Exception ex)
            {
                XmlBlasterException.HandleException(ex);
            }
            return(false);
        }
Пример #2
0
        public MessageUnit[] Get(string key, string qos)
        {
            string me = "Get()";

            logger.Debug(me);
            MessageUnit[] msgs = null;
            try
            {
                object[][] results = xmlBlasterClientProxy.Get(this.sessionId, key, qos);

                int nbrMsgs = results.Length;
                logger.Debug("{0} nbrMsgs= {1}", me, nbrMsgs);
                msgs = new MessageUnit[nbrMsgs];
                for (int i = 0; i < nbrMsgs; i++)
                {
                    try
                    {
                        msgs[i] = new MessageUnit((string)results[i][0], (byte[])results[i][1], (string)results[i][2]);
                    }
                    catch (Exception ex)
                    {
                        XmlBlasterException.HandleException(new Exception(me + " received a malformed message. Ex: " + ex.Message, ex));
                    }
                }
            }
            catch (Exception ex)
            {
                XmlBlasterException.HandleException(ex);
            }
            return(msgs);
        }
Пример #3
0
        public bool Unsubscribe(string subscribtionId)
        {
            string me = "Unsubscribe()";

            logger.Debug(me);

            try
            {
                string         key = "<key oid=\"" + subscribtionId + "\" />\n";
                QosUnsubscribe qos = new QosUnsubscribe();

                string[] results = xmlBlasterClientProxy.Unsubscribe(this.sessionId, key, qos.ToString());

                logger.Debug("{0} results count={1}", me, results.Length);
                foreach (string s in results)
                {
                    XmlBlasterLib.QosUnsubscribeResult qur = new QosUnsubscribeResult(s);
                    logger.Debug(qur.ToString());
                }
            }
            catch (Exception ex)
            {
                XmlBlasterException.HandleException(ex);
                return(false);
            }

            return(true);
        }
Пример #4
0
        public string Subscribe(string key, string qos)
        {
            string me = "Subscribe()";

            logger.Debug(me);

            /* key exemples:
             *  exact :
             *	<key oid='MyMessage' />
             * xpath :
             *	<key oid='' queryType='XPATH'> /xmlBlaster/key[starts-with(@oid,'radar.')] </key>
             */
            try
            {
                string result = xmlBlasterClientProxy.Subscribe(this.sessionId, key, qos.ToString());

                XmlBlasterLib.QosSubscribeResult qsr = new QosSubscribeResult(result);

                return(qsr.SubscribeId);
            }
            catch (Exception ex)
            {
                XmlBlasterException.HandleException(ex);
                return(null);
            }
        }
Пример #5
0
        public bool Publish(string key, string qos, string xmlContent)
        {
            string me = "Publish";

            logger.Debug(me);
            try
            {
                string result = xmlBlasterClientProxy.Publish(this.sessionId, key, xmlContent, qos);

                // TODO: Publish Qos Result
                return(true);
            }
            catch (Exception ex)
            {
                XmlBlasterException.HandleException(ex);
            }
            return(false);
        }
Пример #6
0
        public void Connect(string url, string username, string password)
        {
            logger.Debug("XmlBlaster.Connect()");
            logger.Debug("XmlBlaster.Connect() url:[" + url + "]");

            // reset
            this.sessionId = null;

            this.Url = url;              // Set xml-rpc server url

            try
            {
                // try connect (login)
                // to construct authentification data
                QosConnect qos = new QosConnect(username, password, this.callbackServerUri.ToString());

                XmlBlasterCallback.pingInterval = qos.PingInterval;

                string result = xmlBlasterClientProxy.Connect(qos.ToString());

                QosConnectResult qosConnectResult = new QosConnectResult(result);

                this.sessionId = qosConnectResult.SessionId;

                // TODO: sessionId should be secret !
                // do something better ;o)
                //Random rnd = new Random( );
                //this.uniqueId = rnd.NextDouble().ToString() ;
            }
            catch (Exception ex)
            {
                // reset
                this.sessionId = null;

                XmlBlasterException.HandleException(ex);
            }
        }
Пример #7
0
        public XmlBlasterClient()
        {
            //
            // Client
            //

            xmlBlasterClientProxy    = (IXmlBlasterClient)XmlRpcProxyGen.Create(typeof(IXmlBlasterClient));
            xmlBlasterClientProtocol = (XmlRpcClientProtocol)xmlBlasterClientProxy;

            //
            // Callback Server
            //

            // On peut le faire depuis un fichier
            //RemotingConfiguration.Configure("xmlrpc.exe.config");

            // Ou bien à la mano
            try
            {
                //int port = FindFreeHttpPort( 9090 ) ;
                //logger.Debug( "FindFreeHttpPort() found port "+port );
                // port = 0 pour que le système assigne automatiquement un port non-utilisé.
                int port = 0;

                ListDictionary channelProperties = new ListDictionary();
                channelProperties.Add("port", port);

                httpChannel = new HttpChannel(
                    channelProperties,
                    new CookComputing.XmlRpc.XmlRpcClientFormatterSinkProvider(),
                    new CookComputing.XmlRpc.XmlRpcServerFormatterSinkProvider(null, null)
                    //new SoapClientFormatterSinkProvider(),
                    //new SoapServerFormatterSinkProvider()
                    );
            }
            catch (Exception ex)
            {
                // Listener config failed : Une seule utilisation de chaque adresse de socket (protocole/adresse réseau/port) est habituellement autorisée
                XmlBlasterException.HandleException(new Exception("XmlBlaster callback server, Listener config failed.", ex));
            }

            try
            {
                ChannelServices.RegisterChannel(httpChannel);
            }
            catch (System.Runtime.Remoting.RemotingException)
            {
                // Pas grave: The channel has already been registered.
            }
            catch (Exception ex)
            {
                XmlBlasterException.HandleException(new Exception("XmlBlasterCallback server, failed to RegisterChannel.", ex));
            }

            RemotingConfiguration.RegisterWellKnownServiceType(
                typeof(XmlBlasterCallback),
                "XmlBlasterCallback",
                WellKnownObjectMode.Singleton
                );


            // Comme on a pas indiqué de port, celui-ci a été assigné automatiquement.
            // Il nous faut donc retrouver l'url afin de pouvoir la transmettre dans le Qos de connexion.

            string[] urls = httpChannel.GetUrlsForUri("XmlBlasterCallback");
            foreach (string url in urls)
            {
                logger.Debug("XmlBlasterCallback url: {0}", url);
            }
            //url: http://192.168.0.151:4808/XmlBlasterCallback
            if (urls.Length != 1)
            {
                XmlBlasterException.HandleException(new Exception("XmlBlasterCallback server, failed to retreive url."));
            }
            this.callbackServerUri = new Uri(urls[0]);
        }