コード例 #1
0
        public override async Task UpdateProperties(T destination1, Dictionary <string, string> matches, Dictionary <string, string> excelRow, RecordMode recordMode)
        {
            {
                var product = new Product();
                var productCategoryPropertyName = "ProductCategoryCode";
                var productPropertyName         = PropertyNameHelper.GetPropertyName(() => product.ProductName);

                foreach (var destinationProperty in matches.Keys)
                {
                    var xlsxColumnName = matches[destinationProperty];
                    var value          = excelRow[xlsxColumnName];
                    if (destinationProperty == productCategoryPropertyName)
                    {
                        var newCategory =
                            await _context.Set <ProductCategory>().Where(x => x.CategoryCode == value).FirstOrDefaultAsync();

                        if (newCategory == null)
                        {
                            throw new RowParseException("Category Code does not match a category");
                        }
                        destination1.ProductCategory = newCategory;
                    }
                    else if (destinationProperty == productPropertyName)
                    {
                        destination1.ProductName = value;
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CF.Xamarin.Forms.Classes.PropertyChangeListener"/> class.
        /// </summary>
        /// <param name="owner">Owner.</param>
        /// <param name="callback">Callback.</param>
        public void Listen <TModel>(Expression <Func <TModel, object> > property, object owner, Action callback)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            if (owner == null)
            {
                throw new ArgumentNullException("owner");
            }

            _notifyChangedObject = owner as INotifyPropertyChanged;
            if (_notifyChangedObject == null)
            {
                throw new ArgumentNullException("owner as IPropertyNotifyChanged");
            }

            _propertyName = PropertyNameHelper.GetPropertyName <TModel>(property);
            if (string.IsNullOrEmpty(_propertyName))
            {
                throw new ArgumentException("property");
            }

            _callback = callback;

            // Hook up event
            _notifyChangedObject.PropertyChanged += HandlePropertyChangedEventHandler;

            // Start by updating:
            _callback();
        }
コード例 #3
0
        protected void OnPropertyChanged <T>(Expression <Func <T> > propertyExpression)
        {
            string propertyName = PropertyNameHelper.GetPropertyName(propertyExpression);

            if (propertyName != null)
            {
                OnPropertyChanged(propertyName);
            }
        }
コード例 #4
0
        /// <summary>
        /// Calls the notify property changed event if it is attached. By using some
        /// Expression/Func magic we get compile time type checking on our property
        /// names by using this method instead of calling the event with a string in code.
        /// </summary>
        /// <param name="property">Property.</param>
        protected void RaisePropertyChangedEvent(Expression <Func <object> > property)
        {
            if (PropertyChanged == null)
            {
                return;
            }

            PropertyChanged(this, new PropertyChangedEventArgs(
                                PropertyNameHelper.GetPropertyName <BaseNotifyPropertyChangedObject>(property)));
        }
コード例 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ViewDecorator"/> class.
        /// </summary>
        /// <param name="relativeLayout">Relative layout.</param>
        /// <param name="contents">Contents.</param>
        public ViewDecorator(RelativeLayout relativeLayout, View contents)
        {
            // Add contents
            relativeLayout.Children.Add(contents, () => relativeLayout.Bounds);

            // Create overlay
            var activityIndicatorOverlay = new RelativeLayout {
                BackgroundColor = Color.FromRgba(0x05, 0x05, 0x05, 0.75)
            };

            activityIndicatorOverlay.SetBinding(RelativeLayout.IsVisibleProperty,
                                                PropertyNameHelper.GetPropertyName <TViewModel>((vm) => vm.IsBusy));

            relativeLayout.Children.Add(activityIndicatorOverlay, () => relativeLayout.Bounds);

            // Create darker rectangle in the middle
            var activityIndicatorBackground = new RoundedBorderControl {
                BackgroundColor = Color.FromRgba(0, 0, 0, 0.78),
                CornerRadius    = 8,
            };

            activityIndicatorOverlay.Children.Add(activityIndicatorBackground, () =>
                                                  new Rectangle(activityIndicatorOverlay.Width / 2 - 81, activityIndicatorOverlay.Height / 2 - 41, 81 * 2, 82));

            // Create indicator
            var activityIndicator = new ActivityIndicator {
                Color = Color.White
            };

            activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty,
                                         PropertyNameHelper.GetPropertyName <TViewModel>((vm) => vm.IsBusy));

            activityIndicatorOverlay.Children.Add(activityIndicator, () =>
                                                  new Rectangle(activityIndicatorOverlay.Width / 2 - 16, activityIndicatorOverlay.Height / 2 - 24, 32, 32));

            // Create label with progress text
            var activityLabel = new Label {
                TextColor       = Color.White,
                BackgroundColor = Color.Transparent,
                FontSize        = 12,
                XAlign          = TextAlignment.Center
            };

            activityLabel.SetBinding(Label.TextProperty,
                                     PropertyNameHelper.GetPropertyName <TViewModel>((vm) => vm.IsBusyText));

            activityLabel.SetBinding(Label.IsVisibleProperty,
                                     PropertyNameHelper.GetPropertyName <TViewModel>((vm) => vm.IsBusyTextVisible));

            activityIndicatorOverlay.Children.Add(activityLabel, () =>
                                                  new Rectangle(activityIndicatorOverlay.X, activityIndicatorOverlay.Height / 2 + 14,
                                                                activityIndicatorOverlay.Width, 32));
        }
コード例 #6
0
        /// <summary>
        /// Creates or returns the
        /// </summary>
        /// <returns>The command.</returns>
        /// <param name="action">Action.</param>
        /// <param name="state">State.</param>
        protected Command <T> GetOrCreateCommand <TViewModel, T>(Expression <Func <object> > commandProperty,
                                                                 Command <T> command)
        {
            var commandName = PropertyNameHelper.GetPropertyName <TViewModel> (commandProperty);

            if (!_commands.ContainsKey(commandName))
            {
                _commands.Add(commandName, command);
            }

            return(_commands [commandName] as Command <T>);
        }
コード例 #7
0
        /// <summary>
        /// Adds a dependency between a command and a property. Whenever the property changes, the command's
        /// state will be updated
        /// </summary>
        /// <param name="property">Source Property.</param>
        /// <param name="command">Target Command.</param>
        protected void AddCommandDependency <TViewModel>(Expression <Func <object> > property, Command command)
        {
            var propertyName = PropertyNameHelper.GetPropertyName <TViewModel>(property);

            if (!_commandDependencies.ContainsKey(propertyName))
            {
                _commandDependencies.Add(propertyName, new List <Command> ());
            }

            var list = _commandDependencies [propertyName];

            list.Add(command);
        }
コード例 #8
0
        /// <summary>
        /// Adds a dependency between a property and another property. Whenever the property changes, the command's
        /// state will be updated
        /// </summary>
        /// <param name="property">Source property.</param>
        /// <param name="dependantProperty">Target property.</param>
        protected void AddPropertyDependency <TViewModel>(Expression <Func <object> > property,
                                                          Expression <Func <object> > dependantProperty)
        {
            var propertyName = PropertyNameHelper.GetPropertyName <TViewModel>(property);

            if (!_propertyDependencies.ContainsKey(propertyName))
            {
                _propertyDependencies.Add(propertyName, new List <Expression <Func <object> > > ());
            }

            var list = _propertyDependencies [propertyName];

            list.Add(dependantProperty);
        }
コード例 #9
0
        /// <summary>
        /// Sets a value in viewmodel storage and raises property changed if value has changed
        /// </summary>
        /// <param name="name">Name.</param>
        /// <param name="value">Value.</param>
        /// <typeparam name="TValueType">The 1st type parameter.</typeparam>
        protected bool SetValue <TValueType>(Expression <Func <object> > property, TValueType value)
        {
            var existingValue = GetValue <TValueType>(property);
            var propertyName  = PropertyNameHelper.GetPropertyName <BaseViewModel>(property);

            // Check for equality
            if (!_notifyChangeForSameValues.Contains(propertyName) &&
                EqualityComparer <TValueType> .Default.Equals(existingValue, value))
            {
                return(false);
            }

            _viewModelStorage.SetObjectForKey <TValueType> (propertyName, value);

            RaisePropertyChangedEvent(property);

            // Dependent properties?
            if (_propertyDependencies.ContainsKey(propertyName))
            {
                foreach (var dependentProperty in _propertyDependencies[propertyName])
                {
                    RaisePropertyChangedEvent(dependentProperty);
                }
            }

            // Dependent commands
            if (_commandDependencies.ContainsKey(propertyName))
            {
                foreach (var dependentCommand in _commandDependencies[propertyName])
                {
                    RaiseCommandStateChangedEvent(dependentCommand);
                }
            }

            return(true);
        }
コード例 #10
0
 public void TestGetPropertyName()
 {
     Assert.AreEqual("StaticString", PropertyNameHelper.GetPropertyName(() => TestClass.StaticString));
     Assert.AreEqual("InstanceString", PropertyNameHelper.GetPropertyName((TestClass t) => t.InstanceString));
 }
コード例 #11
0
 protected void OnPropertyChanged <TModel>(Expression <Func <TModel, Object> > propertyExpression)
 {
     OnPropertyChanged(PropertyNameHelper.GetPropertyName(propertyExpression));
 }
コード例 #12
0
 /// <summary>
 /// Calls the notify property changed event if it is attached. By using some
 /// Expression/Func magic we get compile time type checking on our property
 /// names by using this method instead of calling the event with a string in code.
 /// </summary>
 /// <param name="property">Property.</param>
 protected string GetPropertyName(Expression <Func <TViewModel, object> > property)
 {
     return(PropertyNameHelper.GetPropertyName <TViewModel> (property));
 }
コード例 #13
0
 /// <summary>
 /// Calls the notify property changed event if it is attached. By using some
 /// Expression/Func magic we get compile time type checking on our property
 /// names by using this method instead of calling the event with a string in code.
 /// </summary>
 /// <param name="property">Property.</param>
 protected string GetPropertyName <TOwner>(Expression <Func <TOwner, object> > property)
 {
     return(PropertyNameHelper.GetPropertyName <TOwner> (property));
 }
コード例 #14
0
        /// <summary>
        /// Adds the raise notify changed for property when value is the same.
        /// </summary>
        /// <param name="property">Property.</param>
        /// <param name="dependantProperty">Dependant property.</param>
        /// <typeparam name="TViewModel">The 1st type parameter.</typeparam>
        protected void AddRaiseNotifyChangedForPropertyWhenValueIsTheSame <TViewModel>(Expression <Func <object> > property)
        {
            var propertyName = PropertyNameHelper.GetPropertyName <TViewModel>(property);

            _notifyChangeForSameValues.Add(propertyName);
        }
コード例 #15
0
        /// Returns a value from the viewmodel storage
        /// </summary>
        /// <returns>The value.</returns>
        /// <param name="name">Name.</param>
        /// <typeparam name="TValueType">The 1st type parameter.</typeparam>
        protected TValueType GetValue <TValueType>(Expression <Func <object> > property, TValueType defaultValue)
        {
            var propertyName = PropertyNameHelper.GetPropertyName <BaseViewModel> (property);

            return(_viewModelStorage.GetObjectForKey <TValueType> (propertyName, defaultValue));
        }