Exemple #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));
            }
        }
Exemple #2
0
        private XmlDocument SetNotifyAdditionToContactListSetting(XmlDocument xmlDoc, NotifyAdditionToContactListType notifyAdditionToContactList, string xmlns)
        {
            if (notifyAdditionToContactList == NotifyAdditionToContactListType.NoChange)
            {
                return(xmlDoc);
            }

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);

            nsmgr.AddNamespace("alerts", xmlns);
            XmlNode notifyAdditionToContactListNode = xmlDoc.SelectSingleNode("//alerts:notifyAdditionToContactList", nsmgr);

            if (notifyAdditionToContactListNode != null)
            {
                if ((notifyAdditionToContactListNode.InnerText.ToLowerInvariant() == "false") && (notifyAdditionToContactList == NotifyAdditionToContactListType.Yes))
                {
                    // Category "alerts" does exist with value of False -> notifyAdditionToContactList node will be modified with value of True
                    xmlDoc.DocumentElement.RemoveChild(notifyAdditionToContactListNode);
                    XmlNode newNode = xmlDoc.CreateNode(XmlNodeType.Element, "notifyAdditionToContactList", xmlns);
                    newNode.InnerText = "true";
                    xmlDoc.DocumentElement.AppendChild(newNode);
                }

                if ((notifyAdditionToContactListNode.InnerText.ToLowerInvariant() == "true") && (notifyAdditionToContactList == NotifyAdditionToContactListType.No))
                {
                    // Category "alerts" does exist with value of True -> notifyAdditionToContactList node will be modified with value of False
                    xmlDoc.DocumentElement.RemoveChild(notifyAdditionToContactListNode);
                    XmlNode newNode = xmlDoc.CreateNode(XmlNodeType.Element, "notifyAdditionToContactList", xmlns);
                    newNode.InnerText = "false";
                    xmlDoc.DocumentElement.AppendChild(newNode);
                }
            }
            else
            {
                // notifyAdditionToContactList node does not exist -> it will be created
                XmlNode newNode = xmlDoc.CreateNode(XmlNodeType.Element, "notifyAdditionToContactList", xmlns);
                if (notifyAdditionToContactList == NotifyAdditionToContactListType.Yes)
                {
                    newNode.InnerText = "true";
                }
                else
                {
                    newNode.InnerText = "false";
                }
                xmlDoc.DocumentElement.AppendChild(newNode);
            }

            return(xmlDoc);
        }
Exemple #3
0
        public void ProcessAlertNotifications(string usersFile, string alertWhenAddToContactListNotification, string alertWhenDNDNotification)
        {
            List <string> usersList = new List <string>();

            try
            {
                usersList = FileAccess.GetUsersFileData(usersFile);
            }
            catch (Exception ex)
            {
                Log.WriteLogEntry("ERROR", String.Format("Error while reading Users file: {0}", ex.Message), "Error while reading Users file.");
                CleanupEnvironment();
                Program.CloseApplicationOnError();
            }

            NotifyAdditionToContactListType notifyAdditionToContactList = NotifyAdditionToContactListType.NoChange;

            switch (alertWhenAddToContactListNotification.ToLowerInvariant())
            {
            case "":
                notifyAdditionToContactList = NotifyAdditionToContactListType.NoChange;
                break;

            case "yes":
                notifyAdditionToContactList = NotifyAdditionToContactListType.Yes;
                break;

            case "no":
                notifyAdditionToContactList = NotifyAdditionToContactListType.No;
                break;

            default:
                // Should not happen
                Log.WriteLogEntry("ERROR", "Incorrect value for NotifyAdd parameter.");
                CleanupEnvironment();
                Program.CloseApplicationOnError();
                break;
            }

            AlertsWhenDoNotDisturbType alertsWhenDoNotDisturb = AlertsWhenDoNotDisturbType.NoChange;

            switch (alertWhenDNDNotification.ToLowerInvariant())
            {
            case "":
                alertsWhenDoNotDisturb = AlertsWhenDoNotDisturbType.NoChange;
                break;

            case "noalerts":
                alertsWhenDoNotDisturb = AlertsWhenDoNotDisturbType.NoAlerts;
                break;

            case "allalerts":
                alertsWhenDoNotDisturb = AlertsWhenDoNotDisturbType.DisplayAllAlerts;
                break;

            case "alertsfromworkgroup":
                alertsWhenDoNotDisturb = AlertsWhenDoNotDisturbType.DisplayAlertsFromHighPresence;
                break;

            default:
                // Should not happen
                Log.WriteLogEntry("ERROR", "Incorrect value for NotifyWhenDND parameter.");
                CleanupEnvironment();
                Program.CloseApplicationOnError();
                break;
            }

            if (usersList.Count > 0)
            {
                ucmaPlatform.StartupPlatform();
                ucmaEndpoint = new Endpoint(ucmaPlatform.CollabPlatform);
                AlertsManager alertsManager = new AlertsManager(ucmaEndpoint);

                foreach (string user in usersList)
                {
                    Log.WriteLogEntry("INFO", String.Format("Processing user {0}...", user.ToLowerInvariant()), String.Format("Processing user {0}...", user.ToLowerInvariant()));

                    try
                    {
                        alertsManager.SetAlertNotificationSetting(user, notifyAdditionToContactList, alertsWhenDoNotDisturb);
                    }
                    catch (RegisterException rex)
                    {
                        Log.WriteLogEntry("ERROR", String.Format("Error while processing user {0}: {1}. Inner Exception: {2}. Diag Info: {3}.", user.ToLowerInvariant(), rex.Message, (rex.InnerException == null ? "N/A" : rex.InnerException.Message), (String.IsNullOrEmpty(rex.DiagnosticInformation.ToString()) ? "N/A" : rex.DiagnosticInformation.ToString())), String.Format("Error while processing user {0}", user.ToLowerInvariant()));
                    }
                    catch (Exception ex)
                    {
                        Log.WriteLogEntry("ERROR", String.Format("Error while processing user {0}: {1}. Inner Exception: {2}", user.ToLowerInvariant(), ex.Message, (ex.InnerException == null ? "N/A" : ex.InnerException.Message)), String.Format("Error while processing user {0}", user.ToLowerInvariant()));
                    }
                }
            }
            else
            {
                Log.WriteLogEntry("WARNING", "Users file is empty or invalid. No action will be performed.");
            }
        }