public AddEndpointDialog(EndpointSettings settings)
        {
            InitializeComponent();

            if (settings != null)
            {
                Settings = settings;
                EndpointName.ReadOnly = true;
            }
            else
            {
                Settings = new EndpointSettings();
            }

            Prefs = new[] {
                new Mapping(
                    BoundMember.New(() => Settings.Name),
                    BoundMember.New(() => EndpointName.Text)
                    ),
                new Mapping(
                    BoundMember.New(() => Settings.Server),
                    BoundMember.New(() => Server.Text)
                    ),
                new Mapping(
                    BoundMember.New(() => Settings.Username),
                    BoundMember.New(() => Username.Text)
                    ),
                new Mapping(
                    BoundMember.New(() => Settings.Password),
                    BoundMember.New(() => Password.Text)
                    ),
                new Mapping(
                    BoundMember.New(() => Settings.Resource),
                    BoundMember.New(() => Resource.Text)
                    ),
                new Mapping(
                    BoundMember.New(() => Settings.ChatChannel),
                    BoundMember.New(() => ChatChannel.Text)
                    ),
                new Mapping(
                    BoundMember.New(() => Settings.ChatAlias),
                    BoundMember.New(() => ChatAlias.Text)
                    ),
                new Mapping(
                    BoundMember.New(() => Settings.ToUsername),
                    BoundMember.New(() => ToUsername.Text)
                    )
            };

            foreach (var pref in Prefs)
            {
                pref.Control.Value = pref.Setting.Value;
            }

            SendToGroupChat.Checked = (ChatChannel.Text ?? "").Length > 0;
            SendToUser.Checked      = (ToUsername.Text ?? "").Length > 0;

            RefreshEnabledState(null, EventArgs.Empty);
        }
Пример #2
0
 public static Future<Endpoint> Connect(JabberGateway gateway, EndpointSettings settings, Action<float> setStatus)
 {
     var f = new Future<Endpoint>();
     Program.Scheduler.Start(
         f, new SchedulableGeneratorThunk(DoConnect(gateway, settings, setStatus)),
         TaskExecutionPolicy.RunWhileFutureLives
     );
     return f;
 }
Пример #3
0
        public static Future <Endpoint> Connect(JabberGateway gateway, EndpointSettings settings, Action <float> setStatus)
        {
            var f = new Future <Endpoint>();

            Program.Scheduler.Start(
                f, new SchedulableGeneratorThunk(DoConnect(gateway, settings, setStatus)),
                TaskExecutionPolicy.RunWhileFutureLives
                );
            return(f);
        }
Пример #4
0
        public AddEndpointDialog(EndpointSettings settings)
        {
            InitializeComponent();

            if (settings != null) {
                Settings = settings;
                EndpointName.ReadOnly = true;
            } else
                Settings = new EndpointSettings();

            Prefs = new[] {
                new Mapping(
                    BoundMember.New(() => Settings.Name),
                    BoundMember.New(() => EndpointName.Text)
                ),
                new Mapping(
                    BoundMember.New(() => Settings.Server),
                    BoundMember.New(() => Server.Text)
                ),
                new Mapping(
                    BoundMember.New(() => Settings.Username),
                    BoundMember.New(() => Username.Text)
                ),
                new Mapping(
                    BoundMember.New(() => Settings.Password),
                    BoundMember.New(() => Password.Text)
                ),
                new Mapping(
                    BoundMember.New(() => Settings.Resource),
                    BoundMember.New(() => Resource.Text)
                ),
                new Mapping(
                    BoundMember.New(() => Settings.ChatChannel),
                    BoundMember.New(() => ChatChannel.Text)
                ),
                new Mapping(
                    BoundMember.New(() => Settings.ChatAlias),
                    BoundMember.New(() => ChatAlias.Text)
                ),
                new Mapping(
                    BoundMember.New(() => Settings.ToUsername),
                    BoundMember.New(() => ToUsername.Text)
                )
            };

            foreach (var pref in Prefs)
                pref.Control.Value = pref.Setting.Value;

            SendToGroupChat.Checked = (ChatChannel.Text ?? "").Length > 0;
            SendToUser.Checked = (ToUsername.Text ?? "").Length > 0;

            RefreshEnabledState(null, EventArgs.Empty);
        }
