예제 #1
0
        public static async Task CreateOrPatchUserDefinedFunctionAsync(this UserDefinedFunctionDescription description,
                                                                       HttpClient httpClient, string udfText, Guid spaceId, ICollection <Matcher> matchers)
        {
            UserDefinedFunctionWithMatchers userDefinedFunction =
                await FindUserDefinedFunctionAsync(httpClient, description.name, spaceId);

            if (userDefinedFunction != null)
            {
                await UpdateUserDefinedFunction(httpClient,
                                                description.ToDigitalTwins(spaceId, matchers.Select(m => m.Id).ToArray(), userDefinedFunction.Id),
                                                udfText);
            }
            else
            {
                await CreateUserDefinedFunction(httpClient,
                                                description.ToDigitalTwins(spaceId, matchers.Select(m => m.Id).ToArray()),
                                                udfText);
            }
        }
예제 #2
0
        private async Task CreateOrPatchUserDefinedFunction(
            UserDefinedFunctionDescription description,
            string js,
            Guid spaceId,
            IEnumerable <Matcher> matchers)
        {
            var userDefinedFunction = await _digitalTwinsApiConnector.FindUserDefinedFunction(description.name, spaceId);

            if (userDefinedFunction != null)
            {
                await _digitalTwinsApiConnector.UpdateUserDefinedFunction(
                    description.ToUserDefinedFunctionUpdate(userDefinedFunction.Id, spaceId, matchers.Select(m => m.Id)),
                    js);
            }
            else
            {
                await _digitalTwinsApiConnector.CreateUserDefinedFunction(
                    description.ToUserDefinedFunctionCreate(spaceId, matchers.Select(m => m.Id)),
                    js);
            }
        }
