public EnvironmentHelper( string testApplicationName, Type anchorType, ITestOutputHelper output, string testApplicationDirectory = null, bool prependTestApplicationToAppName = true, bool requiresProfiling = true) { TestApplicationName = testApplicationName; _testApplicationDirectory = testApplicationDirectory ?? Path.Combine("test", "test-applications", "integrations"); _targetFramework = Assembly.GetAssembly(anchorType).GetCustomAttribute <TargetFrameworkAttribute>(); _output = output; _requiresProfiling = requiresProfiling; var parts = _targetFramework.FrameworkName.Split(','); _runtime = parts[0]; _isCoreClr = _runtime.Equals(EnvironmentTools.CoreFramework); var versionParts = parts[1].Replace("Version=v", string.Empty).Split('.'); _major = int.Parse(versionParts[0]); _minor = int.Parse(versionParts[1]); if (versionParts.Length == 3) { _patch = versionParts[2]; } _appNamePrepend = prependTestApplicationToAppName ? "TestApplication." : string.Empty; }
public EnvironmentHelper( string sampleName, Type anchorType, ITestOutputHelper output, string samplesDirectory = "samples", string disabledIntegrations = null) { SampleName = sampleName; _samplesDirectory = samplesDirectory ?? "samples"; _disabledIntegrations = disabledIntegrations; _anchorType = anchorType; _anchorAssembly = Assembly.GetAssembly(_anchorType); _targetFramework = _anchorAssembly.GetCustomAttribute <TargetFrameworkAttribute>(); _output = output; var parts = _targetFramework.FrameworkName.Split(','); _runtime = parts[0]; _isCoreClr = _runtime.Equals(CoreFramework); var versionParts = parts[1].Replace("Version=v", string.Empty).Split('.'); _major = int.Parse(versionParts[0]); _minor = int.Parse(versionParts[1]); if (versionParts.Length == 3) { _patch = versionParts[2]; } }
internal static FrameworkType GetFrameworkType(bool printToConsole = false) { string NetCoreIdentifyingString = ".NETCoreApp"; string NetFrameworkIdentifyingString = ".NETFramework"; StackTrace currenStackTrace = new StackTrace(); foreach (StackFrame stackFrame in currenStackTrace.GetFrames()) { Assembly fromAssembly = stackFrame.GetMethod().DeclaringType.Assembly; TargetFrameworkAttribute frameworkAttribute = fromAssembly.GetCustomAttributes(typeof(TargetFrameworkAttribute)).FirstOrDefault() as TargetFrameworkAttribute; if (frameworkAttribute != null && frameworkAttribute.FrameworkName != null) { if (printToConsole) { Console.WriteLine($"{fromAssembly.FullName} : {frameworkAttribute?.FrameworkName}"); } if (frameworkAttribute.FrameworkName.Contains(NetCoreIdentifyingString)) { return(FrameworkType.NetCore); } else if (frameworkAttribute.FrameworkName.Contains(NetFrameworkIdentifyingString)) { return(FrameworkType.NetFramework); } } } return(FrameworkType.Unknown); }
/// <summary> /// Parses the .NET version from the given attribute name. /// </summary> /// <param name="targetFramework"></param> /// <returns></returns> private Version ParseVersion(TargetFrameworkAttribute targetFramework) { var name = targetFramework?.FrameworkName; if (name == null) { return(null); } const string pattern = "Version=v"; int idx = name.IndexOf(pattern); if (idx == -1) { return(null); } idx += pattern.Length; var versionString = name.Substring(idx); Version version; if (!System.Version.TryParse(versionString, out version)) { return(null); } return(version); }
internal static string GetRuntime() { try { Assembly asm = Assembly .GetEntryAssembly(); if (asm == null) { return("not-specified"); } TargetFrameworkAttribute att = asm .GetCustomAttribute <TargetFrameworkAttribute>(); if (att == null) { return("not-specified"); } return(att.FrameworkName); } catch { return("unknown"); } }
/////////////////////////////////////////////////////////////////////// public static string GetAssemblyTargetFramework( Assembly assembly ) { if (assembly != null) { #if NET_40 try { if (assembly.IsDefined( typeof(TargetFrameworkAttribute), false)) { TargetFrameworkAttribute targetFramework = (TargetFrameworkAttribute) assembly.GetCustomAttributes( typeof(TargetFrameworkAttribute), false)[0]; return(targetFramework.FrameworkName); } } catch { // do nothing. } #elif NET_35 return(".NETFramework,Version=v3.5"); #elif NET_20 return(".NETFramework,Version=v2.0"); #endif } return(null); }
public EnvironmentHelper( string sampleName, Type anchorType, ITestOutputHelper output, string samplesDirectory = "test/test-applications/integrations", bool prependSamplesToAppName = true, bool requiresProfiling = true) { SampleName = sampleName; _samplesDirectory = samplesDirectory ?? "test/test-applications/integrations"; _anchorType = anchorType; _anchorAssembly = Assembly.GetAssembly(_anchorType); _targetFramework = Assembly.GetAssembly(anchorType).GetCustomAttribute <TargetFrameworkAttribute>(); _output = output; _requiresProfiling = requiresProfiling; var parts = _targetFramework.FrameworkName.Split(','); _runtime = parts[0]; _isCoreClr = _runtime.Equals(EnvironmentTools.CoreFramework); var versionParts = parts[1].Replace("Version=v", string.Empty).Split('.'); _major = int.Parse(versionParts[0]); _minor = int.Parse(versionParts[1]); if (versionParts.Length == 3) { _patch = versionParts[2]; } _appNamePrepend = prependSamplesToAppName ? "Samples." : string.Empty; }
/// <summary>Gets the framework attributes.</summary> /// <param name="assembly">The assembly.</param> /// <returns>The <see cref="object"/>.</returns> public static TargetFrameworkAttribute GetFrameworkAttributes(Assembly assembly) { var list = GetAllAttributes(assembly); TargetFrameworkAttribute attribute = list.OfType <TargetFrameworkAttribute>().First(); return(attribute); }
public void UnitV_FrameworkProfile() { // Check for least common denominator full framework: Assembly view = Assembly.GetAssembly(typeof(KaosDiags.Diags)); TargetFrameworkAttribute vFramework = view.GetCustomAttributes(false).OfType <TargetFrameworkAttribute>().Single(); Assert.AreEqual(".NETFramework,Version=v4.0", vFramework.FrameworkName); }
/// <summary> /// Gets an instance of the currently executed runtime version. /// </summary> /// <param name="runtime">The current runtime version.</param> /// <returns>True if the runtime version could be retrieved.</returns> public static Boolean TryGetCurrentRuntime(out RuntimeInfo runtime) { runtime = null; Assembly entryAsm = Assembly.GetEntryAssembly(); TargetFrameworkAttribute attr = entryAsm.GetCustomAttribute <TargetFrameworkAttribute>(); return(attr != null && TryParseFullName(attr.FrameworkName, out runtime) && runtime.Framework != FrameworkIdentifiers.Unsupported); }
private static void DisplayFrameworkName() { TargetFrameworkAttribute targetFrameworkAttribute = (TargetFrameworkAttribute)Assembly.GetExecutingAssembly() .GetCustomAttributes(typeof(System.Runtime.Versioning.TargetFrameworkAttribute), false) .SingleOrDefault(); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Target Framework: {0}", targetFrameworkAttribute.FrameworkName); Console.ResetColor(); }
public static IReflectionAttributeInfo TargetFrameworkAttribute(string frameworkName) { var attribute = new TargetFrameworkAttribute(frameworkName); var result = Substitute.For <IReflectionAttributeInfo, InterfaceProxy <IReflectionAttributeInfo> >(); result.Attribute.Returns(attribute); result.GetConstructorArguments().Returns(new object[] { frameworkName }); return(result); }
/// <summary> /// Initialize a new instance of the <see cref="T:iTin.Core.Drawing.Clipping" /> class. /// </summary> /// <param name="frameworkAttribute">Framework compiled information</param> internal FrameworkVersion(TargetFrameworkAttribute frameworkAttribute) { var items = frameworkAttribute.FrameworkName.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); VersionName = items[0]; var frameworkVersionItems = items[1].Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries); VersionNumber = frameworkVersionItems[1].Replace("v", string.Empty); }
public string Graduate(string fileName, string projectName, string projectPath) { try { Assembly assembly = Assembly.LoadFrom(MainWindow.InstallDir + "\\SmallBasicCompiler.exe"); Type CompilerType = assembly.GetType("Microsoft.SmallBasic.Compiler"); List <string> errors = new List <string>(); string source = File.ReadAllText(fileName); var Compiler = CompileVB.Invoke(null, new object[] { source, errors }); if (errors.Count > 0) { MainWindow.Errors.Add(new Error("Graduate : Compilation errors")); for (int i = 0; i < errors.Count; i++) { MainWindow.Errors.Add(new Error("Graduate : " + errors[i])); } return(""); } Type VisualBasicExporterType = assembly.GetType("Microsoft.SmallBasic.VisualBasicExporter"); ConstructorInfo ctor = VisualBasicExporterType.GetConstructor(new Type[] { CompilerType }); var VisualBasicExporter = ctor.Invoke(new object[] { Compiler }); MethodInfo ExportToVisualBasicProject = VisualBasicExporterType.GetMethod("ExportToVisualBasicProject"); string result = (string)ExportToVisualBasicProject.Invoke(VisualBasicExporter, new object[] { projectName, projectPath }); // vbproj bugs string runtime; try { string sblPath = MainWindow.InstallDir + "\\SmallBasicLibrary.dll"; Assembly sblAssembly = Assembly.LoadFile(sblPath); TargetFrameworkAttribute attrib = (TargetFrameworkAttribute)sblAssembly.GetCustomAttribute(typeof(TargetFrameworkAttribute)); runtime = attrib.FrameworkName.Substring(attrib.FrameworkName.Length - 4); } catch { runtime = "v4.5"; } string vbproj = File.ReadAllText(result); vbproj = vbproj.Replace("<HintPath>$(programfiles)\\ (x86)\\Microsoft\\Small Basic\\SmallBasicLibrary.dll</HintPath>", "<HintPath>$(programfiles)\\Microsoft\\Small Basic\\SmallBasicLibrary.dll</HintPath>"); vbproj = vbproj.Replace("<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>", "<TargetFrameworkVersion>" + runtime + "</TargetFrameworkVersion>"); //vcproj = vcproj.Replace("<Project ToolsVersion=\"3.5\" DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">", "<Project ToolsVersion=\"15.0\" DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">"); File.WriteAllText(result, vbproj); return(result); } catch (Exception ex) { MainWindow.Errors.Add(new Error("Graduate : " + ex.Message)); return(""); } }
public DownloadUpdateDialog(string downloadURL, string targetFolder, TargetFrameworkAttribute currentFrameworkAttribute, TaskCompletionSource <bool> taskCompletionSource) { InitializeComponent(); _downloadURL = downloadURL; _targetFolder = targetFolder; _currentFrameworkAttribute = currentFrameworkAttribute; _taskCompletionSource = taskCompletionSource; _tempFile = Path.Combine(Path.GetTempPath(), "Analogy.Updater.zip"); Icon = UserSettingsManager.UserSettings.GetIcon(); }
public void FrameworkDisplayName() { TargetFrameworkAttribute tfa; tfa = new TargetFrameworkAttribute(String.Empty); tfa.FrameworkDisplayName = null; Assert.AreEqual(null, tfa.FrameworkDisplayName, "#A1"); tfa.FrameworkDisplayName = "test"; Assert.AreEqual("test", tfa.FrameworkDisplayName, "#A2"); }
public static string GetTargetFrameworkMoniker() { TargetFrameworkAttribute targetFrameworkAttribute = typeof(BundledTargetFramework) .GetTypeInfo() .Assembly .GetCustomAttribute <TargetFrameworkAttribute>(); return(NuGetFramework .Parse(targetFrameworkAttribute.FrameworkName) .GetShortFolderName()); }
/// <summary> /// Folder can to be the ClickOnce application. /// </summary> /// <param name="fullPath">Folder path.</param> /// <param name="errorString">Error text.</param> /// <returns>Is it possible.</returns> public static bool IsFolderCanBeClickOnceApplication(string fullPath, out string errorString) { errorString = null; /* * Requirements: * 1. Inside folder exists any executable file which one target is v4.0. (EntryPoint) * 2. (?) Every dll should be managed (?) */ foreach ( var executableFilePath in Directory.GetFiles(fullPath, $"*.{Constants.ExecutableFileExtension}")) { Assembly assembly; try { assembly = Assembly.LoadFile(executableFilePath); } catch (NotSupportedException) { // Its happens when you downloaded executable assembly from Internet and Windows marked it as unknown. // Solution is go to [File property] -> [Unblock] or [Check Unblock and press Apply] errorString = $"Assembly {executableFilePath} was downloaded from Internet and have lock mark by Windows. Just go to [File property] -> [Unblock] or [Check Unblock and press Apply]"; continue; } catch (BadImageFormatException) { // $"* continue; } var q = assembly.ImageRuntimeVersion; TargetFrameworkAttribute targetFrameworkAttribute = (TargetFrameworkAttribute) assembly.GetCustomAttributes(typeof(TargetFrameworkAttribute), false).FirstOrDefault(); // TargetFrameworkAttribute framework v4.0 only if (targetFrameworkAttribute != null) { return(true); } } return(false); }
public void Constructor_String() { TargetFrameworkAttribute tfa; Throws <ArgumentNullException> ("#A1-1", () => { tfa = new TargetFrameworkAttribute(null); }); tfa = new TargetFrameworkAttribute(String.Empty); Assert.AreEqual(String.Empty, tfa.FrameworkName, "#A2-1"); Assert.AreEqual(null, tfa.FrameworkDisplayName, "#A2-2"); tfa = new TargetFrameworkAttribute("identifier,Version=2"); Assert.AreEqual("identifier,Version=2", tfa.FrameworkName, "#A3-1"); Assert.AreEqual(null, tfa.FrameworkDisplayName, "#A3-2"); }
/// <summary> /// Gets the target runtime of a loaded <see cref="Assembly"/>. /// </summary> /// <param name="assembly">The loaded assembly.</param> /// <param name="runtime">The target runtime of <paramref name="assembly"/>.</param> /// <returns>True if the target runtime could be retrieved.</returns> public static Boolean TryGetRuntime(Assembly assembly, out RuntimeInfo runtime) { runtime = null; if (assembly != null) { TargetFrameworkAttribute attr = assembly.GetCustomAttribute <TargetFrameworkAttribute>(); if (attr != null) { RuntimesHelper.TryParseFullName(attr.FrameworkName, out runtime); } } return(runtime != null && runtime.Framework != FrameworkIdentifiers.Unsupported && runtime.Version != new Version()); }
public DownloadUpdater(string downloadUrl, string targetFolder, Action <string>?reportDownloadSpeed, Action <string>?reportDownloadProgress, Action <int>?reportDownloadProgressValue, TargetFrameworkAttribute currentFrameworkAttribute, TaskCompletionSource <bool> taskCompletionSource) { _downloadURL = downloadUrl; _targetFolder = targetFolder; _currentFrameworkAttribute = currentFrameworkAttribute; _taskCompletionSource = taskCompletionSource; ReportDownloadProgressValue = reportDownloadProgressValue; ReportDownloadSpeed = reportDownloadSpeed; ReportDownloadProgress = reportDownloadProgress; _tempFile = Path.Combine(Path.GetTempPath(), "Github.Updater.zip"); if (!Directory.Exists(_targetFolder)) { Directory.CreateDirectory(_targetFolder); } }
private static string GetAssemblyTargetFramework(Assembly assembly) { if (assembly != null) { try { if (assembly.IsDefined(typeof(TargetFrameworkAttribute), false)) { TargetFrameworkAttribute targetFrameworkAttribute = (TargetFrameworkAttribute)assembly.GetCustomAttributes(typeof(TargetFrameworkAttribute), false)[0]; return(targetFrameworkAttribute.FrameworkName); } } catch { } } return(null); }
static int Main(string[] args) { string myName = "VerifyNetFrameworkVersion"; string assemblyDir; if (args.Length < 1) { assemblyDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); Console.Error.WriteLine($"{myName}: no directory passed, using current directory: '{assemblyDir}'"); } else { assemblyDir = args[0]; } if (!Directory.Exists(assemblyDir)) { Console.Error.WriteLine($"{myName}: directory does not exist: {assemblyDir}"); return(1); } string[] dlls = Directory.GetFiles(assemblyDir, "*.dll"); if (dlls.Length < 1) { Console.Error.WriteLine($"{myName}: no dlls found in {assemblyDir}"); return(1); } Console.WriteLine($"{myName} analyzing assemblies:"); foreach (var dll in dlls) { Assembly assembly = Assembly.LoadFrom(dll); string frameworkName = "NA"; string frameworkDisplayName = "NA"; #if NET462 TargetFrameworkAttribute targetFWA = assembly.GetCustomAttribute <TargetFrameworkAttribute>(); frameworkName = targetFWA.FrameworkName; frameworkDisplayName = targetFWA.FrameworkDisplayName; #endif Console.WriteLine($"* {Path.GetFileName(dll)}, ImageRuntimeVersion:{assembly.ImageRuntimeVersion}, FrameworkName:{frameworkName}, FrameworkDisplayName:{frameworkDisplayName}"); } return(0); }
private static string GetPlatformVersion() { #if NET45 var version = ""; version = AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName; // in unit testing scenarios, GetEntryAssembly returns null so make sure we aren't blowing up if this isn't available if (version == null && Assembly.GetEntryAssembly() != null) { TargetFrameworkAttribute tfa = (TargetFrameworkAttribute)Assembly.GetEntryAssembly().GetCustomAttributes(typeof(TargetFrameworkAttribute)) .SingleOrDefault(); if (tfa != null) { version = tfa.FrameworkName; } } return(version); #elif NETSTANDARD2_0 return(Assembly.GetEntryAssembly()?.GetCustomAttribute <TargetFrameworkAttribute>()?.FrameworkName); #else return("Unknown Framework Version"); #endif }
public EnvironmentHelper( string sampleName, Type anchorType, ITestOutputHelper output, string samplesDirectory = null, bool prependSamplesToAppName = true) { SampleName = sampleName; _samplesDirectory = samplesDirectory ?? Path.Combine("test", "test-applications", "integrations"); _targetFramework = Assembly.GetAssembly(anchorType).GetCustomAttribute <TargetFrameworkAttribute>(); _output = output; TracerHome = GetTracerHomePath(); // The Tracer is not currently utilizing the Native Loader in production. It is only being used in the Continuous Profiler beta. // Because of that, we don't test it in the default pipeline. bool useNativeLoader = string.Equals("true", Environment.GetEnvironmentVariable("USE_NATIVE_LOADER"), StringComparison.InvariantCultureIgnoreCase); ProfilerPath = useNativeLoader ? GetNativeLoaderPath() : GetTracerNativeDLLPath(); var parts = _targetFramework.FrameworkName.Split(','); _runtime = parts[0]; _isCoreClr = _runtime.Equals(EnvironmentTools.CoreFramework); var versionParts = parts[1].Replace("Version=v", string.Empty).Split('.'); _major = int.Parse(versionParts[0]); _minor = int.Parse(versionParts[1]); if (versionParts.Length == 3) { _patch = versionParts[2]; } _appNamePrepend = prependSamplesToAppName ? "Samples." : string.Empty; }
static void Main(string[] args) { TargetFrameworkAttribute targetFw = (TargetFrameworkAttribute)Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(System.Runtime.Versioning.TargetFrameworkAttribute), false)[0]; Console.WriteLine($"Baked in target for this binary: {targetFw.FrameworkName}"); Console.WriteLine($"ServicePointManager.SecurityProtocol returned: {ServicePointManager.SecurityProtocol}"); HttpClient c = new HttpClient(); HttpResponseMessage res = new HttpResponseMessage(); try { res = c.GetAsync("https://pages.github.io").Result; Console.WriteLine("\nResponse:\n"); Console.WriteLine(res.Headers.ToString()); } catch (Exception ex) { WriteException(ex.InnerException.InnerException.Message); } Console.ReadLine(); }
public bool Decomple(string targetProj, string source, bool bConsole) { targetProj = Environment.ExpandEnvironmentVariables(targetProj); source = Environment.ExpandEnvironmentVariables(source); string targetDirectory = Path.GetDirectoryName(targetProj); string targetName = Path.GetFileNameWithoutExtension(targetProj); bool bSuccess = false; try { using (FileStream fs = new FileStream(source, FileMode.Open, FileAccess.Read)) { WholeProjectDecompiler decompiler = new WholeProjectDecompiler(); PEFile moduleDefinition = new PEFile(source, fs, PEStreamOptions.PrefetchEntireImage); CancellationToken cancellationToken = default(CancellationToken); UniversalAssemblyResolver universalAssemblyResolver = new UniversalAssemblyResolver(source, false, moduleDefinition.Reader.DetectTargetFrameworkId(), PEStreamOptions.PrefetchEntireImage); decompiler.AssemblyResolver = universalAssemblyResolver; decompiler.DecompileProject(moduleDefinition, targetDirectory, cancellationToken); // Set runtime to SB runtime // Update case target name // Copy and rename paths for dlls string runtime; try { string sblPath = MainWindow.InstallDir + "\\SmallBasicLibrary.dll"; Assembly sblAssembly = Assembly.LoadFile(sblPath); TargetFrameworkAttribute attrib = (TargetFrameworkAttribute)sblAssembly.GetCustomAttribute(typeof(TargetFrameworkAttribute)); runtime = attrib.FrameworkName.Substring(attrib.FrameworkName.Length - 4); } catch { runtime = "v4.5"; } string result = targetDirectory + "\\" + moduleDefinition.Name + ".csproj"; XmlDocument doc = new XmlDocument(); doc.Load(result); XmlNodeList elemList = doc.GetElementsByTagName("AssemblyName"); if (elemList.Count == 1 && elemList[0].InnerText == moduleDefinition.Name) { elemList[0].InnerText = targetName; } elemList = doc.GetElementsByTagName("TargetFrameworkVersion"); if (elemList.Count == 1) { elemList[0].InnerText = runtime; } elemList = doc.GetElementsByTagName("OutputType"); if (bConsole && elemList.Count == 1 && elemList[0].InnerText == "WinExe") { elemList[0].InnerText = "Exe"; } elemList = doc.GetElementsByTagName("HintPath"); foreach (XmlNode xmlNode in elemList) { if (xmlNode.InnerText.EndsWith(".dll")) { string dll = targetDirectory + "\\" + Path.GetFileName(xmlNode.InnerText); File.Copy(xmlNode.InnerText, dll); xmlNode.InnerText = dll; } } File.Delete(result); doc.Save(targetProj); //Set Main string projectFile = targetDirectory + "\\_SmallBasicProgram.cs"; if (File.Exists(projectFile)) { string prog = File.ReadAllText(projectFile); prog = prog.Replace("static void _Main()", "static void Main()"); if (bConsole) { prog = prog.Replace("SmallBasicApplication.BeginProgram();", "SmallBasicApplication.BeginProgram();\r\n\t\t//Initialise and hide TextWindow for Console App\r\n\t\tTextWindow.Show();\r\n\t\tTextWindow.Hide();"); } File.WriteAllText(projectFile, prog); } } MainWindow.Errors.Add(new Error("Decompile : " + "Successfully decompiled assembly to " + targetProj)); bSuccess = true; } catch (Exception ex) { MainWindow.Errors.Add(new Error("Decomple : " + ex.Message)); bSuccess = false; } //Start VS or open containing folder //if (File.Exists(targetProj)) Process.Start(targetProj); //else if (Directory.Exists(targetDirectory)) Process.Start("explorer.exe", "\"" + targetDirectory + "\""); if (Directory.Exists(targetDirectory)) { Process.Start("explorer.exe", "\"" + targetDirectory + "\""); } return(bSuccess); }
public static void Configure() { // temprorary; replace with UI model. NameValueCollection appSettings = ConfigurationManager.AppSettings; string strLevel = appSettings["KpSyncLogLevel"]; if (string.IsNullOrEmpty(strLevel)) { strLevel = Enum.GetName(typeof(LogEventLevel), LogEventLevel.Debug); } LogEventLevel level; if (!Enum.TryParse(strLevel, out level)) { uint intLevel; if (uint.TryParse(strLevel, out intLevel)) { intLevel = Math.Min(intLevel, (uint)LogEventLevel.Fatal); level = (LogEventLevel)intLevel; } else { level = LogEventLevel.Debug; } } string strFilePath = appSettings["KpSyncLogFile"]; if (string.IsNullOrEmpty(strFilePath) || Path.GetInvalidPathChars() .Any(c => strFilePath.Contains(c)) || !Path.IsPathRooted(strFilePath)) { return; } try { LoggerConfiguration logConfig = new LoggerConfiguration(); logConfig = logConfig.WriteTo.File(strFilePath, rollingInterval: RollingInterval.Day, retainedFileCountLimit: 20); s_logger = logConfig.MinimumLevel.Is(level) .CreateLogger(); GoogleLogger.Register(); Assembly asm = Assembly.GetExecutingAssembly(); Info("{0} v{1} loaded by {2} v{3}.", GdsDefs.ProductName, asm.GetName().Version, PwDefs.ShortProductName, PwDefs.VersionString); TargetFrameworkAttribute attr = asm.GetCustomAttribute <TargetFrameworkAttribute>(); string tgtFw = attr == null ? "(unknown)" : attr.FrameworkDisplayName; Info("Target={0}, Current CLR=v{1}", tgtFw, Environment.Version); string releaseId = TryGetRegValueAsString( @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ReleaseId", "<unknown>"); string edition = TryGetRegValueAsString( @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductName", "Windows ??"); Info("OS Product: {0}, {1}", edition, releaseId); OperatingSystem os = Environment.OSVersion; Info("Platform ID: {0:G}, {1}, SP('{2}')", os.Platform, os.VersionString, os.ServicePack); Info("Installed .NET Framework: {0}", GetNetFrameworkVer()); } catch (Exception e) { Error(e, "Logging setup exception."); } }
public RadAboutBox1() { InitializeComponent(); string xresult, xresult_core, xresult_plugins = ""; #region [Assembly Header] // Initialize the AboutBox to display the product information from the assembly information. // Change assembly information settings for your application through either: // - Project->Properties->Application->Assembly Information // - AssemblyInfo.cs this.Text = String.Format("About {0}", AssemblyTitle); xresult = AssemblyProduct; xresult += String.Format(" Version {0}", AssemblyVersion) + "\r\n"; xresult += AssemblyCopyright + "\r\n\r\n"; //xresult += AssemblyCompany + "\r\n"; //xresult += AssemblyDescription + "\r\n\r\n"; #endregion xresult_core = "Core Versions:\r\n"; #region [SDRSharper Revised] bool?SDRSharpMain = UnmanagedDllIs64Bit(Application.ExecutablePath); if (SDRSharpMain.HasValue) { if ((bool)SDRSharpMain) { arch = "x64"; } else { arch = "x32"; } } else { arch = "Any CPU"; } Assembly attributes = MainForm.UnmanagedDLLAssemblyVer; TargetFrameworkAttribute x = (System.Runtime.Versioning.TargetFrameworkAttribute)attributes.GetCustomAttribute(typeof(TargetFrameworkAttribute)); if (x == null) { x = new TargetFrameworkAttribute("Pre-.NET Framework 4.0"); x.FrameworkDisplayName = "Pre-.NET Framework 4.0"; } xresult_core += arch + " - " + x.FrameworkDisplayName.Replace(" Framework ", " ") + " - SDRSharperR.exe\r\n"; arch = ""; #endregion #region [Radio] bool?SDRSharpRadio = UnmanagedDllIs64Bit(Application.StartupPath + "\\SDRSharp.Radio.dll"); if (SDRSharpRadio.HasValue) { if ((bool)SDRSharpRadio) { arch = "x64"; } else { arch = "x32"; } } else { arch = "Any CPU"; } attributes = Radio.Utils.UnmanagedDLLAssemblyVer; x = (System.Runtime.Versioning.TargetFrameworkAttribute)attributes.GetCustomAttribute(typeof(TargetFrameworkAttribute)); if (x == null) { x = new TargetFrameworkAttribute("Pre-.NET Framework 4.0"); x.FrameworkDisplayName = "Pre-.NET Framework 4.0"; } xresult_core += arch + " - " + x.FrameworkDisplayName.Replace(" Framework ", " ") + " - SDRSharp.Radio.dll\r\n"; arch = ""; #endregion #region [Controls] bool?SDRSharpControls = UnmanagedDllIs64Bit(Application.StartupPath + "\\SDRSharp.Controls.dll"); if (SDRSharpControls.HasValue) { if ((bool)SDRSharpControls) { arch = "x64"; } else { arch = "x32"; } } else { arch = "Any CPU"; } attributes = SDRSharp.Controls.ControlsUtils.UnmanagedDLLAssemblyVer; x = (System.Runtime.Versioning.TargetFrameworkAttribute)attributes.GetCustomAttribute(typeof(TargetFrameworkAttribute)); if (x == null) { x = new TargetFrameworkAttribute("Pre-.NET Framework 4.0"); x.FrameworkDisplayName = "Pre-.NET Framework 4.0"; } xresult_core += arch + " - " + x.FrameworkDisplayName.Replace(" Framework ", " ") + " - SDRSharp.Controls.dll\r\n"; arch = ""; #endregion #region [CollapsiblePanel] bool?SDRSharpCollapsiblePanel = UnmanagedDllIs64Bit(Application.StartupPath + "\\SDRSharp.CollapsiblePanel.dll"); if (SDRSharpCollapsiblePanel.HasValue) { if ((bool)SDRSharpCollapsiblePanel) { arch = "x64"; } else { arch = "x32"; } } else { arch = "Any CPU"; } attributes = CollapsiblePanel.CollapsiblePanelUtils.UnmanagedDLLAssemblyVer; x = (System.Runtime.Versioning.TargetFrameworkAttribute)attributes.GetCustomAttribute(typeof(TargetFrameworkAttribute)); if (x == null) { x = new TargetFrameworkAttribute("Pre-.NET Framework 4.0"); x.FrameworkDisplayName = "Pre-.NET Framework 4.0"; } xresult_core += arch + " - " + x.FrameworkDisplayName.Replace(" Framework ", " ") + " - SDRSharp.CollapsiblePanel.dll\r\n"; arch = ""; #endregion #region [PanView] bool?SDRSharpPanView = UnmanagedDllIs64Bit(Application.StartupPath + "\\SDRSharp.PanView.dll"); if (SDRSharpPanView.HasValue) { if ((bool)SDRSharpPanView) { arch = "x64"; } else { arch = "x32"; } } else { arch = "Any CPU"; } attributes = PanView.PanViewUtils.UnmanagedDLLAssemblyVer; x = (System.Runtime.Versioning.TargetFrameworkAttribute)attributes.GetCustomAttribute(typeof(TargetFrameworkAttribute)); if (x == null) { x = new TargetFrameworkAttribute("Pre-.NET Framework 4.0"); x.FrameworkDisplayName = "Pre-.NET Framework 4.0"; } xresult_core += arch + " - " + x.FrameworkDisplayName.Replace(" Framework ", " ") + " - SDRSharp.PanView.dll\r\n"; arch = ""; #endregion #region [Common] bool?SDRSharpCommon = UnmanagedDllIs64Bit(Application.StartupPath + "\\SDRSharp.Common.dll"); if (SDRSharpCommon.HasValue) { if ((bool)SDRSharpCommon) { arch = "x64"; } else { arch = "x32"; } } else { arch = "Any CPU"; } attributes = Common.CommonUtils.UnmanagedDLLAssemblyVer; x = (System.Runtime.Versioning.TargetFrameworkAttribute)attributes.GetCustomAttribute(typeof(TargetFrameworkAttribute)); if (x == null) { x = new TargetFrameworkAttribute("Pre-.NET Framework 4.0"); x.FrameworkDisplayName = "Pre-.NET Framework 4.0"; } xresult_core += arch + " - " + x.FrameworkDisplayName.Replace(" Framework ", " ") + " - SDRSharp.Common.dll\r\n"; arch = ""; #endregion xresult_plugins = "Plugin Versions:\r\n"; #region [FrequencyManager] bool?SDRSharpFreqMan = UnmanagedDllIs64Bit(Application.StartupPath + "\\SDRSharp.FrequencyManager.dll"); if (SDRSharpCommon.HasValue) { if ((bool)SDRSharpFreqMan) { arch = "x64"; } else { arch = "x32"; } } else { arch = "Any CPU"; } attributes = FrequencyManager.FreqManUtils.UnmanagedDLLAssemblyVer; x = (System.Runtime.Versioning.TargetFrameworkAttribute)attributes.GetCustomAttribute(typeof(TargetFrameworkAttribute)); if (x == null) { x = new TargetFrameworkAttribute("Pre-.NET Framework 4.0"); x.FrameworkDisplayName = "Pre-.NET Framework 4.0"; } xresult_plugins += arch + " - " + x.FrameworkDisplayName.Replace(" Framework ", " ") + " - SDRSharp.FrequencyManager.dll\r\n"; arch = ""; #endregion radLabel1.Text = xresult; radLabel2.Text = xresult_core; radLabel3.Text = xresult_plugins; }
public static FrameworkName GetTargetFramework(this Assembly assembly) { TargetFrameworkAttribute frameworkAttribute = assembly.GetCustomAttribute <TargetFrameworkAttribute>(); return(new FrameworkName(frameworkAttribute.FrameworkName)); }