示例#1
0
        public void SetAlertNotificationSetting(string userUri, NotifyAdditionToContactListType notifyAdditionToContactList, AlertsWhenDoNotDisturbType alertsWhenDoNotDisturb)
        {
            const string defaultDataXml = "<alerts xmlns=\"http://schemas.microsoft.com/2006/09/sip/options/alerts\"></alerts>";
            const string alertsXmlns    = "http://schemas.microsoft.com/2006/09/sip/options/alerts";

            if ((notifyAdditionToContactList != NotifyAdditionToContactListType.NoChange) || (alertsWhenDoNotDisturb != AlertsWhenDoNotDisturbType.NoChange))
            {
                string newDataXml = "";

                userEndpoint.InitializeUserEndpoint(userUri);
                userEndpoint.SubscribeToPresence();

                if (userEndpoint.User.ContactGroupServices.CurrentState == CollaborationSubscriptionState.Subscribed)
                {
                    XmlDocument doc = new XmlDocument();

                    if (userEndpoint.AlertNotification != null)
                    {
                        string dataXml = userEndpoint.AlertNotification.Category.GetCategoryDataXml();
                        doc.LoadXml(dataXml);

                        string xmlns = doc.DocumentElement.Attributes["xmlns"].Value;
                        if (xmlns != alertsXmlns)
                        {
                            doc.LoadXml(defaultDataXml);
                        }
                    }
                    else
                    {
                        doc.LoadXml(defaultDataXml);
                    }

                    doc = SetNotifyAdditionToContactListSetting(doc, notifyAdditionToContactList, alertsXmlns);
                    doc = SetAlertsWhenDoNotDisturbSetting(doc, alertsWhenDoNotDisturb, alertsXmlns);

                    newDataXml = doc.InnerXml;
                }
                else
                {
                    throw new Exception("Collaboration subscription state is not subscribed");
                }

                PresenceCategory        cat           = new CustomPresenceCategory("alerts", newDataXml);
                List <PresenceCategory> catCollection = new List <PresenceCategory>();
                catCollection.Add(cat);
                userEndpoint.User.LocalOwnerPresence.EndPublishPresence(userEndpoint.User.LocalOwnerPresence.BeginPublishPresence(catCollection, null, null));
            }
        }
