private void DeleteGroupMailbox() { using (PSLocalTask <RemoveGroupMailbox, object> pslocalTask = CmdletTaskFactory.Instance.CreateRemoveGroupMailboxTask(this.accessingPrincipal)) { pslocalTask.CaptureAdditionalIO = true; pslocalTask.Task.ExecutingUser = new RecipientIdParameter(this.accessingPrincipal.MailboxInfo.PrimarySmtpAddress.ToString()); pslocalTask.Task.Identity = new MailboxIdParameter(this.ExternalDirectoryObjectId ?? this.SmtpAddress); UnifiedGroupsTask.Tracer.TraceDebug <Guid, string>((long)this.GetHashCode(), "ActivityId={0}. {1}", base.ActivityId, new PSLocalTaskLogging.RemoveGroupMailboxToString(pslocalTask.Task).ToString()); pslocalTask.Task.Execute(); UnifiedGroupsTask.Tracer.TraceDebug <Guid, string>((long)this.GetHashCode(), "ActivityId={0}. {1}", base.ActivityId, new PSLocalTaskLogging.TaskOutputToString(pslocalTask.AdditionalIO).ToString()); if (pslocalTask.Error != null) { UnifiedGroupsTask.Tracer.TraceError <Guid, string>((long)this.GetHashCode(), "ActivityId={0}. DeleteUnifiedGroupTask.DeleteGroupMailbox() failed: {1}", base.ActivityId, pslocalTask.ErrorMessage); throw new ExchangeAdaptorException(Strings.GroupMailboxFailedDelete(this.ExternalDirectoryObjectId ?? this.SmtpAddress, pslocalTask.ErrorMessage)); } } }
private GroupMailbox CreateGroupMailbox(string groupObjectId) { GroupMailbox result; using (PSLocalTask <NewGroupMailbox, GroupMailbox> pslocalTask = CmdletTaskFactory.Instance.CreateNewGroupMailboxTask(this.accessingPrincipal)) { pslocalTask.CaptureAdditionalIO = true; pslocalTask.Task.ExecutingUser = new RecipientIdParameter(this.accessingPrincipal.MailboxInfo.PrimarySmtpAddress.ToString()); pslocalTask.Task.Alias = this.Alias; pslocalTask.Task.Name = this.Alias; pslocalTask.Task.DisplayName = this.Name; pslocalTask.Task.ModernGroupType = this.Type; pslocalTask.Task.AutoSubscribeNewGroupMembers = (this.AutoSubscribeNewGroupMembers != null && this.AutoSubscribeNewGroupMembers.Value); if (this.Language != null) { pslocalTask.Task.Language = this.Language; } if (VariantConfiguration.GetSnapshot(MachineSettingsContext.Local, null, null).Global.MultiTenancy.Enabled) { pslocalTask.Task.ExternalDirectoryObjectId = groupObjectId; } if (!string.IsNullOrEmpty(this.Description)) { pslocalTask.Task.Description = this.Description; } pslocalTask.Task.Members = new RecipientIdParameter[] { new RecipientIdParameter(this.accessingPrincipal.MailboxInfo.PrimarySmtpAddress.ToString()) }; pslocalTask.Task.Owners = new RecipientIdParameter[] { new RecipientIdParameter(this.accessingPrincipal.MailboxInfo.PrimarySmtpAddress.ToString()) }; UnifiedGroupsTask.Tracer.TraceDebug <Guid, string>((long)this.GetHashCode(), "ActivityId={0}. {1}", base.ActivityId, new PSLocalTaskLogging.NewGroupMailboxToString(pslocalTask.Task).ToString()); pslocalTask.Task.Execute(); UnifiedGroupsTask.Tracer.TraceDebug <Guid, string>((long)this.GetHashCode(), "ActivityId={0}. {1}", base.ActivityId, new PSLocalTaskLogging.TaskOutputToString(pslocalTask.AdditionalIO).ToString()); if (pslocalTask.Error != null) { UnifiedGroupsTask.Tracer.TraceError <Guid, string>((long)this.GetHashCode(), "ActivityId={0}. CreateUnifiedGroupTask.CreateGroupMailbox: New-GroupMailbox failed: {1}", base.ActivityId, pslocalTask.ErrorMessage); throw new ExchangeAdaptorException(Strings.GroupMailboxFailedCreate(this.Name, pslocalTask.ErrorMessage)); } result = pslocalTask.Result; } return(result); }
internal static void WarmUpAsyncIfRequired(ExchangePrincipal currentUser) { if (WarmupGroupManagementDependency.HasWarmUpAttempted) { return; } lock (WarmupGroupManagementDependency.syncObject) { if (!WarmupGroupManagementDependency.HasWarmUpAttempted) { WarmupGroupManagementDependency.hasWarmUpAttempted = true; WarmupGroupManagementDependency.LogEntry("Scheduling Group management warmup call."); System.Threading.Tasks.Task.Factory.StartNew(delegate() { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); using (PSLocalTask <NewGroupMailbox, GroupMailbox> pslocalTask = CmdletTaskFactory.Instance.CreateNewGroupMailboxTask(currentUser)) { pslocalTask.Task.Name = "WarmUpRequest"; pslocalTask.Task.ExecutingUser = new RecipientIdParameter(currentUser.MailboxInfo.PrimarySmtpAddress.ToString()); pslocalTask.WhatIfMode = true; WarmupGroupManagementDependency.LogEntry("Execute warm up call"); pslocalTask.Task.Execute(); WarmupGroupManagementDependency.LogEntry(string.Format("Executed new group mailbox warm call. output = {0}, error = {1}, total seconds = {2}", (pslocalTask.Result == null) ? "null" : pslocalTask.Result.ToString(), pslocalTask.Error, stopwatch.Elapsed.TotalSeconds.ToString("n2"))); if (WarmupGroupManagementDependency.OnAttemptCompletionCallBack != null) { WarmupGroupManagementDependency.OnAttemptCompletionCallBack(pslocalTask.Result, pslocalTask.ErrorMessage); } } }).ContinueWith(delegate(System.Threading.Tasks.Task t) { WarmupGroupManagementDependency.LogEntry("UnExpected exception. error =" + t.Exception); if (WarmupGroupManagementDependency.OnAttemptCompletionCallBack != null) { WarmupGroupManagementDependency.OnAttemptCompletionCallBack(null, t.Exception.ToString()); } }, TaskContinuationOptions.OnlyOnFaulted); } } }
private void UpdateGroupMailbox(UpdateUnifiedGroupTask.UpdateAADLinkResults results) { using (PSLocalTask <SetGroupMailbox, object> pslocalTask = CmdletTaskFactory.Instance.CreateSetGroupMailboxTask(this.accessingPrincipal)) { pslocalTask.CaptureAdditionalIO = true; pslocalTask.Task.ExecutingUser = new RecipientIdParameter(this.accessingPrincipal.MailboxInfo.PrimarySmtpAddress.ToString()); pslocalTask.Task.Identity = new RecipientIdParameter(this.ExternalDirectoryObjectId ?? this.SmtpAddress); if (this.Description != null) { pslocalTask.Task.Description = this.Description; } if (!string.IsNullOrEmpty(this.DisplayName)) { pslocalTask.Task.DisplayName = this.DisplayName; } string[] array = (results != null) ? this.GetSucceededLinkSmtpAddresses(this.addedMembersIdentities, results.FailedAddedMembers) : this.AddedMembers; if (array != null && array.Length != 0) { pslocalTask.Task.AddedMembers = (from o in array select new RecipientIdParameter(o)).ToArray <RecipientIdParameter>(); } string[] array2 = (results != null) ? this.GetSucceededLinkSmtpAddresses(this.removedMembersIdentities, results.FailedRemovedMembers) : this.RemovedMembers; if (array2 != null && array2.Length != 0) { pslocalTask.Task.RemovedMembers = (from o in array2 select new RecipientIdParameter(o)).ToArray <RecipientIdParameter>(); } string[] array3 = (results != null) ? this.GetSucceededLinkSmtpAddresses(this.addedOwnersIdentities, results.FailedAddedOwners) : this.AddedOwners; if (array3 != null && array3.Length != 0) { pslocalTask.Task.AddOwners = (from o in array3 select new RecipientIdParameter(o)).ToArray <RecipientIdParameter>(); } string[] array4 = (results != null) ? this.GetSucceededLinkSmtpAddresses(this.removedOwnersIdentities, results.FailedRemovedOwners) : this.RemovedOwners; if (array4 != null && array4.Length != 0) { pslocalTask.Task.RemoveOwners = (from o in array4 select new RecipientIdParameter(o)).ToArray <RecipientIdParameter>(); } if (this.RequireSenderAuthenticationEnabled != null) { pslocalTask.Task.RequireSenderAuthenticationEnabled = this.RequireSenderAuthenticationEnabled.Value; } if (this.AutoSubscribeNewGroupMembers != null) { pslocalTask.Task.AutoSubscribeNewGroupMembers = this.AutoSubscribeNewGroupMembers.Value; } if (this.Language != null) { pslocalTask.Task.Language = this.Language; } UnifiedGroupsTask.Tracer.TraceDebug <Guid, PSLocalTaskLogging.SetGroupMailboxToString>((long)this.GetHashCode(), "ActivityId={0}. {1}", base.ActivityId, new PSLocalTaskLogging.SetGroupMailboxToString(pslocalTask.Task)); pslocalTask.Task.Execute(); UnifiedGroupsTask.Tracer.TraceDebug <Guid, PSLocalTaskLogging.TaskOutputToString>((long)this.GetHashCode(), "ActivityId={0}. {1}", base.ActivityId, new PSLocalTaskLogging.TaskOutputToString(pslocalTask.AdditionalIO)); if (pslocalTask.Error != null) { UnifiedGroupsTask.Tracer.TraceError <Guid, string>((long)this.GetHashCode(), "ActivityId={0}. UpdateUnifiedGroupTask.UpdateGroupMailbox() failed: {1}", base.ActivityId, pslocalTask.ErrorMessage); throw new ExchangeAdaptorException(Strings.GroupMailboxFailedUpdate(this.ExternalDirectoryObjectId ?? this.SmtpAddress, pslocalTask.ErrorMessage)); } } }