예제 #3
0
        private bool GenerateSiteProvisioningFile(List <Brand> brands, string outputDirectory)
        {
            string siteFilename = Path.Combine(outputDirectory, $"{OutputFilePrefix}_Site_Provisioning.yaml");

            if (File.Exists(siteFilename))
            {
                var overwrite = Prompt.GetYesNo("A site provisioning file already exists," +
                                                " would you like to overwrite it and any brand provisioning" +
                                                $" files that already exist? ({siteFilename})", false);
                if (!overwrite)
                {
                    return(false);
                }
            }

            var p = new ProvisioningDescription();

            p.AddEndpoint(new EndpointDescription {
                type = "EventHub", eventTypes = new List <string> {
                    "DeviceMessage"
                }
            });
            var tenantSpace = new SpaceDescription
            {
                name         = "SmartHotel 360 Tenant",
                description  = "This is the root node for the SmartHotel360 IoT Demo",
                friendlyName = "SmartHotel 360 Tenant",
                type         = "Tenant",
                keystoreName = "SmartHotel360 Keystore"
            };
            SpaceDescription desiredTenantSpace = tenantSpace;

            p.AddSpace(tenantSpace);

            if (!string.IsNullOrWhiteSpace(SubTenantName))
            {
                var subtenantSpace = new SpaceDescription
                {
                    name         = SubTenantName,
                    description  = $"This is the root node for the {SubTenantName} sub Tenant",
                    friendlyName = SubTenantName,
                    type         = "Tenant"
                };
                tenantSpace.AddSpace(subtenantSpace);
                desiredTenantSpace = subtenantSpace;
            }
            else
            {
                tenantSpace.AddResource(new ResourceDescription {
                    type = "IoTHub"
                });
            }

            desiredTenantSpace.AddType(new TypeDescription {
                name = "Classic", category = "SensorType"
            });
            desiredTenantSpace.AddType(new TypeDescription {
                name = "HotelBrand", category = "SpaceType"
            });
            desiredTenantSpace.AddType(new TypeDescription {
                name = "Hotel", category = "SpaceType"
            });
            desiredTenantSpace.AddType(new TypeDescription {
                name = "VIPFloor", category = "SpaceSubType"
            });
            desiredTenantSpace.AddType(new TypeDescription {
                name = "QueenRoom", category = "SpaceSubType"
            });
            desiredTenantSpace.AddType(new TypeDescription {
                name = "KingRoom", category = "SpaceSubType"
            });
            desiredTenantSpace.AddType(new TypeDescription {
                name = "SuiteRoom", category = "SpaceSubType"
            });
            desiredTenantSpace.AddType(new TypeDescription {
                name = "VIPSuiteRoom", category = "SpaceSubType"
            });
            desiredTenantSpace.AddType(new TypeDescription {
                name = "ConferenceRoom", category = "SpaceSubType"
            });
            desiredTenantSpace.AddType(new TypeDescription {
                name = "GymRoom", category = "SpaceSubType"
            });
            desiredTenantSpace.AddType(new TypeDescription {
                name = BlobDescription.FloorplanFileBlobSubType, category = "SpaceBlobSubType"
            });

            desiredTenantSpace.AddPropertyKey(new PropertyKeyDescription
            {
                name = PropertyKeyDescription.DeviceIdPrefixName,
                primitiveDataType = PropertyKeyDescription.PrimitiveDataType.String,
                description       = "Prefix used in sending Device Method calls to the IoT Hub."
            });
            desiredTenantSpace.AddPropertyKey(new PropertyKeyDescription
            {
                name = PropertyKeyDescription.DisplayOrder,
                primitiveDataType = PropertyKeyDescription.PrimitiveDataType.UInt,
                description       = "Order to display spaces"
            });
            desiredTenantSpace.AddPropertyKey(new PropertyKeyDescription
            {
                name = PropertyKeyDescription.MinTemperatureAlertThreshold,
                primitiveDataType = PropertyKeyDescription.PrimitiveDataType.Int,
                description       = "Alert if the temperature goes below this value."
            });
            desiredTenantSpace.AddPropertyKey(new PropertyKeyDescription
            {
                name = PropertyKeyDescription.MaxTemperatureAlertThreshold,
                primitiveDataType = PropertyKeyDescription.PrimitiveDataType.Int,
                description       = "Alert if the temperature goes above this value."
            });
            desiredTenantSpace.AddPropertyKey(new PropertyKeyDescription
            {
                name = PropertyKeyDescription.ImagePath,
                primitiveDataType = PropertyKeyDescription.PrimitiveDataType.String,
                description       = "Path of the image to display for the space."
            });
            desiredTenantSpace.AddPropertyKey(new PropertyKeyDescription
            {
                name = PropertyKeyDescription.ImageBlobId,
                primitiveDataType = PropertyKeyDescription.PrimitiveDataType.String,
                description       = "Id of the image blob for the space."
            });
            desiredTenantSpace.AddPropertyKey(new PropertyKeyDescription
            {
                name = PropertyKeyDescription.DetailedImagePath,
                primitiveDataType = PropertyKeyDescription.PrimitiveDataType.String,
                description       = "Path of the detailed image to display for the space."
            });
            desiredTenantSpace.AddPropertyKey(new PropertyKeyDescription
            {
                name = PropertyKeyDescription.DetailedImageBlobId,
                primitiveDataType = PropertyKeyDescription.PrimitiveDataType.String,
                description       = "Id of the detailed image blob for the space."
            });
            desiredTenantSpace.AddPropertyKey(new PropertyKeyDescription
            {
                name = PropertyKeyDescription.Latitude,
                primitiveDataType = PropertyKeyDescription.PrimitiveDataType.String,
                description       = "Geo Position"
            });
            desiredTenantSpace.AddPropertyKey(new PropertyKeyDescription
            {
                name = PropertyKeyDescription.Longitude,
                primitiveDataType = PropertyKeyDescription.PrimitiveDataType.String,
                description       = "Geo Position"
            });

            desiredTenantSpace.AddUser("Head Of Operations");

            var matcherTemperature = new MatcherDescription {
                name = "Matcher Temperature", dataTypeValue = "Temperature"
            };

            desiredTenantSpace.AddMatcher(matcherTemperature);
            var temperatureProcessor = new UserDefinedFunctionDescription
            {
                name         = "Temperature Processor",
                matcherNames = new List <string>(),
                script       = "../UserDefinedFunctions/temperatureThresholdAlert.js"
            };

            temperatureProcessor.matcherNames.Add(matcherTemperature.name);
            desiredTenantSpace.AddUserDefinedFunction(temperatureProcessor);

            desiredTenantSpace.AddRoleAssignment(new RoleAssignmentDescription
            {
                roleId       = RoleAssignment.RoleIds.SpaceAdmin,
                objectName   = temperatureProcessor.name,
                objectIdType = RoleAssignment.ObjectIdTypes.UserDefinedFunctionId
            });

            foreach (Brand brand in brands)
            {
                string brandFilename = GetBrandProvisioningFilename(brand);
                desiredTenantSpace.AddSpaceReference(new SpaceReferenceDescription {
                    filename = brandFilename
                });
            }

            var    yamlSerializer = new Serializer();
            string serializedProvisioningDescription = yamlSerializer.Serialize(p);

            File.WriteAllText(siteFilename, serializedProvisioningDescription);

            Console.WriteLine($"Successfully created site provisioning file: {siteFilename}");

            return(true);
        }