public void Add(ParameterDescriptor parameterDescriptor, string value, IWatchable watchable)
 {
     lock (_itemsLock)
     {
         _items.Add(new Tuple<ParameterDescriptor, string, IWatchable>(parameterDescriptor, value, watchable));
     }
 }
Пример #2
0
 public void Add(ParameterDescriptor parameterDescriptor, string value, IWatchable watchable)
 {
     lock (_itemsLock)
     {
         _items.Add(new Tuple <ParameterDescriptor, string, IWatchable>(parameterDescriptor, value, watchable));
     }
 }
Пример #3
0
        /// <summary>
        /// Binds the specified collection of attributes.
        /// </summary>
        /// <typeparam name="TValue">The type to bind to.</typeparam>
        /// <param name="attributes">The collection of attributes to bind. The first attribute in the
        /// collection should be the primary attribute.</param>
        /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
        /// <returns></returns>
        public virtual async Task <TValue> BindAsync <TValue>(Attribute[] attributes, CancellationToken cancellationToken = default(CancellationToken))
        {
            var attribute            = attributes.First();
            var additionalAttributes = attributes.Skip(1).ToArray();

            IBinding binding = await _bindingSource.BindAsync <TValue>(attribute, additionalAttributes, cancellationToken);

            if (binding == null)
            {
                throw new InvalidOperationException("No binding found for attribute '" + attribute.GetType() + "'.");
            }

            // Create a clone of the binding context, so any binding data that was added
            // will be applied to the binding
            var ambientBindingContext = new AmbientBindingContext(_bindingSource.AmbientBindingContext.FunctionContext, _bindingData);
            var bindingContext        = new BindingContext(ambientBindingContext, cancellationToken);

            IValueProvider provider = await binding.BindAsync(bindingContext);

            if (provider == null)
            {
                return(default(TValue));
            }

            Debug.Assert(provider.Type == typeof(TValue));

            ParameterDescriptor parameterDesciptor = binding.ToParameterDescriptor();

            parameterDesciptor.Name = null; // Remove the dummy name "?" used for runtime binding.

            // Add even if watchable is null to show parameter descriptor in status.
            string     value     = provider.ToInvokeString();
            IWatchable watchable = provider as IWatchable;

            _watcher.Add(parameterDesciptor, value, watchable);

            IValueBinder binder = provider as IValueBinder;

            if (binder != null)
            {
                _binders.Add(binder);
            }

            IDisposable disposableProvider = provider as IDisposable;

            if (disposableProvider != null)
            {
                _disposable.Add(disposableProvider);
            }

            object result = await provider.GetValueAsync();

            return((TValue)result);
        }
Пример #4
0
 //ローカル視聴履歴に指定したIWatchableが存在したらフラグを立てる
 public static void ApplyLocalHistory(IWatchable target)
 {
     foreach (var entry in App.ViewModelRoot.History.LocalHistoryList)
     {
         if (target.ContentUrl.Contains(entry.Item.VideoId))
         {
             target.IsWatched = true;
             return;
         }
     }
 }
Пример #5
0
        public ParameterLog GetStatus()
        {
            lock (_itemsLock)
            {
                if (_items.Count == 0)
                {
                    return(null);
                }

                List <BinderParameterLogItem> logItems = new List <BinderParameterLogItem>();

                foreach (Tuple <ParameterDescriptor, string, IWatchable> item in _items)
                {
                    ParameterDescriptor parameterDescriptor = item.Item1;
                    string     value     = item.Item2;
                    IWatchable watchable = item.Item3;
                    IWatcher   watcher;

                    if (watchable != null)
                    {
                        watcher = watchable.Watcher;
                    }
                    else
                    {
                        watcher = null;
                    }

                    ParameterLog itemStatus;

                    if (watcher != null)
                    {
                        itemStatus = watcher.GetStatus();
                    }
                    else
                    {
                        itemStatus = null;
                    }

                    BinderParameterLogItem logItem = new BinderParameterLogItem
                    {
                        Descriptor = parameterDescriptor,
                        Value      = value,
                        Log        = itemStatus
                    };
                    logItems.Add(logItem);
                }

                return(new BinderParameterLog {
                    Items = logItems
                });
            }
        }
        private static IReadOnlyDictionary <string, IWatcher> CreateParameterWatchers(IReadOnlyDictionary <string, IValueProvider> parameters)
        {
            Dictionary <string, IWatcher> watches = new Dictionary <string, IWatcher>();

            foreach (KeyValuePair <string, IValueProvider> item in parameters)
            {
                IWatchable watchable = item.Value as IWatchable;
                if (watchable != null)
                {
                    watches.Add(item.Key, watchable.Watcher);
                }
            }

            return(watches);
        }
Пример #7
0
        public async Task <TValue> BindAsync <TValue>(Attribute attribute, CancellationToken cancellationToken)
        {
            IBinding binding = await _bindingSource.BindAsync <TValue>(attribute, cancellationToken);

            if (binding == null)
            {
                throw new InvalidOperationException("No binding found for attribute '" + attribute.GetType() + "'.");
            }

            IValueProvider provider = await binding.BindAsync(new BindingContext(
                                                                  _bindingSource.AmbientBindingContext, cancellationToken));

            if (provider == null)
            {
                return(default(TValue));
            }

            Debug.Assert(provider.Type == typeof(TValue));

            ParameterDescriptor parameterDesciptor = binding.ToParameterDescriptor();

            parameterDesciptor.Name = null; // Remove the dummy name "?" used for runtime binding.

            string value = provider.ToInvokeString();

            IWatchable watchable = provider as IWatchable;

            // Add even if watchable is null to show parameter descriptor in status.
            _watcher.Add(parameterDesciptor, value, watchable);

            IValueBinder binder = provider as IValueBinder;

            if (binder != null)
            {
                _binders.Add(binder);
            }

            IDisposable disposableProvider = provider as IDisposable;

            if (disposableProvider != null)
            {
                _disposable.Add(disposableProvider);
            }

            return((TValue)provider.GetValue());
        }
Пример #8
0
 public static IWatcher <TKey> For <TKey>(IWatchable <TKey> target)
 {
     return(new Watcher <IWatchable <TKey>, TKey>(target));
 }
Пример #9
0
 public void UnregisterWatchable(IWatchable watchable)
 {
     throw new NotImplementedException();
 }
Пример #10
0
 public void RegisterTweakable(IWatchable watchable)
 {
     throw new NotImplementedException();
 }
 public WatchableTileController(IHexGridController console, TileView view, HexGridCell <BaseNode> cell)
     : base(console, view, cell)
 {
     watchable = base.Node.Watchable;
 }
Пример #12
0
 public WatchableNode(IWatchable watchable)
     : base(watchable.Name)
 {
     Watchable = watchable;
 }