Esempio n. 1
0
 public string Create(IConfigFile configFile, string extension)
 {
     Precondition.ArgumentNotNull(configFile, nameof(configFile));
     return(string.IsNullOrWhiteSpace(extension)
         ? configFile.Metadata.Key
         : $"{configFile.Metadata.Key}.{extension}");
 }
Esempio n. 2
0
        /// <summary>
        /// Builds a UI from config data and binds its properties to this the UI.
        /// </summary>
        /// <param name="config">
        /// The config data that will be used to determine the UI structure and binds
        /// its properties to the UI.
        /// </param>
        /// <typeparam name="T">
        /// Type of the UI which is an <see cref="IContainer"/>.
        /// </typeparam>
        /// <returns>The UI instance that is created from the config data.</returns>
        public T Build <T>(object config) where T : IContainer
        {
            Precondition.ArgumentNotNull(config, nameof(config));
            Precondition.PropertyNotNull(SettingBinder, nameof(SettingBinder));
            CheckFactories();

            var container  = _componentManager.CreateComponentFromComponentType <IContainer>(typeof(T));
            var configType = config.GetType();

            var settings = CreateSettingBuilder(configType).Build();

            SettingBinder.BindContainer(container, configType, settings);

            foreach (var propertyInfo in configType.GetProperties())
            {
                var component = BuildRecursive(config, propertyInfo);
                if (component == null)
                {
                    continue;
                }

                container.AddChild(component);
            }

            return((T)container);
        }
Esempio n. 3
0
        public void RegisterComponentFactory(Type componentType, object factory)
        {
            Precondition.ArgumentNotNull(componentType, nameof(componentType));
            Precondition.ArgumentNotNull(factory, nameof(factory));
            Precondition.ArgumentCompatibleType(componentType, typeof(IComponent), nameof(componentType));

            _registeredComponentFactories.Add(componentType, factory);
        }
Esempio n. 4
0
        public T CreateComponentFromPropertyType <T>(Type propertyType) where T : IComponent
        {
            Precondition.ArgumentNotNull(propertyType, nameof(propertyType));
            var componentType = LookupComponentType(propertyType);

            if (componentType == null)
            {
                throw new ArgumentException($"Property type {propertyType.Name} did not register yet.");
            }
            return(CreateComponentFromComponentType <T>(componentType));
        }
Esempio n. 5
0
        public void RegisterDefaultComponentType(Type propertyType, Type componentType)
        {
            Precondition.ArgumentNotNull(componentType, nameof(componentType));
            Precondition.ArgumentNotNull(propertyType, nameof(propertyType));
            Precondition.ArgumentCompatibleType(componentType, typeof(IComponent), nameof(componentType));

            if (_defaultComponenTypeForPropertyTypes.ContainsKey(propertyType))
            {
                _defaultComponenTypeForPropertyTypes.Remove(propertyType);
            }
            _defaultComponenTypeForPropertyTypes.Add(propertyType, componentType);
        }
        public IConfigFile Create(string key, object configData)
        {
            Precondition.ArgumentNotNull(key, nameof(key));
            Precondition.ArgumentNotNull(configData, nameof(configData));

            return(new ConfigFile
            {
                ConfigData = configData,
                Metadata = new Metadata
                {
                    Key = key,
                    TypeId = configData.GetType().AssemblyQualifiedName,
                    Modified = DateTime.Now
                }
            });
        }
Esempio n. 7
0
        public void SetLayoutManager(FlowLayoutManager layoutManager)
        {
            Precondition.ArgumentNotNull(layoutManager, nameof(layoutManager));
            if (_layoutManager != null)
                panel1.Controls.Remove(_layoutManager);

            _layoutManager = layoutManager;
            panel1.Controls.Add(_layoutManager);
            _layoutManager.Dock = DockStyle.Fill;
            _layoutManager.AutoSize = false;
            _layoutManager.AutoScroll = true;
            _layoutManager.WrapContents = true;
            _layoutManager.BringToFront();

            UpdateWidth();
        }
        public IConfigFile ToConfigFile(string configFileAsString)
        {
            Precondition.ArgumentNotNull(configFileAsString, nameof(configFileAsString));
            var jsonObject     = JObject.Parse(configFileAsString);
            var metadata       = jsonObject.GetValue(nameof(IConfigFile.Metadata)).ToObject <Metadata>(_serializer);
            var configDataType = Type.GetType(metadata.TypeId, true);
            var configData     = jsonObject
                                 .GetValue(nameof(IConfigFile.ConfigData))
                                 .ToObject(configDataType, _serializer);

            return(new ConfigFile
            {
                Metadata = metadata,
                ConfigData = configData
            });
        }
