public ProcessingContext Run(ProcessingContext context) { Console.WriteLine("Loading Data..."); var locationData = _httpDownloader.Download(_webApiConfig.LocationDataUrl); context.Rows = JsonConvert.DeserializeObject <List <Data> >(locationData); var locationSettings = _httpDownloader.Download(_webApiConfig.LocationSettingsUrl); context.LocationSettings = JsonConvert.DeserializeObject <LocationSettings>(locationSettings); return(context); }
public void MustDecodeXml(string url) { var httpResponse = _downloader.Download(new HttpGetRequest(url, new HttpHeadersCollection())).Result; var decodedResult = _decoder.DecodeContent(httpResponse); Assert.True(decodedResult != null); }
public void MustGetValidResponse(string url) { var downloader = new HttpDownloader(); var response = downloader.Download(new HttpGetRequest(url, new HttpHeadersCollection())).Result; Assert.True(response != null); }
/// <summary> /// 显示陌生人详情 /// </summary> /// <param name="userId">UserId</param> private void ShowStrangerDetial(string userId) { var dclient = APIHelper.GetUserDetialAsync(userId);//详情 LogHelper.log.Info("陌生用户GetUserDetial" + userId); dclient.UploadDataCompleted += (s, res) => { var user = JsonConvert.DeserializeObject <JsonuserDetial>(Encoding.UTF8.GetString(res.Result)); var tmpFri = user.data.ConvertToDataFriend(); if (tmpFri != null) { Friend = user.data; var downloads = new List <DownLoadFile>(); downloads.Add(new DownLoadFile() { Jid = userId, Token = userId, Name = user.data.nickname, Type = DownLoadFileType.Image, LocalUrl = Applicate.LocalConfigData.GetDownloadAvatorPath(userId), ShouldDeleteWhileFileExists = true }); //下载头像 HttpDownloader.Download(downloads, (file) => { switch (file.State) { case DownloadState.Successed: App.Current.Dispatcher.Invoke(() => { Friend.userId = file.Jid; }); break; case DownloadState.Error: break; default: break; } }); if (!string.IsNullOrWhiteSpace(user.data._remarkName)) { RemarkName = user.data._remarkName; } else { RemarkName = Friend.remarkName; } var stranger = new DataOfFriends(); stranger = user.data.ToDataOfFriend(); stranger.status = 0; stranger.AutoInsert(); } }; }
private void DownlaodNext() { _lastReceive = 0; DownloadFile file = _ques.Dequeue(); label1.Text = "檔案來源 : " + file.HttpURL; label2.Text = "下載目的 : " + file.TargetPath; _downloader.Download(file); }
public void CookieContainerCanParseSetCookieHeader(string url) { var downloader = new HttpDownloader(); var response = downloader.Download(new HttpGetRequest(url, new HttpHeadersCollection())).Result; var cookieContainer = new CookieContainer(); var uri = new Uri(url); string setCookieHeader; response.Headers.TryGetValue("Set-Cookie", out setCookieHeader); cookieContainer.SetCookies(uri, setCookieHeader); Assert.DoesNotThrow(() => cookieContainer.GetCookieHeader(uri)); }
/// <summary> /// 初始化下载类 /// </summary> /// <param name="url">下载文件的URL地址</param> /// <param name="savePath">保存文件的本地地址</param> /// <param name="version">URL对应文件的版本号</param> public Downloader(string url, string savePath, string version = null) { _url = url; _savePath = savePath; string saveDir = Path.GetDirectoryName(savePath); if (Directory.Exists(saveDir) == false) { Directory.CreateDirectory(saveDir); } if (null != version) { string flag; if (url.Contains("?")) { flag = "&"; } else { flag = "?"; } url += string.Format("{0}unity_download_ver={1}", flag, version); } try { Uri uri = new Uri(url); var serverPoint = ServicePointManager.FindServicePoint(uri); serverPoint.ConnectionLimit = downloadConnectionLimit; _progress = 0; _lastProgressChangedDT = DateTime.Now; _httpDownloader = new HttpDownloader(url, savePath); _httpDownloader.onProgress += OnDownloadProgress; _httpDownloader.onComplete += OnDownloadComplete; _httpDownloader.Download(); } catch (Exception ex) { _isDone = true; _error = ex.Message; } }
private void AquireRemoteBanner(Data data) { _logger.LogDebug(string.Format("Aquiring the remote banner image from {0}", data.BannerData.ImageUrl)); var coroutine = Threading.StartThreadCoroutine(() => { CancellationTokenSource source = new CancellationTokenSource(); var downloader = new HttpDownloader(data.BannerFilePath, new string[] { data.BannerData.ImageUrl }); try { UnityDispatcher.Invoke(() => { MainAnimator.SetBool(AnimationLoadingParameter, true); }); downloader.Download(source.Token); return(true); } catch (Exception) { return(false); } }, (bool result) => { if (result) { CachedBannerPath = data.BannerFilePath; CachedBannerModificationDate = data.BannerData.ModificationDate; MainAnimator.SetBool(AnimationLoadingParameter, false); MainAnimator.SetTrigger(AnimationSwitchTrigger); LoadBannerImage(data.BannerFilePath, NewImage); } }); StartCoroutine(coroutine); }
private void OnSearchComplete(object sender, UploadDataCompletedEventArgs e) { if (e.Error == null) { JsonNerbyuser resusers = new JsonNerbyuser(); var str = Encoding.UTF8.GetString(e.Result); //转byte为字符串 resusers = JsonConvert.DeserializeObject <JsonNerbyuser>(str); //反序列化 if (resusers.resultCode == 1) { List <DownLoadFile> files = new List <DownLoadFile>(); if (resusers.data.Count > 0) { for (int i = 0; i < resusers.data.Count; i++) { AccountList.Add(resusers.data[i]); //这里需要把特殊账号 排除出来。 string localpath = Applicate.LocalConfigData.GetDisplayAvatorPath(resusers.data[i].userId); if (!File.Exists(localpath))//添加需要下载的头像 { files.Add(new DownLoadFile { Jid = resusers.data[i].userId, Name = resusers.data[i].nickname, Token = resusers.data[i].userId, ShouldDeleteWhileFileExists = true, LocalUrl = localpath, Type = DownLoadFileType.Image }); } } HttpDownloader.Download(files, (item) => { switch (item.State) { case DownloadState.Successed: var tmp = AccountList.FirstOrDefault(a => a.userId == item.Jid); if (tmp != null) { App.Current.Dispatcher.Invoke(() => { tmp.userId = item.Jid; //下载完成后刷新头像 }); } break; case DownloadState.Error: break; default: break; } }); } else { pageNum--; } } } else { SnackBar.Enqueue("错误:" + e.Error.Message); } ShowLoadingProgressBar(false);//禁用按钮并显示 }
public void Update(CancellationToken cancellationToken) { _logger.LogDebug("Executing content repair strategy."); var installedVersionId = _context.App.GetInstalledVersionId(); string metaDestination = _context.App.DownloadDirectory.GetDiffPackageMetaPath(installedVersionId); var commandFactory = new AppUpdaterCommandFactory(); var validateLicense = commandFactory.CreateValidateLicenseCommand(_context); validateLicense.Prepare(_status, cancellationToken); validateLicense.Execute(cancellationToken); var geolocateCommand = commandFactory.CreateGeolocateCommand(); geolocateCommand.Prepare(_status, cancellationToken); geolocateCommand.Execute(cancellationToken); var resource = _context.App.RemoteData.GetContentPackageResource( installedVersionId, validateLicense.KeySecret, geolocateCommand.CountryCode, cancellationToken); if (!resource.HasMetaUrls()) { throw new ArgumentException("Cannot execute content repair strategy without meta files."); } _logger.LogDebug("Downloading the meta file."); var downloader = new HttpDownloader(metaDestination, resource.GetMetaUrls()); downloader.Download(cancellationToken); ICheckVersionIntegrityCommand checkVersionIntegrityCommand = commandFactory.CreateCheckVersionIntegrityCommand(installedVersionId, _context, true, true, cancellationToken); checkVersionIntegrityCommand.Prepare(_status, cancellationToken); checkVersionIntegrityCommand.Execute(cancellationToken); var meta = Pack1Meta.ParseFromFile(metaDestination); FileIntegrity[] filesIntegrity = checkVersionIntegrityCommand.Results.Files; var contentSummary = _context.App.RemoteMetaData.GetContentSummary(installedVersionId, cancellationToken); foreach (var invalidVersionIdFile in filesIntegrity.Where(x => x.Status == FileIntegrityStatus.InvalidVersion).ToArray()) { var fileName = invalidVersionIdFile.FileName; var file = contentSummary.Files.First(x => x.Path == fileName); var localPath = _context.App.LocalDirectory.Path.PathCombine(file.Path); string actualFileHash = HashCalculator.ComputeFileHash(localPath); if (actualFileHash != file.Hash) { FileOperations.Delete(localPath, cancellationToken); _context.App.LocalMetaData.RegisterEntry(fileName, installedVersionId); invalidVersionIdFile.Status = FileIntegrityStatus.MissingData; } else { _context.App.LocalMetaData.RegisterEntry(fileName, installedVersionId); invalidVersionIdFile.Status = FileIntegrityStatus.Ok; } } Pack1Meta.FileEntry[] brokenFiles = filesIntegrity // Filter only files with invalid size, hash or missing entirely .Where(f => f.Status == FileIntegrityStatus.InvalidHash || f.Status == FileIntegrityStatus.InvalidSize || f.Status == FileIntegrityStatus.MissingData) // Map to file entires from meta .Select(integrity => meta.Files.SingleOrDefault(file => file.Name == integrity.FileName)) // Filter only regular files .Where(file => file.Type == Pack1Meta.RegularFileType) .ToArray(); if (brokenFiles.Length == 0) { _logger.LogDebug("Nothing to repair."); return; } _logger.LogDebug(string.Format("Broken files count: {0}", brokenFiles.Length)); IRepairFilesCommand repairCommand = commandFactory.CreateRepairFilesCommand( installedVersionId, _context, resource, brokenFiles, meta); repairCommand.Prepare(_status, cancellationToken); repairCommand.Execute(cancellationToken); }
private static PushDocument CreateDocumentFromRecord(GsaFeedRecord p_Record, bool p_DownloadContent, string p_ParentId, string p_fileExt) { IDictionary <string, JToken> metadata = p_Record.ConvertMetadata(); if (p_Record.DisplayUrl == null) { p_Record.DisplayUrl = p_Record.Url; } p_Record.Url = p_Record.Url.Replace("&", "|"); metadata.Add("clickableuri", p_Record.DisplayUrl); metadata.Add(nameof(p_Record.DisplayUrl), p_Record.DisplayUrl); metadata.Add(nameof(p_Record.Lock), p_Record.Lock); metadata.Add(nameof(p_Record.MimeType), p_Record.MimeType); metadata.Add(nameof(p_Record.PageRank), p_Record.PageRank); metadata.Add(nameof(p_Record.Scoring), p_Record.Scoring); metadata.Add(nameof(p_Record.Url), p_Record.Url); metadata.Add(nameof(p_Record.AuthMethod), p_Record.AuthMethod.ToString()); metadata.Add(nameof(p_Record.CrawlImmediately), p_Record.CrawlImmediately); metadata.Add(nameof(p_Record.CrawlOnce), p_Record.CrawlOnce); PushDocument document = new PushDocument(p_Record.Url) { ModifiedDate = p_Record.LastModified ?? DateTime.MinValue, Metadata = metadata, ParentId = p_ParentId, FileExtension = p_fileExt }; if (p_Record.Acl != null) { DocumentPermissionSet currentDocSet = new DocumentPermissionSet(); PermissionIdentity denyGroup = new PermissionIdentity(p_Record.Url + DISALLOW_GROUP, PermissionIdentityType.VirtualGroup); PermissionIdentity allowGroup = new PermissionIdentity(p_Record.Url + ALLOW_GROUP, PermissionIdentityType.VirtualGroup); currentDocSet.DeniedPermissions.Add(denyGroup); currentDocSet.AllowedPermissions.Add(allowGroup); DocumentPermissionLevel currentDocLevel = new DocumentPermissionLevel(); currentDocLevel.PermissionSets.Add(currentDocSet); if (p_Record.Acl.ParentAcl != null) { GsaFeedAcl currentAcl = p_Record.Acl; List <DocumentPermissionLevel> allLevels = new List <DocumentPermissionLevel>(); allLevels.Add(currentDocLevel); int currentLevelIndex = 0; while (currentAcl.ParentAcl != null) { GsaFeedAcl curParentAcl = currentAcl.ParentAcl; DocumentPermissionSet curParentDocSet = new DocumentPermissionSet(); PermissionIdentity parentDenyGroup = new PermissionIdentity(curParentAcl.DocumentUrl + DISALLOW_GROUP, PermissionIdentityType.VirtualGroup); PermissionIdentity parentAllowGroup = new PermissionIdentity(curParentAcl.DocumentUrl + ALLOW_GROUP, PermissionIdentityType.VirtualGroup); //We sill always need the parents in a different set curParentDocSet.DeniedPermissions.Add(parentDenyGroup); curParentDocSet.AllowedPermissions.Add(parentAllowGroup); switch (curParentAcl.InheritanceType) { case GsaFeedAclInheritance.BothPermit: //The parent and the document are in two different sets allLevels.ElementAt(currentLevelIndex).PermissionSets.Add(curParentDocSet); break; case GsaFeedAclInheritance.ChildOverrides: //The parent is in a lower level than the current document DocumentPermissionLevel parentLowerDocLevel = new DocumentPermissionLevel(); parentLowerDocLevel.PermissionSets.Add(curParentDocSet); //We are adding our self after the children currentLevelIndex++; allLevels.Insert(currentLevelIndex, parentLowerDocLevel); break; case GsaFeedAclInheritance.ParentOverrides: //The parent is in a higher level than the current document //on doit ajouter avant l'enfant DocumentPermissionLevel parentHigherDocLevel = new DocumentPermissionLevel(); parentHigherDocLevel.PermissionSets.Add(curParentDocSet); allLevels.Insert(currentLevelIndex, parentHigherDocLevel); break; case GsaFeedAclInheritance.LeafNode: //The document is not suppose to have inheritance from a leaf node ConsoleUtilities.WriteLine("> Warning: You are trying to have inheritance on a LeafNode. Document in error: {0}", ConsoleColor.Yellow, p_Record.Url); curParentAcl.ParentAcl = null; break; } currentAcl = curParentAcl; } //Now we push the permissions foreach (DocumentPermissionLevel documentPermissionLevel in allLevels) { document.Permissions.Add(documentPermissionLevel); } } else { //We might need to add the parent level before, so we will not default this action. document.Permissions.Add(currentDocLevel); } } if (p_DownloadContent) { string content = s_HttpDownloader.Download(p_Record.Url); PushDocumentHelper.SetCompressedEncodedContent(document, Compression.GetCompressedBinaryData(content)); } else { if (p_Record.Content.Encoding == GsaFeedContentEncoding.Base64Compressed) { PushDocumentHelper.SetCompressedEncodedContent(document, p_Record.Content.Value.Trim(Convert.ToChar("\n"))); } else { PushDocumentHelper.SetContent(document, p_Record.Content.GetDecodedValue()); } } return(document); }