forked from Topshelf/Topshelf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Porting System.ServiceInstaller and other deps
Adding Install, Unstaller, etc feature for .NET Core
- Loading branch information
Showing
37 changed files
with
3,950 additions
and
68 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/TopShelf.ServiceInstaller/System.Configuration.Install/ComponentInstaller.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace System.Configuration.Install | ||
{ | ||
public abstract class ComponentInstaller : Installer | ||
{ | ||
/// <summary>When overridden in a derived class, copies all the properties that are required at install time from the specified component.</summary> | ||
/// <param name="component">The component to copy from. </param> | ||
public abstract void CopyFromComponent(IComponent component); | ||
|
||
/// <summary>Determines if the specified installer installs the same object as this installer.</summary> | ||
/// <returns>true if this installer and the installer specified by the <paramref name="otherInstaller" /> parameter install the same object; otherwise, false.</returns> | ||
/// <param name="otherInstaller">The installer to compare. </param> | ||
public virtual bool IsEquivalentInstaller(ComponentInstaller otherInstaller) | ||
{ | ||
return false; | ||
} | ||
} | ||
} |
119 changes: 119 additions & 0 deletions
119
src/TopShelf.ServiceInstaller/System.Configuration.Install/InstallContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Specialized; | ||
using System.Globalization; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace System.Configuration.Install | ||
{ | ||
public class InstallContext | ||
{ | ||
private StringDictionary parameters; | ||
|
||
public StringDictionary Parameters => this.parameters; | ||
|
||
public InstallContext() : this(null, null) | ||
{ | ||
} | ||
|
||
public InstallContext(string logFilePath, string[] commandLine) | ||
{ | ||
this.parameters = InstallContext.ParseCommandLine(commandLine); | ||
if (this.Parameters["logfile"] == null && logFilePath != null) | ||
{ | ||
this.Parameters["logfile"] = logFilePath; | ||
} | ||
} | ||
|
||
public bool IsParameterTrue(string paramName) | ||
{ | ||
string text = this.Parameters[paramName.ToLower(CultureInfo.InvariantCulture)]; | ||
if (text == null) | ||
{ | ||
return false; | ||
} | ||
|
||
if (string.Compare(text, "true", StringComparison.OrdinalIgnoreCase) != 0 | ||
&& string.Compare(text, "yes", StringComparison.OrdinalIgnoreCase) != 0 | ||
&& string.Compare(text, "1", StringComparison.OrdinalIgnoreCase) != 0) | ||
{ | ||
return "".Equals(text); | ||
} | ||
return true; | ||
} | ||
|
||
public void LogMessage(string message) | ||
{ | ||
try | ||
{ | ||
this.LogMessageHelper(message); | ||
} | ||
catch (Exception) | ||
{ | ||
try | ||
{ | ||
this.Parameters["logfile"] = Path.Combine(Path.GetTempPath(), Path.GetFileName(this.Parameters["logfile"])); | ||
this.LogMessageHelper(message); | ||
} | ||
catch (Exception) | ||
{ | ||
this.Parameters["logfile"] = null; | ||
} | ||
} | ||
if (!this.IsParameterTrue("LogToConsole") && this.Parameters["logtoconsole"] != null) | ||
{ | ||
return; | ||
} | ||
Console.WriteLine(message); | ||
} | ||
|
||
internal void LogMessageHelper(string message) | ||
{ | ||
StreamWriter streamWriter = null; | ||
try | ||
{ | ||
if (!string.IsNullOrEmpty(this.Parameters["logfile"])) | ||
{ | ||
streamWriter = new StreamWriter(this.Parameters["logfile"], true, Encoding.UTF8); | ||
streamWriter.WriteLine(message); | ||
} | ||
} | ||
finally | ||
{ | ||
if (streamWriter != null) | ||
{ | ||
streamWriter.Close(); | ||
} | ||
} | ||
} | ||
|
||
protected static StringDictionary ParseCommandLine(string[] args) | ||
{ | ||
StringDictionary stringDictionary = new StringDictionary(); | ||
if (args == null) | ||
{ | ||
return stringDictionary; | ||
} | ||
for (int i = 0; i < args.Length; i++) | ||
{ | ||
if (args[i].StartsWith("/", StringComparison.Ordinal) || args[i].StartsWith("-", StringComparison.Ordinal)) | ||
{ | ||
args[i] = args[i].Substring(1); | ||
} | ||
int num = args[i].IndexOf('='); | ||
if (num < 0) | ||
{ | ||
stringDictionary[args[i].ToLower(CultureInfo.InvariantCulture)] = ""; | ||
} | ||
else | ||
{ | ||
stringDictionary[args[i].Substring(0, num).ToLower(CultureInfo.InvariantCulture)] = args[i].Substring(num + 1); | ||
} | ||
} | ||
return stringDictionary; | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/TopShelf.ServiceInstaller/System.Configuration.Install/InstallEventArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Collections; | ||
|
||
namespace System.Configuration.Install | ||
{ | ||
|
||
public delegate void InstallEventHandler(object sender, InstallEventArgs e); | ||
|
||
public class InstallEventArgs | ||
{ | ||
public IDictionary SavedSate { get; } | ||
|
||
public InstallEventArgs() | ||
{ | ||
} | ||
|
||
public InstallEventArgs(IDictionary savedSate) | ||
{ | ||
this.SavedSate = savedSate; | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/TopShelf.ServiceInstaller/System.Configuration.Install/InstallException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Runtime.Serialization; | ||
|
||
namespace System.Configuration.Install | ||
{ | ||
[Serializable] | ||
internal class InstallException : SystemException | ||
{ | ||
public InstallException() | ||
{ | ||
base.HResult = -2146232057; | ||
} | ||
|
||
public InstallException(string message) : base(message) | ||
{ | ||
} | ||
|
||
public InstallException(string message, Exception innerException) : base(message, innerException) | ||
{ | ||
} | ||
|
||
protected InstallException(SerializationInfo info, StreamingContext context) : base(info, context) | ||
{ | ||
} | ||
} | ||
} |
Oops, something went wrong.