Exemplo n.º 1
0
        public override EnvironmentDescription <double, int> GetEnvironmentDescription()
        {
            SpaceDescription <int> actionDescription = new SpaceDescription <int>(new int[1] {
                0
            }, new int[1] {
                1
            }, null, null);

            double[] averageState = new double[6];
            double[] stddevState  = new double[6];
            averageState[0] = 0;
            stddevState[0]  = 0.8;
            averageState[1] = 0;
            stddevState[1]  = 0.8;
            averageState[2] = 0;
            stddevState[2]  = 5;
            averageState[3] = 0;
            stddevState[3]  = 0.8;
            averageState[4] = 0;
            stddevState[4]  = 0.8;
            averageState[5] = 0;
            stddevState[5]  = 5;
            SpaceDescription <double>     stateDescription  = new SpaceDescription <double>(null, null, averageState, stddevState);
            DimensionDescription <double> rewardDescription = new DimensionDescription <double>(-10, 10);

            return(new EnvironmentDescription <double, int>(stateDescription, actionDescription, rewardDescription, this.discountFactor));
        }
Exemplo n.º 2
0
        public override EnvironmentDescription <double, double> GetEnvironmentDescription()
        {
            double[] averageState = Enumerable.Repeat(0.0, 12).ToArray();
            double[] stdDevState  = new double[12];

            averageState[0] = 10;
            stdDevState[0]  = 3;
            stdDevState[1]  = 1;
            stdDevState[2]  = 0.01;
            stdDevState[3]  = 0.01;
            int i = 0;

            for (i = 0; i < 3; i++)
            {
                stdDevState[i * 2 + 4] = 3; // r
                stdDevState[i * 2 + 5] = 1; // cos(alpha)
            }

            stdDevState[10] = stdDevState[11] = 1;

            double[] minAction = Enumerable.Repeat(0.0, this.Arm.Compartments.Length * 3).ToArray();
            double[] maxAction = Enumerable.Repeat(1.0, this.Arm.Compartments.Length * 3).ToArray();
            SpaceDescription <double>     actionsDescription = new SpaceDescription <double>(minAction, maxAction, null, null);
            SpaceDescription <double>     statesDescription  = new SpaceDescription <double>(null, null, averageState, stdDevState);
            DimensionDescription <double> rewardDescription  = new DimensionDescription <double>(-100, 100);

            return(new EnvironmentDescription <double, double>(statesDescription, actionsDescription, rewardDescription, 0.9));
        }
Exemplo n.º 3
0
        private SpaceDescription CreateRoom(int roomNumber, string brandHotelPrefix, string roomType, bool addDevices)
        {
            var roomSpaceDescription = new SpaceDescription
            {
                name         = $"Room {roomNumber}",
                description  = $"Room {roomNumber}",
                friendlyName = $"Room {roomNumber}",
                type         = "Room",
                subType      = roomType
            };

            if (addDevices)
            {
                var roomDevice = new DeviceDescription
                {
                    name       = "Room",
                    hardwareId = $"{brandHotelPrefix}{roomNumber}"
                };
                roomDevice.AddSensor(new SensorDescription {
                    dataType = "Temperature", type = "Classic"
                });
                roomDevice.AddSensor(new SensorDescription {
                    dataType = "Motion", type = "Classic"
                });
                roomDevice.AddSensor(new SensorDescription {
                    dataType = "Light", type = "Classic"
                });

                roomSpaceDescription.AddDevice(roomDevice);
            }

            return(roomSpaceDescription);
        }
Exemplo n.º 4
0
        public override EnvironmentDescription <int, int> GetEnvironmentDescription()
        {
            SpaceDescription <int>        stateSpaceDescription         = new SpaceDescription <int>(new[] { 0 }, new[] { (this.Height * this.Width) - 1 });
            SpaceDescription <int>        actionSpaceDescription        = new SpaceDescription <int>(new[] { 0 }, new[] { 3 });
            DimensionDescription <double> reinforcementSpaceDescription = new DimensionDescription <double>(-1, 10);

            return(new EnvironmentDescription <int, int>(stateSpaceDescription, actionSpaceDescription, reinforcementSpaceDescription, DiscountFactor));
        }
