コード例 #1
0
 /// <summary>
 /// Load objects tree
 /// </summary>
 /// <param name="onLoadedAction">Complete loading objects</param>
 /// <param name="typesFilter"> Objects type filter</param>
 /// <param name="ids">Id or Ids objects</param>
 public void Load(Action <IList <IDataObject> > onLoadedAction, Func <IType, bool> typesFilter, params Guid[] ids)
 {
     _ids            = ids;
     _typesFilter    = typesFilter;
     _onLoadedAction = onLoadedAction;
     _subscriptions.Add(_repository.SubscribeObjects(ids).Subscribe(this));
 }
コード例 #2
0
 private void StartLoad()
 {
     _toLoad.Add(_sourceId);
     _repository.SubscribeObjects(new List <Guid> {
         _sourceId
     }).Subscribe(this);
 }
コード例 #3
0
 public void Load(Action <IList <IDataObject> > onLoadedAction, params Guid[] ids)
 {
     _objects        = new List <IDataObject>();
     _ids            = ids;
     _onLoadedAction = onLoadedAction;
     _subscription   = _repository.SubscribeObjects(ids).Subscribe(this);
 }
コード例 #4
0
 public void Load(ICollection <Guid> ids, Action <List <IDataObject> > onLoadedAction)
 {
     _onLoadedAction = onLoadedAction;
     _count          = ids.Count();
     _list           = new List <IDataObject>();
     _subscription   = _repository.SubscribeObjects(ids).Subscribe(this);
     _subscription.Dispose();
 }
コード例 #5
0
        public void Load(IEnumerable <Guid> ids)
        {
            var disposable = _repository.SubscribeObjects(ids)
                             .Where(x => x.State == DataState.Loaded)
                             .SubscribeOnDispatcher(DispatcherPriority.Background)
                             .Subscribe(o =>
            {
                var dataObject = new DataObject(o.Id, o.ParentId, o.DisplayName, o.Type.SvgIcon, o.Type.Sort, o.Children);
                _dataObjects.AddOrUpdate(dataObject);
            });

            _cleanUp.Add(disposable);
        }
コード例 #6
0
        public void Load(Guid id, Action nothingLoaded, bool isAddParent)
        {
            var disposable = _repository.SubscribeObjects(new [] { id })
                             .Where(x => _childrenFilter.Filter(x))
                             .SubscribeOnDispatcher(DispatcherPriority.Background)
                             .Subscribe(o =>
            {
                var children = _childrenFilter.ChildrenFilter(o).ToList();
                if (children.Count == 0)
                {
                    nothingLoaded();
                    return;
                }
                if (isAddParent)
                {
                    _dataObjects.AddOrUpdate(o);
                }

                Load(children);
            });

            _cleanUp.Add(disposable);
        }
コード例 #7
0
        /// <summary>
        /// Returns objects by identifiers as an asynchronous operation
        /// </summary>
        /// <typeparam name="T">Type of extension-side IDataObject projection</typeparam>
        /// <param name="ids">Object identifiers to be loaded</param>
        /// <param name="converter">Сonverts IDataObject to the extension-side projection.
        /// IDataObject belongs to the application AppDomain and can be used for 2 minutes only after being created,
        /// so it should be converted to the extension-side projection immedeately after being received.</param>
        /// <param name="ct">CancellationToken to cancel objects loading. The OperationCanceledException will be thrown.</param>
        /// <returns>The task object representing the asynchronous operation</returns>
        public Task <IEnumerable <T> > GetObjectsAsync <T>(IEnumerable <Guid> ids, Func <IDataObject, T> converter, CancellationToken ct)
        {
            // Creates an observable that fires notification when cancelling CancellationToken
            var cancel = Observable.Create <T>(o => ct.Register(o.OnCompleted));

            var loading        = ids.ToList();
            var observableList = _repository
                                 .SubscribeObjects(loading)               // Subscribing on interested objects
                                 .TakeUntil(cancel)                       // Stopping subscription on cancel
                                 .Where(o => o.State == DataState.Loaded) // Filtering "NoData" notifications
                                 .Distinct(o => o.Id)                     // Filtering already emitted notifications
                                 .Select(converter)                       // Converting IDataObject to extension-side projection
                                 .Take(loading.Count)                     // Wait for all objects to be loaded
                                 .ToList();

            return(Task <IEnumerable <T> > .Factory.StartNew(() =>
            {
                var lazy = observableList.Wait();
                // Forces the "lazy" enumerable to be immedeately iterated in background thread
                return lazy.ToList();
            }, ct));
        }
コード例 #8
0
 public void Load(Guid id, Action <IDataObject> onLoadedAction)
 {
     _loaded         = false;
     _onLoadedAction = onLoadedAction;
     _subscription   = _repository.SubscribeObjects(new[] { id }).Subscribe(this);
 }