Implementing a MetaWeblog API for ASP.NET Core

Step 1

  • After Creating a ASP.NET CORE Web Application Project
  • Right Click –> Dependencies –> add Nuget
  • Search for “Tamils1809.MetaWeblog” in Nuget

Screenshot (305)

  • To install, use the Nuget "Tamils1809.MetaWeblog":
  PM> Install-Package Tamils1809.MetaWeblog
  • This project is an ASP.NET Core 2.0 Middleware component to support the MetaWeblog API
    that WordPress and Windows LiveWriter uses to support adding and editing of content
    in blogs.

Step 2

To support MetaWeblog, you must first create a class that implements the IMetaWeblogProvider interface:

 public class TestMetaWeblogService : IMetaWeblogProvider
  {
    public UserInfo GetUserInfo(string key, string username, string password)
    {
      // TODO
    }
    public BlogInfo[] GetUsersBlogs(string key, string username, string password)
    {
      // TODO
    }

    public Post GetPost(string postid, string username, string password)
    {
      // TODO
    }
    public Post[] GetRecentPosts(string blogid, string username, string password, int numberOfPosts)
    {
      // TODO
    }

    public string AddPost(string blogid, string username, string password, Post post, bool publish)
    {
      // TODO
    }
    public bool DeletePost(string key, string postid, string username, string password, bool publish)
    {
      // TODO
    }
    public bool EditPost(string postid, string username, string password, Post post, bool publish)
    {
      // TODO
    }

    public CategoryInfo[] GetCategories(string blogid, string username, string password)
    {
      // TODO
    }
    public MediaObjectInfo NewMediaObject(string blogid, string username, string password, MediaObject mediaObject)
    {
      // TODO
    }
    public int AddCategory(string key, string username, string password, NewCategory category)
    {
      // TODO
    }
  } 

Once you've implemented the class, you can register the middleware by first adding MetaWeblog in
ConfigureServices supplying the name of the implemented service class:

public void ConfigureServices(IServiceCollection svcs)
    {
      //...

      // Supporting Live Writer (MetaWeblogAPI)
      svcs.AddMetaWeblog<TestWeblogService>();
      //...
    }
 

Finally, you have to add MetaWeblog in the Configure call to specify the endpoint to listen on when
waiting for the MetaWeblog calls:

public void Configure(IApplicationBuilder app,
                          ILoggerFactory loggerFactory,
                          WilderInitializer initializer)
    {
      //...
      // Support MetaWeblog API
      app.UseMetaWeblog("/livewriter");
      //...
    } 

This simply handles the routing to your methods. It does not implement the service at all.

Configure VSTS Build for UWP Apps

UWP Apps usually require a lot of time to compile a "release" package for submitting to Windows Store, and if you are working in a team, TFS/VSTS can help your team ensure that each check-in has a success build, and make it easier for deployment and testing. Let's see a basic example of how to setup a CI build for a UWP App on VSTS.

Important Pre-condition:

Before you do that, please ensure that your App is already build and running on your local machine.

If you want the package can be used to upload to the Windows Store, you need to manually associate the App to the store and create App packages and validate the release on your machine for the first time.

VSTS build on host agents can not automatically increase the build number in your App's manifest, you will need to do it manually in each check-in, or you can create a custom agent to do that (not discussed in this article)

Example App:

My example App "Thirukkural" is under project "Universal-Windows", you can follow my steps.

Step 1

Go to "Build and Release"

Screenshot (295)

Step 2

Click on +New Build

Screenshot (297)

Step 3

Set a Name, change Agent queue to "Hosted VS2017", and select the "sln" path for this particular App. This is very important, otherwise VSTS will build every "sln" under "Universal-Windows".

Step 4

In "Get sources", change Server path to this particular App source folder (Thirukkural), this is also very important, otherwise VSTS will get all content under "Universal-Windows" even it is only building "Thirukkural" solution.

Screenshot (301)

Step 5

Click "Save & queue" button, and test the build definition.

Screenshot (302)

Double check if the environment configuration is correct. In this case, I want the build artifacts can be used to upload to the Windows Store, so I need to use "release" mode on x86, x64 and ARM. You can change this in the build definition settings according to your demands.

Step 6

After the build is queued, click the build number on the message will open the build watcher window

Screenshot (303)

If everything is correct, you should see the build success after 10-20 minutes depending on your project size. I usually takes more time to build on VSTS comparing to your local machine.

