Is it possible to extend web matrix with plugins? - webmatrix

The new Webmatrix is a cool and free development environment. Does it have any extension points to add new functionality?

With Webmatrix 2.0 Beta and later there is an extensibility framework in place for adding "Extensions." The API is quite simple at present but it appears you can create any arbitrary managed code and include in your constructor where you inherit the Microsoft.WebMatrix.Extensibility.IExtension interface.
Here's a snippet to get you started based on my simple Extension:
[Export(typeof(IExtension))]
public class UmbracoExtension : IExtension
{
public IEnumerable<IDashboardItem> DashboardItems
{
get { return null; }
}
public string Name
{
get { return "Extension"; }
}
public string Version
{
get { return "1.0"; }
}
private IRibbonGroup _ribbonGroup;
private IWebMatrixHost _webMatrixHost;
private List<IRibbonItem> _ribbonItems;
public IEnumerable<IRibbonItem> RibbonItems
{
...
}
[Import(typeof(IWebMatrixHost))]
private IWebMatrixHost WebMatrixHost
{
...
}
-Paul

WebMatrix does not support any extensibility (such as plugins) in version 1.0.

The feature I miss most with WebMatrix 2.0 is not being able to toggle commenting of lines of code but it sure is maturing as an outstanding CMS.

Clinton: You can actually comment and uncomment lines using Ctrl-K-C and Ctrl-K-U keyboard shortcuts.
Others: For more information on extensibility: http://extensions.webmatrix.com/documentation

Related

Is there an alternative to JObject.TryGetValue(string role, value:out var output) in .NET Core 3.X version?

I am migrating to .NET Core 3.X from .NETCore 2.2 and am trying to get following code to work
private static Task SetUserInformationReceived(UserInformationReceivedContext context)
{
if (context.User.TryGetValue(JwtClaimTypes.Role, value: out var roles)){
//Code comes here
}
}
But in .NET Core 3.X UserInformationReceivedContext.User is now a JsonDocument instead of JObject, rendering above code not usable. Is there any other way to get the JToken here with the specified property name?
I just found a solution for this question, and seeing there was no online solution, I'll be posting it here.
private static Task SetUserInformationReceived(UserInformationReceivedContext context){
if (context.User.RootElement.TryGetProperty(JwtClaimTypes.Role, value : out var roles)){
//Code comes here
}
}

Persistent Storage using Application.Current.Properties not working

I'm trying to achieve a persistent storage in Xamarin.Forms. After researching in Xamarin.Forms, I decided to use Application.Current.Properties property.
It looks like it is working just only if the app still remains alive. If I close the app and start it again the Application.Current.Properties is empty.
Does anyone know if I'm doing something wrong? Can I achieve this feature in another way?
As usual, thanks guys.
I have had a ton of problems with Application.Current.Properties on Android. I highly suggest using Xamarin Settings plugin instead which I have never had any issues with. It is persistent even when the app is closed.
That being said Application.Current.Properties is supposed to work even when you close the app. Not sure why it wouldn't but it does not surprise me either.
*Edit: To use once it is installed, basically CrossSettings.Current is the plugin class that will do the work but the example just creates a separate property to access it. So create a new file, lets call it SettingsImplementation:
public static class SettingsImplementation {
#region Instance
private static Lazy<ISettings> _appSettings;
public static ISettings AppSettings {
get {
if(_appSettings == null) {
_appSettings = new Lazy<ISettings>(() => CrossSettings.Current, LazyThreadSafetyMode.PublicationOnly);
}
return _appSettings.Value;
}
set {
_appSettings = new Lazy<ISettings>(() => value, LazyThreadSafetyMode.PublicationOnly);
}
}
#endregion
private const string UserNameKey = "username_key"; //Key used to get your property
private static readonly string UserNameDefault = string.Empty; //Default value for your property if the key-value pair has not been created yet
public static string UserName {
get { return AppSettings.GetValueOrDefault<string>(UserNameKey, UserNameDefault); }
set { AppSettings.AddOrUpdateValue<string>(UserNameKey, value); }
}
}
Then to use that you would do this anywhere in your app:
SettingsImplementation.UserName = "something";
OR
string username = SettingsImplementation.UserName;
My own problem regarding this issue was due to me not explicitly saving the properties with the following line of code:
Application.Current.SavePropertiesAsync();
you can use Xamarin essentials "Preferences" instead:
Preferences.Set("Key", "Value");
Preferences.Get("Key", "Default");
I ran into the same issue.
The problem:
I was trying to throw complex objects into the Application Properties.
It turns out that the Properties can only take primitive data typs.
This Blog was very helpfull.
https://codemilltech.com/persist-whatever-you-want-with-xamarin-forms/

Fetch windows setting value

How do I fetch the Measurement System setting value in javascript?
I'm guessing that it would be throw some WinJS call.
The logical place would be Windows.Globalization, but not seeing if offered there. One pretty simple workaround - faster to write than to research the setting :) is to create a Windows Runtime Component in C# that calls in to System.Globalization:
namespace WindowsRuntimeComponent
{
public sealed class RegionalSettings
{
public bool isMetric()
{
return System.Globalization.RegionInfo.CurrentRegion.IsMetric;
}
}
}
Then add as a reference to your JavaScript app and invoke there:
var r = new WindowsRuntimeComponent.RegionalSettings;
var isMetric = r.isMetric();

