private void Clear(ValueDataType valueType, SignalRule signalRule)
        {
            PropertyInfo[] propertiesInfo = null;

            if (valueType.HasFlag(ValueDataType.Integer))
            {
                propertiesInfo = signalRule.GetType().GetIntegerWhereNotExemptProperties();
                if (propertiesInfo != null)
                {
                    foreach (PropertyInfo propertyInfo in propertiesInfo)
                    {
                        propertyInfo.SetValue(signalRule, null);
                    }
                }
            }

            if (valueType.HasFlag(ValueDataType.String))
            {
                propertiesInfo = signalRule.GetType().GetStringWhereNotExemptProperties();
                if (propertiesInfo != null)
                {
                    foreach (PropertyInfo propertyInfo in propertiesInfo)
                    {
                        propertyInfo.SetValue(signalRule, null);
                    }
                }
            }

            if (valueType.HasFlag(ValueDataType.Datetime))
            {
                propertiesInfo = signalRule.GetType().GetDateTimeWhereNotExemptProperties();
                if (propertiesInfo != null)
                {
                    foreach (PropertyInfo propertyInfo in propertiesInfo)
                    {
                        propertyInfo.SetValue(signalRule, null);
                    }
                }
            }
        }
        public void ValidateCrossFieldDependency(SignalRule signalRule)
        {
            if (signalRule != null)
            {
                PropertyInfo[] propertiesInfo = null;
                switch (signalRule.ValueType)
                {
                case ValueDataType.Integer:
                    propertiesInfo = signalRule.GetType().GetIntegerWhereNotExemptProperties();
                    break;

                case ValueDataType.String:
                    propertiesInfo = signalRule.GetType().GetStringWhereNotExemptProperties();
                    break;

                case ValueDataType.Datetime:
                    propertiesInfo = signalRule.GetType().GetDateTimeWhereNotExemptProperties();
                    break;
                }

                if (propertiesInfo != null)
                {
                    bool isAnySet = false;
                    foreach (PropertyInfo propertyInfo in propertiesInfo)
                    {
                        if (propertyInfo.GetValue(signalRule) != null)
                        {
                            if (propertyInfo.PropertyType.IsArray)
                            {
                                if (propertyInfo.PropertyType.Name == "String[]")
                                {
                                    string[] forLength = propertyInfo.GetValue(signalRule) as string[];
                                    if (forLength.Length != 0)
                                    {
                                        isAnySet = true;
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                isAnySet = true;
                                break;
                            }
                        }
                    }

                    foreach (PropertyInfo property in propertiesInfo)
                    {
                        ElementProperty elementProperty = this.FirstOrDefault(x => x.PropertyName == property.Name);
                        if (elementProperty != null)
                        {
                            elementProperty.HasDataError = false;

                            if (signalRule.ValueType == ValueDataType.Integer)
                            {
                                if (signalRule.MaxValue.HasValue && signalRule.MinValue.HasValue)
                                {
                                    if (signalRule.MaxValue.Value < signalRule.MinValue.Value)
                                    {
                                        elementProperty.HasDataError = true;
                                    }
                                }
                            }
                            else if (signalRule.ValueType == ValueDataType.String)
                            {
                                if (signalRule.MaxLength.HasValue && signalRule.MinLength.HasValue)
                                {
                                    if (signalRule.MaxLength.Value < signalRule.MinLength.Value)
                                    {
                                        elementProperty.HasDataError = true;
                                    }
                                }
                            }
                            else if (signalRule.ValueType == ValueDataType.Datetime)
                            {
                                if (!string.IsNullOrEmpty(signalRule.MaxDate) && !string.IsNullOrEmpty(signalRule.MinDate))
                                {
                                    if (DateTime.TryParse(signalRule.MinDate, out DateTime minDate))
                                    {
                                        if (DateTime.TryParse(signalRule.MaxDate, out DateTime maxDate))
                                        {
                                            if (maxDate < minDate)
                                            {
                                                elementProperty.HasDataError = true;
                                            }
                                        }
                                    }
                                }
                            }

                            elementProperty.IsMandatory = !isAnySet;
                            elementProperty.Validate(nameof(elementProperty.PropertyValue));
                        }
                    }
                }
            }
        }
        private void FillSignalProperties(SignalRule signalRule)
        {
            this.ElementProperties.ToList().ForEach(property => property.PropertyChanged -= this.ElementPropertyChanged);
            this.ElementProperties.Clear();

            if (signalRule != null)
            {
                ElementProperties properties     = new ElementProperties();
                PropertyInfo[]    propertiesInfo = null;

                switch (signalRule.ValueType)
                {
                case ValueDataType.Integer:
                    propertiesInfo = signalRule.GetType().GetIntegerProperties();
                    this.Clear(ValueDataType.Datetime | ValueDataType.String, signalRule);
                    break;

                case ValueDataType.String:
                    propertiesInfo = signalRule.GetType().GetStringProperties();
                    this.Clear(ValueDataType.Integer | ValueDataType.Datetime, signalRule);
                    break;

                case ValueDataType.Datetime:
                    propertiesInfo = signalRule.GetType().GetDateTimeProperties();
                    this.Clear(ValueDataType.Integer | ValueDataType.String, signalRule);
                    break;

                default:
                    propertiesInfo = signalRule.GetType().GetExemptProperties();
                    this.Clear(ValueDataType.Integer | ValueDataType.String | ValueDataType.Datetime, signalRule);
                    break;
                }

                foreach (PropertyInfo propertyInfo in propertiesInfo)
                {
                    ElementProperty elementProperty = null;

                    if (propertyInfo.PropertyType.IsEnum)
                    {
                        elementProperty = this.GetComboBoxProperty(signalRule, propertyInfo);
                    }
                    else if (propertyInfo.PropertyType == typeof(double?))
                    {
                        elementProperty = this.GetDoubleProperty(signalRule, propertyInfo);
                    }
                    else if (propertyInfo.PropertyType == typeof(int?))
                    {
                        elementProperty = this.GetIntegerProperty(signalRule, propertyInfo);
                    }
                    else if (propertyInfo.PropertyType.IsArray)
                    {
                        switch (propertyInfo.PropertyType.Name)
                        {
                        case "String[]":
                            elementProperty = this.GetArrayTextProperty(signalRule, propertyInfo);
                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        elementProperty = this.GetTextProperty(signalRule, propertyInfo);
                    }

                    properties.Add(elementProperty);
                }

                this.ElementProperties = properties;

                this.ElementProperties.ToList().ForEach(property =>
                {
                    if (!property.IsReadOnly)
                    {
                        property.PropertyChanged += this.ElementPropertyChanged;
                    }
                });
            }

            this.PrimaryCommand.RaiseCanExecuteChanged();
        }