Compartir a través de


Deleting an Existing Publication

On the protocol level, removing a published category instance from a publication is equivalent to republishing the category instance as a time-bound instance with the expiration time set to zero. The following example is a SIP message sent to the server when a SERVICE request to delete the publication of a note category instance is submitted.

SERVICE sip:adamb@contoso.com SIP/2.0
FROM: <sip:adamb@contoso.com>;epid=6C801B691B;tag=ff76c3f124
TO: <sip:adamb@contoso.com>;epid=6C801B691B
CSEQ: 7 SERVICE
CALL-ID: 68f271a55a574ac197afccabe755d56b
MAX-FORWARDS: 70
VIA: SIP/2.0/TLS 192.168.0.199:25849;branch=z9hG4bKb2809a28
AUTHORIZATION: NTLM realm="SIP Communications Service",targetname="tuk-ocdr1-03.contoso.com",response="0100000000000000815295211eb3dd60",crand="f99070ee",cnum="11",opaque="5431637F",qop="auth"
CONTACT: <sip:adamb@contoso.com;opaque=user:epid:gAXJXq9AgVCiWynxdwgUSwAA;gruu>;text;audio;video;image
CONTENT-LENGTH: 249
SUPPORTED: gruu-10
USER-AGENT: RTCC/4.0.0.0 PresPub
CONTENT-TYPE: application/msrtc-category-publish+xml
<publish xmlns="https://schemas.microsoft.com/2006/09/sip/rich-presence">
   <publications uri="sip:adamb@contoso.com">
      <publication categoryName="note" instance="1" container="100" version="0" expireType="time" expires="0" />
   </publications>
</publish>

As with presence publications, removing a category instance from a publication can also be grammar-based or grammar-free. The SIP request in the example above originates from a grammar-free deletion of the publication.

On the API level, presence deletion can be exposed in a set of methods dedicated to this particular type of operations. In UCMA, the deletion is implemented as the asynchronous programming pattern of BeginDeletePresence/EndDeletePresence. For grammar-free presence deletion, the BeginDeletePresence takes a collection of PresenceCategory objects in its input. For grammar-based presence deletion, the BeginDeletePresence method takes a collection of PresenceCategoryWithMetaData object in its input. These are illustrated in the following code snippets.

        public void RequestGrammarBasedPresencePublicationRemoval(string categoryName)
        {
            CustomPresenceCategory category = new CustomPresenceCategory(categoryName, string.Empty /* null */);
            PresenceCategory[] categories = new PresenceCategory[] { category };
            _localPresence.BeginDeletePresence(categories, CallbackOnDeletePresenceReturned, _localPresence);
        }

        public void RequestGrammarFreePresencePublicationRemoval(string catName, long instanceId, int containerId)
        {
            PresenceCategoryWithMetaData[] categories = new PresenceCategoryWithMetaData[] {
                new PresenceCategoryWithMetaData(catName, instanceId, containerId) };
            _localPresence.BeginDeletePresence(categories, CallbackOnDeletePresenceReturned, _localPresence);
        }

        void CallbackOnDeletePresenceReturned(IAsyncResult result)
        {
            try
            {
                if (_localPresence == result.AsyncState as LocalOwnerPresence)
                {
                    _localPresence.EndDeletePresence(result);

                    if (OnDeletePresenceCompleted != null)
                        RaiseEvent(OnDeletePresenceCompleted, this,
                            new AsyncOpStatusEventArgs(AsyncOpStatus.OK, null));

                }
            }
            catch (Exception ex)
            {
                if (OnDeletePresenceCompleted != null)
                    RaiseEvent(OnDeletePresenceCompleted, this,
                        new AsyncOpStatusEventArgs(AsyncOpStatus.Error, ex));
            }
        }

In addition to calling BeginDeletePresence/EndDeletePresence, a UCMA can also implement the presence deletion as a publication of time-bound category instances with the expiration time set to zero. The following code example provides an illustration of this.

        public void RequestGrammarFreePresencePublicationToDeletePresenceCategory(string catName, long instanceId, int containerId)
        {           
            PresenceCategoryWithMetaData pcm = new PresenceCategoryWithMetaData(catName, instanceId, containerId);
            pcm.ExpiryPolicy = ExpiryPolicy.Time;
            pcm.Expires = 0;
            this.RequestGrammarFreePresencePublication(new PresenceCategoryWithMetaData[] { pcm });
        }