Example #1
0
        public string Save( )
        {
            StringBuilder [] stringBuilders =
                new StringBuilder[Enum.GetValues(typeof(ConfigurationCategory)).
                                  OfType <ConfigurationCategory> ( ).
                                  Max(type => ( int )type) + 1];

            foreach (ConfigurationCategory type in Enum.GetValues(typeof(ConfigurationCategory)))
            {
                stringBuilders [( int )type] = new StringBuilder( );
            }

            foreach (PropertyInfo property in typeof(Configurations).GetProperties( ))
            {
                ConfigurationItemAttribute attribute =
                    ( ConfigurationItemAttribute )property.GetCustomAttribute(typeof(ConfigurationItemAttribute));
                int           index           = ( int )attribute.ConfigurationCategory;
                StringBuilder propertyBuilder = stringBuilders [index];
                propertyBuilder.AppendLine(attribute.ToString( ));
                propertyBuilder.AppendLine($"{property . Name} = {property . GetValue ( this )}");
                propertyBuilder.AppendLine( );
            }

            StringBuilder builder = new StringBuilder( );

            for (int i = 0; i < stringBuilders.Length; i++)
            {
                builder.AppendLine($"##{( ConfigurationCategory ) i}");
                builder.AppendLine( );
                builder.AppendLine(stringBuilders [i].ToString( ));
                builder.AppendLine( );
            }

            return(builder.ToString( ));
        }
