private async Task <CSEntryChangeResult> PutCSEntryChangeDelete(CSEntryChange csentry) { string teamid = csentry.GetAnchorValueOrDefault <string>("teamid"); try { if (this.context.ConfigParameters[ConfigParameterNames.RandomizeChannelNameOnDelete].Value == "1") { string newname = $"deleted-{Guid.NewGuid():N}"; Beta.Channel c = new Beta.Channel(); c.DisplayName = newname; await GraphHelperTeams.UpdateChannel(this.betaClient, teamid, csentry.DN, c, this.token); logger.Info($"Renamed channel {csentry.DN} on team {teamid} to {newname}"); } await GraphHelperTeams.DeleteChannel(this.betaClient, teamid, csentry.DN, this.token); } catch (ServiceException ex) { if (ex.StatusCode == HttpStatusCode.NotFound) { logger.Warn($"The request to delete the channel {csentry.DN} failed because it doesn't exist"); } else { throw; } } return(CSEntryChangeResult.Create(csentry.Identifier, null, MAExportError.Success)); }
private async Task PutCSEntryChangeUpdateChannel(CSEntryChange csentry) { string teamid = csentry.GetAnchorValueOrDefault <string>("teamid"); string channelid = csentry.GetAnchorValueOrDefault <string>("id"); bool changed = false; Beta.Channel channel = new Beta.Channel(); foreach (AttributeChange change in csentry.AttributeChanges) { if (change.DataType == AttributeType.Boolean && change.ModificationType == AttributeModificationType.Delete) { throw new UnsupportedBooleanAttributeDeleteException(change.Name); } if (change.Name == "team") { throw new InitialFlowAttributeModificationException(change.Name); } else if (change.Name == "isFavoriteByDefault") { channel.IsFavoriteByDefault = change.GetValueAdd <bool>(); } else if (change.Name == "displayName") { if (change.ModificationType == AttributeModificationType.Delete) { throw new UnsupportedAttributeDeleteException(change.Name); } channel.DisplayName = change.GetValueAdd <string>(); } else if (change.Name == "description") { if (change.ModificationType == AttributeModificationType.Delete) { channel.AssignNullToProperty("description"); } else { channel.Description = change.GetValueAdd <string>(); } } else { continue; } changed = true; } if (changed) { logger.Trace($"{csentry.DN}:Updating channel data: {JsonConvert.SerializeObject(channel)}"); await GraphHelperTeams.UpdateChannel(this.betaClient, teamid, channelid, channel, this.token); logger.Info($"{csentry.DN}: Updated channel"); } if (csentry.ObjectType == "privateChannel") { await this.PutMemberChanges(csentry, teamid, channelid); } }