Exemple #1
0
        private void SetParameterObjects(SmartBaseElement element, SmartGenericJsonData data, bool update = false)
        {
            if (data.DescriptionRules != null)
            {
                element.DescriptionRules = new List <DescriptionRule>();
                foreach (SmartDescriptionRulesJsonData rule in data.DescriptionRules)
                {
                    element.DescriptionRules.Add(new DescriptionRule(rule));
                }
            }
            else
            {
                element.DescriptionRules = null;
            }

            element.Id           = data.Id;
            element.ReadableHint = data.Description;

            for (var i = 0; i < element.ParametersCount; ++i)
            {
                element.GetParameter(i).Name   = "Parameter " + (i + 1) + " (unused)";
                element.GetParameter(i).IsUsed = false;
            }

            if (data.Parameters == null)
            {
                return;
            }

            for (var i = 0; i < data.Parameters.Count; ++i)
            {
                string key = data.Parameters[i].Type;
                if (data.Parameters[i].Values != null)
                {
                    key = $"{data.Name}_{i}";
                    if (!parameterFactory.IsRegisteredLong(key))
                    {
                        parameterFactory.Register(key, data.Parameters[i].Type == "FlagParameter" ? new FlagParameter()
                        {
                            Items = data.Parameters[i].Values
                        } : new Parameter()
                        {
                            Items = data.Parameters[i].Values
                        });
                    }
                }

                IParameter <long> parameter = parameterFactory.Factory(key);
                element.GetParameter(i).Name = data.Parameters[i].Name;
                if (!update)
                {
                    element.GetParameter(i).Value = data.Parameters[i].DefaultVal;
                }
                element.GetParameter(i).Parameter = parameter;
                element.GetParameter(i).IsUsed    = true;
            }
        }
 public void Fix(SmartBaseElement e)
 {
     for (int i = 0; i < e.ParametersCount; ++i)
     {
         if (!e.GetParameter(i).IsUsed&& e.GetParameter(i).Value != 0)
         {
             e.GetParameter(i).Value = 0;
         }
     }
 }
        public ParametersEditViewModel(IItemFromListProvider itemFromListProvider, SmartBaseElement element, IEnumerable <KeyValuePair <Parameter, string> > parameters)
        {
            _element = element;

            foreach (var parameter in parameters)
            {
                Parameters.Add(new ParameterEditorViewModel(parameter.Key, parameter.Value, itemFromListProvider));
            }

            _items        = new CollectionViewSource();
            _items.Source = Parameters;
            _items.GroupDescriptions.Add(new PropertyGroupDescription("Group"));
        }
Exemple #4
0
        public ParametersEditViewModel(IUnityContainer _container, SmartBaseElement element, IEnumerable <KeyValuePair <Parameter, string> > parameters)
        {
            this._container = _container;
            _element        = element;

            foreach (var parameter in parameters)
            {
                Parameters.Add(new ParameterEditorViewModel(parameter.Key, parameter.Value, _container));
            }

            _items        = new CollectionViewSource();
            _items.Source = Parameters;
            _items.GroupDescriptions.Add(new PropertyGroupDescription("Group"));
        }
Exemple #5
0
        private void SetParameterObjects(SmartBaseElement element, SmartGenericJsonData data)
        {
            element.ReadableHint = data.Description;
            if (data.Parameters == null)
            {
                return;
            }

            for (int i = 0; i < data.Parameters.Count; ++i)
            {
                var parameter = _parameterFactory.Factory(data.Parameters[i].Type, data.Parameters[i].Name, data.Parameters[i].DefaultVal);
                parameter.Description = data.Parameters[i].Description;
                if (data.Parameters[i].Values != null)
                {
                    parameter.Items = data.Parameters[i].Values;
                }
                element.SetParameterObject(i, parameter);
            }
        }
        public InspectionResult?Inspect(SmartBaseElement e, string ofWhat)
        {
            for (int i = 0; i < e.ParametersCount; ++i)
            {
                if (!e.GetParameter(i).IsUsed&& e.GetParameter(i).Value != 0)
                {
                    int    index = i + 1;
                    string nd    = index == 1 ? "st" : (index == 2 ? "nd" : (index == 3 ? "rd" : "th"));
                    return(new InspectionResult()
                    {
                        Severity = DiagnosticSeverity.Info,
                        Message = $" {index}{nd} parameter of {ofWhat} is not used, but has non zero value.",
                        Line = e.LineId
                    });
                }
            }

            return(null);
        }
        public InspectionResult?Inspect(SmartBaseElement e)
        {
            for (int i = 0; i < e.ParametersCount; ++i)
            {
                if (e.GetParameter(i).IsUsed&&
                    e.GetParameter(i).Value != 0 &&
                    e.GetParameter(i).HasItems&&
                    !((e.GetParameter(i).Parameter.Items?.ContainsKey(e.GetParameter(i).Value) ?? false) ||
                      (e.GetParameter(i).Parameter is FlagParameter fp && ContainsAllFlags(fp, e.GetParameter(i).Value))))
                {
                    return(new InspectionResult()
                    {
                        Severity = DiagnosticSeverity.Info,
                        Message = $"Parameter `{e.GetParameter(i).Name}` value out of range ({e.GetParameter(i).Value})",
                        Line = e.LineId
                    });
                }
            }

            return(null);
        }
