public static void EnsureIntegrity(this PropertyExpression propertyExpression, IReflectionService reflectionService)
        {
            Argument.IsNotNull(() => propertyExpression);
            Argument.IsNotNull(() => reflectionService);

            if (propertyExpression.Property == null)
            {
                var serializationValue = propertyExpression.PropertySerializationValue;
                if (!string.IsNullOrWhiteSpace(serializationValue))
                {
                    var splittedString = serializationValue.Split(new[] { Separator }, StringSplitOptions.RemoveEmptyEntries);
                    if (splittedString.Length == 2)
                    {
                        var type = TypeCache.GetType(splittedString[0]);
                        if (type != null)
                        {
                            var typeProperties = reflectionService.GetInstanceProperties(type);
                            propertyExpression.Property = typeProperties.GetProperty(splittedString[1]);
                        }
                    }
                }
            }
            else
            {
                // We already have it, but make sure to get the right instance
                var property = propertyExpression.Property;

                var typeProperties = reflectionService.GetInstanceProperties(property.OwnerType);
                propertyExpression.Property = typeProperties.GetProperty(property.Name);
            }
        }
Example #2
0
        public override void DeserializeMember(ISerializationContext context, MemberValue memberValue)
        {
            if (string.Equals(memberValue.Name, "Property"))
            {
                var propertyMetadata = memberValue.Value as string;
                if (propertyMetadata != null)
                {
                    // We need to delay this
                    ((PropertyExpression)context.Model).PropertySerializationValue = propertyMetadata;

                    var splitted = propertyMetadata.Split(Separators, System.StringSplitOptions.None);

                    var type = TypeCache.GetTypeWithoutAssembly(splitted[0]);
                    var instanceProperties = _reflectionService.GetInstanceProperties(type);
                    memberValue.Value = instanceProperties.GetProperty(splitted[1]);
                }
            }
        }
        public EditFilterViewModel(FilterSchemeEditInfo filterSchemeEditInfo, IReflectionService reflectionService, 
            IXmlSerializer xmlSerializer, IMessageService messageService)
        {
            Argument.IsNotNull(() => filterSchemeEditInfo);
            Argument.IsNotNull(() => reflectionService);
            Argument.IsNotNull(() => xmlSerializer);
            Argument.IsNotNull(() => messageService);

            PreviewItems = new FastObservableCollection<object>();
            RawCollection = filterSchemeEditInfo.RawCollection;
            EnableAutoCompletion = filterSchemeEditInfo.EnableAutoCompletion;
            AllowLivePreview = filterSchemeEditInfo.AllowLivePreview;
            EnableLivePreview = filterSchemeEditInfo.AllowLivePreview;
            
            var filterScheme = filterSchemeEditInfo.FilterScheme;

            _originalFilterScheme = filterScheme;
            _reflectionService = reflectionService;
            _xmlSerializer = xmlSerializer;
            _messageService = messageService;

            DeferValidationUntilFirstSaveCall = true;

            InstanceProperties = _reflectionService.GetInstanceProperties(filterScheme.TargetType).Properties;

            // Serializing gives us a *real* deep clone, there was a bug in Copy()
            //FilterScheme = _originalFilterScheme.Copy();

            using (var memoryStream = new MemoryStream())
            {
                xmlSerializer.Serialize(_originalFilterScheme, memoryStream);
                memoryStream.Position = 0L;
                FilterScheme = (FilterScheme) xmlSerializer.Deserialize(typeof (FilterScheme), memoryStream);
            }

            FilterSchemeTitle = FilterScheme.Title;

            AddGroupCommand = new Command<ConditionGroup>(OnAddGroup);
            AddExpressionCommand = new Command<ConditionGroup>(OnAddExpression);
            DeleteConditionItem = new Command<ConditionTreeItem>(OnDeleteCondition);
        }
Example #4
0
        public static void EnsureIntegrity(this PropertyExpression propertyExpression)
        {
            Argument.IsNotNull(() => propertyExpression);

            if (propertyExpression.Property == null)
            {
                var serializationValue = propertyExpression.PropertySerializationValue;
                if (!string.IsNullOrWhiteSpace(serializationValue))
                {
                    var splittedString = serializationValue.Split(new[] { Separator }, StringSplitOptions.RemoveEmptyEntries);
                    if (splittedString.Length == 2)
                    {
                        var type = TypeCache.GetType(splittedString[0]);
                        if (type != null)
                        {
                            var typeProperties = _reflectionService.GetInstanceProperties(type);
                            propertyExpression.Property = typeProperties.GetProperty(splittedString[1]);
                        }
                    }
                }
            }
        }
Example #5
0
        protected override async Task InitializeAsync()
        {
            await base.InitializeAsync();

            InstanceProperties = _reflectionService.GetInstanceProperties(_originalFilterScheme.TargetType).Properties;

            using (var memoryStream = new MemoryStream())
            {
                _xmlSerializer.Serialize(_originalFilterScheme, memoryStream, null);
                memoryStream.Position = 0L;
                _xmlSerializer.Deserialize(FilterScheme, memoryStream, null);
            }

            FilterScheme.EnsureIntegrity(_reflectionService);
            FilterScheme.Scope = _originalFilterScheme.Scope;
            FilterSchemeTitle  = FilterScheme.Title;

            RaisePropertyChanged(() => FilterScheme);

            UpdatePreviewItems();

            FilterScheme.Updated += OnFilterSchemeUpdated;
        }