public Client(string baseUrl, HttpClient httpClient) { DisunityClient = new DisunityClient(baseUrl, httpClient); ModListClient = new ModListClient(baseUrl, httpClient); ModPublishingClient = new ModPublishingClient(baseUrl, httpClient); OrgMemberClient = new OrgMemberClient(baseUrl, httpClient); TargetClient = new TargetClient(baseUrl, httpClient); UploadClient = new UploadClient(baseUrl, httpClient); }
public ApiClient(IConfiguration config, HttpClient httpClient) { HttpClient = httpClient; DisunityClient = new DisunityClient(config, httpClient); ModListClient = new ModListClient(config, httpClient); ModPublishingClient = new ModPublishingClient(config, httpClient); OrgMemberClient = new OrgMemberClient(config, httpClient); TargetClient = new TargetClient(config, httpClient); UploadClient = new UploadClient(config, httpClient); }
public override async Task <bool> Process(PipeContext context) { if (context == null) { throw new System.ArgumentNullException("context"); } if (OnWillProcess != null && !OnWillProcess(context)) { return(true); } if (client == null) { var ipAddress = await Dns.GetHostAddressesAsync(Host); var ipv4Addr = ipAddress.FirstOrDefault((v) => v.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork); client = GetClientByHost(HostType.Ftp); client.Host = ipv4Addr.ToString(); client.UserName = UserName; client.Password = Password; await client.Initialize(); } List <UploadGroupInfo> needToUpload = new List <UploadGroupInfo>(); needToUpload.Add(new UploadGroupInfo() { localPath = RemoteBuildPath, remotePath = RemoteLoadPath, files = Directory.GetFiles(RemoteBuildPath, "*.*", SearchOption.AllDirectories) }); bool success = true; try { await UploadGroups(client, needToUpload); } catch (System.Exception e) { success = false; Debug.LogException(e); } finally { await client.Release(); client = null; } return(success); }
public static async Task UploadGroups(IUploadClient uploader, List <UploadGroupInfo> uploadGroups) { int allFileCount = 0; uploadGroups.ForEach(v => allFileCount += v.files.Length); int uploadedCount = 0; for (int i = 0; i < uploadGroups.Count; i++) { var groupBuildPath = uploadGroups[i].localPath; var groupLoadPath = uploadGroups[i].remotePath; var files = uploadGroups[i].files; string basePath = groupBuildPath.Replace('\\', '/'); foreach (var file in files) { var newFile = file.Replace('\\', '/'); if (!newFile.StartsWith(basePath)) { Debug.LogFormat("{0} not at path::{1}", newFile, basePath); continue; } var relPath = newFile.Substring(basePath.Length); var remoteFile = (groupLoadPath + relPath).Replace('\\', '/'); try { bool success = await uploader.UploadFile(newFile, remoteFile); uploadedCount++; EditorUtility.DisplayProgressBar("上传文件", newFile, (float)uploadedCount / allFileCount); if (success) { Debug.LogFormat("上传成功,{0}", remoteFile); } else { Debug.LogErrorFormat("上传失败,{0}", newFile); } } catch (System.Exception e) { Debug.LogErrorFormat("上传失败,{0},{1}", remoteFile, e.Message); } } EditorUtility.ClearProgressBar(); } }
public UploadClient() { switch (new SettingsBuilder().Build().UploadService.ToLower()) { case UploadServices.IMAGESHACK: _currentClient = new ImageShackClient(); break; case UploadServices.IMAGEBB: _currentClient = new ImageBBClient(); break; } }