/// <inheritdoc />
 protected override void InitializeLeftPath()
 {
     if (Entity.LeftPath != null)
     {
         LeftPath = DataModelConditionList.ListType != null
             ? new DataModelPath(ListPredicateWrapperDataModel.Create(DataModelConditionList.ListType), Entity.LeftPath)
             : null;
     }
 }
示例#2
0
        /// <inheritdoc />
        public void Save()
        {
            // Do not save an invalid state
            if (!IsValid)
            {
                return;
            }

            Entity.Path        = Path;
            Entity.DataModelId = DataModelId;

            Entity.WrapperType = Target switch
            {
                ListPredicateWrapperDataModel _ => PathWrapperType.List,
                EventPredicateWrapperDataModel _ => PathWrapperType.Event,
                                              _ => PathWrapperType.None
            };
        }
 /// <inheritdoc />
 protected override void InitializeRightPath()
 {
     if (PredicateType == ProfileRightSideType.Dynamic && Entity.RightPath != null)
     {
         // Right side dynamic inside the list
         if (Entity.RightPath.WrapperType == PathWrapperType.List)
         {
             RightPath = DataModelConditionList.ListType != null
                 ? new DataModelPath(ListPredicateWrapperDataModel.Create(DataModelConditionList.ListType), Entity.RightPath)
                 : null;
         }
         // Right side dynamic
         else
         {
             RightPath = new DataModelPath(null, Entity.RightPath);
         }
     }
 }
        private void Initialize()
        {
            ConditionOperatorStore.ConditionOperatorAdded   += ConditionOperatorStoreOnConditionOperatorAdded;
            ConditionOperatorStore.ConditionOperatorRemoved += ConditionOperatorStoreOnConditionOperatorRemoved;

            // Left side
            if (Entity.LeftPath != null)
            {
                LeftPath = DataModelConditionList.ListType != null
                    ? new DataModelPath(ListPredicateWrapperDataModel.Create(DataModelConditionList.ListType), Entity.LeftPath)
                    : null;
            }

            // Operator
            if (Entity.OperatorPluginGuid != null)
            {
                ConditionOperator?conditionOperator = ConditionOperatorStore.Get(Entity.OperatorPluginGuid.Value, Entity.OperatorType)?.ConditionOperator;
                if (conditionOperator != null)
                {
                    UpdateOperator(conditionOperator);
                }
            }

            // Right side dynamic
            if (PredicateType == ProfileRightSideType.Dynamic && Entity.RightPath != null)
            {
                // Right side dynamic inside the list
                // TODO: Come up with a general wrapper solution because this will clash with events
                if (Entity.RightPath.DataModelGuid == Constants.CorePluginInfo.Guid)
                {
                    RightPath = DataModelConditionList.ListType != null
                        ? new DataModelPath(ListPredicateWrapperDataModel.Create(DataModelConditionList.ListType), Entity.RightPath)
                        : null;
                }
                // Right side dynamic
                else
                {
                    RightPath = new DataModelPath(null, Entity.RightPath);
                }
            }
            // Right side static
            else if (PredicateType == ProfileRightSideType.Static && Entity.RightStaticValue != null)
            {
                try
                {
                    if (LeftPath != null && LeftPath.IsValid)
                    {
                        // Use the left side type so JSON.NET has a better idea what to do
                        Type   leftSideType = LeftPath.GetPropertyType() !;
                        object?rightSideValue;

                        try
                        {
                            rightSideValue = JsonConvert.DeserializeObject(Entity.RightStaticValue, leftSideType);
                        }
                        // If deserialization fails, use the type's default
                        catch (JsonSerializationException e)
                        {
                            DeserializationLogger.LogListPredicateDeserializationFailure(this, e);
                            rightSideValue = Activator.CreateInstance(leftSideType);
                        }

                        UpdateRightSideStatic(rightSideValue);
                    }
                    else
                    {
                        // Hope for the best... we must infer the type from JSON now
                        UpdateRightSideStatic(JsonConvert.DeserializeObject(Entity.RightStaticValue));
                    }
                }
                catch (JsonException e)
                {
                    DeserializationLogger.LogListPredicateDeserializationFailure(this, e);
                }
            }
        }