Exemplo n.º 1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="PluginDataRepository" /> class.
        /// </summary>
        /// <exception cref="Exception"></exception>
        public PluginDataRepository([NotNull] IPluginsSetup pluginsSetup, [NotNull][ItemNotNull] IEnumerable <IPlugin> plugins,
                                    [NotNull] ISettings globalSettings, [NotNull] ITypeBasedSimpleSerializerAggregator typeBasedSimpleSerializerAggregator)
        {
            var typeToPluginMap = new Dictionary <Type, IPlugin>();

            foreach (var plugin in plugins)
            {
                if (typeToPluginMap.ContainsKey(plugin.GetType()))
                {
                    throw new Exception($"Multiple occurrences of plugin of type '{plugin.GetType()}'.");
                }

                typeToPluginMap[plugin.GetType()] = plugin;
            }

            foreach (var pluginSetup in pluginsSetup.AllPluginSetups)
            {
                if (!pluginSetup.Enabled)
                {
                    continue;
                }

                var         plugin     = typeToPluginMap[pluginSetup.PluginImplementationElement.ValueTypeInfo.Type];
                IPluginData pluginData = new PluginData(pluginSetup,
                                                        plugin, globalSettings,
                                                        typeBasedSimpleSerializerAggregator);
                plugin.PluginData = pluginData;

                _pluginNameToPluginData[pluginSetup.Plugin.Name] = pluginData;
                _pluginTypeToPluginData[pluginSetup.PluginImplementationElement.ValueTypeInfo.Type] = pluginData;
            }
        }
Exemplo n.º 2
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="PluginData" /> class.
 /// </summary>
 public PluginData([NotNull] IPluginSetup pluginSetup, [NotNull] IPlugin plugin,
                   [NotNull] ISettings globalSettings,
                   [NotNull] ITypeBasedSimpleSerializerAggregator typeBasedSimpleSerializerAggregator)
 {
     Settings   = new PluginSettings(globalSettings, pluginSetup.SettingsElement, typeBasedSimpleSerializerAggregator);
     PluginName = pluginSetup.Plugin.Name;
     Plugin     = plugin;
 }
Exemplo n.º 3
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="Settings" /> class.
        /// </summary>
        public Settings([NotNull] ISettingsElement settingsElement, [NotNull] ITypeBasedSimpleSerializerAggregator typeBasedSimpleSerializerAggregator)
        {
            _typeBasedSimpleSerializerAggregator = typeBasedSimpleSerializerAggregator;

            foreach (var setting in settingsElement.AllSettings)
            {
                _settingNameToSettingMap[setting.Name] = new Setting(setting);
            }
        }
Exemplo n.º 4
0
 static TypeBasedSimpleSerializerAggregator()
 {
     _defaultSerializerAggregator = new TypeBasedSimpleSerializerAggregator();
     _defaultSerializerAggregator.Register(new TypeBasedSimpleSerializerDouble());
     _defaultSerializerAggregator.Register(new TypeBasedSimpleSerializerLong());
     _defaultSerializerAggregator.Register(new TypeBasedSimpleSerializerInt());
     _defaultSerializerAggregator.Register(new TypeBasedSimpleSerializerShort());
     _defaultSerializerAggregator.Register(new TypeBasedSimpleSerializerByte());
     _defaultSerializerAggregator.Register(new TypeBasedSimpleSerializerBoolean());
     _defaultSerializerAggregator.Register(new TypeBasedSimpleSerializerDateTime());
     _defaultSerializerAggregator.Register(new TypeBasedSimpleSerializerGuid());
     _defaultSerializerAggregator.Register(new TypeBasedSimpleSerializerString());
     _defaultSerializerAggregator.Register(new TypeBasedSimpleSerializerType());
     _defaultSerializerAggregator.Register(new TypeBasedSimpleSerializerAssembly());
 }