Adding a custom editor to visual studio editor list

I am in the process of writing a custom editor for visual studio. I have implemented some basic functionality for the new language e.g. syntax highlighting and I succesfully installed tha package by using the generated .vsix file. All works just nice, however my custom editor needs to be able to be associated with different file extensions.
I thought, mistakenly, that since I installed the editor it would appear under
Tools->Options..->Text Editor->File Extension->Editors list:
However it does not appear there. So the question is: how do you add a custom editor to this list?
Thanks for any help!
Well at least I got the tumbleweed badge for this question.
After a lot of reverse engineering I found the solution... which is not documented.. Anywhere..
Step number 1:
First you need to create an editor factory with all the bells and whistles it comes with - MSVS has an extension for it.
Step number 2:
Then you have to create such a class
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
class ProvideFileExtensionMapping : RegistrationAttribute
{
private readonly string _name, _id, _editorGuid, _package;
private readonly int _sortPriority;
public ProvideFileExtensionMapping(string id, string name, object editorGuid, string package, int sortPriority)
{
_id = id;
_name = name;
if (editorGuid is Type)
{
_editorGuid = ((Type)editorGuid).GUID.ToString("B");
}
else
{
_editorGuid = editorGuid.ToString();
}
_package = package;
_sortPriority = sortPriority;
}
public override void Register(RegistrationContext context)
{
using (Key mappingKey = context.CreateKey("FileExtensionMapping\\" + _id))
{
mappingKey.SetValue("", _name);
mappingKey.SetValue("DisplayName", _name);
mappingKey.SetValue("EditorGuid", _editorGuid);
mappingKey.SetValue("Package", _package);
mappingKey.SetValue("SortPriority", _sortPriority);
}
}
public override void Unregister(RegistrationAttribute.RegistrationContext context)
{
}
}
Step 3:
Then you need to add this class as an attribute to your editor factory (which you created in step 1):
[ProvideFileExtensionMapping("{E23E32ED-3467-4401-A364-1352666A3502}", "RText Editor", typeof(EditorFactory), GuidList.guidRTextEditorPluginEditorFactoryString, 100)]
public sealed class EditorFactory : IVsEditorFactory, IDisposable{...}
That's it. You should now be able to see your editor in the list of editors in visual studio.
Your editor shall be invoked when the file mapping is right.
Hopefully this post saves a lot of time for someone else..

Can Resharper (or Visual Studio) collapse a method call (replace the call with the contents of that method/constant)?

I've inherited a web application written in ASP.NET that has an incomplete implementation of a localization scheme (not using resource files). Here's a micro version:
public class Useful
{
public void DoSomething()
{
return Localizations.Do_Something_Message_vx7Hds8i;
}
}
public class Localizations
{
public const string Do_Something_Message_vx7Hds8i = "Some text!";
}
In almost all cases, these localized strings aren't even used in more than one place. I'd like to factor out this annoying localization layer before properly localizing the app.
The end result I want is just:
public class Useful
{
public void DoSomething()
{
return "Some text!";
}
}
This is proving tediously slow and I have over 1000 in this app.
What would be awesome would be a one-click way of selecting the reference and have it automatically suck in the string contents. I'm using Visual Studio 2008 and ReSharper 5.1.
Does anyone know if there's a way to accomplish this? It seems like there should be a proper name for what I'm trying to do (anti-modularization?) but I'm a little stumped where to start.
The default key command in Resharper is Ctrl+Alt+N for inline refactoring.

Resources