Exemple #1
0
        public static List <Download> GetDownloads(MyDownloadTask t)
        {
            List <Download> d = new List <Download>();

            using (Helper db = new Helper())
            {
                d = db.DownloadTasks
                    .Include(b => b.Link.Download)
                    .SingleOrDefault(a => a.Id == t.DownloadTaskId)
                    .Link
                    .Download
                    .ToList();
            }
            return(d);
        }
Exemple #2
0
        // Operation : Remove DownloadTasks(Id) from List<MyDownloadTask>
        public static List <MyDownloadTask> RemoveTasks(MyDownloadTask t)
        {
            List <MyDownloadTask> returnValue;

            using (Helper db = new Helper())
            {
                var  records        = db.DownloadTasks.Include(b => b.Link).Include(c => c.Exchange).SingleOrDefault(a => a.Id == t.DownloadTaskId);
                int  count          = records != null ? 1 : 0;
                bool isExistingTask = (count > 0) ? true : false;
                if (isExistingTask)
                {
                    db.Links.Remove(records.Link);
                    db.DownloadTasks.Remove(records);
                    db.SaveChanges();
                }
                returnValue = GetTaskList();
            }
            return(returnValue);
        }
Exemple #3
0
        // Operation : Add MyDownloadTask to List<MyDownloadTask>.
        public static List <MyDownloadTask> AddOrUpdateTasks(MyDownloadTask t)
        {
            List <MyDownloadTask> returnValue = new List <MyDownloadTask>();

            using (Helper db = new Helper())
            {
                var records = db.DownloadTasks
                              .Include(b => b.Link)
                              .Include(c => c.Exchange)
                              .SingleOrDefault(a => a.Id == t.DownloadTaskId);
                int  count          = records != null ? 1 : 0;
                bool isExistingTask = (count > 0) ? true : false;

                if (isExistingTask)
                {
                    //Id
                    records.Name                   = t.TaskName;
                    records.Link.Name              = $"{t.TaskName} Link";
                    records.Link.SourceURL         = t.SourceUrl;
                    records.Link.FormattedURL      = t.UrlFormat;
                    records.Link.Destination       = t.DownloadLocation;
                    records.Link.DestinationFormat = t.DestinationFileFormat;
                    db.SaveChanges();
                }
                else
                {
                    //Add a new record with this TaskName.
                    Link l = new Link
                    {
                        Name              = $"{t.TaskName} Link",
                        SourceURL         = t.SourceUrl,
                        FormattedURL      = t.UrlFormat,
                        Destination       = t.DownloadLocation,
                        DestinationFormat = t.DestinationFileFormat
                    };
                    db.Links.Add(l);

                    Download download = new Download {
                        At = DateTime.Today, LinkId = l.Id, Progress = 0, Status = "Pending", SourceLink = URLParser.getThisDownloadsUrl(t.UrlFormat, DateTime.Today)
                    };
                    db.Downloads.Add(download);

                    Exchange exchange = new Exchange();
                    if (l.SourceURL.ToLower().Contains("nseindia"))
                    {
                        exchange = db.Exchanges.SingleOrDefault(x => x.Name == "NSE");
                    }
                    else if (l.SourceURL.ToLower().Contains("bseindia"))
                    {
                        exchange = db.Exchanges.SingleOrDefault(x => x.Name == "BSE");
                    }
                    else
                    {
                        Uri j = new Uri(l.SourceURL);
                        exchange = new Exchange {
                            Name = j.Host
                        };
                        db.Exchanges.Add(exchange);
                        db.SaveChanges();
                    }
                    db.SaveChanges();
                    DownloadTask dt = new DownloadTask
                    {
                        Name       = t.TaskName,
                        LinkId     = l.Id,
                        ExchangeId = exchange.Id
                    };
                    db.DownloadTasks.Add(dt);
                    db.SaveChanges();
                }
                returnValue = GetTaskList();
            }
            return(returnValue);
        }