Пример #1
0
        private async Task CreatePropertyKeysAsync(HttpClient httpClient, IList <PropertyKeyDescription> propertyKeys, Guid spaceId)
        {
            if (spaceId == Guid.Empty)
            {
                throw new ArgumentException($"PropertyKey must have a {nameof( spaceId )}");
            }

            var space = await SpaceHelpers.GetSpaceAsync(httpClient, spaceId);

            IReadOnlyCollection <PropertyKey> existingPropertyKeys = await space.GetExistingPropertyKeysAsync(httpClient);

            var propertyKeysToCreate =
                propertyKeys.Where(pkd =>
                                   !existingPropertyKeys.Any(epk => epk.Name.Equals(pkd.name, StringComparison.OrdinalIgnoreCase)))
                .ToArray();

            foreach (PropertyKeyDescription propertyKeyDescription in propertyKeysToCreate)
            {
                PropertyKey propertyKey = propertyKeyDescription.ToDigitalTwins(spaceId);
                await propertyKey.CreatePropertyKeyAsync(spaceId, httpClient, JsonSerializerSettings);
            }
        }