Exemple #8
0
        private void SetParameterObjects(SmartBaseElement element, ConditionJsonData data)
        {
            element.Id           = data.Id;
            element.ReadableHint = data.Description;

            for (var i = 0; i < element.ParametersCount; ++i)
            {
                element.GetParameter(i).IsUsed = false;
            }

            if (data.Parameters == null)
            {
                return;
            }

            for (var i = 0; i < data.Parameters.Count; ++i)
            {
                string key = data.Parameters[i].Type;
                if (data.Parameters[i].Values != null)
                {
                    key = $"{data.Name}_{i}";
                    if (!parameterFactory.IsRegisteredLong(key))
                    {
                        parameterFactory.Register(key, new Parameter()
                        {
                            Items = data.Parameters[i].Values
                        });
                    }
                }

                IParameter <long> parameter = parameterFactory.Factory(key);

                element.GetParameter(i).Name      = data.Parameters[i].Name;
                element.GetParameter(i).IsUsed    = true;
                element.GetParameter(i).Parameter = parameter;
            }
        }
Exemple #9
0
        public InspectionResult?Inspect(SmartBaseElement e)
        {
            for (int i = 0; i < e.ParametersCount; ++i)
            {
                if (e.GetParameter(i).IsUsed&&
                    e.GetParameter(i).HasItems)
                {
                    if (e.GetParameter(i).Parameter is FlagParameter fp &&
                        ContainsAllFlags(fp, e.GetParameter(i).Value) != 0)
                    {
                        var unknownFlag = ContainsAllFlags(fp, e.GetParameter(i).Value);
                        return(new InspectionResult()
                        {
                            Severity = DiagnosticSeverity.Info,
                            Message = $"Parameter `{e.GetParameter(i).Name}` uses non existing flag {unknownFlag}",
                            Line = e.LineId
                        });
                    }

                    if (e.GetParameter(i).Value != 0 &&
                        e.GetParameter(i).Parameter is not FlagParameter &&
                        !e.GetParameter(i).Parameter.AllowUnknownItems&&
                        !(e.GetParameter(i).Items?.ContainsKey(e.GetParameter(i).Value) ?? false))
                    {
                        return(new InspectionResult()
                        {
                            Severity = DiagnosticSeverity.Info,
                            Message = $"Parameter `{e.GetParameter(i).Name}` value out of range ({e.GetParameter(i).Value})",
                            Line = e.LineId
                        });
                    }
                }
            }

            return(null);
        }
 public ParametersEditViewModel(IItemFromListProvider itemFromListProvider,
     ICurrentCoreVersion currentCoreVersion,
     SmartBaseElement element,
     bool focusFirst,
     IEnumerable<(ParameterValueHolder<long> parameter, string name)>? parameters,
Exemple #11
0
 private void SmartSourceOnOnIdChanged(SmartBaseElement source, int old, int @new)
 {
     PushAction(new SmartIdChangedAction <SmartSource>((SmartSource)source, old, @new, (a, id) => smartFactory.UpdateSource(a, id)));
 }
Exemple #12
0
 private void SmartTargetOnOnIdChanged(SmartBaseElement target, int old, int @new)
 {
     PushAction(new SmartIdChangedAction <SmartTarget>((SmartTarget)target, old, @new, (a, id) => smartFactory.UpdateTarget(a, id)));
 }
Exemple #13
0
 private void SmartConditionOnOnIdChanged(SmartBaseElement condition, int old, int @new)
 {
     PushAction(new SmartIdChangedAction <SmartCondition>((SmartCondition)condition, old, @new, (a, id) => smartFactory.UpdateCondition(a, id)));
 }
 public InspectionResult?Inspect(SmartBaseElement element) => throw new NotImplementedException();
Exemple #15
0
 private void SmartActionOnOnIdChanged(SmartBaseElement action, int old, int @new)
 {
     PushAction(new SmartIdChangedAction <SmartAction>(action as SmartAction, old, @new, (a, id) => smartFactory.UpdateAction(a, id)));
 }
Exemple #16
0
 public ParametersEditViewModel(IItemFromListProvider itemFromListProvider,
                                SmartBaseElement element,
                                bool focusFirst,
                                IEnumerable <(ParameterValueHolder <int> parameter, string name)> parameters,
Exemple #17
0
 private void SmartEventOnOnIdChanged(SmartBaseElement element, int oldId, int newId)
 {
     PushAction(new SmartIdChangedAction <SmartEvent>((SmartEvent)element, oldId, newId, (e, id) => smartFactory.UpdateEvent(e, id)));
 }
Exemple #18
0
 public InspectionResult?Inspect(SmartBaseElement element) => throw new Exception("Repeat validator is not suported for actions, because it doesn't make any sense");