Skip to content
Merged
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
36 changes: 36 additions & 0 deletions src/ServicePulse.Host.Tests/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("ServicePulse.Host.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ServicePulse.Host.Tests")]
[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("113a09cc-9665-4e87-9fc7-7e5c8c0afe71")]

// 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")]
35 changes: 35 additions & 0 deletions src/ServicePulse.Host.Tests/RegExTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace ServicePulse.Host.Tests
{
using System;
using System.IO;
using System.Text.RegularExpressions;
using NUnit.Framework;

[TestFixture, Serializable]
public class RegExTests
{
[Ignore]
[Test]
public void find_service_control_url()
{
var pathToConfig = Path.Combine("app.constants.js");
var config = File.ReadAllText(pathToConfig);
Assert.IsTrue(!string.IsNullOrWhiteSpace(config));
var match = Regex.Match(config, @"(service_control_url: ')([\w:/]*)(')");
Assert.IsTrue(match.Success);
Assert.IsTrue(!string.IsNullOrWhiteSpace(match.Value));
}

[Ignore]
[Test]
public void match_service_control_url_in_string()
{
var test = "service_control_url: 'http://localhost:33333/api',";
var match = Regex.Match(test, @"(service_control_url: ')([\w:/]*)(')");
Assert.AreEqual("http://localhost:33333/api", match.Groups[2].Value);
}



}
}
67 changes: 67 additions & 0 deletions src/ServicePulse.Host.Tests/ServicePulse.Host.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{113A09CC-9665-4E87-9FC7-7E5C8C0AFE71}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ServicePulse.Host.Tests</RootNamespace>
<AssemblyName>ServicePulse.Host.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="RegExTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="..\ServicePulse.Host\app\js\app.constants.js">
<Link>app.constants.js</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
4 changes: 4 additions & 0 deletions src/ServicePulse.Host.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="2.6.4" targetFramework="net452" />
</packages>
15 changes: 9 additions & 6 deletions src/ServicePulse.Host/Commands/AbstractCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
using System.Text.RegularExpressions;
using Hosting;

