public static IObservable <TValue> BindToView <TView, TViewProp, TTarget, TValue>(IObservable <TValue> valueChange, TTarget target, Expression <Func <TView, TViewProp> > viewProperty)
        {
            var viewExpression = global::ReactiveUI.Reflection.Rewrite(viewProperty.Body);

            var setter = global::ReactiveUI.Reflection.GetValueSetterOrThrow(viewExpression.GetMemberInfo());

            if (viewExpression.GetParent().NodeType == ExpressionType.Parameter)
            {
                return(valueChange.Do(
                           x => setter(target, x, viewExpression.GetArgumentsArray()),
                           ex =>
                {
                    RxLog.Log(typeof(ValidationBinding), Classified.Error(ex));
                    //todo: this.Log().ErrorException(String.Format("{0} Binding received an Exception!", viewExpression), ex);
                }));
            }

            var bindInfo = valueChange.CombineLatest(target.WhenAnyDynamic(viewExpression.GetParent(), x => x.Value),
                                                     (val, host) => new { val, host });

            return(bindInfo
                   .Where(x => x.host != null)
                   .Do(
                       x => setter(x.host, x.val, viewExpression.GetArgumentsArray()),
                       ex =>
            {
                RxLog.Log(typeof(ValidationBinding), Classified.Error(ex));
                //todo: this.Log().ErrorException(String.Format("{0} Binding received an Exception!", viewExpression), ex);
            })
                   .Select(v => v.val));
        }
        public static IDisposable BindToDirect <TTarget, TValue>(IObservable <TValue> This, TTarget target, Expression viewExpression)
        {
            var setter = global::ReactiveUI.Reflection.GetValueSetterOrThrow(viewExpression.GetMemberInfo());

            if (viewExpression.GetParent().NodeType == ExpressionType.Parameter)
            {
                return(This.Subscribe(
                           x => setter(target, x, viewExpression.GetArgumentsArray()),
                           ex =>
                {
                    RxLog.Log(typeof(IViewForValidateableMixins), Classified.Error(ex));
                    //TODO:this.Log().ErrorException(String.Format("{0} Binding received an Exception!", viewExpression), ex);
                }));
            }

            var bindInfo = Observable.CombineLatest(
                This, target.WhenAnyDynamic(viewExpression.GetParent(), x => x.Value),
                (val, host) => new { val, host });

            return(bindInfo
                   .Where(x => x.host != null)
                   .Subscribe(
                       x => setter(x.host, x.val, viewExpression.GetArgumentsArray()),
                       ex => {
                RxLog.Log(typeof(IViewForValidateableMixins), Classified.Error(ex));
                //TODO:this.Log().ErrorException(String.Format("{0} Binding received an Exception!", viewExpression), ex);
            }));
        }
 public void ErrorMessagesTest()
 {
     CreateForMessage((s) => Classified.Error(), LogLevel.Error, String.Empty);
     CreateForMessage(Classified.Error, LogLevel.Error, testMessage);
     CreateForMessageWithParams(Classified.Error, LogLevel.Error, formattedMessage, testParam);
     CreateForException(Classified.Error, LogLevel.Error, exception);
     CreateForExceptionWithAdditional(Classified.Error, LogLevel.Error, exception, testMessage);
 }
Esempio n. 4
0
 /// <summary>
 /// Set the default <see cref="RxLog"/> implementation.
 /// </summary>
 /// <param name="rxLog"></param>
 public static void SetDefault(RxLog rxLog)
 {
     if (RxLog.Default != null)
     {
         RxLog.Log(typeof(RxLog), Classified.Error("RxLog already has a default host assigned, request ignored."));
         return;
     }
     RxLog.Default = rxLog;
 }
        /// <summary>
        /// Updates an existing <see cref="KeyedReactiveList{TItem,TKey}"/> smartly with a new set of items.
        /// </summary>
        /// <typeparam name="TItem"></typeparam>
        /// <typeparam name="TKey"></typeparam>
        /// <param name="destination"></param>
        /// <param name="source"></param>
        /// <remarks>
        /// Instead of a block replacement occuring, the <see cref="TKey"/> is used to determine
        /// items which have either been removed, moved or added and the destination list is updated in this once.</remarks>
        public static void SmartUpdate <TItem, TKey>(this KeyedReactiveList <TItem, TKey> destination,
                                                     IReadOnlyList <TItem> source)
        {
            var index = 0;

            Guard.NotNull(destination);
            Guard.NotNull(source);

            try
            {
                //
                // construct the final set of keys
                var finalKeys = source.ToLookup(destination.KeyFor);

                // get the list of removals
                var removals = destination.Where(d => !finalKeys.Contains(destination.KeyFor(d))).ToList();

                foreach (var removal in removals)
                {
                    destination.Remove(removal);
                }

                // so now, we are just into additions and updates
                foreach (var newItem in source)
                {
                    TItem currentItem;

                    if (destination.GetForKey(destination.KeyFor(newItem), out currentItem))
                    {
                        var currentIndex = destination.IndexOf(currentItem);

                        if (currentIndex != index)
                        {
                            destination.Move(currentIndex, index);
                        }
                        else
                        {
                            destination[currentIndex] = newItem;
                        }
                    }
                    else
                    {
                        destination.Insert(index, newItem);
                    }
                    ++index;
                }
            }
            catch (Exception ex)
            {
                // log the exception, and re-throw
                RxLog.Log(destination, Classified.Error(ex));
                throw;
            }
        }