Exemplo n.º 5
0
        private async Task <Guid> GetExistingSpaceOrCreate(Guid parentId, SpaceDescription description)
        {
            var existingSpace = await _digitalTwinsApiConnector.FindSpace(description.name, parentId);

            return(existingSpace?.Id != null
                ? Guid.Parse(existingSpace.Id)
                : await _digitalTwinsApiConnector.CreateSpace(description.ToSpaceCreate(parentId)));
        }
 public EnvironmentDescription(
     SpaceDescription <TStateType> stateSpaceDescription,
     SpaceDescription <TActionType> actionSpaceDescription,
     DimensionDescription <double> reinforcementSpaceDescription,
     double discountFactor)
 {
     this.ActionSpaceDescription        = actionSpaceDescription;
     this.StateSpaceDescription         = stateSpaceDescription;
     this.ReinforcementSpaceDescription = reinforcementSpaceDescription;
     this.DiscountFactor = discountFactor;
 }
Exemplo n.º 7
0
        public override EnvironmentDescription <double, int> GetEnvironmentDescription()
        {
            double[] minimum           = new double[] { minX, -100, -1, -1, -100 };
            double[] maximum           = new double[] { maxX, 100, 1, 1, 100 };
            double[] average           = new double[] { 0, 0, 0, 0, 0 };
            double[] standardDeviation = new double[] { 2, 3, 0.8, 0.8, 4 };

            return(new EnvironmentDescription <double, int>(
                       new SpaceDescription <double>(minimum, maximum, average, standardDeviation),
                       SpaceDescription <int> .CreateOneDimensionalSpaceDescription(0, 3),
                       new DimensionDescription <double>(-100, 1),
                       this.discountFactor));
        }
Exemplo n.º 8
0
        public override EnvironmentDescription <double, int> GetEnvironmentDescription()
        {
            double[] averageState = new double[2] {
                14, -55
            };
            double[] stddevState = new double[2] {
                19, 55
            };
            SpaceDescription <double>     stateDescription         = new SpaceDescription <double>(null, null, averageState, stddevState);
            SpaceDescription <int>        actionDescription        = new SpaceDescription <int>(new int[] { 0 }, new int[] { 4 }, null, null);
            DimensionDescription <double> reinforcementDescription = new DimensionDescription <double>(-10, 10);

            return(new EnvironmentDescription <double, int>(stateDescription, actionDescription, reinforcementDescription, discountFactor));
        }
        private static IEnumerable <SpaceDescription> FindAllReferenceSpaces(SpaceDescription parentDescription)
        {
            List <SpaceDescription> referenceSpaces = new List <SpaceDescription>();

            if (parentDescription.spaceReferences != null)
            {
                referenceSpaces.Add(parentDescription);
            }
            else if (parentDescription.spaces != null)
            {
                foreach (SpaceDescription childDescription in parentDescription.spaces)
                {
                    referenceSpaces.AddRange(FindAllReferenceSpaces(childDescription));
                }
            }

            return(referenceSpaces);
        }
        private static void LoadReferenceProvisionings(SpaceDescription spaceDescription, string directoryPath)
        {
            var referenceSpaces = new List <SpaceDescription>();

            foreach (SpaceReferenceDescription spaceReferenceDescription in spaceDescription.spaceReferences)
            {
                if (String.IsNullOrEmpty(spaceReferenceDescription.filename))
                {
                    throw new Exception($"SpaceReference filename expected.");
                }

                string filepath = Path.Combine(directoryPath, spaceReferenceDescription.filename);

                var referenceSpace = LoadReferenceProvisioning(filepath);

                referenceSpaces.Add(referenceSpace);
            }

            spaceDescription.spaces = referenceSpaces;
        }
        private static int GetTotalNumberOfChildSpaces(SpaceDescription spaceDescription)
        {
            if (spaceDescription.spaces == null)
            {
                return(0);
            }

            int numberOfChildSpaces = spaceDescription.spaces.Count;

            foreach (SpaceDescription childSpace in spaceDescription.spaces)
            {
                int childSpacesCount = GetTotalNumberOfChildSpaces(childSpace);
                if (childSpacesCount > 0)
                {
                    // Uncomment this line to see how each "level" of spaces stacks up
                    // Console.WriteLine( $"{childSpace.name}: {childSpacesCount} child spaces" );
                }
                numberOfChildSpaces += childSpacesCount;
            }

            return(numberOfChildSpaces);
        }
        public override EnvironmentDescription <double, double> GetEnvironmentDescription()
        {
            double[] standardDeviation = new double[6];
            double[] averageState      = Enumerable.Repeat <double>(0.0, 6).ToArray();

            standardDeviation[0] = 3;
            standardDeviation[1] = 2;
            standardDeviation[2] = 3;
            standardDeviation[3] = 2;
            standardDeviation[4] = 3;
            standardDeviation[5] = 2;

            SpaceDescription <double> stateDescription = new SpaceDescription <double>(null, null, averageState, standardDeviation);

            SpaceDescription <double> actionDescription
                = new SpaceDescription <double>(
                      Enumerable.Repeat <double>(-50, 3).ToArray(),
                      Enumerable.Repeat <double>(50, 3).ToArray());

            DimensionDescription <double> reinforcementDescription = new DimensionDescription <double>(-4, 4);

            return(new EnvironmentDescription <double, double>(stateDescription, actionDescription, reinforcementDescription, 0.9));
        }
