public static async Task CreateTypeAsync(this Type type, HttpClient httpClient, JsonSerializerSettings jsonSerializerSettings) { Console.WriteLine($"Creating {nameof(Type)}: {JsonConvert.SerializeObject( type, Formatting.Indented, jsonSerializerSettings )}"); var request = HttpMethod.Post.CreateRequest("types", JsonConvert.SerializeObject(type, jsonSerializerSettings)); await httpClient.SendAsync(request); }
private static async Task CreateTypesAsync(HttpClient httpClient, IList <TypeDescription> typeDescriptions, Guid spaceId) { if (spaceId == Guid.Empty) { throw new ArgumentException($"Types must have a {nameof( spaceId )}"); } foreach (TypeDescription typeDescription in typeDescriptions) { Type type = typeDescription.ToDigitalTwins(spaceId); Console.WriteLine($"Creating Type: {JsonConvert.SerializeObject( type, Formatting.Indented, JsonSerializerSettings )}"); var request = HttpMethod.Post.CreateRequest("types", JsonConvert.SerializeObject(type, JsonSerializerSettings)); await httpClient.SendAsync(request); } }
private static async Task CreateTypesAsync(HttpClient httpClient, IList <TypeDescription> typeDescriptions, Guid spaceId) { if (spaceId == Guid.Empty) { throw new ArgumentException($"Types must have a {nameof( spaceId )}"); } var space = await SpaceHelpers.GetSpaceAsync(httpClient, spaceId); IReadOnlyCollection <Type> existingTypes = await space.GetExistingTypesAsync(httpClient); var typesToCreate = typeDescriptions.Where(td => !existingTypes.Any(et => et.Name.Equals(td.name, StringComparison.OrdinalIgnoreCase) && et.Category.Equals(td.category, StringComparison.OrdinalIgnoreCase))) .ToArray(); foreach (TypeDescription typeDescription in typesToCreate) { Type type = typeDescription.ToDigitalTwins(spaceId); await type.CreateTypeAsync(httpClient, JsonSerializerSettings); } }