qol: interpolated strings

This commit is contained in:
Gary Sharp
2025-07-20 11:56:34 +10:00
parent 4e518d6684
commit 7faebe56a8
108 changed files with 342 additions and 350 deletions
@@ -56,10 +56,10 @@ namespace Disco.Services.Plugins.Features.UIExtension
page.WriteLiteral("\n<div id=\"layout_uiExtensions\">");
foreach (var uiExtResult in uiExtResults)
{
string extensionDescription = HttpUtility.HtmlEncode(string.Format("{0} @ {1} v{2}", uiExtResult.Source.Id, uiExtResult.Source.PluginManifest.Id, uiExtResult.Source.PluginManifest.Version.ToString(4)));
page.WriteLiteral(string.Format("\n<!-- BEGIN UI EXTENSION: {0} -->\n", extensionDescription));
string extensionDescription = HttpUtility.HtmlEncode($"{uiExtResult.Source.Id} @ {uiExtResult.Source.PluginManifest.Id} v{uiExtResult.Source.PluginManifest.Version.ToString(4)}");
page.WriteLiteral($"\n<!-- BEGIN UI EXTENSION: {extensionDescription} -->\n");
uiExtResult.ExecuteResult(page);
page.WriteLiteral(string.Format("\n<!-- END UI EXTENSION: {0} -->", extensionDescription));
page.WriteLiteral($"\n<!-- END UI EXTENSION: {extensionDescription} -->");
}
page.WriteLiteral("\n</div>");
page.WriteLiteral("\n<!-- END: Disco ICT UI Extensions -->");
+5 -5
View File
@@ -69,7 +69,7 @@ namespace Disco.Services.Plugins
packageManifest = PluginManifest.FromPluginManifestFile(packageManifestStream);
}
Status.UpdateStatus(20, string.Format("{0} [{1} v{2}] by {3}", packageManifest.Name, packageManifest.Id, packageManifest.Version.ToString(4), packageManifest.Author), "Initializing Install Environment");
Status.UpdateStatus(20, $"{packageManifest.Name} [{packageManifest.Id} v{packageManifest.Version.ToString(4)}] by {packageManifest.Author}", "Initializing Install Environment");
PluginsLog.LogInstalling(packageManifest);
@@ -80,7 +80,7 @@ namespace Disco.Services.Plugins
// Ensure not already installed
if (Plugins.GetPlugins().FirstOrDefault(p => p.Id == packageManifest.Id) != null)
throw new InvalidOperationException(string.Format("The '{0} [{1}]' Plugin is already installed, please uninstall any existing versions before trying again", packageManifest.Name, packageManifest.Id));
throw new InvalidOperationException($"The '{packageManifest.Name} [{packageManifest.Id}]' Plugin is already installed, please uninstall any existing versions before trying again");
using (DiscoDataContext database = new DiscoDataContext())
{
@@ -90,7 +90,7 @@ namespace Disco.Services.Plugins
var libraryIncompatibility = PluginLibrary.LoadManifest(database).LoadIncompatibilityData();
PluginIncompatibility incompatibility;
if (!libraryIncompatibility.IsCompatible(packageManifest.Id, packageManifest.Version, out incompatibility))
throw new InvalidOperationException(string.Format("The plugin [{0} v{1}] is not compatible: {2}", packageManifest.Id, packageManifest.VersionFormatted, incompatibility.Reason));
throw new InvalidOperationException($"The plugin [{packageManifest.Id} v{packageManifest.VersionFormatted}] is not compatible: {incompatibility.Reason}");
// Force Delete of Existing Folder
if (Directory.Exists(packagePath))
@@ -116,7 +116,7 @@ namespace Disco.Services.Plugins
// Extract Package Contents
foreach (var packageEntry in packageArchive.Entries)
{
Status.UpdateStatus(30 + (countExtractedFiles++ * extractFileInterval), string.Format("Extracting File: {0}", packageEntry.FullName));
Status.UpdateStatus(30 + (countExtractedFiles++ * extractFileInterval), $"Extracting File: {packageEntry.FullName}");
// Determine Extraction Path
var packageEntryTarget = Path.Combine(packagePath, packageEntry.FullName);
@@ -153,7 +153,7 @@ namespace Disco.Services.Plugins
ScheduledTasks.InitializeScheduledTasks(database, new List<Assembly>() { packageManifest.PluginAssembly });
PluginsLog.LogInstalled(packageManifest);
Status.SetFinishedUrl(string.Format("/Config/Plugins/{0}", System.Web.HttpUtility.UrlEncode(packageManifest.Id)));
Status.SetFinishedUrl($"/Config/Plugins/{System.Web.HttpUtility.UrlEncode(packageManifest.Id)}");
Status.UpdateStatus(100, "Plugin Installation Completed");
}
}
@@ -37,9 +37,9 @@ namespace Disco.Services.Plugins
get
{
if (string.IsNullOrEmpty(_pluginRequested))
return string.Format("Invalid Category Type [{0}]", _categoryType.Name);
return $"Invalid Category Type [{_categoryType.Name}]";
else
return string.Format("Plugin [{1}] is not of the correct Category Type [{0}]", _categoryType.Name, _pluginRequested);
return $"Plugin [{_pluginRequested}] is not of the correct Category Type [{_categoryType.Name}]";
}
}
+1 -1
View File
@@ -23,7 +23,7 @@ namespace Disco.Services.Plugins
public override sealed string ToString()
{
return string.Format("{0} ({1}) - v{2}", Manifest.Name, Manifest.Id, Manifest.Version.ToString(4));
return $"{Manifest.Name} ({Manifest.Id}) - v{Manifest.Version.ToString(4)}";
}
}
}
+2 -2
View File
@@ -152,7 +152,7 @@ namespace Disco.Services.Plugins
var routeValues = new RouteValueDictionary(new { PluginId = manifest.Id, res = Resource });
string pluginActionUrl = UrlHelper.GenerateUrl("Plugin_Resources", null, null, routeValues, RouteTable.Routes, RequestContext, false);
pluginActionUrl += string.Format("?v={0}", resourcePath.Item2);
pluginActionUrl += $"?v={resourcePath.Item2}";
if (Download)
pluginActionUrl += "&Download=true";
@@ -297,7 +297,7 @@ namespace Disco.Services.Plugins
var routeValues = new RouteValueDictionary(new { PluginId = manifest.Id, res = Resource });
string pluginResourceUrl = UrlHelper.GenerateUrl("Plugin_Resources", null, null, routeValues, RouteTable.Routes, RequestContext, false);
pluginResourceUrl += string.Format("?v={0}", resourcePath.Item2);
pluginResourceUrl += $"?v={resourcePath.Item2}";
HtmlString pluginResourceUrlHtml = new HtmlString(pluginResourceUrl);
@@ -57,7 +57,7 @@ namespace Disco.Services.Plugins
return i;
}
else
throw new InvalidOperationException(string.Format("The feature [{0}] cannot be cast into type [{1}]", Type.Name, typeof(CategoryType).Name));
throw new InvalidOperationException($"The feature [{Type.Name}] cannot be cast into type [{typeof(CategoryType).Name}]");
}
/// <summary>
@@ -70,7 +70,7 @@ namespace Disco.Services.Plugins
var featureAttribute = (PluginFeatureAttribute)featureType.GetCustomAttributes(typeof(PluginFeatureAttribute), false).FirstOrDefault();
if (featureAttribute == null)
throw new ArgumentException(string.Format("Plugin Feature found [{0}], but no PluginFeatureAttribute found", featureType.Name), "featureType");
throw new ArgumentException($"Plugin Feature found [{featureType.Name}], but no PluginFeatureAttribute found", "featureType");
var featureId = featureAttribute.Id;
var featureName = featureAttribute.Name;
@@ -80,19 +80,19 @@ namespace Disco.Services.Plugins
var featureCategoryType = featureType.BaseType;
if (featureCategoryType == null)
throw new ArgumentException(string.Format("Plugin Feature found [{0}], but has no Base Type to determine its Category", featureType.Name), "featureType");
throw new ArgumentException($"Plugin Feature found [{featureType.Name}], but has no Base Type to determine its Category", "featureType");
// Handle Generic-Type Features (Only use base-feature, not generic parameters)
if (featureCategoryType.IsGenericType)
featureCategoryType = featureCategoryType.GetGenericTypeDefinition();
if (featureCategoryType == typeof(PluginFeature) || !typeof(PluginFeature).IsAssignableFrom(featureCategoryType))
throw new ArgumentException(string.Format("Plugin Feature found [{0}], but its Base Type is not a valid Feature Category Type (Base Feature or not assignable)", featureType.Name), "featureType");
throw new ArgumentException($"Plugin Feature found [{featureType.Name}], but its Base Type is not a valid Feature Category Type (Base Feature or not assignable)", "featureType");
var featureCategoryAttribute = (PluginFeatureCategoryAttribute)featureCategoryType.GetCustomAttributes(typeof(PluginFeatureCategoryAttribute), false).FirstOrDefault();
if (featureCategoryAttribute == null)
throw new ArgumentException(string.Format("Plugin Feature found [{0}], but its Base Type is not a valid Feature Category Type (no attribute)", featureType.Name), "featureType");
throw new ArgumentException($"Plugin Feature found [{featureType.Name}], but its Base Type is not a valid Feature Category Type (no attribute)", "featureType");
return new PluginFeatureManifest()
{
+12 -12
View File
@@ -68,7 +68,7 @@ namespace Disco.Services.Plugins
get
{
var v = Version;
return string.Format("{0}.{1}.{2:0000}.{3:0000}", v.Major, v.Minor, v.Build, v.Revision);
return $"{v.Major}.{v.Minor}.{v.Build:0000}.{v.Revision:0000}";
}
}
@@ -242,7 +242,7 @@ namespace Disco.Services.Plugins
var pluginAttributes = pluginType.GetCustomAttribute<PluginAttribute>(false);
if (pluginAttributes == null)
throw new ArgumentException(string.Format("Plugin found [{0}], but no PluginAttribute found", pluginType.Name), "pluginAssembly");
throw new ArgumentException($"Plugin found [{pluginType.Name}], but no PluginAttribute found", "pluginAssembly");
var pluginId = pluginAttributes.Id;
var pluginName = pluginAttributes.Name;
@@ -328,19 +328,19 @@ namespace Disco.Services.Plugins
var assemblyFullPath = Path.Combine(PluginLocation, AssemblyPath);
if (!File.Exists(assemblyFullPath))
throw new FileNotFoundException(string.Format("Plugin Assembly [{0}] not found at: {1}", Id, assemblyFullPath), assemblyFullPath);
throw new FileNotFoundException($"Plugin Assembly [{Id}] not found at: {assemblyFullPath}", assemblyFullPath);
if (PluginAssembly == null)
PluginAssembly = Assembly.LoadFile(assemblyFullPath);
if (PluginAssembly == null)
throw new InvalidOperationException(string.Format("Unable to load Plugin Assembly [{0}] at: {1}", Id, assemblyFullPath));
throw new InvalidOperationException($"Unable to load Plugin Assembly [{Id}] at: {assemblyFullPath}");
PluginsLog.LogInitializingPluginAssembly(PluginAssembly);
// Check Manifest/Assembly Versions Match
if (Version != PluginAssembly.GetName().Version)
throw new InvalidOperationException(string.Format("The plugin [{0}] manifest version [{1}] doesn't match the plugin assembly [{2} : {3}]", Id, Version, assemblyFullPath, PluginAssembly.GetName().Version));
throw new InvalidOperationException($"The plugin [{Id}] manifest version [{Version}] doesn't match the plugin assembly [{assemblyFullPath} : {PluginAssembly.GetName().Version}]");
if (Type == null)
Type = PluginAssembly.GetType(TypeName, true, true);
@@ -442,7 +442,7 @@ namespace Disco.Services.Plugins
{
get
{
return string.Format("/Config/Plugins/{0}", HttpUtility.UrlEncode(Id));
return $"/Config/Plugins/{HttpUtility.UrlEncode(Id)}";
}
}
[JsonIgnore]
@@ -471,7 +471,7 @@ namespace Disco.Services.Plugins
{
var attributeDenied = WebHandlerAuthorizers.FirstOrDefault(a => !a.IsAuthorized(HostController.HttpContext));
if (attributeDenied != null)
throw new AccessDeniedException(attributeDenied.HandleUnauthorizedMessage(), string.Format("[Plugin]::{0}::[Handler]", Id));
throw new AccessDeniedException(attributeDenied.HandleUnauthorizedMessage(), $"[Plugin]::{Id}::[Handler]");
}
var handler = (PluginWebHandler)Activator.CreateInstance(WebHandlerType);
@@ -487,7 +487,7 @@ namespace Disco.Services.Plugins
{
get
{
return string.Format("/Plugin/{0}", HttpUtility.UrlEncode(Id));
return $"/Plugin/{HttpUtility.UrlEncode(Id)}";
}
}
public string WebActionUrl(string Action)
@@ -513,7 +513,7 @@ namespace Disco.Services.Plugins
var resourcePath = Path.Combine(PluginLocation, "WebResources", Resource.Replace(@"/", @"\"));
Tuple<string, DateTime> resourceHash;
string resourceKey = string.Format("{0}://{1}", Name, Resource);
string resourceKey = $"{Name}://{Resource}";
if (WebResourceHashes.TryGetValue(resourceKey, out resourceHash))
{
#if DEBUG
@@ -524,7 +524,7 @@ namespace Disco.Services.Plugins
}
if (!File.Exists(resourcePath))
throw new FileNotFoundException(string.Format("Resource [{0}] not found", Resource), resourcePath);
throw new FileNotFoundException($"Resource [{Resource}] not found", resourcePath);
var fileDate = System.IO.File.GetLastWriteTime(resourcePath);
var fileBytes = System.IO.File.ReadAllBytes(resourcePath);
@@ -548,7 +548,7 @@ namespace Disco.Services.Plugins
new RouteValueDictionary(new Dictionary<string, object>() { { "PluginId", Id }, { "res", Resource } }),
RouteTable.Routes, HttpContext.Current.Request.RequestContext, false);
url += string.Format("?v={0}", resourcePath.Item2);
url += $"?v={resourcePath.Item2}";
return url;
}
@@ -577,7 +577,7 @@ namespace Disco.Services.Plugins
public override string ToString()
{
return string.Format("{0} [{1} v{2}]", Name, Id, VersionFormatted);
return $"{Name} [{Id} v{VersionFormatted}]";
}
}
}
+1 -1
View File
@@ -292,7 +292,7 @@ namespace Disco.Services.Plugins
var routeValues = new RouteValueDictionary(new { PluginId = Manifest.Id, res = Resource });
string pluginActionUrl = UrlHelper.GenerateUrl("Plugin_Resources", null, null, routeValues, RouteTable.Routes, HostController.Request.RequestContext, false);
pluginActionUrl += string.Format("?v={0}", resourcePath.Item2);
pluginActionUrl += $"?v={resourcePath.Item2}";
if (Download.HasValue && Download.Value)
{
@@ -173,7 +173,7 @@ namespace Disco.Services.Plugins
var filters = methodInfo.GetCustomAttributes<FilterAttribute>(true).OfType<IAuthorizationFilter>().ToList();
foreach (var authorizer in filters.OfType<DiscoAuthorizeBaseAttribute>())
authorizer.AuthorizeResource = string.Format("[Plugin]::{0}::{1}", controllerDescription.Manifest.Id, methodInfo.Name);
authorizer.AuthorizeResource = $"[Plugin]::{controllerDescription.Manifest.Id}::{methodInfo.Name}";
return filters.ToArray();
}
+9 -9
View File
@@ -35,7 +35,7 @@ namespace Disco.Services.Plugins
lock (_PluginLock)
{
if (_PluginManifests.ContainsKey(Manifest.Id))
throw new InvalidOperationException(string.Format("The '{0} [{1}]' Plugin is already installed, please uninstall any existing versions before trying again", Manifest.Name, Manifest.Id));
throw new InvalidOperationException($"The '{Manifest.Name} [{Manifest.Id}]' Plugin is already installed, please uninstall any existing versions before trying again");
// Add Plugin Manifest to Environment
_PluginManifests[Manifest.Id] = Manifest;
@@ -256,7 +256,7 @@ namespace Disco.Services.Plugins
if (FeatureCategoryDisplayNames.TryGetValue(FeatureCategoryType, out displayName))
return displayName;
else
throw new InvalidOperationException(string.Format("Unknown Plugin Feature Category Type: [{0}]", FeatureCategoryType.Name));
throw new InvalidOperationException($"Unknown Plugin Feature Category Type: [{FeatureCategoryType.Name}]");
}
public static void InitalizePlugins(DiscoDataContext Database)
@@ -295,10 +295,10 @@ namespace Disco.Services.Plugins
if (pluginManifest != null)
{
if (loadedPlugins.ContainsKey(pluginManifest.Id))
throw new InvalidOperationException(string.Format("The plugin [{0}] is already initialized", pluginManifest.Id));
throw new InvalidOperationException($"The plugin [{pluginManifest.Id}] is already initialized");
// Check for Update
string updatePackagePath = Path.Combine(pluginDirectoryRoot.FullName, string.Format("{0}.discoPlugin", pluginManifest.Id));
string updatePackagePath = Path.Combine(pluginDirectoryRoot.FullName, $"{pluginManifest.Id}.discoPlugin");
if (File.Exists(updatePackagePath))
{
// Update Plugin
@@ -310,12 +310,12 @@ namespace Disco.Services.Plugins
// Check Version Compatibility
var pluginIncompatible = compatibilityData.Value.IncompatiblePlugins.FirstOrDefault(i => i.PluginId.Equals(pluginManifest.Id, StringComparison.OrdinalIgnoreCase) && pluginManifest.Version == i.Version);
if (pluginIncompatible != null)
throw new InvalidOperationException(string.Format("The plugin [{0} v{1}] is not compatible: {2}", pluginManifest.Id, pluginManifest.VersionFormatted, pluginIncompatible.Reason));
throw new InvalidOperationException($"The plugin [{pluginManifest.Id} v{pluginManifest.VersionFormatted}] is not compatible: {pluginIncompatible.Reason}");
if (pluginManifest.HostVersionMin != null && pluginManifest.HostVersionMin > hostVersion)
throw new InvalidOperationException(string.Format("The plugin [{0} v{1}] does not support this version of Disco ICT (Requires v{2} or greater)", pluginManifest.Id, pluginManifest.VersionFormatted, pluginManifest.HostVersionMin.ToString()));
throw new InvalidOperationException($"The plugin [{pluginManifest.Id} v{pluginManifest.VersionFormatted}] does not support this version of Disco ICT (Requires v{pluginManifest.HostVersionMin.ToString()} or greater)");
if (pluginManifest.HostVersionMax != null && pluginManifest.HostVersionMax < hostVersion)
throw new InvalidOperationException(string.Format("The plugin [{0} v{1}] does not support this version of Disco ICT (Support expired as of v{2})", pluginManifest.Id, pluginManifest.VersionFormatted, pluginManifest.HostVersionMax.ToString()));
throw new InvalidOperationException($"The plugin [{pluginManifest.Id} v{pluginManifest.VersionFormatted}] does not support this version of Disco ICT (Support expired as of v{pluginManifest.HostVersionMax.ToString()})");
RegisterPluginAssemblyReferences(pluginManifest);
@@ -429,7 +429,7 @@ namespace Disco.Services.Plugins
PluginLibraryIncompatibility = PluginLibrary.LoadManifest(Database).LoadIncompatibilityData();
var pluginIncompatibility = PluginLibraryIncompatibility.IncompatiblePlugins.FirstOrDefault(i => i.PluginId.Equals(packageManifest.Id, StringComparison.OrdinalIgnoreCase) && packageManifest.Version == i.Version);
if (pluginIncompatibility != null)
throw new InvalidOperationException(string.Format("The plugin [{0} v{1}] is not compatible: {2}", packageManifest.Id, packageManifest.VersionFormatted, pluginIncompatibility.Reason));
throw new InvalidOperationException($"The plugin [{packageManifest.Id} v{packageManifest.VersionFormatted}] is not compatible: {pluginIncompatibility.Reason}");
string packagePath = Path.Combine(Database.DiscoConfiguration.PluginsLocation, packageManifest.Id);
@@ -554,7 +554,7 @@ namespace Disco.Services.Plugins
}
catch (Exception ex)
{
PluginsLog.LogPluginException(string.Format("Resolving Plugin Reference Assembly: '{0}' [{1}]; Requested by: '{2}' [{3}]; Disco.Plugins.DiscoPlugins.CurrentDomain_AssemblyResolve()", args.Name, assemblyPath, args.RequestingAssembly.FullName, args.RequestingAssembly.Location), ex);
PluginsLog.LogPluginException($"Resolving Plugin Reference Assembly: '{args.Name}' [{assemblyPath}]; Requested by: '{args.RequestingAssembly.FullName}' [{args.RequestingAssembly.Location}]; Disco.Plugins.DiscoPlugins.CurrentDomain_AssemblyResolve()", ex);
}
}
}
@@ -16,7 +16,7 @@ namespace Disco.Services.Plugins
var manifest = (PluginManifest)ExecutionContext.JobDetail.JobDataMap["PluginManifest"];
var UninstallData = (bool)ExecutionContext.JobDetail.JobDataMap["UninstallData"];
Status.UpdateStatus(25, string.Format("Uninstalling Plugin: {0} [{1}]", manifest.Name, manifest.Id), "Queuing plugin for uninstall");
Status.UpdateStatus(25, $"Uninstalling Plugin: {manifest.Name} [{manifest.Id}]", "Queuing plugin for uninstall");
PluginsLog.LogUninstalling(manifest, UninstallData);
@@ -27,7 +27,7 @@ namespace Disco.Services.Plugins
{
get
{
return string.Format("Unknown Plugin Id: [{0}]", _pluginRequested);
return $"Unknown Plugin Id: [{_pluginRequested}]";
}
}
}
+5 -5
View File
@@ -187,8 +187,8 @@ namespace Disco.Services.Plugins
if (string.IsNullOrEmpty(packageTempFilePath))
{
// Download Update
Status.UpdateStatus(0, string.Format("Downloading Plugin Package: {0}", pluginName), "Connecting...");
packageTempFilePath = Path.Combine(pluginPackagesLocation, string.Format("{0}.discoPlugin", pluginId));
Status.UpdateStatus(0, $"Downloading Plugin Package: {pluginName}", "Connecting...");
packageTempFilePath = Path.Combine(pluginPackagesLocation, $"{pluginId}.discoPlugin");
if (File.Exists(packageTempFilePath))
File.Delete(packageTempFilePath);
@@ -238,7 +238,7 @@ namespace Disco.Services.Plugins
if (updateManifest.Version < existingManifest.Version)
throw new InvalidOperationException("Older versions cannot update existing plugins");
Status.UpdateStatus(20, string.Format("{0} [{1} v{2}] by {3}", updateManifest.Name, updateManifest.Id, updateManifest.Version.ToString(4), updateManifest.Author), "Initializing Update Environment");
Status.UpdateStatus(20, $"{updateManifest.Name} [{updateManifest.Id} v{updateManifest.Version.ToString(4)}] by {updateManifest.Author}", "Initializing Update Environment");
using (DiscoDataContext database = new DiscoDataContext())
{
@@ -246,9 +246,9 @@ namespace Disco.Services.Plugins
var incompatibilityLibrary = PluginLibrary.LoadManifest(database).LoadIncompatibilityData();
PluginIncompatibility incompatibility;
if (!incompatibilityLibrary.IsCompatible(updateManifest.Id, updateManifest.Version, out incompatibility))
throw new InvalidOperationException(string.Format("The plugin [{0} v{1}] is not compatible: {2}", updateManifest.Id, updateManifest.VersionFormatted, incompatibility.Reason));
throw new InvalidOperationException($"The plugin [{updateManifest.Id} v{updateManifest.VersionFormatted}] is not compatible: {incompatibility.Reason}");
var updatePluginPath = Path.Combine(database.DiscoConfiguration.PluginsLocation, string.Format("{0}.discoPlugin", updateManifest.Id));
var updatePluginPath = Path.Combine(database.DiscoConfiguration.PluginsLocation, $"{updateManifest.Id}.discoPlugin");
File.Move(packageTempFilePath, updatePluginPath);
if (existingManifest != null)