示例#2
0
        // Publish note, state, contact card presence categories
        private void PublishPresenceCategories(bool publishFlag, string status = null)
        {
            try
            {
                if (publishFlag == true)
                {
                    // The CustomPresenceCategory class enables creation of a
                    // category using XML. This allows precise crafting of a
                    // category, but it is also possible to create a category
                    // in other, more simple ways, shown below.
                    _note = new CustomPresenceCategory("note", String.Format(_noteXml, _noteValue));

                    switch (status)
                    {
                    default:     //Available
                        _userState = PresenceState.UserAvailable;
                        Console.WriteLine(DateTime.Now.ToString() + " Setting available status.");
                        // It is possible to create and publish state with a custom availablity string, shown below
                        LocalizedString localizedAvailableString = new LocalizedString("Available");

                        // Create a PresenceActivity indicating the "In a call" state.
                        PresenceActivity Available = new PresenceActivity(localizedAvailableString);

                        // Set the Availability of the "In a call" state to Busy.
                        Available.SetAvailabilityRange((int)PresenceAvailability.Online,
                                                       (int)PresenceAvailability.Online);

                        // Microsoft Lync will also show the Busy presence icon.
                        _phoneState = new PresenceState(
                            (int)PresenceAvailability.Online,
                            Available,
                            PhoneCallType.Voip,
                            "phone uri");
                        break;

                    case "Busy":     //Busy
                        Console.WriteLine(DateTime.Now.ToString() + " Setting busy status.");
                        _userState = PresenceState.UserBusy;
                        LocalizedString  localizedBusyString = new LocalizedString("Busy");
                        PresenceActivity Busy = new PresenceActivity(localizedBusyString);
                        Busy.SetAvailabilityRange((int)PresenceAvailability.Busy,
                                                  (int)PresenceAvailability.IdleBusy);
                        _phoneState = new PresenceState(
                            (int)PresenceAvailability.Busy,
                            Busy,
                            PhoneCallType.Voip,
                            "phone uri");
                        break;


                    case "In a call":     //In a call
                        Console.WriteLine(DateTime.Now.ToString() + " Setting in a call status.");
                        _userState = PresenceState.UserBusy;
                        LocalizedString  localizedCallString = new LocalizedString("In a call");
                        PresenceActivity inACall             = new PresenceActivity(localizedCallString);
                        inACall.SetAvailabilityRange((int)PresenceAvailability.Busy,
                                                     (int)PresenceAvailability.IdleBusy);
                        _phoneState = new PresenceState(
                            (int)PresenceAvailability.Busy,
                            inACall,
                            PhoneCallType.Voip,
                            "phone uri");
                        break;

                    case "In a meeting":     //In a meeting
                        Console.WriteLine(DateTime.Now.ToString() + " Setting in a meeting status.");
                        _userState = PresenceState.UserBusy;
                        LocalizedString  localizedMeetingString = new LocalizedString("In a meeting");
                        PresenceActivity inAMeeting             = new PresenceActivity(localizedMeetingString);
                        inAMeeting.SetAvailabilityRange((int)PresenceAvailability.Busy,
                                                        (int)PresenceAvailability.IdleBusy);
                        _phoneState = new PresenceState(
                            (int)PresenceAvailability.Busy,
                            inAMeeting,
                            PhoneCallType.Voip,
                            "phone uri");
                        break;

                    case "In a conference call":     //In a conference call
                        Console.WriteLine(DateTime.Now.ToString() + " Setting in a conference call status.");
                        _userState = PresenceState.UserBusy;
                        LocalizedString  localizedConferenceString = new LocalizedString("In a conference call");
                        PresenceActivity inAConference             = new PresenceActivity(localizedConferenceString);
                        inAConference.SetAvailabilityRange((int)PresenceAvailability.Busy,
                                                           (int)PresenceAvailability.IdleBusy);
                        _phoneState = new PresenceState(
                            (int)PresenceAvailability.Busy,
                            inAConference,
                            PhoneCallType.Voip,
                            "phone uri");
                        break;

                    case "Presenting":     //Presenting
                        Console.WriteLine(DateTime.Now.ToString() + " Setting presenting status.");
                        _userState = PresenceState.UserBusy;
                        LocalizedString  localizedPresentingString = new LocalizedString("Presenting");
                        PresenceActivity Presenting = new PresenceActivity(localizedPresentingString);
                        Presenting.SetAvailabilityRange((int)PresenceAvailability.Busy,
                                                        (int)PresenceAvailability.DoNotDisturb);
                        _phoneState = new PresenceState(
                            (int)PresenceAvailability.DoNotDisturb,
                            Presenting,
                            PhoneCallType.Voip,
                            "phone uri");
                        break;

                    case "Offline":     //Offline
                        Console.WriteLine(DateTime.Now.ToString() + " Setting offline status.");
                        _userState = PresenceState.UserOffline;
                        LocalizedString  localizedOfflineString = new LocalizedString("Offline");
                        PresenceActivity Offline = new PresenceActivity(localizedOfflineString);
                        Offline.SetAvailabilityRange((int)PresenceAvailability.Offline,
                                                     (int)PresenceAvailability.Offline);
                        _phoneState = new PresenceState(
                            (int)PresenceAvailability.Offline,
                            Offline,
                            PhoneCallType.Voip,
                            "phone uri");
                        break;
                    }

                    // Machine or Endpoint states must always be published to
                    // indicate the endpoint is actually online, otherwise it is
                    // assumed the endpoint is offline, and no presence
                    // published from that endpoint will be displayed.
                    _machineState = PresenceState.EndpointOnline;

                    // It is also possible to create presence categories such
                    // as ContactCard, Note, PresenceState, and Services with
                    // their constructors.
                    // Here we create a ContactCard and change the title.
                    _contactCard = new ContactCard(0);

                    /* The title string to be displayed. */
                    if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["UserTitle"]))
                    {
                        LocalizedString localizedTitleString = new LocalizedString(ConfigurationManager.AppSettings["UserTitle"]);
                        _contactCard.JobTitle = localizedTitleString.Value;
                    }

                    if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["UserOffice"]))
                    {
                        LocalizedString localizedTitleString = new LocalizedString(ConfigurationManager.AppSettings["UserOffice"]);
                        _contactCard.OfficeLocation = localizedTitleString.Value;
                    }

                    if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["JobTitle"]))
                    {
                        LocalizedString localizedTitleString = new LocalizedString(ConfigurationManager.AppSettings["JobTitle"]);
                        _contactCard.JobTitle = localizedTitleString.Value;
                    }
                    // Publish a photo
                    // If the supplied value for photo is null or empty, then set value of IsAllowedToShowPhoto to false
                    _contactCard.IsAllowedToShowPhoto = false;

                    string photoUri = ConfigurationManager.AppSettings["PhotoUri"];
                    if (!String.IsNullOrEmpty(photoUri))
                    {
                        _contactCard.IsAllowedToShowPhoto = true;
                        _contactCard.PhotoUri             = photoUri;
                    }

                    // Publish all presence categories with new values.
                    _localOwnerPresence.BeginPublishPresence(
                        new PresenceCategory[]
                    {
                        _userState,
                        _phoneState,
                        _machineState,
                        _note,
                        _contactCard
                    },
                        PublishPresenceCompleted, /* async callback when publishing operation completes. */
                        publishFlag /* value TRUE indicates that presence to be published with new values. */);
                }
                else
                {
                    // Delete all presence categories.
                    Console.WriteLine(DateTime.Now.ToString() + " Revert status back.");
                    _localOwnerPresence.BeginDeletePresence(
                        new PresenceCategory[]
                    {
                        _userState,
                        _phoneState,
                        _machineState,
                        _note,
                        _contactCard
                    },
                        PublishPresenceCompleted,
                        publishFlag /* value FALSE indicates that presence reverted to original values. */);
                }
            }
            catch (PublishSubscribeException pse)
            {
                // PublishSubscribeException is thrown when there were
                // exceptions during this presence operation such as badly
                // formed sip request, duplicate publications in the same
                // request etc.
                // TODO (Left to the reader): Include exception handling code
                // here.
                Console.WriteLine(pse.ToString());
            }
            catch (RealTimeException rte)
            {
                // RealTimeException is thrown when SIP Transport, SIP
                // Authentication, and credential-related errors are
                // encountered.
                // TODO (Left to the reader): Include exception handling code
                // here.
                Console.WriteLine(rte.ToString());
            }
        }
