Ejemplo n.º 1
0
        public void Debug(string content, [CallerFilePath] string callerName = "",
                          [CallerMemberName] string memberName = "")
        {
            var logStatement =
                $"{DateTime.UtcNow:O}[DEBUG]{Path.GetFileNameWithoutExtension(callerName)}.{memberName}|{content}\n";

            queueProcessor.Add(logStatement);
        }
Ejemplo n.º 2
0
        private void Listen()
        {
            log.Debug($"Listening to HTTP endpoint - {config.ExposedHttpUrl}");

            while (!CancellationTokenSource.Token.WaitHandle.WaitOne(1))
            {
                HttpListenerContext receivedContent;

                try
                {
                    receivedContent = httpListener.GetContext();
                }
                catch (HttpListenerException e)
                {
                    if (e.ErrorCode != 995)
                    {
                        throw;
                    }

                    log.Info(
                        $"Catching HttpListenerException, ErrorCode: {e.ErrorCode}, Message: {e.Message}");

                    continue;
                }

                requestQueue.Add(receivedContent);
            }
        }
Ejemplo n.º 3
0
        internal void Enqueue(object obj)
        {
            if (obj == null)
            {
                return;
            }
            var items = (obj as ObservableCollection <object>).Cast <DownloaderObjectModel>().ToList();

            foreach (var item in items)
            {
                item.Enqueue();
                QueueProcessor.Add(item);
            }
        }
Ejemplo n.º 4
0
        private void Redownload(object obj)
        {
            var items        = (obj as ObservableCollection <object>).Cast <DownloaderObjectModel>().ToArray();
            var tasks        = new List <Task>();
            var forceEnqueue = false;
            var total        = items.Count();

            if (total > Settings.Default.MaxParallelDownloads)
            {
                forceEnqueue = true;
            }

            foreach (var item in items)
            {
                if (File.Exists(item.Destination))
                {
                    try
                    {
                        File.Delete(item.Destination);
                    }
                    catch (IOException)
                    {
                        continue;
                    }
                }
                if (forceEnqueue)
                {
                    item.Enqueue();
                    QueueProcessor.Add(item);
                }
                else
                {
                    item.Dequeue();
                    QueueProcessor.Remove(item);
                    tasks.Add(item.StartAsync());
                }
            }

            if (forceEnqueue)
            {
                Task.Run(async() => await QueueProcessor.StartAsync());
            }
            else
            {
                Task.Run(async() => await Task.WhenAll(tasks.ToArray()));
            }
        }
Ejemplo n.º 5
0
        internal void Start(object obj)
        {
            var items        = (obj as ObservableCollection <object>).Cast <DownloaderObjectModel>().ToArray();
            var tasks        = new List <Task>();
            var forceEnqueue = false;
            var total        = items.Count();

            if (total > Settings.Default.MaxParallelDownloads)
            {
                forceEnqueue = true;
            }

            foreach (var item in items)
            {
                if (item.IsBeingDownloaded)
                {
                    continue;
                }
                if (forceEnqueue)
                {
                    item.Enqueue();
                    QueueProcessor.Add(item);
                }
                else
                {
                    item.Dequeue();
                    QueueProcessor.Remove(item);
                    tasks.Add(item.StartAsync());
                }
            }

            if (forceEnqueue)
            {
                Task.Run(async() => await QueueProcessor.StartAsync());
            }
            else
            {
                Task.Run(async() => await Task.WhenAll(tasks.ToArray()));
            }
        }