Exemplo n.º 1
0
        /// <summary>
        /// Setup a reoccurring data client which is bound to a source property of an object.
        /// The Start method must be called to begin the request.
        /// </summary>
        /// <param name="source"></param>
        public Request(object context, string propertyName)
        {
            if (context == null)
            {
                throw new ArgumentNullException("Context must not be null.");
            }

            if (!(context is INotifyPropertyChanged))
            {
                throw new ArgumentException("Context does not implement INotifyPropertyChanged.");
            }

            this.boundPropertyName = propertyName;
            this.context = context;
            this.source = GetSourceFromContext(context, propertyName);

            (context as INotifyPropertyChanged).PropertyChanged += context_PropertyChanged;

            if (source != null && source.Interval != TimeSpan.MaxValue)
            {
                this.timer = new DispatcherTimer();
                timer.Tick += timer_Tick;
                timer.Interval = source.Interval;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Setup a reoccurring data client.
        /// The Start method must be called to begin the request.
        /// </summary>
        /// <param name="source"></param>
        public Request(Source source)
        {
            if (source == null)
                throw new ArgumentNullException("Source");

            this.source = source;
            if (source.Interval != TimeSpan.MaxValue)
            {
                this.timer = new DispatcherTimer();
                timer.Tick += timer_Tick;
                timer.Interval = source.Interval;
            }
        }
Exemplo n.º 3
0
        private Source GetSourceFromContext(object context, string propertyName)
        {
            Source source = null;

            Type type = context.GetType();
            PropertyInfo property = type.GetProperty(this.boundPropertyName);

            source = property.GetValue(context, null) as Source;

            return source;
        }
Exemplo n.º 4
0
        private void context_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (this.boundPropertyName != string.Empty && e.PropertyName == this.boundPropertyName)
            {
                timer.Stop();

                this.source = GetSourceFromContext(this.context, this.boundPropertyName);
                if (this.source != null)
                {
                    timer.Interval = source.Interval;
                }

                timer.Start();
            }
        }