internal abstract class AbstractCommand
abstract class AbstractCommand
{
public abstract void Execute(HostArguments args);

public static void UpdateConfig(string directoryPath, string serviceControlUrl)
public static void MigrateServiceControlUrl(HostArguments args, string filePath)
{
var appJsPath = Path.Combine(directoryPath, "config.js");
var appJsCode = File.ReadAllText(appJsPath);
var config = File.ReadAllText(filePath);
var match = Regex.Match(config, @"(service_control_url: ')([\w:/]*)(')");

File.WriteAllText(appJsPath,
Regex.Replace(appJsCode, @"(service_control_url: ')([\w:/]*)(')", "$1" + serviceControlUrl + "$3"));
// if the installer was given a value use it otherwise use any existing value
if (match.Success && string.IsNullOrWhiteSpace(args.ServiceControlUrl))
{
args.ServiceControlUrl = match.Groups[2].Value;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,32 @@
using System.Text.RegularExpressions;
using Hosting;

internal class UpdateVersionCommand : AbstractCommand
internal class ExtractAndUpdateConstantsCommand : AbstractCommand
{
public override void Execute(HostArguments args)
{
#if !DEBUG
ExtractApp(args.OutputPath);
ExtractApp(args);
UpdateVersion(args.OutputPath);
UpdateConfig(args.OutputPath, args.ServiceControlUrl);
#endif
}

static void ExtractApp(string directoryPath)
static void ExtractApp(HostArguments args)
{
string directoryPath = args.OutputPath;
var assembly = Assembly.GetExecutingAssembly();

using (var resourceStream = assembly.GetManifestResourceStream(@"app\js\app.constants.js"))
{
var destinationPath = Path.Combine(directoryPath, "js/app.constants.js");
var destinationPath = Path.Combine(directoryPath, "js\\app.constants.js");

Directory.CreateDirectory(Path.GetDirectoryName(destinationPath));

if (File.Exists(destinationPath))
{
MigrateServiceControlUrl(args, destinationPath);

File.Delete(destinationPath);
}

Expand All @@ -38,7 +42,17 @@ static void ExtractApp(string directoryPath)
}
}

static void UpdateVersion(string directoryPath)

public static void UpdateConfig(string directoryPath, string serviceControlUrl)
{
var appJsPath = Path.Combine(directoryPath, "js/app.constants.js");
var appJsCode = File.ReadAllText(appJsPath);

File.WriteAllText(appJsPath,
Regex.Replace(appJsCode, @"(service_control_url: ')([\w:/]*)(')", "$1" + serviceControlUrl + "$3"));
}

public static void UpdateVersion(string directoryPath)
{
var appJsPath = Path.Combine(directoryPath, "js/app.constants.js");
var appJsCode = File.ReadAllText(appJsPath);
Expand Down
3 changes: 2 additions & 1 deletion src/ServicePulse.Host/Commands/ExtractCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public override void Execute(HostArguments args)
return;
}

UpdateConfig(args.OutputPath, args.ServiceControlUrl);
ExtractAndUpdateConstantsCommand.UpdateVersion(args.OutputPath);
ExtractAndUpdateConstantsCommand.UpdateConfig(args.OutputPath, args.ServiceControlUrl);
}

static void ExtractResources(string directoryPath)
Expand Down
39 changes: 39 additions & 0 deletions src/ServicePulse.Host/Commands/RemoveDeprecatedOveridesCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace ServicePulse.Host.Commands
{
using System.IO;
using System.Text.RegularExpressions;
using ServicePulse.Host.Hosting;

class RemoveDeprecatedOveridesCommand : AbstractCommand
{
public override void Execute(HostArguments args)
{
DeleteAppJsFile(args);
}

static void DeleteAppJsFile(HostArguments args)
{

var directoryPath = args.OutputPath;

var configPath = Path.Combine(directoryPath, "config.js");

if (File.Exists(configPath))
{
MigrateServiceControlUrl(args, configPath);

File.Delete(configPath);
}

var destinationPath = Path.Combine(directoryPath, "js\\app.js");

if (File.Exists(destinationPath))
{
MigrateServiceControlUrl(args, destinationPath);
File.Delete(destinationPath);
}
}


}
}
45 changes: 0 additions & 45 deletions src/ServicePulse.Host/Commands/UpdateConfigCommand.cs

This file was deleted.

7 changes: 4 additions & 3 deletions src/ServicePulse.Host/Hosting/HostArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public HostArguments(string[] args)
{
var executionMode = ExecutionMode.Run;

commands = new List<Type> { typeof(UpdateConfigCommand), typeof(UpdateVersionCommand), typeof(RunCommand) };
commands = new List<Type> { typeof(RemoveDeprecatedOveridesCommand), typeof(ExtractAndUpdateConstantsCommand), typeof(RunCommand) };
startMode = StartMode.Automatic;
url = "http://localhost:8081";
ServiceName = "Particular.ServicePulse";
Expand Down Expand Up @@ -60,7 +60,7 @@ public HostArguments(string[] args)
@"Extract files to be installed in a Web Server."
, s =>
{
commands = new List<Type> { typeof(UpdateConfigCommand), typeof(UpdateVersionCommand), typeof(ExtractCommand) };
commands = new List<Type> { typeof(ExtractAndUpdateConstantsCommand), typeof(ExtractCommand) };
executionMode = ExecutionMode.Extract;
}
},
Expand Down Expand Up @@ -109,7 +109,7 @@ public HostArguments(string[] args)
@"Install the endpoint as a Windows service."
, s =>
{
commands = new List<Type> { typeof(UpdateConfigCommand), typeof(UpdateVersionCommand), typeof(InstallCommand) };
commands = new List<Type> { typeof(RemoveDeprecatedOveridesCommand), typeof(ExtractAndUpdateConstantsCommand), typeof(InstallCommand) };
executionMode = ExecutionMode.Install;
}
},
Expand Down Expand Up @@ -230,6 +230,7 @@ public string Url
public string ServiceControlUrl
{
get { return serviceControlUrl; }
set { serviceControlUrl = value; }
}

public string DisplayName { get; set; }
Expand Down
Loading