Пример #5
0
        protected Endpoint(JabberGateway gateway, EndpointSettings settings, Session session)
        {
            Gateway = gateway;
            Settings = settings;
            Session = session;
            Queue = Gateway.GetQueue(settings.Name);

            Endpoint oldEndpoint = null;
            if (gateway.Endpoints.TryGetValue(settings.Name, out oldEndpoint) && (oldEndpoint != null))
                oldEndpoint.Dispose();

            gateway.Endpoints[settings.Name] = this;

            QueueTaskFuture = Program.Scheduler.Start(QueueTask(), TaskExecutionPolicy.RunAsBackgroundTask);
        }
Пример #6
0
        protected Endpoint(JabberGateway gateway, EndpointSettings settings, Session session)
        {
            Gateway  = gateway;
            Settings = settings;
            Session  = session;
            Queue    = Gateway.GetQueue(settings.Name);

            Endpoint oldEndpoint = null;

            if (gateway.Endpoints.TryGetValue(settings.Name, out oldEndpoint) && (oldEndpoint != null))
            {
                oldEndpoint.Dispose();
            }

            gateway.Endpoints[settings.Name] = this;

            QueueTaskFuture = Program.Scheduler.Start(QueueTask(), TaskExecutionPolicy.RunAsBackgroundTask);
        }
        private IEnumerator <object> SaveEndpoint(EndpointSettings settings)
        {
            using (new ControlDisabler(this)) {
                var columnNames   = Mapper <EndpointSettings> .ColumnNames;
                var questionMarks = new string[columnNames.Length];
                for (int i = 0; i < questionMarks.Length; i++)
                {
                    questionMarks[i] = "?";
                }

                using (var q = Program.Database.BuildQuery(String.Format(
                                                               "REPLACE INTO jabber.endpoints ({0}) VALUES ({1})", String.Join(", ", columnNames), String.Join(", ", questionMarks)
                                                               )))
                    yield return(q.ExecuteNonQuery(Mapper <EndpointSettings> .GetColumnValues(settings)));

                yield return(LoadConfiguration());

                yield return(Script.InitGateways());
            }
        }
Пример #8
0
        protected static IEnumerator <object> DoConnect(JabberGateway gateway, EndpointSettings settings, Action <float> setStatus)
        {
            Session session = null;
            var     options = new ConnectionOptions(settings.Server);

            yield return(Jabber.AsyncLogin(
                             settings.Username, settings.Password, settings.Resource, false, options
                             ).Bind(() => session));

            setStatus(0.5f);

            // F*****g soapbox doesn't handle pings or let you handle them with strongly typed packets, wee
            session.OnXMLReceived += (xml, socketID) => {
                if (xml.Contains("<ping xmlns=\"urn:xmpp:ping\""))
                {
                    Program.Scheduler.Start(HandlePing(session, xml, socketID), TaskExecutionPolicy.RunAsBackgroundTask);
                }
            };

            var messagePrefix = settings.ChatAlias.ToLowerInvariant() + ":";

            session.AddHandler(typeof(SoapboxCore.Message.ChatMessagePacket), (p) => {
                var cm = (SoapboxCore.Message.ChatMessagePacket)p;

                string bodyText = null;
                try {
                    bodyText = cm.Body;
                } catch {
                }

                if (bodyText != null)
                {
                    HandleIncomingMessage(gateway, settings.Name, cm.From, bodyText);
                }
            });

            session.AddHandler(typeof(MUC.Message.GroupChatMessage), (p) => {
                var gcm = (MUC.Message.GroupChatMessage)p;

                string bodyText = null;
                try {
                    bodyText = gcm.Body;
                } catch {
                }

                if ((bodyText != null) && (bodyText.ToLowerInvariant().Trim().StartsWith(messagePrefix)))
                {
                    bodyText = bodyText.Substring(bodyText.IndexOf(':') + 1);
                    HandleIncomingMessage(gateway, settings.Name, gcm.From, bodyText);
                }
            });

            session.OnAsynchronousException += (e) => {
                Program.Scheduler.OnTaskError(e);
            };

            var roomJid = settings.GetRoomJid(true);

            if (roomJid != null)
            {
                yield return(session.AsyncSend(new MUC.Presence.JoinRoomRequest(roomJid)));
            }

            setStatus(1.0f);

            yield return(new Result(new Endpoint(
                                        gateway, settings, session
                                        )));
        }
