public void ShowDownloadDialog(DownloadParameters downloadParams, Action <bool, DownloadParameters> dialogCompleteCallback) { if (downloadParams == null) { throw new ArgumentNullException(nameof(downloadParams)); } if (dialogCompleteCallback == null) { throw new ArgumentNullException(nameof(dialogCompleteCallback)); } DownloadWindowVM vm = this.kernel.Get <DownloadWindowVM>(); vm.DownloadParams = downloadParams; DownloadWindow window = this.kernel.Get <DownloadWindow>(); window.DataContext = vm; bool?result = window.ShowDialog(); DownloadParameters resultObject = vm.ResultObject; dialogCompleteCallback(result != true, resultObject); }
private void PersistList(object state) { List <DownloadItem> downloadsToSave = new List <DownloadItem>(); using (DownloadManager.Instance.LockDownloadList(false)) { //IList<Downloader> downloads = DownloadManager.Instance.Downloads; //for (int i = 0; i < downloads.Count; i++) foreach (Downloader downloader in DownloadManager.Instance.OrderedDownloads) { //if (downloads[i].State == DownloaderState.Ended) if (downloader.State == DownloaderState.Ended) { continue; } //Downloader downloader = downloads[i]; DownloadItem di = new DownloadItem(); di.id = downloader.Id; di.LocalFile = downloader.LocalFile; di.rl = downloader.ResourceLocation; di.mirrors = downloader.Mirrors.ToArray(); di.remoteInfo = downloader.RemoteFileInfo; di.requestedSegments = downloader.RequestedSegments; di.createdDateTime = downloader.CreatedDateTime; di.extendedProperties = new SerializableDictionary <string, object>(downloader.ExtendedProperties); using (downloader.LockSegments()) { di.Segments = new SegmentItem[downloader.Segments.Count]; for (int j = 0; j < downloader.Segments.Count; j++) { SegmentItem si = new SegmentItem(); Segment seg = downloader.Segments[j]; si.Index = seg.Index; si.InitialStartPositon = seg.InitialStartPosition; si.StartPositon = seg.StartPosition; si.EndPosition = seg.EndPosition; di.Segments[j] = si; } } downloadsToSave.Add(di); } } DownloadParameters downloadParameters = new DownloadParameters(); downloadParameters.defaultDownloadDirectory = DownloadManager.Instance.DefaultDownloadDirectorySource; downloadParameters.lastDownloadId = DownloadManager.Instance.LastDownloadId; downloadParameters.downloadItems = downloadsToSave.ToArray(); //SaveObjects(downloadsToSave); SaveObjects(downloadParameters); }
/// <summary> /// Writes the specified entities to a local temporary file after download. /// </summary> /// <param name="downloadParameters"></param> /// <returns></returns> protected async Task <List <BulkEntity> > DownloadEntitiesAsync( DownloadParameters downloadParameters, Progress <BulkOperationProgressInfo> progress, CancellationToken cancellationToken) { // The system temp directory will be used if another working directory is not specified. If you are // using a cloud service such as Azure you'll want to ensure you do not exceed the file or directory limits. // You can specify a different working directory for each BulkServiceManager instance. BulkServiceManager.WorkingDirectory = FileDirectory; // The DownloadEntitiesAsync method returns IEnumerable<BulkEntity>, so the download file will not // be accessible e.g. for CleanupTempFiles until you iterate over the result e.g. via ToList(). var resultEntities = (await BulkServiceManager.DownloadEntitiesAsync( parameters: downloadParameters, progress: progress, cancellationToken: cancellationToken)).ToList(); // The CleanupTempFiles method removes all files (not sub-directories) within the working directory, // whether or not the files were created by this BulkServiceManager instance. //BulkServiceManager.CleanupTempFiles(); return(resultEntities); }
/// <summary> /// Gets the list of BulkAdGroupProductPartition that represent a product partition tree for the specified ad group. /// </summary> /// <param name="adGroupId">The identifier of the ad group whose product partition tree you want to get.</param> /// <returns>The BulkAdGroupProductPartition download results, filtered by the specified ad group ID.</returns> private async Task <IList <BulkAdGroupProductPartition> > GetBulkAdGroupProductPartitionTree(long adGroupId) { var downloadParameters = new DownloadParameters { DownloadEntities = new[] { DownloadEntity.AdGroupProductPartitions }, ResultFileDirectory = FileDirectory, ResultFileName = DownloadFileName, OverwriteResultFile = true, LastSyncTimeInUTC = null }; var bulkFilePath = await BulkServiceManager.DownloadFileAsync(downloadParameters); Reader = new BulkFileReader(bulkFilePath, ResultFileType.FullDownload, FileType); var downloadEntities = Reader.ReadEntities().ToList(); var bulkAdGroupProductPartitionResults = downloadEntities.OfType <BulkAdGroupProductPartition>().ToList(); Reader.Dispose(); IList <BulkAdGroupProductPartition> bulkAdGroupProductPartitions = new List <BulkAdGroupProductPartition>(); foreach (var bulkAdGroupProductPartitionResult in bulkAdGroupProductPartitionResults) { if (bulkAdGroupProductPartitionResult.AdGroupCriterion != null && bulkAdGroupProductPartitionResult.AdGroupCriterion.AdGroupId == adGroupId) { bulkAdGroupProductPartitions.Add(bulkAdGroupProductPartitionResult); } } return(bulkAdGroupProductPartitions); }
private void DownloadVideo(string id) { try { lock (this.commandLockObject) { if (!string.IsNullOrWhiteSpace(id)) { TwitchVideo video = this.Videos.Where(v => v.Id == id).FirstOrDefault(); if (video != null) { Preferences currentPrefs = this.preferencesService.CurrentPreferences.Clone(); TwitchVideoResolution resolution = video.Resolutions.Where(r => r.VideoQuality == currentPrefs.DownloadVideoQuality).FirstOrDefault(); if (resolution == null) { resolution = video.Resolutions.First(); } string filename = this.filenameService.SubstituteWildcards(currentPrefs.DownloadFileName, video); DownloadParameters downloadParams = new DownloadParameters(video, resolution, currentPrefs.DownloadFolder, filename); this.guiService.ShowDownloadDialog(downloadParams, this.DownloadCallback); } } } } catch (Exception ex) { this.guiService.ShowAndLogException(ex); } }
private void DownloadVideo(string id) { try { lock (_commandLockObject) { if (!string.IsNullOrWhiteSpace(id)) { TwitchVideo video = Videos.Where(v => v.Id == id).FirstOrDefault(); if (video != null) { TwitchVideoAuthInfo vodAuthInfo = _apiService.GetVodAuthInfo(video.Id); if (!vodAuthInfo.Privileged && vodAuthInfo.SubOnly) { if (_isAuthenticatedSubOnly) { _dialogService.ShowMessageBox("This video is sub-only but you are not subscribed to the channel!", "Download", MessageBoxButton.OK, MessageBoxImage.Exclamation); } else { _dialogService.ShowMessageBox("This video is sub-only! You need to enable sub-only video download support first!", "Download", MessageBoxButton.OK, MessageBoxImage.Exclamation); } return; } Dictionary <TwitchVideoQuality, string> playlistInfo = _apiService.GetPlaylistInfo(id, vodAuthInfo); List <TwitchVideoQuality> qualities = playlistInfo.Keys.OrderBy(q => q).ToList(); Preferences currentPrefs = _preferencesService.CurrentPreferences.Clone(); TwitchVideoQuality selectedQuality = GetSelectedQuality(qualities, currentPrefs.DownloadDefaultQuality); string folder = currentPrefs.DownloadSubfoldersForFav && _preferencesService.IsChannelInFavourites(video.Channel) ? Path.Combine(currentPrefs.DownloadFolder, video.Channel) : currentPrefs.DownloadFolder; string filename = _filenameService.SubstituteWildcards(currentPrefs.DownloadFileName, video, selectedQuality); filename = _filenameService.EnsureExtension(filename, currentPrefs.DownloadDisableConversion); DownloadParameters downloadParams = new DownloadParameters(video, qualities, selectedQuality, folder, filename, currentPrefs.DownloadDisableConversion); if (video.StartTime.HasValue) { downloadParams.CropStartTime = video.StartTime.Value; } _navigationService.ShowDownload(downloadParams); } } } } catch (Exception ex) { _dialogService.ShowAndLogException(ex); } }
public void ShowDownload(DownloadParameters downloadParams) { DownloadViewVM vm = this._kernel.Get <DownloadViewVM>(); vm.DownloadParams = downloadParams ?? throw new ArgumentNullException(nameof(downloadParams)); this.Navigate(vm); }
private void DownloadAll() { foreach (var param in _downloadParamsList) { _downloadParams = param; Download(); } }
static void TestDownload() { var parameters = new DownloadParameters() { ThrustCurveId = 33, }; var results = services.Download(parameters); }
private void WriteDownloadInfo(Action <string> log, DownloadParameters downloadParams, string ffmpegFile, string tempDir) { log(Environment.NewLine + Environment.NewLine + "VOD ID: " + downloadParams.Video.IdTrimmed); log(Environment.NewLine + "Selected Quality: " + downloadParams.Resolution.ResolutionFps); log(Environment.NewLine + "Download Url: " + downloadParams.Video.Url); log(Environment.NewLine + "Output File: " + downloadParams.FullPath); log(Environment.NewLine + "FFMPEG Path: " + ffmpegFile); log(Environment.NewLine + "Temporary Download Folder: " + tempDir); log(Environment.NewLine + "Crop Start: " + (downloadParams.CropStart ? "Yes (" + downloadParams.CropStartTime + ")" : "No")); log(Environment.NewLine + "Crop End: " + (downloadParams.CropEnd ? "Yes (" + downloadParams.CropEndTime + ")" : "No")); }
public void Enqueue(DownloadParameters downloadParams) { if (_paused) { return; } lock (_changeDownloadLockObject) { _downloads.Add(new TwitchVideoDownload(downloadParams)); } }
private static bool IsFileChecksumOK(string filename, DownloadParameters param) { using var hashAlgo = HashAlgorithm.Create(param.Hash ?? "SHA512"); using var stream = File.OpenRead(filename); var checksum = BitConverter.ToString(hashAlgo.ComputeHash(stream)).Replace("-", string.Empty).ToLowerInvariant(); if (param.CheckSum.Equals(checksum, StringComparison.OrdinalIgnoreCase)) { return(true); } return(false); }
/// <summary> /// You can submit a download or upload request and the BulkServiceManager will automatically /// return results. The BulkServiceManager abstracts the details of checking for result file /// completion, and you don't have to write any code for results polling. /// </summary> /// <param name="downloadParameters"></param> /// <param name="progress"></param> /// <returns></returns> private async Task BackgroundCompletionAsync( DownloadParameters downloadParameters, Progress <BulkOperationProgressInfo> progress, CancellationToken cancellationToken) { var resultFilePath = await BulkServiceManager.DownloadFileAsync( parameters : downloadParameters, progress : progress, cancellationToken : cancellationToken); OutputStatusMessage(string.Format("Download result file: {0}", resultFilePath)); }
//private static void LoadPersistedObjects(DownloadItem[] downloads) private static void LoadPersistedObjects(DownloadParameters downloadParameters) { string directory = downloadParameters.defaultDownloadDirectory; DownloadManager.Instance.DefaultDownloadDirectorySource = directory; if (!Path.IsPathRooted(directory)) { directory = Path.Combine(GetDatabaseDirectory(), directory); } DownloadManager.Instance.DefaultDownloadDirectory = directory; DownloadManager.Instance.LastDownloadId = downloadParameters.lastDownloadId; DownloadItem[] downloads = downloadParameters.downloadItems; for (int i = 0; i < downloads.Length; i++) { List <Segment> segments = new List <Segment>(); for (int j = 0; j < downloads[i].Segments.Length; j++) { Segment seg = new Segment(); seg.Index = downloads[i].Segments[j].Index; seg.InitialStartPosition = downloads[i].Segments[j].InitialStartPositon; seg.StartPosition = downloads[i].Segments[j].StartPositon; seg.EndPosition = downloads[i].Segments[j].EndPosition; segments.Add(seg); } //Downloader d = DownloadManager.Instance.Add( // downloads[i].rl, // downloads[i].mirrors, // downloads[i].LocalFile, // segments, // downloads[i].remoteInfo, // downloads[i].requestedSegments, // false, // downloads[i].createdDateTime); Downloader d = new Downloader(downloads[i].id, downloads[i].rl, downloads[i].mirrors, downloads[i].LocalFile, segments, downloads[i].remoteInfo, downloads[i].requestedSegments, downloads[i].createdDateTime); DownloadManager.Instance.Add(d, false); if (downloads[i].extendedProperties != null) { SerializableDictionary <string, object> .Enumerator e = downloads[i].extendedProperties.GetEnumerator(); while (e.MoveNext()) { d.ExtendedProperties.Add(e.Current.Key, e.Current.Value); } } } }
protected override async void OnStartup(StartupEventArgs e) { DetectWindows.Supported(); base.OnStartup(e); Uninstall.Run(); await DownloadParameters.AppListAsync(); var bootstrapper = new Bootstrapper(); bootstrapper.Run(); }
/// <summary> /// You can submit a download or upload request and the BulkServiceManager will automatically /// return results. The BulkServiceManager abstracts the details of checking for result file /// completion, and you don't have to write any code for results polling. /// </summary> /// <param name="downloadParameters"></param> /// <param name="progress"></param> /// <returns></returns> private async Task BackgroundCompletionAsync( DownloadParameters downloadParameters, Progress <BulkOperationProgressInfo> progress) { // You may optionally cancel the DownloadFileAsync operation after a specified time interval. var tokenSource = new CancellationTokenSource(); tokenSource.CancelAfter(TimeoutInMilliseconds); var resultFilePath = await BulkServiceManager.DownloadFileAsync(downloadParameters, progress, tokenSource.Token); OutputStatusMessage(string.Format("Download result file: {0}\n", resultFilePath)); }
private void DownloadAllVideos(List <string> Ids) { var downloadQueue = new List <DownloadParameters>(); try { foreach (var vid in Videos) { lock (_commandLockObject) { if (!string.IsNullOrWhiteSpace(vid.Id)) { TwitchVideo video = Videos.Where(v => v.Id == vid.Id).FirstOrDefault(); if (video != null) { VodAuthInfo vodAuthInfo = _twitchService.RetrieveVodAuthInfo(video.Id); if (!vodAuthInfo.Privileged && vodAuthInfo.SubOnly) { _dialogService.ShowMessageBox("This video is sub-only! Twitch removed the ability for 3rd party software to download such videos, sorry :(", "SUB HYPE!", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } Preferences currentPrefs = _preferencesService.CurrentPreferences.Clone(); string folder = currentPrefs.DownloadSubfoldersForFav && _preferencesService.IsChannelInFavourites(video.Channel) ? Path.Combine(currentPrefs.DownloadFolder, video.Channel) : currentPrefs.DownloadFolder; string filename = _filenameService.SubstituteWildcards(currentPrefs.DownloadFileName, video); filename = _filenameService.EnsureExtension(filename, currentPrefs.DownloadDisableConversion); DownloadParameters downloadParams = new DownloadParameters(video, vodAuthInfo, video.Qualities.First(), folder, filename, currentPrefs.DownloadDisableConversion); downloadQueue.Add(downloadParams); //_navigationService.ShowDownload(downloadParams); } } } } DownloadAll(downloadQueue); } catch (Exception ex) { _dialogService.ShowAndLogException(ex); } }
private void DownloadVideo(string id) { try { lock (this.commandLockObject) { if (!string.IsNullOrWhiteSpace(id)) { TwitchVideo video = this.Videos.Where(v => v.Id == id).FirstOrDefault(); if (video != null) { VodAuthInfo vodAuthInfo = this.twitchService.RetrieveVodAuthInfo(video.IdTrimmed); if (!vodAuthInfo.Privileged && vodAuthInfo.SubOnly) { if (!this.twitchService.IsAuthorized) { this.dialogService.ShowMessageBox("This video is sub-only! Please authorize your Twitch account by clicking the Twitch button in the menu.", "SUB HYPE!", MessageBoxButton.OK, MessageBoxImage.Exclamation); } else { this.dialogService.ShowMessageBox("This video is sub-only but you are not subscribed to '" + video.Channel + "'!", "SUB HYPE!", MessageBoxButton.OK, MessageBoxImage.Exclamation); } return; } Preferences currentPrefs = this.preferencesService.CurrentPreferences.Clone(); TwitchVideoQuality resolution = video.Resolutions.Where(r => r.QualityFormatted == currentPrefs.DownloadVideoQuality).FirstOrDefault(); if (resolution == null) { resolution = video.Resolutions.First(); } string filename = this.filenameService.SubstituteWildcards(currentPrefs.DownloadFileName, video); DownloadParameters downloadParams = new DownloadParameters(video, resolution, vodAuthInfo, currentPrefs.DownloadFolder, filename); this.navigationService.ShowDownload(downloadParams); } } } } catch (Exception ex) { this.dialogService.ShowAndLogException(ex); } }
private void DownloadVideo(string id) { try { lock (_commandLockObject) { if (!string.IsNullOrWhiteSpace(id)) { TwitchVideo video = Videos.Where(v => v.Id == id).FirstOrDefault(); if (video != null) { VodAuthInfo vodAuthInfo = _twitchService.RetrieveVodAuthInfo(video.Id); if (!vodAuthInfo.Privileged && vodAuthInfo.SubOnly) { if (!_twitchService.IsAuthorized) { _dialogService.ShowMessageBox("This video is sub-only! Please authorize your Twitch account by clicking the Twitch button in the menu.", "SUB HYPE!", MessageBoxButton.OK, MessageBoxImage.Exclamation); } else { _dialogService.ShowMessageBox("This video is sub-only but you are not subscribed to '" + video.Channel + "'!", "SUB HYPE!", MessageBoxButton.OK, MessageBoxImage.Exclamation); } return; } Preferences currentPrefs = _preferencesService.CurrentPreferences.Clone(); string folder = currentPrefs.DownloadSubfoldersForFav && _preferencesService.IsChannelInFavourites(video.Channel) ? Path.Combine(currentPrefs.DownloadFolder, video.Channel) : currentPrefs.DownloadFolder; string filename = _filenameService.SubstituteWildcards(currentPrefs.DownloadFileName, video); filename = _filenameService.EnsureExtension(filename, currentPrefs.DownloadDisableConversion); DownloadParameters downloadParams = new DownloadParameters(video, vodAuthInfo, video.Qualities.First(), folder, filename, currentPrefs.DownloadDisableConversion); _navigationService.ShowDownload(downloadParams); } } } } catch (Exception ex) { _dialogService.ShowAndLogException(ex); } }
public void DownloadCallback(bool cancelled, DownloadParameters downloadParams) { try { if (!cancelled) { this.twitchService.Enqueue(downloadParams); this.eventAggregator.GetEvent <ShowDownloadsEvent>().Publish(); } } catch (Exception ex) { this.guiService.ShowAndLogException(ex); } }
public static async Task StartAsync(string url, IDictionary <string, string> headers = null) { var assembly = Assembly.GetEntryAssembly(); var client = new HttpClient(); client.Timeout = TimeSpan.FromSeconds(10); if (headers != null && headers.Count > 0) { foreach (var h in headers) { client.DefaultRequestHeaders.Add(h.Key, h.Value); } } try { // Get Update Info var resp = await client.GetAsync(url); resp.EnsureSuccessStatusCode(); var json = await resp.Content.ReadAsStringAsync(); _param = JsonSerializer.Deserialize <DownloadParameters>(json); var currentVersion = new Version(_param.Version); if (currentVersion <= assembly.GetName().Version) { UpdateDownloadedEvent?.Invoke(new UpdateDownloadedEventArgs { IsDownloaded = false }); return; } // Start Download _tempFile = Path.GetTempFileName(); _webClient = new AppWebClient(); _webClient.DownloadFileCompleted += WebClient_DownloadFileCompleted; UpdateDownloadingEvent?.Invoke(new UpdateDownloadedEventArgs { IsDownloaded = false }); await _webClient.DownloadFileTaskAsync(new Uri(_param.Url), _tempFile); } catch (Exception e) { UpdateErrorEvent?.Invoke(new UpdateErrorEventArgs { Message = e.Message }); } }
/// <summary> /// Downloads all target criterions in the account. You can use this method /// to sync criterion identifiers and map them to your campaigns and ad groups. /// </summary> /// <returns>The string result of the Task is the local path to the downloaded bulk file.</returns> private async Task <string> DownloadTargetsAsCriterions(IList <long> campaignIds) { var downloadParameters = new DownloadParameters { CampaignIds = campaignIds, DownloadEntities = new List <DownloadEntity> { DownloadEntity.AdGroupTargetCriterions, DownloadEntity.CampaignTargetCriterions }, ResultFileDirectory = FileDirectory, ResultFileName = DownloadFileName, OverwriteResultFile = true, LastSyncTimeInUTC = null }; OutputStatusMessage("Downloading targets as criterions . . . \n"); return(await BulkServiceManager.DownloadFileAsync(downloadParameters).ConfigureAwait(continueOnCapturedContext: false)); }
//private void SaveObjects(List<DownloadItem> downloadsToSave) private void SaveObjects(DownloadParameters downloadParameters) { using (new MyStopwatch("Saving download list")) { try { using (FileStream fs = new FileStream(GetDatabaseFile(), FileMode.Create)) { //serializer.Serialize(fs, downloadsToSave.ToArray()); serializer.Serialize(fs, downloadParameters); } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } } }
public void ShowDownloadDialog(TwitchVideo video, TwitchVideoResolution resolution, string folder, string filename, Action <bool, DownloadParameters> dialogCompleteCallback) { if (video == null) { throw new ArgumentNullException(nameof(video)); } if (resolution == null) { throw new ArgumentNullException(nameof(resolution)); } if (string.IsNullOrWhiteSpace(folder)) { throw new ArgumentNullException(nameof(folder)); } if (string.IsNullOrWhiteSpace(filename)) { throw new ArgumentNullException(nameof(filename)); } if (dialogCompleteCallback == null) { throw new ArgumentNullException(nameof(dialogCompleteCallback)); } DownloadWindowVM vm = this.kernel.Get <DownloadWindowVM>(); vm.Video = video; vm.Resolution = resolution; vm.Folder = folder; vm.Filename = filename; DownloadWindow window = this.kernel.Get <DownloadWindow>(); window.DataContext = vm; bool?result = window.ShowDialog(); DownloadParameters resultObject = vm.ResultObject; dialogCompleteCallback(result != true, resultObject); }
private void DownloadVideo(string id) { try { lock (_commandLockObject) { if (!string.IsNullOrWhiteSpace(id)) { TwitchVideo video = Videos.Where(v => v.Id == id).FirstOrDefault(); if (video != null) { VodAuthInfo vodAuthInfo = _twitchService.RetrieveVodAuthInfo(video.Id); if (!vodAuthInfo.Privileged && vodAuthInfo.SubOnly) { _dialogService.ShowMessageBox("이 비디오는 구독자 전용입니다! '" + video.Channel + "'에 구독해주세요!", "구독냥이!", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } Preferences currentPrefs = _preferencesService.CurrentPreferences.Clone(); string folder = currentPrefs.DownloadSubfoldersForFav && _preferencesService.IsChannelInFavourites(video.Channel) ? Path.Combine(currentPrefs.DownloadFolder, video.Channel) : currentPrefs.DownloadFolder; string filename = _filenameService.SubstituteWildcards(currentPrefs.DownloadFileName, video); filename = _filenameService.EnsureExtension(filename, currentPrefs.DownloadDisableConversion); DownloadParameters downloadParams = new DownloadParameters(video, vodAuthInfo, video.Qualities.First(), folder, filename, currentPrefs.DownloadDisableConversion); _navigationService.ShowDownload(downloadParams); } } } } catch (Exception ex) { _dialogService.ShowAndLogException(ex); } }
private void LoadSavedList() { if (File.Exists(GetDatabaseFile())) { try { using (FileStream fs = new FileStream(GetDatabaseFile(), FileMode.Open)) { //DownloadItem[] downloads = (DownloadItem[])serializer.Deserialize(fs); DownloadParameters downloadParameters = (DownloadParameters)serializer.Deserialize(fs); //LoadPersistedObjects(downloads); LoadPersistedObjects(downloadParameters); } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } } }
private void WriteDownloadInfo(Action <string> log, DownloadParameters downloadParams, string ffmpegFile, string tempDir) { log(Environment.NewLine + Environment.NewLine + "TWITCH LEECHER INFO"); log(Environment.NewLine + "--------------------------------------------------------------------------------------------"); log(Environment.NewLine + "Version: " + AssemblyUtil.Get.GetAssemblyVersion().Trim()); log(Environment.NewLine + Environment.NewLine + "VOD INFO"); log(Environment.NewLine + "--------------------------------------------------------------------------------------------"); log(Environment.NewLine + "VOD ID: " + downloadParams.Video.Id); log(Environment.NewLine + "Selected Quality: " + downloadParams.SelectedQuality.DisplayString); log(Environment.NewLine + "Download Url: " + downloadParams.Video.Url); log(Environment.NewLine + "Crop Start: " + (downloadParams.CropStart ? "Yes (" + downloadParams.CropStartTime.ToDaylessString() + ")" : "No")); log(Environment.NewLine + "Crop End: " + (downloadParams.CropEnd ? "Yes (" + downloadParams.CropEndTime.ToDaylessString() + ")" : "No")); log(Environment.NewLine + Environment.NewLine + "OUTPUT INFO"); log(Environment.NewLine + "--------------------------------------------------------------------------------------------"); log(Environment.NewLine + "Disable Conversion: " + (downloadParams.DisableConversion ? "Yes" : "No")); log(Environment.NewLine + "Output File: " + downloadParams.FullPath); log(Environment.NewLine + "FFMPEG Path: " + ffmpegFile); log(Environment.NewLine + "Temporary Download Folder: " + tempDir); }
public IActionResult Export(DownloadParameters parameters) { _executionContextConfigurator.ConfigureFor(_tenantResolver.Resolve(HttpContext.Request), Dolittle.Execution.CorrelationId.New(), ClaimsPrincipal.Current.ToClaims()); var exporter = _exporters.FirstOrDefault(_ => _.Format == parameters.Format); if (exporter != null) { var reports = _allCaseReports().Query; var filtered = reports.Where(parameters.FilterPredicate); var ordered = parameters.OrderDescending ? filtered.OrderByDescending(parameters.GetOrderByPredicate) : filtered.OrderBy(parameters.GetOrderByPredicate); var fileName = "CaseReports-" + DateTimeOffset.UtcNow.ToString("yyyy-MM-dd") + exporter.FileExtension; var stream = new MemoryStream(); exporter.WriteReportsTo(ordered, stream); stream.Position = 0; return(File(stream, exporter.MIMEType, fileName)); } else { return(NotFound()); } }
public async override Task RunAsync(AuthorizationData authorizationData) { try { ApiEnvironment environment = ((OAuthDesktopMobileAuthCodeGrant)authorizationData.Authentication).Environment; CampaignManagementExampleHelper = new CampaignManagementExampleHelper(this.OutputStatusMessage); BulkServiceManager = new BulkServiceManager(authorizationData, environment); BulkServiceManager.StatusPollIntervalInMilliseconds = 5000; var progress = new Progress <BulkOperationProgressInfo>(x => OutputStatusMessage(string.Format("{0} % Complete", x.PercentComplete.ToString(CultureInfo.InvariantCulture)))); #region Download // In this example we will download all ad groups in the account. var entities = new[] { DownloadEntity.AdGroups, }; // You can limit by specific campaign IDs and request performance data. var downloadParameters = new DownloadParameters { CampaignIds = null, DataScope = DataScope.EntityData, PerformanceStatsDateRange = null, DownloadEntities = entities, FileType = FileType, LastSyncTimeInUTC = null, ResultFileDirectory = FileDirectory, ResultFileName = DownloadFileName, OverwriteResultFile = true }; // You can submit a download or upload request and the BulkServiceManager will automatically // return results. The BulkServiceManager abstracts the details of checking for result file // completion, and you don't have to write any code for results polling. var bulkFilePath = await BulkServiceManager.DownloadFileAsync(downloadParameters); OutputStatusMessage("Downloaded all ad groups in the account.\n"); #endregion Download #region Parse Reader = new BulkFileReader(bulkFilePath, ResultFileType.FullDownload, FileType); var bulkAdGroups = Reader.ReadEntities().ToList().OfType <BulkAdGroup>().ToList(); OutputBulkAdGroups(bulkAdGroups); Writer = new BulkFileWriter(FileDirectory + UploadFileName); // We will activate ad groups for one month starting from today as an example. var nextMonth = DateTime.UtcNow.AddMonths(1); // Within the downloaded records, find all ad groups that you want to update. foreach (var bulkAdGroup in bulkAdGroups) { var adGroup = bulkAdGroup.AdGroup; if (adGroup != null && bulkAdGroup.IsExpired) { // For best performance, only upload the properties that you want to update. Writer.WriteEntity(new BulkAdGroup { CampaignId = bulkAdGroup.CampaignId, AdGroup = new AdGroup { Id = adGroup.Id, EndDate = new Microsoft.BingAds.V12.CampaignManagement.Date { Month = nextMonth.Month, Day = nextMonth.Day, Year = nextMonth.Year }, Status = AdGroupStatus.Active, } }); } } Reader.Dispose(); Writer.Dispose(); #endregion Parse #region Upload // Upload the local file that we already prepared var fileUploadParameters = new FileUploadParameters { ResultFileDirectory = FileDirectory, CompressUploadFile = true, ResultFileName = ResultFileName, OverwriteResultFile = true, UploadFilePath = FileDirectory + UploadFileName, ResponseMode = ResponseMode.ErrorsAndResults }; var resultFilePath = await BulkServiceManager.UploadFileAsync(fileUploadParameters, progress, CancellationToken.None); OutputStatusMessage("Updated ad groups.\n"); Reader = new BulkFileReader(resultFilePath, ResultFileType.Upload, FileType); bulkAdGroups = Reader.ReadEntities().ToList().OfType <BulkAdGroup>().ToList(); OutputBulkAdGroups(bulkAdGroups); Reader.Dispose(); #endregion Upload #region Entities // We can make the same update without explicitly reading or writing a local file. // When working with entities a file is downloaded to the temp directory, // although you don't need to manage it. var downloadEntities = await BulkServiceManager.DownloadEntitiesAsync(downloadParameters); OutputStatusMessage("Downloaded all ad groups in the account.\n"); bulkAdGroups = downloadEntities.ToList().OfType <BulkAdGroup>().ToList(); OutputBulkAdGroups(bulkAdGroups); var uploadEntities = new List <BulkEntity>(); foreach (var bulkAdGroup in bulkAdGroups) { var adGroup = bulkAdGroup.AdGroup; if (adGroup != null && bulkAdGroup.IsExpired) { // Instead of Writer.WriteEntity, we will add to the in-memory list uploadEntities.Add(new BulkAdGroup { CampaignId = bulkAdGroup.CampaignId, AdGroup = new AdGroup { Id = adGroup.Id, EndDate = new Microsoft.BingAds.V12.CampaignManagement.Date { Month = nextMonth.Month, Day = nextMonth.Day, Year = nextMonth.Year }, Status = AdGroupStatus.Active, } }); } } var entityUploadParameters = new EntityUploadParameters { Entities = uploadEntities, ResponseMode = ResponseMode.ErrorsAndResults, }; var resultEntities = await BulkServiceManager.UploadEntitiesAsync(entityUploadParameters, progress, CancellationToken.None); OutputStatusMessage("Updated ad groups.\n"); bulkAdGroups = resultEntities.ToList().OfType <BulkAdGroup>().ToList(); OutputBulkAdGroups(bulkAdGroups); #endregion Entities } // Catch authentication exceptions catch (OAuthTokenRequestException ex) { OutputStatusMessage(string.Format("Couldn't get OAuth tokens. Error: {0}. Description: {1}", ex.Details.Error, ex.Details.Description)); } // Catch Bulk service exceptions catch (FaultException <Microsoft.BingAds.V12.Bulk.AdApiFaultDetail> ex) { OutputStatusMessage(string.Join("; ", ex.Detail.Errors.Select(error => string.Format("{0}: {1}", error.Code, error.Message)))); } catch (FaultException <Microsoft.BingAds.V12.Bulk.ApiFaultDetail> ex) { OutputStatusMessage(string.Join("; ", ex.Detail.OperationErrors.Select(error => string.Format("{0}: {1}", error.Code, error.Message)))); OutputStatusMessage(string.Join("; ", ex.Detail.BatchErrors.Select(error => string.Format("{0}: {1}", error.Code, error.Message)))); } catch (BulkOperationInProgressException ex) { OutputStatusMessage("The result file for the bulk operation is not yet available for download."); OutputStatusMessage(ex.Message); } catch (BulkOperationCouldNotBeCompletedException <DownloadStatus> ex) { OutputStatusMessage(string.Join("; ", ex.Errors.Select(error => string.Format("{0}: {1}", error.Code, error.Message)))); } catch (BulkOperationCouldNotBeCompletedException <UploadStatus> ex) { OutputStatusMessage(string.Join("; ", ex.Errors.Select(error => string.Format("{0}: {1}", error.Code, error.Message)))); } catch (Exception ex) { OutputStatusMessage(ex.Message); } }
public async override Task RunAsync(AuthorizationData authorizationData) { try { CustomerService = new ServiceClient <ICustomerManagementService>(authorizationData); BulkService = new BulkServiceManager(authorizationData); var progress = new Progress <BulkOperationProgressInfo>(x => OutputStatusMessage(string.Format("{0} % Complete", x.PercentComplete.ToString(CultureInfo.InvariantCulture)))); Dictionary <long, List <long> > targetToEntities = new Dictionary <long, List <long> >(); Dictionary <long, List <Dictionary <long, KeyValuePair <long, string> > > > targetToEntities2 = new Dictionary <long, List <Dictionary <long, KeyValuePair <long, string> > > >(); var downloadParameters = new DownloadParameters { CampaignIds = null, Entities = BulkDownloadEntity.AdGroupTargets | BulkDownloadEntity.CampaignTargets, ResultFileDirectory = FileDirectory, ResultFileName = DownloadFileName, OverwriteResultFile = true, LastSyncTimeInUTC = null }; // Search for the Bing Ads accounts that the user can access. var getUserResponse = await GetUserAsync(null); var user = getUserResponse.User; var accounts = await SearchAccountsByUserIdAsync(user.Id); foreach (var account in accounts) { var linkToUI = string.Format("https://ui.bingads.microsoft.com/Campaign/Campaigns?cid={0}&aid={1}#/customer/{0}/account/{1}/campaign", authorizationData.CustomerId, account.Id); OutputStatusMessage(string.Format("Downloading targets for account {0} \n", account.Number)); OutputStatusMessage(linkToUI); authorizationData.AccountId = (long)account.Id; BulkService = new BulkServiceManager(authorizationData); var downloadEntities = (await BulkService.DownloadEntitiesAsync(downloadParameters)).ToList(); var adGroupTargetResults = downloadEntities.OfType <Microsoft.BingAds.V10.Bulk.Entities.BulkAdGroupTarget>().ToList(); foreach (var entity in adGroupTargetResults) { MapTargetToEntity(targetToEntities, (long)entity.Target.Id, (long)entity.AdGroupId); MapTargetToEntity2( targetToEntities2, authorizationData.AccountId, (long)entity.Target.Id, (long)entity.AdGroupId, "AdGroup" ); } var campaignTargetResults = downloadEntities.OfType <Microsoft.BingAds.V10.Bulk.Entities.BulkCampaignTarget>().ToList(); foreach (var entity in campaignTargetResults) { MapTargetToEntity(targetToEntities, (long)entity.Target.Id, (long)entity.CampaignId); MapTargetToEntity2( targetToEntities2, authorizationData.AccountId, (long)entity.Target.Id, (long)entity.CampaignId, "Campaign" ); } } OutputStatusMessage("\nView 1: By Target Id:"); foreach (var dict in targetToEntities) { if (dict.Value.Count() > 1) { OutputStatusMessage(string.Format("\nTargetId {0} is shared by the following entities:", dict.Key)); OutputStatusMessage(string.Join("\r\n", dict.Value.Select(id => string.Format("{0}", id)))); } } OutputStatusMessage("\nView 2: With Account Detail:"); OutputStatusMessage("\nTargetId, AccountId, EntityId, EntityType"); foreach (var targetDictionary in targetToEntities2) { if (targetDictionary.Value.Count() > 1) { foreach (var accountDictionary in targetDictionary.Value) { foreach (var accountIdKey in accountDictionary.Keys) { OutputStatusMessage( string.Format("{0}, {1}, {2}, {3}", targetDictionary.Key, accountIdKey, accountDictionary[accountIdKey].Key, // EntityId accountDictionary[accountIdKey].Value // EntityType e.g. Campaign or AdGroup )); } } } } } // Catch Microsoft Account authorization exceptions. catch (OAuthTokenRequestException ex) { OutputStatusMessage(string.Format("Couldn't get OAuth tokens. Error: {0}. Description: {1}", ex.Details.Error, ex.Details.Description)); } // Catch Bulk service exceptions catch (FaultException <Microsoft.BingAds.V10.Bulk.AdApiFaultDetail> ex) { OutputStatusMessage(string.Join("; ", ex.Detail.Errors.Select(error => string.Format("{0}: {1}", error.Code, error.Message)))); } catch (FaultException <ApiFaultDetail> ex) { OutputStatusMessage(string.Join("; ", ex.Detail.OperationErrors.Select(error => string.Format("{0}: {1}", error.Code, error.Message)))); OutputStatusMessage(string.Join("; ", ex.Detail.BatchErrors.Select(error => string.Format("{0}: {1}", error.Code, error.Message)))); } catch (BulkOperationInProgressException ex) { OutputStatusMessage("The result file for the bulk operation is not yet available for download."); OutputStatusMessage(ex.Message); } catch (BulkOperationCouldNotBeCompletedException <DownloadStatus> ex) { OutputStatusMessage(string.Join("; ", ex.Errors.Select(error => string.Format("{0}: {1}", error.Code, error.Message)))); } catch (Exception ex) { OutputStatusMessage(ex.Message); } finally { if (Reader != null) { Reader.Dispose(); } if (Writer != null) { Writer.Dispose(); } } }
//private static void LoadPersistedObjects(DownloadItem[] downloads) private static void LoadPersistedObjects(DownloadParameters downloadParameters) { string directory = downloadParameters.defaultDownloadDirectory; DownloadManager.Instance.DefaultDownloadDirectorySource = directory; if (!Path.IsPathRooted(directory)) directory = Path.Combine(GetDatabaseDirectory(), directory); DownloadManager.Instance.DefaultDownloadDirectory = directory; DownloadManager.Instance.LastDownloadId = downloadParameters.lastDownloadId; DownloadItem[] downloads = downloadParameters.downloadItems; for (int i = 0; i < downloads.Length; i++) { List<Segment> segments = new List<Segment>(); for (int j = 0; j < downloads[i].Segments.Length; j++) { Segment seg = new Segment(); seg.Index = downloads[i].Segments[j].Index; seg.InitialStartPosition = downloads[i].Segments[j].InitialStartPositon; seg.StartPosition = downloads[i].Segments[j].StartPositon; seg.EndPosition = downloads[i].Segments[j].EndPosition; segments.Add(seg); } //Downloader d = DownloadManager.Instance.Add( // downloads[i].rl, // downloads[i].mirrors, // downloads[i].LocalFile, // segments, // downloads[i].remoteInfo, // downloads[i].requestedSegments, // false, // downloads[i].createdDateTime); Downloader d = new Downloader(downloads[i].id, downloads[i].rl, downloads[i].mirrors, downloads[i].LocalFile, segments, downloads[i].remoteInfo, downloads[i].requestedSegments, downloads[i].createdDateTime); DownloadManager.Instance.Add(d, false); if (downloads[i].extendedProperties != null) { SerializableDictionary<string, object>.Enumerator e = downloads[i].extendedProperties.GetEnumerator(); while (e.MoveNext()) { d.ExtendedProperties.Add(e.Current.Key, e.Current.Value); } } } }
private void PersistList(object state) { List<DownloadItem> downloadsToSave = new List<DownloadItem>(); using (DownloadManager.Instance.LockDownloadList(false)) { //IList<Downloader> downloads = DownloadManager.Instance.Downloads; //for (int i = 0; i < downloads.Count; i++) foreach (Downloader downloader in DownloadManager.Instance.OrderedDownloads) { //if (downloads[i].State == DownloaderState.Ended) if (downloader.State == DownloaderState.Ended) { continue; } //Downloader downloader = downloads[i]; DownloadItem di = new DownloadItem(); di.id = downloader.Id; di.LocalFile = downloader.LocalFile; di.rl = downloader.ResourceLocation; di.mirrors = downloader.Mirrors.ToArray(); di.remoteInfo = downloader.RemoteFileInfo; di.requestedSegments = downloader.RequestedSegments; di.createdDateTime = downloader.CreatedDateTime; di.extendedProperties = new SerializableDictionary<string,object>(downloader.ExtendedProperties); using (downloader.LockSegments()) { di.Segments = new SegmentItem[downloader.Segments.Count]; for (int j = 0; j < downloader.Segments.Count; j++) { SegmentItem si = new SegmentItem(); Segment seg = downloader.Segments[j]; si.Index = seg.Index; si.InitialStartPositon = seg.InitialStartPosition; si.StartPositon = seg.StartPosition; si.EndPosition = seg.EndPosition; di.Segments[j] = si; } } downloadsToSave.Add(di); } } DownloadParameters downloadParameters = new DownloadParameters(); downloadParameters.defaultDownloadDirectory = DownloadManager.Instance.DefaultDownloadDirectorySource; downloadParameters.lastDownloadId = DownloadManager.Instance.LastDownloadId; downloadParameters.downloadItems = downloadsToSave.ToArray(); //SaveObjects(downloadsToSave); SaveObjects(downloadParameters); }