WIXInstaller. part 1
This commit is contained in:
parent
18b605cd00
commit
aa93b3b31d
12 changed files with 675 additions and 1 deletions
|
@ -0,0 +1,32 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup useLegacyV2RuntimeActivationPolicy="true">
|
||||
|
||||
<!--
|
||||
Use supportedRuntime tags to explicitly specify the version(s) of the .NET Framework runtime that
|
||||
the custom action should run on. If no versions are specified, the chosen version of the runtime
|
||||
will be the "best" match to what Microsoft.Deployment.WindowsInstaller.dll was built against.
|
||||
|
||||
WARNING: leaving the version unspecified is dangerous as it introduces a risk of compatibility
|
||||
problems with future versions of the .NET Framework runtime. It is highly recommended that you specify
|
||||
only the version(s) of the .NET Framework runtime that you have tested against.
|
||||
|
||||
Note for .NET Framework v3.0 and v3.5, the runtime version is still v2.0.
|
||||
|
||||
In order to enable .NET Framework version 2.0 runtime activation policy, which is to load all assemblies
|
||||
by using the latest supported runtime, @useLegacyV2RuntimeActivationPolicy="true".
|
||||
|
||||
For more information, see http://msdn.microsoft.com/en-us/library/bbx34a2h.aspx
|
||||
-->
|
||||
|
||||
<supportedRuntime version="v4.0" />
|
||||
<supportedRuntime version="v2.0.50727"/>
|
||||
|
||||
</startup>
|
||||
|
||||
<!--
|
||||
Add additional configuration settings here. For more information on application config files,
|
||||
see http://msdn.microsoft.com/en-us/library/kza1yk3a.aspx
|
||||
-->
|
||||
|
||||
</configuration>
|
|
@ -0,0 +1,274 @@
|
|||
// Copyright (c) 2015, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration.Install;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.ServiceProcess;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Forms.VisualStyles;
|
||||
using System.Xml;
|
||||
using Microsoft.Deployment.WindowsInstaller;
|
||||
using WebsitePanel.Setup;
|
||||
|
||||
namespace WebsitePanel.WIXInstaller
|
||||
{
|
||||
public class CustomActions
|
||||
{
|
||||
public const string CustomDataDelimiter = "-=del=-";
|
||||
|
||||
[CustomAction]
|
||||
public static ActionResult CheckConnection(Session session)
|
||||
{
|
||||
string testConnectionString = session["AUTHENTICATIONTYPE"].Equals("Windows Authentication") ? GetConnectionString(session["SERVERNAME"], "master") : GetConnectionString(session["SERVERNAME"], "master", session["LOGIN"], session["PASSWORD"]);
|
||||
|
||||
if (CheckConnection(testConnectionString))
|
||||
{
|
||||
session["CORRECTCONNECTION"] = "1";
|
||||
session["CONNECTIONSTRING"] = session["AUTHENTICATIONTYPE"].Equals("Windows Authentication") ? GetConnectionString(session["SERVERNAME"], session["DATABASENAME"]) : GetConnectionString(session["SERVERNAME"], session["DATABASENAME"], session["LOGIN"], session["PASSWORD"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
session["CORRECTCONNECTION"] = "0";
|
||||
}
|
||||
|
||||
return ActionResult.Success;
|
||||
}
|
||||
|
||||
[CustomAction]
|
||||
public static ActionResult FinalizeInstall(Session session)
|
||||
{
|
||||
var connectionString = GetCustomActionProperty(session, "ConnectionString").Replace(CustomDataDelimiter, ";");
|
||||
var serviceFolder = GetCustomActionProperty(session, "ServiceFolder");
|
||||
var previousConnectionString = GetCustomActionProperty(session, "PreviousConnectionString").Replace(CustomDataDelimiter, ";");
|
||||
var previousCryptoKey = GetCustomActionProperty(session, "PreviousCryptoKey");
|
||||
|
||||
if (string.IsNullOrEmpty(serviceFolder))
|
||||
{
|
||||
return ActionResult.Success;
|
||||
}
|
||||
|
||||
connectionString = string.IsNullOrEmpty(previousConnectionString)
|
||||
? connectionString
|
||||
: previousConnectionString;
|
||||
|
||||
ChangeConfigString("/configuration/connectionStrings/add[@name='EnterpriseServer']", "connectionString", connectionString, serviceFolder);
|
||||
ChangeConfigString("/configuration/appSettings/add[@key='WebsitePanel.CryptoKey']", "value", previousCryptoKey, serviceFolder);
|
||||
InstallService(serviceFolder);
|
||||
|
||||
return ActionResult.Success;
|
||||
}
|
||||
|
||||
[CustomAction]
|
||||
public static ActionResult FinalizeUnInstall(Session session)
|
||||
{
|
||||
UnInstallService();
|
||||
|
||||
return ActionResult.Success;
|
||||
}
|
||||
|
||||
[CustomAction]
|
||||
public static ActionResult PreInstallationAction(Session session)
|
||||
{
|
||||
session["SKIPCONNECTIONSTRINGSTEP"] = "0";
|
||||
|
||||
session["SERVICEFOLDER"] = session["INSTALLFOLDER"];
|
||||
|
||||
var servicePath = SecurityUtils.GetServicePath("WebsitePanel Scheduler");
|
||||
|
||||
if (!string.IsNullOrEmpty(servicePath))
|
||||
{
|
||||
string path = Path.Combine(servicePath, "WebsitePanel.SchedulerService.exe.config");
|
||||
|
||||
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);
|
||||
session["PREVIOUSCRYPTOKEY"] = match.Value;
|
||||
|
||||
var connectionStringPattern = new Regex(@"(?<=<add name=""EnterpriseServer"" .*?connectionString\s*=\s*"")[^""]+(?="".*?>)");
|
||||
match = connectionStringPattern.Match(content);
|
||||
session["PREVIOUSCONNECTIONSTRING"] = match.Value.Replace(";", CustomDataDelimiter);
|
||||
}
|
||||
|
||||
session["SKIPCONNECTIONSTRINGSTEP"] = "1";
|
||||
|
||||
if (string.IsNullOrEmpty(session["SERVICEFOLDER"]))
|
||||
{
|
||||
session["SERVICEFOLDER"] = servicePath;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ActionResult.Success;
|
||||
}
|
||||
|
||||
private static void InstallService(string installFolder)
|
||||
{
|
||||
try
|
||||
{
|
||||
var schedulerService =
|
||||
ServiceController.GetServices().FirstOrDefault(
|
||||
s => s.DisplayName.Equals("WebsitePanel Scheduler", StringComparison.CurrentCultureIgnoreCase));
|
||||
|
||||
if (schedulerService != null)
|
||||
{
|
||||
StopService(schedulerService.ServiceName);
|
||||
|
||||
SecurityUtils.DeleteService(schedulerService.ServiceName);
|
||||
}
|
||||
|
||||
ManagedInstallerClass.InstallHelper(new[] { "/i", Path.Combine(installFolder, "WebsitePanel.SchedulerService.exe") });
|
||||
|
||||
StartService("WebsitePanel Scheduler");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private static void UnInstallService()
|
||||
{
|
||||
try
|
||||
{
|
||||
var schedulerService =
|
||||
ServiceController.GetServices().FirstOrDefault(
|
||||
s => s.DisplayName.Equals("WebsitePanel Scheduler", StringComparison.CurrentCultureIgnoreCase));
|
||||
|
||||
if (schedulerService != null)
|
||||
{
|
||||
StopService(schedulerService.ServiceName);
|
||||
|
||||
SecurityUtils.DeleteService(schedulerService.ServiceName);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private static void ChangeConfigString(string nodePath, string attrToChange, string value, string installFolder)
|
||||
{
|
||||
string path = Path.Combine(installFolder, "WebsitePanel.SchedulerService.exe.config");
|
||||
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
XmlDocument xmldoc = new XmlDocument();
|
||||
xmldoc.Load(path);
|
||||
|
||||
XmlElement node = xmldoc.SelectSingleNode(nodePath) as XmlElement;
|
||||
|
||||
if (node != null)
|
||||
{
|
||||
node.SetAttribute(attrToChange, value);
|
||||
|
||||
xmldoc.Save(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void StopService(string serviceName)
|
||||
{
|
||||
var sc = new ServiceController(serviceName);
|
||||
|
||||
if (sc.Status == ServiceControllerStatus.Running)
|
||||
{
|
||||
sc.Stop();
|
||||
sc.WaitForStatus(ServiceControllerStatus.Stopped);
|
||||
}
|
||||
}
|
||||
|
||||
private static void StartService(string serviceName)
|
||||
{
|
||||
var sc = new ServiceController(serviceName);
|
||||
|
||||
if (sc.Status == ServiceControllerStatus.Stopped)
|
||||
{
|
||||
sc.Start();
|
||||
sc.WaitForStatus(ServiceControllerStatus.Running);
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetConnectionString(string serverName, string databaseName)
|
||||
{
|
||||
return string.Format("Server={0};database={1};Trusted_Connection=true;", serverName, databaseName).Replace(";", CustomDataDelimiter);
|
||||
}
|
||||
|
||||
private static string GetConnectionString(string serverName, string databaseName, string login, string password)
|
||||
{
|
||||
return string.Format("Server={0};database={1};uid={2};password={3};", serverName, databaseName, login, password).Replace(";", CustomDataDelimiter);
|
||||
}
|
||||
|
||||
private static bool CheckConnection(string connectionString)
|
||||
{
|
||||
var connection = new SqlConnection(connectionString);
|
||||
bool result = true;
|
||||
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (connection != null && connection.State == ConnectionState.Open)
|
||||
{
|
||||
connection.Close();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static string GetCustomActionProperty(Session session, string key)
|
||||
{
|
||||
if (session.CustomActionData.ContainsKey(key))
|
||||
{
|
||||
return session.CustomActionData[key].Replace("-=-", ";");
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
// Copyright (c) 2015, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
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("WebsitePanel.WIXInstaller")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("WebsitePanel.WIXInstaller")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2015")]
|
||||
[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("CA494A4D-8D40-4A7D-8473-2F5E05605831")]
|
||||
|
||||
// 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")]
|
|
@ -0,0 +1,59 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{3343FFD8-7CCE-451B-95AE-3D97244313A2}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>WebsitePanel.WIXInstaller</RootNamespace>
|
||||
<AssemblyName>WebsitePanel.WIXInstaller</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<WixCATargetsPath Condition=" '$(WixCATargetsPath)' == '' ">$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.CA.targets</WixCATargetsPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\Setup.WIXInstaller\bin\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\Setup.WIXInstaller\bin\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration.Install" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.ServiceProcess" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Microsoft.Deployment.WindowsInstaller" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CustomAction.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Content Include="CustomAction.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WebsitePanel.Setup\WebsitePanel.Setup.csproj">
|
||||
<Project>{3951C0EC-BD98-450E-B228-CDBE5BD4AD49}</Project>
|
||||
<Name>WebsitePanel.Setup</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(WixCATargetsPath)" />
|
||||
</Project>
|
Loading…
Add table
Add a link
Reference in a new issue