Exemplo n.º 13
0
        public override EnvironmentDescription <double, double> GetEnvironmentDescription()
        {
            double[] average = new double[]
            {
                0.1, 0, 0.5, 0.6, 1, 0, 0, 0.1, 0, 0.5,
                0, 0, 0,
                0, 0, 0,
                0, 0, 0,
                0, 0, 0,
                0, 0, 0,
                0, 0, 0,
                0, 0, 0
            };
            double[] standardDeviation = new double[]
            {
                0.1, 1, 0.5, 0.2, 2, 0.7, 0.7, 0.1, 1, 0.5,
                0.7, 0.7, 6,
                0.7, 0.7, 6,
                0.7, 0.7, 6,
                0.7, 0.7, 6,
                0.7, 0.7, 6,
                0.7, 0.7, 6,
                0.7, 0.7, 6,
            };

            SpaceDescription <double> stateSpaceDescription
                = new SpaceDescription <double>(null, null, average, standardDeviation);

            SpaceDescription <double> actionSpaceDescription
                = new SpaceDescription <double>(Enumerable.Repeat(-1.0, 6).ToArray(), Enumerable.Repeat(1.0, 6).ToArray());

            DimensionDescription <double> reinforcementSpaceDescription
                = new DimensionDescription <double>(-1, 1, 0, 1);

            return(new EnvironmentDescription <double, double>(stateSpaceDescription, actionSpaceDescription, reinforcementSpaceDescription, 0.9));
        }
