示例#1
0
        private void xcapService_onXcapEvent(object sender, BogheCore.Xcap.Events.XcapEventArgs e)
        {
            if (e.Type != XcapEventTypes.PRESCONTENT_DONE)
            {
                return;
            }

            if (this.Dispatcher.Thread != System.Threading.Thread.CurrentThread)
            {
                this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
                                            new EventHandler <XcapEventArgs>(this.xcapService_onXcapEvent), sender, new object[] { e });
                return;
            }

            switch (e.Type)
            {
            case XcapEventTypes.PRESCONTENT_DONE:
            {
                object content = e.GetExtra(XcapEventArgs.EXTRA_CONTENT);
                if (content != null && content is String)
                {
                    this.SetAvatarFromBase64String(content as String);
                }
                break;
            }

            default:
                break;
            }
        }
示例#2
0
        private void xcapService_onXcapEvent(object sender, XcapEventArgs e)
        {
            if (e.Type != XcapEventTypes.PRESCONTENT_DONE)
            {
                return;
            }

            if (this.Dispatcher.Thread != System.Threading.Thread.CurrentThread)
            {
                this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
                        new EventHandler<XcapEventArgs>(this.xcapService_onXcapEvent), sender, new object[] { e });
                return;
            }

            switch (e.Type)
            {
                case XcapEventTypes.PRESCONTENT_DONE:
                    {
                        System.Drawing.Image avatar;
                        object content = e.GetExtra(XcapEventArgs.EXTRA_CONTENT);
                        if (content != null && content is String)
                        {
                            try
                            {
                                using (MemoryStream stream = new MemoryStream(Convert.FromBase64String(content as String)))
                                {
                                    avatar = System.Drawing.Bitmap.FromStream(stream);
                                    this.imageAvatar.Source = MyImageConverter.FromBitmap(avatar as System.Drawing.Bitmap);
                                }
                            }
                            catch (Exception ex)
                            {
                                LOG.Error("Failed to get avatar", ex);
                            }
                        }
                        break;
                    }

                default:
                    break;
            }
        }
示例#3
0
        public bool AvatarPublish(String base64Content, String mimeType)
        {
            if (!this.prepared)
            {
                LOG.Error("XCAP sevice not prepared");
                return false;
            }
            if (!this.hasOMAPresenceContent)
            {
                LOG.Error("OMAPresenceContent not supported");
                return false;
            }

            new System.Threading.Thread(delegate()
                {
                    if (this.CreatePresenceContentDocument(base64Content, mimeType))
                    {
                        this.Avatar = base64Content;
                        XcapEventArgs eargs = new XcapEventArgs(XcapEventTypes.PRESCONTENT_DONE, 200, "OK");
                        eargs.AddExtra(XcapEventArgs.EXTRA_CONTENT, this.Avatar);
                        EventHandlerTrigger.TriggerEvent<XcapEventArgs>(this.onXcapEvent, this, eargs);
                    }
                })
                .Start();

            return true;
        }
