Esempio n. 1
0
        public static IManagedDownloaderToken AsManaged(this IDownloader @this, string managerName = DefaultManagerName)
        {
            Guards.ThrowIfNull(@this);
            Guards.ThrowIfNullOrEmpty(managerName);

            if (@this.Context == null)
            {
                throw new InvalidOperationException();
            }

            var id = @this.Context.Id;

            if (!ManagedDownloaderTokens.ContainsKey(id))
            {
                ManagedDownloaderTokens[id] = new ManagedDownloaderTokenImpl(GetFileDownloaderManager(managerName), @this);
            }

            return(ManagedDownloaderTokens[id]);
        }
Esempio n. 2
0
        public static Func <TInput, Task <IEnumerable <T> > > ThenAsync <TInput, TOutput, T>(
            this Func <TInput, Task <IEnumerable <TOutput> > > @this,
            Func <TOutput, T> function,
            CancellationToken cancellationToken = default)
        {
            Guards.ThrowIfNull(function);

            return(async input =>
            {
                cancellationToken.ThrowIfCancellationRequested();
                var output = await @this(input);

                return output.Select(item =>
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    return function(item);
                });
            });
        }
Esempio n. 3
0
        public static Func <TInput, Task <IEnumerable <T> > > ThenAsync <TInput, TOutput, T>(
            this Func <TInput, Task <IEnumerable <TOutput> > > @this,
            Func <TOutput, Task <T> > function,
            CancellationToken cancellationToken = default)
        {
            Guards.ThrowIfNull(function);

            return(async input =>
            {
                cancellationToken.ThrowIfCancellationRequested();
                var output = await @this(input);

                var result = new List <T>();
                foreach (var item in output)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    result.Add(await function(item));
                }

                return result;
            });
        }
Esempio n. 4
0
        public static long GetTotalSize(this IDownloader @this)
        {
            Guards.ThrowIfNull(@this);

            return(@this.Context?.TotalSize ?? 0);
        }
Esempio n. 5
0
        public static long GetCompletedSize(this IDownloader @this)
        {
            Guards.ThrowIfNull(@this);

            return(@this.BlockContexts?.Values.Sum(item => item.CompletedSize) ?? 0);
        }
        public ViewModelResolver(Func<IContainerProvider> containerFactory)
        {
            Guards.ThrowIfNull(containerFactory);

            _containerFactory = containerFactory;
        }
        public static IViewModelResolver IfInheritsFrom<TViewModel>(this IViewModelResolver @this, Action<FrameworkElement, TViewModel, IContainerProvider> configuration)
        {
            Guards.ThrowIfNull(@this, configuration);

            return @this.IfInheritsFrom(configuration);
        }
            //.IfInheritsFrom<IAwareTabItemSelectionChanged>((view, viewModel) =>
            //{
            //    TabControlHelper.SetAwareSelectionChanged(view, true);
            //});

        public static IViewModelResolver IfInheritsFrom<TViewModel>(this IViewModelResolver @this, Action<FrameworkElement, TViewModel> configuration)
        {
            Guards.ThrowIfNull(@this, configuration);

            return @this.IfInheritsFrom<FrameworkElement, TViewModel>((view, viewModel, container) => configuration(view, viewModel));
        }
        public UpgradeService(Func <Task <List <UpgradeInfo> > > upgradeInfosGetter)
        {
            Guards.ThrowIfNull(upgradeInfosGetter);

            _upgradeInfosGetter = upgradeInfosGetter;
        }
 public DataTransmissionPanelViewModel(IContainerExtension container, IHouseSiteService houseSiteService) : base(container)
 {
     Guards.ThrowIfNull(container, houseSiteService);
     this.houseSiteService = houseSiteService;
 }
Esempio n. 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PropertyMapping{TSource, TDestination}"/> class.
        /// </summary>
        /// <param name="mappingDictionary">The mapping dictionary.</param>
        public PropertyMapping(Dictionary <string, PropertyMappingValue> mappingDictionary)
        {
            Guards.ThrowIfNull(mappingDictionary);

            MappingDictionary = mappingDictionary;
        }
        public static long GetTotalSize(this ITransferInfo <DownloadContext> @this)
        {
            Guards.ThrowIfNull(@this);

            return(@this.Context?.TotalSize ?? 0);
        }