Skip to content

Commit

Permalink
Porting System.ServiceInstaller and other deps
Browse files Browse the repository at this point in the history
Adding Install, Unstaller, etc feature for .NET Core
  • Loading branch information
Robert Slaney authored and phatboyg committed Sep 19, 2018
1 parent 05fe495 commit 77548a2
Show file tree
Hide file tree
Showing 37 changed files with 3,950 additions and 68 deletions.
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;
}
}
}
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;
}
}
}
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;
}
}
}
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)
{
}
}
}
Loading

0 comments on commit 77548a2

Please sign in to comment.