Screenshot (304)

Step 7

Now, we have validated the build works. Let's configure the CI trigger.

Back to the build definition, click "Triggers", and enable "Continuous Integration" trigger. We also need to change the Path specification to this particular App folder, or every check-in under "Universal Windows" will trigger this build, which is not our intention.

Step 8

The build number by VSTS will not automatically increase like you do it with Visual Studio manually. If you want to upload to the store, the build number must be higher than the old one already in the store. Now we need to go back to Visual Studio, open your project's manifest file, and manually increase the build number.

Step 9

Now when you check-in the App source, a build will be triggered.

After it is done, go to "Artifacts", now you can download or browse the App packages.

Step 10

Upload your wonderful App to Windows Store and change the world!!! You can see the "appxupload" file is successfully recognized by Windows Dev Center.


Thank You!

Keyboard shortcuts response in UWP Apps

A good Windows application is not only for the mouse, touch screen users, but also for keyboard operations, especially some common shortcuts, such as undo (CTRL + Z), to provide a comprehensive user experience.

So how do you define keyboard shortcuts in UWP, in my "tracing" app, I need to implement Undo shortcuts (CTRL + Z). First, we need to define the operation of the shortcut key, which is the user's current focus on which control, if you need the entire application interface to listen to keyboard operation, then this UI control is the XAML page outermost container: GRID

So first we define 2 events on the first level grid, the outermost container, below the page: And, as follows:KeyDownKeyUp

<Grid Background="{ThemeResource TracingAcrylicBrush}" KeyDown="LayoutRoot_KeyDown" KeyUp="LayoutRoot_KeyUp">

Next, because the shortcut key (CTRL + Z) We want to manipulate is a key combination, we need to know whether the user presses the CTRL key and the Z key at the same time, so we define a Boolean variable to identify the state in which CTRL is pressed:

private bool _isCtrlKeyPressed;

Then define the event handler function:

private void LayoutRoot_KeyUp(object sender, KeyRoutedEventArgs e)

and

private async void LayoutRoot_KeyDown(object sender, KeyRoutedEventArgs e)

The argument used to determine which key the user is pressing is. The key is represented by this enumeration. So to determine whether to press CTRL, just judge. So the logic for recording the CTRL key state is that when you press CTRL, the assignment is true, otherwise (releasing the key) is false:KeyRoutedEventArgs eWindows.System.VirtualKeye.Key == VirtualKey.Control_isCtrlKeyPressed

private void LayoutRoot_KeyUp(object sender, KeyRoutedEventArgs e)
{
    if (e.Key == VirtualKey.Control) _isCtrlKeyPressed = false;
}

private async void LayoutRoot_KeyDown(object sender, KeyRoutedEventArgs e)
{
    if (e.Key == VirtualKey.Control) _isCtrlKeyPressed = true;
}

The next step is to determine whether the user has pressed the Z key, also in the Layoutroot_keydown event handler, to determine if CTRL has been pressed, and then to Judge E. Key is not Z, like this:

private async void LayoutRoot_KeyDown(object sender, KeyRoutedEventArgs e)
{
    if (e.Key == VirtualKey.Control) _isCtrlKeyPressed = true;
    else if (_isCtrlKeyPressed)
    {
        switch (e.Key)
        {
            case VirtualKey.Z: ViewModel.CommandUndo.Execute(null); break;
        }
    }
}

Now your application interface is ready to respond to the CTRL+Z key combination.

Similarly, if you have other shortcuts that you use with CTRL, you can also put them together in Swtich case:

case VirtualKey.V: await PasteInkOrImageFromClipboard(); break;
case VirtualKey.Z: ViewModel.CommandUndo.Execute(null); break;
case VirtualKey.Y: ViewModel.CommandRedo.Execute(null); break;
case VirtualKey.S: ViewModel.CommandSaveCurrent.Execute(null); break;

Welcome to my personal blog where I post about stuff I do

.Net, Web, Windows, Xamarin, Azure, IoT

Nice that you’re here. This is my personal blog and I post about things I do and I am interested in. Not regularly. If you have any questions I am happy you get in touch with me. Please see the get in touch page

Work:

After having had a very cool time at Chennai from Nov 2017, I am now working at enation solutions with a great team. We are developing a greater mobiles apps and web apps

Thank You.

© 2018 - Tamilan Subramani
Design and Developed by TAMILS1809
Version 1.0.0 CV:feb201827

Follow Me