public async Task CreateExtensions() { var schemaExtension = new SchemaExtension { Id = "GroupExtensionProperties", Description = "Dotnetsoft Graph Extension Properties", TargetTypes = new List <String>() { "Group" }, Properties = new List <ExtensionSchemaProperty>() { new ExtensionSchemaProperty { Name = "DeptId", Type = "String" }, new ExtensionSchemaProperty { Name = "ParentDeptId", Type = "String" } } }; SchemaExtension schema = await graphClient.SchemaExtensions.Request().AddAsync(schemaExtension); }
private void VisitSchemaExtension(SchemaExtension node) { EnterNode(node); Visit(node.Directives); Visit(node.Operations); ExitNode(node); }
public void FromString() { /* Given */ /* When */ SchemaExtension original = "extend schema { query: Query }"; /* Then */ Assert.Equal("Query", original.Operations?.Single().NamedType.Name); }
public void FromBytes() { /* Given */ /* When */ SchemaExtension original = Encoding.UTF8.GetBytes("extend schema { query: Query }") .AsReadOnlySpan(); /* Then */ Assert.Equal("Query", original.Operations?.Single().NamedType.Name); }
public async Task <SchemaExtension> SetSchemaExtensionStatus(SchemaExtensionTypes types, JsonHelpers.SchemaExtensionStatusTypes status) { var schemaExtension = new SchemaExtension { Id = GetSchemaExtensionId(types), Status = status.ToString() }; var result = await graphClient.SchemaExtensions[schemaExtension.Id].Request().UpdateAsync(schemaExtension); return(result); }
/// <summary> /// Update entity in schemaExtensions /// <param name="body"></param> /// <param name="requestConfiguration">Configuration for the request such as headers, query parameters, and middleware options.</param> /// </summary> public RequestInformation CreatePatchRequestInformation(SchemaExtension body, Action <SchemaExtensionItemRequestBuilderPatchRequestConfiguration> requestConfiguration = default) { _ = body ?? throw new ArgumentNullException(nameof(body)); var requestInfo = new RequestInformation { HttpMethod = Method.PATCH, UrlTemplate = UrlTemplate, PathParameters = PathParameters, }; requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); if (requestConfiguration != null) { var requestConfig = new SchemaExtensionItemRequestBuilderPatchRequestConfiguration(); requestConfiguration.Invoke(requestConfig); requestInfo.AddRequestOptions(requestConfig.Options); requestInfo.AddHeaders(requestConfig.Headers); } return(requestInfo); }
public async Task <string> Post([FromBody] ExtensionModel extension) { try { _logger.LogInfo("ExtensionController-Post: [Started] creation of user attribute in Azure AD B2C"); if (extension == null) { _logger.LogError("ExtensionController-Post: Input cannot be null"); return(string.Empty); } #region Validation if (extension.TargetObjects == null) { _logger.LogError("ExtensionController-Post: Target Object for creation of custom attribute cannot be empty"); return(string.Empty); } if (string.IsNullOrEmpty(extension.Name) && string.IsNullOrEmpty(extension.DataType) && !extension.TargetObjects.Any()) { _logger.LogError("ExtensionController-Post: Input [Name | Data Type | Target Obejct] for creation of custom attribute cannot be empty"); return(string.Empty); } #endregion var client = GraphClientUtility.GetGraphServiceClient(); if (client == null) { _logger.LogError("ExtensionController-Post: Unable create graph proxy to access Azure AD B2C"); return(string.Empty); } var taskSchemaName = CheckIfExtensionExist(CareStreamConst.Schema_Extension_Id); var schemaName = string.Empty; if (taskSchemaName != null) { schemaName = taskSchemaName.Result; } if (string.IsNullOrEmpty(schemaName)) { var schemaExtension = new SchemaExtension { Id = CareStreamConst.Schema_Extension_Id, Description = extension.Description, TargetTypes = extension.TargetObjects, Properties = new List <ExtensionSchemaProperty>() { new ExtensionSchemaProperty { Name = extension.Name, Type = extension.DataType } } }; await client.SchemaExtensions.Request().AddAsync(schemaExtension); } else { var schemaExtension = new SchemaExtension { TargetTypes = extension.TargetObjects, Properties = new List <ExtensionSchemaProperty>() { new ExtensionSchemaProperty { Name = extension.Name, Type = extension.DataType } } }; await client.SchemaExtensions[schemaName].Request().UpdateAsync(schemaExtension); } _logger.LogInfo("ExtensionController-Post: [Completed] creation of user attribute in Azure AD B2C"); return(""); } catch (Exception ex) { _logger.LogError("ExtensionController-Post: Exception occured...."); _logger.LogError(ex); throw ex; } }
public async Async.Task SchemaExtensionTest() { // Create a schema extension on a contact. // TODO: a tool that creates an object based on a schemaExtension definition. SchemaExtension extensionDefinition = new SchemaExtension() { Description = "This extension correlates a group with a foreign database.", Id = $"crmForeignKey", // Microsoft Graph will prepend 8 chars Properties = new List <ExtensionSchemaProperty>() { new ExtensionSchemaProperty() { Name = "fid", Type = "Integer" } }, TargetTypes = new List <string>() { "Group" } }; // Create the schema extension. This results in a call to Microsoft Graph. SchemaExtension schemaExtension = await graphClient.SchemaExtensions.Request().AddAsync(extensionDefinition); Assert.NotNull(schemaExtension); Assert.Equal(schemaExtension.Status, "InDevelopment"); Assert.Contains(extensionDefinition.Id, schemaExtension.Id); Assert.NotNull(schemaExtension.Owner); // List all of the schema extensions available to this application. IGraphServiceSchemaExtensionsCollectionPage schemaExtensions = await graphClient.SchemaExtensions.Request().GetAsync(); Assert.True(schemaExtensions.Count > 0); Assert.NotNull(schemaExtensions[0].Properties); Assert.True(schemaExtensions[0].Description.Length > 0); Assert.NotNull(schemaExtensions[0].TargetTypes); Assert.NotNull(schemaExtensions[0].Id); // Get a specific schema extension. SchemaExtension extensionFromGet = await graphClient.SchemaExtensions[schemaExtension.Id].Request().GetAsync(); Assert.NotNull(extensionFromGet); // Add header so we get back a representation of the updated schema extension. List <HeaderOption> headers = new List <HeaderOption>(); HeaderOption preferHeader = new HeaderOption("Prefer", "return=representation"); headers.Add(preferHeader); // Update a specific schema extension. extensionFromGet.Description = "This extension will be deleted"; // Potential bug: state transition from deprecated to available is not working. // Potential bug here as the service is not returning the SchemaExtension on update. Must delete test until this is fixed. 5/30/2017 // SchemaExtension extensionFromUpdate = await graphClient.SchemaExtensions[extensionFromGet.Id].Request(headers).UpdateAsync(extensionFromGet); await graphClient.SchemaExtensions[extensionFromGet.Id].Request(headers).UpdateAsync(extensionFromGet); // Enable or re-write test when we learn expected behavior. //Assert.Equal(extensionFromGet.Status, extensionFromUpdate.Status, "Expected: the patch object status property matches the returned status property; Actual: they don't match."); // Create a group with the schema extension defined earlier. IDictionary <string, object> extensionInstance = new Dictionary <string, object>(); extensionInstance.Add(schemaExtension.Id, new MyDBExtensionClass(123123)); Group group = new Group() { DisplayName = $"Test group - {Guid.NewGuid().ToString()}", Description = "This group was created with a schema extension", MailEnabled = false, MailNickname = "nickname", // silly requirement since this isn't mail enabled. SecurityEnabled = false, GroupTypes = new List <string>() { "Unified" }, AdditionalData = extensionInstance }; await Async.Task.Delay(15000); // It takes some time for the schema extension def to be available for the creation of a group. group = await graphClient.Groups.Request().AddAsync(group); // Delete a specific schema extension. await graphClient.SchemaExtensions[extensionFromGet.Id].Request().DeleteAsync(); try { var deletedSchemaExtension = await graphClient.SchemaExtensions[extensionFromGet.Id].Request().GetAsync(); Assert.False(true, "Expected: ServiceException since the schema extension ws deleted; Actual: the GET on the supposedly deleted schema extension returned successfully."); } catch (ServiceException e) { Assert.Equal(e.StatusCode, System.Net.HttpStatusCode.NotFound); } // Delete the group. try { await graphClient.Groups[group.Id].Request().DeleteAsync(); } catch (ServiceException e) { Assert.False(true, ($"Error: {e.Error.ToString()}")); } }
public static SchemaExtension WithDescription(this SchemaExtension definition, in StringValue?description)
public async Task UpsertUserAttributes(ExtensionModel extension) { try { _logger.LogInfo("UserAttributeService-UpsertUserAttributes: [Started] creation of user attribute in Azure AD B2C"); if (extension == null) { _logger.LogError("UserAttributeService-UpsertUserAttributes: Input cannot be null"); return; } #region Validation if (extension.TargetObjects == null) { _logger.LogError("UserAttributeService-UpsertUserAttributes: Target Object for creation of custom attribute cannot be empty"); return; } if (string.IsNullOrEmpty(extension.Name) && string.IsNullOrEmpty(extension.DataType) && !extension.TargetObjects.Any()) { _logger.LogError("UserAttributeService-UpsertUserAttributes: Input [Name | Data Type | Target Obejct] for creation of custom attribute cannot be empty"); return; } #endregion var client = GraphClientUtility.GetGraphServiceClient(); if (client == null) { _logger.LogError("UserAttributeService-UpsertUserAttributes: Unable create graph proxy to access Azure AD B2C"); return; } var taskSchemaName = await CheckIfExtensionExist(GraphClientUtility.ExtensionName); var schemaName = string.Empty; if (taskSchemaName != null) { schemaName = ""; } if (string.IsNullOrEmpty(schemaName)) { //var schemaExtension = new SchemaExtension //{ // Id = GraphClientUtility.ExtensionName, // Description = extension.Description, // TargetTypes = extension.TargetObjects, // Properties = new List<ExtensionSchemaProperty>() // { // new ExtensionSchemaProperty // { // Name= extension.Name, // Type = extension.DataType // } // } //}; var schemaExtension = new SchemaExtension { Id = "prasadtest3vikas", Description = "Prasad Learn training courses extensions", Status = "InDevelopment", TargetTypes = new List <String>() { "User" }, Properties = new List <ExtensionSchemaProperty>() { new ExtensionSchemaProperty { Name = "courseId", Type = "Integer" }, new ExtensionSchemaProperty { Name = "courseName", Type = "String" }, new ExtensionSchemaProperty { Name = "courseType", Type = "String" } } }; try { var response = await client.SchemaExtensions .Request() .AddAsync(schemaExtension); var result = response; } catch (Exception ex) { Console.Write(ex); } } else { var schemaExtension = new SchemaExtension { TargetTypes = extension.TargetObjects, Properties = new List <ExtensionSchemaProperty>() { new ExtensionSchemaProperty { Name = extension.Name, Type = extension.DataType } } }; await client.SchemaExtensions[schemaName].Request().UpdateAsync(schemaExtension); } _logger.LogInfo("UserAttributeService-UpsertUserAttributes: [Completed] creation of user attribute in Azure AD B2C"); } catch (Exception ex) { _logger.LogError("UserAttributeService-UpsertUserAttributes: Exception occured...."); _logger.LogError(ex); throw ex; } }
public async Async.Task CreateSchemaExtension() { // Create a schema extension on a contact. SchemaExtension extensionPayload = new SchemaExtension() { Description = "This extension correlates a group with a foreign database.", Id = $"crmForeignKey", // Microsoft Graph will prepend 8 chars Properties = new List <ExtensionSchemaProperty>() { new ExtensionSchemaProperty() { Name = "fid", Type = "Integer" } }, TargetTypes = new List <string>() { "Group" } }; // Create the schema extension. This results in a call to Microsoft Graph. SchemaExtension schemaExtension = await graphClient.SchemaExtensions.Request().AddAsync(extensionPayload); Assert.IsNotNull(schemaExtension, "Expected: schemaExtension is not null; Actual: it returned null"); Assert.AreEqual(schemaExtension.Status, "InDevelopment", $"Expected: a new schem extension has a status as InDevelopment; Actual: {schemaExtension.Status}"); StringAssert.Contains(schemaExtension.Id, extensionPayload.Id, "Expected: the payload identifier is contained in the schema extension returned by the service; Actual: it is not returned"); Assert.IsNotNull(schemaExtension.Owner, "Expected: the owner value is set by the service; Actual: it wasn't set by the service."); // List all of the schema extensions available to this application. IGraphServiceSchemaExtensionsCollectionPage schemaExtensions = await graphClient.SchemaExtensions.Request().GetAsync(); Assert.IsTrue(schemaExtensions.Count > 0, "Expected: at least one schema extension; Actual: 0"); Assert.IsNotNull(schemaExtensions[0].Properties, "Expected: the extension properties are set; Actual: extension properties are not set."); Assert.IsTrue(schemaExtensions[0].Description.Length > 0, "Expected: the description has at least one character; Actual: the description was not set"); Assert.IsNotNull(schemaExtensions[0].TargetTypes, "Expected: the extension targets are set; Actual: extension targets are not set."); Assert.IsNotNull(schemaExtensions[0].Id, "Expected: the Id property is set; Actual: Id property is not set."); // Get a specific schema extension. SchemaExtension extensionFromGet = await graphClient.SchemaExtensions[schemaExtension.Id].Request().GetAsync(); Assert.IsNotNull(extensionFromGet, "Expected: returned a schema extension object; Actual: an object wasn't returned."); // Add header so we get back a representation of the updated schema extension. List <HeaderOption> headers = new List <HeaderOption>(); HeaderOption preferHeader = new HeaderOption("Prefer", "return=representation"); headers.Add(preferHeader); // Update a specific schema extension. extensionFromGet.Description = "This extension will be deleted"; // Potential bug: state transition from deprecated to available is not working. // Potential bug here as the service is not returning the SchemaExtension on update. Must delete test until this is fixed. 5/30/2017 // SchemaExtension extensionFromUpdate = await graphClient.SchemaExtensions[extensionFromGet.Id].Request(headers).UpdateAsync(extensionFromGet); await graphClient.SchemaExtensions[extensionFromGet.Id].Request(headers).UpdateAsync(extensionFromGet); // Enable or re-write test when we learn expected behavior. //Assert.AreEqual(extensionFromGet.Status, extensionFromUpdate.Status, "Expected: the patch object status property matches the returned status property; Actual: they don't match."); // Delete a specific scheam extension. await graphClient.SchemaExtensions[extensionFromGet.Id].Request().DeleteAsync(); try { var deletedSchemaExtension = await graphClient.SchemaExtensions[extensionFromGet.Id].Request().GetAsync(); Assert.Fail("Expected: ServiceException since the schema extension ws deleted; Actual: the GET on the supposedly deleted schema extension returned successfully."); } catch (ServiceException e) { Assert.AreEqual(e.StatusCode, System.Net.HttpStatusCode.NotFound, $"Expected: {System.Net.HttpStatusCode.NotFound}; Actual: {e.StatusCode}"); } }
protected virtual void ExitSchemaExtension(TContext context, SchemaExtension schemaExtension) { }