Esempio n. 9
0
        /// <summary>
        /// Copy whole settings from source to this instance.
        /// </summary>
        public void Copy(UiManager source)
        {
            Precondition.ArgumentNotNull(source, nameof(source));

            _componentManager.Copy(source._componentManager);
            _settingBinder = source._settingBinder;

            SettingBinder = source.SettingBinder;

            LayoutManagerFactory       = source.LayoutManagerFactory;
            LayoutOptionsFactory       = source.LayoutOptionsFactory;
            SizeOptionsFactory         = source.SizeOptionsFactory;
            DateTimeOptionsFactory     = source.DateTimeOptionsFactory;
            ContainerAppearanceFactory = source.ContainerAppearanceFactory;
            EditorAppearanceFactory    = source.EditorAppearanceFactory;

            AllowAutoCreateInstanceIfMissing = source.AllowAutoCreateInstanceIfMissing;
        }
Esempio n. 10
0
        /// <summary>
        /// Lookups child component from property name.
        /// </summary>
        /// <param name="container">An <see cref="IContainer"/> that contains the lookup component.</param>
        /// <param name="propertyName">Property name that equals to component name. Lookups by this name.</param>
        /// <typeparam name="T">Type of the result component.</typeparam>
        /// <returns></returns>
        public static T LookupByName <T>(this IContainer container, string propertyName) where T : IComponent
        {
            Precondition.ArgumentNotNull(container, nameof(container));
            Precondition.ArgumentNotNull(propertyName, nameof(propertyName));

            foreach (var child in container.Children)
            {
                if (child.Name == propertyName)
                {
                    return((T)child);
                }

                if (child is IContainer childContainer)
                {
                    return(LookupByName <T>(childContainer, propertyName));
                }
            }

            return(default(T));
        }
Esempio n. 11
0
        /// <summary>
        /// Changes the UI value.
        /// </summary>
        /// <param name="newValue">New value.</param>
        /// <param name="doChaningValue">Do changing the UI value.</param>
        /// <param name="onValueChanging">Trigger value changing event.</param>
        /// <param name="onValueChanged">Trigger value changed event.</param>
        public void ChangeValue(
            T newValue,
            Action doChaningValue,
            ValueChangingEventHandler onValueChanging,
            ValueChangedEventHandler onValueChanged)
        {
            Precondition.ArgumentNotNull(doChaningValue, nameof(doChaningValue));

            var oldValue = _editor.Value;

            if (onValueChanging != null)
            {
                var args = new ValueChangingEventArgs(oldValue, newValue);
                onValueChanging.Invoke(_editor, args);
                if (args.Cancel)
                {
                    return;
                }
            }

            doChaningValue();

            onValueChanged?.Invoke(_editor, new ValueChangedEventArgs(oldValue, newValue));
        }
Esempio n. 12
0
 public T CreateComponentFromComponentType <T>(Type componentType) where T : IComponent
 {
     Precondition.ArgumentNotNull(componentType, nameof(componentType));
     Precondition.ArgumentCompatibleType(componentType, typeof(IComponent), nameof(componentType));
     return((T)ComponentFactoryWrapper.From(_registeredComponentFactories[componentType]).Create());
 }
Esempio n. 13
0
 private EditorWrapper(object genericEditor)
 {
     Precondition.ArgumentNotNull(genericEditor, nameof(genericEditor));
     _genericEditor = genericEditor;
 }
Esempio n. 14
0
 public void SetItemFactory(Func<object, Control> itemContentFactory)
 {
     Precondition.ArgumentNotNull(itemContentFactory, nameof(itemContentFactory));
     _itemContentFactory = itemContentFactory;
 }
 public string ToString(IConfigFile configFile)
 {
     Precondition.ArgumentNotNull(configFile, nameof(configFile));
     return(JObject.FromObject(configFile, _serializer).ToString());
 }