Exemplo n.º 1
0
        private async void ProcessDownloadsAsync()
        {
            if (this.CanAccept)
            {
                Interlocked.Increment(ref this.CurrentThreadCount);

                try
                {
                    DownloadTask task = null;
                    // lock(_locker)
                    //   {
                    if (this.Queue.Count > 0)
                    {
                        task = this.Queue.Dequeue();
                    }
                    // }
                    if (task != null)
                    {
                        var routeid = Data.IDGenerator.Generate(task.RelativeUrl, ConstObjectType.Route);
                        if (this.SiteDb != null)
                        {
                            var route = this.SiteDb.Routes.Get(routeid);

                            if (route == null || route.objectId == default(Guid))
                            {
                                var exec = GetExecutor(task.ConstType);
                                if (exec != null)
                                {
                                    exec.DownloadTask = task;
                                    await exec.Execute().ConfigureAwait(false);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    var error = ex.Message;
                }

                Interlocked.Decrement(ref this.CurrentThreadCount);

                if (this.EnableDownload)
                {
                    StartNewDownload();
                }
            }
        }
Exemplo n.º 2
0
        public void AddTask(DownloadTask task)
        {
            // lock (_locker)
            //  {
            Guid absId = Lib.Security.Hash.ComputeGuidIgnoreCase(task.AbsoluteUrl);

            if (this.AddedAbsUrl.Contains(absId))
            {
                return;
            }
            else
            {
                this.AddedAbsUrl.Add(absId);
            }

            this.Queue.Enqueue(task);
            /// }

            if (this.EnableDownload)
            {
                StartNewDownload();
            }
        }