Example #2
0
        /// <summary>
        /// Applies the caption configuration resources.
        /// </summary>
        /// <param name="configurationItemAttribute">The configuration item attribute.</param>
        /// <param name="connectorType">Type of the connector.</param>
        private static void ApplyCaptionConfigResources(ConfigurationItemAttribute configurationItemAttribute, Type connectorType)
        {
            if (captionsCache == null)
            {
                captionsCache = new Dictionary <string, string>();
            }

            if (captionsCache.ContainsKey(configurationItemAttribute.Key))
            {
                configurationItemAttribute.Caption = captionsCache[configurationItemAttribute.Key];
                return;
            }

            IList <Assembly> scannedAssembliesCache = new List <Assembly>();

            // firstly search in current assembly
            var currentAsemblyResourceResult = GetConfigResourceByName(configurationItemAttribute.Key, typeof(ConnectorViewModel).Assembly);

            if (currentAsemblyResourceResult != null)
            {
                captionsCache[configurationItemAttribute.Key] = currentAsemblyResourceResult;
                configurationItemAttribute.Caption            = currentAsemblyResourceResult;
                return;
            }

            scannedAssembliesCache.Add(typeof(ConnectorViewModel).Assembly);

            // search in current connector assembly
            var currentConnectorAssembly = connectorType.Assembly;

            if (!scannedAssembliesCache.Contains(currentConnectorAssembly))
            {
                var connectorsAssemblyResourceResult = GetConfigResourceByName(configurationItemAttribute.Key, currentConnectorAssembly);
                if (connectorsAssemblyResourceResult != null)
                {
                    configurationItemAttribute.Caption            = connectorsAssemblyResourceResult;
                    captionsCache[configurationItemAttribute.Key] = connectorsAssemblyResourceResult;
                    return;
                }
            }

            // search parent assemblies
            var parentTypes = connectorType.GetParentTypes();

            foreach (var parentType in parentTypes)
            {
                var parentTypeAssembly = parentType.Assembly;
                if (!scannedAssembliesCache.Contains(parentTypeAssembly))
                {
                    var parentTypeAsemblyResourceResult = GetConfigResourceByName(configurationItemAttribute.Key, parentTypeAssembly);
                    if (parentTypeAsemblyResourceResult != null)
                    {
                        configurationItemAttribute.Caption            = parentTypeAsemblyResourceResult;
                        captionsCache[configurationItemAttribute.Key] = parentTypeAsemblyResourceResult;
                        return;
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        /// Creates a new control and returns it.
        /// </summary>
        /// <param name="configItem">The configuration item of the connector.</param>
        /// <param name="configItemAttribute">The configuration item attribute.</param>
        /// <returns>
        /// Returns the <see cref="FrameworkElement" /> for the <see cref="configItem" />.
        /// </returns>
        public FrameworkElement GetControl(IConfigurationItem configItem, ConfigurationItemAttribute configItemAttribute)
        {
            var control = this.GetControlInternal(configItem, configItemAttribute);

            control.Margin = new Thickness(control.Margin.Left, control.Margin.Top, control.Margin.Right, control.Margin.Bottom + this.RequiredBottomMargin);
            if (this.ValueBindingDependencyProperty != null)
            {
                this.InitilizeValueBinding(control, configItem, configItemAttribute);
            }

            return(control);
        }
Example #4
0
        public static Configurations GenerateNew( )
        {
            Configurations configuration = new Configurations( );

            foreach (PropertyInfo property in typeof(Configurations).GetProperties( ))
            {
                ConfigurationItemAttribute attribute =
                    ( ConfigurationItemAttribute )property.GetCustomAttribute(typeof(ConfigurationItemAttribute));
                property.SetValue(configuration, attribute.DefultValue);
            }

            return(configuration);
        }
        //[DataRow(typeof(bool?), null)]
        public void ShouldSuccess(Type type, object value)
        {
            var expectedConverted = "null";

            if (value != null)
            {
                expectedConverted = value.ToJson();
            }

            var e = new ConfigurationItemAttribute(
                0, string.Empty, string.Empty,
                type, value, string.Empty)
                    .ToEntity();

            Assert.AreEqual(expectedConverted, e.Value);
        }
Example #6
0
        /// <summary>
        /// Initilizes the value binding.
        /// </summary>
        /// <param name="control">The control.</param>
        /// <param name="configItem">The configuration item.</param>
        /// <param name="configItemAttribute">The configuration item attribute.</param>
        /// <returns>
        /// The binding instance assigned to the control.
        /// </returns>
        public virtual Binding InitilizeValueBinding(FrameworkElement control, IConfigurationItem configItem, ConfigurationItemAttribute configItemAttribute)
        {
            var valueBinding = new Binding();

            valueBinding.Source = configItem;
            valueBinding.Path   = new PropertyPath(nameof(ConfigurationItemViewModel.Value));
            valueBinding.Mode   = BindingMode.TwoWay;
            valueBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            if (!configItemAttribute.Optional)
            {
                var notEmptyValidationRule = new NotEmptyValidationRule();
                valueBinding.ValidationRules.Add(notEmptyValidationRule);
            }

            this.SetValueBinding(control, this.ValueBindingDependencyProperty, valueBinding);
            return(valueBinding);
        }
Example #7
0
 /// <summary>
 /// Creates a new control and returns it.
 /// </summary>
 /// <param name="configItem">The configuration item.</param>
 /// <param name="configItemAttribute">The configuration item attribute.</param>
 /// <returns>Returns the <see cref="Control" /> for the <see cref="configItem" />.</returns>
 public abstract FrameworkElement GetControlInternal(IConfigurationItem configItem, ConfigurationItemAttribute configItemAttribute);
Example #8
0
 /// <summary>
 /// Applies the configuration resources.
 /// </summary>
 /// <param name="configurationItemAttribute">The configuration item attribute.</param>
 /// <param name="connectorType">Type of the connector.</param>
 public static void ApplyConfigResourses(ConfigurationItemAttribute configurationItemAttribute, Type connectorType)
 {
     ApplyCaptionConfigResources(configurationItemAttribute, connectorType);
 }
Example #9
0
        /// <summary>
        /// Creates a new control and returns it.
        /// </summary>
        /// <param name="configItem">The configuration item.</param>
        /// <param name="configItemAttribute">The configuration item attribute.</param>
        /// <returns>
        /// Returns the <see cref="FrameworkElement" /> for the <see cref="configItem" />.
        /// </returns>
        public override FrameworkElement GetControlInternal(IConfigurationItem configItem, ConfigurationItemAttribute configItemAttribute)
        {
            var stackPanel = new StackPanel();

            stackPanel.Orientation       = Orientation.Horizontal;
            stackPanel.Margin            = new Thickness(0, 0, 0, 0);
            stackPanel.VerticalAlignment = VerticalAlignment.Center;

            var checkBox = new CheckBox();

            checkBox.DataContext = configItem;
            var style = Application.Current.FindResource("MaterialDesignSwitchToggleButton") as Style;

            checkBox.Style  = style;
            checkBox.Margin = new Thickness(2, 8, 0, 8);
            stackPanel.Children.Add(checkBox);

            var label = new Label();

            label.Content           = configItemAttribute.Caption;
            label.Margin            = new Thickness(8, 8, 0, 8);
            label.Padding           = new Thickness(0, 0, 0, 0);
            label.VerticalAlignment = VerticalAlignment.Center;
            stackPanel.Children.Add(label);

            return(stackPanel);
        }
        /// <summary>
        /// Creates a new control and returns it.
        /// </summary>
        /// <param name="configItem">The configuration item.</param>
        /// <param name="configItemAttribute">The configuration item attribute.</param>
        /// <returns>
        /// Returns the <see cref="Control" /> for the <see cref="configItem" />.
        /// </returns>
        public override FrameworkElement GetControlInternal(IConfigurationItem configItem, ConfigurationItemAttribute configItemAttribute)
        {
            var card = new Card();

            card.Margin = new Thickness(4, 0, 4, 0);
            card.SetResourceReference(Control.BackgroundProperty, "MaterialDesignBackground");
            var expander = new Expander();

            card.Content = expander;
            expander.HorizontalAlignment = HorizontalAlignment.Stretch;
            var itemsStackPanel = new StackPanel();

            itemsStackPanel.Orientation = Orientation.Horizontal;
            expander.Content            = itemsStackPanel;
            var itemsStackPanelColumn1 = new StackPanel();

            itemsStackPanelColumn1.Margin = new Thickness(0, 0, 50, 0);
            var itemsStackPanelColumn2 = new StackPanel();

            itemsStackPanel.Children.Add(itemsStackPanelColumn1);
            itemsStackPanel.Children.Add(itemsStackPanelColumn2);

            var notificationState = new NotificationsState();

            this.ApplyConfigurationItemToNotificationState(notificationState, configItem, configItemAttribute, expander);
            var configItemPropertyChanged = (INotifyPropertyChanged)configItem;

            configItemPropertyChanged.PropertyChanged += (s, e) => this.ApplyConfigurationItemToNotificationState(notificationState, configItem, configItemAttribute, expander);

            foreach (var notificationStateItem in notificationState.ItemsState)
            {
                var stackPanelForToggleButton = this.CreateControlForNotificationStateItem(notificationStateItem);
                itemsStackPanelColumn1.Children.Add(stackPanelForToggleButton);
            }

            var stackPanelForUseGlobalToggleButton = this.CreateControlForNotificationStateItem(notificationState.UseGlobalSettings, false);

            itemsStackPanelColumn2.Children.Add(stackPanelForUseGlobalToggleButton);

            var stackPanelForOnlyIfStateChangedToggleButton = this.CreateControlForNotificationStateItem(notificationState.OnlyIfStateChanged);

            itemsStackPanelColumn2.Children.Add(stackPanelForOnlyIfStateChangedToggleButton);

            this.AssignPropertyChangeOfStateItems(notificationState, configItem);
            this.UpdateExpanderHeader(expander, notificationState);
            return(card);
        }
        /// <summary>
        /// Applies the <see cref="IConfigurationItem" />to <see cref="NotificationsState" />s.
        /// </summary>
        /// <param name="notificationsState">The notification state.</param>
        /// <param name="configItem">The configuration item.</param>
        /// <param name="configItemAttribute">The configuration item attribute.</param>
        /// <param name="expander">The expander control.</param>
        private void ApplyConfigurationItemToNotificationState(NotificationsState notificationsState, IConfigurationItem configItem, ConfigurationItemAttribute configItemAttribute, Expander expander)
        {
            var configItemValue   = configItem.GetOrCreateConnectorNotificationConfiguration();
            var observationStates = Enum.GetValues(typeof(ObservationState)).Cast <ObservationState>().ToList();

            if (configItemAttribute is NotificationConfigurationItemAttribute notificationConfigurationItemAttribute)
            {
                this.RemoveNotSupportedObservationStates(observationStates, notificationConfigurationItemAttribute);
            }

            var useGlobalSettingsNewState = configItemValue.UseGlobalNotificationSettings;

            if (useGlobalSettingsNewState != notificationsState.UseGlobalSettings.IsActive)
            {
                notificationsState.UseGlobalSettings.IsActive = useGlobalSettingsNewState;
            }

            var onlyIfStateChangedSettingsNewState = configItemValue.OnlyIfChanged;

            if (onlyIfStateChangedSettingsNewState != notificationsState.OnlyIfStateChanged.IsActive)
            {
                notificationsState.OnlyIfStateChanged.IsActive = onlyIfStateChangedSettingsNewState;
            }

            foreach (var observationState in observationStates)
            {
                var notificationStateItem = notificationsState.ItemsState.FirstOrDefault(n => n.ObservationState == observationState);
                if (notificationStateItem == null)
                {
                    notificationStateItem                  = new NotificationStateItem(notificationsState);
                    notificationStateItem.IsActive         = configItemValue.AsObservationStateFlag(observationState);
                    notificationStateItem.ObservationState = observationState;
                    notificationStateItem.Caption          = observationState.ToString(); // TODO load from resources
                    notificationStateItem.PropertyChanged += (s, e) => this.NotificationStateChanged(notificationStateItem, configItem, e.PropertyName);
                    notificationStateItem.PropertyChanged += (s, e) => this.UpdateExpanderHeader(expander, notificationsState);
                    notificationsState.ItemsState.Add(notificationStateItem);
                }
                else
                {
                    var newActiveState = configItemValue.UseGlobalNotificationSettings;
                    if (notificationStateItem.IsActive != newActiveState)
                    {
                        notificationStateItem.IsActive = configItemValue.AsObservationStateFlag(observationState);
                    }
                }
            }
        }
Example #12
0
        /// <summary>
        /// Creates a new control and returns it.
        /// </summary>
        /// <param name="configItem">The configuration item.</param>
        /// <param name="configItemAttribute">The configuration item attribute.</param>
        /// <returns>
        /// Returns the <see cref="Control" /> for the <see cref="configItem" />.
        /// </returns>
        public override FrameworkElement GetControlInternal(IConfigurationItem configItem, ConfigurationItemAttribute configItemAttribute)
        {
            var card = new Card();

            card.Margin = new Thickness(4, 0, 4, 0);
            card.SetResourceReference(Control.BackgroundProperty, "MaterialDesignBackground");
            var expander = new Expander();

            card.Content = expander;
            expander.HorizontalAlignment = HorizontalAlignment.Stretch;
            var itemsStackPanel = new StackPanel();

            expander.Content = itemsStackPanel;

            IList <NotificationState> notificationStates = new List <NotificationState>();

            this.ApplyConfigurationItemToNotificationStateList(notificationStates, configItem, configItemAttribute, expander);
            var configItemPropertyChanged = (INotifyPropertyChanged)configItem;

            configItemPropertyChanged.PropertyChanged += (s, e) => this.ApplyConfigurationItemToNotificationStateList(notificationStates, configItem, configItemAttribute, expander);

            foreach (var notificationState in notificationStates)
            {
                var itemStackPanel = new StackPanel();
                itemStackPanel.Orientation = Orientation.Horizontal;
                itemStackPanel.Margin      = new Thickness(2, 6, 2, 0);
                var toggleButton        = new ToggleButton();
                var toogleButtonBinding = new Binding(nameof(NotificationState.IsActive));
                toogleButtonBinding.Source = notificationState;
                toogleButtonBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
                toggleButton.SetBinding(ToggleButton.IsCheckedProperty, toogleButtonBinding);
                itemStackPanel.Children.Add(toggleButton);
                var label = new Label();
                label.Content = notificationState.Caption;

                if (!notificationState.IsUseGlobalSettings)
                {
                    var toogleButtonEnabledBinding = new Binding(nameof(NotificationState.IsNotUseGlobalSettingsForParentListActive));
                    toogleButtonEnabledBinding.Source = notificationState;
                    toogleButtonEnabledBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
                    toggleButton.SetBinding(UIElement.IsEnabledProperty, toogleButtonEnabledBinding);
                }

                itemStackPanel.Children.Add(label);
                itemsStackPanel.Children.Add(itemStackPanel);
            }

            this.UpdateExpanderHeader(expander, notificationStates);
            return(card);
        }
Example #13
0
        /// <summary>
        /// Creates a new control and returns it.
        /// </summary>
        /// <param name="configItem">The configuration item of the connector.</param>
        /// <param name="configItemAttribute">The configuration item attribute.</param>
        /// <returns>
        /// Returns the <see cref="FrameworkElement" /> for the <see cref="configItem" />.
        /// </returns>
        public override FrameworkElement GetControlInternal(IConfigurationItem configItem, ConfigurationItemAttribute configItemAttribute)
        {
            var comboBox = new ComboBox();

            comboBox.DataContext = configItem;
            var style = Application.Current.FindResource("MaterialDesignFloatingHintComboBox") as Style;

            comboBox.Style = style;
            HintAssist.SetIsFloating(comboBox, true);
            HintAssist.SetHint(comboBox, configItemAttribute.Caption);
            return(comboBox);
        }
Example #14
0
        /// <summary>
        /// Creates a new control and returns it.
        /// </summary>
        /// <param name="configItem">The configuration item of the connector.</param>
        /// <param name="configItemAttribute">The configuration item attribute.</param>
        /// <returns>
        /// Returns the <see cref="FrameworkElement" /> for the <see cref="configItem" />.
        /// </returns>
        public override FrameworkElement GetControlInternal(IConfigurationItem configItem, ConfigurationItemAttribute configItemAttribute)
        {
            var comboBox = (ComboBox)base.GetControlInternal(configItem, configItemAttribute);

            comboBox.IsEditable = true;
            var suggestedValueBinding = new Binding();

            suggestedValueBinding.Source = GlobalConfigDataViewModel.Instance;
            suggestedValueBinding.Path   = new PropertyPath(nameof(GlobalConfigDataViewModel.UsedCategories));
            suggestedValueBinding.Mode   = BindingMode.OneWay;
            suggestedValueBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            BindingOperations.SetBinding(comboBox, ItemsControl.ItemsSourceProperty, suggestedValueBinding);
            return(comboBox);
        }
Example #15
0
        /// <summary>
        /// Creates a new control and returns it.
        /// </summary>
        /// <param name="configItem">The configuration item of the connector.</param>
        /// <param name="configItemAttribute">The configuration item attribute.</param>
        /// <returns>
        /// Returns the <see cref="FrameworkElement" /> for the <see cref="configItem" />.
        /// </returns>
        public override FrameworkElement GetControlInternal(IConfigurationItem configItem, ConfigurationItemAttribute configItemAttribute)
        {
            var numericTextBox = base.GetControlInternal(configItem, configItemAttribute);

            numericTextBox.PreviewTextInput   += this.NumberValidationTextBox;
            numericTextBox.Width               = 150;
            numericTextBox.HorizontalAlignment = HorizontalAlignment.Left;
            return(numericTextBox);
        }