Пример #9
0
        protected static IEnumerator<object> DoConnect(JabberGateway gateway, EndpointSettings settings, Action<float> setStatus)
        {
            Session session = null;
            var options = new ConnectionOptions(settings.Server);
            yield return Jabber.AsyncLogin(
                settings.Username, settings.Password, settings.Resource, false, options
            ).Bind(() => session);

            setStatus(0.5f);

            // F*****g soapbox doesn't handle pings or let you handle them with strongly typed packets, wee
            session.OnXMLReceived += (xml, socketID) => {
                if (xml.Contains("<ping xmlns=\"urn:xmpp:ping\""))
                    Program.Scheduler.Start(HandlePing(session, xml, socketID), TaskExecutionPolicy.RunAsBackgroundTask);
            };

            var messagePrefix = settings.ChatAlias.ToLowerInvariant() + ":";

            session.AddHandler(typeof(SoapboxCore.Message.ChatMessagePacket), (p) => {
                var cm = (SoapboxCore.Message.ChatMessagePacket)p;

                string bodyText = null;
                try {
                    bodyText = cm.Body;
                } catch {
                }

                if (bodyText != null)
                    HandleIncomingMessage(gateway, settings.Name, cm.From, bodyText);
            });

            session.AddHandler(typeof(MUC.Message.GroupChatMessage), (p) => {
                var gcm = (MUC.Message.GroupChatMessage)p;

                string bodyText = null;
                try {
                    bodyText = gcm.Body;
                } catch {
                }

                if ((bodyText != null) && (bodyText.ToLowerInvariant().Trim().StartsWith(messagePrefix))) {
                    bodyText = bodyText.Substring(bodyText.IndexOf(':') + 1);
                    HandleIncomingMessage(gateway, settings.Name, gcm.From, bodyText);
                }
            });

            session.OnAsynchronousException += (e) => {
                Program.Scheduler.OnTaskError(e);
            };

            var roomJid = settings.GetRoomJid(true);
            if (roomJid != null)
                yield return session.AsyncSend(new MUC.Presence.JoinRoomRequest(roomJid));

            setStatus(1.0f);

            yield return new Result(new Endpoint(
                gateway, settings, session
            ));
        }
Пример #10
0
        private IEnumerator<object> SaveEndpoint(EndpointSettings settings)
        {
            using (new ControlDisabler(this)) {
                var columnNames = Mapper<EndpointSettings>.ColumnNames;
                var questionMarks = new string[columnNames.Length];
                for (int i = 0; i < questionMarks.Length; i++)
                    questionMarks[i] = "?";

                using (var q = Program.Database.BuildQuery(String.Format(
                    "REPLACE INTO jabber.endpoints ({0}) VALUES ({1})", String.Join(", ", columnNames), String.Join(", ", questionMarks)
                )))
                    yield return q.ExecuteNonQuery(Mapper<EndpointSettings>.GetColumnValues(settings));

                yield return LoadConfiguration();

                yield return Script.InitGateways();
            }
        }