Exemplo n.º 5
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="PluginSettings" /> class.
        /// </summary>
        public PluginSettings([NotNull] ISettings globalSettings, ISettingsElement pluginSettingsElementElement,
                              [NotNull] ITypeBasedSimpleSerializerAggregator typeBasedSimpleSerializerAggregator)
        {
            _globalSettings = globalSettings;
            _pluginSettings = new Settings(pluginSettingsElementElement, typeBasedSimpleSerializerAggregator);

            foreach (var setting in _globalSettings.AllSettings)
            {
                _settingNameToSettingMap[setting.Name] = setting;
            }

            // Override global settings with plugin settings
            foreach (var setting in _pluginSettings.AllSettings)
            {
                _settingNameToSettingMap[setting.Name] = setting;
            }
        }
        public override void ValidateAfterChildrenAdded()
        {
            base.ValidateAfterChildrenAdded();

            var defaultSerializer = OROptimizer.Serializer.TypeBasedSimpleSerializerAggregator.GetDefaultSerializerAggregator();

            var serializerAggregatorObject = _createInstanceFromTypeAndConstructorParameters.CreateInstance(this,
                                                                                                            typeof(ITypeBasedSimpleSerializerAggregator), _serializerAggregatorType, _parameters?.AllParameters ?? Array.Empty <IParameterElement>());

            TypeBasedSimpleSerializerAggregator = (ITypeBasedSimpleSerializerAggregator)serializerAggregatorObject;

            if (_parameterSerializersCollection != null)
            {
                foreach (var parameterSerializer in _parameterSerializersCollection.AllSerializers)
                {
                    if (parameterSerializer.Serializer == null)
                    {
                        LogHelper.Context.Log.WarnFormat("The value of '{0}.{1}' should not be null.", typeof(IParameterSerializer).FullName, nameof(IParameterSerializer.Serializer));
                        continue;
                    }

                    var defaultSerializerForType = defaultSerializer.GetSerializerForType(parameterSerializer.Serializer.SerializedType);
                    if (defaultSerializerForType != null)
                    {
                        LogHelper.Context.Log.InfoFormat("Replacing default serializer for type '{0}' with a serializer '{1}'. The default serializer was '{2}'.",
                                                         parameterSerializer.Serializer.SerializedType.GetTypeNameInCSharpClass(),
                                                         parameterSerializer.Serializer.GetType().GetTypeNameInCSharpClass(),
                                                         defaultSerializerForType.GetType().GetTypeNameInCSharpClass());

                        TypeBasedSimpleSerializerAggregator.UnRegister(parameterSerializer.Serializer.SerializedType);
                    }

                    TypeBasedSimpleSerializerAggregator.Register(parameterSerializer.Serializer);
                }
            }

            foreach (var serializer in defaultSerializer.GetRegisteredSerializers())
            {
                if (!TypeBasedSimpleSerializerAggregator.HasSerializerForType(serializer.SerializedType))
                {
                    TypeBasedSimpleSerializerAggregator.Register(serializer);
                }
            }

            LogSerializersData();
        }
 public DeserializedFromStringValueInitializerHelper([NotNull] ITypeBasedSimpleSerializerAggregator typeBasedSimpleSerializerAggregator)
 {
     _typeBasedSimpleSerializerAggregator = typeBasedSimpleSerializerAggregator;
 }
 public void OnDiContainerReady(IDiContainer diContainer)
 {
     _diContainer         = diContainer;
     _parameterSerializer = _diContainer.Resolve <ITypeBasedSimpleSerializerAggregator>();
 }
Exemplo n.º 9
0
 public IDeserializedFromStringValueInitializerHelper CreateDeserializedFromStringValueInitializerHelper(ITypeBasedSimpleSerializerAggregator typeBasedSimpleSerializerAggregator)
 {
     return(_ioCServiceFactory.CreateDeserializedFromStringValueInitializerHelper(typeBasedSimpleSerializerAggregator));
 }