示例#3
0
        // Publish note, state, contact card presence categories
        private void PublishPresenceCategories(bool publishFlag)
        {
            try
            {
                if (publishFlag == true)
                {
                    // The CustomPresenceCategory class enables creation of a
                    // category using XML. This allows precise crafting of a
                    // category, but it is also possible to create a category
                    // in other, more simple ways, shown below.
                    _note = new CustomPresenceCategory("note", String.Format(_noteXml, _noteValue));

                    // The PresenceState class has several static properties
                    // and methods which will provide standard states such as
                    // online, busy, and on-the-phone, for example.
                    _userState = PresenceState.UserBusy;

                    // It is possible to create and publish state with a
                    // custom availablity string, shown below. "In a call" will
                    // be shown in Microsoft Lync.
                    LocalizedString localizedCallString = new LocalizedString(
                        "In a call" /* The string to be displayed. */);

                    // Create a PresenceActivity indicating the
                    // "In a call" state.
                    PresenceActivity inACall = new PresenceActivity(
                        localizedCallString);

                    // Set the Availability of the "In a call" state to Busy.
                    inACall.SetAvailabilityRange((int)PresenceAvailability.Busy,
                                                 (int)PresenceAvailability.IdleBusy);

                    // Microsoft Lync will also show the Busy presence icon.
                    _phoneState = new PresenceState(
                        (int)PresenceAvailability.Busy,
                        inACall,
                        PhoneCallType.Voip,
                        "phone uri");

                    // Machine or Endpoint states must always be published to
                    // indicate the endpoint is actually online, otherwise it is
                    // assumed the endpoint is offline, and no presence
                    // published from that endpoint will be displayed.
                    _machineState = PresenceState.EndpointOnline;

                    // It is also possible to create presence categories such
                    // as ContactCard, Note, PresenceState, and Services with
                    // their constructors.
                    // Here we create a ContactCard and change the title.
                    _contactCard = new ContactCard(3);
                    LocalizedString localizedTitleString = new LocalizedString(
                        "The Boss" /* The title string to be displayed. */);
                    _contactCard.JobTitle = localizedTitleString.Value;

                    // Publish a photo
                    // If the supplied value for photo is null or empty, then set value of IsAllowedToShowPhoto to false
                    _contactCard.IsAllowedToShowPhoto = true;
                    string photoUri = UCMASampleHelper.PromptUser("Please enter a Photo Uri in the form of http://mysite/photo1.jpg", "PhotoURI1");
                    if (String.IsNullOrEmpty(photoUri))
                    {
                        photoUri = null;
                        _contactCard.IsAllowedToShowPhoto = false;
                    }
                    _contactCard.PhotoUri = photoUri;

                    // Publish all presence categories with new values.
                    _localOwnerPresence.BeginPublishPresence(
                        new PresenceCategory[]
                    {
                        _userState,
                        _phoneState,
                        _machineState,
                        _note,
                        _contactCard
                    },
                        PublishPresenceCompleted, /* async callback when publishing operation completes. */
                        publishFlag /* value TRUE indicates that presence to be published with new values. */);
                }
                else
                {
                    // Delete all presence categories.
                    _localOwnerPresence.BeginDeletePresence(
                        new PresenceCategory[]
                    {
                        _userState,
                        _phoneState,
                        _machineState,
                        _note,
                        _contactCard
                    },
                        PublishPresenceCompleted,
                        publishFlag /* value FALSE indicates that presence reverted to original values. */);
                }
            }
            catch (PublishSubscribeException pse)
            {
                // PublishSubscribeException is thrown when there were
                // exceptions during this presence operation such as badly
                // formed sip request, duplicate publications in the same
                // request etc.
                // TODO (Left to the reader): Include exception handling code
                // here.
                Console.WriteLine(pse.ToString());
            }
            catch (RealTimeException rte)
            {
                // RealTimeException is thrown when SIP Transport, SIP
                // Authentication, and credential-related errors are
                // encountered.
                // TODO (Left to the reader): Include exception handling code
                // here.
                Console.WriteLine(rte.ToString());
            }
        }