Exemplo n.º 1
0
        /// <summary>
        /// Updates the value of a trigger property in this object's <see cref="Parameters"/>. If the trigger property does not exist, it will be added.
        /// </summary>
        /// <param name="property">The property whose value will be updated.</param>
        /// <param name="value">The value to insert.</param>
        /// <param name="requireValue">Indicates whether null is allowed for the specified property.</param>
        protected void UpdateCustomParameter(TriggerProperty property, object value, bool requireValue = false)
        {
            if (value == null && requireValue && Action != ModifyAction.Edit)
            {
                throw new InvalidOperationException($"Trigger property '{property}' cannot be null for trigger type '{Type}'");
            }

            var name      = $"{property.GetDescription()}_{this.subId}";
            var parameter = new CustomParameter(name, value);

            var index = GetCustomParameterIndex(property);

            if (index == -1)
            {
                Parameters.Add(parameter);
            }
            else
            {
                if (value == null)
                {
                    Parameters.RemoveAt(index);
                }
                else
                {
                    Parameters[index] = parameter;
                }
            }
        }
        private static object TryInvokeTypeParser(TriggerProperty property, object v, TriggerParameters parameters)
        {
            var propertyInfo = parameters.GetTypeCache().Properties.FirstOrDefault(p => p.GetAttribute <PropertyParameterAttribute>()?.Property.Equals(property) == true)?.Property;

            if (propertyInfo == null)
            {
                throw new InvalidOperationException($"Property '{property}' does not exist on triggers of type '{parameters.Type}'.");
            }

            if (ReflectionExtensions.IsPrtgAPIProperty(typeof(TriggerParameters), propertyInfo) && !propertyInfo.PropertyType.IsEnum)
            {
                var method = propertyInfo.PropertyType.GetMethod("Parse", BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static);

                if (method != null)
                {
                    try
                    {
                        var newValue = method.Invoke(null, new[] { v });
                        v = newValue;
                    }
                    catch (Exception)
                    {
                        //Don't care if our value wasn't parsable
                    }
                }
            }

            return(v);
        }
 private void ValidateActionType(TriggerProperty actionType)
 {
     if (!IsNotificationAction(actionType))
     {
         throw new ArgumentException($"'{actionType}' is not a valid notification action type. Please specify one of {string.Join(", ", notificationActionTypes)}.", nameof(actionType));
     }
 }
Exemplo n.º 4
0
 internal TriggerPropertyEntry(string jsonName, TriggerProperty property, PropertyCache typedProperty, FieldCache typedRawField, PropertyCache rawProperty, PropertyCache rawInput)
 {
     JsonName      = jsonName;
     Property      = property;
     TypedProperty = typedProperty;
     TypedRawField = typedRawField;
     RawProperty   = rawProperty;
     RawInput      = rawInput;
 }
Exemplo n.º 5
0
        /// <summary>
        /// Retrieves the value of a trigger property from this object's <see cref="Parameters"/>.
        /// </summary>
        /// <param name="property">The property to retrieve.</param>
        /// <returns>The value of this property. If the property does not exist, this method returns null.</returns>
        protected object GetCustomParameterValue(TriggerProperty property)
        {
            var index = GetCustomParameterIndex(property);

            if (index == -1)
            {
                return(null);
            }

            return(Parameters[index].Value);
        }
Exemplo n.º 6
0
            internal TriggerProperty NewOrGetTriggerProperty(int _coordinate, int _slot, int _refKind, int _refState)
            {
                TriggerProperty _trigger = GetTriggerProperty(_coordinate, _slot, _refKind, _refState);

                if (_trigger == null)
                {
                    _trigger = new TriggerProperty(_coordinate, _slot, _refKind, _refState);
                    TriggerPropertyList.Add(_trigger);
                }
                return(_trigger);
            }
Exemplo n.º 7
0
        /// <summary>
        /// Retrieves the enum value of a trigger property from this object's <see cref="Parameters"/> that has been stored using its XML representation.
        /// </summary>
        /// <typeparam name="T">The type of enum stored in the property</typeparam>
        /// <param name="property">The property to retrieve.</param>
        /// <returns>The value of this property. If the property does not exist, this method returns null.</returns>
        protected object GetCustomParameterEnumXml <T>(TriggerProperty property)
        {
            var value = GetCustomParameterValue(property);

            if (value == null)
            {
                return(null);
            }

            return(value.ToString().XmlToEnum <T>());
        }
        /// <summary>
        /// Updates a <see cref="NotificationAction"/> in this object's <see cref="Parameters"/>. If the notification action is null, an empty notification action is inserted.
        /// </summary>
        /// <param name="actionType">The type of notification action to insert.</param>
        /// <param name="value">The notification action to insert. If this value is null, an empty notification action is inserted.</param>
        protected void SetNotificationAction(TriggerProperty actionType, NotificationAction value)
        {
            ValidateActionType(actionType);

            if (value == null)
            {
                value = EmptyNotificationAction();
            }

            UpdateCustomParameter(actionType, value);
        }
