Ejemplo n.º 1
0
        private void QueueScheduler()
        {
            lock (Downloads)
            {
                Downloads
                .Where(x => x.State == DownloadState.InQueue)
                .ToList()
                .ForEach(x => x.State = DownloadState.Scheduled);
            }

            while (StartTime > DateTime.Now)
            {
                Thread.Sleep(_scheduleCheckDelay);
            }

            lock (Downloads)
            {
                Downloads
                .Where(x => x.State == DownloadState.Scheduled)
                .ToList()
                .ForEach(x => x.State = DownloadState.InQueue);
            }

            Application.Current.Dispatcher.BeginInvoke((Action)UpdateQueueState);
        }
Ejemplo n.º 2
0
        private void ViewVideo(string id)
        {
            try
            {
                lock (_commandLockObject)
                {
                    if (!string.IsNullOrWhiteSpace(id))
                    {
                        TwitchVideoDownload download = Downloads.Where(d => d.Id == id).FirstOrDefault();

                        if (download != null)
                        {
                            string folder = download.DownloadParams.Folder;

                            if (Directory.Exists(folder))
                            {
                                Process.Start(folder);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _dialogService.ShowAndLogException(ex);
            }
        }
Ejemplo n.º 3
0
        public void RefreshDownloads()
        {
            var downloads = DownloadManager.GetDownloads();

            foreach (var download in downloads)
            {
                var existingDownload = Downloads.FirstOrDefault(d => d.Id == download.Id);

                if (existingDownload != null)
                {
                    existingDownload.UpdateValues(download);
                }
                else
                {
                    Downloads.Add(new DownloadViewModel(download));
                }
            }

            var nonExistantDownloads = new List <DownloadViewModel>();

            foreach (var nonExistantDownload in Downloads.Where(d => !downloads.Any(existinDownload => existinDownload.Id == d.Id)))
            {
                nonExistantDownloads.Add(nonExistantDownload);
            }

            foreach (var toRemove in nonExistantDownloads)
            {
                Downloads.Remove(toRemove);
            }
        }
Ejemplo n.º 4
0
 public void CancelRunningDownloads()
 {
     foreach (var download in Downloads.Where(d => !d.Completed))
     {
         try
         {
             download.Cancel(null);
         }
         catch (Exception ex)
         {
             _log.Error("Unable to cancel download.", ex);
         }
     }
 }
Ejemplo n.º 5
0
        public static void AddDownload(Download dl)
        {
            dl.DownloadStatusChanged += Dl_DownloadStatusChanged;
            Downloads.Add(dl);

            if (Downloads.Where(x => x.Status == DownloadStatus.Downloading).Count() < MaxParallelDownloads)
            {
                dl.Start();
                Trace.TraceInformation("Starting download '{0}'.", dl.Title);
            }
            else
            {
                Trace.TraceInformation("Putting '{0}' into queue.", dl.Title);
            }
        }
Ejemplo n.º 6
0
        private void ShowLog(string id)
        {
            try
            {
                lock (_commandLockObject)
                {
                    if (!string.IsNullOrWhiteSpace(id))
                    {
                        TwitchVideoDownload download = Downloads.Where(d => d.Id == id).FirstOrDefault();

                        if (download != null)
                        {
                            _navigationService.ShowLog(download);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _dialogService.ShowAndLogException(ex);
            }
        }
Ejemplo n.º 7
0
        private void UpdateQueueState()
        {
            lock (Downloads)
            {
                switch (Type)
                {
                case QueueType.Parallel:
                    var downloadsForStartup = Downloads.Where(x => x.State == DownloadState.InQueue);
                    foreach (var download in downloadsForStartup)
                    {
                        download.Start();
                    }

                    break;

                case QueueType.Sequence:
                    var firstDownload  = Downloads.FirstOrDefault(x => x.State == DownloadState.InProgress);
                    var downloadsInRun = Downloads
                                         .Where(x => x.State == DownloadState.InProgress)
                                         .ToList();
                    foreach (var download in downloadsInRun)
                    {
                        if (download != firstDownload)
                        {
                            download.Suspend();
                        }
                    }

                    if (firstDownload == null)
                    {
                        TakeSequanceItem();
                    }

                    break;
                }
            }
        }
Ejemplo n.º 8
0
 public void ClearCompletedDownloads()
 {
     Downloads.Where((x) => x.DownloadState == PackageDownloadHandle.State.Installed ||
                     x.DownloadState == PackageDownloadHandle.State.Error).ToList().ForEach(x => Downloads.Remove(x));
 }
Ejemplo n.º 9
0
 private void RemoveAllCompletedDownloads()
 {
     MainModel.Downloader.RemoveDownloads(Downloads.Where(downloadItem => IsCompleted(downloadItem.Status)).Select(downloadItem => downloadItem.Id));
 }
Ejemplo n.º 10
0
 private void StopAllDownloads()
 {
     MainModel.Downloader.StopDownloads(Downloads.Where(downloadItem => CanBeStopped(downloadItem.Status)).Select(downloadItem => downloadItem.Id));
 }
Ejemplo n.º 11
0
        public IEnumerable <Section> GetFileDownloadGroups()
        {
            var retVal = new List <Section>();

            var allEstabData = Downloads?.Where(x => new[] { "all.edubase.data", "all.edubase.data.links" }.Contains(x.Tag)) ?? Array.Empty <FileDownload>();
            var openAcademiesAndFreeSchoolsData = Downloads?.Where(x => new[] { "all.open.academies.and.free.schools", "all.open.academies.and.free.school.links" }.Contains(x.Tag)) ?? Array.Empty <FileDownload>();
            var openStateFundedSchoolsData      = Downloads?.Where(x => new[] { "all.open.state-funded.schools", "all.open.state-funded.school.links" }.Contains(x.Tag)) ?? Array.Empty <FileDownload>();
            var openChildrensCentresData        = Downloads?.Where(x => new[] { "all.open.childrens.centres", "all.open.childrens.centres.links" }.Contains(x.Tag)) ?? Array.Empty <FileDownload>();
            var allGroupData    = Downloads?.Where(x => new[] { "all.group.records", "all.group.links.records", "all.group.with.links.records", "academies.mat.membership" }.Contains(x.Tag)) ?? Array.Empty <FileDownload>();
            var openGroupData   = Downloads?.Where(x => new[] { "academy.sponsor.and.trust.links" }.Contains(x.Tag)) ?? Array.Empty <FileDownload>();
            var allGovernorData = Downloads?.Where(x => new[] { "all.governance.records", "all.mat.governance.records", "all.academy.governance.records", "all.la.maintained.governance.records" }.Contains(x.Tag)) ?? Array.Empty <FileDownload>();

            var miscData = Downloads?.Where(x => !(allEstabData).Concat(openAcademiesAndFreeSchoolsData)
                                            .Concat(openStateFundedSchoolsData)
                                            .Concat(openChildrensCentresData)
                                            .Concat(allGroupData)
                                            .Concat(openGroupData)
                                            .Concat(allGovernorData)
                                            .Select(y => y.Tag)
                                            .Contains(x.Tag)) ?? Array.Empty <FileDownload>();


            if (allEstabData.Any() || openAcademiesAndFreeSchoolsData.Any() || openStateFundedSchoolsData.Any() || openChildrensCentresData.Any())
            {
                var section = new Section {
                    Heading = "Establishment downloads", Paragraph = "You can download the complete record for the specified establishment types. There's a separate file with links to any predecessor or successor establishments."
                };

                if (allEstabData.Any())
                {
                    section.SubSections.Add(new Section
                    {
                        Heading = "All establishment data",
                        Files   = allEstabData.Select(x => new Tuple <string, FileDownload>(FileDownloadNames.ResourceManager.GetString(CleanTag(x.Tag)) ?? x.Name, x)).ToList()
                    });
                }

                if (openAcademiesAndFreeSchoolsData.Any())
                {
                    section.SubSections.Add(new Section
                    {
                        Heading = "Open academies and free schools data",
                        Files   = openAcademiesAndFreeSchoolsData.Select(x => new Tuple <string, FileDownload>(FileDownloadNames.ResourceManager.GetString(CleanTag(x.Tag)) ?? x.Name, x)).ToList()
                    });
                }

                if (openStateFundedSchoolsData.Any())
                {
                    section.SubSections.Add(new Section
                    {
                        Heading = "Open state-funded schools data",
                        Files   = openStateFundedSchoolsData.Select(x => new Tuple <string, FileDownload>(FileDownloadNames.ResourceManager.GetString(CleanTag(x.Tag)) ?? x.Name, x)).ToList()
                    });
                }

                if (openChildrensCentresData.Any())
                {
                    section.SubSections.Add(new Section
                    {
                        Heading = "Open children's centres data ",
                        Files   = openChildrensCentresData.Select(x => new Tuple <string, FileDownload>(FileDownloadNames.ResourceManager.GetString(CleanTag(x.Tag)) ?? x.Name, x)).ToList()
                    });
                }

                retVal.Add(section);
            }

            if (allGroupData.Any() || openGroupData.Any())
            {
                var section = new Section
                {
                    Heading   = "Establishment groups",
                    Paragraph = "You can download the complete record for the specified establishment group. There's a separate file with links to any establishments associated with the groups."
                };
                if (allGroupData.Any())
                {
                    section.SubSections.Add(new Section
                    {
                        Heading = "All group data",
                        Files   = allGroupData.Select(x =>
                                                      new Tuple <string, FileDownload>(
                                                          FileDownloadNames.ResourceManager.GetString(CleanTag(x.Tag)) ?? x.Name, x)).ToList()
                    });
                }

                if (openGroupData.Any())
                {
                    section.SubSections.Add(new Section
                    {
                        Heading = "Open group data",
                        Files   = openGroupData.Select(x =>
                                                       new Tuple <string, FileDownload>(
                                                           FileDownloadNames.ResourceManager.GetString(CleanTag(x.Tag)) ?? x.Name, x)).ToList()
                    });
                }

                retVal.Add(section);
            }

            if (allGovernorData.Any())
            {
                var section = new Section {
                    Heading = "Governors", Paragraph = "You can download the complete record for all governors listed within GIAS."
                };
                section.SubSections.Add(new Section
                {
                    Heading = "All governor data",
                    Files   = allGovernorData.Select(x => new Tuple <string, FileDownload>(FileDownloadNames.ResourceManager.GetString(CleanTag(x.Tag)) ?? x.Name, x)).ToList()
                });
                retVal.Add(section);
            }

            if (miscData.Any())
            {
                miscData.ForEach(x => x.AuthenticationRequired = true);

                var section = new Section {
                    Heading = "Miscellaneous", Paragraph = ""
                };
                section.SubSections.Add(new Section
                {
                    Heading = "All data",
                    Files   = miscData.Select(x => new Tuple <string, FileDownload>(FileDownloadNames.ResourceManager.GetString(CleanTag(x.Tag)) ?? x.Name, x)).ToList()
                });
                retVal.Add(section);
            }


            /*
             * tag=all.edubase.data
             * tag=all.edubase.data.links
             *
             * tag=all.open.academies.and.free.schools
             * tag=all.open.academies.and.free.school.links
             *
             * tag=all.open.state-funded.schools
             * tag=all.open.state-funded.school.links
             *
             * tag=academy.sponsor.and.trust.links
             * tag=all.open.childrens.centres
             * tag=all.governance.records
             * tag=all.mat.governance.records
             * tag=all.academy.governance.records
             * tag=all.la.maintained.governance.records
             *
             * --
             * tag=all.edubase.data
             * tag=all.edubase.data.links
             * tag=all.open.state-funded.schools
             * tag=all.open.state-funded.school.links
             * tag=all.open.academies.and.free.schools
             * tag=all.open.academies.and.free.school.links
             * tag=academy.sponsor.and.trust.links
             * tag=all.open.childrens.centres
             +tag=all.open.childrens.centres.links
             * tag=all.governance.records
             * tag=all.mat.governance.records
             * tag=all.academy.governance.records
             * tag=all.la.maintained.governance.records
             +tag=all.group.records
             +tag=all.group.links.records
             +tag=all.group.with.links.records
             */


            return(retVal);
        }
Ejemplo n.º 12
0
 public static List <Download> GetDownloadsWithStatus(DownloadStatus status)
 {
     return(Downloads.Where(x => x.Status == status).ToList());
 }
Ejemplo n.º 13
0
 private void StartAllDownloads()
 {
     MainModel.DownloadManager.StartDownloads(Downloads.Where(downloadItem => CanBeStarted(downloadItem.Status)).Select(downloadItem => downloadItem.Id));
 }
Ejemplo n.º 14
0
        public async void OnLoaded()
        {
            this.Downloads = new List <DownloadViewModel>();
            Downloads.Add(new DownloadViewModel("Basic")
            {
                FileName     = "BASIC",
                ChnName      = "基础系列",
                FullFileName = "BASIC.zip",
                Address      = string.Format("http://{0}/HSDecks/Home/Download?ImageName=BASIC.zip", HOST),
                Progress     = 0,
                Size         = 85,
                Mode         = "standard",
            });
            Downloads.Add(new DownloadViewModel("BRM")
            {
                FileName     = "BRM",
                ChnName      = "黑石山的火焰",
                FullFileName = "BRM.zip",
                Address      = string.Format("http://{0}/HSDecks/Home/Download?ImageName=BRM.zip", HOST),
                Progress     = 0,
                Size         = 5,
                Mode         = "standard",
            });
            Downloads.Add(new DownloadViewModel("GVG")
            {
                FileName     = "GVG",
                ChnName      = "地精大战侏儒",
                FullFileName = "GVG.zip",
                Address      = string.Format("http://{0}/HSDecks/Home/Download?ImageName=GVG.zip", HOST),
                Progress     = 0,
                Size         = 25,
                Mode         = "wild",
            });
            Downloads.Add(new DownloadViewModel("LOE")
            {
                FileName     = "LOE",
                ChnName      = "探险者协会",
                FullFileName = "LOE.zip",
                Address      = string.Format("http://{0}/HSDecks/Home/Download?ImageName=LOE.zip", HOST),
                Progress     = 0,
                Size         = 9,
                Mode         = "standard",
            });
            Downloads.Add(new DownloadViewModel("NAX")
            {
                FileName     = "NAX",
                ChnName      = "纳克萨玛斯",
                FullFileName = "NAX.zip",
                Address      = string.Format("http://{0}/HSDecks/Home/Download?ImageName=NAX.zip", HOST),
                Progress     = 0,
                Size         = 5,
                Mode         = "wild",
            });
            Downloads.Add(new DownloadViewModel("OG")
            {
                FileName     = "OG",
                ChnName      = "古神的低语",
                FullFileName = "OG.zip",
                Address      = string.Format("http://{0}/HSDecks/Home/Download?ImageName=OG.zip", HOST),
                Progress     = 0,
                Size         = 28,
                Mode         = "standard",
            });
            Downloads.Add(new DownloadViewModel("AT")
            {
                FileName     = "AT",
                ChnName      = "冠军的试炼",
                FullFileName = "AT.zip",
                Address      = string.Format("http://{0}/HSDecks/Home/Download?ImageName=AT.zip", HOST),
                Progress     = 0,
                Size         = 26,
                Mode         = "standard",
            });
            foreach (var set in Downloads)
            {
                var s = await ApplicationData.Current.LocalFolder.TryGetItemAsync(set.FullFileName);

                if (s != null)
                {
                    set.Complete();
                }
            }
            StandardSet = Downloads.Where(p => p.Mode == "standard").ToList();
            WildSet     = Downloads.Where(p => p.Mode == "wild").ToList();

            StandardSet.ForEach(p => p.PropertyChanged += this.NotifyStandardSetCount);
            WildSet.ForEach(p => p.PropertyChanged     += this.NotifyWildSetCount);
            Downloads.ForEach(p => p.PropertyChanged   += this.UpdateCardImage);

            await refreshPageAsync();
            await DeckInitializing();
        }