// To Translate mapping between scope tags a hashtable stores the id of the export as key with the current id as value public async Task AddIntuneScopeTag(string result) { GraphJson json = JsonConvert.DeserializeObject <GraphJson>(result); if (json.OdataValue.Equals("microsoft.graph.roleScopeTag")) { try { if (this.scopeTags == null) { this.scopeTags = await graphIntune.GetRoleScopeTagsAsync(); } RoleScopeTag scopeTag = JsonConvert.DeserializeObject <RoleScopeTag>(result); // Check if scope tag with same name and id already exists var check = scopeTags.Where(s => s.DisplayName.Equals(scopeTag.DisplayName)); if (check != null && check.Count() == 1 && check.First().Id.Equals(scopeTag.Id)) { if (scopeTag.IsBuiltIn.HasValue && !scopeTag.IsBuiltIn.Value) { // Add original scope tag to migration table scopeTagMigrationTable.Add(scopeTag.Id, scopeTag.Id); signalRMessage.sendMessage($"Scope tag with name '{scopeTag.DisplayName}' id '{scopeTag.Id}' already exists"); } } // Look for scope tag with same name else if (check != null && check.Count() == 1) { // Add changed scope tag id to migration table scopeTagMigrationTable.Add(scopeTag.Id, check.First().Id); signalRMessage.sendMessage($"Warning scope tag with name '{scopeTag.DisplayName}' already exists - mapping existing id '{scopeTag.Id}' -> '{check.First().Id}'!"); } // Recreate scope tag else if (check == null || check.Count() == 0) { string scopeTagId = scopeTag.Id; scopeTag.Id = null; scopeTag.IsBuiltIn = null; RoleScopeTag importedScopeTag = await graphIntune.AddRoleScopeTagAsync(scopeTag); // Add new created scope tag id to migration table scopeTagMigrationTable.Add(scopeTagId, importedScopeTag.Id); signalRMessage.sendMessage($"Created Scope tag '{importedScopeTag.DisplayName}' with id '{importedScopeTag.Id}'"); // Refresh existing scope tags this.scopeTags = await graphIntune.GetRoleScopeTagsAsync(); } else { throw new ArgumentException("Ambiguous scope tag reference", scopeTag.DisplayName); } }catch (Exception e) { signalRMessage.sendMessage($"Error {e.Message}"); } } }