Beispiel #1
0
        internal DataBindingModifierTypeRegistration(DataBindingModifierType dataBindingModifierType, Plugin plugin)
        {
            DataBindingModifierType = dataBindingModifierType;
            Plugin = plugin;

            Plugin.PluginDisabled += PluginOnPluginDisabled;
        }
        private void DataBindingModifierTypeStoreOnDataBindingModifierAdded(object sender, DataBindingModifierTypeStoreEvent e)
        {
            if (ModifierType != null)
            {
                return;
            }

            DataBindingModifierType modifierType = e.TypeRegistration.DataBindingModifierType;

            if (modifierType.PluginInfo.Guid == Entity.ModifierTypePluginGuid && modifierType.GetType().Name == Entity.ModifierType)
            {
                UpdateModifierType(modifierType);
            }
        }
        private void Initialize()
        {
            DataBindingModifierTypeStore.DataBindingModifierAdded   += DataBindingModifierTypeStoreOnDataBindingModifierAdded;
            DataBindingModifierTypeStore.DataBindingModifierRemoved += DataBindingModifierTypeStoreOnDataBindingModifierRemoved;

            // Modifier type
            if (Entity.ModifierTypePluginGuid != null && ModifierType == null)
            {
                DataBindingModifierType modifierType = DataBindingModifierTypeStore.Get(Entity.ModifierTypePluginGuid.Value, Entity.ModifierType)?.DataBindingModifierType;
                if (modifierType != null)
                {
                    UpdateModifierType(modifierType);
                }
            }

            // Dynamic parameter
            if (ParameterType == ProfileRightSideType.Dynamic && Entity.ParameterPath != null)
            {
                ParameterPath = new DataModelPath(null, Entity.ParameterPath);
            }
            // Static parameter
            else if (ParameterType == ProfileRightSideType.Static && Entity.ParameterStaticValue != null && ParameterStaticValue == null)
            {
                // Use the target type so JSON.NET has a better idea what to do
                Type   parameterType = ModifierType?.ParameterType ?? DirectDataBinding.DataBinding.GetTargetType();
                object staticValue;

                try
                {
                    staticValue = JsonConvert.DeserializeObject(Entity.ParameterStaticValue, parameterType);
                }
                // If deserialization fails, use the type's default
                catch (JsonSerializationException e)
                {
                    DeserializationLogger.LogModifierDeserializationFailure(GetType().Name, e);
                    staticValue = Activator.CreateInstance(parameterType);
                }

                UpdateParameterStatic(staticValue);
            }
        }
        public static DataBindingModifierTypeRegistration Add(DataBindingModifierType modifierType)
        {
            DataBindingModifierTypeRegistration typeRegistration;

            lock (Registrations)
            {
                if (Registrations.Any(r => r.DataBindingModifierType == modifierType))
                {
                    throw new ArtemisCoreException($"Data binding modifier type store already contains modifier '{modifierType.Name}'");
                }

                typeRegistration = new DataBindingModifierTypeRegistration(modifierType, modifierType.PluginInfo.Instance)
                {
                    IsInStore = true
                };
                Registrations.Add(typeRegistration);
            }

            OnDataBindingModifierAdded(new DataBindingModifierTypeStoreEvent(typeRegistration));
            return(typeRegistration);
        }
        /// <summary>
        ///     Updates the modifier type of the modifier and re-compiles the expression
        /// </summary>
        /// <param name="modifierType"></param>
        public void UpdateModifierType(DataBindingModifierType modifierType)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException("DataBindingModifier");
            }

            // Calling CreateExpression will clear compiled expressions
            if (modifierType == null)
            {
                ModifierType = null;
                return;
            }

            Type targetType = DirectDataBinding.DataBinding.GetTargetType();

            if (!modifierType.SupportsType(targetType))
            {
                throw new ArtemisCoreException($"Cannot apply modifier type {modifierType.GetType().Name} to this modifier because " +
                                               $"it does not support this data binding's type {targetType.Name}");
            }

            ModifierType = modifierType;
        }