Ejemplo n.º 1
0
        public void Index()
        {
            var fls = new List <FileLink>();

            using (var ae = new A51())
            {
                fls = ae.FileLinks.ToList();
            }
            Parallel.ForEach(fls, new ParallelOptions {
                MaxDegreeOfParallelism = 10
            }, (fl =>
            {
                if (string.IsNullOrWhiteSpace(fl?.UrlsJson) == false)
                {
                    var urls = JsonConvert.DeserializeObject <List <string> >(fl.UrlsJson);
                    using (var ae = new A51())
                    {
                        urls.ForEach(u =>
                        {
                            var f = new FileLoader
                            {
                                Url = u,
                                UpdateOn = DateTimeOffset.Now
                            };
                            var exist = ae.FileLoaders.FirstOrDefault(a => a.Url == u);
                            f.Id = exist?.Id ?? Guid.NewGuid();
                            ae.FileLoaders.AddOrUpdate(f);
                            ae.SaveChanges();
                        });
                    }
                }
            }));
        }
Ejemplo n.º 2
0
        public void Downloads()
        {
            var fls = new List <FileLoader>();

            using (var ae = new A51())
            {
                fls = ae.FileLoaders.ToList();
            }
            //Parallel.ForEach(fls, new ParallelOptions { MaxDegreeOfParallelism = 10 }, (fl =>
            fls.ForEach(fl =>
            {
                var url = $"http://nothing.new{fl.Url}";
                Download(url);
            }
                        );
            //));
        }
Ejemplo n.º 3
0
        public static FileLink GetFileLink(string url)
        {
            var urls = GetMediaUrls(url);

            if (urls == null || urls.Count == 0)
            {
                return(null);
            }
            var fl = new FileLink
            {
                BaseUrl  = url,
                UpdateOn = DateTimeOffset.Now,
                UrlsJson = JsonConvert.SerializeObject(urls)
            };

            using (var ae = new A51())
            {
                var exist = ae.FileLinks.FirstOrDefault(a => a.BaseUrl == fl.BaseUrl);
                fl.Id = exist?.Id ?? Guid.NewGuid();
                ae.FileLinks.AddOrUpdate(fl);
                ae.SaveChanges();
            }
            return(fl);
        }