private async Task putApplicationOffline(DeployerClient dc, RemoteDeployment deployment) { using (FileStream stream = File.OpenRead(txtAppOfflineURL.Text)) { await dc.SendFileAsync(deployment.Path + "\\" + "App_Offline.htm", stream); } log("{0} Application is now Offline", deployment.FriendlyName); }
private async void deploy() { if (chkOfflineBeforeDeployment.Checked && !File.Exists(txtAppOfflineURL.Text)) { MessageBox.Show("Invalid App Offline Page", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { txtConsole.Text = String.Empty; progressBar1.Value = 0; btnDeploy.Enabled = false; cleanDataGrid(); IEnumerable <FileDetail> localFileDetails = Directory.GetFiles(txtLocalDeployment.Text, "*", SearchOption.AllDirectories) .Select(f => new FileDetail { Path = f, Hash = f.MD5Hash(), }); progressBar1.Maximum = localFileDetails.Count() * config.RemoteDeployments.Count; foreach (RemoteDeployment deployment in config.RemoteDeployments) { log("Deploying to {0}", deployment.FriendlyName); var dc = new DeployerClient("NetTcpBinding_IDeployer", "net.tcp://" + deployment.Host + ":6969/Deployer"); dc.InnerChannel.OperationTimeout = new TimeSpan(0, 5, 0); int uploaded = 0; int same = 0; int excluded = 0; bool isApplicationOffline = false; if (chkOfflineBeforeDeployment.Checked && !checkSmartOffline.Checked) { await putApplicationOffline(dc, deployment); isApplicationOffline = true; } try { progressBar1.Style = ProgressBarStyle.Marquee; FileDetail[] remoteFileDetails = await dc.GetAllFilesAsync(deployment.Path); progressBar1.Style = ProgressBarStyle.Continuous; foreach (FileDetail localFileDetail in localFileDetails) { progressBar1.Value++; bool toExclude = config.ExclusionList.Any( el => localFileDetail.Path.Contains(el, StringComparison.InvariantCultureIgnoreCase)); string relativeLocalPath = localFileDetail.Path.Remove(txtLocalDeployment.Text).TrimStart('\\'); if (!toExclude) { FileDetail remoteFile = remoteFileDetails.SingleOrDefault( rf => rf.Path.Remove(deployment.Path) .TrimStart('\\') .Equals(relativeLocalPath, StringComparison.InvariantCultureIgnoreCase)); bool upload = false; if (remoteFile != null) { bool isDifferent = !localFileDetail.Hash.IsEqualTo(remoteFile.Hash); if (isDifferent) { upload = true; } } else { upload = true; } if (upload) { if (chkOfflineBeforeDeployment.Checked && checkSmartOffline.Checked && !isApplicationOffline && new FileInfo(localFileDetail.Path).Extension.Contains("dll", StringComparison.InvariantCultureIgnoreCase)) { isApplicationOffline = true; await putApplicationOffline(dc, deployment); } log("{0} is different. Uploading...", relativeLocalPath); uploaded++; using (FileStream stream = File.OpenRead(localFileDetail.Path)) { await dc.SendFileAsync(deployment.Path + "\\" + relativeLocalPath, stream); } } else { same++; } } else { excluded++; } } if (checkOnlineAfterDeployment.Checked && isApplicationOffline) { await putApplicationOnline(dc, deployment); } log("Finished Deployment on {0}: Uploaded: {1} - Unchanged: {2} - Excluded: {3}{4}", deployment.FriendlyName, uploaded, same, excluded, Environment.NewLine); } catch (EndpointNotFoundException enfe) { log("Couldn't connect to: {0}... Skipping Deployment{1}", deployment.Host, Environment.NewLine); } catch (Exception e) { log("Error: {0}... Skipping Deployment on {1}{2}", e.Message, deployment.FriendlyName, Environment.NewLine); } } btnDeploy.Enabled = true; } }