Initial project state: .NET reference, design, Rust port (M0+M1), evidence
rust / build / test / clippy / fmt (push) Has been cancelled
rust / build / test / clippy / fmt (push) Has been cancelled
Layout:
- src/ .NET 10 x64 reference: MxNativeCodec, MxNativeClient,
MxAsbClient, probes, tests, harnesses. Executable spec.
- design/ Architectural plan for the Rust port (M0–M6), error
model, protocol invariants, risks (R1–R16), adversarial
review log (review.md).
- rust/ Rust workspace. M0 skeleton + M1 codec parity.
mxaccess-codec: 215 unit tests + 2 cross-implementation
parity tests (byte-identical against .NET reference).
Other crates are M0 stubs awaiting M2+.
- captures/ Frida + netsh + pcap evidence per CLAUDE.md
("captures are evidence, not throwaway logs").
- analysis/ Decompiled C# (frida/proxy/decompiled-*),
Ghidra exports for native DLLs (`exports/` only —
working state at `projects/` and AVEVA's input
binaries at `input/` are gitignored).
- docs/ Reverse-engineering reference docs.
- tools/ Setup-LiveProbeEnv.ps1 (Infisical credential fetcher),
Compute-Crc.ps1 (.NET parity helper).
- .github/workflows/ Rust CI: fmt + build + test + clippy on Windows.
- LICENSE MIT (Joseph Doherty, 2026).
Verified:
- cargo test --workspace → 217 passed (215 unit + 2 .NET parity), 0 failed
- cargo clippy --workspace -- -D warnings → clean
- cargo fmt --all -- --check → clean
- cargo publish --dry-run -p mxaccess-codec → packages cleanly
Excluded from history (see .gitignore):
- **/bin, **/obj, **/target — build artifacts
- analysis/ghidra/projects/ — Ghidra working state (regenerable)
- analysis/ghidra/input/ — AVEVA proprietary DLLs (vendor IP)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,275 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Security;
|
||||
using System.Security.Permissions;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace ArchestrA.Diagnostics;
|
||||
|
||||
internal static class Logger
|
||||
{
|
||||
public static int ErrorCount
|
||||
{
|
||||
get
|
||||
{
|
||||
if (InitLoggerDll())
|
||||
{
|
||||
int errorCount = 0;
|
||||
int warningCount = 0;
|
||||
long ftLastError = 0L;
|
||||
long ftLastWarning = 0L;
|
||||
if (NativeMethods.GetLoggerStats(string.Empty, ref errorCount, ref ftLastError, ref warningCount, ref ftLastWarning) <= 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return errorCount;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsLoaded { get; private set; }
|
||||
|
||||
public static int WarningCount
|
||||
{
|
||||
get
|
||||
{
|
||||
if (InitLoggerDll())
|
||||
{
|
||||
int errorCount = 0;
|
||||
int warningCount = 0;
|
||||
long ftLastError = 0L;
|
||||
long ftLastWarning = 0L;
|
||||
if (NativeMethods.GetLoggerStats(string.Empty, ref errorCount, ref ftLastError, ref warningCount, ref ftLastWarning) <= 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return warningCount;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool CheckRegistry { get; set; }
|
||||
|
||||
private static bool DomainUnloaded { get; set; }
|
||||
|
||||
private static int LoggerClientIdentity { get; set; }
|
||||
|
||||
static Logger()
|
||||
{
|
||||
LoggerClientIdentity = 0;
|
||||
CheckRegistry = true;
|
||||
}
|
||||
|
||||
public static void LogConnection(string errorMessage)
|
||||
{
|
||||
if (Initialize())
|
||||
{
|
||||
NativeMethods.InternalLogConnection(LoggerClientIdentity, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public static void LogCtorDtor(string errorMessage)
|
||||
{
|
||||
if (Initialize())
|
||||
{
|
||||
NativeMethods.InternalLogCtorDtor(LoggerClientIdentity, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public static void LogCustom(int cookie, string errorMessage)
|
||||
{
|
||||
if (Initialize())
|
||||
{
|
||||
NativeMethods.InternalLogCustom(LoggerClientIdentity, cookie, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public static void LogEntryExit(string errorMessage)
|
||||
{
|
||||
if (Initialize())
|
||||
{
|
||||
NativeMethods.InternalLogEntryExit(LoggerClientIdentity, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public static void LogError(string errorMessage)
|
||||
{
|
||||
if (Initialize())
|
||||
{
|
||||
NativeMethods.InternalLogError(LoggerClientIdentity, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public static void LogInfo(string errorMessage)
|
||||
{
|
||||
if (Initialize())
|
||||
{
|
||||
NativeMethods.InternalLogInfo(LoggerClientIdentity, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public static void LogRefCount(string errorMessage)
|
||||
{
|
||||
if (Initialize())
|
||||
{
|
||||
NativeMethods.InternalLogRefCount(LoggerClientIdentity, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public static int LogRegisterCustomFlag(string flagName)
|
||||
{
|
||||
if (!Initialize())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return NativeMethods.RegisterLogFlag(LoggerClientIdentity, 11, flagName);
|
||||
}
|
||||
|
||||
public static int LogRegisterCustomFlagEx(string flagName, int defaultValue)
|
||||
{
|
||||
if (!Initialize())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return NativeMethods.RegisterLogFlagEx(LoggerClientIdentity, 11, flagName, defaultValue);
|
||||
}
|
||||
|
||||
public static void LogSQL(string errorMessage)
|
||||
{
|
||||
if (Initialize())
|
||||
{
|
||||
NativeMethods.InternalLogSQL(LoggerClientIdentity, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public static void LogSetIdentityName(string identityName)
|
||||
{
|
||||
if (Initialize())
|
||||
{
|
||||
NativeMethods.SetIdentityName(LoggerClientIdentity, identityName);
|
||||
}
|
||||
}
|
||||
|
||||
public static void LogStartStop(string errorMessage)
|
||||
{
|
||||
if (Initialize())
|
||||
{
|
||||
NativeMethods.InternalLogStartStop(LoggerClientIdentity, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public static void LogThreadStartStop(string errorMessage)
|
||||
{
|
||||
if (Initialize())
|
||||
{
|
||||
NativeMethods.InternalLogThreadStartStop(LoggerClientIdentity, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public static void LogTrace(string errorMessage)
|
||||
{
|
||||
if (Initialize())
|
||||
{
|
||||
NativeMethods.InternalLogTrace(LoggerClientIdentity, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public static void LogWarning(string errorMessage)
|
||||
{
|
||||
if (Initialize())
|
||||
{
|
||||
NativeMethods.InternalLogWarning(LoggerClientIdentity, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ResetLoggerCheck()
|
||||
{
|
||||
CheckRegistry = true;
|
||||
}
|
||||
|
||||
private static bool InitLoggerDll()
|
||||
{
|
||||
bool flag = IsLoaded;
|
||||
if (flag)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (CheckRegistry)
|
||||
{
|
||||
IntPtr intPtr = IntPtr.Zero;
|
||||
CheckRegistry = false;
|
||||
new RegistryPermission(RegistryPermissionAccess.Read, "HKEY_LOCAL_MACHINE\\Software\\ArchestrA\\Framework\\Logger").Assert();
|
||||
try
|
||||
{
|
||||
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("Software\\ArchestrA\\Framework\\Logger", writable: false);
|
||||
if (registryKey != null)
|
||||
{
|
||||
string text = Convert.ToString(registryKey.GetValue("InstallPath", string.Empty), CultureInfo.InvariantCulture);
|
||||
if (text.Length > 0)
|
||||
{
|
||||
intPtr = NativeMethods.LoadLibraryExW(wParam: new IntPtr(0), lpMdoule: Path.Combine(text, "LoggerDll.dll"), flag: 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
CodeAccessPermission.RevertAssert();
|
||||
}
|
||||
flag = intPtr != IntPtr.Zero;
|
||||
}
|
||||
IsLoaded = flag;
|
||||
return flag;
|
||||
}
|
||||
|
||||
private static bool Initialize()
|
||||
{
|
||||
if (DomainUnloaded)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (LoggerClientIdentity != 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (InitLoggerDll())
|
||||
{
|
||||
int hIdentity = 0;
|
||||
int num = NativeMethods.RegisterLoggerClient(ref hIdentity);
|
||||
LoggerClientIdentity = hIdentity;
|
||||
if (num != 0 && LoggerClientIdentity != 0)
|
||||
{
|
||||
new FileIOPermission(PermissionState.Unrestricted).Assert();
|
||||
try
|
||||
{
|
||||
NativeMethods.SetIdentityName(LoggerClientIdentity, Assembly.GetExecutingAssembly().GetName().Name);
|
||||
}
|
||||
finally
|
||||
{
|
||||
CodeAccessPermission.RevertAssert();
|
||||
}
|
||||
AppDomain.CurrentDomain.DomainUnload += OnCurrentDomainUnload;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void OnCurrentDomainUnload(object sender, EventArgs e)
|
||||
{
|
||||
UnInitialize();
|
||||
DomainUnloaded = true;
|
||||
}
|
||||
|
||||
private static void UnInitialize()
|
||||
{
|
||||
if (LoggerClientIdentity != 0)
|
||||
{
|
||||
NativeMethods.UnregisterLoggerClient(LoggerClientIdentity);
|
||||
LoggerClientIdentity = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace ArchestrA.Diagnostics;
|
||||
|
||||
internal static class NativeMethods
|
||||
{
|
||||
[DllImport("kernel32")]
|
||||
public static extern IntPtr LoadLibraryExW([MarshalAs(UnmanagedType.LPWStr)] string lpMdoule, IntPtr wParam, int flag);
|
||||
|
||||
[DllImport("kernel32")]
|
||||
internal static extern IntPtr LoadLibraryW([MarshalAs(UnmanagedType.LPWStr)] string lpMdoule);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "REGISTERLOGGERCLIENT", ExactSpelling = true)]
|
||||
internal static extern int RegisterLoggerClient(ref int hIdentity);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "UNREGISTERLOGGERCLIENT", ExactSpelling = true)]
|
||||
internal static extern int UnregisterLoggerClient(int hIdentity);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "SETIDENTITYNAME", ExactSpelling = true)]
|
||||
internal static extern int SetIdentityName(int hIdentity, string strIdentity);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "LOGERROR", ExactSpelling = true)]
|
||||
internal static extern void InternalLogError(int hIdentity, [MarshalAs(UnmanagedType.LPWStr)] string errorMessage);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "LOGWARNING", ExactSpelling = true)]
|
||||
internal static extern void InternalLogWarning(int hIdentity, [MarshalAs(UnmanagedType.LPWStr)] string errorMessage);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "LOGINFO", ExactSpelling = true)]
|
||||
internal static extern void InternalLogInfo(int hIdentity, [MarshalAs(UnmanagedType.LPWStr)] string errorMessage);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "LOGTRACE", ExactSpelling = true)]
|
||||
internal static extern void InternalLogTrace(int hIdentity, [MarshalAs(UnmanagedType.LPWStr)] string errorMessage);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "LOGSTARTSTOP", ExactSpelling = true)]
|
||||
internal static extern void InternalLogStartStop(int hIdentity, [MarshalAs(UnmanagedType.LPWStr)] string errorMessage);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "LOGENTRYEXIT", ExactSpelling = true)]
|
||||
internal static extern void InternalLogEntryExit(int hIdentity, [MarshalAs(UnmanagedType.LPWStr)] string errorMessage);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "LOGTHREADSTARTSTOP", ExactSpelling = true)]
|
||||
internal static extern void InternalLogThreadStartStop(int hIdentity, [MarshalAs(UnmanagedType.LPWStr)] string errorMessage);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "LOGSQL", ExactSpelling = true)]
|
||||
internal static extern void InternalLogSQL(int hIdentity, [MarshalAs(UnmanagedType.LPWStr)] string errorMessage);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "LOGCONNECTION", ExactSpelling = true)]
|
||||
internal static extern void InternalLogConnection(int hIdentity, [MarshalAs(UnmanagedType.LPWStr)] string errorMessage);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "LOGCTORDTOR", ExactSpelling = true)]
|
||||
internal static extern void InternalLogCtorDtor(int hIdentity, [MarshalAs(UnmanagedType.LPWStr)] string errorMessage);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "LOGREFCOUNT", ExactSpelling = true)]
|
||||
internal static extern void InternalLogRefCount(int hIdentity, [MarshalAs(UnmanagedType.LPWStr)] string errorMessage);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "REGISTERLOGFLAG", ExactSpelling = true)]
|
||||
internal static extern int RegisterLogFlag(int hIdentity, int nCustomFlag, [MarshalAs(UnmanagedType.LPWStr)] string strFlag);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "REGISTERLOGFLAGEX", ExactSpelling = true)]
|
||||
internal static extern int RegisterLogFlagEx(int hIdentity, int nCustomFlag, [MarshalAs(UnmanagedType.LPWStr)] string strFlag, int nDefaultVal);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "LOGCUSTOM2", ExactSpelling = true)]
|
||||
internal static extern void InternalLogCustom(int hIdentity, int nCustomFlag, [MarshalAs(UnmanagedType.LPWStr)] string errorMessage);
|
||||
|
||||
[DllImport("LoggerDLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "GETLOGGERSTATS", ExactSpelling = true)]
|
||||
internal static extern int GetLoggerStats([MarshalAs(UnmanagedType.LPWStr)] string hostName, ref int errorCount, ref long ftLastError, ref int warningCount, ref long ftLastWarning);
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.CodeDom.Compiler;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace ArchestrAServices.Common.Constants;
|
||||
|
||||
[Serializable]
|
||||
[GeneratedCode("System.Xml", "4.0.30319.34230")]
|
||||
[XmlType(Namespace = "urn:data.configuration.framework.asb.se:1")]
|
||||
[XmlRoot(Namespace = "urn:data.configuration.framework.asb.se:1", IsNullable = false)]
|
||||
public enum BindingType
|
||||
{
|
||||
Custom,
|
||||
NetNamedPipe,
|
||||
NetTcp,
|
||||
BasicHttp,
|
||||
Ws2007FederationHttp,
|
||||
Ws2007Http,
|
||||
WsDualHttp,
|
||||
WsHttp,
|
||||
Msmq
|
||||
}
|
||||
+198
@@ -0,0 +1,198 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace ArchestrAServices.Common.Constants;
|
||||
|
||||
public static class DiscoveryScope
|
||||
{
|
||||
public const string AsbCoreServiceScope = "archestra://coreservices";
|
||||
|
||||
public const string AsbUserServiceScope = "archestra://asb/";
|
||||
|
||||
public const string ServiceNameScope = "instancename/";
|
||||
|
||||
public const string ServiceVersionScope = "serviceversion/";
|
||||
|
||||
public const string DataTypeScope = "datatype/";
|
||||
|
||||
public const string SolutionNameScope = "asbsolution/";
|
||||
|
||||
public const string NodeNameScope = "asbnode/";
|
||||
|
||||
public const string BindingScope = "servicebinding/";
|
||||
|
||||
public const string CustomSerializerScope = "binding/customserializer/version2";
|
||||
|
||||
public const string DomainScope = "domainname/";
|
||||
|
||||
public const string NamespaceScope = "namespace/";
|
||||
|
||||
public const string SourceIdScope = "sourceid/";
|
||||
|
||||
public const string AssociationTypeScope = "associationType/";
|
||||
|
||||
public const string HierarchyIdScope = "hierarchyId/";
|
||||
|
||||
public const string HierarchyNameScope = "hierarchy/";
|
||||
|
||||
public const string TlsScope = "tls/";
|
||||
|
||||
public const string BaseRevisionScope = "baserevision/";
|
||||
|
||||
public const string RevisionScope = "revision/";
|
||||
|
||||
public static bool IsTransportSecurityScope(Uri scope)
|
||||
{
|
||||
bool result = false;
|
||||
if (scope != null)
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.Append("archestra://asb/");
|
||||
stringBuilder.Append("tls/");
|
||||
string text = stringBuilder.ToString();
|
||||
if (scope.ToString().ToUpperInvariant().StartsWith(text.ToUpperInvariant()))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static bool DoesScopeIndicateThatTlsIsEnabled(Uri scope)
|
||||
{
|
||||
bool result = false;
|
||||
if (scope != null && IsTransportSecurityScope(scope))
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.Append("archestra://asb/");
|
||||
stringBuilder.Append("tls/");
|
||||
string text = stringBuilder.ToString();
|
||||
if (bool.TryParse(scope.ToString().ToUpperInvariant().Replace(text.ToUpperInvariant(), string.Empty), out var result2))
|
||||
{
|
||||
result = result2;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Uri GetSolutionScope(string solutionName)
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.Append("archestra://asb/");
|
||||
stringBuilder.Append("asbsolution/");
|
||||
stringBuilder.Append(solutionName);
|
||||
return new Uri(stringBuilder.ToString());
|
||||
}
|
||||
|
||||
public static Uri GetSourceIdScope(ushort sourceId)
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.Append("archestra://asb/");
|
||||
stringBuilder.Append("sourceid/");
|
||||
stringBuilder.Append(sourceId.ToString(CultureInfo.InvariantCulture));
|
||||
return new Uri(stringBuilder.ToString());
|
||||
}
|
||||
|
||||
public static Uri[] GetStandardServiceScope(string instanceName, string nodeName, string solutionName, BindingType bindingType, IEnumerable<ushort> sourceIds, IEnumerable<string> associationTypes, IEnumerable<ushort> hierarchyIds, IEnumerable<string> hierarchyNames, IEnumerable<Uri> customScopes, bool tlsEnabled = false)
|
||||
{
|
||||
List<Uri> list = new List<Uri>();
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
if (!string.IsNullOrEmpty(solutionName))
|
||||
{
|
||||
list.Add(GetSolutionScope(solutionName));
|
||||
}
|
||||
Uri item;
|
||||
if (bindingType != BindingType.Custom)
|
||||
{
|
||||
stringBuilder.Append("archestra://asb/");
|
||||
stringBuilder.Append("servicebinding/");
|
||||
stringBuilder.Append(bindingType.ToString());
|
||||
item = new Uri(stringBuilder.ToString());
|
||||
stringBuilder.Clear();
|
||||
list.Add(item);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(nodeName))
|
||||
{
|
||||
stringBuilder.Append("archestra://asb/");
|
||||
stringBuilder.Append("asbnode/");
|
||||
stringBuilder.Append(nodeName);
|
||||
item = new Uri(stringBuilder.ToString());
|
||||
stringBuilder.Clear();
|
||||
list.Add(item);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(instanceName))
|
||||
{
|
||||
stringBuilder.Append("archestra://asb/");
|
||||
stringBuilder.Append("instancename/");
|
||||
stringBuilder.Append(instanceName);
|
||||
item = new Uri(stringBuilder.ToString());
|
||||
stringBuilder.Clear();
|
||||
list.Add(item);
|
||||
}
|
||||
if (sourceIds != null)
|
||||
{
|
||||
foreach (ushort sourceId in sourceIds)
|
||||
{
|
||||
stringBuilder.Append("archestra://asb/");
|
||||
stringBuilder.Append("sourceid/");
|
||||
stringBuilder.Append(sourceId.ToString(CultureInfo.InvariantCulture));
|
||||
item = new Uri(stringBuilder.ToString());
|
||||
stringBuilder.Clear();
|
||||
list.Add(item);
|
||||
}
|
||||
}
|
||||
if (associationTypes != null)
|
||||
{
|
||||
foreach (string associationType in associationTypes)
|
||||
{
|
||||
stringBuilder.Append("archestra://asb/");
|
||||
stringBuilder.Append("associationType/");
|
||||
stringBuilder.Append(associationType);
|
||||
item = new Uri(stringBuilder.ToString());
|
||||
stringBuilder.Clear();
|
||||
list.Add(item);
|
||||
}
|
||||
}
|
||||
if (hierarchyIds != null)
|
||||
{
|
||||
foreach (ushort hierarchyId in hierarchyIds)
|
||||
{
|
||||
stringBuilder.Append("archestra://asb/");
|
||||
stringBuilder.Append("hierarchyId/");
|
||||
stringBuilder.Append(hierarchyId.ToString(CultureInfo.InvariantCulture));
|
||||
item = new Uri(stringBuilder.ToString());
|
||||
stringBuilder.Clear();
|
||||
list.Add(item);
|
||||
}
|
||||
}
|
||||
if (hierarchyNames != null)
|
||||
{
|
||||
foreach (string hierarchyName in hierarchyNames)
|
||||
{
|
||||
stringBuilder.Append("archestra://asb/");
|
||||
stringBuilder.Append("hierarchy/");
|
||||
stringBuilder.Append(hierarchyName);
|
||||
item = new Uri(stringBuilder.ToString());
|
||||
stringBuilder.Clear();
|
||||
list.Add(item);
|
||||
}
|
||||
}
|
||||
stringBuilder.Clear();
|
||||
stringBuilder.Append("archestra://asb/");
|
||||
stringBuilder.Append("tls/");
|
||||
stringBuilder.Append(tlsEnabled ? "true" : "false");
|
||||
item = new Uri(stringBuilder.ToString());
|
||||
stringBuilder.Clear();
|
||||
list.Add(item);
|
||||
if (customScopes != null)
|
||||
{
|
||||
foreach (Uri customScope in customScopes)
|
||||
{
|
||||
list.Add(customScope);
|
||||
}
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
#define TRACE
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace ArchestrAServices.Common.Extensions;
|
||||
|
||||
public static class DataExtensions
|
||||
{
|
||||
public static string ToBase64(this string value)
|
||||
{
|
||||
return Convert.ToBase64String(Encoding.UTF8.GetBytes(value));
|
||||
}
|
||||
|
||||
public static string FromBase64(this string value)
|
||||
{
|
||||
string result = string.Empty;
|
||||
if (value != null)
|
||||
{
|
||||
byte[] bytes = Convert.FromBase64String(value);
|
||||
result = Encoding.UTF8.GetString(bytes);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string FromByteArrayToBase64(this byte[] value)
|
||||
{
|
||||
string result = string.Empty;
|
||||
try
|
||||
{
|
||||
result = Convert.ToBase64String(value);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Trace.WriteLine(ex.Message);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string FromByteArrayToHex(this byte[] value)
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
if (value != null)
|
||||
{
|
||||
foreach (byte b in value)
|
||||
{
|
||||
stringBuilder.Append(b.ToString("X2", CultureInfo.CurrentCulture));
|
||||
}
|
||||
}
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
public static byte[] FromBase64ToByteArray(this string value)
|
||||
{
|
||||
byte[] result = null;
|
||||
if (value != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
result = Convert.FromBase64String(value);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Trace.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static byte[] FromHexToByteArray(this string value)
|
||||
{
|
||||
List<byte> list = new List<byte>();
|
||||
if (value != null)
|
||||
{
|
||||
string text = value.Replace(" ", string.Empty);
|
||||
text = text.Replace("\r", string.Empty);
|
||||
text = text.Replace("\n", string.Empty);
|
||||
if (text.Length % 2 == 0)
|
||||
{
|
||||
for (int i = 0; i < text.Length; i += 2)
|
||||
{
|
||||
if (byte.TryParse(text.Substring(i, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var result))
|
||||
{
|
||||
list.Add(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public static byte[] Concatenate(this byte[] value, byte[] other)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw new ArgumentNullException("value");
|
||||
}
|
||||
if (other == null)
|
||||
{
|
||||
throw new ArgumentNullException("other");
|
||||
}
|
||||
List<byte> list = new List<byte>();
|
||||
list.AddRange(value);
|
||||
list.AddRange(other);
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public static int CompareTo(this byte[] value, byte[] other)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw new ArgumentNullException("value");
|
||||
}
|
||||
if (other == null)
|
||||
{
|
||||
throw new ArgumentNullException("other");
|
||||
}
|
||||
int num = -1;
|
||||
if (value.Length == other.Length)
|
||||
{
|
||||
num = 0;
|
||||
for (int i = 0; i < value.Length; i++)
|
||||
{
|
||||
if (num != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (value[i] != other[i])
|
||||
{
|
||||
num = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return num;
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Xml;
|
||||
|
||||
namespace ArchestrAServices.Common.Extensions;
|
||||
|
||||
public static class StringExtensions
|
||||
{
|
||||
public static int CompareTo(this XmlQualifiedName value, XmlQualifiedName other)
|
||||
{
|
||||
int num = 0;
|
||||
if (value != null && other != null)
|
||||
{
|
||||
num = value.IsEmpty.CompareTo(other.IsEmpty);
|
||||
if (num == 0)
|
||||
{
|
||||
num = string.Compare(value.Namespace, other.Namespace, StringComparison.Ordinal);
|
||||
if (num == 0)
|
||||
{
|
||||
num = string.Compare(value.Name, other.Name, StringComparison.Ordinal);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (value == null && other != null)
|
||||
{
|
||||
num = -1;
|
||||
}
|
||||
else if (value != null)
|
||||
{
|
||||
num = 1;
|
||||
}
|
||||
return num;
|
||||
}
|
||||
}
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace ArchestrAServices.Common;
|
||||
|
||||
public class ASBConfigurationInformation
|
||||
{
|
||||
private const string DefaultCryptoGenerator = "22";
|
||||
|
||||
private const int DefaultKeySize = 256;
|
||||
|
||||
private const string DefaultPrime768 = "1552518092300708935130918131258481755631334049434514313202351194902966239949102107258669453876591642442910007680288864229150803718918046342632727613031282983744380820890196288509170691316593175367469551763119843371637221007210577919";
|
||||
|
||||
private const string DefaultHashAlgorithm = "None";
|
||||
|
||||
private const int DefaultPasswordIterations = 1;
|
||||
|
||||
private const string DefaultSaltValue = "s@1tValue";
|
||||
|
||||
private const string DefaultInitializationVector = "ba172e9941be138b";
|
||||
|
||||
public string SolutionName { get; set; }
|
||||
|
||||
public string Generator { get; set; }
|
||||
|
||||
public string Prime { get; set; }
|
||||
|
||||
public string HashAlgorithm { get; set; }
|
||||
|
||||
public string InitializationVector { get; set; }
|
||||
|
||||
public string SaltValue { get; set; }
|
||||
|
||||
public int PasswordDerivationIterations { get; set; }
|
||||
|
||||
public int KeySize { get; set; }
|
||||
|
||||
public string EncryptedSharedSecret { get; set; }
|
||||
|
||||
public string EncryptedCertificate { get; set; }
|
||||
|
||||
public string IsDefault { get; set; }
|
||||
|
||||
public string SRNodeName { get; set; }
|
||||
|
||||
public string PrimaryGlobalDiscovery { get; set; }
|
||||
|
||||
public string SecondaryGlobalDiscovery { get; set; }
|
||||
|
||||
public string PrimaryUniversalDiscovery { get; set; }
|
||||
|
||||
public string SecondaryUniversalDiscovery { get; set; }
|
||||
|
||||
public ASBConfigurationInformation()
|
||||
{
|
||||
Generator = "22";
|
||||
KeySize = 256;
|
||||
Prime = "1552518092300708935130918131258481755631334049434514313202351194902966239949102107258669453876591642442910007680288864229150803718918046342632727613031282983744380820890196288509170691316593175367469551763119843371637221007210577919";
|
||||
HashAlgorithm = "None";
|
||||
PasswordDerivationIterations = 1;
|
||||
SaltValue = "s@1tValue";
|
||||
InitializationVector = "ba172e9941be138b";
|
||||
}
|
||||
|
||||
public static string GetNewSharedSecret(int length)
|
||||
{
|
||||
if (length < 1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("length");
|
||||
}
|
||||
StringBuilder stringBuilder = new StringBuilder(length);
|
||||
RNGCryptoServiceProvider rNGCryptoServiceProvider = new RNGCryptoServiceProvider();
|
||||
try
|
||||
{
|
||||
char[] array = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".ToCharArray();
|
||||
byte[] array2 = new byte[1];
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
do
|
||||
{
|
||||
rNGCryptoServiceProvider.GetBytes(array2);
|
||||
}
|
||||
while (!IsFairRandomNumber(array2[0], array.Length));
|
||||
stringBuilder.Append(array[array2[0] % array.Length]);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
rNGCryptoServiceProvider.Dispose();
|
||||
}
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
private static bool IsFairRandomNumber(byte randomNumber, int numChars)
|
||||
{
|
||||
int num = 255 / numChars;
|
||||
return randomNumber < numChars * num;
|
||||
}
|
||||
}
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace ArchestrAServices.Common;
|
||||
|
||||
internal class ASBCustomLoggingConfigurationParser
|
||||
{
|
||||
public static void Parse(ConfiguredLogger logger)
|
||||
{
|
||||
if (logger == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string uri = Path.Combine(Environment.CurrentDirectory, logger.ComponentName + ".logger.config");
|
||||
try
|
||||
{
|
||||
XDocument xDocument = XDocument.Load(uri);
|
||||
if (xDocument == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
XElement xElement = xDocument.Element("configuration");
|
||||
if (xElement == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
XElement xElement2 = xElement.Element("asb.diagnostics");
|
||||
if (xElement2 != null)
|
||||
{
|
||||
XElement xElement3 = xElement2.Element("sources");
|
||||
if (xElement3 != null)
|
||||
{
|
||||
ParseSources(logger, xElement3);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private static void ParseSources(ConfiguredLogger logger, XElement sourcesElement)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (XElement item in sourcesElement.Elements("source"))
|
||||
{
|
||||
XAttribute xAttribute = item.Attribute("name");
|
||||
XAttribute xAttribute2 = item.Attribute("switchValue");
|
||||
if (xAttribute == null || xAttribute2 == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
SourceLevels newLevel = SourceLevels.Off;
|
||||
try
|
||||
{
|
||||
newLevel = (SourceLevels)Enum.Parse(typeof(SourceLevels), xAttribute2.Value);
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
}
|
||||
TraceSource traceSource = logger.ChangeSourceLevel(xAttribute.Value, newLevel);
|
||||
if (traceSource == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
XElement xElement = item.Element("listeners");
|
||||
if (xElement == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
foreach (XElement item2 in xElement.Elements("add"))
|
||||
{
|
||||
XAttribute xAttribute3 = item2.Attribute("type");
|
||||
item2.Attribute("traceOutputOptions");
|
||||
XAttribute xAttribute4 = item2.Attribute("initializeData");
|
||||
if (xAttribute3 != null)
|
||||
{
|
||||
string value = xAttribute3.Value;
|
||||
if (value == "aaLoggerETWListner" && xAttribute4 != null)
|
||||
{
|
||||
string value2 = xAttribute4.Value;
|
||||
traceSource.Listeners.Remove(value2);
|
||||
aaLoggerListner aaLoggerListner2 = new aaLoggerListner(value2, logger.ComponentName);
|
||||
aaLoggerListner2.Name = value2;
|
||||
traceSource.Listeners.Add(aaLoggerListner2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.ServiceModel.Channels;
|
||||
|
||||
namespace ArchestrAServices.Common;
|
||||
|
||||
public struct ASBEndpointDescription(Uri Address, string Interface, Binding Binding)
|
||||
{
|
||||
public Uri EndpointAddress = Address;
|
||||
|
||||
public string EndpointInterface = Interface;
|
||||
|
||||
public Binding EndpointBinding = Binding;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
using System.Security.Permissions;
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
|
||||
namespace ArchestrAServices.Common;
|
||||
|
||||
[SecurityPermission(SecurityAction.InheritanceDemand, UnmanagedCode = true)]
|
||||
[SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
|
||||
internal class ArchestraSafeHandle : SafeHandleZeroOrMinusOneIsInvalid
|
||||
{
|
||||
internal static ArchestraSafeHandle Empty => new ArchestraSafeHandle();
|
||||
|
||||
internal IntPtr Handle
|
||||
{
|
||||
get
|
||||
{
|
||||
return handle;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetHandle(value);
|
||||
}
|
||||
}
|
||||
|
||||
private ArchestraSafeHandle()
|
||||
: base(ownsHandle: true)
|
||||
{
|
||||
}
|
||||
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
|
||||
protected override bool ReleaseHandle()
|
||||
{
|
||||
return NativeMethods.CloseHandle(handle);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace ArchestrAServices.Common;
|
||||
|
||||
public sealed class ConfigFileWatcher : IDisposable
|
||||
{
|
||||
private static readonly ConfigFileWatcher theInstance = new ConfigFileWatcher();
|
||||
|
||||
private readonly List<FileSystemEventHandler> eventHandlers = new List<FileSystemEventHandler>();
|
||||
|
||||
private bool disposed;
|
||||
|
||||
private FileSystemWatcher watcher;
|
||||
|
||||
private ConfigFileWatcher()
|
||||
{
|
||||
string directoryName = Path.GetDirectoryName(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
|
||||
string fileName = Path.GetFileName(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
|
||||
if (string.IsNullOrWhiteSpace(directoryName) || string.IsNullOrWhiteSpace(fileName))
|
||||
{
|
||||
throw new ArgumentException("Invalid configuration file path.");
|
||||
}
|
||||
watcher = new FileSystemWatcher(directoryName, fileName);
|
||||
AppDomain.CurrentDomain.ProcessExit += delegate
|
||||
{
|
||||
Dispose();
|
||||
};
|
||||
}
|
||||
|
||||
public static void AddHandler(FileSystemEventHandler eventHandler)
|
||||
{
|
||||
theInstance.RegisterHandler(eventHandler);
|
||||
}
|
||||
|
||||
public static void RemoveHandler(FileSystemEventHandler eventHandler)
|
||||
{
|
||||
theInstance.UnRegisterHandler(eventHandler);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
}
|
||||
|
||||
private void RegisterHandler(FileSystemEventHandler eventHandler)
|
||||
{
|
||||
if (watcher != null)
|
||||
{
|
||||
watcher.Changed += eventHandler;
|
||||
eventHandlers.Add(eventHandler);
|
||||
watcher.EnableRaisingEvents = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void UnRegisterHandler(FileSystemEventHandler eventHandler)
|
||||
{
|
||||
if (watcher != null)
|
||||
{
|
||||
watcher.Changed -= eventHandler;
|
||||
eventHandlers.Remove(eventHandler);
|
||||
if (!eventHandlers.Any())
|
||||
{
|
||||
watcher.EnableRaisingEvents = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
if (disposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (disposing && watcher != null)
|
||||
{
|
||||
foreach (FileSystemEventHandler eventHandler in eventHandlers)
|
||||
{
|
||||
watcher.Changed -= eventHandler;
|
||||
}
|
||||
watcher.EnableRaisingEvents = false;
|
||||
watcher.Dispose();
|
||||
watcher = null;
|
||||
eventHandlers.Clear();
|
||||
}
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
#define TRACE
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace ArchestrAServices.Common;
|
||||
|
||||
public class ConfigurationRepository
|
||||
{
|
||||
private readonly Dictionary<string, string> configurationRepositoryInternal = new Dictionary<string, string>();
|
||||
|
||||
public ConfigurationRepository()
|
||||
{
|
||||
configurationRepositoryInternal = new Dictionary<string, string>();
|
||||
Initialize();
|
||||
}
|
||||
|
||||
public static string ExtractValueFromKey(XElement configuration, string key, string defaultValue)
|
||||
{
|
||||
string text = LookupKeyInElement(configuration, "ServiceParameters", key);
|
||||
if (string.IsNullOrEmpty(text))
|
||||
{
|
||||
text = LookupKeyInElement(configuration, "CustomData", key);
|
||||
}
|
||||
if (string.IsNullOrEmpty(text))
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 2, $"ExtractValueFromKey cannot find key '{key}', using default '{defaultValue}'");
|
||||
text = defaultValue;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
public void InsertExtractedParameter(XElement configuration, string Name, string DefaultValue = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(DefaultValue))
|
||||
{
|
||||
DefaultValue = GetParameter(Name);
|
||||
}
|
||||
string value = ExtractValueFromKey(configuration, Name, DefaultValue);
|
||||
configurationRepositoryInternal[Name] = value;
|
||||
}
|
||||
|
||||
public void InsertParameter(string Name, string Value)
|
||||
{
|
||||
configurationRepositoryInternal[Name] = Value;
|
||||
}
|
||||
|
||||
public string GetParameter(string Name)
|
||||
{
|
||||
string result = string.Empty;
|
||||
if (configurationRepositoryInternal.ContainsKey(Name))
|
||||
{
|
||||
result = configurationRepositoryInternal[Name];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public string GetParameter(string Name, string DefaultValue)
|
||||
{
|
||||
string text = GetParameter(Name);
|
||||
if (string.IsNullOrEmpty(text))
|
||||
{
|
||||
text = DefaultValue;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
private static string LookupKeyInElement(XElement configuration, string OuterElement, string key)
|
||||
{
|
||||
string empty = string.Empty;
|
||||
try
|
||||
{
|
||||
string text = (from ServiceParameters in configuration.Element(OuterElement).Elements("Parameter")
|
||||
where key == ServiceParameters.Attribute("name").Value
|
||||
select ServiceParameters.Attribute("value").Value).First();
|
||||
if (text != null && text.Length > 0)
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 3, $"ExtractValueFromKey extracting value '{text}' from key '{key}'");
|
||||
empty = text;
|
||||
}
|
||||
else
|
||||
{
|
||||
empty = string.Empty;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
empty = string.Empty;
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 0, $"Exception raised : {ex.Message}");
|
||||
}
|
||||
return empty;
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
InsertParameter("netTcpBinding.Security.Mode", "None");
|
||||
InsertParameter("netTcpBinding.TransferMode", "Buffered");
|
||||
InsertParameter("netTcpBinding.MaxReceivedMessageSize", int.MaxValue.ToString());
|
||||
InsertParameter("netTcpBinding.MaxBufferSize", int.MaxValue.ToString());
|
||||
InsertParameter("netTcpBinding.MaxBufferPoolSize", long.MaxValue.ToString());
|
||||
InsertParameter("netTcpBinding.ReaderQuotas.MaxArrayLength", int.MaxValue.ToString());
|
||||
InsertParameter("netTcpBinding.ReaderQuotas.MaxBytesPerRead", int.MaxValue.ToString());
|
||||
InsertParameter("netTcpBinding.ReaderQuotas.MaxDepth", int.MaxValue.ToString());
|
||||
InsertParameter("netTcpBinding.ReaderQuotas.MaxNameTableCharCount", int.MaxValue.ToString());
|
||||
InsertParameter("netTcpBinding.ReaderQuotas.MaxStringContentLength", int.MaxValue.ToString());
|
||||
InsertParameter("netTcpBinding.OpenTimeout", new TimeSpan(0, 1, 0).ToString());
|
||||
InsertParameter("netTcpBinding.ReceiveTimeout", new TimeSpan(0, 1, 0).ToString());
|
||||
InsertParameter("netTcpBinding.SendTimeout", new TimeSpan(0, 1, 0).ToString());
|
||||
InsertParameter("netTcpBinding.CloseTimeout", new TimeSpan(0, 1, 0).ToString());
|
||||
InsertParameter("netTcpBinding.ReliableSession.InactivityTimeout", new TimeSpan(0, 1, 0).ToString());
|
||||
InsertParameter("HttpBinding.Security.Mode", "None");
|
||||
InsertParameter("HttpBinding.AllowCookies", "false");
|
||||
InsertParameter("HttpBinding.BypassProxyOnLocal", "true");
|
||||
InsertParameter("HttpBinding.HostNameComparisonMode", "StrongWildcard");
|
||||
InsertParameter("HttpBinding.MessageEncoding", "Text");
|
||||
InsertParameter("HttpBinding.MaxReceivedMessageSize", int.MaxValue.ToString());
|
||||
InsertParameter("HttpBinding.MaxBufferPoolSize", long.MaxValue.ToString());
|
||||
InsertParameter("HttpBinding.ReaderQuotas.MaxArrayLength", int.MaxValue.ToString());
|
||||
InsertParameter("HttpBinding.ReaderQuotas.MaxBytesPerRead", int.MaxValue.ToString());
|
||||
InsertParameter("HttpBinding.ReaderQuotas.MaxDepth", int.MaxValue.ToString());
|
||||
InsertParameter("HttpBinding.ReaderQuotas.MaxNameTableCharCount", int.MaxValue.ToString());
|
||||
InsertParameter("HttpBinding.ReaderQuotas.MaxStringContentLength", int.MaxValue.ToString());
|
||||
InsertParameter("HttpBinding.OpenTimeout", new TimeSpan(0, 1, 0).ToString());
|
||||
InsertParameter("HttpBinding.ReceiveTimeout", new TimeSpan(0, 1, 0).ToString());
|
||||
InsertParameter("HttpBinding.SendTimeout", new TimeSpan(0, 1, 0).ToString());
|
||||
InsertParameter("HttpBinding.CloseTimeout", new TimeSpan(0, 1, 0).ToString());
|
||||
InsertParameter("HttpBinding.ReliableSession.InactivityTimeout", new TimeSpan(0, 1, 0).ToString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace ArchestrAServices.Common;
|
||||
|
||||
public class ConfiguredLogger
|
||||
{
|
||||
private Dictionary<string, TraceSource> TraceSourceMap;
|
||||
|
||||
public string ComponentName { get; set; }
|
||||
|
||||
public ConfiguredLogger(string componentName)
|
||||
{
|
||||
TraceSourceMap = new Dictionary<string, TraceSource>();
|
||||
ComponentName = componentName;
|
||||
AddCustomTraceSource("DataFlowLogs", SvcTrace.DiagData, "LogTraceType");
|
||||
AddCustomTraceSource("ControlFlowLogs", SvcTrace.DiagControl, "LogInfoType");
|
||||
AddCustomTraceSource("CommandLogs", SvcTrace.DiagCommand, "ASBCommand");
|
||||
AddCustomTraceSource("ExceptionLogs", SvcTrace.DiagException, "ASBException");
|
||||
AddCustomTraceSource("DiagnosticsLogs", SvcTrace.DiagDiagnostics, "ASBDiagnostic");
|
||||
}
|
||||
|
||||
public void AddCustomTraceSource(string name, TraceSource source, string logFlag, SourceLevels newLevel = SourceLevels.Off)
|
||||
{
|
||||
TraceSourceMap[name] = source;
|
||||
bool flag = false;
|
||||
foreach (TraceListener listener in source.Listeners)
|
||||
{
|
||||
if (listener.Name == logFlag)
|
||||
{
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
source.Listeners.Remove("Default");
|
||||
if (!flag)
|
||||
{
|
||||
aaLoggerListner aaLoggerListner2 = new aaLoggerListner(logFlag, ComponentName);
|
||||
aaLoggerListner2.Name = logFlag;
|
||||
aaLoggerListner2.SourceLevel = newLevel;
|
||||
source.Listeners.Add(aaLoggerListner2);
|
||||
if (source.Switch == null || source.Switch.DisplayName != name)
|
||||
{
|
||||
source.Switch = new SourceSwitch(name);
|
||||
}
|
||||
source.Switch.Level = SourceLevels.All;
|
||||
}
|
||||
}
|
||||
|
||||
public TraceSource ChangeSourceLevel(string name, SourceLevels newLevel)
|
||||
{
|
||||
TraceSource value = null;
|
||||
if (TraceSourceMap.TryGetValue(name, out value) && value.Switch != null)
|
||||
{
|
||||
value.Switch.Level = newLevel;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public void ReloadConfiguration()
|
||||
{
|
||||
ASBCustomLoggingConfigurationParser.Parse(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,232 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace ArchestrAServices.Common;
|
||||
|
||||
public class DPUtility
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
internal struct DATA_BLOB
|
||||
{
|
||||
public int cbData;
|
||||
|
||||
public IntPtr pbData;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
internal struct CRYPTPROTECT_PROMPTSTRUCT
|
||||
{
|
||||
public int cbSize;
|
||||
|
||||
public int dwPromptFlags;
|
||||
|
||||
public IntPtr hwndApp;
|
||||
|
||||
public string szPrompt;
|
||||
}
|
||||
|
||||
public enum Store
|
||||
{
|
||||
USE_MACHINE_STORE = 1,
|
||||
USE_USER_STORE
|
||||
}
|
||||
|
||||
private static IntPtr NullPtr = (IntPtr)0;
|
||||
|
||||
private const int CRYPTPROTECT_UI_FORBIDDEN = 1;
|
||||
|
||||
private const int CRYPTPROTECT_LOCAL_MACHINE = 4;
|
||||
|
||||
private Store store;
|
||||
|
||||
[DllImport("Crypt32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
private static extern bool CryptProtectData(ref DATA_BLOB pDataIn, string szDataDescr, ref DATA_BLOB pOptionalEntropy, IntPtr pvReserved, ref CRYPTPROTECT_PROMPTSTRUCT pPromptStruct, int dwFlags, ref DATA_BLOB pDataOut);
|
||||
|
||||
[DllImport("Crypt32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
private static extern bool CryptUnprotectData(ref DATA_BLOB pDataIn, string szDataDescr, ref DATA_BLOB pOptionalEntropy, IntPtr pvReserved, ref CRYPTPROTECT_PROMPTSTRUCT pPromptStruct, int dwFlags, ref DATA_BLOB pDataOut);
|
||||
|
||||
public DPUtility(Store tempStore)
|
||||
{
|
||||
store = tempStore;
|
||||
}
|
||||
|
||||
public byte[] Encrypt(byte[] plainText, byte[] optionalEntropy)
|
||||
{
|
||||
if (plainText == null || plainText.Length == 0)
|
||||
{
|
||||
if (optionalEntropy == null)
|
||||
{
|
||||
optionalEntropy = new byte[0];
|
||||
}
|
||||
return new byte[0];
|
||||
}
|
||||
DATA_BLOB pDataIn = default(DATA_BLOB);
|
||||
DATA_BLOB pDataOut = default(DATA_BLOB);
|
||||
DATA_BLOB pOptionalEntropy = default(DATA_BLOB);
|
||||
CRYPTPROTECT_PROMPTSTRUCT ps = default(CRYPTPROTECT_PROMPTSTRUCT);
|
||||
InitPromptstruct(ref ps);
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
int num = plainText.Length;
|
||||
pDataIn.pbData = Marshal.AllocHGlobal(num);
|
||||
if (IntPtr.Zero == pDataIn.pbData)
|
||||
{
|
||||
throw new Exception("Unable to allocate plaintext buffer.");
|
||||
}
|
||||
pDataIn.cbData = num;
|
||||
Marshal.Copy(plainText, 0, pDataIn.pbData, num);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("Exception marshalling data. " + ex.Message);
|
||||
}
|
||||
int dwFlags;
|
||||
if (Store.USE_MACHINE_STORE == store)
|
||||
{
|
||||
dwFlags = 5;
|
||||
if (optionalEntropy == null)
|
||||
{
|
||||
optionalEntropy = new byte[0];
|
||||
}
|
||||
try
|
||||
{
|
||||
int num2 = optionalEntropy.Length;
|
||||
pOptionalEntropy.pbData = Marshal.AllocHGlobal(optionalEntropy.Length);
|
||||
if (IntPtr.Zero == pOptionalEntropy.pbData)
|
||||
{
|
||||
throw new Exception("Unable to allocate entropy data buffer.");
|
||||
}
|
||||
Marshal.Copy(optionalEntropy, 0, pOptionalEntropy.pbData, num2);
|
||||
pOptionalEntropy.cbData = num2;
|
||||
}
|
||||
catch (Exception ex2)
|
||||
{
|
||||
throw new Exception("Exception entropy marshalling data. " + ex2.Message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dwFlags = 1;
|
||||
}
|
||||
if (!CryptProtectData(ref pDataIn, string.Empty, ref pOptionalEntropy, IntPtr.Zero, ref ps, dwFlags, ref pDataOut))
|
||||
{
|
||||
throw new Exception("Encryption failed.");
|
||||
}
|
||||
if (IntPtr.Zero != pDataIn.pbData)
|
||||
{
|
||||
Marshal.FreeHGlobal(pDataIn.pbData);
|
||||
}
|
||||
if (IntPtr.Zero != pOptionalEntropy.pbData)
|
||||
{
|
||||
Marshal.FreeHGlobal(pOptionalEntropy.pbData);
|
||||
}
|
||||
}
|
||||
catch (Exception ex3)
|
||||
{
|
||||
throw new Exception("Exception encrypting. " + ex3.Message);
|
||||
}
|
||||
byte[] array = new byte[pDataOut.cbData];
|
||||
Marshal.Copy(pDataOut.pbData, array, 0, pDataOut.cbData);
|
||||
Marshal.FreeHGlobal(pDataOut.pbData);
|
||||
return array;
|
||||
}
|
||||
|
||||
private void InitPromptstruct(ref CRYPTPROTECT_PROMPTSTRUCT ps)
|
||||
{
|
||||
ps.cbSize = Marshal.SizeOf(typeof(CRYPTPROTECT_PROMPTSTRUCT));
|
||||
ps.dwPromptFlags = 0;
|
||||
ps.hwndApp = NullPtr;
|
||||
ps.szPrompt = null;
|
||||
}
|
||||
|
||||
public byte[] Decrypt(byte[] cipherText, byte[] optionalEntropy)
|
||||
{
|
||||
if (cipherText == null || cipherText.Length == 0)
|
||||
{
|
||||
if (optionalEntropy == null)
|
||||
{
|
||||
optionalEntropy = new byte[0];
|
||||
}
|
||||
return new byte[0];
|
||||
}
|
||||
DATA_BLOB pDataOut = default(DATA_BLOB);
|
||||
DATA_BLOB pDataIn = default(DATA_BLOB);
|
||||
CRYPTPROTECT_PROMPTSTRUCT ps = default(CRYPTPROTECT_PROMPTSTRUCT);
|
||||
InitPromptstruct(ref ps);
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
int num = cipherText.Length;
|
||||
pDataIn.pbData = Marshal.AllocHGlobal(num);
|
||||
if (IntPtr.Zero == pDataIn.pbData)
|
||||
{
|
||||
throw new Exception("Unable to allocate cipherText buffer.");
|
||||
}
|
||||
pDataIn.cbData = num;
|
||||
Marshal.Copy(cipherText, 0, pDataIn.pbData, pDataIn.cbData);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("Exception marshalling data. " + ex.Message);
|
||||
}
|
||||
DATA_BLOB pOptionalEntropy = default(DATA_BLOB);
|
||||
int dwFlags;
|
||||
if (Store.USE_MACHINE_STORE == store)
|
||||
{
|
||||
dwFlags = 5;
|
||||
if (optionalEntropy == null)
|
||||
{
|
||||
optionalEntropy = new byte[0];
|
||||
}
|
||||
try
|
||||
{
|
||||
int num2 = optionalEntropy.Length;
|
||||
pOptionalEntropy.pbData = Marshal.AllocHGlobal(num2);
|
||||
if (IntPtr.Zero == pOptionalEntropy.pbData)
|
||||
{
|
||||
throw new Exception("Unable to allocate entropy buffer.");
|
||||
}
|
||||
pOptionalEntropy.cbData = num2;
|
||||
Marshal.Copy(optionalEntropy, 0, pOptionalEntropy.pbData, num2);
|
||||
}
|
||||
catch (Exception ex2)
|
||||
{
|
||||
throw new Exception("Exception entropy marshalling data. " + ex2.Message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dwFlags = 1;
|
||||
}
|
||||
if (!CryptUnprotectData(ref pDataIn, null, ref pOptionalEntropy, IntPtr.Zero, ref ps, dwFlags, ref pDataOut))
|
||||
{
|
||||
throw new Exception("Decryption failed.");
|
||||
}
|
||||
if (IntPtr.Zero != pDataIn.pbData)
|
||||
{
|
||||
Marshal.FreeHGlobal(pDataIn.pbData);
|
||||
}
|
||||
if (IntPtr.Zero != pOptionalEntropy.pbData)
|
||||
{
|
||||
Marshal.FreeHGlobal(pOptionalEntropy.pbData);
|
||||
}
|
||||
}
|
||||
catch (Exception ex3)
|
||||
{
|
||||
throw new Exception("Exception decrypting. " + ex3.Message);
|
||||
}
|
||||
byte[] array = new byte[pDataOut.cbData];
|
||||
Marshal.Copy(pDataOut.pbData, array, 0, pDataOut.cbData);
|
||||
Marshal.FreeHGlobal(pDataOut.pbData);
|
||||
return array;
|
||||
}
|
||||
|
||||
public byte[] GetOptionalEntropy()
|
||||
{
|
||||
return Encoding.Unicode.GetBytes("wonderware");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
#define TRACE
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace ArchestrAServices.Common;
|
||||
|
||||
public static class DetachedProcess
|
||||
{
|
||||
private static class NativeMethods
|
||||
{
|
||||
public struct STARTUPINFO
|
||||
{
|
||||
public int cb;
|
||||
|
||||
public string lpReserved;
|
||||
|
||||
public string lpDesktop;
|
||||
|
||||
public string lpTitle;
|
||||
|
||||
public int dwX;
|
||||
|
||||
public int dwY;
|
||||
|
||||
public int dwXSize;
|
||||
|
||||
public int dwXCountChars;
|
||||
|
||||
public int dwYCountChars;
|
||||
|
||||
public int dwFillAttribute;
|
||||
|
||||
public int dwFlags;
|
||||
|
||||
public short wShowWindow;
|
||||
|
||||
public short cbReserved2;
|
||||
|
||||
public IntPtr lpReserved2;
|
||||
|
||||
public IntPtr hStdInput;
|
||||
|
||||
public IntPtr hStdOutput;
|
||||
|
||||
public IntPtr hStdError;
|
||||
}
|
||||
|
||||
public struct STARTUPINFOEX
|
||||
{
|
||||
public STARTUPINFO StartupInfo;
|
||||
|
||||
public IntPtr lpAttributeList;
|
||||
}
|
||||
|
||||
public struct PROCESS_INFORMATION
|
||||
{
|
||||
public IntPtr hProcess;
|
||||
|
||||
public IntPtr hThread;
|
||||
|
||||
public int dwProcessID;
|
||||
|
||||
public int dwThreadID;
|
||||
}
|
||||
|
||||
public struct SECURITY_ATTRIBUTES
|
||||
{
|
||||
public int Length;
|
||||
|
||||
public IntPtr lpSecurityDescriptor;
|
||||
|
||||
public bool bInheritHandle;
|
||||
}
|
||||
|
||||
public const uint ZERO_FLAG = 0u;
|
||||
|
||||
public const uint CREATE_BREAKAWAY_FROM_JOB = 16777216u;
|
||||
|
||||
public const uint CREATE_DEFAULT_ERROR_MODE = 67108864u;
|
||||
|
||||
public const uint CREATE_NEW_CONSOLE = 16u;
|
||||
|
||||
public const uint CREATE_NEW_PROCESS_GROUP = 512u;
|
||||
|
||||
public const uint CREATE_NO_WINDOW = 134217728u;
|
||||
|
||||
public const uint CREATE_PROTECTED_PROCESS = 262144u;
|
||||
|
||||
public const uint CREATE_PRESERVE_CODE_AUTHZ_LEVEL = 33554432u;
|
||||
|
||||
public const uint CREATE_SEPARATE_WOW_VDM = 4096u;
|
||||
|
||||
public const uint CREATE_SHARED_WOW_VDM = 4096u;
|
||||
|
||||
public const uint CREATE_SUSPENDED = 4u;
|
||||
|
||||
public const uint CREATE_UNICODE_ENVIRONMENT = 1024u;
|
||||
|
||||
public const uint DEBUG_ONLY_THIS_PROCESS = 2u;
|
||||
|
||||
public const uint DEBUG_PROCESS = 1u;
|
||||
|
||||
public const uint DETACHED_PROCESS = 8u;
|
||||
|
||||
public const uint EXTENDED_STARTUPINFO_PRESENT = 524288u;
|
||||
|
||||
public const uint INHERIT_PARENT_AFFINITY = 65536u;
|
||||
|
||||
public const uint PROC_THREAD_ATTRIBUTE_HANDLE_LIST = 131074u;
|
||||
|
||||
public const uint PROC_THREAD_ATTRIBUTE_PARENT_PROCESS = 131072u;
|
||||
|
||||
public const uint FILE_ACCESS_WRITE = 1073741824u;
|
||||
|
||||
public const int STARTF_USESTDHANDLES = 256;
|
||||
|
||||
[DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern bool CreateProcess([MarshalAs(UnmanagedType.LPTStr)] string lpApplicationName, StringBuilder lpCommandLine, ref SECURITY_ATTRIBUTES lpProcessAttributes, ref SECURITY_ATTRIBUTES lpThreadAttributes, bool bInheritHandles, uint dwCreationFlags, IntPtr lpEnvironment, [MarshalAs(UnmanagedType.LPTStr)] string lpCurrentDirectory, [In] ref STARTUPINFOEX lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool InitializeProcThreadAttributeList(IntPtr lpAttributeList, int dwAttributeCount, int dwFlags, ref IntPtr lpSize);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool DeleteProcThreadAttributeList(IntPtr lpAttributeList);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
public static extern bool CloseHandle(IntPtr hHandle);
|
||||
}
|
||||
|
||||
public static Process Start(string executablePath, string commandLine)
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, "Starting detached process {0} {1} with command '{2}'", Environment.CurrentDirectory, executablePath, commandLine);
|
||||
NativeMethods.STARTUPINFOEX lpStartupInfo = default(NativeMethods.STARTUPINFOEX);
|
||||
lpStartupInfo.StartupInfo.cb = Marshal.SizeOf((object)lpStartupInfo);
|
||||
lpStartupInfo.lpAttributeList = IntPtr.Zero;
|
||||
try
|
||||
{
|
||||
IntPtr lpSize = IntPtr.Zero;
|
||||
if (NativeMethods.InitializeProcThreadAttributeList(IntPtr.Zero, 1, 0, ref lpSize) || lpSize == IntPtr.Zero)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
IntPtr intPtr = Marshal.AllocHGlobal(lpSize);
|
||||
if (!NativeMethods.InitializeProcThreadAttributeList(intPtr, 1, 0, ref lpSize))
|
||||
{
|
||||
Marshal.FreeHGlobal(intPtr);
|
||||
return null;
|
||||
}
|
||||
lpStartupInfo.lpAttributeList = intPtr;
|
||||
NativeMethods.SECURITY_ATTRIBUTES lpProcessAttributes = default(NativeMethods.SECURITY_ATTRIBUTES);
|
||||
lpProcessAttributes.Length = Marshal.SizeOf((object)lpProcessAttributes);
|
||||
lpProcessAttributes.bInheritHandle = true;
|
||||
StringBuilder lpCommandLine = new StringBuilder(commandLine);
|
||||
if (NativeMethods.CreateProcess(executablePath, lpCommandLine, ref lpProcessAttributes, ref lpProcessAttributes, bInheritHandles: false, 8u, IntPtr.Zero, null, ref lpStartupInfo, out var lpProcessInformation))
|
||||
{
|
||||
NativeMethods.CloseHandle(lpProcessInformation.hProcess);
|
||||
NativeMethods.CloseHandle(lpProcessInformation.hThread);
|
||||
return Process.GetProcessById(lpProcessInformation.dwProcessID);
|
||||
}
|
||||
int lastWin32Error = Marshal.GetLastWin32Error();
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Warning, 0, "Starting detached process {0} failed with error {1}", executablePath, lastWin32Error);
|
||||
return null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SvcTrace.DiagControl.TraceEvent(TraceEventType.Warning, 0, "Detached process start failed: {0}", ex.Message);
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (lpStartupInfo.lpAttributeList != IntPtr.Zero)
|
||||
{
|
||||
NativeMethods.DeleteProcThreadAttributeList(lpStartupInfo.lpAttributeList);
|
||||
Marshal.FreeHGlobal(lpStartupInfo.lpAttributeList);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Management;
|
||||
using System.Security;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace ArchestrAServices.Common;
|
||||
|
||||
public static class FingerprintedDataProtector
|
||||
{
|
||||
private const string PrefixV1 = "____NCHENC___";
|
||||
|
||||
private static readonly byte[] AdditionalEntropy = Value;
|
||||
|
||||
private static readonly UTF8Encoding Encoding = new UTF8Encoding();
|
||||
|
||||
private static byte[] Value => GetHash(string.Format(CultureInfo.InvariantCulture, "{0}, {1}", new object[2]
|
||||
{
|
||||
CpuId(),
|
||||
BiosId()
|
||||
}), string.Format(CultureInfo.InvariantCulture, "{0}, {1}", new object[2]
|
||||
{
|
||||
BaseId(),
|
||||
DiskId()
|
||||
}));
|
||||
|
||||
public static string Protect(string data)
|
||||
{
|
||||
return Convert.ToBase64String(Protect(Encoding.GetBytes(AttachPrefix(data))));
|
||||
}
|
||||
|
||||
public static byte[] Protect(byte[] data)
|
||||
{
|
||||
return ProtectedData.Protect(data, AdditionalEntropy, DataProtectionScope.LocalMachine);
|
||||
}
|
||||
|
||||
public static string Unprotect(string encoded)
|
||||
{
|
||||
return DetachPrefix(Encoding.GetString(Unprotect(Convert.FromBase64String(encoded))));
|
||||
}
|
||||
|
||||
public static byte[] Unprotect(byte[] encoded)
|
||||
{
|
||||
return ProtectedData.Unprotect(encoded, AdditionalEntropy, DataProtectionScope.LocalMachine);
|
||||
}
|
||||
|
||||
private static string AttachPrefix(string toEncode)
|
||||
{
|
||||
return "____NCHENC___" + toEncode;
|
||||
}
|
||||
|
||||
private static string BaseId()
|
||||
{
|
||||
Dictionary<string, string> dictionary = Identifier("Win32_BaseBoard", "Model", "Manufacturer", "Name", "SerialNumber");
|
||||
return string.Format(CultureInfo.InvariantCulture, "{0}-{1}-{2}-{3}", dictionary["Model"], dictionary["Manufacturer"], dictionary["Name"], dictionary["SerialNumber"]);
|
||||
}
|
||||
|
||||
private static string BiosId()
|
||||
{
|
||||
Dictionary<string, string> dictionary = Identifier("Win32_BIOS", "Manufacturer", "IdentificationCode");
|
||||
return string.Format(CultureInfo.InvariantCulture, "{0}-{1}", new object[2]
|
||||
{
|
||||
dictionary["Manufacturer"],
|
||||
dictionary["IdentificationCode"]
|
||||
});
|
||||
}
|
||||
|
||||
private static string CpuId()
|
||||
{
|
||||
Dictionary<string, string> dictionary = Identifier("Win32_Processor", "UniqueId", "ProcessorId", "Name", "Manufacturer", "MaxClockSpeed");
|
||||
return string.Format(CultureInfo.InvariantCulture, "{0}-{1}-{2}-{3}-{4}", dictionary["UniqueId"], dictionary["ProcessorId"], dictionary["Name"], dictionary["Manufacturer"], dictionary["MaxClockSpeed"]);
|
||||
}
|
||||
|
||||
private static string DetachPrefix(string decoded)
|
||||
{
|
||||
if (decoded.Length > "____NCHENC___".Length && decoded.StartsWith("____NCHENC___", StringComparison.Ordinal))
|
||||
{
|
||||
return decoded.Substring("____NCHENC___".Length);
|
||||
}
|
||||
throw new SecurityException("Invalid encoded string.");
|
||||
}
|
||||
|
||||
private static string DiskId()
|
||||
{
|
||||
Dictionary<string, string> dictionary = Identifier("Win32_DiskDrive", "Model", "Manufacturer", "Signature", "TotalHeads");
|
||||
return string.Format(CultureInfo.InvariantCulture, "{0}-{1}-{2}-{3}", dictionary["Model"], dictionary["Manufacturer"], dictionary["Signature"], dictionary["TotalHeads"]);
|
||||
}
|
||||
|
||||
private static byte[] GetHash(string partOne, string partTwo)
|
||||
{
|
||||
byte[] bytes = new UTF8Encoding().GetBytes(partTwo);
|
||||
using Rfc2898DeriveBytes rfc2898DeriveBytes = new Rfc2898DeriveBytes(partOne, bytes);
|
||||
return rfc2898DeriveBytes.GetBytes(16);
|
||||
}
|
||||
|
||||
private static Dictionary<string, string> Identifier(string wmiClass, params string[] wmiProperties)
|
||||
{
|
||||
Dictionary<string, string> dictionary = new Dictionary<string, string>(wmiProperties.Length);
|
||||
string[] array = wmiProperties;
|
||||
foreach (string key in array)
|
||||
{
|
||||
dictionary[key] = string.Empty;
|
||||
}
|
||||
using ManagementClass managementClass = new ManagementClass(wmiClass);
|
||||
foreach (ManagementObject item in managementClass.GetInstances().Cast<ManagementObject>())
|
||||
{
|
||||
array = wmiProperties;
|
||||
foreach (string text in array)
|
||||
{
|
||||
try
|
||||
{
|
||||
dictionary[text] = item[text].ToString();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
dictionary[text] = string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
return dictionary;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,416 @@
|
||||
#define TRACE
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
|
||||
namespace ArchestrAServices.Common;
|
||||
|
||||
public class HostNameValidator
|
||||
{
|
||||
public static bool IsValidHostAddress(string hostAddress)
|
||||
{
|
||||
bool result = false;
|
||||
try
|
||||
{
|
||||
UriHostNameType uriHostNameType = Uri.CheckHostName(hostAddress);
|
||||
if (uriHostNameType != UriHostNameType.Unknown)
|
||||
{
|
||||
result = true;
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, $"The Host Address {hostAddress} is a valid {uriHostNameType}.");
|
||||
}
|
||||
else
|
||||
{
|
||||
SvcTrace.DiagControl.TraceEvent(TraceEventType.Warning, 0, $"The given host Address {hostAddress} is invalid");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 0, ex.Message);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static bool IsValidIPAddress(string hostAddress)
|
||||
{
|
||||
bool result = false;
|
||||
try
|
||||
{
|
||||
UriHostNameType uriHostNameType = Uri.CheckHostName(hostAddress);
|
||||
if (uriHostNameType != UriHostNameType.Unknown)
|
||||
{
|
||||
result = true;
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, $"The Host Address {hostAddress} is a valid {uriHostNameType}.");
|
||||
}
|
||||
else
|
||||
{
|
||||
SvcTrace.DiagControl.TraceEvent(TraceEventType.Warning, 0, $"The given host Address {hostAddress} is invalid");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 0, ex.Message);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static bool IsValidFQDNAddress(string hostAddress)
|
||||
{
|
||||
bool result = false;
|
||||
try
|
||||
{
|
||||
UriHostNameType uriHostNameType = Uri.CheckHostName(hostAddress);
|
||||
if (uriHostNameType != UriHostNameType.Unknown)
|
||||
{
|
||||
result = true;
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, $"The Host Address {hostAddress} is a valid {uriHostNameType}.");
|
||||
}
|
||||
else
|
||||
{
|
||||
SvcTrace.DiagControl.TraceEvent(TraceEventType.Warning, 0, $"The given host Address {hostAddress} is invalid");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 0, ex.Message);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static bool IsValidNodeName(string nodeName)
|
||||
{
|
||||
bool result = false;
|
||||
try
|
||||
{
|
||||
UriHostNameType uriHostNameType = Uri.CheckHostName(nodeName);
|
||||
if (uriHostNameType != UriHostNameType.Unknown)
|
||||
{
|
||||
result = true;
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, $"The node name {nodeName} is a valid {uriHostNameType}.");
|
||||
}
|
||||
else
|
||||
{
|
||||
SvcTrace.DiagControl.TraceEvent(TraceEventType.Warning, 0, $"The given node name Address {nodeName} is invalid");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 0, ex.Message);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static bool IsEndpointEquals(string oldEndpoint, string newEndPoint)
|
||||
{
|
||||
bool flag = false;
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(oldEndpoint) && string.IsNullOrEmpty(newEndPoint))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (string.IsNullOrEmpty(oldEndpoint) ^ string.IsNullOrEmpty(newEndPoint))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
string text = string.Empty;
|
||||
string text2 = string.Empty;
|
||||
int num = 0;
|
||||
int num2 = 0;
|
||||
Uri uri = new Uri(oldEndpoint);
|
||||
if (null != uri)
|
||||
{
|
||||
text = GetHostName(uri.Host, returnSameHNIfNotAvailable: true);
|
||||
num = uri.Port;
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, $"Old endpoint host name {text}, and Port number: {num}");
|
||||
}
|
||||
uri = new Uri(newEndPoint);
|
||||
if (null != uri)
|
||||
{
|
||||
text2 = GetHostName(uri.Host, returnSameHNIfNotAvailable: true);
|
||||
num2 = uri.Port;
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, $"New endpoint host {text2}, and Port number: {num2}");
|
||||
}
|
||||
if (string.Equals(text, text2, StringComparison.CurrentCultureIgnoreCase) && num == num2)
|
||||
{
|
||||
SvcTrace.DiagControl.TraceEvent(TraceEventType.Information, 0, $"{oldEndpoint} and {newEndPoint} are equal");
|
||||
return true;
|
||||
}
|
||||
SvcTrace.DiagControl.TraceEvent(TraceEventType.Information, 0, $"{oldEndpoint} and {newEndPoint} are Not equal");
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Information, 0, ex.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsHostAddressEquals(string sourceHostAddr, string targetHostAddr)
|
||||
{
|
||||
bool flag = false;
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(sourceHostAddr) && string.IsNullOrEmpty(targetHostAddr))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (string.IsNullOrEmpty(sourceHostAddr) ^ string.IsNullOrEmpty(targetHostAddr))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
string hostName = GetHostName(sourceHostAddr, returnSameHNIfNotAvailable: true);
|
||||
string hostName2 = GetHostName(targetHostAddr, returnSameHNIfNotAvailable: true);
|
||||
return string.Equals(hostName, hostName2, StringComparison.CurrentCultureIgnoreCase);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Information, 0, ex.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetHostName(string hostAddress, bool returnSameHNIfNotAvailable)
|
||||
{
|
||||
string text = string.Empty;
|
||||
bool flag = false;
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(hostAddress) && IsValidHostAddress(hostAddress))
|
||||
{
|
||||
if (IsLocalIPAddress(hostAddress))
|
||||
{
|
||||
flag = true;
|
||||
text = Environment.MachineName;
|
||||
}
|
||||
else
|
||||
{
|
||||
IPHostEntry hostEntry = Dns.GetHostEntry(hostAddress);
|
||||
if (hostEntry != null)
|
||||
{
|
||||
flag = true;
|
||||
string hostName = hostEntry.HostName;
|
||||
if (!string.IsNullOrEmpty(hostName) && hostName.Contains('.'))
|
||||
{
|
||||
if (hostName.EndsWith("."))
|
||||
{
|
||||
hostName = Dns.GetHostEntry(hostEntry.AddressList[0]).HostName;
|
||||
}
|
||||
text = hostName.Substring(0, hostName.IndexOf("."));
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, $"The HostName for {hostAddress} is : {text}");
|
||||
}
|
||||
else
|
||||
{
|
||||
text = hostEntry.HostName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
flag = true;
|
||||
SvcTrace.DiagControl.TraceEvent(TraceEventType.Warning, 0, string.Format("The HostAddress is emtpy or invalid", hostAddress));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
text = string.Empty;
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Information, 0, ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (!flag)
|
||||
{
|
||||
if (returnSameHNIfNotAvailable)
|
||||
{
|
||||
text = hostAddress;
|
||||
}
|
||||
SvcTrace.DiagControl.TraceEvent(TraceEventType.Information, 0, $"Couldn't find the DNS server for givem hostAddress {hostAddress} ");
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
public static string GetHostName(string endPointAddress, bool returnSameHNIfNotAvailable, out int portNumber)
|
||||
{
|
||||
string result = string.Empty;
|
||||
portNumber = 0;
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(endPointAddress))
|
||||
{
|
||||
Uri uri = new Uri(endPointAddress);
|
||||
if (null != uri)
|
||||
{
|
||||
result = GetHostName(uri.Host, returnSameHNIfNotAvailable);
|
||||
portNumber = uri.Port;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result = string.Empty;
|
||||
SvcTrace.DiagControl.TraceEvent(TraceEventType.Warning, 0, $"Invalid endpoint address {endPointAddress}.");
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Information, 0, ex.Message);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static bool IsLocalMachine(string baseAddress)
|
||||
{
|
||||
bool flag = false;
|
||||
SvcTrace.DiagCommand.TraceEvent(TraceEventType.Information, 3, string.Format(CultureInfo.CurrentCulture, "IsLocalMachine called for URI {0} ", new object[1] { baseAddress }));
|
||||
try
|
||||
{
|
||||
IPAddress[] hostAddresses = GetHostAddresses(new Uri(baseAddress));
|
||||
IPAddress[] hostAddresses2 = Dns.GetHostAddresses(Dns.GetHostName());
|
||||
IPAddress[] array = hostAddresses;
|
||||
foreach (IPAddress iPAddress in array)
|
||||
{
|
||||
if (IPAddress.IsLoopback(iPAddress))
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, string.Format(CultureInfo.CurrentCulture, "IsLocalMachine: URI designates loopback, returning true"));
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
IPAddress[] array2 = hostAddresses2;
|
||||
foreach (IPAddress obj in array2)
|
||||
{
|
||||
if (iPAddress.Equals(obj))
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, string.Format(CultureInfo.CurrentCulture, "IsLocalMachine: URI designates localhost, returning true"));
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (flag)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Critical, 0, string.Format(CultureInfo.CurrentCulture, "IsLocalMachine method has an exception {0}.", new object[1] { ex.Message }));
|
||||
flag = false;
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, string.Format(CultureInfo.CurrentCulture, "IsLocalMachine: URI designates foreign node, returning false"));
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
public static bool IsLocalIPAddress(string ipAddress)
|
||||
{
|
||||
bool result = false;
|
||||
if (IsValidIPAddress(ipAddress))
|
||||
{
|
||||
IPAddress[] addressList = Dns.GetHostEntry(string.Empty).AddressList;
|
||||
for (int i = 0; i < addressList.Length; i++)
|
||||
{
|
||||
string b = addressList[i].ToString();
|
||||
if (string.Equals(ipAddress, b, StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static IPAddress[] GetHostAddresses(Uri uri)
|
||||
{
|
||||
IPAddress[] result = new IPAddress[0];
|
||||
try
|
||||
{
|
||||
SvcTrace.DiagCommand.TraceEvent(TraceEventType.Information, 3, string.Format(CultureInfo.CurrentCulture, "GetHostAddresses called for URI {0} ", new object[1] { uri }));
|
||||
UriBuilder uriBuilder = new UriBuilder(uri);
|
||||
if (uriBuilder != null)
|
||||
{
|
||||
result = GetHostAddresses(uriBuilder.Host);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Critical, 0, string.Format(CultureInfo.CurrentCulture, "GetHostAddresses method has an exception {0}.", new object[1] { ex.Message }));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static IPAddress[] GetHostAddresses(string hostAddress)
|
||||
{
|
||||
IPAddress[] result = new IPAddress[0];
|
||||
try
|
||||
{
|
||||
if (hostAddress != null)
|
||||
{
|
||||
SvcTrace.DiagCommand.TraceEvent(TraceEventType.Information, 3, string.Format(CultureInfo.CurrentCulture, "GetHostAddresses called for hostname {0} ", new object[1] { hostAddress }));
|
||||
if (hostAddress.StartsWith("localhost", ignoreCase: true, CultureInfo.CurrentCulture))
|
||||
{
|
||||
hostAddress = hostAddress.Replace("localhost", Environment.MachineName);
|
||||
}
|
||||
result = Dns.GetHostAddresses(hostAddress.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
SvcTrace.DiagCommand.TraceEvent(TraceEventType.Information, 3, string.Format(CultureInfo.CurrentCulture, "GetHostAddresses called for 'null' hostname "));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Critical, 0, string.Format(CultureInfo.CurrentCulture, "GetHostAddresses method has an exception {0}.", new object[1] { ex.Message }));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static bool IsRemoteNodeSameasSRNode(string remoteRepositoryNode, string defaultSRNodeName)
|
||||
{
|
||||
bool result = false;
|
||||
try
|
||||
{
|
||||
string value = string.Empty;
|
||||
if (string.IsNullOrEmpty(defaultSRNodeName))
|
||||
{
|
||||
value = RegistryHandler.GetSrNode(out defaultSRNodeName);
|
||||
}
|
||||
if (string.IsNullOrEmpty(value) && IsValidNodeName(remoteRepositoryNode) && string.Equals(GetHostName(remoteRepositoryNode, returnSameHNIfNotAvailable: true), defaultSRNodeName, StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Information, 0, $"IsRemoteNodeSameasSRNode failed: {ex.Message}");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static bool IsValidateEndpointUri(string endpointAddr)
|
||||
{
|
||||
bool result = false;
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(endpointAddr))
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, "Endpoint address is empty or null");
|
||||
}
|
||||
else if (Uri.IsWellFormedUriString(endpointAddr, UriKind.RelativeOrAbsolute))
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, $"The endpoint address {endpointAddr} of the discovery service is valid URI address.");
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, $"Invalid endpoint address '{endpointAddr}'.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, ex.Message);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
namespace ArchestrAServices.Common;
|
||||
|
||||
public delegate void IPAddressChangeEventHandler();
|
||||
@@ -0,0 +1,156 @@
|
||||
#define TRACE
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ArchestrAServices.Common;
|
||||
|
||||
public class IPAddressWatcher : IDisposable
|
||||
{
|
||||
private readonly ReaderWriterLockSlim cacheLock = new ReaderWriterLockSlim();
|
||||
|
||||
private List<IPAddress> ipAddresses = new List<IPAddress>();
|
||||
|
||||
private bool disposed;
|
||||
|
||||
public event IPAddressChangeEventHandler AddressChangedEvent;
|
||||
|
||||
public IPAddressWatcher()
|
||||
{
|
||||
ipAddresses = GetAllIpAddresses();
|
||||
}
|
||||
|
||||
~IPAddressWatcher()
|
||||
{
|
||||
Dispose(disposing: false);
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, "Start watching for IP address changes");
|
||||
NetworkChange.NetworkAddressChanged += IpChangedEventHandler;
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, "Stop watching for IP address changes");
|
||||
NetworkChange.NetworkAddressChanged -= IpChangedEventHandler;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
private static List<IPAddress> GetAllIpAddresses()
|
||||
{
|
||||
List<IPAddress> list = new List<IPAddress>();
|
||||
NetworkInterface[] allNetworkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
|
||||
for (int i = 0; i < allNetworkInterfaces.Length; i++)
|
||||
{
|
||||
foreach (UnicastIPAddressInformation unicastAddress in allNetworkInterfaces[i].GetIPProperties().UnicastAddresses)
|
||||
{
|
||||
if (unicastAddress.IsDnsEligible && unicastAddress.Address.AddressFamily == AddressFamily.InterNetwork)
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, " Found IPV4 address = {0}", unicastAddress.Address);
|
||||
list.Add(unicastAddress.Address);
|
||||
}
|
||||
}
|
||||
}
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, "Found a total of {0} IPV4 addresses", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
private bool HaveIpAddressesChanged()
|
||||
{
|
||||
bool flag = false;
|
||||
List<IPAddress> allIpAddresses = GetAllIpAddresses();
|
||||
if (allIpAddresses.Count != ipAddresses.Count)
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, "IP Address count has changed: current count = {0}, previous count = {1}", allIpAddresses.Count, ipAddresses.Count);
|
||||
flag = true;
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
foreach (IPAddress item in allIpAddresses)
|
||||
{
|
||||
if (!ipAddresses.Contains(item))
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, "IP Address has changed: new address = {0} did not previously exist", item);
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
foreach (IPAddress ipAddress in ipAddresses)
|
||||
{
|
||||
if (!allIpAddresses.Contains(ipAddress))
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, "IP Address has changed: old address = {0} no longer exists", ipAddress);
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (flag)
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, "IP Addresses Previous: {0} and current {1}", string.Join(",", ipAddresses.Select((IPAddress a) => a.ToString())), string.Join(",", allIpAddresses.Select((IPAddress a) => a.ToString())));
|
||||
ipAddresses = allIpAddresses;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
private void IpChangedEventHandler(object sender, EventArgs e)
|
||||
{
|
||||
cacheLock.EnterWriteLock();
|
||||
bool flag;
|
||||
try
|
||||
{
|
||||
flag = HaveIpAddressesChanged();
|
||||
}
|
||||
finally
|
||||
{
|
||||
cacheLock.ExitWriteLock();
|
||||
}
|
||||
if (flag)
|
||||
{
|
||||
TriggerNetworkAddressChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private Task TriggerNetworkAddressChanged()
|
||||
{
|
||||
IPAddressChangeEventHandler handler = this.AddressChangedEvent;
|
||||
if (handler != null)
|
||||
{
|
||||
return Task.Factory.StartNew(delegate
|
||||
{
|
||||
handler();
|
||||
});
|
||||
}
|
||||
return Task.Factory.StartNew(delegate
|
||||
{
|
||||
});
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
if (disposing && cacheLock != null)
|
||||
{
|
||||
cacheLock.Dispose();
|
||||
}
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Principal;
|
||||
|
||||
namespace ArchestrAServices.Common;
|
||||
|
||||
public class Impersonator : IDisposable
|
||||
{
|
||||
private WindowsImpersonationContext _impersonatedUser;
|
||||
|
||||
private ArchestraSafeHandle _userHandle;
|
||||
|
||||
public const int LOGON32_LOGON_INTERACTIVE = 2;
|
||||
|
||||
public const int LOGON32_LOGON_SERVICE = 3;
|
||||
|
||||
public const int LOGON32_PROVIDER_DEFAULT = 0;
|
||||
|
||||
public Impersonator()
|
||||
{
|
||||
}
|
||||
|
||||
public Impersonator(string userDomain, string userName, string password)
|
||||
{
|
||||
_userHandle = ArchestraSafeHandle.Empty;
|
||||
IntPtr phToken = IntPtr.Zero;
|
||||
if (!LogonUser(userName, userDomain, password, 2, 0, ref phToken))
|
||||
{
|
||||
throw new ApplicationException("Could not impersonate user");
|
||||
}
|
||||
_userHandle.Handle = phToken;
|
||||
WindowsIdentity windowsIdentity = new WindowsIdentity(_userHandle.Handle);
|
||||
_impersonatedUser = windowsIdentity.Impersonate();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_impersonatedUser != null)
|
||||
{
|
||||
_impersonatedUser.Undo();
|
||||
if (_userHandle != null && _userHandle.IsInvalid)
|
||||
{
|
||||
_userHandle.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern bool LogonUser(string lpszUserName, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
|
||||
public static extern bool CloseHandle(IntPtr handle);
|
||||
|
||||
[DllImport("InteropUtils.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern uint GetAdminUserDetails([MarshalAs(UnmanagedType.BStr)] out string pbstrOSDomainName, [MarshalAs(UnmanagedType.BStr)] out string pbstrOSUserName, [MarshalAs(UnmanagedType.BStr)] out string pbstrPassword);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace ArchestrAServices.Common;
|
||||
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
internal static class NativeMethods
|
||||
{
|
||||
[DllImport("kernel32", SetLastError = true)]
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
|
||||
internal static extern bool CloseHandle(IntPtr handle);
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
namespace ArchestrAServices.Common;
|
||||
|
||||
public enum NetTcpBindingSecurityMode
|
||||
{
|
||||
None,
|
||||
CredentialAuthentication,
|
||||
CertificateEncryption
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace ArchestrAServices.Common;
|
||||
|
||||
[Flags]
|
||||
public enum RegistryChangeFilter
|
||||
{
|
||||
SubKey = 1,
|
||||
Attributes = 2,
|
||||
Value = 4,
|
||||
Security = 8
|
||||
}
|
||||
@@ -0,0 +1,954 @@
|
||||
#define TRACE
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Security;
|
||||
using System.Security.AccessControl;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace ArchestrAServices.Common;
|
||||
|
||||
public class RegistryHandler
|
||||
{
|
||||
private static string asbInstallPath = string.Empty;
|
||||
|
||||
private static string asbCoreServicesInstallPath = string.Empty;
|
||||
|
||||
private static string managementServerAddress = string.Empty;
|
||||
|
||||
public static string ASBSolutionsSubkey = string.Empty;
|
||||
|
||||
public static string ASBRegistration = "NodeRegistration";
|
||||
|
||||
public static string LDSPort = "808";
|
||||
|
||||
public static string PGDSEndPoint = "PrimaryGlobalDiscovery";
|
||||
|
||||
public static string SGDSEndPoint = "SecondaryGlobalDiscovery";
|
||||
|
||||
public static string PUDSEndPoint = "PrimaryUniversalDiscovery";
|
||||
|
||||
public static string SUDSEndPoint = "SecondaryUniversalDiscovery";
|
||||
|
||||
public static string LDSEndPoint = "EndPointLocalDiscovery";
|
||||
|
||||
private static string Wow64OptionalLayer
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Environment.Is64BitProcess)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
return "Wow6432Node\\";
|
||||
}
|
||||
}
|
||||
|
||||
public static string RegistryPath => "SOFTWARE\\" + Wow64OptionalLayer + "ArchestrA\\ArchestrAServices\\";
|
||||
|
||||
public static string Registry32Path => "SOFTWARE\\ArchestrA\\ArchestrAServices\\";
|
||||
|
||||
public static string ASBSolutionPath => RegistryPath + ASBSolutionsSubkey;
|
||||
|
||||
public static string ASBNodeRegistraion => $"{RegistryPath}{ASBRegistration}";
|
||||
|
||||
public static string ASBInstallPath
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(asbInstallPath))
|
||||
{
|
||||
try
|
||||
{
|
||||
asbInstallPath = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\" + Wow64OptionalLayer + "ArchestrA\\ArchestrAServices", "ASBInstallPath", string.Empty).ToString();
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
SvcTrace.DiagControl.TraceEvent(TraceEventType.Warning, 0, "ParentKey for ASBInstallPath key was not found in registry");
|
||||
}
|
||||
}
|
||||
return asbInstallPath;
|
||||
}
|
||||
}
|
||||
|
||||
public static string AsbCoreServicesInstallPath
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!string.IsNullOrEmpty(asbCoreServicesInstallPath))
|
||||
{
|
||||
return asbCoreServicesInstallPath;
|
||||
}
|
||||
try
|
||||
{
|
||||
string text = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\" + Wow64OptionalLayer + "ArchestrA\\ArchestrAServices", "FwkInstallPath", string.Empty).ToString();
|
||||
if (!string.IsNullOrEmpty(text))
|
||||
{
|
||||
asbCoreServicesInstallPath = Path.Combine(text, "CoreServices");
|
||||
}
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
SvcTrace.DiagControl.TraceEvent(TraceEventType.Warning, 0, "ParentKey for FwkInstallPath key was not found in registry");
|
||||
}
|
||||
return asbCoreServicesInstallPath;
|
||||
}
|
||||
}
|
||||
|
||||
public static SecureCommunicationModes SecureCommunicationMode
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
string text = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\" + Wow64OptionalLayer + "ArchestrA\\ArchestrAServices", "SecureCommunicationMode", 0).ToString();
|
||||
if (!string.IsNullOrEmpty(text))
|
||||
{
|
||||
int.TryParse(text, out var result);
|
||||
return (SecureCommunicationModes)result;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return SecureCommunicationModes.Never;
|
||||
}
|
||||
set
|
||||
{
|
||||
try
|
||||
{
|
||||
Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\" + Wow64OptionalLayer + "ArchestrA\\ArchestrAServices", "SecureCommunicationMode", (int)value, RegistryValueKind.DWord);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool AsbManagedCertificates
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
return Convert.ToBoolean(Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\" + Wow64OptionalLayer + "ArchestrA\\ArchestrAServices", "ASBManagedCertificates", 1));
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return true;
|
||||
}
|
||||
set
|
||||
{
|
||||
Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\" + Wow64OptionalLayer + "ArchestrA\\ArchestrAServices", "ASBManagedCertificates", value, RegistryValueKind.DWord);
|
||||
}
|
||||
}
|
||||
|
||||
public static int DefaultSslPort
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
return Convert.ToInt32(Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\" + Wow64OptionalLayer + "ArchestrA\\WebApplications\\Default", "SslPort", 443));
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return 443;
|
||||
}
|
||||
set
|
||||
{
|
||||
Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\" + Wow64OptionalLayer + "ArchestrA\\WebApplications\\Default", "SslPort", value, RegistryValueKind.DWord);
|
||||
}
|
||||
}
|
||||
|
||||
public static string ManagementServerAddress
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(managementServerAddress))
|
||||
{
|
||||
managementServerAddress = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\" + Wow64OptionalLayer + "ArchestrA\\ArchestrAServices", "MSAddress", string.Empty).ToString();
|
||||
}
|
||||
return managementServerAddress;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public static Uri MakeLDSProbeEndpointAddress(string NodeName)
|
||||
{
|
||||
return new Uri("net.tcp://" + NodeName + "/LDS/Probe");
|
||||
}
|
||||
|
||||
public static Uri MakeLDSEndpointAddress(string NodeName)
|
||||
{
|
||||
return new Uri("net.tcp://" + NodeName + "/LDS");
|
||||
}
|
||||
|
||||
public static string DeleteFromRegistry(string solutionName)
|
||||
{
|
||||
string SRNodeName;
|
||||
string srNode = GetSrNode(solutionName, out SRNodeName);
|
||||
if (!string.IsNullOrEmpty(srNode))
|
||||
{
|
||||
return srNode;
|
||||
}
|
||||
if (SRNodeName.ToUpperInvariant() == Environment.MachineName.ToUpperInvariant())
|
||||
{
|
||||
return "Cannot delete the SR node solution.";
|
||||
}
|
||||
string subkey = RegistryPath;
|
||||
if (!string.IsNullOrEmpty(solutionName))
|
||||
{
|
||||
subkey = ASBSolutionPath + solutionName;
|
||||
}
|
||||
try
|
||||
{
|
||||
Registry.LocalMachine.DeleteSubKeyTree(subkey);
|
||||
return "Success";
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
return "Node Does not exist to delete: " + ex.Message;
|
||||
}
|
||||
catch (SecurityException ex2)
|
||||
{
|
||||
return "Security Error: " + ex2.Message;
|
||||
}
|
||||
catch (ArgumentException ex3)
|
||||
{
|
||||
return "Node Does not exist to delete: " + ex3.Message;
|
||||
}
|
||||
catch (ObjectDisposedException ex4)
|
||||
{
|
||||
return ex4.Message;
|
||||
}
|
||||
catch (UnauthorizedAccessException ex5)
|
||||
{
|
||||
return "UnauthorizedAccessException: " + ex5.Message;
|
||||
}
|
||||
}
|
||||
|
||||
public static string CreateASBConfigInfoStructureInRegistry(ASBConfigurationInformation securityConfiguration, string srNode, bool isRegister)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (securityConfiguration != null)
|
||||
{
|
||||
CreateSolutionKey(securityConfiguration);
|
||||
CreateNodeRegistrationyKey(securityConfiguration, isRegister);
|
||||
return "Success";
|
||||
}
|
||||
return "Cannot write security configuration to registry: Please provide SecurityConfiguration";
|
||||
}
|
||||
catch (UnauthorizedAccessException ex)
|
||||
{
|
||||
return "Cannot write security configuration to registry: " + ex.Message;
|
||||
}
|
||||
catch (SecurityException ex2)
|
||||
{
|
||||
return "Cannot write security configuration to registry: " + ex2.Message;
|
||||
}
|
||||
catch (IOException ex3)
|
||||
{
|
||||
return "Cannot write security configuration to registry: " + ex3.Message;
|
||||
}
|
||||
catch (ObjectDisposedException ex4)
|
||||
{
|
||||
return "Cannot write security configuration to registry: " + ex4.Message;
|
||||
}
|
||||
}
|
||||
|
||||
public static string ReadASBConfigInfoStructureFromRegistry(string solutionName, out ASBConfigurationInformation securityConfiguration)
|
||||
{
|
||||
string empty = string.Empty;
|
||||
string text = solutionName;
|
||||
string DefaultSolutionName;
|
||||
string defaultSolutionName = GetDefaultSolutionName(out DefaultSolutionName);
|
||||
if (string.IsNullOrEmpty(solutionName))
|
||||
{
|
||||
if (string.IsNullOrEmpty(defaultSolutionName))
|
||||
{
|
||||
securityConfiguration = null;
|
||||
return "Read of default ASBSolution requested, but no default on local machine";
|
||||
}
|
||||
text = DefaultSolutionName;
|
||||
}
|
||||
RegistryKey registryKey = null;
|
||||
using (RegistryKey registryKey2 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32))
|
||||
{
|
||||
registryKey = registryKey2.OpenSubKey(Registry32Path + "\\" + text);
|
||||
registryKey2.Close();
|
||||
if (registryKey == null)
|
||||
{
|
||||
securityConfiguration = null;
|
||||
return "ASBSolution " + text + " does not exist local machine";
|
||||
}
|
||||
}
|
||||
using (registryKey)
|
||||
{
|
||||
securityConfiguration = FillConfigurationFromRegistry(registryKey, text, DefaultSolutionName);
|
||||
registryKey.Close();
|
||||
return empty;
|
||||
}
|
||||
}
|
||||
|
||||
private static ASBConfigurationInformation FillConfigurationFromRegistry(RegistryKey asbSolutionKey, string solutionNameToRead, string defaultSolutionName)
|
||||
{
|
||||
if (asbSolutionKey == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
ASBConfigurationInformation aSBConfigurationInformation = new ASBConfigurationInformation
|
||||
{
|
||||
SolutionName = solutionNameToRead
|
||||
};
|
||||
try
|
||||
{
|
||||
aSBConfigurationInformation.Generator = asbSolutionKey.GetValue("Generator", string.Empty).ToString();
|
||||
aSBConfigurationInformation.Prime = asbSolutionKey.GetValue("Prime", string.Empty).ToString();
|
||||
aSBConfigurationInformation.HashAlgorithm = asbSolutionKey.GetValue("HashAlgorthim", string.Empty).ToString();
|
||||
aSBConfigurationInformation.InitializationVector = asbSolutionKey.GetValue("initailizationVector", string.Empty).ToString();
|
||||
aSBConfigurationInformation.SaltValue = asbSolutionKey.GetValue("saltValue", string.Empty).ToString();
|
||||
string s = asbSolutionKey.GetValue("passowordIterations", "0").ToString();
|
||||
aSBConfigurationInformation.PasswordDerivationIterations = int.Parse(s);
|
||||
string s2 = asbSolutionKey.GetValue("keySize", "0").ToString();
|
||||
aSBConfigurationInformation.KeySize = int.Parse(s2);
|
||||
try
|
||||
{
|
||||
DPUtility dPUtility = new DPUtility(DPUtility.Store.USE_MACHINE_STORE);
|
||||
byte[] bytes = Encoding.Unicode.GetBytes("wonderware");
|
||||
byte[] cipherText = (byte[])asbSolutionKey.GetValue("sharedsecret", RegistryValueKind.Binary);
|
||||
byte[] bytes2 = dPUtility.Decrypt(cipherText, bytes);
|
||||
aSBConfigurationInformation.EncryptedSharedSecret = Encoding.Unicode.GetString(bytes2);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SvcTrace.DiagControl.TraceEvent(TraceEventType.Warning, 0, "Reading and decrypting shared secret failed with exception {0}", ex.Message);
|
||||
}
|
||||
aSBConfigurationInformation.EncryptedCertificate = asbSolutionKey.GetValue("Certificate", RegistryValueKind.String).ToString();
|
||||
aSBConfigurationInformation.IsDefault = ((string.Compare(solutionNameToRead, defaultSolutionName, ignoreCase: true) == 0) ? "true" : "false");
|
||||
if (string.IsNullOrEmpty(GetSrNode(solutionNameToRead, out var SRNodeName)))
|
||||
{
|
||||
aSBConfigurationInformation.SRNodeName = SRNodeName;
|
||||
}
|
||||
}
|
||||
catch (Exception ex2)
|
||||
{
|
||||
SvcTrace.DiagControl.TraceEvent(TraceEventType.Warning, 0, "Failed to read a solution element for ASB Solution {0} with exception {1}", solutionNameToRead, ex2.Message);
|
||||
}
|
||||
return aSBConfigurationInformation;
|
||||
}
|
||||
|
||||
private static void CreateNodeRegistrationyKey(ASBConfigurationInformation securityConfiguration, bool isRegister)
|
||||
{
|
||||
RegistryKey registryKey = Registry.LocalMachine.CreateSubKey(ASBSolutionPath + securityConfiguration.SolutionName + "\\NodeRegistration", RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryOptions.None);
|
||||
Uri uri = MakeLDSEndpointAddress(securityConfiguration.SRNodeName);
|
||||
if (registryKey != null)
|
||||
{
|
||||
SetSecurityParameter(uri.AbsoluteUri, registryKey, LDSEndPoint);
|
||||
SetSecurityParameter(securityConfiguration.PrimaryGlobalDiscovery, registryKey, PGDSEndPoint);
|
||||
SetSecurityParameter(securityConfiguration.SecondaryGlobalDiscovery, registryKey, SGDSEndPoint);
|
||||
SetSecurityParameter(securityConfiguration.PrimaryUniversalDiscovery, registryKey, PUDSEndPoint);
|
||||
SetSecurityParameter(securityConfiguration.SecondaryUniversalDiscovery, registryKey, SUDSEndPoint);
|
||||
SetSecurityParameter(securityConfiguration.SRNodeName, registryKey, "ServiceRepositoryNode");
|
||||
registryKey.Close();
|
||||
registryKey.Dispose();
|
||||
}
|
||||
if (isRegister && string.Compare(securityConfiguration.IsDefault, "true", StringComparison.OrdinalIgnoreCase) == 0)
|
||||
{
|
||||
RegistryKey registryKey2 = Registry.LocalMachine.CreateSubKey(RegistryPath + "NodeRegistration", RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryOptions.None);
|
||||
Uri uri2 = MakeLDSEndpointAddress(Environment.MachineName);
|
||||
if (registryKey2 != null)
|
||||
{
|
||||
SetSecurityParameter(uri2.AbsoluteUri, registryKey2, LDSEndPoint);
|
||||
SetSecurityParameter(securityConfiguration.PrimaryGlobalDiscovery, registryKey2, PGDSEndPoint);
|
||||
SetSecurityParameter(securityConfiguration.SecondaryGlobalDiscovery, registryKey2, SGDSEndPoint);
|
||||
SetSecurityParameter(securityConfiguration.PrimaryUniversalDiscovery, registryKey2, PUDSEndPoint);
|
||||
SetSecurityParameter(securityConfiguration.SecondaryUniversalDiscovery, registryKey2, SUDSEndPoint);
|
||||
SetSecurityParameter(securityConfiguration.SRNodeName, registryKey2, "ServiceRepositoryNode");
|
||||
CreateRootKey(securityConfiguration);
|
||||
registryKey2.Close();
|
||||
registryKey2.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void CreateRootKey(ASBConfigurationInformation securityConfiguration)
|
||||
{
|
||||
using RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(RegistryPath, RegistryKeyPermissionCheck.ReadWriteSubTree);
|
||||
registryKey?.SetValue("DefaultASBSolution", securityConfiguration.SolutionName);
|
||||
}
|
||||
|
||||
private static void CreateSolutionKey(ASBConfigurationInformation securityConfiguration)
|
||||
{
|
||||
RegistryKey registryKey = Registry.LocalMachine.CreateSubKey(ASBSolutionPath + securityConfiguration.SolutionName, RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryOptions.None);
|
||||
if (registryKey != null)
|
||||
{
|
||||
SetSecurityParameter(securityConfiguration.EncryptedCertificate, registryKey, "Certificate");
|
||||
SetSecurityParameter(securityConfiguration.Generator, registryKey, "Generator");
|
||||
SetSecurityParameter(securityConfiguration.HashAlgorithm, registryKey, "HashAlgorthim");
|
||||
SetSecurityParameter(securityConfiguration.InitializationVector, registryKey, "initailizationVector");
|
||||
SetSecurityParameter(securityConfiguration.SaltValue, registryKey, "saltValue");
|
||||
SetSecurityParameter(securityConfiguration.Prime, registryKey, "Prime");
|
||||
try
|
||||
{
|
||||
DPUtility dPUtility = new DPUtility(DPUtility.Store.USE_MACHINE_STORE);
|
||||
byte[] bytes = Encoding.Unicode.GetBytes(securityConfiguration.EncryptedSharedSecret);
|
||||
byte[] bytes2 = Encoding.Unicode.GetBytes("wonderware");
|
||||
byte[] value = dPUtility.Encrypt(bytes, bytes2);
|
||||
registryKey.SetValue("sharedsecret", value, RegistryValueKind.Binary);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, "Failed to write passphrase to registry: {0}", ex.Message);
|
||||
}
|
||||
registryKey.SetValue("passowordIterations", securityConfiguration.PasswordDerivationIterations);
|
||||
registryKey.SetValue("keySize", securityConfiguration.KeySize);
|
||||
registryKey.Close();
|
||||
registryKey.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetSecurityParameter(string securityConfiguration, RegistryKey solutionKey, string name)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(securityConfiguration))
|
||||
{
|
||||
solutionKey.SetValue(name, securityConfiguration);
|
||||
}
|
||||
else
|
||||
{
|
||||
solutionKey.SetValue(name, string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
public static string CreateUniversalSolutionStructureInRegistry(ASBConfigurationInformation securityConfiguration)
|
||||
{
|
||||
string result = string.Empty;
|
||||
try
|
||||
{
|
||||
if (securityConfiguration != null)
|
||||
{
|
||||
using RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(ASBSolutionPath, RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.SetValue);
|
||||
if (registryKey == null)
|
||||
{
|
||||
result = "Cannot open parent registry key for creating the Universal Solution.";
|
||||
}
|
||||
else
|
||||
{
|
||||
using (RegistryKey registryKey2 = registryKey.OpenSubKey(securityConfiguration.SolutionName))
|
||||
{
|
||||
if (registryKey2 == null)
|
||||
{
|
||||
CreateSolutionKey(securityConfiguration);
|
||||
}
|
||||
}
|
||||
registryKey.SetValue("UniversalSolution", securityConfiguration.SolutionName, RegistryValueKind.String);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = "Please provide details for configuring the Universal Solution.";
|
||||
}
|
||||
}
|
||||
catch (UnauthorizedAccessException ex)
|
||||
{
|
||||
result = ex.Message;
|
||||
}
|
||||
catch (SecurityException ex2)
|
||||
{
|
||||
result = ex2.Message;
|
||||
}
|
||||
catch (IOException ex3)
|
||||
{
|
||||
result = ex3.Message;
|
||||
}
|
||||
catch (ObjectDisposedException ex4)
|
||||
{
|
||||
result = ex4.Message;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string GetSrNode(out string SRNodeName)
|
||||
{
|
||||
SRNodeName = string.Empty;
|
||||
RegistryKey registryKey = null;
|
||||
string result = string.Empty;
|
||||
try
|
||||
{
|
||||
registryKey = Registry.LocalMachine.OpenSubKey(RegistryPath + "NodeRegistration");
|
||||
object obj = null;
|
||||
if (registryKey != null && (obj = registryKey.GetValue("ServiceRepositoryNode")) != null)
|
||||
{
|
||||
SRNodeName = obj.ToString();
|
||||
if (string.IsNullOrEmpty(SRNodeName))
|
||||
{
|
||||
result = "Default SR Node name is empty";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = "Unable to open registry key " + RegistryPath + "NodeRegistration\\ServiceRepositoryNode";
|
||||
}
|
||||
}
|
||||
catch (UnauthorizedAccessException ex)
|
||||
{
|
||||
result = ex.Message;
|
||||
}
|
||||
catch (SecurityException ex2)
|
||||
{
|
||||
result = ex2.Message;
|
||||
}
|
||||
catch (IOException ex3)
|
||||
{
|
||||
result = ex3.Message;
|
||||
}
|
||||
catch (ObjectDisposedException ex4)
|
||||
{
|
||||
result = ex4.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
registryKey?.Close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static bool GetSRInstalled()
|
||||
{
|
||||
bool result = false;
|
||||
try
|
||||
{
|
||||
result = GetBinaryRegistryValue(RegistryPath, "SRInstalled");
|
||||
}
|
||||
catch (Exception ex) when (ex is UnauthorizedAccessException || ex is SecurityException || ex is IOException || ex is ObjectDisposedException)
|
||||
{
|
||||
SvcTrace.DiagControl.TraceEvent(TraceEventType.Warning, 0, "GetSRInstalled: Unable to read SR installation status from registry, assuming false: {0}", ex.Message);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static bool GetManagementServerInstalled()
|
||||
{
|
||||
bool result = false;
|
||||
try
|
||||
{
|
||||
result = GetBinaryRegistryValue(RegistryPath, "MSInstalled");
|
||||
}
|
||||
catch (Exception ex) when (ex is UnauthorizedAccessException || ex is SecurityException || ex is IOException || ex is ObjectDisposedException)
|
||||
{
|
||||
SvcTrace.DiagControl.TraceEvent(TraceEventType.Warning, 0, "GetManagementServerInstalled: Unable to read Management Server installation status from registry, assuming false: {0}", ex.Message);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string GetSrNode(string SolutionName, out string SRNodeName)
|
||||
{
|
||||
SRNodeName = string.Empty;
|
||||
RegistryKey registryKey = null;
|
||||
string result = string.Empty;
|
||||
try
|
||||
{
|
||||
registryKey = Registry.LocalMachine.OpenSubKey(ASBSolutionPath + SolutionName + "\\NodeRegistration", writable: true);
|
||||
object obj = null;
|
||||
if (registryKey != null && (obj = registryKey.GetValue("ServiceRepositoryNode")) != null)
|
||||
{
|
||||
SRNodeName = obj.ToString();
|
||||
if (string.IsNullOrEmpty(SRNodeName))
|
||||
{
|
||||
result = "Default SR Node name is empty";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = "Unable to open registry key " + ASBSolutionPath + SolutionName + "\\NodeRegistration\\ServiceRepositoryNode";
|
||||
}
|
||||
}
|
||||
catch (UnauthorizedAccessException ex)
|
||||
{
|
||||
result = ex.Message;
|
||||
}
|
||||
catch (SecurityException ex2)
|
||||
{
|
||||
result = ex2.Message;
|
||||
}
|
||||
catch (IOException ex3)
|
||||
{
|
||||
result = ex3.Message;
|
||||
}
|
||||
catch (ObjectDisposedException ex4)
|
||||
{
|
||||
result = ex4.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
registryKey?.Close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string GetDefaultSolutionName(out string DefaultSolutionName)
|
||||
{
|
||||
DefaultSolutionName = string.Empty;
|
||||
RegistryKey registryKey = null;
|
||||
string result = string.Empty;
|
||||
try
|
||||
{
|
||||
registryKey = Registry.LocalMachine.OpenSubKey(RegistryPath, writable: false);
|
||||
object obj = null;
|
||||
if (registryKey != null && (obj = registryKey.GetValue("DefaultASBSolution")) != null)
|
||||
{
|
||||
DefaultSolutionName = obj.ToString();
|
||||
result = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = "Unable to open registry key " + RegistryPath + "\\DefaultASBSolution";
|
||||
}
|
||||
}
|
||||
catch (UnauthorizedAccessException ex)
|
||||
{
|
||||
result = ex.Message;
|
||||
}
|
||||
catch (SecurityException ex2)
|
||||
{
|
||||
result = ex2.Message;
|
||||
}
|
||||
catch (IOException ex3)
|
||||
{
|
||||
result = ex3.Message;
|
||||
}
|
||||
catch (ObjectDisposedException ex4)
|
||||
{
|
||||
result = ex4.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
registryKey?.Close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string GetSolutionPassphrase(string asbSolution, out string passphrase)
|
||||
{
|
||||
passphrase = string.Empty;
|
||||
string result = string.Empty;
|
||||
if (string.IsNullOrEmpty(asbSolution))
|
||||
{
|
||||
result = GetDefaultSolutionName(out asbSolution);
|
||||
}
|
||||
if (string.IsNullOrEmpty(asbSolution))
|
||||
{
|
||||
passphrase = string.Empty;
|
||||
return result;
|
||||
}
|
||||
RegistryKey registryKey = null;
|
||||
try
|
||||
{
|
||||
registryKey = Registry.LocalMachine.OpenSubKey(ASBSolutionPath + asbSolution, writable: false);
|
||||
object obj = null;
|
||||
if (registryKey != null && (obj = registryKey.GetValue("sharedsecret")) != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] bytes = new DPUtility(DPUtility.Store.USE_MACHINE_STORE).Decrypt(optionalEntropy: Encoding.Unicode.GetBytes("wonderware"), cipherText: (byte[])obj);
|
||||
passphrase = Encoding.Unicode.GetString(bytes);
|
||||
result = string.Empty;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, "Failed to read passphrase from registry.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = string.Format("Unable to find the passphrase for the solution: '{0}'. Confirm that local galaxy and remote galaxy (whose solution name is '{0}') have been paired", asbSolution);
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, "Unable to open registry key {0}{1}\\sharedsecret", ASBSolutionPath, asbSolution);
|
||||
}
|
||||
}
|
||||
catch (UnauthorizedAccessException ex2)
|
||||
{
|
||||
result = ex2.Message;
|
||||
}
|
||||
catch (SecurityException ex3)
|
||||
{
|
||||
result = ex3.Message;
|
||||
}
|
||||
catch (IOException ex4)
|
||||
{
|
||||
result = ex4.Message;
|
||||
}
|
||||
catch (ObjectDisposedException ex5)
|
||||
{
|
||||
result = ex5.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
registryKey?.Close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<string> EnumerateSolutionsAtThisNode()
|
||||
{
|
||||
_ = string.Empty;
|
||||
List<string> list = new List<string>();
|
||||
RegistryKey registryKey = null;
|
||||
try
|
||||
{
|
||||
registryKey = Registry.LocalMachine.OpenSubKey(ASBSolutionPath, writable: true);
|
||||
if (registryKey != null)
|
||||
{
|
||||
string[] subKeyNames = registryKey.GetSubKeyNames();
|
||||
foreach (string text in subKeyNames)
|
||||
{
|
||||
if (string.Compare(text, ASBRegistration, ignoreCase: true) != 0)
|
||||
{
|
||||
list.Add(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_ = "Unable to open registry key " + ASBSolutionPath;
|
||||
}
|
||||
}
|
||||
catch (UnauthorizedAccessException ex)
|
||||
{
|
||||
_ = ex.Message;
|
||||
}
|
||||
catch (SecurityException ex2)
|
||||
{
|
||||
_ = ex2.Message;
|
||||
}
|
||||
catch (IOException ex3)
|
||||
{
|
||||
_ = ex3.Message;
|
||||
}
|
||||
catch (ObjectDisposedException ex4)
|
||||
{
|
||||
_ = ex4.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
registryKey?.Close();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<KeyValuePair<string, string>> ReadDiscoveryInfoFromRegistry(string asbSolutionName)
|
||||
{
|
||||
List<KeyValuePair<string, string>> list = new List<KeyValuePair<string, string>>();
|
||||
using (RegistryKey registryKey = Registry.LocalMachine.CreateSubKey(ASBSolutionPath + asbSolutionName + "\\" + ASBRegistration, RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryOptions.None))
|
||||
{
|
||||
if (registryKey != null)
|
||||
{
|
||||
list.Add(new KeyValuePair<string, string>(LDSEndPoint, registryKey.GetValue(LDSEndPoint, string.Empty).ToString()));
|
||||
list.Add(new KeyValuePair<string, string>(PGDSEndPoint, registryKey.GetValue(PGDSEndPoint, string.Empty).ToString()));
|
||||
list.Add(new KeyValuePair<string, string>(SGDSEndPoint, registryKey.GetValue(SGDSEndPoint, string.Empty).ToString()));
|
||||
list.Add(new KeyValuePair<string, string>(PUDSEndPoint, registryKey.GetValue(PUDSEndPoint, string.Empty).ToString()));
|
||||
list.Add(new KeyValuePair<string, string>(SUDSEndPoint, registryKey.GetValue(SUDSEndPoint, string.Empty).ToString()));
|
||||
list.Add(new KeyValuePair<string, string>("ServiceRepositoryNode", registryKey.GetValue("ServiceRepositoryNode", string.Empty).ToString()));
|
||||
registryKey.Close();
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static bool SetDiscoveryInfoInRegistry(string solutionName, List<KeyValuePair<string, string>> extraInfo, string srNode = null)
|
||||
{
|
||||
if (extraInfo == null)
|
||||
{
|
||||
SvcTrace.DiagControl.TraceEvent(TraceEventType.Warning, 0, "SetDiscoveryInfoInRegistry: Unable to proceed with no info to set, not setting Discovery information");
|
||||
return false;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(srNode))
|
||||
{
|
||||
extraInfo.Add(new KeyValuePair<string, string>("ServiceRepositoryNode", srNode));
|
||||
}
|
||||
string text = solutionName;
|
||||
if (!string.IsNullOrEmpty(GetDefaultSolutionName(out var DefaultSolutionName)))
|
||||
{
|
||||
DefaultSolutionName = string.Empty;
|
||||
}
|
||||
if (string.IsNullOrEmpty(text))
|
||||
{
|
||||
text = DefaultSolutionName;
|
||||
}
|
||||
if (string.IsNullOrEmpty(text))
|
||||
{
|
||||
SvcTrace.DiagControl.TraceEvent(TraceEventType.Warning, 0, "SetDiscoveryInfoInRegistry: Default solution specified, but does not exist, not setting Discovery information");
|
||||
return false;
|
||||
}
|
||||
using (RegistryKey registryKey = Registry.LocalMachine.CreateSubKey(ASBSolutionPath + solutionName + "\\NodeRegistration", RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryOptions.None))
|
||||
{
|
||||
if (registryKey != null)
|
||||
{
|
||||
foreach (KeyValuePair<string, string> item in extraInfo)
|
||||
{
|
||||
if (string.Compare(item.Key, LDSEndPoint) == 0 || string.Compare(item.Key, PGDSEndPoint) == 0 || string.Compare(item.Key, SGDSEndPoint) == 0 || string.Compare(item.Key, PUDSEndPoint) == 0 || string.Compare(item.Key, SUDSEndPoint) == 0 || string.Compare(item.Key, "ServiceRepositoryNode") == 0)
|
||||
{
|
||||
SetSecurityParameter(item.Value, registryKey, item.Key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
registryKey.Close();
|
||||
}
|
||||
}
|
||||
if (string.Compare(text, DefaultSolutionName, ignoreCase: true) == 0)
|
||||
{
|
||||
using RegistryKey registryKey2 = Registry.LocalMachine.CreateSubKey(RegistryPath + "NodeRegistration", RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryOptions.None);
|
||||
if (registryKey2 != null)
|
||||
{
|
||||
foreach (KeyValuePair<string, string> item2 in extraInfo)
|
||||
{
|
||||
if (string.Compare(item2.Key, LDSEndPoint) == 0 || string.Compare(item2.Key, PGDSEndPoint) == 0 || string.Compare(item2.Key, SGDSEndPoint) == 0 || string.Compare(item2.Key, PUDSEndPoint) == 0 || string.Compare(item2.Key, SUDSEndPoint) == 0 || string.Compare(item2.Key, "ServiceRepositoryNode") == 0)
|
||||
{
|
||||
SetSecurityParameter(item2.Value, registryKey2, item2.Key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
registryKey2.Close();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void UpdateDiscoveryInfos(List<KeyValuePair<string, string>> discoveryInfos)
|
||||
{
|
||||
UpdateDiscoverySingleRegKey(string.Empty, discoveryInfos);
|
||||
if (string.IsNullOrEmpty(GetDefaultSolutionName(out var DefaultSolutionName)))
|
||||
{
|
||||
UpdateDiscoverySingleRegKey(DefaultSolutionName, discoveryInfos);
|
||||
}
|
||||
}
|
||||
|
||||
private static void UpdateDiscoverySingleRegKey(string solutionName, List<KeyValuePair<string, string>> discoveryInfos)
|
||||
{
|
||||
if (solutionName == null)
|
||||
{
|
||||
solutionName = string.Empty;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(solutionName))
|
||||
{
|
||||
solutionName += "\\";
|
||||
}
|
||||
RegistryKey registryKey = Registry.LocalMachine.CreateSubKey(ASBSolutionPath + solutionName + "NodeRegistration", RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryOptions.None);
|
||||
if (registryKey == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach (KeyValuePair<string, string> discoveryInfo in discoveryInfos)
|
||||
{
|
||||
switch (discoveryInfo.Key)
|
||||
{
|
||||
case "PrimaryGlobalDiscovery":
|
||||
WriteRegistryValue(registryKey, PGDSEndPoint, discoveryInfo.Value);
|
||||
break;
|
||||
case "SecondaryGlobalDiscovery":
|
||||
WriteRegistryValue(registryKey, SGDSEndPoint, discoveryInfo.Value);
|
||||
break;
|
||||
case "PrimaryUniversalDiscovery":
|
||||
WriteRegistryValue(registryKey, PUDSEndPoint, discoveryInfo.Value);
|
||||
break;
|
||||
case "SecondaryUniversalDiscovery":
|
||||
WriteRegistryValue(registryKey, SUDSEndPoint, discoveryInfo.Value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteRegistryValue(RegistryKey solutionKey, string key, string value)
|
||||
{
|
||||
if (solutionKey != null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
{
|
||||
solutionKey.SetValue(key, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
solutionKey.SetValue(key, string.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static string GenerateXMLExtraInfo(List<KeyValuePair<string, string>> Parameters)
|
||||
{
|
||||
XElement xElement = new XElement("extrainfo");
|
||||
if (Parameters != null)
|
||||
{
|
||||
foreach (KeyValuePair<string, string> Parameter in Parameters)
|
||||
{
|
||||
XElement xElement2 = new XElement("parameter");
|
||||
xElement2.Add(new XAttribute("name", Parameter.Key));
|
||||
xElement2.Add(new XAttribute("value", Parameter.Value));
|
||||
xElement.Add(xElement2);
|
||||
}
|
||||
}
|
||||
return xElement.ToString();
|
||||
}
|
||||
|
||||
public static Dictionary<string, string> ParseXMLExtraInfo(string XMLExtraInfo)
|
||||
{
|
||||
Dictionary<string, string> dictionary = new Dictionary<string, string>();
|
||||
if (!string.IsNullOrEmpty(XMLExtraInfo))
|
||||
{
|
||||
XElement xElement = null;
|
||||
using StringReader stringReader = new StringReader(XMLExtraInfo);
|
||||
if (stringReader != null)
|
||||
{
|
||||
xElement = XElement.Load(stringReader);
|
||||
}
|
||||
if (xElement != null)
|
||||
{
|
||||
foreach (XElement item in xElement.Elements("parameter"))
|
||||
{
|
||||
XAttribute xAttribute = item.Attribute("name");
|
||||
XAttribute xAttribute2 = item.Attribute("value");
|
||||
if (xAttribute != null && xAttribute2 != null)
|
||||
{
|
||||
dictionary.Add(xAttribute.Value, xAttribute2.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Warning, 0, $"ParseXMLExtraInfo failed to parse XMLExtraInfo {XMLExtraInfo}");
|
||||
}
|
||||
}
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
private static bool GetBinaryRegistryValue(string keyPath, string keyName)
|
||||
{
|
||||
bool result = false;
|
||||
RegistryKey registryKey = null;
|
||||
try
|
||||
{
|
||||
registryKey = Registry.LocalMachine.OpenSubKey(keyPath);
|
||||
if (registryKey != null)
|
||||
{
|
||||
result = Convert.ToBoolean(registryKey.GetValue(keyName));
|
||||
}
|
||||
registryKey?.Close();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
registryKey?.Close();
|
||||
throw;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,327 @@
|
||||
#define TRACE
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace ArchestrAServices.Common;
|
||||
|
||||
public class RegistryWatcher : IDisposable
|
||||
{
|
||||
private IntPtr intPtrRegistryHive;
|
||||
|
||||
private string strRegistrySubName;
|
||||
|
||||
private object objThreadLock = new object();
|
||||
|
||||
private Thread workerThread;
|
||||
|
||||
private bool bDisposed;
|
||||
|
||||
private ManualResetEvent eventToTerminate = new ManualResetEvent(initialState: false);
|
||||
|
||||
private bool bEnableRaisingEvents;
|
||||
|
||||
private RegistryChangeFilter registryChangeFilter = RegistryChangeFilter.Value;
|
||||
|
||||
private static readonly string wow64OptionalLayer = (Environment.Is64BitProcess ? "Wow6432Node\\" : string.Empty);
|
||||
|
||||
private const int KEY_QUERY_VALUE = 1;
|
||||
|
||||
private const int KEY_NOTIFY = 16;
|
||||
|
||||
private const int STANDARD_RIGHTS_READ = 131072;
|
||||
|
||||
private static readonly IntPtr HKEY_CLASSES_ROOT = new IntPtr(int.MinValue);
|
||||
|
||||
private static readonly IntPtr HKEY_CURRENT_USER = new IntPtr(-2147483647);
|
||||
|
||||
private static readonly IntPtr HKEY_LOCAL_MACHINE = new IntPtr(-2147483646);
|
||||
|
||||
private static readonly IntPtr HKEY_USERS = new IntPtr(-2147483645);
|
||||
|
||||
private static readonly IntPtr HKEY_PERFORMANCE_DATA = new IntPtr(-2147483644);
|
||||
|
||||
private static readonly IntPtr HKEY_CURRENT_CONFIG = new IntPtr(-2147483643);
|
||||
|
||||
private static readonly IntPtr HKEY_DYN_DATA = new IntPtr(-2147483642);
|
||||
|
||||
public RegistryChangeFilter RegistryChangeNotifyFilter
|
||||
{
|
||||
get
|
||||
{
|
||||
return registryChangeFilter;
|
||||
}
|
||||
set
|
||||
{
|
||||
lock (objThreadLock)
|
||||
{
|
||||
if (IsMonitoring)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 2, "Monitoring thread is already running");
|
||||
}
|
||||
else
|
||||
{
|
||||
registryChangeFilter = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool EnableRaisingEvents
|
||||
{
|
||||
get
|
||||
{
|
||||
return bEnableRaisingEvents;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (bEnableRaisingEvents != value)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
bEnableRaisingEvents = Start();
|
||||
return;
|
||||
}
|
||||
Stop();
|
||||
bEnableRaisingEvents = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsMonitoring => workerThread != null;
|
||||
|
||||
private event EventHandler changed;
|
||||
|
||||
public event EventHandler Changed
|
||||
{
|
||||
add
|
||||
{
|
||||
lock (objThreadLock)
|
||||
{
|
||||
changed += value.Invoke;
|
||||
}
|
||||
}
|
||||
remove
|
||||
{
|
||||
lock (objThreadLock)
|
||||
{
|
||||
changed -= value.Invoke;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("advapi32.dll", BestFitMapping = false, CharSet = CharSet.Auto, SetLastError = true)]
|
||||
private static extern int RegOpenKeyEx(IntPtr hKey, string subKey, uint options, int samDesired, out IntPtr phkResult);
|
||||
|
||||
[DllImport("advapi32.dll", SetLastError = true)]
|
||||
private static extern int RegNotifyChangeKeyValue(IntPtr hKey, bool bWatchSubtree, RegistryChangeFilter dwNotifyFilter, IntPtr hEvent, bool fAsynchronous);
|
||||
|
||||
[DllImport("advapi32.dll", SetLastError = true)]
|
||||
private static extern int RegCloseKey(IntPtr hKey);
|
||||
|
||||
protected virtual void OnChanged()
|
||||
{
|
||||
EventHandler eventHandler = this.changed;
|
||||
if (eventHandler != null)
|
||||
{
|
||||
lock (objThreadLock)
|
||||
{
|
||||
eventHandler(this, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool SetRegistryPath(RegistryHive registryHive, string subKey)
|
||||
{
|
||||
bool flag = false;
|
||||
try
|
||||
{
|
||||
flag = InitAndValidateRegistryKey(registryHive, subKey);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
flag = false;
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 2, $"SetRegistryPath exception: '{ex.Message}'");
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
private bool InitAndValidateRegistryKey(RegistryHive hive, string name)
|
||||
{
|
||||
bool flag = true;
|
||||
switch (hive)
|
||||
{
|
||||
case RegistryHive.ClassesRoot:
|
||||
intPtrRegistryHive = HKEY_CLASSES_ROOT;
|
||||
break;
|
||||
case RegistryHive.CurrentConfig:
|
||||
intPtrRegistryHive = HKEY_CURRENT_CONFIG;
|
||||
break;
|
||||
case RegistryHive.CurrentUser:
|
||||
intPtrRegistryHive = HKEY_CURRENT_USER;
|
||||
break;
|
||||
case RegistryHive.LocalMachine:
|
||||
intPtrRegistryHive = HKEY_LOCAL_MACHINE;
|
||||
break;
|
||||
case RegistryHive.PerformanceData:
|
||||
intPtrRegistryHive = HKEY_PERFORMANCE_DATA;
|
||||
break;
|
||||
case RegistryHive.Users:
|
||||
intPtrRegistryHive = HKEY_USERS;
|
||||
break;
|
||||
default:
|
||||
flag = false;
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 2, "Invalid rootkey for registry path");
|
||||
break;
|
||||
}
|
||||
if (flag)
|
||||
{
|
||||
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(name);
|
||||
if (registryKey != null)
|
||||
{
|
||||
strRegistrySubName = name;
|
||||
registryKey.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
flag = false;
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 2, "Invalid subkey for registry path");
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
private bool Start()
|
||||
{
|
||||
bool result = false;
|
||||
if (bDisposed)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Warning, 2, "This instance is already disposed");
|
||||
}
|
||||
if (!string.IsNullOrEmpty(strRegistrySubName))
|
||||
{
|
||||
IntPtr phkResult;
|
||||
int num = RegOpenKeyEx(intPtrRegistryHive, strRegistrySubName, 0u, 131089, out phkResult);
|
||||
if (phkResult != IntPtr.Zero)
|
||||
{
|
||||
RegCloseKey(phkResult);
|
||||
}
|
||||
if (num == 0)
|
||||
{
|
||||
lock (objThreadLock)
|
||||
{
|
||||
if (!IsMonitoring)
|
||||
{
|
||||
eventToTerminate.Reset();
|
||||
workerThread = new Thread(RegWatcherThread);
|
||||
workerThread.IsBackground = true;
|
||||
workerThread.Start();
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void RegWatcherThread()
|
||||
{
|
||||
IntPtr phkResult = IntPtr.Zero;
|
||||
try
|
||||
{
|
||||
if (RegOpenKeyEx(intPtrRegistryHive, strRegistrySubName, 0u, 131089, out phkResult) != 0)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 2, "RegOpenKeyEx is failed to open the given registry key path");
|
||||
}
|
||||
AutoResetEvent autoResetEvent = new AutoResetEvent(initialState: false);
|
||||
WaitHandle[] waitHandles = new WaitHandle[2] { autoResetEvent, eventToTerminate };
|
||||
int num = ReadWaitTimeout();
|
||||
while (!eventToTerminate.WaitOne(0, exitContext: true))
|
||||
{
|
||||
int num2 = RegNotifyChangeKeyValue(phkResult, bWatchSubtree: true, registryChangeFilter, autoResetEvent.SafeWaitHandle.DangerousGetHandle(), fAsynchronous: true);
|
||||
if (num2 != 0)
|
||||
{
|
||||
throw new Win32Exception(num2);
|
||||
}
|
||||
if (WaitHandle.WaitAny(waitHandles) == 0)
|
||||
{
|
||||
while (RegNotifyChangeKeyValue(phkResult, bWatchSubtree: true, RegistryChangeFilter.Value, autoResetEvent.SafeWaitHandle.DangerousGetHandle(), fAsynchronous: true) == 0 && WaitHandle.WaitAny(waitHandles, TimeSpan.FromSeconds(num)) == 0)
|
||||
{
|
||||
}
|
||||
OnChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 2, "MonitorThread exception {0}", ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (phkResult != IntPtr.Zero)
|
||||
{
|
||||
RegCloseKey(phkResult);
|
||||
}
|
||||
workerThread = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static int ReadWaitTimeout()
|
||||
{
|
||||
int result = 2;
|
||||
try
|
||||
{
|
||||
using RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\" + wow64OptionalLayer + "ArchestrA\\ArchestrAServices", writable: false);
|
||||
object obj = registryKey?.GetValue("DiscoveryChangeNotifyDelay");
|
||||
if (obj != null && !int.TryParse(obj.ToString(), out result))
|
||||
{
|
||||
result = 2;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void Stop()
|
||||
{
|
||||
if (bDisposed)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Warning, 2, "This instance is already disposed");
|
||||
return;
|
||||
}
|
||||
lock (objThreadLock)
|
||||
{
|
||||
Thread thread = workerThread;
|
||||
if (thread != null)
|
||||
{
|
||||
eventToTerminate.Set();
|
||||
thread.Join();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!bDisposed)
|
||||
{
|
||||
Stop();
|
||||
if (disposing && eventToTerminate != null)
|
||||
{
|
||||
eventToTerminate.Dispose();
|
||||
eventToTerminate = null;
|
||||
}
|
||||
bDisposed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
|
||||
namespace ArchestrAServices.Common;
|
||||
|
||||
public static class SafeEnum
|
||||
{
|
||||
public static bool TryParse<TEnum>(string inputValue, out TEnum enumValue) where TEnum : struct
|
||||
{
|
||||
TEnum result;
|
||||
bool flag = Enum.TryParse<TEnum>(inputValue, ignoreCase: true, out result);
|
||||
if (flag && !Enum.IsDefined(typeof(TEnum), result))
|
||||
{
|
||||
flag = false;
|
||||
result = default(TEnum);
|
||||
}
|
||||
enumValue = result;
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
namespace ArchestrAServices.Common;
|
||||
|
||||
public enum SecureCommunicationModes
|
||||
{
|
||||
Never,
|
||||
Preferred,
|
||||
Required
|
||||
}
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
#define TRACE
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
|
||||
namespace ArchestrAServices.Common;
|
||||
|
||||
public class ServiceShutdownControl : IDisposable
|
||||
{
|
||||
public delegate void ShutdownCallback();
|
||||
|
||||
private readonly ShutdownCallback m_Callback;
|
||||
|
||||
private bool disposed;
|
||||
|
||||
public ServiceShutdownControl(ShutdownCallback callback = null)
|
||||
{
|
||||
m_Callback = callback;
|
||||
}
|
||||
|
||||
~ServiceShutdownControl()
|
||||
{
|
||||
Dispose(disposing: false);
|
||||
}
|
||||
|
||||
public static void SignalShutdown(Process watchedServiceProcess, string serviceInstanceName)
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, "ServiceShutdownControl: SignalShutdown called");
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(serviceInstanceName))
|
||||
{
|
||||
EventWaitHandle eventWaitHandle = EventWaitHandle.OpenExisting(serviceInstanceName);
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, $"ServiceShutdownControl: Setting shutdown signal for process {serviceInstanceName}");
|
||||
eventWaitHandle.Set();
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, $"ServiceShutdownControl: Closing the process {serviceInstanceName}");
|
||||
watchedServiceProcess?.WaitForExit(15000);
|
||||
}
|
||||
else
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Warning, 0, "ServiceShutdownControl: Process name cannot be null/empty.");
|
||||
}
|
||||
}
|
||||
catch (WaitHandleCannotBeOpenedException)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 0, "ServiceShutdownControl: Named event does not exist.");
|
||||
}
|
||||
catch (UnauthorizedAccessException ex2)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 0, $"ServiceShutdownControl: Unauthorized access: {ex2.Message}");
|
||||
}
|
||||
catch (Exception ex3)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 0, $"ServiceShutdownControl: Exception in SignalShutdown: {ex3.Message}");
|
||||
}
|
||||
if (watchedServiceProcess != null && !watchedServiceProcess.HasExited)
|
||||
{
|
||||
try
|
||||
{
|
||||
watchedServiceProcess.Kill();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, "ServiceShutdownControl: SignalShutdown exited");
|
||||
}
|
||||
|
||||
public void WaitForShutdown(string serviceInstanceName)
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, "ServiceShutdownControl: WaitForShutdown called.");
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(serviceInstanceName))
|
||||
{
|
||||
EventWaitHandle eventWaitHandle = new EventWaitHandle(initialState: false, EventResetMode.AutoReset, serviceInstanceName);
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, $"ServiceShutdownControl: Starting wait for shutdown signal for process {serviceInstanceName}");
|
||||
eventWaitHandle.WaitOne();
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, $"ServiceShutdownControl: Received shutdown signal, stopping process {serviceInstanceName}");
|
||||
}
|
||||
else
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Warning, 0, "ServiceShutdownControl: Process name cannot be null/empty.");
|
||||
}
|
||||
}
|
||||
catch (WaitHandleCannotBeOpenedException)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 0, $"ServiceShutdownControl: Named event does not exist for process {serviceInstanceName}");
|
||||
}
|
||||
catch (UnauthorizedAccessException ex2)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 0, $"ServiceShutdownControl: Unauthorized access: {ex2.Message}");
|
||||
}
|
||||
catch (Exception ex3)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 0, $"ServiceShutdownControl: Exception in WaitForShutdown: {ex3.Message}");
|
||||
}
|
||||
try
|
||||
{
|
||||
if (m_Callback != null)
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, "ServiceShutdownControl: Calling user-supplied shutdown callback");
|
||||
m_Callback();
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, "ServiceShutdownControl: Returned from user-supplied shutdown callback");
|
||||
}
|
||||
}
|
||||
catch (Exception ex4)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 0, $"ServiceShutdownControl: Exception calling user-supplied callback: {ex4.Message}");
|
||||
}
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, "ServiceShutdownControl: WaitForShutdown exited.");
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Stop, 0, "ServiceShutdownControl disposing");
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
#define TRACE
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
|
||||
namespace ArchestrAServices.Common;
|
||||
|
||||
public static class ServiceTrace
|
||||
{
|
||||
public static TraceSource DiagData { get; private set; }
|
||||
|
||||
public static TraceSource DiagControl { get; private set; }
|
||||
|
||||
public static TraceSource DiagCommand { get; private set; }
|
||||
|
||||
public static TraceSource DiagException { get; private set; }
|
||||
|
||||
public static TraceSource SecurityEvent { get; private set; }
|
||||
|
||||
public static TraceSource DiagDiagnostics { get; private set; }
|
||||
|
||||
public static TraceSource DiagCsv { get; private set; }
|
||||
|
||||
static ServiceTrace()
|
||||
{
|
||||
DiagData = new TraceSource("DataFlowLogs");
|
||||
DiagControl = new TraceSource("ControlFlowLogs");
|
||||
DiagCommand = new TraceSource("CommandLogs");
|
||||
DiagException = new TraceSource("ExceptionLogs");
|
||||
SecurityEvent = new TraceSource("SecurityLogs");
|
||||
DiagDiagnostics = new TraceSource("DiagnosticsLogs");
|
||||
DiagCsv = new TraceSource("CSVDiagnostics");
|
||||
}
|
||||
|
||||
public static void SetLogIdentityAll(string identity)
|
||||
{
|
||||
DiagData.SetLogIdentity(identity);
|
||||
DiagControl.SetLogIdentity(identity);
|
||||
DiagCommand.SetLogIdentity(identity);
|
||||
DiagException.SetLogIdentity(identity);
|
||||
SecurityEvent.SetLogIdentity(identity);
|
||||
DiagDiagnostics.SetLogIdentity(identity);
|
||||
DiagCsv.SetLogIdentity(identity);
|
||||
}
|
||||
|
||||
public static void SetLogIdentity(this TraceSource traceSource, [Localizable(false)] string identity)
|
||||
{
|
||||
if (traceSource == null || string.IsNullOrEmpty(identity))
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach (TraceListener listener in traceSource.Listeners)
|
||||
{
|
||||
PropertyInfo property = listener.GetType().GetProperty("LoggingIdentity");
|
||||
if (property != null && property.CanWrite && property.PropertyType == typeof(string))
|
||||
{
|
||||
property.SetValue(listener, identity, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void LogInfo([Localizable(false)] string message)
|
||||
{
|
||||
DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, message);
|
||||
}
|
||||
|
||||
public static void LogInfo([Localizable(false)] string format, params object[] args)
|
||||
{
|
||||
LogInfo(string.Format(CultureInfo.InvariantCulture, format, args));
|
||||
}
|
||||
|
||||
public static void LogWarning([Localizable(false)] string message)
|
||||
{
|
||||
DiagException.TraceEvent(TraceEventType.Warning, 0, message);
|
||||
}
|
||||
|
||||
public static void LogWarning([Localizable(false)] string format, params object[] args)
|
||||
{
|
||||
LogWarning(string.Format(CultureInfo.InvariantCulture, format, args));
|
||||
}
|
||||
|
||||
public static void LogError([Localizable(false)] string message)
|
||||
{
|
||||
DiagException.TraceEvent(TraceEventType.Error, 0, message);
|
||||
}
|
||||
|
||||
public static void LogError([Localizable(false)] string format, params object[] args)
|
||||
{
|
||||
LogError(string.Format(CultureInfo.InvariantCulture, format, args));
|
||||
}
|
||||
|
||||
public static void LogCritical([Localizable(false)] string message)
|
||||
{
|
||||
DiagException.TraceEvent(TraceEventType.Critical, 0, message);
|
||||
}
|
||||
|
||||
public static void LogCritical([Localizable(false)] string format, params object[] args)
|
||||
{
|
||||
LogCritical(string.Format(CultureInfo.InvariantCulture, format, args));
|
||||
}
|
||||
|
||||
public static void LogVerbose([Localizable(false)] string message)
|
||||
{
|
||||
DiagDiagnostics.TraceEvent(TraceEventType.Verbose, 0, message);
|
||||
}
|
||||
|
||||
public static void LogVerbose([Localizable(false)] string format, params object[] args)
|
||||
{
|
||||
LogVerbose(string.Format(CultureInfo.InvariantCulture, format, args));
|
||||
}
|
||||
|
||||
public static void LogStart([Localizable(false)] string message)
|
||||
{
|
||||
SecurityEvent.TraceEvent(TraceEventType.Start, 0, message);
|
||||
}
|
||||
|
||||
public static void LogStart([Localizable(false)] string format, params object[] args)
|
||||
{
|
||||
LogStart(string.Format(CultureInfo.InvariantCulture, format, args));
|
||||
}
|
||||
|
||||
public static void LogStop([Localizable(false)] string message)
|
||||
{
|
||||
SecurityEvent.TraceEvent(TraceEventType.Stop, 0, message);
|
||||
}
|
||||
|
||||
public static void LogStop([Localizable(false)] string format, params object[] args)
|
||||
{
|
||||
LogStop(string.Format(CultureInfo.InvariantCulture, format, args));
|
||||
}
|
||||
|
||||
public static void LogSuspend([Localizable(false)] string message)
|
||||
{
|
||||
SecurityEvent.TraceEvent(TraceEventType.Suspend, 0, message);
|
||||
}
|
||||
|
||||
public static void LogSuspend([Localizable(false)] string format, params object[] args)
|
||||
{
|
||||
LogSuspend(string.Format(CultureInfo.InvariantCulture, format, args));
|
||||
}
|
||||
|
||||
public static void LogResume([Localizable(false)] string message)
|
||||
{
|
||||
SecurityEvent.TraceEvent(TraceEventType.Resume, 0, message);
|
||||
}
|
||||
|
||||
public static void LogResume([Localizable(false)] string format, params object[] args)
|
||||
{
|
||||
LogResume(string.Format(CultureInfo.InvariantCulture, format, args));
|
||||
}
|
||||
|
||||
public static void LogCsv(params object[] args)
|
||||
{
|
||||
DiagCsv.TraceEvent(TraceEventType.Information, 0, string.Empty, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace ArchestrAServices.Common;
|
||||
|
||||
public class SvcTrace
|
||||
{
|
||||
public static TraceSource DiagData = new TraceSource("DataFlowLogs");
|
||||
|
||||
public static TraceSource DiagControl = new TraceSource("ControlFlowLogs");
|
||||
|
||||
public static TraceSource DiagCommand = new TraceSource("CommandLogs");
|
||||
|
||||
public static TraceSource DiagException = new TraceSource("ExceptionLogs");
|
||||
|
||||
public static TraceSource DiagDiagnostics = new TraceSource("DiagnosticsLogs");
|
||||
|
||||
public static TraceSource DiagCsv = new TraceSource("CSVDiagnostics");
|
||||
}
|
||||
@@ -0,0 +1,917 @@
|
||||
#define TRACE
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Net.Security;
|
||||
using System.Net.Sockets;
|
||||
using System.ServiceModel;
|
||||
using System.ServiceModel.Channels;
|
||||
using System.ServiceModel.Discovery;
|
||||
using System.ServiceProcess;
|
||||
using System.Threading;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace ArchestrAServices.Common;
|
||||
|
||||
public static class SvcUtilities
|
||||
{
|
||||
public const string AsbCoreServiceScope = "archestra://coreservices";
|
||||
|
||||
public const string AsbUserServiceScope = "archestra://asb/";
|
||||
|
||||
public const string AsbScopePrefix = "archestra://";
|
||||
|
||||
public const string ServiceNameScope = "instancename/";
|
||||
|
||||
public const string ServiceVersionScope = "serviceversion/";
|
||||
|
||||
public const string DataTypeScope = "datatype/";
|
||||
|
||||
public const string SolutionNameScope = "asbsolution/";
|
||||
|
||||
public const string DomainScope = "domainname/";
|
||||
|
||||
public const string NamespaceScope = "namespace/";
|
||||
|
||||
public static ConfigurationRepository asbCommonConfiguration = new ConfigurationRepository();
|
||||
|
||||
public static string MetaOuterElement = "ArchestrA.Discovery";
|
||||
|
||||
public static string MetaReplicationElement = "replicationScope";
|
||||
|
||||
public static string MetaReplicationAttributeName = "scope";
|
||||
|
||||
public static string MetaReplicationAttributeValue = "localASBSolution";
|
||||
|
||||
private static readonly int Auto_Port = 0;
|
||||
|
||||
private static readonly int portStartIndex = 10000;
|
||||
|
||||
private static readonly int portEndIndex = 15000;
|
||||
|
||||
public static string ParseCommandLine(string[] args, string switchName)
|
||||
{
|
||||
if (args == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
if (string.IsNullOrEmpty(switchName))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
string text = switchName.ToUpperInvariant();
|
||||
if (!switchName.StartsWith("/", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
text = "/" + text;
|
||||
}
|
||||
foreach (string text2 in args)
|
||||
{
|
||||
if (text2.ToUpperInvariant().StartsWith(text, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
string text3 = text2.Substring(text.Length);
|
||||
if (text3.StartsWith("=", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
text3 = text3.Substring(1);
|
||||
}
|
||||
return text3;
|
||||
}
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public static Binding GetBinding(string endpointAddress)
|
||||
{
|
||||
return GetBinding(endpointAddress, NetTcpBindingSecurityMode.None);
|
||||
}
|
||||
|
||||
public static Binding GetBinding(string endpointAddress, NetTcpBindingSecurityMode securityMode)
|
||||
{
|
||||
Binding result = null;
|
||||
string text = endpointAddress.ToLower();
|
||||
if (text.StartsWith("http"))
|
||||
{
|
||||
result = GetWSHttpBinding();
|
||||
}
|
||||
else if (text.StartsWith("net.tcp"))
|
||||
{
|
||||
switch (securityMode)
|
||||
{
|
||||
case NetTcpBindingSecurityMode.None:
|
||||
result = GetTcpBinding();
|
||||
break;
|
||||
case NetTcpBindingSecurityMode.CertificateEncryption:
|
||||
result = GetSecureCertificateTcpBinding();
|
||||
break;
|
||||
case NetTcpBindingSecurityMode.CredentialAuthentication:
|
||||
result = GetSecureCredentialTcpBinding();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (text.StartsWith("net.pipe"))
|
||||
{
|
||||
result = GetNamedPipeBinding();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static WSHttpBinding GetHttpBinding()
|
||||
{
|
||||
return GetWSHttpBinding();
|
||||
}
|
||||
|
||||
public static WSHttpBinding GetWSHttpBinding()
|
||||
{
|
||||
int num = int.MaxValue;
|
||||
WSHttpBinding wSHttpBinding = new WSHttpBinding();
|
||||
try
|
||||
{
|
||||
string parameter = asbCommonConfiguration.GetParameter("HttpBinding.Security.Mode", "None");
|
||||
wSHttpBinding.Security.Mode = (SecurityMode)Enum.Parse(typeof(SecurityMode), parameter);
|
||||
parameter = asbCommonConfiguration.GetParameter("HttpBinding.AllowCookies", "false");
|
||||
wSHttpBinding.AllowCookies = bool.Parse(parameter);
|
||||
parameter = asbCommonConfiguration.GetParameter("HttpBinding.BypassProxyOnLocal", "true");
|
||||
wSHttpBinding.BypassProxyOnLocal = bool.Parse(parameter);
|
||||
parameter = asbCommonConfiguration.GetParameter("HttpBinding.HostNameComparisonMode", "StrongWildcard");
|
||||
wSHttpBinding.HostNameComparisonMode = (HostNameComparisonMode)Enum.Parse(typeof(HostNameComparisonMode), parameter);
|
||||
parameter = asbCommonConfiguration.GetParameter("HttpBinding.MessageEncoding", "Text");
|
||||
wSHttpBinding.MessageEncoding = (WSMessageEncoding)Enum.Parse(typeof(WSMessageEncoding), parameter);
|
||||
parameter = asbCommonConfiguration.GetParameter("HttpBinding.MaxReceivedMessageSize", int.MaxValue.ToString());
|
||||
wSHttpBinding.MaxReceivedMessageSize = int.Parse(parameter);
|
||||
parameter = asbCommonConfiguration.GetParameter("HttpBinding.MaxBufferPoolSize", long.MaxValue.ToString());
|
||||
wSHttpBinding.MaxBufferPoolSize = long.Parse(parameter);
|
||||
parameter = asbCommonConfiguration.GetParameter("HttpBinding.ReaderQuotas.MaxArrayLength", int.MaxValue.ToString());
|
||||
wSHttpBinding.ReaderQuotas.MaxArrayLength = int.Parse(parameter);
|
||||
parameter = asbCommonConfiguration.GetParameter("HttpBinding.ReaderQuotas.MaxBytesPerRead", int.MaxValue.ToString());
|
||||
wSHttpBinding.ReaderQuotas.MaxBytesPerRead = num;
|
||||
parameter = asbCommonConfiguration.GetParameter("HttpBinding.ReaderQuotas.MaxDepth", int.MaxValue.ToString());
|
||||
wSHttpBinding.ReaderQuotas.MaxDepth = num;
|
||||
parameter = asbCommonConfiguration.GetParameter("HttpBinding.ReaderQuotas.MaxNameTableCharCount", int.MaxValue.ToString());
|
||||
wSHttpBinding.ReaderQuotas.MaxNameTableCharCount = num;
|
||||
parameter = asbCommonConfiguration.GetParameter("HttpBinding.ReaderQuotas.MaxStringContentLength", int.MaxValue.ToString());
|
||||
wSHttpBinding.ReaderQuotas.MaxStringContentLength = num;
|
||||
parameter = asbCommonConfiguration.GetParameter("HttpBinding.OpenTimeout", new TimeSpan(0, 1, 0).ToString());
|
||||
wSHttpBinding.OpenTimeout = TimeSpan.Parse(parameter);
|
||||
parameter = asbCommonConfiguration.GetParameter("HttpBinding.ReceiveTimeout", new TimeSpan(0, 1, 0).ToString());
|
||||
wSHttpBinding.ReceiveTimeout = TimeSpan.Parse(parameter);
|
||||
parameter = asbCommonConfiguration.GetParameter("HttpBinding.SendTimeout", new TimeSpan(0, 1, 0).ToString());
|
||||
wSHttpBinding.SendTimeout = TimeSpan.Parse(parameter);
|
||||
parameter = asbCommonConfiguration.GetParameter("HttpBinding.CloseTimeout", new TimeSpan(0, 1, 0).ToString());
|
||||
wSHttpBinding.CloseTimeout = TimeSpan.Parse(parameter);
|
||||
parameter = asbCommonConfiguration.GetParameter("HttpBinding.ReliableSession.InactivityTimeout", new TimeSpan(0, 1, 0).ToString());
|
||||
wSHttpBinding.ReliableSession.InactivityTimeout = TimeSpan.Parse(parameter);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 2, $"GetHttpBinding exception: '{ex.Message}'");
|
||||
}
|
||||
return wSHttpBinding;
|
||||
}
|
||||
|
||||
public static IEnumerable<ASBEndpointDescription> ParseEndpoints(XElement ServiceConfiguration)
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 2, "ParseEndpoints entry");
|
||||
List<ASBEndpointDescription> list = new List<ASBEndpointDescription>();
|
||||
string text = "ASBService";
|
||||
XAttribute xAttribute = ServiceConfiguration.Attribute("ServiceName");
|
||||
if (xAttribute != null)
|
||||
{
|
||||
text = xAttribute.Value;
|
||||
}
|
||||
string text2 = "ASBInstance";
|
||||
XAttribute xAttribute2 = ServiceConfiguration.Attribute("InstanceName");
|
||||
if (xAttribute2 != null)
|
||||
{
|
||||
text2 = xAttribute2.Value;
|
||||
}
|
||||
XElement xElement = ServiceConfiguration.Descendants("CommonData").FirstOrDefault();
|
||||
IEnumerable<XElement> enumerable = null;
|
||||
if (xElement != null)
|
||||
{
|
||||
enumerable = xElement.Descendants("Endpoint");
|
||||
}
|
||||
if (enumerable != null)
|
||||
{
|
||||
foreach (XElement item in enumerable)
|
||||
{
|
||||
string text3 = "<unknown>";
|
||||
XAttribute xAttribute3 = item.Attribute("transport");
|
||||
if (xAttribute3 != null)
|
||||
{
|
||||
text3 = xAttribute3.Value;
|
||||
}
|
||||
string text4 = "localhost";
|
||||
XAttribute xAttribute4 = item.Attribute("address");
|
||||
if (xAttribute4 != null)
|
||||
{
|
||||
text4 = xAttribute4.Value;
|
||||
}
|
||||
string text5 = string.Empty;
|
||||
XAttribute xAttribute5 = item.Attribute("interfaceName");
|
||||
if (xAttribute5 != null)
|
||||
{
|
||||
text5 = xAttribute5.Value;
|
||||
}
|
||||
string text6 = string.Empty;
|
||||
XAttribute xAttribute6 = item.Attribute("port");
|
||||
if (xAttribute6 != null)
|
||||
{
|
||||
text6 = xAttribute6.Value;
|
||||
if (text6 == "0")
|
||||
{
|
||||
text6 = string.Empty;
|
||||
}
|
||||
}
|
||||
string value = string.Empty;
|
||||
XAttribute xAttribute7 = item.Attribute("default");
|
||||
if (xAttribute7 != null)
|
||||
{
|
||||
value = xAttribute7.Value;
|
||||
}
|
||||
bool flag = true;
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
{
|
||||
flag = Convert.ToBoolean(value);
|
||||
}
|
||||
Binding TypedBinding = null;
|
||||
string addressPrefix = GetAddressPrefix(text3, out TypedBinding);
|
||||
if (!string.IsNullOrEmpty(text5) && !string.IsNullOrEmpty(addressPrefix) && TypedBinding != null)
|
||||
{
|
||||
string empty = string.Empty;
|
||||
empty = ((!(string.IsNullOrEmpty(text6) || flag)) ? (addressPrefix + "://" + text4 + ":" + text6 + "/" + text + "/" + text2) : (addressPrefix + "://" + text4 + "/" + text + "/" + text2));
|
||||
Uri endpointUri = GetEndpointUri(new Uri(empty), bCreatePort: false);
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 2, "ParseEndpoints adding description: Address = {0} Contract = {1} Binding = {2}", endpointUri, text5, TypedBinding.Name);
|
||||
if (flag)
|
||||
{
|
||||
if (TypedBinding is NetTcpBinding)
|
||||
{
|
||||
((NetTcpBinding)TypedBinding).PortSharingEnabled = true;
|
||||
}
|
||||
}
|
||||
else if (TypedBinding is NetTcpBinding)
|
||||
{
|
||||
((NetTcpBinding)TypedBinding).PortSharingEnabled = string.IsNullOrEmpty(text6);
|
||||
}
|
||||
list.Add(new ASBEndpointDescription(endpointUri, text5, TypedBinding));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrEmpty(text5))
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 2, "ParseEndpoints: <Endpoint /> element in configuration without an interfaceName attribute, no endpoint generated");
|
||||
}
|
||||
if (string.IsNullOrEmpty(addressPrefix))
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 2, $"ParseEndpoints: <Endpoint /> element in configuration with transport attribute='{text3}' does not translate to a scheme, no endpoint generated");
|
||||
}
|
||||
if (TypedBinding == null)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 2, $"ParseEndpoints: <Endpoint /> element in configuration with transport attribute='{text3}' does not translate to a binding, no endpoint generated");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static string GetAddressPrefix(string Transport, out Binding TypedBinding)
|
||||
{
|
||||
string result = string.Empty;
|
||||
TypedBinding = null;
|
||||
if (!string.IsNullOrEmpty(Transport))
|
||||
{
|
||||
switch (Transport.ToLower())
|
||||
{
|
||||
case "net.tcp":
|
||||
result = "net.tcp";
|
||||
TypedBinding = GetTcpBinding();
|
||||
break;
|
||||
case "basichttp":
|
||||
result = "http";
|
||||
TypedBinding = new BasicHttpBinding();
|
||||
break;
|
||||
case "webhttp":
|
||||
result = "http";
|
||||
TypedBinding = null;
|
||||
break;
|
||||
case "wsdualhttp":
|
||||
result = "http";
|
||||
TypedBinding = new WSDualHttpBinding();
|
||||
break;
|
||||
case "wshttp":
|
||||
case "http":
|
||||
result = "http";
|
||||
TypedBinding = GetWSHttpBinding();
|
||||
break;
|
||||
default:
|
||||
TypedBinding = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static EndpointAddress GetEndPointAddress(Uri endpointAddressUri)
|
||||
{
|
||||
return GetEndPointAddress(endpointAddressUri, bCreatePort: true);
|
||||
}
|
||||
|
||||
public static EndpointAddress GetEndPointAddress(Uri endpointAddressUri, bool bCreatePort)
|
||||
{
|
||||
if (endpointAddressUri == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
EndpointAddress result = new EndpointAddress(endpointAddressUri);
|
||||
Uri endpointUri = GetEndpointUri(endpointAddressUri, bCreatePort);
|
||||
if (endpointUri != null)
|
||||
{
|
||||
result = new EndpointAddress(endpointUri);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Uri GetEndpointUri(Uri endpointAddressUri, bool bCreatePort)
|
||||
{
|
||||
if (endpointAddressUri == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
try
|
||||
{
|
||||
UriBuilder uriBuilder = new UriBuilder(endpointAddressUri);
|
||||
if (uriBuilder.Scheme != "net.pipe")
|
||||
{
|
||||
if (endpointAddressUri.OriginalString.IndexOf("localhost", StringComparison.OrdinalIgnoreCase) != -1)
|
||||
{
|
||||
uriBuilder.Host = Environment.MachineName;
|
||||
}
|
||||
if (bCreatePort && (uriBuilder.Port == -1 || uriBuilder.Port == Auto_Port))
|
||||
{
|
||||
uriBuilder.Port = FindAvailablePortOnMachine();
|
||||
}
|
||||
}
|
||||
return uriBuilder.Uri;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Warning, 2, $"GetEndpointUri exception: '{ex.Message}'");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Uri GetEndpointListenUri(Uri endpointAddress)
|
||||
{
|
||||
Uri result = null;
|
||||
if (endpointAddress != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
UriBuilder uriBuilder = new UriBuilder(endpointAddress);
|
||||
if (uriBuilder != null)
|
||||
{
|
||||
IPAddress[] hostAddresses = Dns.GetHostAddresses(uriBuilder.Host);
|
||||
foreach (IPAddress iPAddress in hostAddresses)
|
||||
{
|
||||
if (iPAddress.AddressFamily == AddressFamily.InterNetwork)
|
||||
{
|
||||
uriBuilder.Host = iPAddress.ToString();
|
||||
}
|
||||
}
|
||||
result = uriBuilder.Uri;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = endpointAddress;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Warning, 2, $"GetEndpointListenUri exception: '{ex.Message}'");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int FindAvailablePortOnMachine()
|
||||
{
|
||||
int result = 0;
|
||||
Random random = new Random(Environment.TickCount);
|
||||
using (Mutex mutex = new Mutex(initiallyOwned: false, "ArchestraCommon"))
|
||||
{
|
||||
mutex.WaitOne();
|
||||
List<int> list = (from p in IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners()
|
||||
select p.Port).ToList();
|
||||
for (int num = 0; num < 5000; num++)
|
||||
{
|
||||
int num2 = random.Next(portStartIndex, portEndIndex);
|
||||
if (!list.Contains(num2))
|
||||
{
|
||||
result = num2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static EndpointDiscoveryMetadata GetDiscoveryEndpointMetada(EndpointDiscoveryMetadata metaData)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (metaData != null)
|
||||
{
|
||||
UriBuilder uriBuilder = new UriBuilder(metaData.Address.Uri);
|
||||
if (uriBuilder != null && !string.IsNullOrEmpty(uriBuilder.Host))
|
||||
{
|
||||
IPAddress[] hostAddresses = Dns.GetHostAddresses(uriBuilder.Host);
|
||||
foreach (IPAddress iPAddress in hostAddresses)
|
||||
{
|
||||
if (iPAddress.AddressFamily == AddressFamily.InterNetwork)
|
||||
{
|
||||
uriBuilder.Host = iPAddress.ToString();
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 2, string.Format(CultureInfo.CurrentCulture, "IP address {0} for host name {1}", new object[2]
|
||||
{
|
||||
iPAddress.ToString(),
|
||||
metaData.Address.Uri.ToString()
|
||||
}));
|
||||
if (!metaData.ListenUris.Contains(uriBuilder.Uri))
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 2, string.Format(CultureInfo.CurrentCulture, "IP address {0} is not exist in the ListenUris collection ", new object[1] { uriBuilder.Uri.ToString() }));
|
||||
metaData.ListenUris.Insert(0, uriBuilder.Uri);
|
||||
}
|
||||
else
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 2, string.Format(CultureInfo.CurrentCulture, "IP address {0} is already exist in the ListenUris collection ", new object[1] { uriBuilder.Uri.ToString() }));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Information, 2, string.Format(CultureInfo.CurrentCulture, "GetDiscoveryEndpointMetada: Exception {0}", new object[1] { ex.Message }));
|
||||
}
|
||||
return metaData;
|
||||
}
|
||||
|
||||
public static string ReadKeyValue(string subKey, string value)
|
||||
{
|
||||
string result = string.Empty;
|
||||
try
|
||||
{
|
||||
string text = RegistryHandler.RegistryPath;
|
||||
if (!string.IsNullOrEmpty(subKey))
|
||||
{
|
||||
text = text + "\\" + subKey;
|
||||
}
|
||||
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(text, writable: false);
|
||||
if (registryKey != null)
|
||||
{
|
||||
object value2 = registryKey.GetValue(value);
|
||||
if (value2 != null)
|
||||
{
|
||||
result = value2.ToString();
|
||||
}
|
||||
registryKey.Close();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 0, $"ReadKeyValue: Exception caught: {ex.Message}");
|
||||
result = string.Empty;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void GetLocalDiscoveryInfoFromWatchdogConfigFile(string WatchdogConfigFilePath, out string LocalDiscovery)
|
||||
{
|
||||
LocalDiscovery = string.Empty;
|
||||
if (!File.Exists(WatchdogConfigFilePath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
XElement xElement = XElement.Load(WatchdogConfigFilePath);
|
||||
if (!xElement.Elements("appSettings").Any())
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach (XElement item in xElement.Elements("appSettings").Descendants())
|
||||
{
|
||||
if (item.Attribute("key") != null && item.Attribute("key").Value == "LocalDiscoveryEndpoint" && item.Attribute("value") != null)
|
||||
{
|
||||
LocalDiscovery = item.Attribute("value").Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 0, $"GetLocalDiscoveryInfoFromWatchdogConfigFile: Exception caught: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public static void GetDiscoveryInfoFromWatchdogConfigFile(string WatchdogConfigFilePath, out string Discovery1, out string Discovery2)
|
||||
{
|
||||
Discovery1 = string.Empty;
|
||||
Discovery2 = string.Empty;
|
||||
if (!File.Exists(WatchdogConfigFilePath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
XElement xElement = XElement.Load(WatchdogConfigFilePath);
|
||||
if (!xElement.Elements("appSettings").Any())
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach (XElement item in xElement.Elements("appSettings").Descendants())
|
||||
{
|
||||
if (item.Attribute("key") != null && item.Attribute("key").Value == "PrimaryGlobalDiscoveryEndpoint" && item.Attribute("value") != null)
|
||||
{
|
||||
Discovery1 = item.Attribute("value").Value;
|
||||
}
|
||||
if (item.Attribute("key") != null && item.Attribute("key").Value == "SecondaryGlobalDiscoveryEndpoint" && item.Attribute("value") != null)
|
||||
{
|
||||
Discovery2 = item.Attribute("value").Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 0, $"GetDiscoveryInfoFromWatchdogConfigFile: Exception caught: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetDiscoveryEndpoint()
|
||||
{
|
||||
string empty = string.Empty;
|
||||
empty = ReadKeyValue(RegistryHandler.ASBRegistration, RegistryHandler.LDSEndPoint);
|
||||
if (string.IsNullOrEmpty(empty))
|
||||
{
|
||||
empty = "net.tcp://localhost/LDS/Probe";
|
||||
}
|
||||
return empty;
|
||||
}
|
||||
|
||||
public static bool UpdateWatchDogFile(string WatchdogConfigFilePath, string endpoint1, string endpoint2)
|
||||
{
|
||||
SvcTrace.DiagDiagnostics.TraceEvent(TraceEventType.Information, 0, "UpdateWatchDogFile: returning true.");
|
||||
return true;
|
||||
}
|
||||
|
||||
public static string ReadWatchdogConfigFilePath()
|
||||
{
|
||||
string text = ReadKeyValue(string.Empty, "ASBInstallPath");
|
||||
if (!string.IsNullOrEmpty(text))
|
||||
{
|
||||
text = Path.Combine(text, "aaServiceWatchdog.exe.config");
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
public static void PersistDiscoveryInfo(string discovery1, string discovery2)
|
||||
{
|
||||
string text = ReadWatchdogConfigFilePath();
|
||||
if (!string.IsNullOrEmpty(text))
|
||||
{
|
||||
UpdateWatchDogFile(text, discovery1, discovery2);
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteKeyValue(string subKey, string key, string value)
|
||||
{
|
||||
try
|
||||
{
|
||||
string text = RegistryHandler.RegistryPath;
|
||||
if (!string.IsNullOrEmpty(subKey))
|
||||
{
|
||||
text = text + "\\" + subKey;
|
||||
}
|
||||
Registry.LocalMachine.OpenSubKey(text, writable: true)?.SetValue(key, value);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 0, $"WriteKeyValue: Exception caught: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsKeyExist(string subKey, string value)
|
||||
{
|
||||
try
|
||||
{
|
||||
string text = RegistryHandler.RegistryPath;
|
||||
if (!string.IsNullOrEmpty(subKey))
|
||||
{
|
||||
text = text + "\\" + subKey;
|
||||
}
|
||||
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(text, writable: false);
|
||||
if (registryKey != null && registryKey.GetValue(value) != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 0, $"IsKeyExist: Exception caught: {ex.Message}");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void CreateKeysIfNotExist(string subKey)
|
||||
{
|
||||
if (!IsKeyExist(subKey, "NodeRegistration"))
|
||||
{
|
||||
string text = RegistryHandler.RegistryPath;
|
||||
if (!string.IsNullOrEmpty(subKey))
|
||||
{
|
||||
text = text + "\\" + subKey;
|
||||
}
|
||||
text += "\\NodeRegistration";
|
||||
try
|
||||
{
|
||||
Registry.LocalMachine.CreateSubKey(text);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 0, $"CreateKeysIfNotExist: Exception caught: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Collection<Uri> CreateRegisterScopes(string version, string serviceName, string dataType, string domain, string nameSpace, XElement configuration, List<string> extraScopes)
|
||||
{
|
||||
if (string.IsNullOrEmpty(version) || string.IsNullOrEmpty(serviceName) || string.IsNullOrEmpty(dataType) || string.IsNullOrEmpty(domain) || string.IsNullOrEmpty(nameSpace))
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Warning, 0, "While creating Discovery scopes for a service, one of (version, serviceName, dataType, domain, or nameSpace) was missing, generating scopes for the rest");
|
||||
}
|
||||
Collection<Uri> collection = CreateFindScopes(version, serviceName, dataType, domain, nameSpace, extraScopes);
|
||||
RegistryHandler.GetDefaultSolutionName(out var DefaultSolutionName);
|
||||
if (!string.IsNullOrEmpty(DefaultSolutionName))
|
||||
{
|
||||
BuildScopeUri("asbsolution/", DefaultSolutionName, collection);
|
||||
}
|
||||
return collection;
|
||||
}
|
||||
|
||||
public static Collection<Uri> CreateFindScopes(string version, string serviceName, string dataType, string domain, string nameSpace, List<string> extraScopes)
|
||||
{
|
||||
Collection<Uri> collection = new Collection<Uri>();
|
||||
if (extraScopes != null)
|
||||
{
|
||||
foreach (string extraScope in extraScopes)
|
||||
{
|
||||
BuildScopeUri(string.Empty, extraScope, collection);
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(serviceName))
|
||||
{
|
||||
BuildScopeUri("instancename/", serviceName, collection);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(version))
|
||||
{
|
||||
BuildScopeUri("serviceversion/", version, collection);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(dataType))
|
||||
{
|
||||
BuildScopeUri("datatype/", dataType, collection);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(domain))
|
||||
{
|
||||
BuildScopeUri("domainname/", domain, collection);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(nameSpace))
|
||||
{
|
||||
BuildScopeUri("namespace/", nameSpace, collection);
|
||||
}
|
||||
return collection;
|
||||
}
|
||||
|
||||
public static Collection<Uri> CreateRegisterScopes(string version, string serviceName, string dataType, XElement configuration, List<string> extraScopes)
|
||||
{
|
||||
if (string.IsNullOrEmpty(version) || string.IsNullOrEmpty(serviceName) || string.IsNullOrEmpty(dataType))
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Warning, 0, "While creating Discovery scopes for a service, one of (version, serviceName, or dataType) was missing, generating scopes for the rest");
|
||||
}
|
||||
Collection<Uri> collection = CreateFindScopes(version, serviceName, dataType, extraScopes);
|
||||
RegistryHandler.GetDefaultSolutionName(out var DefaultSolutionName);
|
||||
if (!string.IsNullOrEmpty(DefaultSolutionName))
|
||||
{
|
||||
BuildScopeUri("asbsolution/", DefaultSolutionName, collection);
|
||||
}
|
||||
return collection;
|
||||
}
|
||||
|
||||
public static Collection<Uri> CreateFindScopes(string version, string serviceName, string dataType, List<string> extraScopes)
|
||||
{
|
||||
Collection<Uri> collection = new Collection<Uri>();
|
||||
if (extraScopes != null)
|
||||
{
|
||||
foreach (string extraScope in extraScopes)
|
||||
{
|
||||
BuildScopeUri(string.Empty, extraScope, collection);
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(serviceName))
|
||||
{
|
||||
BuildScopeUri("instancename/", serviceName, collection);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(version))
|
||||
{
|
||||
BuildScopeUri("serviceversion/", version, collection);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(dataType))
|
||||
{
|
||||
BuildScopeUri("datatype/", dataType, collection);
|
||||
}
|
||||
return collection;
|
||||
}
|
||||
|
||||
public static bool IsGRInstalled(out string message)
|
||||
{
|
||||
bool result = false;
|
||||
message = string.Empty;
|
||||
try
|
||||
{
|
||||
if ((from svc in ServiceController.GetServices()
|
||||
where svc.ServiceName == "aaGR"
|
||||
select svc).FirstOrDefault() != null)
|
||||
{
|
||||
result = true;
|
||||
message = "IsGRInstalled()::true; aaGR Service is Installed.";
|
||||
}
|
||||
else
|
||||
{
|
||||
message = "IsGRInstalled()::false; aaGR Service is not Installed.";
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
message = ex.ToString();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static bool IsAnyPlatformIsDeployed(out string strFromMachineName, out string strGalaxyName, out string message)
|
||||
{
|
||||
bool result = false;
|
||||
strFromMachineName = string.Empty;
|
||||
strGalaxyName = string.Empty;
|
||||
message = string.Empty;
|
||||
string name = "SOFTWARE\\ArchestrA\\Framework\\ClusterInformation";
|
||||
RegistryKey registryKey = null;
|
||||
try
|
||||
{
|
||||
registryKey = Registry.LocalMachine.OpenSubKey(name, writable: false);
|
||||
if (registryKey != null)
|
||||
{
|
||||
strGalaxyName = registryKey.GetValue("ClusterName").ToString();
|
||||
strFromMachineName = registryKey.GetValue("GalaxyPlatformName").ToString();
|
||||
result = true;
|
||||
message = "IsAnyPlatformIsDeployed():: true; platform is deployed.";
|
||||
}
|
||||
else
|
||||
{
|
||||
message = "IsAnyPlatformIsDeployed():: false; platform is not deployed.";
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
message = ex.ToString();
|
||||
}
|
||||
finally
|
||||
{
|
||||
registryKey?.Close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void BuildScopeUri(string scopeType, string scopeName, Collection<Uri> scopeCollection)
|
||||
{
|
||||
if (scopeCollection != null && !string.IsNullOrEmpty(scopeName))
|
||||
{
|
||||
string text = scopeName;
|
||||
if (!text.StartsWith("archestra://", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
text = "archestra://asb/" + scopeType + scopeName;
|
||||
}
|
||||
scopeCollection.Add(new Uri(text.ToLower(CultureInfo.InvariantCulture)));
|
||||
}
|
||||
}
|
||||
|
||||
public static NetTcpBinding GetTcpBinding()
|
||||
{
|
||||
int num = int.MaxValue;
|
||||
NetTcpBinding netTcpBinding = new NetTcpBinding();
|
||||
try
|
||||
{
|
||||
netTcpBinding.Security.Mode = SecurityMode.None;
|
||||
netTcpBinding.TransferMode = TransferMode.Buffered;
|
||||
netTcpBinding.PortSharingEnabled = true;
|
||||
netTcpBinding.MaxReceivedMessageSize = num;
|
||||
netTcpBinding.MaxBufferSize = num;
|
||||
netTcpBinding.MaxBufferPoolSize = long.MaxValue;
|
||||
netTcpBinding.ReaderQuotas.MaxArrayLength = num;
|
||||
netTcpBinding.ReaderQuotas.MaxBytesPerRead = num;
|
||||
netTcpBinding.ReaderQuotas.MaxDepth = num;
|
||||
netTcpBinding.ReaderQuotas.MaxNameTableCharCount = num;
|
||||
netTcpBinding.ReaderQuotas.MaxStringContentLength = num;
|
||||
netTcpBinding.OpenTimeout = new TimeSpan(0, 1, 0);
|
||||
netTcpBinding.ReceiveTimeout = new TimeSpan(0, 1, 0);
|
||||
netTcpBinding.SendTimeout = new TimeSpan(0, 1, 0);
|
||||
netTcpBinding.CloseTimeout = new TimeSpan(0, 1, 0);
|
||||
netTcpBinding.ReliableSession.InactivityTimeout = new TimeSpan(0, 1, 0);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 2, $"GetTcpBinding exception: '{ex.Message}'");
|
||||
}
|
||||
return netTcpBinding;
|
||||
}
|
||||
|
||||
public static NetTcpBinding GetAnnouncementBinding()
|
||||
{
|
||||
if (RegistryHandler.SecureCommunicationMode != SecureCommunicationModes.Never)
|
||||
{
|
||||
return GetSecureCredentialTcpBinding();
|
||||
}
|
||||
return GetTcpBinding();
|
||||
}
|
||||
|
||||
public static NetTcpBinding GetAnnouncementBinding(Uri announcementAddress)
|
||||
{
|
||||
if (announcementAddress.AbsoluteUri.Contains("/LDS/") && RegistryHandler.SecureCommunicationMode != SecureCommunicationModes.Never)
|
||||
{
|
||||
return GetSecureCredentialTcpBinding();
|
||||
}
|
||||
return GetTcpBinding();
|
||||
}
|
||||
|
||||
public static NetTcpBinding GetSecureCertificateTcpBinding()
|
||||
{
|
||||
NetTcpBinding tcpBinding = GetTcpBinding();
|
||||
try
|
||||
{
|
||||
tcpBinding.Security.Mode = SecurityMode.Transport;
|
||||
tcpBinding.Security.Transport.ProtectionLevel = ProtectionLevel.EncryptAndSign;
|
||||
tcpBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 2, $"GetTcpBinding exception: '{ex.Message}'");
|
||||
}
|
||||
return tcpBinding;
|
||||
}
|
||||
|
||||
private static NetTcpBinding GetSecureCredentialTcpBinding()
|
||||
{
|
||||
NetTcpBinding tcpBinding = GetTcpBinding();
|
||||
try
|
||||
{
|
||||
tcpBinding.Security.Mode = SecurityMode.Transport;
|
||||
tcpBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 2, $"GetTcpBinding exception: '{ex.Message}'");
|
||||
}
|
||||
return tcpBinding;
|
||||
}
|
||||
|
||||
public static NetNamedPipeBinding GetNamedPipeBinding()
|
||||
{
|
||||
int num = int.MaxValue;
|
||||
NetNamedPipeBinding netNamedPipeBinding = new NetNamedPipeBinding();
|
||||
try
|
||||
{
|
||||
netNamedPipeBinding.Security.Mode = NetNamedPipeSecurityMode.None;
|
||||
netNamedPipeBinding.TransferMode = TransferMode.Buffered;
|
||||
netNamedPipeBinding.MaxReceivedMessageSize = num;
|
||||
netNamedPipeBinding.MaxBufferSize = num;
|
||||
netNamedPipeBinding.MaxBufferPoolSize = long.MaxValue;
|
||||
netNamedPipeBinding.ReaderQuotas.MaxArrayLength = num;
|
||||
netNamedPipeBinding.ReaderQuotas.MaxBytesPerRead = num;
|
||||
netNamedPipeBinding.ReaderQuotas.MaxDepth = num;
|
||||
netNamedPipeBinding.ReaderQuotas.MaxNameTableCharCount = num;
|
||||
netNamedPipeBinding.ReaderQuotas.MaxStringContentLength = num;
|
||||
netNamedPipeBinding.OpenTimeout = new TimeSpan(0, 1, 0);
|
||||
netNamedPipeBinding.ReceiveTimeout = new TimeSpan(0, 1, 0);
|
||||
netNamedPipeBinding.SendTimeout = new TimeSpan(0, 1, 0);
|
||||
netNamedPipeBinding.CloseTimeout = new TimeSpan(0, 1, 0);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SvcTrace.DiagException.TraceEvent(TraceEventType.Error, 2, $"NetNamedPipeBinding exception: '{ex.Message}'");
|
||||
}
|
||||
return netNamedPipeBinding;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace ArchestrAServices.Common;
|
||||
|
||||
public static class ThrowHelper
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Parameter)]
|
||||
private sealed class ValidatedNotNullAttribute : Attribute
|
||||
{
|
||||
}
|
||||
|
||||
public static void ThrowIfArgumentNull<T>([ValidatedNotNull] T argument, string argumentName) where T : class
|
||||
{
|
||||
if (argument == null)
|
||||
{
|
||||
throw new ArgumentNullException(argumentName);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ThrowIfArgumentNullOrEmpty<T>([ValidatedNotNull] IEnumerable<T> argument, string argumentName)
|
||||
{
|
||||
if (argument == null)
|
||||
{
|
||||
throw new ArgumentNullException(argumentName);
|
||||
}
|
||||
if (!argument.Any())
|
||||
{
|
||||
throw new ArgumentException("Value must not be empty.", argumentName);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ThrowIfArgumentNullOrWhiteSpace([ValidatedNotNull] string argument, string argumentName)
|
||||
{
|
||||
if (argument == null)
|
||||
{
|
||||
throw new ArgumentNullException(argumentName);
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(argument))
|
||||
{
|
||||
throw new ArgumentException("Value must not be empty or only whitespace.", argumentName);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ThrowIfArgumentOutOfRange(bool outOfRange, string argumentName)
|
||||
{
|
||||
if (outOfRange)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(argumentName, "Value out of range.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void ThrowArgumentException(bool invalid, string argumentName, [Localizable(false)] string message)
|
||||
{
|
||||
if (invalid)
|
||||
{
|
||||
throw new ArgumentException(message, argumentName);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ThrowInvalidOperation([Localizable(false)] string message)
|
||||
{
|
||||
throw new InvalidOperationException(message);
|
||||
}
|
||||
|
||||
public static void ThrowIfServiceIsNull<T>([ValidatedNotNull] T service) where T : class
|
||||
{
|
||||
if (service == null)
|
||||
{
|
||||
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Service {0} is not available", new object[1] { typeof(T).FullName }));
|
||||
}
|
||||
}
|
||||
|
||||
public static void ThrowIfHResultError(int code)
|
||||
{
|
||||
Marshal.ThrowExceptionForHR(code);
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
using System;
|
||||
|
||||
namespace ArchestrAServices.Common;
|
||||
|
||||
public class WindowsServiceStatusChangedEventArgs : EventArgs
|
||||
{
|
||||
public bool IsRunning { get; set; }
|
||||
}
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
#define TRACE
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.ServiceProcess;
|
||||
using System.Timers;
|
||||
|
||||
namespace ArchestrAServices.Common;
|
||||
|
||||
public class WindowsServiceWatcher : IDisposable
|
||||
{
|
||||
private static readonly int TimerInterval = 5000;
|
||||
|
||||
private static readonly int LogWarningCount = 12;
|
||||
|
||||
private readonly string serviceName;
|
||||
|
||||
private bool disposed;
|
||||
|
||||
private Timer timer;
|
||||
|
||||
private int isOfflineCounter;
|
||||
|
||||
private bool lastIsRunningStatus;
|
||||
|
||||
private ServiceController serviceController;
|
||||
|
||||
public event EventHandler<WindowsServiceStatusChangedEventArgs> StatusChanged;
|
||||
|
||||
public WindowsServiceWatcher(string serviceName)
|
||||
{
|
||||
this.serviceName = serviceName;
|
||||
timer = new Timer(TimerInterval);
|
||||
timer.Elapsed += MonitorServiceStatus;
|
||||
timer.Enabled = false;
|
||||
timer.AutoReset = false;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
MonitorServiceStatus(null, null);
|
||||
timer.Enabled = true;
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
timer.Enabled = false;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (disposing)
|
||||
{
|
||||
if (timer != null)
|
||||
{
|
||||
timer.Elapsed -= MonitorServiceStatus;
|
||||
timer.Dispose();
|
||||
timer = null;
|
||||
}
|
||||
if (serviceController != null)
|
||||
{
|
||||
serviceController.Dispose();
|
||||
serviceController = null;
|
||||
}
|
||||
lastIsRunningStatus = false;
|
||||
isOfflineCounter = 0;
|
||||
}
|
||||
disposed = true;
|
||||
}
|
||||
|
||||
private void MonitorServiceStatus(object source, ElapsedEventArgs e)
|
||||
{
|
||||
bool flag = false;
|
||||
bool flag2;
|
||||
try
|
||||
{
|
||||
if (serviceController == null)
|
||||
{
|
||||
serviceController = new ServiceController(serviceName);
|
||||
}
|
||||
serviceController.Refresh();
|
||||
flag2 = serviceController.Status == ServiceControllerStatus.Running;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
if (serviceController != null)
|
||||
{
|
||||
serviceController.Dispose();
|
||||
serviceController = null;
|
||||
}
|
||||
flag2 = false;
|
||||
flag = true;
|
||||
}
|
||||
if (flag2)
|
||||
{
|
||||
if (!lastIsRunningStatus)
|
||||
{
|
||||
SvcTrace.DiagControl.TraceEvent(TraceEventType.Information, 0, string.Format(CultureInfo.InvariantCulture, "{0} windows service is running.", new object[1] { serviceName }));
|
||||
OnStatusChanged(new WindowsServiceStatusChangedEventArgs
|
||||
{
|
||||
IsRunning = true
|
||||
});
|
||||
lastIsRunningStatus = true;
|
||||
isOfflineCounter = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (lastIsRunningStatus)
|
||||
{
|
||||
OnStatusChanged(new WindowsServiceStatusChangedEventArgs
|
||||
{
|
||||
IsRunning = false
|
||||
});
|
||||
lastIsRunningStatus = false;
|
||||
}
|
||||
isOfflineCounter++;
|
||||
if (isOfflineCounter % LogWarningCount == 0)
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
SvcTrace.DiagControl.TraceEvent(TraceEventType.Error, 0, string.Format(CultureInfo.InvariantCulture, "{0} windows service does not exist. If this problem persists, please try installing the {0} windows service.", new object[1] { serviceName }));
|
||||
}
|
||||
else
|
||||
{
|
||||
SvcTrace.DiagControl.TraceEvent(TraceEventType.Warning, 0, string.Format(CultureInfo.InvariantCulture, "{0} windows service is not running. If this problem persists, please try restarting the {0} windows service.", new object[1] { serviceName }));
|
||||
}
|
||||
}
|
||||
}
|
||||
timer.Enabled = true;
|
||||
}
|
||||
|
||||
private void OnStatusChanged(WindowsServiceStatusChangedEventArgs newStatus)
|
||||
{
|
||||
if (this.StatusChanged != null)
|
||||
{
|
||||
this.StatusChanged(this, newStatus);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,322 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using ArchestrA.Diagnostics;
|
||||
|
||||
namespace ArchestrAServices.Common;
|
||||
|
||||
public class aaLoggerListner : TraceListener
|
||||
{
|
||||
private enum aaLogType
|
||||
{
|
||||
LogErrorType,
|
||||
LogWarningType,
|
||||
LogInfoType,
|
||||
LogTraceType,
|
||||
LogStartStopType,
|
||||
LogThreadStartStopType,
|
||||
LogConnectionType,
|
||||
LogRefCountType,
|
||||
LogCtorDtorType,
|
||||
LogSQLType,
|
||||
LogEntryExitType
|
||||
}
|
||||
|
||||
private static object LogLockObject = new object();
|
||||
|
||||
private string CSVLOGFLAG = "ASBAdvancedLog";
|
||||
|
||||
private string LoggingIdentity = string.Empty;
|
||||
|
||||
private bool IsCustomLogType;
|
||||
|
||||
private bool IsCsvLogType;
|
||||
|
||||
private aaLogType LoggerType;
|
||||
|
||||
private int CustomLogTypeCookie;
|
||||
|
||||
private SourceLevels sourceLevel = SourceLevels.All;
|
||||
|
||||
private string asbLogFolder = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\ArchestrA\\LogFiles\\ASBLogging\\";
|
||||
|
||||
private string asbLogFile;
|
||||
|
||||
private static object LogFileLockObject = new object();
|
||||
|
||||
public SourceLevels SourceLevel
|
||||
{
|
||||
get
|
||||
{
|
||||
return sourceLevel;
|
||||
}
|
||||
set
|
||||
{
|
||||
sourceLevel = value;
|
||||
}
|
||||
}
|
||||
|
||||
public aaLoggerListner()
|
||||
{
|
||||
Logger.LogSetIdentityName(Process.GetCurrentProcess().ProcessName);
|
||||
LoggerType = aaLogType.LogTraceType;
|
||||
IsCustomLogType = false;
|
||||
IsCsvLogType = false;
|
||||
CustomLogTypeCookie = 0;
|
||||
InitializeAdvanceLog();
|
||||
}
|
||||
|
||||
public aaLoggerListner(string initializeData)
|
||||
{
|
||||
string[] array = new string[0];
|
||||
if (!string.IsNullOrEmpty(initializeData))
|
||||
{
|
||||
array = initializeData.Split(',');
|
||||
}
|
||||
string logCategory = "LogTraceType";
|
||||
if (array.Length != 0)
|
||||
{
|
||||
logCategory = array[0].Trim();
|
||||
}
|
||||
string text = "All";
|
||||
if (array.Length > 1)
|
||||
{
|
||||
text = array[1].Trim();
|
||||
}
|
||||
SetSourceLevel(text);
|
||||
LoggingIdentity = Process.GetCurrentProcess().ProcessName;
|
||||
string[] commandLineArgs = Environment.GetCommandLineArgs();
|
||||
foreach (string text2 in commandLineArgs)
|
||||
{
|
||||
if (!text2.ToLower().StartsWith("/n"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
string text3 = text2.Substring(2).ToLower();
|
||||
if (!text3.Contains("discovery"))
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (text3.Contains("local"))
|
||||
{
|
||||
LoggingIdentity = "aaDiscoveryLocal";
|
||||
}
|
||||
else if (text3.Contains("global"))
|
||||
{
|
||||
if (text3.Contains("primary"))
|
||||
{
|
||||
LoggingIdentity = "aaDiscoveryPrimaryGlobal";
|
||||
}
|
||||
else if (text3.Contains("secondary"))
|
||||
{
|
||||
LoggingIdentity = "aaDiscoverySecondaryGlobal";
|
||||
}
|
||||
}
|
||||
else if (text3.Contains("universal"))
|
||||
{
|
||||
if (text3.Contains("primary"))
|
||||
{
|
||||
LoggingIdentity = "aaDiscoveryPrimaryUniversal";
|
||||
}
|
||||
else if (text3.Contains("secondary"))
|
||||
{
|
||||
LoggingIdentity = "aaDiscoverySecondaryUniversal";
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
Logger.LogSetIdentityName(LoggingIdentity);
|
||||
InitializeAdvanceLog();
|
||||
IsCsvLogType = false;
|
||||
SetLogCategory(logCategory);
|
||||
}
|
||||
|
||||
public aaLoggerListner(string LogCategory, string LogIdentityName)
|
||||
{
|
||||
LoggingIdentity = LogIdentityName;
|
||||
Logger.LogSetIdentityName(LoggingIdentity);
|
||||
InitializeAdvanceLog();
|
||||
IsCsvLogType = false;
|
||||
SetLogCategory(LogCategory);
|
||||
}
|
||||
|
||||
private void InitializeAdvanceLog()
|
||||
{
|
||||
if (!Directory.Exists(asbLogFolder))
|
||||
{
|
||||
Directory.CreateDirectory(asbLogFolder);
|
||||
}
|
||||
asbLogFile = asbLogFolder + Environment.MachineName + "_" + LoggingIdentity + ".log";
|
||||
}
|
||||
|
||||
private void SetLogCategory(string LogCategory)
|
||||
{
|
||||
aaLogType loggerType = aaLogType.LogTraceType;
|
||||
try
|
||||
{
|
||||
loggerType = (aaLogType)Enum.Parse(typeof(aaLogType), LogCategory);
|
||||
IsCustomLogType = false;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
if (string.Compare(LogCategory, CSVLOGFLAG, ignoreCase: true) == 0)
|
||||
{
|
||||
IsCsvLogType = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
CustomLogTypeCookie = Logger.LogRegisterCustomFlag(LogCategory);
|
||||
}
|
||||
IsCustomLogType = true;
|
||||
}
|
||||
LoggerType = loggerType;
|
||||
}
|
||||
|
||||
private void SetSourceLevel(string level)
|
||||
{
|
||||
SourceLevels sourceLevels = SourceLevels.All;
|
||||
try
|
||||
{
|
||||
sourceLevels = (SourceLevels)Enum.Parse(typeof(SourceLevels), level);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
sourceLevels = SourceLevels.All;
|
||||
}
|
||||
sourceLevel = sourceLevels;
|
||||
}
|
||||
|
||||
public override void Write(string message)
|
||||
{
|
||||
LogIt(message, TraceEventType.Verbose);
|
||||
}
|
||||
|
||||
public override void WriteLine(string message)
|
||||
{
|
||||
LogIt(message, TraceEventType.Verbose);
|
||||
}
|
||||
|
||||
public override void WriteLine(string message, string category)
|
||||
{
|
||||
LogIt(message, TraceEventType.Verbose);
|
||||
}
|
||||
|
||||
public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message)
|
||||
{
|
||||
LogAdvancedFile(eventCache, source, eventType, message);
|
||||
LogIt(message, eventType);
|
||||
}
|
||||
|
||||
public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, params object[] args)
|
||||
{
|
||||
if (IsCsvLogType)
|
||||
{
|
||||
LogCsvFile(eventCache, source, eventType, id, format, args);
|
||||
return;
|
||||
}
|
||||
string message = string.Format(CultureInfo.CurrentCulture, format, args);
|
||||
LogAdvancedFile(eventCache, source, eventType, message);
|
||||
LogIt(message, eventType);
|
||||
}
|
||||
|
||||
private void LogIt(string message, TraceEventType eventType)
|
||||
{
|
||||
aaLogType aaLogType2 = LoggerType;
|
||||
switch (eventType)
|
||||
{
|
||||
case TraceEventType.Warning:
|
||||
aaLogType2 = aaLogType.LogWarningType;
|
||||
break;
|
||||
case TraceEventType.Error:
|
||||
aaLogType2 = aaLogType.LogErrorType;
|
||||
break;
|
||||
case TraceEventType.Critical:
|
||||
aaLogType2 = aaLogType.LogErrorType;
|
||||
break;
|
||||
}
|
||||
if (!IsCustomLogType)
|
||||
{
|
||||
switch (aaLogType2)
|
||||
{
|
||||
case aaLogType.LogErrorType:
|
||||
Logger.LogError(message);
|
||||
break;
|
||||
case aaLogType.LogWarningType:
|
||||
Logger.LogWarning(message);
|
||||
break;
|
||||
case aaLogType.LogInfoType:
|
||||
Logger.LogInfo(message);
|
||||
break;
|
||||
case aaLogType.LogTraceType:
|
||||
Logger.LogTrace(message);
|
||||
break;
|
||||
case aaLogType.LogStartStopType:
|
||||
Logger.LogStartStop(message);
|
||||
break;
|
||||
case aaLogType.LogThreadStartStopType:
|
||||
Logger.LogThreadStartStop(message);
|
||||
break;
|
||||
case aaLogType.LogConnectionType:
|
||||
Logger.LogConnection(message);
|
||||
break;
|
||||
case aaLogType.LogRefCountType:
|
||||
Logger.LogRefCount(message);
|
||||
break;
|
||||
case aaLogType.LogCtorDtorType:
|
||||
Logger.LogCtorDtor(message);
|
||||
break;
|
||||
case aaLogType.LogSQLType:
|
||||
Logger.LogSQL(message);
|
||||
break;
|
||||
case aaLogType.LogEntryExitType:
|
||||
Logger.LogEntryExit(message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (aaLogType2)
|
||||
{
|
||||
case aaLogType.LogErrorType:
|
||||
Logger.LogError(message);
|
||||
break;
|
||||
case aaLogType.LogWarningType:
|
||||
Logger.LogWarning(message);
|
||||
break;
|
||||
default:
|
||||
Logger.LogCustom(CustomLogTypeCookie, message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LogCsvFile(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, params object[] args)
|
||||
{
|
||||
string text = eventCache.DateTime.ToString("M/d/yyyy HH:mm:ss.fff") + "," + Environment.MachineName + "," + LoggingIdentity + "," + eventType.ToString() + "," + id + "," + eventCache.ProcessId + "," + eventCache.ThreadId.ToString() + "," + format;
|
||||
foreach (object obj in args)
|
||||
{
|
||||
text = text + "," + obj.ToString();
|
||||
}
|
||||
string text2 = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\ArchestrA\\LogFiles\\";
|
||||
if (!Directory.Exists(text2))
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
lock (LogLockObject)
|
||||
{
|
||||
using StreamWriter streamWriter = File.AppendText(text2 + Environment.MachineName + "_" + LoggingIdentity + "_" + eventCache.ProcessId + ".csv");
|
||||
streamWriter.WriteLine(text);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void LogAdvancedFile(TraceEventCache eventCache, string source, TraceEventType eventType, string message)
|
||||
{
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class AspChildControlTypeAttribute : Attribute
|
||||
{
|
||||
public string TagName { get; private set; }
|
||||
|
||||
public Type ControlType { get; private set; }
|
||||
|
||||
public AspChildControlTypeAttribute(string tagName, Type controlType)
|
||||
{
|
||||
TagName = tagName;
|
||||
ControlType = controlType;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class AspDataFieldAttribute : Attribute
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class AspDataFieldsAttribute : Attribute
|
||||
{
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class AspMethodPropertyAttribute : Attribute
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Parameter)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class AspMvcActionAttribute : Attribute
|
||||
{
|
||||
public string AnonymousProperty { get; private set; }
|
||||
|
||||
public AspMvcActionAttribute()
|
||||
{
|
||||
}
|
||||
|
||||
public AspMvcActionAttribute(string anonymousProperty)
|
||||
{
|
||||
AnonymousProperty = anonymousProperty;
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Parameter)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class AspMvcActionSelectorAttribute : Attribute
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Parameter)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class AspMvcAreaAttribute : Attribute
|
||||
{
|
||||
public string AnonymousProperty { get; private set; }
|
||||
|
||||
public AspMvcAreaAttribute()
|
||||
{
|
||||
}
|
||||
|
||||
public AspMvcAreaAttribute(string anonymousProperty)
|
||||
{
|
||||
AnonymousProperty = anonymousProperty;
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class AspMvcAreaMasterLocationFormatAttribute : Attribute
|
||||
{
|
||||
public string Format { get; private set; }
|
||||
|
||||
public AspMvcAreaMasterLocationFormatAttribute(string format)
|
||||
{
|
||||
Format = format;
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class AspMvcAreaPartialViewLocationFormatAttribute : Attribute
|
||||
{
|
||||
public string Format { get; private set; }
|
||||
|
||||
public AspMvcAreaPartialViewLocationFormatAttribute(string format)
|
||||
{
|
||||
Format = format;
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class AspMvcAreaViewLocationFormatAttribute : Attribute
|
||||
{
|
||||
public string Format { get; private set; }
|
||||
|
||||
public AspMvcAreaViewLocationFormatAttribute(string format)
|
||||
{
|
||||
Format = format;
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Parameter)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class AspMvcControllerAttribute : Attribute
|
||||
{
|
||||
public string AnonymousProperty { get; private set; }
|
||||
|
||||
public AspMvcControllerAttribute()
|
||||
{
|
||||
}
|
||||
|
||||
public AspMvcControllerAttribute(string anonymousProperty)
|
||||
{
|
||||
AnonymousProperty = anonymousProperty;
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Parameter)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class AspMvcDisplayTemplateAttribute : Attribute
|
||||
{
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Parameter)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class AspMvcEditorTemplateAttribute : Attribute
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Parameter)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class AspMvcMasterAttribute : Attribute
|
||||
{
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class AspMvcMasterLocationFormatAttribute : Attribute
|
||||
{
|
||||
public string Format { get; private set; }
|
||||
|
||||
public AspMvcMasterLocationFormatAttribute(string format)
|
||||
{
|
||||
Format = format;
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Parameter)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class AspMvcModelTypeAttribute : Attribute
|
||||
{
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Parameter)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class AspMvcPartialViewAttribute : Attribute
|
||||
{
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class AspMvcPartialViewLocationFormatAttribute : Attribute
|
||||
{
|
||||
public string Format { get; private set; }
|
||||
|
||||
public AspMvcPartialViewLocationFormatAttribute(string format)
|
||||
{
|
||||
Format = format;
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class AspMvcSuppressViewErrorAttribute : Attribute
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Parameter)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class AspMvcTemplateAttribute : Attribute
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Parameter)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class AspMvcViewAttribute : Attribute
|
||||
{
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Parameter)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class AspMvcViewComponentAttribute : Attribute
|
||||
{
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Parameter)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class AspMvcViewComponentViewAttribute : Attribute
|
||||
{
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class AspMvcViewLocationFormatAttribute : Attribute
|
||||
{
|
||||
public string Format { get; private set; }
|
||||
|
||||
public AspMvcViewLocationFormatAttribute(string format)
|
||||
{
|
||||
Format = format;
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class AspRequiredAttributeAttribute : Attribute
|
||||
{
|
||||
public string Attribute { get; private set; }
|
||||
|
||||
public AspRequiredAttributeAttribute(string attribute)
|
||||
{
|
||||
Attribute = attribute;
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class AspTypePropertyAttribute : Attribute
|
||||
{
|
||||
public bool CreateConstructorReferences { get; private set; }
|
||||
|
||||
public AspTypePropertyAttribute(bool createConstructorReferences)
|
||||
{
|
||||
CreateConstructorReferences = createConstructorReferences;
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Parameter)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class AssertionConditionAttribute : Attribute
|
||||
{
|
||||
public AssertionConditionType ConditionType { get; private set; }
|
||||
|
||||
public AssertionConditionAttribute(AssertionConditionType conditionType)
|
||||
{
|
||||
ConditionType = conditionType;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
internal enum AssertionConditionType
|
||||
{
|
||||
IS_TRUE,
|
||||
IS_FALSE,
|
||||
IS_NULL,
|
||||
IS_NOT_NULL
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class AssertionMethodAttribute : Attribute
|
||||
{
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class BaseTypeRequiredAttribute : Attribute
|
||||
{
|
||||
public Type BaseType { get; private set; }
|
||||
|
||||
public BaseTypeRequiredAttribute(Type baseType)
|
||||
{
|
||||
BaseType = baseType;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Parameter | AttributeTargets.Delegate | AttributeTargets.GenericParameter)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class CanBeNullAttribute : Attribute
|
||||
{
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class CannotApplyEqualityOperatorAttribute : Attribute
|
||||
{
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class CollectionAccessAttribute : Attribute
|
||||
{
|
||||
public CollectionAccessType CollectionAccessType { get; private set; }
|
||||
|
||||
public CollectionAccessAttribute(CollectionAccessType collectionAccessType)
|
||||
{
|
||||
CollectionAccessType = collectionAccessType;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[Flags]
|
||||
internal enum CollectionAccessType
|
||||
{
|
||||
None = 0,
|
||||
Read = 1,
|
||||
ModifyExistingContent = 2,
|
||||
UpdatedContent = 6
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class ContractAnnotationAttribute : Attribute
|
||||
{
|
||||
public string Contract { get; private set; }
|
||||
|
||||
public bool ForceFullStates { get; private set; }
|
||||
|
||||
public ContractAnnotationAttribute(string contract)
|
||||
: this(contract, forceFullStates: false)
|
||||
{
|
||||
}
|
||||
|
||||
public ContractAnnotationAttribute(string contract, bool forceFullStates)
|
||||
{
|
||||
Contract = contract;
|
||||
ForceFullStates = forceFullStates;
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class HtmlAttributeValueAttribute : Attribute
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
|
||||
public HtmlAttributeValueAttribute(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class HtmlElementAttributesAttribute : Attribute
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
|
||||
public HtmlElementAttributesAttribute()
|
||||
{
|
||||
}
|
||||
|
||||
public HtmlElementAttributesAttribute(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class ImplicitNotNullAttribute : Attribute
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[Flags]
|
||||
internal enum ImplicitUseKindFlags
|
||||
{
|
||||
Default = 7,
|
||||
Access = 1,
|
||||
Assign = 2,
|
||||
InstantiatedWithFixedConstructorSignature = 4,
|
||||
InstantiatedNoFixedConstructorSignature = 8
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[Flags]
|
||||
internal enum ImplicitUseTargetFlags
|
||||
{
|
||||
Default = 1,
|
||||
Itself = 1,
|
||||
Members = 2,
|
||||
WithMembers = 3
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Parameter)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class InstantHandleAttribute : Attribute
|
||||
{
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Parameter)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class InvokerParameterNameAttribute : Attribute
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Delegate)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class ItemCanBeNullAttribute : Attribute
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Delegate)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class ItemNotNullAttribute : Attribute
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class LinqTunnelAttribute : Attribute
|
||||
{
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.All)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class LocalizationRequiredAttribute : Attribute
|
||||
{
|
||||
public bool Required { get; private set; }
|
||||
|
||||
public LocalizationRequiredAttribute()
|
||||
: this(required: true)
|
||||
{
|
||||
}
|
||||
|
||||
public LocalizationRequiredAttribute(bool required)
|
||||
{
|
||||
Required = required;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Parameter, AllowMultiple = true)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class MacroAttribute : Attribute
|
||||
{
|
||||
public string Expression { get; set; }
|
||||
|
||||
public int Editable { get; set; }
|
||||
|
||||
public string Target { get; set; }
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.GenericParameter)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class MeansImplicitUseAttribute : Attribute
|
||||
{
|
||||
public ImplicitUseKindFlags UseKindFlags { get; private set; }
|
||||
|
||||
public ImplicitUseTargetFlags TargetFlags { get; private set; }
|
||||
|
||||
public MeansImplicitUseAttribute()
|
||||
: this(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Default)
|
||||
{
|
||||
}
|
||||
|
||||
public MeansImplicitUseAttribute(ImplicitUseKindFlags useKindFlags)
|
||||
: this(useKindFlags, ImplicitUseTargetFlags.Default)
|
||||
{
|
||||
}
|
||||
|
||||
public MeansImplicitUseAttribute(ImplicitUseTargetFlags targetFlags)
|
||||
: this(ImplicitUseKindFlags.Default, targetFlags)
|
||||
{
|
||||
}
|
||||
|
||||
public MeansImplicitUseAttribute(ImplicitUseKindFlags useKindFlags, ImplicitUseTargetFlags targetFlags)
|
||||
{
|
||||
UseKindFlags = useKindFlags;
|
||||
TargetFlags = targetFlags;
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class MustUseReturnValueAttribute : Attribute
|
||||
{
|
||||
public string Justification { get; private set; }
|
||||
|
||||
public MustUseReturnValueAttribute()
|
||||
{
|
||||
}
|
||||
|
||||
public MustUseReturnValueAttribute(string justification)
|
||||
{
|
||||
Justification = justification;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Parameter)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class NoEnumerationAttribute : Attribute
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.All)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class NoReorder : Attribute
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Parameter | AttributeTargets.Delegate | AttributeTargets.GenericParameter)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class NotNullAttribute : Attribute
|
||||
{
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class NotifyPropertyChangedInvocatorAttribute : Attribute
|
||||
{
|
||||
public string ParameterName { get; private set; }
|
||||
|
||||
public NotifyPropertyChangedInvocatorAttribute()
|
||||
{
|
||||
}
|
||||
|
||||
public NotifyPropertyChangedInvocatorAttribute(string parameterName)
|
||||
{
|
||||
ParameterName = parameterName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Parameter)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class PathReferenceAttribute : Attribute
|
||||
{
|
||||
public string BasePath { get; private set; }
|
||||
|
||||
public PathReferenceAttribute()
|
||||
{
|
||||
}
|
||||
|
||||
public PathReferenceAttribute(string basePath)
|
||||
{
|
||||
BasePath = basePath;
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Interface | AttributeTargets.Parameter | AttributeTargets.GenericParameter)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class ProvidesContextAttribute : Attribute
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class PublicAPIAttribute : Attribute
|
||||
{
|
||||
public string Comment { get; private set; }
|
||||
|
||||
public PublicAPIAttribute()
|
||||
{
|
||||
}
|
||||
|
||||
public PublicAPIAttribute(string comment)
|
||||
{
|
||||
Comment = comment;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class PureAttribute : Attribute
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class RazorDirectiveAttribute : Attribute
|
||||
{
|
||||
public string Directive { get; private set; }
|
||||
|
||||
public RazorDirectiveAttribute(string directive)
|
||||
{
|
||||
Directive = directive;
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class RazorHelperCommonAttribute : Attribute
|
||||
{
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class RazorImportNamespaceAttribute : Attribute
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
|
||||
public RazorImportNamespaceAttribute(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class RazorInjectionAttribute : Attribute
|
||||
{
|
||||
public string Type { get; private set; }
|
||||
|
||||
public string FieldName { get; private set; }
|
||||
|
||||
public RazorInjectionAttribute(string type, string fieldName)
|
||||
{
|
||||
Type = type;
|
||||
FieldName = fieldName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class RazorLayoutAttribute : Attribute
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Parameter)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class RazorSectionAttribute : Attribute
|
||||
{
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class RazorWriteLiteralMethodAttribute : Attribute
|
||||
{
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
[Conditional("JETBRAINS_ANNOTATIONS")]
|
||||
internal sealed class RazorWriteMethodAttribute : Attribute
|
||||
{
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user