Exemplo n.º 9
0
Arquivo: VAlarm.cs Projeto: ywscr/PDI
        /// <summary>
        /// The method can be called to clear all current property values from the alarm.  The version is left
        /// unchanged.
        /// </summary>
        public override void ClearProperties()
        {
            action   = null;
            trigger  = null;
            repeat   = null;
            duration = null;
            summary  = null;
            desc     = null;

            attendees   = null;
            attachments = null;
            customProps = null;
        }
Exemplo n.º 10
0
        /// <summary>
        /// Updates a <see cref="NotificationAction"/> in this object's <see cref="Parameters"/>. If the notification action is null, an empty notification action is inserted.
        /// </summary>
        /// <param name="actionType">The type of notification action to insert.</param>
        /// <param name="value">The notification action to insert. If this value is null, an empty notification action is inserted.</param>
        protected void SetNotificationAction(TriggerProperty actionType, NotificationAction value)
        {
            if (actionType != TriggerProperty.OnNotificationAction && actionType != TriggerProperty.OffNotificationAction && actionType != TriggerProperty.EscalationNotificationAction)
            {
                throw new ArgumentException($"{actionType} is not a valid notification action type");
            }

            if (value == null)
            {
                value = EmptyNotificationAction();
            }

            UpdateCustomParameter(actionType, value);
        }
Exemplo n.º 11
0
        private TriggerParameter CreateTriggerParameter(TriggerProperty property, object value)
        {
            var parameter = new TriggerParameter(property, value);

            parameterParser.UpdateParameterValue(parameter, new Lazy <PrtgObject>(() =>
            {
                if (Trigger != null)
                {
                    return(client.GetObject(Trigger.ObjectId));
                }

                return(client.GetObject(ObjectId));
            }));

            return(parameter);
        }
Exemplo n.º 12
0
Arquivo: VAlarm.cs Projeto: ywscr/PDI
        /// <summary>
        /// This is overridden to allow copying of the additional properties
        /// </summary>
        /// <param name="p">The PDI object from which the settings are to be copied</param>
        protected override void Clone(PDIObject p)
        {
            VAlarm o = (VAlarm)p;

            this.ClearProperties();

            action   = (ActionProperty)o.Action.Clone();
            trigger  = (TriggerProperty)o.Trigger.Clone();
            repeat   = (RepeatProperty)o.Repeat.Clone();
            duration = (DurationProperty)o.Duration.Clone();
            summary  = (SummaryProperty)o.Summary.Clone();
            desc     = (DescriptionProperty)o.Description.Clone();

            this.Attendees.CloneRange(o.Attendees);
            this.Attachments.CloneRange(o.Attachments);
            this.CustomProperties.CloneRange(o.CustomProperties);
        }
        /// <summary>
        /// Retrieves a <see cref="NotificationAction"/> from this object's <see cref="Parameters"/>. If the specified action type does not exist, an empty notification action is returned.
        /// </summary>
        /// <param name="actionType">The type of notification action to retrieve.</param>
        /// <returns>If the notification action exists, the notification action. Otherwise, an empty notification action.</returns>
        protected NotificationAction GetNotificationAction(TriggerProperty actionType)
        {
            ValidateActionType(actionType);

            var value = GetCustomParameterValue(actionType);

            if (value == null)
            {
                if (Action == ModifyAction.Edit)
                {
                    return(null);
                }
                return(EmptyNotificationAction());
            }

            return((NotificationAction)value);
        }
Exemplo n.º 14
0
        public static void Write(this TriggerProperty property, bool isLastProperty, PropertiesStyle style, CSideWriter writer)
        {
            writer.Write("{0}=", property.Name);
            writer.Indent(writer.Column);
            property.Value.Variables.Write(writer);

            writer.WriteLine("BEGIN");
            writer.Indent();
            property.Value.CodeLines.Write(writer);
            writer.Unindent();
            writer.WriteLine("END;");

            writer.Unindent();

            if (!isLastProperty || style == PropertiesStyle.Object)
            {
                writer.InnerWriter.WriteLine();
            }
        }
