Beispiel #1
0
 public ServiceEndpoint(IChannelDispatcher channelDispatcher, IServiceBinder binder, ITaskScheduler scheduler, Uri uri)
 {
     this.channelDispatcher = channelDispatcher;
     this.binder            = binder;
     this.scheduler         = scheduler;
     this.Uri = uri;
     channelDispatcher.OnMessage(this.OnMessage);
 }
Beispiel #2
0
        public void OpenConversationWithBuddy(string contactId, string message)
        {
            Contact contact = FindContact(contactId);

            ObjectPath         opath = new ObjectPath(EmpathyPlugin.CHANNELDISPATCHER_PATH);
            IChannelDispatcher iChannelDispatcherBus = Bus.Session.GetObject <IChannelDispatcher> (EmpathyPlugin.CHANNELDISPATCHER_IFACE, opath);

            Dictionary <string, object> channelRequestParameters = new Dictionary <string, object> ();

            channelRequestParameters.Add(EmpathyPlugin.CHANNEL_TYPE, EmpathyPlugin.CHANNEL_TYPE_TEXT);
            channelRequestParameters.Add(EmpathyPlugin.CHANNEL_TARGETHANDLETYPE, HandleType.Contact);
            channelRequestParameters.Add(EmpathyPlugin.CHANNEL_TARGETHANDLE, contact.ContactUInt);

            ObjectPath messageChannelPath = iChannelDispatcherBus.EnsureChannel(this.accountPath, channelRequestParameters, DateTime.Now.Ticks, "org.freedesktop.Telepathy.Client.Empathy");

            IChannelRequest iChannelRequest = Bus.Session.GetObject <IChannelRequest> (EmpathyPlugin.ACCOUNTMANAGER_IFACE, messageChannelPath);

            iChannelRequest.Proceed();

            if (message == null)
            {
                return;
            }

            foreach (ChannelInfo channelInfo in this.iConnection.ListChannels())
            {
                if (channelInfo.ChannelType == EmpathyPlugin.CHANNEL_TYPE_TEXT &&
                    channelInfo.HandleType == HandleType.Contact && channelInfo.Handle == contact.ContactUInt)
                {
                    IMessages messageChannel            = Bus.Session.GetObject <IMessages> (this.connectionBusIFace, channelInfo.Channel);
                    IDictionary <string, object> header = new Dictionary <string, object>()
                    {
                        { "message-type", ChannelTextMessageType.Notice }
                    };
                    IDictionary <string, object> alternative = new Dictionary <string, object>()
                    {
                        { "alternative", "main" },
                        { "content-type", "text/plain" },
                        { "content", message }
                    };
                    messageChannel.SendMessage(new IDictionary <string, object>[] { header, alternative }, MessageSendingFlags.None);
                }
            }
        }