コード例 #1
0
        private (bool?IsNecessary, string content) GetContent(HueGroupDto currentGroup, HueGroupStatePutDto state, bool withoutOn)
        {
            object content = null;

            if (withoutOn)
            {
                content = this._mapper.Map <GroupStateWithoutOnPut>(state);
            }

            else
            {
                content = this._mapper.Map <GroupStateWithOnPut>(state);
            }

            if (content == null)
            {
                this._logger?.LogError($"{nameof(GroupStateHandler)}hat keinen gültigen Status Wert");

                return(false, string.Empty);
            }

            try
            {
                return(true, LowerCaseSerializer.SerializeObjectWithoutNullProperties(content));
            }

            catch (Exception ex)
            {
                this._logger?.LogError(ex, "Während der Serialisierung trat ein Fehler auf");

                return(null, string.Empty);
            }
        }
コード例 #2
0
        public (bool?IsNecessary, string content) GetSwtichContent(HueGroupDto currentGroup, HueSwitchPutDto switchDto)
        {
            var newPutDto = new HueGroupStatePutDto
            {
                Id = switchDto.Id,
                On = !currentGroup.Action.On
            };

            return(this.GetContent(currentGroup, newPutDto, false));
        }
コード例 #3
0
        public (bool?isNecessary, string content) GetPostContent(HueGroupDto currentGroup, HueGroupStatePutDto wantedState)
        {
            if (wantedState.On != currentGroup.Action.On)
            {
                return(this.GetContent(currentGroup, wantedState, false));
            }

            else
            {
                if (currentGroup.Action.On) // Soll laut Api nicht immer mit On auf True schicken wenn dieser bereits True ist
                {
                    return(this.GetContent(currentGroup, wantedState, true));
                }

                else
                {
                    this._logger?.LogDebug($"Aktueller Status von Gruppe {currentGroup.Name} " +
                                           $"hat bereits den gewünschten Status {currentGroup.Action.On}");

                    return(false, string.Empty);
                }
            }
        }