当前位置: 首页>>代码示例>>C#>>正文


C# JsonServiceClient.PostFile方法代码示例

本文整理汇总了C#中JsonServiceClient.PostFile方法的典型用法代码示例。如果您正苦于以下问题:C# JsonServiceClient.PostFile方法的具体用法?C# JsonServiceClient.PostFile怎么用?C# JsonServiceClient.PostFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JsonServiceClient的用法示例。


在下文中一共展示了JsonServiceClient.PostFile方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DeployApp

        public static void DeployApp(string endpoint, string appName)
        {
            try
            {
                JsonServiceClient client = new JsonServiceClient(endpoint);

                Console.WriteLine("----> Compressing files");
                byte[] folder = CompressionHelper.CompressFolderToBytes(Environment.CurrentDirectory);

                Console.WriteLine("----> Uploading files (" + ((float)folder.Length / (1024.0f*1024.0f)) + " MB)");

                File.WriteAllBytes("deploy.gzip", folder);
                client.PostFile<int>("/API/Deploy/" + appName, new FileInfo("deploy.gzip"), "multipart/form-data");
                File.Delete("deploy.gzip");

                DeployAppStatusRequest request = new DeployAppStatusRequest() { AppName = appName };
                DeployAppStatusResponse response = client.Get(request);
                while (!response.Completed)
                {
                    Console.Write(response.Log);
                    response = client.Get(request);
                }
            }
            catch (WebServiceException e)
            {
                Console.WriteLine(e.ResponseBody);
                Console.WriteLine(e.ErrorMessage);
                Console.WriteLine(e.ServerStackTrace);
            }
        }
开发者ID:zanders3,项目名称:katla,代码行数:30,代码来源:DeployAppClient.cs

示例2: _btnExport_Click

        private void _btnExport_Click(object sender, EventArgs e)
        {
            try 
            {
                if (string.IsNullOrEmpty(_txtOutputFileName.Text))
                {
                    MessageBox.Show("Please enter an output file name");
                    return;
                }
                if(_chkPublishToWebsite.Checked && string.IsNullOrEmpty(_txtPublishUrl.Text))
                {
                    MessageBox.Show("Please enter a publish URL");
                    return;
                }

                var deployStateDirectory = Path.Combine(_workingDirectory,"states");
                if(!Directory.Exists(deployStateDirectory))
                {
                    MessageBox.Show("No deploy history found");
                    return;
                }
                var stateFileList = Directory.GetFiles(deployStateDirectory, "*.json");
                if(stateFileList.Length == 0)
                {
                    MessageBox.Show("No deploy history found");
                    return;
                }
                var exportDirectory = Path.Combine(_workingDirectory, "exports", Guid.NewGuid().ToString());
                if (!Directory.Exists(exportDirectory))
                {
                    Directory.CreateDirectory(exportDirectory);
                }
                foreach (var fileName in stateFileList)
                {
                    string exportFileName = Path.Combine(exportDirectory, Path.GetFileName(fileName));
                    File.Copy(fileName, exportFileName);
                }
                string zipPath = _txtOutputFileName.Text;
                var zipper = _diFactory.CreateInjectedObject<IZipper>();
                zipper.ZipDirectory(exportDirectory, zipPath);

                if(_chkPublishToWebsite.Checked)
                {
                    var url = _txtPublishUrl.Text;
                    if (!url.EndsWith("/"))
                    {
                        url += "/";
                    }
                    if (!url.EndsWith("/api/", StringComparison.CurrentCultureIgnoreCase))
                    {
                        url += "api/";
                    }
                    var deployFile = new DeployFileDto
                    {
                        FileData = File.ReadAllBytes(zipPath),
                        FileName = Path.GetFileName(zipPath)
                    };

                    Cookie authCookie = null;
                    if (!string.IsNullOrEmpty(_txtUserName.Text) && !string.IsNullOrEmpty(_txtPassword.Text))
                    {
                        authCookie = GetAuthCookie(url, _txtUserName.Text, _txtPassword.Text);
                    }
                
                    using (var client = new JsonServiceClient(url))
			        {
				        var fileToUpload = new FileInfo(zipPath);
						client.AllowAutoRedirect = false;
				        client.Credentials = System.Net.CredentialCache.DefaultCredentials;
				        client.Timeout = TimeSpan.FromMinutes(2);
				        client.ReadWriteTimeout = TimeSpan.FromMinutes(2);
                        if(authCookie != null)
                        {  
                            client.CookieContainer.Add(authCookie);
                        }

                        var offlineDeployment = client.Get<OfflineDeployment>(url + "deploy/offline?deployBatchRequestId=" + _batchRequest.Id);
                        if(offlineDeployment == null)
                        {
                            throw new Exception("Could not find offline deployment record for batch request ID " + _batchRequest.Id);
                        }

				        var fileResponse = client.PostFile<DeployFileDto>(url + "file", fileToUpload, MimeTypes.GetMimeType(fileToUpload.Name));

                        var updateRequest = new OfflineDeployment
                        {
                            Id = offlineDeployment.Id,
                            DeployBatchRequestId = _batchRequest.Id,
                            ResultFileId = fileResponse.Id
                        };
                        client.Post<OfflineDeployment>(url + "deploy/offline", updateRequest);
                    }
                }
                MessageBox.Show("Export Complete");
            }
            catch (Exception err)
            {
                WinFormsHelper.DisplayError("Error exporting history", err);
            }
        }