示例#4
0
        public bool DownloadDocuments()
        {
            if (!this.prepared)
            {
                LOG.Error("XCAP sevice not prepared");
                return false;
            }

            this.ready = false;
            this.xcapDocumentsUris.Clear();
            this.rlsPresUri = null;

            lock (this.xcapSelector)
            {
                MyXcapMessage xcapMessage;

                // ============== xcap-caps ============== //
                String xcapCapsUrl;
                lock (this.xcapSelector)
                {
                    this.xcapSelector.reset();
                    this.xcapSelector.setAUID(XcapService.XCAP_AUID_IETF_XCAP_CAPS_ID);
                    xcapCapsUrl = this.xcapSelector.getString();
                }
                xcapMessage = this.xcapStack.GetDocument(xcapCapsUrl);
                // xcap-caps is mandatory ==> continue the process only if all is ok
                if (xcapMessage == null)
                {
                    LOG.Error("Failed to get 'xcap-caps' document");
                    return false;
                }
                if (!this.handleXcapCapsEvent(xcapMessage.Code, xcapMessage.Content))
                {
                    LOG.Error("Failed to handle 'xcap-caps' document");
                    return false;
                }

                // ============== org.openmobilealliance.xcap-directory ============== //
                if (this.hasOMADirectory)
                {
                    if (this.xcapStack.IsRunning)
                    {
                        xcapMessage = this.GetWellKnownDocument(XcapService.XCAP_AUID_OMA_DIRECTORY_ID);
                        if (xcapMessage != null)
                        {
                            if (!this.handleOMADirectoryEvent(xcapMessage.Code, xcapMessage.Content))
                            {
                                LOG.Error("Failed to handle 'org.openmobilealliance.xcap-directory' document");
                            }
                        }
                        else
                        {
                            LOG.Error("Failed to get 'org.openmobilealliance.xcap-directory' document");
                        }
                    }
                    else
                    {
                        LOG.Warn("XCAP Stack not running");
                    }
                }
                else
                {
                    LOG.Warn("'org.openmobilealliance.xcap-directory' not supported");
                }

                // ============== resource-lists ============== //
                if (hasResourceLists)
                {
                    if (this.xcapStack.IsRunning)
                    {
                        xcapMessage = this.GetWellKnownDocument(XcapService.XCAP_AUID_IETF_RESOURCE_LISTS_ID);
                        if (xcapMessage != null)
                        {
                            if (!this.HandleResourceListsEvent(xcapMessage.Code, xcapMessage.Content))
                            {
                                LOG.Error("Failed to handle 'resource-lists' document");
                            }
                            else
                            {
                                EventHandlerTrigger.TriggerEvent<XcapEventArgs>(this.onXcapEvent, this,
                                    new XcapEventArgs(XcapEventTypes.RESOURCE_LISTS_DONE, xcapMessage.Code, xcapMessage.Phrase));
                            }
                        }
                        else
                        {
                            LOG.Error("Failed to get 'resource-lists' document");
                        }
                    }
                    else
                    {
                        LOG.Warn("XCAP Stack not running");
                    }
                }
                else
                {
                    LOG.Error("'resource-lists' not supported");
                }

                // ============== rls-services ============== //
                if (this.hasRLS)
                {
                    if (this.xcapStack.IsRunning)
                    {
                        xcapMessage = this.GetWellKnownDocument(XcapService.XCAP_AUID_IETF_RLS_SERVICES_ID);
                        if (xcapMessage != null)
                        {
                            if (!this.HandleRLSEvent(xcapMessage.Code, xcapMessage.Content))
                            {
                                LOG.Error("Failed to handle 'resource-lists' document");
                            }
                            else
                            {
                                EventHandlerTrigger.TriggerEvent<XcapEventArgs>(this.onXcapEvent, this,
                                    new XcapEventArgs(XcapEventTypes.RLS_DONE, xcapMessage.Code, xcapMessage.Phrase));
                            }
                        }
                        else
                        {
                            LOG.Error("Failed to get 'resource-lists' document");
                        }
                    }
                    else
                    {
                        LOG.Warn("XCAP Stack not running");
                    }
                }
                else
                {
                    LOG.Error("'rls-services' not supported");
                }

                // ============== org.openmobilealliance.pres-content ============== //
                if (this.hasOMAPresRules)
                {
                    if (this.xcapStack.IsRunning)
                    {
                        xcapMessage = this.GetWellKnownDocument(XcapService.XCAP_AUID_OMA_PRES_RULES_ID);
                        if (xcapMessage != null)
                        {
                            if (!this.HandleOMAPresRules(xcapMessage.Code, xcapMessage.Content))
                            {
                                LOG.Error("Failed to handle 'org.openmobilealliance.pres-content' document");
                            }
                        }
                        else
                        {
                            LOG.Error("Failed to get 'org.openmobilealliance.pres-content' document");
                        }
                    }
                    else
                    {
                        LOG.Warn("XCAP Stack not running");
                    }
                }
                else
                {
                    LOG.Error("'org.openmobilealliance.pres-content' not supported");
                }

                // ============== org.openmobilealliance.pres-content ============== //
                if (this.hasOMAPresenceContent)
                {
                    if (this.xcapStack.IsRunning)
                    {
                        xcapMessage = this.GetWellKnownDocument(XcapService.XCAP_AUID_OMA_PRES_CONTENT_ID);
                        if (xcapMessage != null)
                        {
                            if (!this.HandlePresContent(xcapMessage.Code, xcapMessage.Content))
                            {
                                LOG.Error("Failed to handle 'org.openmobilealliance.pres-content' document");
                            }
                            else
                            {
                                XcapEventArgs eargs = new XcapEventArgs(XcapEventTypes.PRESCONTENT_DONE, xcapMessage.Code, xcapMessage.Phrase);
                                eargs.AddExtra(XcapEventArgs.EXTRA_CONTENT, this.Avatar);
                                EventHandlerTrigger.TriggerEvent<XcapEventArgs>(this.onXcapEvent, this, eargs);
                            }
                        }
                        else
                        {
                            LOG.Error("Failed to get 'org.openmobilealliance.pres-content' document");
                        }
                    }
                    else
                    {
                        LOG.Warn("XCAP Stack not running");
                    }
                }

            }

            this.ready = true;

            return true;
        }
示例#5
0
        private void xcapService_onXcapEvent(object sender, XcapEventArgs e)
        {
            switch (e.Type)
            {
                case XcapEventTypes.RLS_DONE:
                    if (this.IsSubscriptionToRLSEnabled)
                    {
                        this.SubscribeToRLSPresence();
                    }
                    break;

                default:
                    break;
            }
        }