Scheduler service installed by new wix installer
This commit is contained in:
parent
ce95326f7d
commit
c443d94ac3
17 changed files with 512 additions and 132 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,122 @@
|
|||
using System;
|
||||
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 Microsoft.Deployment.WindowsInstaller;
|
||||
|
||||
namespace WebsitePanel.SchedulerServiceInstaller
|
||||
{
|
||||
public class CustomActions
|
||||
{
|
||||
[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)
|
||||
{
|
||||
ChangeConnectionString(session["CONNECTIONSTRING"], session["INSTALLFOLDER"]);
|
||||
InstallService(session["INSTALLFOLDER"]);
|
||||
|
||||
return ActionResult.Success;
|
||||
}
|
||||
|
||||
private static void InstallService(string installFolder)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ServiceController.GetServices().Any(s => s.DisplayName.Equals("WebsitePanel Scheduler", StringComparison.CurrentCultureIgnoreCase)))
|
||||
{
|
||||
ManagedInstallerClass.InstallHelper(new[] {"/i", Path.Combine(installFolder, "WebsitePanel.SchedulerService.exe")});
|
||||
}
|
||||
|
||||
StartService("WebsitePanel Scheduler");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private static void ChangeConnectionString(string connectionString, string installFolder)
|
||||
{
|
||||
string content;
|
||||
string path = Path.Combine(installFolder, "WebsitePanel.SchedulerService.exe.config");
|
||||
|
||||
using (var reader = new StreamReader(path))
|
||||
{
|
||||
content = reader.ReadToEnd();
|
||||
}
|
||||
|
||||
var re = new Regex("\\$\\{" + "installer.connectionstring" + "\\}+", RegexOptions.IgnoreCase);
|
||||
content = re.Replace(content, connectionString);
|
||||
|
||||
using (var writer = new StreamWriter(path))
|
||||
{
|
||||
writer.Write(content);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
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.SchedulerServiceInstaller")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("WebsitePanel.SchedulerServiceInstaller")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2013")]
|
||||
[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("64885563-cef3-4553-9006-31282c033b3b")]
|
||||
|
||||
// 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,52 @@
|
|||
<?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>{24A4C231-73A9-4F03-ABAD-9A8FE5324495}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>WebsitePanel.SchedulerServiceInstaller</RootNamespace>
|
||||
<AssemblyName>WebsitePanel.SchedulerServiceInstaller</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.SchedulerService\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.SchedulerService\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.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>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(WixCATargetsPath)" />
|
||||
</Project>
|
Loading…
Add table
Add a link
Reference in a new issue