Exemplo n.º 14
0
        private void GenerateBrandProvisioningFile(Brand brand, int brandNumber, List <HotelType> hotelTypes, ref int globalHotelNumber)
        {
            string brandFilename = GetBrandProvisioningFilename(brand);

            var brandSpaceDescription = new SpaceDescription
            {
                name         = brand.Name,
                description  = $"SmartHotel360 {brand.Name}",
                friendlyName = brand.Name,
                type         = "HotelBrand"
            };

            brandSpaceDescription.AddUser($"Hotel Brand {brandNumber} Manager");
            brandSpaceDescription.AddProperty(new PropertyDescription {
                name = PropertyKeyDescription.DisplayOrder, value = brandNumber.ToString()
            });
            brandSpaceDescription.AddProperty(new PropertyDescription
            {
                name  = PropertyKeyDescription.ImagePath,
                value = $"{imageAssetsRootPath}brands/brand{brandNumber}.jpg"
            });

            // Create the hotels
            for (int hotelIndex = 0; hotelIndex < brand.Hotels.Count; hotelIndex++)
            {
                globalHotelNumber++;
                Hotel     hotel                 = brand.Hotels[hotelIndex];
                HotelType hotelType             = hotelTypes.First(t => t.Name == hotel.Type);
                var       hotelSpaceDescription = new SpaceDescription
                {
                    name         = hotel.Name,
                    description  = $"SmartHotel360 {hotel.Name}",
                    friendlyName = hotel.Name,
                    type         = "Hotel"
                };
                hotelSpaceDescription.AddUser($"Hotel {globalHotelNumber} Manager");
                hotelSpaceDescription.AddProperty(new PropertyDescription {
                    name = PropertyKeyDescription.DisplayOrder, value = hotelIndex.ToString()
                });
                hotelSpaceDescription.AddProperty(new PropertyDescription
                {
                    name = PropertyKeyDescription.MinTemperatureAlertThreshold, value = hotelType.MinTempAlertThreshold.ToString()
                });
                hotelSpaceDescription.AddProperty(new PropertyDescription
                {
                    name = PropertyKeyDescription.MaxTemperatureAlertThreshold, value = hotelType.MaxTempAlertThreshold.ToString()
                });
                hotelSpaceDescription.AddProperty(new PropertyDescription
                {
                    name  = PropertyKeyDescription.ImagePath,
                    value = $"{imageAssetsRootPath}hotels/{hotelType.Name.ToLower()}.jpg"
                });

                string brandHotelPrefix = $"{brand.Name}-{hotel.Name}-".Replace(" ", string.Empty);

                int numberRegularFloors = hotelType.TotalNumberFloors - hotelType.NumberVipFloors;

                // Create the floors
                for (int floorIndex = 0; floorIndex < hotelType.TotalNumberFloors; floorIndex++)
                {
                    bool isVipFloor            = floorIndex >= numberRegularFloors;
                    var  floorSpaceDescription = new SpaceDescription
                    {
                        name         = $"Floor {floorIndex + 1:D02}",
                        description  = $"Floor {floorIndex + 1}",
                        friendlyName = $"Floor {floorIndex + 1}",
                        type         = "Floor"
                    };
                    floorSpaceDescription.AddProperty(new PropertyDescription
                    {
                        name  = PropertyKeyDescription.DeviceIdPrefixName,
                        value = brandHotelPrefix
                    });

                    string imagePathSuffix = string.Empty;
                    if (isVipFloor)
                    {
                        imagePathSuffix = "vip";
                        floorSpaceDescription.subType = "VIPFloor";
                    }

                    floorSpaceDescription.AddProperty(new PropertyDescription
                    {
                        name  = PropertyKeyDescription.ImagePath,
                        value = $"{imageAssetsRootPath}floors/{hotelType.Name.ToLower()}{imagePathSuffix}.jpg"
                    });

                    if (!isVipFloor && !string.IsNullOrEmpty(hotel.RegularFloorEmployeeUser))
                    {
                        floorSpaceDescription.AddUser($"Hotel {hotelIndex + 1} {hotel.RegularFloorEmployeeUser}");
                    }

                    int numberOfRooms = isVipFloor ? hotelType.NumberRoomsPerVipFloor : hotelType.NumberRoomsPerRegularFloor;
                    // Create the rooms
                    for (int roomIndex = 0; roomIndex < numberOfRooms; roomIndex++)
                    {
                        string           roomType             = GetRoomType(roomIndex, numberOfRooms, isVipFloor);
                        SpaceDescription roomSpaceDescription = CreateRoom(100 * (floorIndex + 1) + roomIndex + 1, brandHotelPrefix,
                                                                           roomType, hotel.AddDevices);
                        floorSpaceDescription.AddSpace(roomSpaceDescription);
                    }

                    if (floorIndex == 0 && hotelType.IncludeGym)
                    {
                        SpaceDescription roomSpaceDescription = CreateRoom(100 * (floorIndex + 1) + numberOfRooms + 1,
                                                                           brandHotelPrefix, "GymRoom", hotel.AddDevices);
                        floorSpaceDescription.AddSpace(roomSpaceDescription);
                    }

                    if (floorIndex == 1 && hotelType.IncludeConferenceRoom)
                    {
                        SpaceDescription roomSpaceDescription = CreateRoom(100 * (floorIndex + 1) + numberOfRooms + 1,
                                                                           brandHotelPrefix, "ConferenceRoom", hotel.AddDevices);
                        floorSpaceDescription.AddSpace(roomSpaceDescription);
                    }

                    hotelSpaceDescription.AddSpace(floorSpaceDescription);
                }

                brandSpaceDescription.AddSpace(hotelSpaceDescription);
            }

            var yamlSerializer = new SerializerBuilder()
                                 .Build();
            string serializedProvisioningDescription = yamlSerializer.Serialize(brandSpaceDescription);

            File.WriteAllText(brandFilename, serializedProvisioningDescription);

            Console.WriteLine($"Successfully created brand provisioning file: {brandFilename}");
        }
