예제 #1
0
        public void SetComponentSetting(string componentUid, string uid, object value)
        {
            if (componentUid == null)
            {
                throw new ArgumentNullException(nameof(componentUid));
            }
            if (uid == null)
            {
                throw new ArgumentNullException(nameof(uid));
            }

            var oldValueString = "<unset>";
            var newValueString = Convert.ToString(value, CultureInfo.InvariantCulture);

            var component = GetComponent(componentUid);

            if (!component.TryGetSetting(uid, out var oldValue))
            {
                oldValueString = Convert.ToString(oldValue, CultureInfo.InvariantCulture);
                var hasChanged = !string.Equals(oldValueString, newValueString, StringComparison.Ordinal);

                if (!hasChanged)
                {
                    return;
                }
            }

            component.SetSetting(uid, value);

            _logger.LogDebug(
                "Component setting changed: [Component={0}] [Setting UID={1}] [Value={2} -> {3}].",
                component.Uid,
                uid,
                oldValueString,
                newValueString);

            _storageService.Write(component.GetSettings(), ComponentsDirectory, component.Uid, DefaultFileNames.Settings);
            _messageBusWrapper.PublishSettingChangedEvent(component.Uid, uid, oldValue, value);
        }
예제 #2
0
        public void SetComponentSetting(string componentUid, string settingUid, object value)
        {
            if (componentUid == null)
            {
                throw new ArgumentNullException(nameof(componentUid));
            }
            if (settingUid == null)
            {
                throw new ArgumentNullException(nameof(settingUid));
            }

            var component = GetComponent(componentUid);

            component.Settings.TryGetValue(settingUid, out var oldValue);

            var oldValueString = Convert.ToString(oldValue, CultureInfo.InvariantCulture);
            var newValueString = Convert.ToString(value, CultureInfo.InvariantCulture);
            var hasChanged     = !string.Equals(oldValueString, newValueString, StringComparison.Ordinal);

            if (!hasChanged)
            {
                return;
            }

            component.Settings[settingUid] = value;

            _storageService.Write(component.Settings, ComponentsDirectory, component.Uid, DefaultFilenames.Settings);
            _messageBusWrapper.PublishSettingChangedEvent(component.Uid, settingUid, oldValue, value);

            _logger.LogDebug(
                "Component setting '{0}' changed '{1}' ({2} -> {3}).",
                component.Uid,
                settingUid,
                oldValueString,
                newValueString);
        }