public void SetPrivacyPreference(string userUri, PrivacyModePreference privacyMode) { userEndpoint.InitializeUserEndpoint(userUri); userEndpoint.SubscribeToPresence(); if (userEndpoint.User.ContactGroupServices.CurrentState == CollaborationSubscriptionState.Subscribed) { userEndpoint.User.PresenceServices.EndUpdatePrivacyPreference(userEndpoint.User.PresenceServices.BeginUpdatePrivacyPreference(privacyMode, null, null)); } else { throw new Exception("Collaboration subscription state is not subscribed"); } }
public void ProcessPrivacy(string usersFile, string privacyPreference) { 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(); } PrivacyModePreference userPrivacyPreference = PrivacyModePreference.None; switch (privacyPreference.ToLowerInvariant()) { case "default": userPrivacyPreference = PrivacyModePreference.None; break; case "private": userPrivacyPreference = PrivacyModePreference.Private; break; case "public": userPrivacyPreference = PrivacyModePreference.Standard; break; default: // Should not happen Log.WriteLogEntry("ERROR", "Incorrect value for PrivacyPreference parameter."); CleanupEnvironment(); Program.CloseApplicationOnError(); break; } if (usersList.Count > 0) { ucmaPlatform.StartupPlatform(); ucmaEndpoint = new Endpoint(ucmaPlatform.CollabPlatform); PrivacyManager privacyManager = new PrivacyManager(ucmaEndpoint); foreach (string user in usersList) { Log.WriteLogEntry("INFO", String.Format("Processing user {0}...", user.ToLowerInvariant()), String.Format("Processing user {0}...", user.ToLowerInvariant())); try { privacyManager.SetPrivacyPreference(user, userPrivacyPreference); } 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."); } }