예제 #1
0
        public Instance(string server, Session.IInfo sessionInfo)
        {
            _connectServer = server;
            _sessionInfo   = sessionInfo;

            _messages = new Subject <agsXMPP.protocol.client.Message>();
            _iq       = new Subject <agsXMPP.protocol.client.IQ>();
        }
예제 #2
0
        public Instance(string server, Session.IInfo sessionInfo)
        {
            _connectServer = server;
            _sessionInfo = sessionInfo;

            _messages = new Subject<agsXMPP.protocol.client.Message>();
            _iq = new Subject<agsXMPP.protocol.client.IQ>();
        }
예제 #3
0
        public async Task <Session.IInfo> AuthenticateAsync(string connectServer, string authenticationToken)
        {
            XmppClientConnection connection = new XmppClientConnection();

            connection.Server   = Guest.Server;
            connection.Username = Guest.User;
            connection.Password = GuestPassword;

            connection.AutoResolveConnectServer = false;
            connection.ForceStartTls            = false;
            connection.ConnectServer            = connectServer; // values.HarmonyHubAddress;
            connection.AutoAgents   = false;
            connection.AutoPresence = false;
            connection.AutoRoster   = false;
            connection.OnSaslStart += OnSaslStart;
            connection.OnSaslEnd   += OnSaslEnd;
            connection.OnXmppConnectionStateChanged += (s, e) => Instrumentation.Xmpp.ConnectionStateChanged(e);
            connection.OnReadXml     += (s, e) => Instrumentation.Xmpp.Receive(e);
            connection.OnWriteXml    += (s, e) => Instrumentation.Xmpp.Transmit(e);
            connection.OnError       += (s, e) => Instrumentation.Xmpp.Error(e);
            connection.OnSocketError += (s, e) => Instrumentation.Xmpp.SocketError(e);

            Task connected = Observable.FromEvent <agsXMPP.ObjectHandler, Unit>(handler => s => handler(Unit.Default), handler => connection.OnLogin += handler, handler => connection.OnLogin -= handler)
                             .Timeout(TimeSpan.FromSeconds(30))
                             .Take(1)
                             .ToTask();

            connection.Open();

            await connected;

            Task <Session.IInfo> session =
                Observable.FromEvent <agsXMPP.protocol.client.IqHandler, agsXMPP.protocol.client.IQEventArgs>(handler => (s, e) => handler(e), handler => connection.OnIq += handler, handler => connection.OnIq -= handler)
                .Do(args => Instrumentation.Xmpp.IqReceived(args.IQ.From, args.IQ.To, args.IQ.Id, args.IQ.Error, args.IQ.Type, args.IQ.Value))
                .Do(args => args.Handled = true)
                .Select(args => args.IQ)
                .SessionResponses()
                .Timeout(TimeSpan.FromSeconds(10))
                .Take(1)
                .ToTask();

            connection.Send(Builder.ConstructSessionInfoRequest(authenticationToken));

            Session.IInfo sessionInfo = await session;

            connection.Close();

            return(sessionInfo);
        }
예제 #4
0
 public static IObservable <Configuration.IValues> HarmonyConfiguration(this IObservable <IQ> source, Session.IInfo sessionInfo)
 {
     return(source.Select(iq => iq.InnerXml)
            .Except(string.IsNullOrWhiteSpace)
            .Select(ExtractConfigurationString)
            .Except(string.IsNullOrWhiteSpace)
            .Select(value => Configuration.Parser.FromJson(sessionInfo.FriendlyName, value)));
 }
예제 #5
0
 public IInstance Create(string server, Session.IInfo sessionInfo)
 {
     return(new Instance(server, sessionInfo));
 }