开发者ID:gsbastian,项目名称:Sriracha.Deploy,代码行数:100,代码来源:ExportHistoryForm.cs

示例3: PublishZip

		private DeployBuild PublishZip(string apiUrl, string projectId, string componentId, string branchId, string version, string zipPath, string userName, string password)
		{
			string url = apiUrl;
			if (!url.EndsWith("/"))
			{
				url += "/";
			}
			if (!url.EndsWith("/api/", StringComparison.CurrentCultureIgnoreCase))
			{
				url += "api/";
			}
			var deployFile = new DeployFileDto
			{
				FileData = File.ReadAllBytes(zipPath),
				FileName = Path.GetFileName(zipPath)
			};
			branchId = FormatBranch(branchId, version);

            Cookie authCookie = null;
            if(!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password))
            {
                authCookie = GetAuthCookie(apiUrl, userName, password);
            }
			using (var client = new JsonServiceClient(url))
			{
				_logger.Debug("Posting file {0} to URL {1}", zipPath, url);
				//var x = client.Send<DeployFileDto>(deployFile);
				var fileToUpload = new FileInfo(zipPath);
				string fileUrl = url + "file";
				client.Credentials = System.Net.CredentialCache.DefaultCredentials;
				client.Timeout = TimeSpan.FromMinutes(5);
				client.ReadWriteTimeout = TimeSpan.FromMinutes(5);
                if(authCookie != null)
                {  
                    client.CookieContainer.Add(authCookie);
                }
				var fileResponse = client.PostFile<DeployFileDto>(fileUrl, fileToUpload, MimeTypes.GetMimeType(fileToUpload.Name));
				_logger.Debug("Done posting file {0} to URL {1}, returned fileId {2} and fileStorageId {3}", zipPath, url, fileResponse.Id, fileResponse.FileStorageId);

				var buildRequest = new DeployBuild
				{
					FileId = fileResponse.Id,
					ProjectId = projectId,
					ProjectBranchId = branchId,
					ProjectComponentId = componentId,
					Version = version
				};
				_logger.Debug("Posting DeployBuild object to URL {0}, sending{1}", url, buildRequest.ToJson());
				string buildUrl = url + "build";
				try 
				{
					var buildResponse = client.Post<DeployBuild>(buildUrl, buildRequest);
                    _logger.Debug("Posting DeployBuild object to URL {0}, returned {1}", url, buildRequest.ToJson());
                    return buildResponse;
                }
				catch(Exception err)
				{
					_logger.WarnException(string.Format("Error posting DeployBuild object to URL {0}: {1}, ERROR: {2}", url, buildRequest.ToJson(), err.ToString()), err);
					throw;
				}
			}

		}
开发者ID:gsbastian,项目名称:Sriracha.Deploy,代码行数:63,代码来源:BuildPublisher.cs


注:本文中的JsonServiceClient.PostFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。