Skip to content

Create a Website DeployHelper #837 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions WebDeployHelper/WebDeployHelper.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25123.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebDeployHelper", "WebDeployHelper\WebDeployHelper.csproj", "{C43BDD5D-FDC9-45BF-B2C8-233F9E339624}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C43BDD5D-FDC9-45BF-B2C8-233F9E339624}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C43BDD5D-FDC9-45BF-B2C8-233F9E339624}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C43BDD5D-FDC9-45BF-B2C8-233F9E339624}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C43BDD5D-FDC9-45BF-B2C8-233F9E339624}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
109 changes: 109 additions & 0 deletions WebDeployHelper/WebDeployHelper/ConfigReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using System;
using System.IO;

namespace WebDeployHelper
{
class ConfigReader
{
#region Read Config

private readonly string _configDirectory;

private static string _configDirUpload;
private static string _configReleaseType;
private static string _configSftpAddress;
private static string _configSftpUser;
private static string _configDevPath;
private static string _configReleasePath;

private static string _remotePath;

public ConfigReader()
{
_configDirectory = DeployConfig.DirConfig;
}

public ConfigReader(string configDirectory, string vstoDirectory)
{
_configDirectory = configDirectory;
}

public ConfigReader ReadConfig()
{
//Sequence matters
InitConfigVariables();
InitRemotePath();
InitDeployInfo();
return this;
}

public DeployConfig ToDeployConfig()
{
var config = new DeployConfig
{
ConfigDirUpload = _configDirUpload,
ConfigReleaseType = _configReleaseType,
ConfigSftpAddress = _configSftpAddress,
ConfigSftpUser = _configSftpUser,
RemotePath = _remotePath
};
return config;
}

private void InitConfigVariables()
{
string[] configContent = {};
try
{
configContent = File.ReadAllLines(_configDirectory);
}
catch (Exception e)
{
Util.DisplayWarning(TextCollection.ErrorNoConfig, e);
}

//index here refers to the line number in DeployHelper.conf
_configDirUpload = configContent[1];
_configReleaseType = configContent[3];
_configSftpAddress = configContent[5];
_configSftpUser = configContent[7];
_configDevPath = configContent[9];
_configReleasePath = configContent[11];
}

private void InitRemotePath()
{
switch (_configReleaseType)
{
case TextCollection.VarRelease:
_remotePath = _configReleasePath;
break;
case TextCollection.VarDev:
_remotePath = _configDevPath;
break;
default:
Util.DisplayWarning(TextCollection.ErrorInvalidReleaseType, new Exception());
break;
}
}

private void InitDeployInfo()
{
PrintInfo("You are going to deploy PowerPointLabs Website");
PrintInfo("");
PrintInfo("Settings info:");
PrintInfo("Upload Directory: ", _configDirUpload);
PrintInfo("Release Type: ", _configReleaseType);
PrintInfo("Remote Path: ", _remotePath);
PrintInfo("");
}

private void PrintInfo(string text, string highlightedText = "")
{
Console.Write(text);
Util.ConsoleWriteWithColor(highlightedText, ConsoleColor.Yellow);
Console.WriteLine("");
}
#endregion
}
}
16 changes: 16 additions & 0 deletions WebDeployHelper/WebDeployHelper/DeployConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace WebDeployHelper
{
class DeployConfig
{
public static readonly string DirConfig = Environment.CurrentDirectory + @"\WebDeployHelper.conf";

public string ConfigDirUpload;
public string ConfigReleaseType;
public string ConfigSftpAddress;
public string ConfigSftpUser;

public string RemotePath;
}
}
34 changes: 34 additions & 0 deletions WebDeployHelper/WebDeployHelper/DeployUploader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;

namespace WebDeployHelper
{
class DeployUploader
{
#region SFTP upload

private readonly DeployConfig _config;

public DeployUploader(DeployConfig config)
{
_config = config;
}

public void SftpUpload()
{
try
{
Console.WriteLine("Connecting the server...");
var uploader = new Uploader();
uploader.SetConfig(_config);
uploader.Upload();
}
catch (Exception e)
{
Console.WriteLine("Error during SFTP uploading:");
Util.DisplayWarning(e.Message, e);
}
}

#endregion
}
}
65 changes: 65 additions & 0 deletions WebDeployHelper/WebDeployHelper/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
#region WebDeployHelper Description
//
// WebDeployHelper Class
// ------------------
// Simply double click the .exe file to patch PowerPointLabs Website,
// so that it uploads the files onto the PowerPointLabs server.
//
// HOW TO USE
//
// For the first time use, you need to setup the followings:
//
// 0. Compile WebDeployHelper using Visual Studio. .NET 4.5 is required. The output program is under bin/debug or bin/release folder.
//
// 1. Fill in WebDeployHelper.conf
// - Upload directory is the local directory to upload to the server
// - Release type is dev or release
// - SFTP address is the server to upload to
// - SFTP username is the username used to login the server
// - Dev path is the installation folder path on the server for dev version PowerPointLabs Website
// - Release path is the installation folder path on the server for release version PowerPointLabs Website
//
// 2. Copy WebDeployHelper.exe, WebDeployHelper.conf, WinSCP.exe and WinSCP.com from the output folder to the publish folder
//
// 3. Run WebDeployHelper.exe and follow the instructions.
//
// For the next time
//
// 0. Run WebDeployHelper.exe and follow the instructions.
//
// Have a nice day :)
//
//TODO: add testing
#endregion
namespace WebDeployHelper
{
class Program
{
public static void Main(string[] args)
{
try
{
# region Init

var config = new ConfigReader()
.ReadConfig()
.ToDeployConfig();

# endregion

new DeployUploader(config)
.SftpUpload();
Util.DisplayEndMessage();
}
catch
{
Util.IgnoreException();
}
finally
{
Console.ReadKey();
}
}
}
}
36 changes: 36 additions & 0 deletions WebDeployHelper/WebDeployHelper/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("DeployHelper")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DeployHelper")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("57277935-16d4-471b-9706-49fca9fa69cb")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
21 changes: 21 additions & 0 deletions WebDeployHelper/WebDeployHelper/TextCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

namespace WebDeployHelper
{
class TextCollection
{
public const string ErrorNoConfig = "Cannot find config file.";
public const string ErrorInvalidReleaseType = "Invalid release type in config file.";

public const string DoneUploaded = "Uploaded.";

public const string InfoEnterPassword = "Enter SFTP password: ";

public const string VarDev = "dev";
public const string VarRelease = "release";

public const string FileXmlLogName = "log.xml";

public const string PermissionsFile = "644";
public const string PermissionsDirectory = "755";
}
}
Loading