Exemplo n.º 15
0
        private async Task CreateSpaceAsync(HttpClient httpClient, SpaceDescription spaceDescription,
                                            Guid parentId, Guid keystoreId, UserAadObjectIdsDescription userAadObjectIds)
        {
            Space spaceToCreate = spaceDescription.ToDigitalTwins(parentId);
            Space existingSpace = await SpaceHelpers.GetUniqueSpaceAsync(httpClient, spaceToCreate.Name, parentId, JsonSerializerSettings);

            var spaceId = !string.IsNullOrWhiteSpace(existingSpace?.Id)
                                ? Guid.Parse(existingSpace.Id)
                                : await CreateSpaceAsync(httpClient, spaceToCreate);

            Console.WriteLine();

            if (spaceId != Guid.Empty)
            {
                Guid keystoreIdToUseForChildren = keystoreId;
                // Keystore creation must happen first to ensure that devices down the tree can get their SaS tokens from it
                if (!string.IsNullOrWhiteSpace(spaceDescription.keystoreName))
                {
                    Keystore existingKeystore = await KeyStoresHelper.GetUniqueKeystoreAsync(httpClient,
                                                                                             spaceDescription.keystoreName, spaceId, JsonSerializerSettings);

                    Guid createdKeystoreId = !string.IsNullOrWhiteSpace(existingKeystore?.Id)
                                                ? Guid.Parse(existingKeystore.Id)
                                                : await CreateKeystoreAsync(httpClient, spaceDescription.keystoreName, spaceId);

                    if (createdKeystoreId != Guid.Empty)
                    {
                        keystoreIdToUseForChildren = createdKeystoreId;
                    }
                }

                // Resources must be created next to ensure that devices created down the tree will succeed
                if (spaceDescription.resources != null)
                {
                    await CreateResourcesAsync(httpClient, spaceDescription.resources, spaceId);
                }

                // Types must be created next to ensure that devices/sensors created down the tree will succeed
                if (spaceDescription.types != null)
                {
                    await CreateTypesAsync(httpClient, spaceDescription.types, spaceId);
                }

                if (spaceDescription.devices != null)
                {
                    await CreateDevicesAsync(httpClient, spaceDescription.devices, keystoreIdToUseForChildren, spaceId);
                }

                if (spaceDescription.matchers != null)
                {
                    await CreateMatchersAsync(httpClient, spaceDescription.matchers, spaceId);
                }

                if (spaceDescription.userDefinedFunctions != null)
                {
                    await CreateUserDefinedFunctionsAsync(httpClient, spaceDescription.userDefinedFunctions, spaceId);
                }

                if (spaceDescription.roleAssignments != null)
                {
                    await CreateRoleAssignmentsAsync(httpClient, spaceDescription.roleAssignments, spaceId);
                }

                if (spaceDescription.users != null)
                {
                    await CreateUserRoleAssignmentsAsync(httpClient, spaceDescription.users, spaceId, userAadObjectIds);
                }

                if (spaceDescription.propertyKeys != null)
                {
                    await CreatePropertyKeysAsync(httpClient, spaceDescription.propertyKeys, spaceId);
                }

                if (spaceDescription.properties != null)
                {
                    await CreatePropertiesAsync(httpClient, spaceDescription.properties, spaceId);
                }

                if (spaceDescription.spaces != null)
                {
                    await CreateSpacesAsync(httpClient, spaceDescription.spaces, spaceId, keystoreIdToUseForChildren, userAadObjectIds);
                }
            }
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
0
        private void GenerateBrandProvisioningFile(Brand brand, int brandNumber, List <HotelType> hotelTypes,
                                                   string outputDirectory, ref int globalHotelNumber)
        {
            string brandFilename = Path.Combine(outputDirectory, GetBrandProvisioningFilename(brand));

            var brandSpaceDescription = new SpaceDescription
            {
                name         = brand.Name,
                description  = $"SmartHotel360 {brand.Name}",
                friendlyName = brand.Name,
                type         = "HotelBrand"
            };

            brandSpaceDescription.AddUser($"Hotel Brand {brandNumber} Manager");
            brandSpaceDescription.AddProperty(new PropertyDescription {
                name = PropertyKeyDescription.DisplayOrder, value = brandNumber.ToString()
            });

            brandSpaceDescription.AddBlob(new BlobDescription
            {
                name          = $"{brand.Name} Blob",
                type          = BlobDescription.FileBlobType,
                subtype       = BlobDescription.NoneBlobType,
                description   = "Brand image",
                filepath      = $"{ImageFolderRelativePath}/brands/brand{brandNumber}.png",
                contentType   = BlobDescription.PngContentType,
                isPrimaryBlob = true
            });

            // Create the hotels
            for (int hotelIndex = 0; hotelIndex < brand.Hotels.Count; hotelIndex++)
            {
                globalHotelNumber++;
                Hotel     hotel                 = brand.Hotels[hotelIndex];
                HotelType hotelType             = hotelTypes.First(t => t.Name == hotel.Type);
                var       hotelSpaceDescription = new SpaceDescription
                {
                    name         = hotel.Name,
                    description  = $"SmartHotel360 {hotel.Name}",
                    friendlyName = hotel.Name,
                    type         = "Hotel"
                };
                hotelSpaceDescription.AddUser($"Hotel {globalHotelNumber} Manager");

                hotelSpaceDescription.AddProperty(new PropertyDescription
                {
                    name = PropertyKeyDescription.DisplayOrder, value = hotelIndex.ToString()
                });

                hotelSpaceDescription.AddProperty(new PropertyDescription
                {
                    name = PropertyKeyDescription.MinTemperatureAlertThreshold, value = hotelType.MinTempAlertThreshold.ToString()
                });

                hotelSpaceDescription.AddProperty(new PropertyDescription
                {
                    name = PropertyKeyDescription.MaxTemperatureAlertThreshold, value = hotelType.MaxTempAlertThreshold.ToString()
                });

                hotelSpaceDescription.AddProperty(new PropertyDescription
                {
                    name = PropertyKeyDescription.Latitude, value = hotel.Latitude.ToString()
                });

                hotelSpaceDescription.AddProperty(new PropertyDescription
                {
                    name = PropertyKeyDescription.Longitude, value = hotel.Longitude.ToString()
                });

                hotelSpaceDescription.AddBlob(new BlobDescription
                {
                    name          = $"{brand.Name} {hotel.Name} Blob",
                    type          = BlobDescription.FileBlobType,
                    subtype       = BlobDescription.NoneBlobType,
                    description   = "Hotel image",
                    filepath      = $"{ImageFolderRelativePath}/hotels/{hotelType.Name.ToLower()}.jpg",
                    contentType   = BlobDescription.JpegContentType,
                    isPrimaryBlob = true
                });

                string brandHotelPrefix = $"{brand.Name}-{hotel.Name}-".Replace(" ", string.Empty);

                int numberRegularFloors = hotelType.TotalNumberFloors - hotelType.NumberVipFloors;

                // Create the floors
                for (int floorIndex = 0; floorIndex < hotelType.TotalNumberFloors; floorIndex++)
                {
                    bool   isVipFloor            = floorIndex >= numberRegularFloors;
                    string floorName             = $"Floor {floorIndex + 1:D02}";
                    var    floorSpaceDescription = new SpaceDescription
                    {
                        name         = floorName,
                        description  = $"Floor {floorIndex + 1}",
                        friendlyName = $"Floor {floorIndex + 1}",
                        type         = "Floor"
                    };
                    floorSpaceDescription.AddProperty(new PropertyDescription
                    {
                        name  = PropertyKeyDescription.DeviceIdPrefixName,
                        value = brandHotelPrefix
                    });

                    string imagePathSuffix = string.Empty;
                    if (isVipFloor)
                    {
                        imagePathSuffix = "vip";
                        floorSpaceDescription.subType = "VIPFloor";
                    }

                    floorSpaceDescription.AddBlob(new BlobDescription
                    {
                        name          = $"{brand.Name} {hotel.Name} {floorName} Blob",
                        type          = BlobDescription.FileBlobType,
                        subtype       = BlobDescription.NoneBlobType,
                        description   = "Floor image",
                        filepath      = $"{ImageFolderRelativePath}/floors/{hotelType.Name.ToLower()}{imagePathSuffix}.jpg",
                        contentType   = BlobDescription.JpegContentType,
                        isPrimaryBlob = true
                    });

                    floorSpaceDescription.AddBlob(new BlobDescription
                    {
                        name          = $"{brand.Name} {hotel.Name} {floorName} Floorplan Blob",
                        type          = BlobDescription.FileBlobType,
                        subtype       = BlobDescription.FloorplanFileBlobSubType,
                        description   = "Floorplan image",
                        filepath      = $"{ImageFolderRelativePath}/floorplans/{hotelType.Name.ToLower()}{imagePathSuffix}.svg",
                        contentType   = BlobDescription.SvgContentType,
                        isPrimaryBlob = false
                    });

                    if (!isVipFloor && !string.IsNullOrEmpty(hotel.RegularFloorEmployeeUser))
                    {
                        floorSpaceDescription.AddUser($"Hotel {hotelIndex + 1} {hotel.RegularFloorEmployeeUser}");
                    }

                    bool includeGymForThisFloor            = floorIndex == 0 && hotelType.IncludeGym;
                    bool includeConferenceRoomForThisFloor = floorIndex == 1 && hotelType.IncludeConferenceRoom;

                    int numberOfRooms = isVipFloor ? hotelType.NumberRoomsPerVipFloor : hotelType.NumberRoomsPerRegularFloor;
                    if (includeGymForThisFloor)
                    {
                        numberOfRooms--;
                    }
                    if (includeConferenceRoomForThisFloor)
                    {
                        numberOfRooms--;
                    }

                    // Create the rooms
                    for (int roomIndex = 0; roomIndex < numberOfRooms; roomIndex++)
                    {
                        string           roomType             = GetRoomType(roomIndex, numberOfRooms, isVipFloor);
                        SpaceDescription roomSpaceDescription = CreateRoom(100 * (floorIndex + 1) + roomIndex + 1, brandHotelPrefix,
                                                                           roomType, hotel.AddDevices);
                        floorSpaceDescription.AddSpace(roomSpaceDescription);
                    }

                    if (includeGymForThisFloor)
                    {
                        SpaceDescription roomSpaceDescription = CreateRoom(100 * (floorIndex + 1) + numberOfRooms + 1,
                                                                           brandHotelPrefix, "GymRoom", hotel.AddDevices);
                        floorSpaceDescription.AddSpace(roomSpaceDescription);
                    }

                    if (includeConferenceRoomForThisFloor)
                    {
                        SpaceDescription roomSpaceDescription = CreateRoom(100 * (floorIndex + 1) + numberOfRooms + 1,
                                                                           brandHotelPrefix, "ConferenceRoom", hotel.AddDevices);
                        floorSpaceDescription.AddSpace(roomSpaceDescription);
                    }

                    hotelSpaceDescription.AddSpace(floorSpaceDescription);
                }

                brandSpaceDescription.AddSpace(hotelSpaceDescription);
            }

            var yamlSerializer = new SerializerBuilder()
                                 .Build();
            string serializedProvisioningDescription = yamlSerializer.Serialize(brandSpaceDescription);

            File.WriteAllText(brandFilename, serializedProvisioningDescription);

            Console.WriteLine($"Successfully created brand provisioning file: {brandFilename}");
        }