Fixing deploy issue

This commit is contained in:
vfedosevich 2013-07-18 11:41:25 +03:00
parent 8d9e46969a
commit ec1ad64b9d
2 changed files with 64 additions and 4 deletions

View file

@ -33,6 +33,7 @@ using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
using System.Xml;
namespace WebsitePanel.Setup.Actions
@ -444,6 +445,66 @@ namespace WebsitePanel.Setup.Actions
}
}
public class SaveSchedulerServiceCryptoKeyAction : Action, IInstallAction
{
void IInstallAction.Run(SetupVariables vars)
{
Log.WriteStart(string.Format("Updating {0}.config file (crypto key)", Global.Parameters.SchedulerServiceFileName));
try
{
UpdateCryptoKey(vars.InstallationFolder);
}
catch (Exception)
{
}
Log.WriteEnd(string.Format("Updated {0}.config file (connection string)", Global.Parameters.SchedulerServiceFileName));
}
private static void UpdateCryptoKey(string installFolder)
{
string path = Path.Combine(installFolder, "web.config");
string cryptoKey = "0123456789";
if (File.Exists(path))
{
using (var reader = new StreamReader(path))
{
string content = reader.ReadToEnd();
var pattern = new Regex(@"(?<=<add key=""WebsitePanel.CryptoKey"" .*?value\s*=\s*"")[^""]+(?="".*?>)");
Match match = pattern.Match(content);
cryptoKey = match.Value;
}
}
ChangeConfigString("installer.cryptokey", cryptoKey, installFolder);
}
private static void ChangeConfigString(string searchString, string replaceValue, string installFolder)
{
string path = Path.Combine(installFolder, "bin", string.Format("{0}.config", Global.Parameters.SchedulerServiceFileName));
if (File.Exists(path))
{
string content;
using (var reader = new StreamReader(path))
{
content = reader.ReadToEnd();
}
var re = new Regex("\\$\\{" + searchString + "\\}+", RegexOptions.IgnoreCase);
content = re.Replace(content, replaceValue);
using (var writer = new StreamWriter(path))
{
writer.Write(content);
}
}
}
}
public class SaveEntServerConfigSettingsAction : Action, IInstallAction
{
void IInstallAction.Run(SetupVariables vars)
@ -488,6 +549,7 @@ namespace WebsitePanel.Setup.Actions
new SaveComponentConfigSettingsAction(),
new SaveEntServerConfigSettingsAction(),
new SaveSchedulerServiceConnectionStringAction(),
new SaveSchedulerServiceCryptoKeyAction(),
new InstallSchedulerServiceAction()
};

View file

@ -308,9 +308,6 @@
ItemName="WebsitePanelInstallerMsi" />
</MSBuild>
<XmlUpdate XmlFileName="$(RootFolder)\WebsitePanel\Sources\WebsitePanel.SchedulerService\Bin\WebsitePanel.SchedulerService.exe.config" Xpath="//configuration/connectionStrings/add/@connectionString" Value="${installer.connectionstring}" />
<XmlUpdate XmlFileName="$(RootFolder)\WebsitePanel\Sources\WebsitePanel.SchedulerService\Bin\WebsitePanel.SchedulerService.exe.config" Xpath="//configuration/appSettings/add[@key=%22WebsitePanel.CryptoKey%22]/@value" Value="${installer.cryptokey}" />
<MSBuild Projects="$(RootFolder)\WebsitePanel.Installer\Sources\WebsitePanel.SchedulerServiceInstaller\WebsitePanel.SchedulerServiceInstaller.csproj" Properties="Configuration=$(BuildConfiguration);DefineSolutionProperties=false"/>
<MSBuild Projects="$(RootFolder)\WebsitePanel.Installer\Sources\Setup.SchedulerService\Setup.SchedulerService.wixproj" Properties="Configuration=$(BuildConfiguration);DefineSolutionProperties=false">
@ -378,6 +375,7 @@
<Copy SourceFiles="@(EnterpriseServerDeployFiles)" DestinationFolder="$(EnterpriseServerInstall)\%(RecursiveDir)" />
<XmlUpdate XmlFileName="$(EnterpriseServerInstall)\web.config" Xpath="//configuration/connectionStrings/add/@connectionString" Value="${installer.connectionstring}" />
<XmlUpdate XmlFileName="$(EnterpriseServerInstall)\bin\WebsitePanel.SchedulerService.exe.config" Xpath="//configuration/connectionStrings/add/@connectionString" Value="${installer.connectionstring}" />
<XmlUpdate XmlFileName="$(EnterpriseServerInstall)\bin\WebsitePanel.SchedulerService.exe.config" Xpath="//configuration/appSettings/add[@key=%22WebsitePanel.CryptoKey%22]/@value" Value="${installer.cryptokey}" />
<XmlUpdate XmlFileName="$(EnterpriseServerInstall)\web.config" Xpath="//configuration/appSettings/add[@key=%22WebsitePanel.CryptoKey%22]/@value" Value="${installer.cryptokey}" />
</Target>