Exemplo n.º 15
0
        internal static Type GetPropertyType(TriggerProperty e)
        {
            //Channel could be convertable to a TriggerChannel, or could be the name of a channel to retrieve
            //(in which case we need to TryParse TriggerChannel manually)
            if (e == TriggerProperty.Channel)
            {
                return(typeof(object));
            }

            var type = triggerProperties
                       .First(p => (TriggerProperty)p.GetAttribute <PropertyParameterAttribute>().Property == e).Property
                       .PropertyType;

            if (type == typeof(NotificationAction))
            {
                type = typeof(NameOrObject <NotificationAction>);
            }

            return(type);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Retrieves a <see cref="NotificationAction"/> from this object's <see cref="Parameters"/>. If the specified action type does not exist, an empty notification action is returned.
        /// </summary>
        /// <param name="actionType">The type of notification action to retrieve.</param>
        /// <returns>If the notification action exists, the notification action. Otherwise, an empty notification action.</returns>
        protected NotificationAction GetNotificationAction(TriggerProperty actionType)
        {
            if (actionType != TriggerProperty.OnNotificationAction && actionType != TriggerProperty.OffNotificationAction && actionType != TriggerProperty.EscalationNotificationAction)
            {
                throw new ArgumentException($"{actionType} is not a valid notification action type");
            }

            var value = GetCustomParameterValue(actionType);

            if (value == null)
            {
                if (Action == ModifyAction.Edit)
                {
                    return(null);
                }
                return(EmptyNotificationAction());
            }

            return((NotificationAction)value);
        }
Exemplo n.º 17
0
        private string GetEnglishValue(TriggerProperty property, Type type, string value)
        {
            switch (property)
            {
            case TriggerProperty.State:
            case TriggerProperty.UnitSize:
            case TriggerProperty.UnitTime:
            case TriggerProperty.Period:
            case TriggerProperty.Condition:
                return(ToXmlEnum(type, value));

            case TriggerProperty.OnNotificationAction:
            case TriggerProperty.OffNotificationAction:
            case TriggerProperty.EscalationNotificationAction:
                return(ToAction(value));

            case TriggerProperty.Channel:
                return(ToChannel(value));

            default:
                throw new NotImplementedException($"Don't know how to handle property '{property}'.");
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// Retrieves the enum value of a trigger property from this object's <see cref="Parameters"/> that has been stored as an integer.
        /// </summary>
        /// <typeparam name="T">The type of enum to retrieve.</typeparam>
        /// <param name="property">The trigger property whose value should be retrieved.</param>
        /// <returns>If the trigger property has a value, a value of type T. Otherwise, a null value of type T?</returns>
        protected object GetCustomParameterEnumInt <T>(TriggerProperty property) where T : struct
        {
            var value = GetCustomParameterValue(property);

            return(value == null ? (T?)null : (T)value);
        }
 internal static bool IsNotificationAction(TriggerProperty property) => notificationActionTypes.Contains(property);
Exemplo n.º 20
0
        private int GetCustomParameterIndex(TriggerProperty property)
        {
            var index = Parameters.FindIndex(a => a.Name.StartsWith(property.GetDescription()));

            return(index);
        }
Exemplo n.º 21
0
            public void CloneSlotTriggerProperty(int _srcSlotIndex, int _dstSlotIndex, int _srcCoordinateIndex, int _dstCoordinateIndex)
            {
                RemoveSlotTriggerProperty(_dstCoordinateIndex, _dstSlotIndex);
                List <TriggerProperty> _triggers = TriggerPropertyList.Where(x => x.Coordinate == _srcCoordinateIndex && x.Slot == _srcSlotIndex).ToList();

                if (_triggers?.Count > 0)
                {
                    foreach (TriggerProperty _trigger in _triggers)
                    {
                        TriggerProperty _copy = _trigger.JsonClone() as TriggerProperty;
                        _copy.Coordinate = _dstCoordinateIndex;
                        _copy.Slot       = _dstSlotIndex;

                        if (_srcCoordinateIndex != _dstCoordinateIndex && _copy.RefKind >= 9)
                        {
                            string _guid = TriggerGroupList.Where(x => x.Coordinate == _srcCoordinateIndex && x.Kind == _copy.RefKind).FirstOrDefault()?.GUID;
                            if (_guid.IsNullOrEmpty())
                            {
                                _logger.LogMessage($"Something seriously f****d up, don't save your card");
                                continue;
                            }

                            TriggerGroup _dstGroup = TriggerGroupList.Where(x => x.Coordinate == _dstCoordinateIndex && x.GUID == _guid).FirstOrDefault();
                            if (_dstGroup == null)
                            {
                                TriggerGroup _clone = GetTriggerGroup(_srcCoordinateIndex, _trigger.RefKind).JsonClone() as TriggerGroup;
                                _clone.Coordinate = _dstCoordinateIndex;

                                if (TriggerGroupList.Any(x => x.Coordinate == _dstCoordinateIndex && x.Kind == _copy.RefKind))
                                {
                                    int _kind = GetNextGroupID(_dstCoordinateIndex);
                                    _clone.Kind   = _kind;
                                    _copy.RefKind = _kind;
                                    TriggerPropertyList.RemoveAll(x => x.Coordinate == _dstCoordinateIndex && x.RefKind == _kind);
                                }

                                TriggerGroupList.Add(_clone);
                            }
                            else
                            {
                                int _kind = _dstGroup.Kind;
                                _copy.RefKind = _kind;
                                int          _state    = _trigger.RefState;
                                TriggerGroup _srcGroup = GetTriggerGroup(_srcCoordinateIndex, _kind);
                                if (!_dstGroup.States.ContainsKey(_state))
                                {
                                    _dstGroup.States.Add(_state, _srcGroup.States[_state]);
                                    TriggerPropertyList.RemoveAll(x => x.Coordinate == _dstCoordinateIndex && x.RefKind == _kind && x.RefState == _state);
                                    HashSet <int> _slots = new HashSet <int>(TriggerPropertyList.Where(x => x.Coordinate == _dstCoordinateIndex && x.RefKind == _kind && x.Slot != _dstSlotIndex).Select(x => x.Slot));
                                    if (_slots.Count > 0)
                                    {
                                        List <TriggerProperty> _tempTriggerProperty = new List <TriggerProperty>();
                                        foreach (int _slot in _slots)
                                        {
                                            _tempTriggerProperty.Add(new TriggerProperty(_dstCoordinateIndex, _slot, _kind, _state));
                                        }
                                        TriggerPropertyList.AddRange(_tempTriggerProperty);
                                    }
                                }
                            }
                        }

                        TriggerPropertyList.Add(_copy);
                    }
                }
            }
Exemplo n.º 22
0
            internal void ToggleByRefKind(int _refKind)
            {
                if (_duringLoadChange)
                {
                    return;
                }
                if (JetPack.CharaMaker.Loaded && !_cfgCharaMakerPreview.Value)
                {
                    return;
                }
                if (JetPack.CharaStudio.Loaded && !TriggerEnabled)
                {
                    return;
                }

                Dictionary <int, TriggerProperty> _effectingPropertList = new Dictionary <int, TriggerProperty>();

                Dictionary <int, int> _clothesStates = _ListClothesStates();

                HashSet <int> _filtered = new HashSet <int>(_cachedCoordinatePropertyList.Where(x => x.RefKind == _refKind).Select(x => x.Slot));

                if (ChaControl.notBot && (_refKind == 0 || _refKind == 1))
                {
                    _filtered = new HashSet <int>(_cachedCoordinatePropertyList.Where(x => (x.RefKind == 0 || x.RefKind == 1)).Select(x => x.Slot));
                }
                if (ChaControl.notShorts && (_refKind == 2 || _refKind == 3))
                {
                    _filtered = new HashSet <int>(_cachedCoordinatePropertyList.Where(x => (x.RefKind == 2 || x.RefKind == 3)).Select(x => x.Slot));
                }
                if (_refKind == 7 || _refKind == 8)
                {
                    _filtered = new HashSet <int>(_cachedCoordinatePropertyList.Where(x => (x.RefKind == 7 || x.RefKind == 8)).Select(x => x.Slot));
                }

                foreach (int _slot in _filtered)
                {
                    TriggerProperty        _effectingPropert = null;
                    List <TriggerProperty> _slotPropertyList = _cachedCoordinatePropertyList.Where(x => x.Slot == _slot).OrderByDescending(x => x.Priority).ThenBy(x => x.RefKind).ThenBy(x => x.RefState).ToList();
                    foreach (TriggerProperty x in _slotPropertyList)
                    {
                        DebugMsg(LogLevel.Info, $"[ToggleByRefKind][Slot: {x.Slot}][Priority: {x.Priority}][RefKind: {x.RefKind}][RefState: {x.RefState}][Visible: {x.Visible}]");

                        if (MathfEx.RangeEqualOn(0, x.RefKind, 8))
                        {
                            if (!_clothesStates.ContainsKey(x.RefKind))
                            {
                                continue;
                            }
                            if (_shoesType == 0 && x.RefKind == 8 && ChaControl.GetClothesStateKind(7) != null)
                            {
                                continue;
                            }
                            if (_shoesType == 1 && x.RefKind == 7 && ChaControl.GetClothesStateKind(8) != null)
                            {
                                continue;
                            }

                            if (_clothesStates[x.RefKind] == x.RefState)
                            {
                                _effectingPropert = x;
                                break;
                            }
                        }
                        else if (x.RefKind >= 9)
                        {
                            TriggerGroup _group = _cachedCoordinateGroupList.Where(y => y.Kind == x.RefKind).FirstOrDefault();
                            if (_group != null && _group.State == x.RefState)
                            {
                                _effectingPropert = x;
                                break;
                            }
                        }
                    }

                    if (_effectingPropert != null)
                    {
                        _effectingPropertList[_slot] = _effectingPropert;
                    }
                }

                foreach (TriggerProperty _trigger in _effectingPropertList.Values)
                {
                    ChaControl.SetAccessoryState(_trigger.Slot, _trigger.Visible);
                }
            }
Exemplo n.º 23
0
 public PropertyParameterAttribute(TriggerProperty property)
 {
     Property = property;
 }
Exemplo n.º 24
0
            private void DrawMakerWindow(int _windowID)
            {
#if KKS
                GUI.backgroundColor = Color.grey;
#endif
                Event _windowEvent = Event.current;
                if (EventType.MouseDown == _windowEvent.type || EventType.MouseUp == _windowEvent.type || EventType.MouseDrag == _windowEvent.type || EventType.MouseMove == _windowEvent.type)
                {
                    _hasFocus = true;
                }

                GUI.Box(new Rect(0, 0, _windowSize.x, _windowSize.y), _windowBGtex);
                GUI.Box(new Rect(0, 0, _windowSize.x, 30), $"AccStateSync - Slot{_slotIndex + 1:00}", new GUIStyle(GUI.skin.label)
                {
                    alignment = TextAnchor.MiddleCenter
                });

                if (GUI.Button(new Rect(_windowSize.x - 27, 4, 23, 23), new GUIContent("X", "Close this window")))
                {
                    CloseWindow();
                }

                if (GUI.Button(new Rect(_windowSize.x - 100, 4, 50, 23), new GUIContent("ON", $"Turn on/off the preview of the settings"), (_sidebarTogglePreview.Value ? _buttonActive : GUI.skin.button)))
                {
                    _sidebarTogglePreview.Value = !_sidebarTogglePreview.Value;
                }

                if (GUI.Button(new Rect(_windowSize.x - 50, 4, 23, 23), new GUIContent("0", "Config window will not block mouse drag from outside (experemental)"), (_passThrough ? _buttonActive : new GUIStyle(GUI.skin.button))))
                {
                    _passThrough = !_passThrough;
                    _logger.LogMessage($"Pass through mode: {(_passThrough ? "ON" : "OFF")}");
                }

                if (GUI.Button(new Rect(4, 4, 23, 23), new GUIContent("<", "Reset window position")))
                {
                    ChangeRes();
                }

                if (GUI.Button(new Rect(27, 4, 23, 23), new GUIContent("T", "Use current window position when reset")))
                {
                    if (_cfgMakerWinResScale.Value)
                    {
                        _windowPos.x = _windowRect.x * _cfgScaleFactor;
                        _windowPos.y = _windowRect.y * _cfgScaleFactor;
                    }
                    else
                    {
                        _windowPos.x = _windowRect.x / _resScaleFactor.x * _cfgScaleFactor;
                        _windowPos.y = _windowRect.y / _resScaleFactor.y * _cfgScaleFactor;
                    }
                    _cfgMakerWinX.Value = _windowPos.x;
                    _cfgMakerWinY.Value = _windowPos.y;
                }

                if (GUI.Button(new Rect(50, 4, 23, 23), new GUIContent("-", "")))
                {
                    int _index = _scaleFactorList.IndexOf(_cfgMakerWinScale.Value);
                    if (_index > 0)
                    {
                        _cfgMakerWinScale.Value = _scaleFactorList.ElementAt(_index - 1);
                    }
                }

                if (GUI.Button(new Rect(73, 4, 23, 23), new GUIContent("+", "")))
                {
                    int _index = _scaleFactorList.IndexOf(_cfgMakerWinScale.Value);
                    if (_index < (_scaleFactorList.Count - 1))
                    {
                        _cfgMakerWinScale.Value = _scaleFactorList.ElementAt(_index + 1);
                    }
                }

                GUILayout.BeginVertical();
                {
                    GUILayout.Space(10);
                    GUILayout.BeginHorizontal();
                    {
                        GUILayout.BeginVertical(GUI.skin.box, GUILayout.Width(300));
                        {
                            _kindScrollPos = GUILayout.BeginScrollView(_kindScrollPos);
                            {
                                for (int i = 0; i <= 8; i++)
                                {
                                    Dictionary <byte, string> _keys = _chaCtrl.GetClothesStateKind(i);
                                    if (_keys != null)
                                    {
                                        List <TriggerProperty> _triggersRefSlot = _pluginCtrl._cachedSlotPropertyList.Where(x => x.RefKind == i).ToList();
                                        GUILayout.BeginVertical(GUI.skin.box);
                                        {
                                            bool _bind = _triggersRefSlot.Count > 0;
                                            GUILayout.BeginHorizontal(GUI.skin.box, GUILayout.ExpandWidth(false));
                                            {
                                                if (_bind)
                                                {
                                                    if (GUILayout.Button(new GUIContent("bind", _toggleUnBindAcc), _buttonActive, _buttonElem))
                                                    {
                                                        _pluginCtrl.TriggerPropertyList.RemoveAll(x => x.Coordinate == _currentCoordinateIndex && x.Slot == _slotIndex && x.RefKind == i);
                                                        RefreshCache();
                                                    }
                                                }
                                                else
                                                {
                                                    if (GUILayout.Button(new GUIContent("bind", _toggleBindAcc), _buttonElem))
                                                    {
                                                        for (int j = 0; j <= 3; j++)
                                                        {
                                                            _pluginCtrl.TriggerPropertyList.Add(new TriggerProperty(_currentCoordinateIndex, _slotIndex, i, j, j < 3, 0));
                                                        }
                                                        RefreshCache();
                                                    }
                                                }
                                                GUILayout.Label(_clothesNames[i], (_bind ? GUI.skin.label : _labelDisabled));
                                                GUILayout.FlexibleSpace();
                                            }
                                            GUILayout.EndHorizontal();

                                            if (_bind)
                                            {
                                                for (int j = 0; j <= 3; j++)
                                                {
                                                    if (_keys.ContainsKey((byte)j))
                                                    {
                                                        TriggerProperty _triggerState = _triggersRefSlot.Where(x => x.RefState == j).FirstOrDefault();
                                                        GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false));
                                                        GUILayout.Label(_statesNames[j], GUILayout.ExpandWidth(false));
                                                        GUILayout.FlexibleSpace();

                                                        if (_triggerState.Visible)
                                                        {
                                                            GUILayout.Button("show", _buttonActive, _buttonElem);
                                                            if (GUILayout.Button("hide", _buttonElem))
                                                            {
                                                                _triggerState.Visible = false;
                                                                RefreshCache();
                                                            }
                                                        }
                                                        else
                                                        {
                                                            if (GUILayout.Button("show", _buttonElem))
                                                            {
                                                                _triggerState.Visible = true;
                                                                RefreshCache();
                                                            }
                                                            GUILayout.Button("hide", _buttonActive, _buttonElem);
                                                        }

                                                        if (GUILayout.Button(new GUIContent("-", _priorityTooltipDown), _priorityElem))
                                                        {
                                                            _triggerState.Priority = Math.Max(_triggerState.Priority - 1, 0);
                                                            RefreshCache();
                                                        }
                                                        GUILayout.Label(_triggerState.Priority.ToString(), _labelAlignCenter, _priorityElem);
                                                        if (GUILayout.Button(new GUIContent("+", _priorityTooltipUp), _priorityElem))
                                                        {
                                                            _triggerState.Priority = Math.Min(_triggerState.Priority + 1, 99);
                                                            RefreshCache();
                                                        }
                                                        GUILayout.EndHorizontal();
                                                    }
                                                }
                                            }
                                            GUI.enabled = true;

                                            GUILayout.EndHorizontal();
                                        }
                                    }
                                }

                                foreach (TriggerGroup _group in _pluginCtrl._cachedCoordinateGroupList.ToList())
                                {
                                    List <TriggerProperty> _triggersRefSlot = _pluginCtrl._cachedSlotPropertyList.Where(x => x.RefKind == _group.Kind).ToList();
                                    GUILayout.BeginVertical(GUI.skin.box);
                                    {
                                        bool _bind = _triggersRefSlot.Count > 0;
                                        GUILayout.BeginHorizontal(GUI.skin.box, GUILayout.ExpandWidth(false));
                                        {
                                            if (_bind)
                                            {
                                                if (GUILayout.Button(new GUIContent("bind", _toggleUnBindAcc), _buttonActive, _buttonElem))
                                                {
                                                    _pluginCtrl.TriggerPropertyList.RemoveAll(x => x.Coordinate == _currentCoordinateIndex && x.Slot == _slotIndex && x.RefKind == _group.Kind);
                                                    RefreshCache();
                                                }
                                            }
                                            else
                                            {
                                                if (GUILayout.Button(new GUIContent("bind", _toggleBindAcc), _buttonElem))
                                                {
                                                    foreach (int _state in _group.States.Keys)
                                                    {
                                                        _pluginCtrl.NewOrGetTriggerProperty(_currentCoordinateIndex, _slotIndex, _group.Kind, _state);
                                                    }
                                                    _pluginCtrl.GetTriggerProperty(_currentCoordinateIndex, _slotIndex, _group.Kind, 1).Visible = false;
                                                    RefreshCache();
                                                }
                                            }
                                            GUILayout.Label(_group.Label, (_bind ? GUI.skin.label : _labelDisabled));
                                            GUILayout.FlexibleSpace();

                                            if (!_bind)
                                            {
                                                GUI.enabled = false;
                                            }
                                            if (GUILayout.Button(new GUIContent("+", $"Add a new state to virtual group: {_group.Label}"), _priorityElem))
                                            {
                                                int           _state = _group.AddNewState();
                                                HashSet <int> _slots = new HashSet <int>(_pluginCtrl.TriggerPropertyList.Where(x => x.Coordinate == _currentCoordinateIndex && x.RefKind == _group.Kind).Select(x => x.Slot));
                                                foreach (int _slot in _slots)
                                                {
                                                    _pluginCtrl.NewOrGetTriggerProperty(_currentCoordinateIndex, _slot, _group.Kind, _state);
                                                }
                                                RefreshCache();
                                            }
                                            GUI.enabled = true;
                                        }
                                        GUILayout.EndHorizontal();

                                        Dictionary <int, string> _states = _group.States.OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value);

                                        if (_bind)
                                        {
                                            foreach (KeyValuePair <int, string> _state in _states)
                                            {
                                                TriggerProperty _trigger = _triggersRefSlot.Where(x => x.RefState == _state.Key).FirstOrDefault();
                                                if (_trigger == null)
                                                {
                                                    continue;
                                                }

                                                GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false));
                                                GUILayout.Label(_state.Value, GUILayout.ExpandWidth(false));
                                                GUILayout.FlexibleSpace();

                                                if (_trigger.Visible)
                                                {
                                                    GUILayout.Button("show", _buttonActive, _buttonElem);
                                                    if (GUILayout.Button("hide", _buttonElem))
                                                    {
                                                        _trigger.Visible = false;
                                                        RefreshCache();
                                                    }
                                                }
                                                else
                                                {
                                                    if (GUILayout.Button("show", _buttonElem))
                                                    {
                                                        _trigger.Visible = true;
                                                        RefreshCache();
                                                    }
                                                    GUILayout.Button("hide", _buttonActive, _buttonElem);
                                                }

                                                if (GUILayout.Button(new GUIContent("-", _priorityTooltipDown), _priorityElem))
                                                {
                                                    _trigger.Priority = Math.Max(_trigger.Priority - 1, 0);
                                                    RefreshCache();
                                                }
                                                GUILayout.Label(_trigger.Priority.ToString(), _labelAlignCenter, _priorityElem);
                                                if (GUILayout.Button(new GUIContent("+", _priorityTooltipUp), _priorityElem))
                                                {
                                                    _trigger.Priority = Math.Min(_trigger.Priority + 1, 99);
                                                    RefreshCache();
                                                }
                                                GUILayout.EndHorizontal();
                                            }
                                        }
                                        GUILayout.EndHorizontal();
                                    }
                                }

                                if (GUILayout.Button(new GUIContent("+", "Add a new virtual group")))
                                {
                                    _pluginCtrl.CreateTriggerGroup();
                                    RefreshCache();
                                }
                            }
                            GUILayout.EndScrollView();
                        }
                        GUILayout.EndVertical();

                        GUILayout.BeginVertical(GUI.skin.box, GUILayout.Width(225));
                        {
                            GUILayout.BeginHorizontal(GUI.skin.box);
                            {
                                GUILayout.FlexibleSpace();
                                if (GUILayout.Button(new GUIContent("preview", "Switch to group preview panel"), (_rightPane == "preview" ? _buttonActive : GUI.skin.button), GUILayout.Width(70)))
                                {
                                    _rightPane = "preview";
                                }
                                if (GUILayout.Button(new GUIContent("edit", "Switch to group setting edit panel"), (_rightPane == "edit" ? _buttonActive : GUI.skin.button), GUILayout.Width(70)))
                                {
                                    _rightPane = "edit";
                                }
                                GUILayout.FlexibleSpace();
                            }
                            GUILayout.EndHorizontal();

                            if (_rightPane == "edit")
                            {
                                DrawEditBlock();
                            }
                            else
                            {
                                DrawPreviewBlock();
                            }
                        }
                        GUILayout.EndVertical();
                    }
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal(GUI.skin.box);
                    GUILayout.Label(GUI.tooltip);
                    GUILayout.EndHorizontal();
                }
                GUILayout.EndVertical();
                GUI.DragWindow();
            }
