public OfflineDeployment CreateOfflineDeployment(string deployBatchRequestId, EnumOfflineDeploymentStatus initialStatus)
		{
            if(string.IsNullOrEmpty(deployBatchRequestId))
            {
                throw new ArgumentNullException("deployBatchRequestId");
            }
			var item = new OfflineDeployment
			{
				Id = Guid.NewGuid().ToString(),
				DeployBatchRequestId = deployBatchRequestId,
				Status = initialStatus,
				CreatedByUserName = _userIdentity.UserName,
				CreatedDateTimeUtc = DateTime.UtcNow,
				UpdatedByUserName = _userIdentity.UserName,
				UpdatedDateTimeUtc = DateTime.UtcNow,
			};
			return _documentSession.StoreSaveEvict(item);
		}
 public static SqlOfflineDeployment FromDto(OfflineDeployment item)
 {
     return AutoMapper.Mapper.Map(item, new SqlOfflineDeployment());
 }
Ejemplo n.º 3
0
        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);
            }
        }