public void Download(int id) { using (IDownloadItemRepository repository = createRepository()) { var item = repository.Get(id); item.Status = DownloadStatus.Delegated; repository.SaveChanges(); } eventBus.Notify(this, EventBusToken.DownloadedDelegated); ThreadPool.QueueUserWorkItem(ProcessQueueItem, id); }
private async void ProcessQueueItem(object status) { var id = (int)status; string address; using (IDownloadItemRepository repository = createRepository()) { var item = repository.Get(id); item.Status = DownloadStatus.Downloading; address = item.Address; repository.SaveChanges(); } eventBus.Notify(this, EventBusToken.DownloadBegin); try { string value = await DownloadFile(address); using (IDownloadItemRepository repository = createRepository()) { var item = repository.Get(id); item.Html = value; item.Status = DownloadStatus.Downloaded; repository.SaveChanges(); } eventBus.Notify(this, EventBusToken.DownloadComplete); } catch (Exception e) { using (IDownloadItemRepository repository = createRepository()) { var item = repository.Get(id); item.Status = DownloadStatus.Errored; repository.SaveChanges(); } eventBus.Notify(this, EventBusToken.DownloadErrored); } }
public void Download(int id) { string address; using (IDownloadItemRepository repository = createRepository()) { var item = repository.Get(id); item.Status = DownloadStatus.Downloading; address = item.Address; repository.SaveChanges(); } eventBus.Notify(this, EventBusToken.DownloadBegin); string value; if (DownloadFile(address, out value)) { using (IDownloadItemRepository repository = createRepository()) { var item = repository.Get(id); item.Html = value; item.Status = DownloadStatus.Downloaded; repository.SaveChanges(); } eventBus.Notify(this, EventBusToken.DownloadComplete); } else { using (IDownloadItemRepository repository = createRepository()) { var item = repository.Get(id); item.Status = DownloadStatus.Errored; repository.SaveChanges(); } eventBus.Notify(this, EventBusToken.DownloadErrored); } }