public static DownloadInfo[] DownloadPatches(VersionDownload argument, OnFileDownloadCompleteDelegate handle) { Directory.CreateDirectory(TempPath); var dc = new DownloadClient(); dc.OnFileDownloadComplete = handle; var dic = new Dictionary <string, string>(argument.Files.Length); foreach (var file in argument.Files) { var destFile = Path.Combine(TempPath, Path.GetFileName(file)); int i = 0; while (dic.Values.Contains(destFile, StringComparer.InvariantCultureIgnoreCase)) { var filename = Path.GetFileName(file); destFile = Path.Combine(TempPath, $"{Path.GetFileNameWithoutExtension(filename)}-{i++}{Path.GetExtension(filename)}"); } dic.Add(argument.FileServer.AppendPathSegment(file), destFile); } return(dc.StartDownload(dic)); }
private async Task GetClipAsync(Clip clip, Header course, int moduleId, string moduleTitle, bool list) { if (clip == null) { throw new Exception("The clip was not found. Check the clip and Try again."); } if (list) { Utils.WriteText($"\t\t{clip.Index}. {clip.Title}", newLine: false); Utils.WriteCyanText($" -- {clip.Id}"); return; } var response = await api.Video.GetClipUrls(course.Id, clip.Id, clip.SupportsWidescreen); if (!response.Success) { Utils.WriteRedText($"\n\t\t---Error retrieving clip '{clip.Title}'. Message: {response.Error.Message}"); return; } var client = new DownloadClient(response.Data, options.OutputPath, course.Title, moduleId, moduleTitle, clip, api.HttpClientFactoryInstance); queue.Enqueue(client); }
private static void DownloadFile(string localFilePath, bool deleted = false) { var fileToDownload = GetCurrentFile(localFilePath, deleted); Console.WriteLine(); Console.WriteLine("Start File Downloading..."); var downloadClient = new DownloadClient(); Console.WriteLine(); try { downloadClient.DownloadFileSimple(fileToDownload, ConfigurationHelper.DownloadFolder); Console.WriteLine($"Download of {fileToDownload.Filename} to {ConfigurationHelper.DownloadFolder} succeeded."); } catch (Exception e) { Console.WriteLine($"Download of {fileToDownload.Filename} to {ConfigurationHelper.DownloadFolder} failed."); Console.WriteLine("Exception caught:"); Console.WriteLine(e); throw; } }
protected override void ProcessRecord() { if (!this.ContainsParameter(x => x.Id)) { List <DownloadClient> clients = this.GetAllDownloadClients(); if (!this.ContainsParameter(x => x.Protocol)) { base.SendToPipeline(clients); } else { base.SendToPipeline(this.FindByProtocol(clients)); } } else { for (int i = 0; i < this.Id.Length; i++) { DownloadClient dlc = base.SendSonarrGet <DownloadClient>(string.Format(ApiEndpoints.DownloadClient_ById, this.Id[i])); base.SendToPipeline(dlc); } } }
private void RetrieveYahooCompanyProfile(string symbol, ref Dictionary <string, Object> stats) { CompanyProfileDownload d1 = new CompanyProfileDownload(); DownloadClient <CompanyProfileResult> baseD1 = d1; CompanyProfileDownloadSettings settings = d1.Settings; settings.ID = symbol; Response <CompanyProfileResult> resp = baseD1.Download(); SettingsBase baseSettings = baseD1.Settings; ConnectionInfo connInfo = resp.Connection; if (connInfo.State == ConnectionState.Success) { CompanyProfileResult result = resp.Result; //stats.Add("CorporateGovernance", result.Item.CorporateGovernance); stats.Add("BusinessSummary", result.Item.BusinessSummary); } else { Exception ex = connInfo.Exception; Console.WriteLine(ex.Message); } }
private void html_DownloadAsyncCompleted(DownloadClient<XDocument> sender, DownloadCompletedEventArgs<XDocument> e) { sender.AsyncDownloadCompleted -= this.html_DownloadAsyncCompleted; AsyncArgs args = (AsyncArgs)e.UserArgs; this.ConvertHtml(e.Response.Result, args); this.UploadAsync2(args); }
protected override void ProcessRecord() { if (this.ParameterSetName != "ByClientId") { List <DownloadClient> clients = this.GetAllDownloadClients(); if (clients != null) { if (!this.MyInvocation.BoundParameters.ContainsKey("Protocol")) { base.WriteObject(clients, true); } else { base.WriteObject(this.FindByProtocol(clients), true); } } } else { for (int i = 0; i < this.Id.Length; i++) { string jsonRes = base.TryGetSonarrResult(string.Format(EP_ID, this.Id[i])); if (!string.IsNullOrEmpty(jsonRes)) { DownloadClient dlCli = SonarrHttp.ConvertToSonarrResult <DownloadClient>(jsonRes); base.WriteObject(dlCli); } } } }
/// <summary> /// Start Downloading the file without disturbing the Ongoing Thread i.e asynchronously. /// </summary> /// <param name="URL">url of the file to be downloaded</param> /// <param name="FileLocation">Loaction where to store the file after Download</param> public void DownloadFileAsync(string URL, string FileLocation, DownloadMode Mode, string FileName = "", bool DownloadAnyway = true) { //creating a URI Uri url = new Uri(URL); //Getting DownloadFile name from the server. DownloadFileName = System.IO.Path.GetFileName(url.LocalPath); //Setting File Location and File name. if (FileName != "") { Client = new DownloadClient(URL, FileLocation + "/" + FileName, Mode, DownloadAnyway); } else { Client = new DownloadClient(URL, FileLocation + "/" + DownloadFileName, Mode, DownloadAnyway); } //Registering to the events on DownloadClient Class. Client.ProgressChangedEvent += OnProgressChanged; Client.DownloadCompletedEvent += OnDownloadCompleted; ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) { return(true); }); DownloadSpeed = 0; DataDownloaded = 0; FileSize = 0; SW.Reset(); SW.Start(); Client.StartDownloadAsync(); IsDownloadCancelled = false; }
private async Task DownloadFile(string url, string to, DownloadProgress progress, CancellationToken cancelToken) { using (var resp = await DownloadClient.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, cancelToken)) { using (var inStream = await resp.Content.ReadAsStreamAsync()) using (var outStream = new FileStream(to, System.IO.FileMode.Create)) { long?totalSize = resp.Content.Headers.ContentLength; progress(0, totalSize); long transferred = 0; byte[] buf = new byte[1024 * 1024]; while (true) { int n = await inStream.ReadAsync(buf, 0, buf.Length, cancelToken); if (n == 0) { break; } await outStream.WriteAsync(buf, 0, n, cancelToken); transferred += n; progress(transferred, totalSize); } } } }
private void HoldingsDownload_Completed(DownloadClient <HoldingsResult> sender, DownloadCompletedEventArgs <HoldingsResult> e) { sender.AsyncDownloadCompleted -= this.HoldingsDownload_Completed; if (this.AsyncHoldingsDownloadCompleted != null) { this.AsyncHoldingsDownloadCompleted(this, e); } }
private void html_DownloadAsyncCompleted(DownloadClient <XDocument> sender, DownloadCompletedEventArgs <XDocument> e) { sender.AsyncDownloadCompleted -= this.html_DownloadAsyncCompleted; AsyncArgs args = (AsyncArgs)e.UserArgs; this.ConvertHtml(e.Response.Result, args); this.UploadAsync2(args); }
private void PortfolioInfoDownload_Completed(DownloadClient <PortfolioInfoResult> sender, DownloadCompletedEventArgs <PortfolioInfoResult> e) { sender.AsyncDownloadCompleted -= this.PortfolioInfoDownload_Completed; if (this.AsyncPortfolioInfoDownloadCompleted != null) { this.AsyncPortfolioInfoDownloadCompleted(this, e); } }
// ---------[ INITIALIZATION ]--------- public void OnEnable() { GetData(); FileDownloadInfo downloadInfo = DownloadClient.GetActiveModBinaryDownload(m_data.profile.modId, m_data.currentBuild.modfileId); DisplayDownload(downloadInfo); }
public static string DownloadRelease(string url) { //Download relase save to disk and return filename var client = new DownloadClient(url); var file = client.DownloadFile(); return(file); }
private void dl_DownloadAsyncCompleted(DownloadClient<System.IO.Stream> sender, DownloadCompletedEventArgs<System.IO.Stream> e) { sender.AsyncDownloadCompleted -= this.dl_DownloadAsyncCompleted; XDocument doc = null; if (e.Response.Result != null) { doc = MyHelper.ParseXmlDocument(e.Response.Result); } if (this.AsyncUploadCompleted != null) this.AsyncUploadCompleted(this, ((DefaultDownloadCompletedEventArgs<System.IO.Stream>)e).CreateNew(doc)); }
public RequestManager(ObservableSettings settings, RiZhi log) { _settings = settings; _log = log ?? throw new ArgumentNullException(nameof(log)); _downloadClient = new DownloadClient(_cachePath, _settings, _log); _cacheClient = new CacheClient(_cachePath, _log); _inProgressTasks = new ConcurrentDictionary <string, Task <ResponseBase> >(); }
private void AddPortfolioItem_Completed(DownloadClient <XParseDocument> sender, DownloadCompletedEventArgs <XParseDocument> e) { AddPfItemAsyncArgs args = (AddPfItemAsyncArgs)e.UserArgs; Portfolio pf = new PortfolioDownload().ConvertHtmlDoc(e.Response.Result); if (this.AsyncAddPortfolioItemCompleted != null) { this.AsyncAddPortfolioItemCompleted(this, ((DefaultDownloadCompletedEventArgs <XParseDocument>)e).CreateNew(pf)); } }
private async void OnStartDownloadAsync() { var dialog = new VistaFolderBrowserDialog { RootFolder = System.Environment.SpecialFolder.MyDocuments }; if ((bool)!dialog.ShowDialog()) { return; } string directory = dialog.SelectedPath; tokenSource = new CancellationTokenSource(); var token = tokenSource.Token; IsWorking = true; try { foreach (Link link in Links) { if (link.LinkStatus == Status.Finished) { continue; } currentLink = link; link.LinkStatus = Status.Downloading; string cmd = link.ExtractAudio ? $"-x --audio-format m4a {link.Url}" : link.Url; var process = new ProcessCommand(cmd, directory, token); await Task.Run(() => DownloadClient.downloadAsync(process, token), token); if (link.LinkStatus == Status.Failed) { link.Eta = "Failed"; continue; } link.LinkStatus = Status.Finished; link.Progress = 100.0; link.Eta = "Finished"; try { NormalizeName(directory); } catch (Exception) { } } } catch (OperationCanceledException) { currentLink.LinkStatus = Status.Failed; currentLink.Eta = "Canceled"; } IsWorking = false; tokenSource.Dispose(); }
static async System.Threading.Tasks.Task Main(string[] args) { var httpClient = new HttpClient(); httpClient.BaseAddress = new Uri("https://fastreport.cloud"); httpClient.DefaultRequestHeaders.Authorization = new FastReportCloudApiKeyHeader(ApiKey); var subscriptions = new SubscriptionsClient(httpClient); var rpClientTemplates = new TemplatesClient(httpClient); var rpClientExports = new ExportsClient(httpClient); var downloadClient = new DownloadClient(httpClient); var subscription = (await subscriptions.GetSubscriptionsAsync(0, 10)).Subscriptions.First(); var templateFolder = subscription.TemplatesFolder.FolderId; var exportFolder = subscription.ExportsFolder.FolderId; TemplateCreateVM templateCreateVM = new TemplateCreateVM() { Name = "box.frx", Content = TestData.BoxReport }; TemplateVM uploadedFile = await rpClientTemplates.UploadFileAsync(templateFolder, templateCreateVM); ExportTemplateTaskVM export = new ExportTemplateTaskVM() { FileName = "box.pdf", FolderId = exportFolder, Format = ExportTemplateTaskVMFormat.Pdf }; ExportVM exportedFile = await rpClientTemplates.ExportAsync(uploadedFile.Id, export) as ExportVM; string fileId = exportedFile.Id; int attempts = 3; exportedFile = rpClientExports.GetFile(fileId); while (exportedFile.Status != ExportVMStatus.Success && attempts >= 0) { await Task.Delay(1000); exportedFile = rpClientExports.GetFile(fileId); attempts--; } using (var file = await downloadClient.GetExportAsync(fileId)) { using (var pdf = File.Open("report.pdf", FileMode.Create)) { file.Stream.CopyTo(pdf); } } }
public void RetrieveYahooCompanyInfo(string symbol, ref Dictionary <string, Object> stats) { CompanyInfoDownload d1 = new CompanyInfoDownload(); DownloadClient <CompanyInfoResult> baseD1 = d1; CompanyInfoDownloadSettings settings = d1.Settings; settings.IDs = new string[] { symbol }; Response <CompanyInfoResult> resp = baseD1.Download(); SettingsBase baseSettings = baseD1.Settings; ConnectionInfo connInfo = resp.Connection; if (connInfo.State == ConnectionState.Success) { CompanyInfoResult result = resp.Result; stats.Add("Sector", result.Items[0].SectorName); stats.Add("Industry", result.Items[0].IndustryName); } else { Exception ex = connInfo.Exception; Console.WriteLine(ex.Message); } QuotesDownload d2 = new QuotesDownload(); DownloadClient <QuotesResult> baseD2 = d2; QuotesDownloadSettings settings1 = d2.Settings; settings1.IDs = new string[] { symbol }; settings1.Properties = new QuoteProperty[] { QuoteProperty.Symbol, QuoteProperty.Name }; Response <QuotesResult> resp1 = baseD2.Download(); SettingsBase baseSettings1 = baseD2.Settings; ConnectionInfo connInfo1 = resp1.Connection; if (connInfo1.State == ConnectionState.Success) { QuotesResult result = resp1.Result; stats.Add("Name", Convert.ToString(result.Items[0].Name)); } else { Exception ex = connInfo.Exception; Console.WriteLine(ex.Message); } }
/// <summary> /// Execute /// </summary> /// <param name="context">WF context</param> /// <returns></returns> protected override void Execute(NativeActivityContext context) { var url = context.GetValue <Uri>(this.SourceUrl); var filePath = context.GetValue <string>(this.DownloadFilePath); _fileName = Path.GetFileName(filePath); this._isNotifyDownloading = context.GetValue <bool>(this.NotifyDownloadProgress); var minFileSizeKB = context.GetValue <int>(this.MinFileSizeKB); var delaySeconds = context.GetValue <int>(this.DelaySeconds); //set _notifyEpisodeContentDownloadState before Notify this._notifyEpisodeContentDownloadState = context.GetExtension <INotifyEpisodeContentDownloadState>(); NotifyDownloadStart(_fileName, url); if (this.CheckFileIsOK(filePath, minFileSizeKB) == true) { this.Result.Set(context, DownloadFileResult.Exists); NotifyDownloadEnd(_fileName, DownloadFileResult.Exists); } else { DownloadClient downloadClient = new DownloadClient(); if (this._isNotifyDownloading == true) { downloadClient.DownloadProgressChanged += downloadClient_DownloadProgressChanged; } downloadClient.DownloadFileCompleted += downloadClient_DownloadFileCompleted; var task = downloadClient.DownloadFileAsync(filePath, url); task.Wait(); //autoResetEvent.WaitOne(); if (this.CheckFileIsOK(filePath, minFileSizeKB) == true) { this.Result.Set(context, DownloadFileResult.Success); NotifyDownloadEnd(_fileName, DownloadFileResult.Success); if (delaySeconds > 0) { Thread.Sleep(TimeSpan.FromSeconds(delaySeconds)); } } else { this.Result.Set(context, DownloadFileResult.Fail); NotifyDownloadEnd(_fileName, DownloadFileResult.Fail); } } }
public async Task DOCX(string filepath, long?userId) { var rpClientTemplates = new TemplatesClient(httpClient); var rpClientExports = new ExportsClient(httpClient); var downloadClient = new DownloadClient(httpClient); var templateFolder = subscription.TemplatesFolder.FolderId; var exportFolder = subscription.ExportsFolder.FolderId; TemplateCreateVM templateCreateVM = new TemplateCreateVM() { Name = "box.frx", Content = Convert.ToBase64String(File.ReadAllBytes(filepath)) }; TemplateVM uploadedFile = await rpClientTemplates.UploadFileAsync(templateFolder, templateCreateVM); ExportTemplateTaskVM export = new ExportTemplateTaskVM() { FileName = "box.docx", FolderId = exportFolder, Format = ExportTemplateTaskVMFormat.Docx }; ExportVM exportedFile = await rpClientTemplates.ExportAsync(uploadedFile.Id, export) as ExportVM; string fileId = exportedFile.Id; int attempts = 3; exportedFile = rpClientExports.GetFile(fileId); while (exportedFile.Status != ExportVMStatus.Success && attempts >= 0) { await Task.Delay(1000); exportedFile = rpClientExports.GetFile(fileId); attempts--; } using (var file = await downloadClient.GetExportAsync(fileId)) { using (var pdf = File.Open("report.docx", FileMode.Create)) { file.Stream.CopyTo(pdf); } using (var stream = File.Open("report.docx", FileMode.Open)) { await Program.tgBot.SendDocumentAsync(userId, new InputOnlineFile(stream, "report.docx")); } } //await Program.tgBot.SendDocumentAsync(userId, name); }
private void dl_DownloadAsyncCompleted(DownloadClient <System.IO.Stream> sender, DownloadCompletedEventArgs <System.IO.Stream> e) { sender.AsyncDownloadCompleted -= this.dl_DownloadAsyncCompleted; XDocument doc = null; if (e.Response.Result != null) { doc = MyHelper.ParseXmlDocument(e.Response.Result); } if (this.AsyncUploadCompleted != null) { this.AsyncUploadCompleted(this, ((DefaultDownloadCompletedEventArgs <System.IO.Stream>)e).CreateNew(doc)); } }
private void LogOutAsync_Completed(DownloadClient <XParseDocument> sender, DownloadCompletedEventArgs <XParseDocument> e) { if (e.Response.Connection.State == ConnectionState.Success) { mCookies = null; this.SetCrumb(string.Empty); if (this.PropertyChanged != null) { this.PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs("IsLoggedIn")); } if (this.LoggedStatusChanged != null) { this.LoggedStatusChanged(this, new LoginStateEventArgs(this.IsLoggedIn, e.UserArgs)); } } }
private void PreFlightCheck(DownloadClient client) { switch (client) { case DownloadClient.Nzbget: nzbgetService.CheckConnection(); break; case DownloadClient.Sabnzbd: sabnzbdService.CheckConnection(); break; default: throw new ApplicationException($"Please specify a valid download client - given: {client} - expected: sabnzbd or nzbget"); } }
private void Client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { if (CancellationToken.IsCancellationRequested) { DownloadClient.CancelAsync(); return; } Dispatcher.Invoke(() => { StatusTextBlock.FontSize = 20; double remainingMB = (e.TotalBytesToReceive - e.BytesReceived) / (1024.0 * 1024.0); StatusTextBlock.Text = string.Format("Downloaded {0}% ({1:F2}MB remaining)...", e.ProgressPercentage, remainingMB); ProgressBar.Value = e.ProgressPercentage; }); }
private void UpdateManagerDataLoaded(bool l) { if (!l) { return; } if (updateManager.IsAvailable(version)) { DownloadClient dc = new DownloadClient(); dc.DownloadCompleted += DcDownloadCompleted; dc.WebException += DcWebException; string zip = updateManager.Last.GetZIP().Replace('\r', ' '); zip = zip.Replace('\n', ' '); dc.DownloadFile(zip, ARCHIVE_TEMP); } }
private async Task <string> DownloadServerPackage( ServerBuildDownloadInfo serverInfo, CancellationToken token = default) { var pkgDownloadUrl = $"{_downloadsS3BucketUrl}/{serverInfo.PackageFileName}"; var downloadFilePath = Path.Combine(ServerDownloadPath, serverInfo.PackageDownloadFileName); var packageFilePath = Path.Combine(ServerDownloadPath, serverInfo.PackageFileName); try { var response = await DownloadClient.GetAsync(pkgDownloadUrl, HttpCompletionOption.ResponseHeadersRead, token); if (response.IsSuccessStatusCode == false) { var msg = await response.Content.ReadAsStringAsync(); throw new InvalidOperationException( $"Error downloading {pkgDownloadUrl}: {response.StatusCode} {msg}"); } using (var stream = await response.Content.ReadAsStreamAsync()) { using (var file = File.OpenWrite(downloadFilePath)) { await stream.CopyToAsync(file, token); } } File.Move(downloadFilePath, packageFilePath); return(packageFilePath); } catch (Exception) { if (File.Exists(downloadFilePath)) { IOExtensions.DeleteFile(downloadFilePath); } if (File.Exists(packageFilePath)) { IOExtensions.DeleteFile(packageFilePath); } throw; } }
private void GetClipAsync(Clip clip, Header course, int moduleId, string moduleTitle, bool list) { if (clip == null) { throw new Exception("The clip was not found. Check the clip and Try again."); } if (list) { Utils.WriteText($"\t\t{clip.Index + 1:00} - {clip.Title}", newLine: false); Utils.WriteCyanText($" -- {clip.Id}"); return; } var client = new DownloadClient(options.OutputPath, course, moduleId, moduleTitle, clip, httpClient, api.GetAccessToken); queue.Enqueue(client); }
public ActionResult ForecastImage10(string id) { DateTime correctNow = GetCurrentTimeAtJapan(); TryPraseTime(id, ref correctNow); string dirRaw = HttpContext.Server.MapPath("~/App_Data/raw/"); DownloadClient client = new DownloadClient(dirRaw); var pre10 = client.Start(correctNow - new TimeSpan(0, 10, 0)); var pre05 = client.Start(correctNow - new TimeSpan(0, 5, 0)); var pre00 = client.Start(correctNow); string next05 = GetForecast5Path(correctNow); string next10 = GetForecast10Path(correctNow); CheckDirectory(next05); if (!System.IO.File.Exists(next05)) Forecast(next05, new List<string>() { pre10.Path, pre05.Path, pre00.Path }); if (!System.IO.File.Exists(next10)) Forecast(next10, new List<string>() { pre05.Path, pre00.Path, next05 }); DumpImage(next10); return View(); }
static void Main(string[] args) { string workDir = @""; string runDir = Path.Combine(workDir, $"run_{DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss")}"); string logDir = runDir; string uri = ""; Logger.ConfigureLogger(logDir); try { DownloadClient client = new DownloadClient("1", uri, runDir, new PicWebParser()); Crawler crawler = new Crawler("1", new CrawlingController(0, 0, 0), client); crawler.StartCrawling(); } catch (Exception e) { Logger.SafeWriteError(e.ToString()); } }
/// <summary> /// /// </summary> /// <param name="settings"></param> /// <param name="deviceProfile"></param> /// <param name="authenticatedUser"></param> public PokemonGoApiClient(IApiSettings settings, IDeviceProfile deviceProfile, AuthenticatedUser authenticatedUser = null) : this() { StartTime = DateTimeOffset.UtcNow; CancellationTokenSource = new CancellationTokenSource(); RequestQueue = new BlockingCollection <RequestEnvelope>(); Player = new PlayerClient(this); Download = new DownloadClient(this); Inventory = new InventoryClient(this); Map = new MapClient(this); Fort = new FortClient(this); Encounter = new EncounterClient(this); ApiSettings = settings; DeviceProfile = deviceProfile; SetAuthenticationProvider(); AuthenticatedUser = authenticatedUser; Player.SetCoordinates(ApiSettings.DefaultPosition.Latitude, ApiSettings.DefaultPosition.Longitude, ApiSettings.DefaultPosition.Accuracy); }
private void RetrieveYahooCompanyStatistics(string symbol, ref Dictionary <string, Object> stats) { CompanyStatisticsDownload d2 = new CompanyStatisticsDownload(); DownloadClient <CompanyStatisticsResult> baseD2 = d2; CompanyStatisticsDownloadSettings settings2 = d2.Settings; settings2.ID = symbol; Response <CompanyStatisticsResult> resp2 = baseD2.Download(); SettingsBase baseSettings = baseD2.Settings; ConnectionInfo connInfo = resp2.Connection; if (connInfo.State == ConnectionState.Success) { CompanyStatisticsResult result = resp2.Result; CompanyFinancialHighlights highlights = result.Item.FinancialHighlights; stats.Add("TotalDeptPerEquity", CheckDecimalItem(Convert.ToString(highlights.TotalDeptPerEquity))); stats.Add("OperatingMarginPercent", CheckDecimalItem(Convert.ToString(highlights.OperatingMarginPercent))); stats.Add("ProfitMarginPercent", CheckDecimalItem(Convert.ToString(highlights.ProfitMarginPercent))); stats.Add("ReturnOnAssetsPercent", CheckDecimalItem(Convert.ToString(highlights.ReturnOnAssetsPercent))); stats.Add("ReturnOnEquityPercent", CheckDecimalItem(Convert.ToString(highlights.ReturnOnEquityPercent))); stats.Add("TotalDeptInMillion", CheckDecimalItem(Convert.ToString(highlights.TotalDeptInMillion)) * 1000000); stats.Add("EBITDAInMillion", CheckDecimalItem(Convert.ToString(highlights.EBITDAInMillion)) * 1000000); stats.Add("CurrentRatio", CheckDecimalItem(Convert.ToString(highlights.CurrentRatio))); stats.Add("GrossProfitInMillion", CheckDecimalItem(Convert.ToString(highlights.GrossProfitInMillion)) * 1000000); stats.Add("LeveredFreeCashFlowInMillion", CheckDecimalItem(Convert.ToString(highlights.LeveredFreeCashFlowInMillion)) * 1000000); stats.Add("OperatingCashFlowInMillion", CheckDecimalItem(Convert.ToString(highlights.OperatingCashFlowInMillion)) * 1000000); stats.Add("QuarterlyRevenueGrowthPercent", CheckDecimalItem(Convert.ToString(highlights.QuarterlyRevenueGrowthPercent))); stats.Add("QuarterlyEarningsGrowthPercent", CheckDecimalItem(Convert.ToString(highlights.QuaterlyEarningsGrowthPercent))); stats.Add("RevenuePerShare", CheckDecimalItem(Convert.ToString(highlights.RevenuePerShare))); stats.Add("TotalCashInMillion", CheckDecimalItem(Convert.ToString(highlights.TotalCashInMillion)) * 1000000); stats.Add("TotalCashPerShare", CheckDecimalItem(Convert.ToString(highlights.TotalCashPerShare)));; } else { Exception ex = connInfo.Exception; Console.WriteLine(ex.Message); } }
// 定期的に画像をクロール&学習 public ActionResult Crawl() { string dirRaw = HttpContext.Server.MapPath("~/App_Data/raw/"); DownloadClient client = new DownloadClient(dirRaw); DateTime now = GetCurrentTimeAtJapan(); var list = client.Start(now - new TimeSpan(1, 15, 0), now); LearningManager m = GetLearningManager(); string pathNeuro = GetNeuroPath(m.Filename); if (!System.IO.File.Exists(pathNeuro)) m.Initialize(); // ファイルが無い時 List<LearningImage> images = new List<LearningImage>(); foreach (var item in list) images.Add(RainImage.LoadGif(item.Path).Shrink(SCALE)); m.Learn(images); m.Save(pathNeuro); string[] files = Directory.GetFiles(dirRaw, "*.gif", SearchOption.AllDirectories); ViewBag.Message = "Files=" + files.Length + Environment.NewLine; client.StartAsync(now - new TimeSpan(3, 0, 0), now - new TimeSpan(1, 0, 0)); // 念のため return View(); }
private RainImage Forecast(string forecasted, DateTime start, DateTime end) { List<string> paths = new List<string>(); string dirRaw = HttpContext.Server.MapPath("~/App_Data/raw/"); DownloadClient client = new DownloadClient(dirRaw); var requests = client.Start(start, end); foreach (var r in requests) paths.Add(r.Path); return Forecast(forecasted, paths); }
public ActionResult PassedImage(string id) { DateTime now = GetCurrentTimeAtJapan(); TryPraseTime(id, ref now); string dirRaw = HttpContext.Server.MapPath("~/App_Data/raw/"); DownloadClient client = new DownloadClient(dirRaw); var item = client.Start(now); DumpImage(item.Path, true); return View(); }
// 特定の時間を学習させる public ActionResult Learn(string id) { DateTime now = GetCurrentTimeAtJapan(); TryPraseTime(id, ref now); string dirRaw = HttpContext.Server.MapPath("~/App_Data/raw/"); DownloadClient client = new DownloadClient(dirRaw); var list = client.SearchLocal(now - new TimeSpan(0, 10, 0), now + new TimeSpan(0, 5, 0)); LearningManager m = GetLearningManager(); List<LearningImage> images = new List<LearningImage>(); foreach (var item in list) images.Add(RainImage.LoadGif(item.Path).Shrink(SCALE)); if (images.Count < 4) return View("Error"); m.Learn(images); m.Save(GetNeuroPath(m.Filename)); var forecasted = m.Forecast(images.Take(m.HistoryLimit).ToList()); string path05 = GetForecast5Path(now, ".detail.png"); if (forecasted is RainImage) (forecasted as RainImage).SavePngDetail(path05); DumpImage(path05); return View(); }
public async Task<ManifestResponse> ManifestAysnc(string id) { string url=$"http://www.dr.dk/mu-online/api/1.3/manifest/{id}"; DownloadClient<ManifestResponse> dc = new DownloadClient<ManifestResponse>(); return await dc.DownloadAndConvert(url); }
/// <summary> /// Free text search method. Searches Series Titles starting with the supplied query. The result is ordered alphabetically by series title, unless otherwise is specified in paramters. /// </summary> /// <param name="query">Search query SeriesTitle</param> /// <param name="onlineGenreTexts"> Comma seperated genre list to filter search on.List of online genres : /// "Drama" ,"Dokumentar", "Livsstil", "Kultur", "Natur & viden", "Nyheder & aktualitet", "Sport" and "Underholdning". /// (Optional)</param> /// <param name="channels">Comma seperated channel slug or whatsOnUri list. (Optional)</param> /// <param name="orderBy">Supported values are "Title" and "PrimaryBroadcastDay". Default sort order is ascending by title. (Optional)</param> /// <param name="orderDescending">True will sort descending, and false will sort ascending. This value is only use, if orderBy has a value. Default is false. (Optional)</param> /// <param name="excludeGeofiltered">Filter to exclude geofiltered programcards.Default is false. (Optional)</param> /// <param name="limit">Page size, must be less than 75. (Optional)</param> /// <param name="offset">Page offset. (optional)</param> /// <param name="assetTarget"></param> /// <returns></returns> public async Task<ListResponse> SearchProgramcardsLatestEpisodeWithBroadcastAsync(string query, string onlineGenreTexts = "", string channels = "", string orderBy = "", bool orderDescending = false, bool excludeGeofiltered = false, int limit = 5, int offset = 0, string assetTarget = "") { string url = $"http://www.dr.dk/mu-online/api/1.3/search/tv/programcards-latest-episode-with-broadcast/series-title-starts-with/{query}?limit={limit}&orderdescending={orderDescending}&excludegeofiltered={excludeGeofiltered}"; if(!string.IsNullOrEmpty(onlineGenreTexts)) { url += $"&onlinegenretexts={onlineGenreTexts}"; } if(!string.IsNullOrEmpty(channels)) { url += $"&channels={channels}"; } if(!string.IsNullOrEmpty(orderBy)) { url += $"&orderby={orderBy}"; } if(offset > 0) { url += $"&offset={offset}"; } if(!string.IsNullOrEmpty(assetTarget)) { url += $"&assettarget={assetTarget}"; } DownloadClient<ListResponse> dc = new DownloadClient<ListResponse>(); return await dc.DownloadAndConvert(url); }
private void HoldingsDownload_Completed(DownloadClient<HoldingsResult> sender, DownloadCompletedEventArgs<HoldingsResult> e) { sender.AsyncDownloadCompleted -= this.HoldingsDownload_Completed; if (this.AsyncHoldingsDownloadCompleted != null) this.AsyncHoldingsDownloadCompleted(this, e); }
private void PortfolioInfoDownload_Completed(DownloadClient<PortfolioInfoResult> sender, DownloadCompletedEventArgs<PortfolioInfoResult> e) { sender.AsyncDownloadCompleted -= this.PortfolioInfoDownload_Completed; if (this.AsyncPortfolioInfoDownloadCompleted != null) this.AsyncPortfolioInfoDownloadCompleted(this, e); }
/// <summary> /// /// </summary> /// <param name="query"></param> /// <param name="orderBy"></param> /// <param name="orderDescending"></param> /// <param name="limitPrograms"></param> /// <param name="limitEpisodes"></param> /// <returns cref="ListQuickSearchResponse"></returns> public async Task<ListQuickSearchResponse> ListQuickSearchAsync(string query, string orderBy = "", bool orderDescending = false, int limitPrograms = 5, int limitEpisodes = 5) { // Ugly if else structure string url = $"http://www.dr.dk/mu-online/api/1.3/search/tv/programcards-latest-episode-with-broadcast/series-title-starts-with/{query}?limit={limitPrograms}&limitepisodes{limitEpisodes}"; if(!string.IsNullOrEmpty(orderBy)) { url += $"&orderby={orderBy}&orderdescending={orderDescending}"; } DownloadClient<ListQuickSearchResponse> dc = new DownloadClient<ListQuickSearchResponse>(); return await dc.DownloadAndConvert(url); }
private void AddPortfolioItem_Completed(DownloadClient<XDocument> sender, DownloadCompletedEventArgs<XDocument> e) { AddPfItemAsyncArgs args = (AddPfItemAsyncArgs)e.UserArgs; Portfolio pf = new PortfolioDownload().ConvertHtmlDoc(e.Response.Result); if (this.AsyncAddPortfolioItemCompleted != null) this.AsyncAddPortfolioItemCompleted(this, ((DefaultDownloadCompletedEventArgs<XDocument>)e).CreateNew(pf)); }
/// <summary> /// Gets a ProgramCard by id /// </summary> /// <param name="id">Urn or Slug</param> /// <returns>Programcard</returns> public async Task<Programcard.Programcard> GetProgramcard(string id) { string url = $"http://www.dr.dk/mu-online/api/1.3/programcard/{id}"; DownloadClient<Programcard.Programcard> dc = new DownloadClient<Programcard.Programcard>(); return await dc.DownloadAndConvert(url); }
/// <summary> /// Gets an image for a programcard. Falls back to series image, then the image from the override bundle id if specified, otherwise to the PrimaryChannel image, if the bundles does not have an image. /// </summary> /// <param name="id">Programcard slug or urn.</param> /// <param name="forcechanneloverrideid">Optional fallback bundle slug or urn. Can be used to override image from channel bundle.</param> /// <returns cref="BarResponse"></returns> public async Task<BarResponse> BarImageForProgramcardAsync(string id, string forcechanneloverrideid) { string url=$"http://www.dr.dk/mu-online/api/1.3/bar/helper/get-image-for-programcard/{id}/{forcechanneloverrideid}"; DownloadClient<BarResponse> dc = new DownloadClient<BarResponse>(); return await dc.DownloadAndConvert(url); }
/// <summary> /// Returns a service message for a given id. If it is enabled otherwise null. /// </summary> /// <param name="id">Configuration id</param> /// <returns></returns> public async Task<ConfigurationResponse> ConfigurationServiceMessageAsync(string id) { string url=$"http://www.dr.dk/mu-online/api/1.3/configuration/service-message/%7Bid%7D"; DownloadClient<ConfigurationResponse> dc = new DownloadClient<ConfigurationResponse>(); return await dc.DownloadAndConvert(url); }
/// <summary> /// Gets all active tv channels. DR1, DR2, DR3, DR Ramasjang, DR Ultra and DR K /// </summary> /// <returns cref="ChannelResponse"></returns> public async Task<ChannelResponse> ChannelAllActiveDrTvAsync() { string url="http://www.dr.dk/mu-online/api/1.3/channel/all-active-dr-tv-channels"; DownloadClient<ChannelResponse> dc = new DownloadClient<ChannelResponse>(); return await dc.DownloadAndConvert(url); }
/// <summary> /// Return info for a given channel /// </summary> /// <param name="id">Channel slug, urn or WhatsOnUri.</param> /// <returns cref="ChannelResponse"></returns> public async Task<ChannelResponse> ChannelAsync(string id) { string url=$"http://www.dr.dk/mu-online/api/1.3/channel/{id}"; DownloadClient<ChannelResponse> dc = new DownloadClient<ChannelResponse>(); return await dc.DownloadAndConvert(url); }
// TODO: channel is channelSlug (build enum with these for easier use in the future /// <summary> /// /// </summary> /// <param name="limit">Page size, must be less than 48. (Optional)</param> /// <param name="offset">Page offset default is 0. (Optional)</param> /// <param name="channel">Channel to select last chance from. Default is all DR Channels except children channels. (Optional)</param> /// <returns></returns> public async Task<ListResponse> ListLastChanceAsync(int limit = 5, int offset = 0, string channel = "") { string url=$"http://www.dr.dk/mu-online/api/1.3/list/view/lastchance?limit={limit}&offset={offset}&channel={channel}"; DownloadClient<ListResponse> dc = new DownloadClient<ListResponse>(); return await dc.DownloadAndConvert(url); }
/// <summary> /// Gets a paged list of most viewed programcards within the latest 7 days filtered by channel and channeltype. Lists are paged by 12 per default. /// </summary> /// <param name="channel">Channel slug e.g. dr1, dr2 or whatsOnUri</param> /// <param name="channelType">TV or RADIO</param> /// <param name="limit">Page size, must be less than 48. (Optional)</param> /// <param name="offset">Page offset. (Optional)</param> /// <returns cref="ListResponse"></returns> public async Task<ListResponse> ListMostViewedAsync(string channel, string channelType = "TV", int limit = 5, int offset = 0) { string url= $"http://www.dr.dk/mu-online/api/1.3/list/view/mostviewed?channel={channel}&channeltype={channelType}&limit={limit}&offset={offset}"; DownloadClient<ListResponse> dc = new DownloadClient<ListResponse>(); return await dc.DownloadAndConvert(url); }
/// <summary> /// Gets suggested programs which relates to the supplied programcard id. Standard for not logged in users /// </summary> /// <param name="programcardId">Urn or Slug for programcard</param> /// <param name="limit">Page size. Default value 10. (Optional)</param> /// <param name="offset">Page offset. Default value 0. (Optional)</param> /// <param name="channel">Required for Ramasjang (dr-ramasjang) and Ultra (dr-ultra). But not for other channels</param> /// <returns cref="ListResponse">A list cotaining the obtained suggestions based on the progg</returns> public async Task<ListResponse> ListSuggestions(string programcardId, int limit = 5, int offset = 0, string channel = "") { string url = $"http://www.dr.dk/mu-online/api/1.3/list/view/suggestions?programcardid={programcardId}&limit={limit}&offset={offset}&channel={channel}"; DownloadClient<ListResponse> dc = new DownloadClient<ListResponse>(); return await dc.DownloadAndConvert(url); }
// TODO: 'limit' is limited to 60 /// <summary> /// Gets a paged list by either slug or urn. /// </summary> /// <param name="id">Bundle slug or urn</param> /// <param name="limit">Page size, must be less than 60. (Optional)</param> /// <param name="offset">Page offset. (Optional)</param> /// <param name="excludedId">An id to exclude from the list. This can either be an urn or a slug (Optional)</param> /// <returns cref="ListResponse"></returns> /// For some reason this currently doesn't support any optional parameteres. BUG on DR.dk/muTest API. public async Task<ListResponse> ListAsync(string id, int limit = 5, int offset = 0, string excludedId = "") { string url=$"http://www.dr.dk/mu-online/api/1.3/list/{id}?limit={limit}&offset={offset}&excludeid={excludedId}"; //string url = $"http://www.dr.dk/mu-online/api/1.3/list/{id}"; DownloadClient<ListResponse> dc = new DownloadClient<ListResponse>(); var res = await dc.DownloadAndConvert(url); res.Offset = offset; res.Limit = limit; return res; }
private void LogOutAsync_Completed(DownloadClient<XDocument> sender, DownloadCompletedEventArgs<XDocument> e) { if (e.Response.Connection.State == ConnectionState.Success) { mCookies = null; this.SetCrumb(string.Empty); if (this.PropertyChanged != null) this.PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs("IsLoggedIn")); if (this.LoggedStatusChanged != null) this.LoggedStatusChanged(this, new LoginStateEventArgs(this.IsLoggedIn, e.UserArgs)); } }
/// <summary> /// Overview list of themes. Combines first programcard from each theme into one list. /// Series information on each MuListItem is info from theme and not from the belonging series. /// Changed the overview collection only to include repremiere themes according to aggrement with Sille /// </summary> /// <param name="limit">Default value is 5</param> /// <param name="offset">Default value is 0</param> /// <returns></returns> public async Task<ListResponse> ListThemesOverviewAsync(int limit = 5, int offset = 0) { string url = $"http://www.dr.dk/mu-online/api/1.3/list/view/themesoverview?limit={limit}&offset={offset}"; DownloadClient<ListResponse> dc = new DownloadClient<ListResponse>(); return await dc.DownloadAndConvert(url); }