public async Task <IActionResult> GetBrandImage(string spaceId)
        {
            ICollection <DigitalTwinsSpace> spaces = await _topologyClient.GetBrandLevelSpaces();

            DigitalTwinsSpace space     = spaces.FirstOrDefault(s => s.id == spaceId);
            Property          imagePath = space?.properties?.SingleOrDefault(p => string.Equals(p.name, "ImagePath", StringComparison.InvariantCultureIgnoreCase));

            if (!Uri.TryCreate(imagePath?.value, UriKind.Absolute, out Uri uri))
            {
                return(NotFound());
            }
            else
            {
                byte[] imageResult = await _digitalTwinsClient.GetFromDigitalTwinsAsBytes(uri.AbsoluteUri);

                return(File(imageResult, "image/png"));
            }
        }
예제 #2
0
        private string[] GetAncestorSpaceIds(DigitalTwinsSpace childSpace, Dictionary <string, DigitalTwinsSpace> ancestorSpacesById)
        {
            var ancestorSpaceIds = new List <string>();

            DigitalTwinsSpace nextSpace = childSpace;

            while (!string.IsNullOrWhiteSpace(nextSpace.parentSpaceId))
            {
                ancestorSpaceIds.Add(nextSpace.parentSpaceId);
                if (ancestorSpacesById.TryGetValue(nextSpace.parentSpaceId, out DigitalTwinsSpace parentSpace))
                {
                    nextSpace = parentSpace;
                }
                else
                {
                    break;
                }
            }

            return(ancestorSpaceIds.ToArray());
        }
        private string GetFriendlySpaceIdentifier(DigitalTwinsSpace space, Dictionary <string, DigitalTwinsSpace> firstFourLevelsTopology)
        {
            string identifier = string.Empty;

            if (IsTypeNeededForFriendlyIdentifier(space.type))
            {
                identifier = space.friendlyName;
            }

            if (!string.IsNullOrWhiteSpace(space.parentSpaceId) &&
                firstFourLevelsTopology.TryGetValue(space.parentSpaceId, out DigitalTwinsSpace parentSpace))
            {
                string parentIdentifier = GetFriendlySpaceIdentifier(parentSpace, firstFourLevelsTopology);
                if (!string.IsNullOrWhiteSpace(parentIdentifier))
                {
                    identifier = string.IsNullOrWhiteSpace(identifier) ? parentIdentifier : $"{parentIdentifier} -> {identifier}";
                }
            }

            return(identifier);
        }