Exemplo n.º 25
0
 set => SetValue(TriggerProperty, value);
Exemplo n.º 26
0
        /// <summary>
        ///     TODO The crete json trigger configuration template.
        /// </summary>
        /// <param name="triggerObject">
        ///     TODO The bubbling event.
        /// </param>
        /// <returns>
        ///     The <see cref="string" />.
        /// </returns>
        public static string CreteJsonTriggerConfigurationTemplate(ITriggerAssembly triggerObject)
        {
            var eventCorrelationTemplate = new Event(
                "{Event component ID to execute if Correlation = true}",
                "{Configuration ID to execute if Correlation = true}",
                "Event Name Sample",
                "Event Description Sample");

            try
            {
                var triggerConfiguration = new TriggerConfiguration();
                triggerConfiguration.Trigger = new Trigger(
                    triggerObject.Id,
                    Guid.NewGuid().ToString(),
                    triggerObject.Name,
                    triggerObject.Description);
                triggerConfiguration.Trigger.TriggerProperties = new List <TriggerProperty>();
                foreach (var Property in triggerObject.Properties)
                {
                    if (Property.Value.Name != "DataContext")
                    {
                        var triggerProperty = new TriggerProperty(Property.Value.Name, "Value to set");
                        triggerConfiguration.Trigger.TriggerProperties.Add(triggerProperty);
                    }
                }

                triggerConfiguration.Events = new List <Event>();

                // 1*
                var eventTriggerTemplate = new Event(
                    "{Event component ID  Sample to execute}",
                    "{Configuration ID  Sample to execute}",
                    "Event Name Sample",
                    "Event Description Sample");
                eventTriggerTemplate.Channels = new List <Channel>();
                var points = new List <Point>();
                points.Add(new Point("Point ID Sample", "Point Name Sample", "Point Description Sample"));
                eventTriggerTemplate.Channels.Add(
                    new Channel("Channel ID Sample", "Channel Name Sample", "Channel Description Sample", points));

                eventCorrelationTemplate.Channels = new List <Channel>();
                eventCorrelationTemplate.Channels.Add(
                    new Channel("Channel ID Sample", "Channel Name Sample", "Channel Description Sample", points));

                triggerConfiguration.Events.Add(eventTriggerTemplate);

                var events = new List <Event>();
                events.Add(eventCorrelationTemplate);
                eventTriggerTemplate.Correlation = new Correlation("Correlation Name Sample", "C# script", events);

                var serializedMessage = JsonConvert.SerializeObject(
                    triggerConfiguration,
                    Formatting.Indented,
                    new JsonSerializerSettings {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                });

                // string serializedMessage = JsonConvert.SerializeObject(triggerConfiguration);
                return(serializedMessage);

                // return "<![CDATA[" + serializedMessage + "]]>";
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }