Back in the day we would write Http Handlers to process requests that needed to be tied to a particular endpoint while avoiding the overhead of the Web Forms page life cycle. This is an older concept but you can find plenty of examples in the DasBlog code line. This was before RESTful APIs were popular, even preceding the first versions of WCF. HttpHandlers were a straightforward way to provide an RPC like interface, you could even define HTTP verbs in the web.config:

<add verb="GET" path="DeleteItem.aspx" type="newtelligence.DasBlog.Web.Services.DeleteItemHandler, newtelligence.DasBlog.Web.Services"/> 

Your handler class (DeleteItemHandler in this example) would need to inherit from IHttpHandler. The web request and response are handled in the ProcessRequest(HttpContext). Here is an abbreviated version of a handler over at DasBlog:

public class DeleteItemHandler : IHttpHandler 
{
     public bool IsReusable
     {
         get { return true; }
     }

    public void ProcessRequest( HttpContext context )
     {
         // All the work is done here…
     }
}

This solution provided an incredibly versatile way of defining completely custom pipelines and routes akin to ISAPI extension but with much less C++.

Middleware

Middleware, like HttpHandlers, are assembled into the application pipeline to handle both requests and responses of ASP.NET Core applications. The important improvements over HttpHandlers is that each Middleware component gets to decide whether to pass the request along and you also determine explicitly where that component is order in the pipeline.

Here is the basic skeleton of a Middleware, where Invoke takes the place ProcessRequest:

public class DeleteItemMiddleware
{
     public DeleteItemMiddleware(RequestDelegate next)
     {
         // This is an HTTP Handler replacement so we do nothing...
     }

    public async Task Invoke(HttpContext context)
     {
         // All the work is now done here…
     }
}

Note the constructor signature is always necessary but as this is a HttpHandler replacement (representing the very end of the pipeline) we do nothing with it, I actually wonder why middleware is not defined through an interface by design.

The following extension method exposes the middleware to your IApplicationBuilder:

public static IApplicationBuilder AddDeleteItem(this IApplicationBuilder builder)
{
     return builder.UseMiddleware<DeleteItemMiddleware>();
}

The final step is defining what URI the Middleware will respond to, for HttpHandlers this would have been defined in the web.config path property. For Middleware this is defined programmatically in Startup.cs as follows:

app.MapWhen(
     context => context.Request.Path.ToString().EndsWith("/blogger"),
     appBranch => {
         appBranch.UseXmlRpc();
     });


January 19, 2018 1:50  Comments [0]
Tagged in ASP.NET Core
Share on Twitter, Facebook and Google+

I am genuinely grateful for life that I have been gifted and for the many privileges that I have been afforded. I believe I can honor these blessings by enabling those who may not ever be presented with the opportunities that have been so generously bestowed on me.



January 14, 2018 19:54  Comments [0]
Tagged in Musings
Share on Twitter, Facebook and Google+

MonitorSetup_Kensington_SD3500v

Many years ago it was both necessary and indeed a right of passage to upgrade some part of your PC. We would upgrade graphics cards, memory, hard drives, RAM or do a total heart transplant and swap out the motherboard. In the “Post PC” era such ideas seem a little anachronistic, if someone needs an upgrade you buy a new phone or tablet. Ease of fabrication and production has trumped the idea of easy hardware upgrades. However, there are still 600 million or so PCs with at least Windows 10 on them right now and some subset of them, like my PC, are a little old and need a little tender care.

My old PC has enough RAM and the processor is this side of sufficient but I am missing things like Bluetooth and, more importantly, USB 3. Now USB 3 is a dramatic improvement over the prior USB 2 standard, as in 10x faster (transfer speeds up to 5 Gb/s) such that basic peripherals have started to expect it. So I grabbed a $20 USB 3 PCIe host card from Microcenter, and got it installed in about 2 minutes and now I am looking at full backups that occur in minutes rather than hours.

On the negative side you have to use a CD to install … and it encourages you to run the setup application as follows:

D:\NEC\uPD720202\Setup.exe

This is fine for me but most members of my family would not care to perform this type of installation, it seems like the problem of modular plug and play upgrades was never solved.

One of the other benefits, actually the primary one for me, is its support for USB 3.0 docking stations which then allows me to have dual HD video ports, I selected the Kensington SD3500v. So now I have two monitors that I can quickly hook up to my either home PC or my laptop when working from home.



January 3, 2018 5:04  Comments [0]
Tagged in PC
Share on Twitter, Facebook and Google+

I am looking for help with DasBlog, lots and lots of help, and to that end I am trying to ensure that I am not just hacking at the code solo but providing an appropriate on ramp for new developers and/or first timers to open source. So I wanted to use the concept of TagHelpers to get folks productive quickly.

TagHelpers enable server-side code to participate in creating and rendering HTML elements in Razor files. They are developed using C# and enable custom HTML elements based on a simple naming convention, for example, if I were to create a “PostCreatedTagHelper” class it could activate it inside a page by using the <postcreated> tag. A really comprehensive introduction to TagHelpers can be found here, however, the following may be enough for you to start contributing.

TagHelpers in DasBlog

For people who are still using DasBlog I wanted the designing pages to be a simple task, especially if you are Web Designer by trade. I am planning on using TagHelpers to define components within the View (Title, Description, Category, etc) . If we take the case of a single post you will probably be getting information from the PostViewModel type and using it in the _PostPartial.cshtml page.

So imagine you are tasked with creating a new TagHelper that applies a date format to the PostViewModel.Created field, you would reference the TagHelper in the View as follows:

<postcreated post=@Model>MMMM dd, yyyy</postcreated>

Setting post=@Model allows you to inject the Views model type directly into field of the TagHelper class you will need to create. The date format (MMMM dd, yyyy) becomes a useful input to the TagHelper class so that a designer can quickly change the format of the date output without knowing C#.

Here is an example where I create a HTML p tag, pull the format information from the View (as in "MMM dd, yyy") and apply it to the PostViewModel.Created date field:

public class PostCreatedTagHelper : TagHelper
{
    public PostViewModel Post { get; set; }

    public override async Process(TagHelperContext context, TagHelperOutput output)
    {
        var content = await output.GetChildContentAsync();
        string format = content.GetContent() 
        output.TagName = "p";
        output.Content.SetHtmlContent(Post.Created.ToString(format));
        output.TagMode = TagMode.StartTagAndEndTag;
    }
}

The final step is to ensure that your ViewImports.cshtml has a reference to the TagHelper class namespace and it should produce the following HTML:

<p>June 10, 2017</p>

This is a fairly straightforward case, and to be honest I probably would not be well served to use paragraphs in this context, but I hope this lays out an efficient way to start creating  your own TagHelpers over at DasBlog.

Please note that I have labeled these TagHelper tasks for code newbies who are looking to make contributions to supportive open source project using ASP.NET Core MVC. Please feel free to reach out to me on twitter and I will be happy to help walk you through this.



December 29, 2017 20:48  Comments [0]
Tagged in ASP.NET Core
Share on Twitter, Facebook and Google+

I just got through reading Stephen Toub’s “All about Span: Exploring a new .NET Mainstay”, it is comprehensive, brilliant and it feels like one of those seminal pieces we will be referencing for years. It introduces a new type that is set to transform the way we approach sorting and it starts with System.Span<T>. Here is how it described:

“System.Span<T> is a new value type at the heart of .NET. It enables the representation of contiguous regions of arbitrary memory, regardless of whether that memory is associated with a managed object, is provided by native code via interop, or is on the stack.”

So this means, for example, I can convert any array (as in T[]) into a Span (as in Span<T>)

var intarray = new int[10];
Span<int> intspan = intarray;

or

var bytearray = new byte[10];
Span<byte> bytespan = byterarray;

You get the picture … but why is this important? Now that we have it in Span we can efficiently reference any part of the array without quietly making copies (allocations).

Span<byte> sliced = bytespan.Slice(start: 2, length: 3);
sliced[0] = 42;
sliced[1] = 43;
sliced[2] = 44;
Assert.Equal(42, sliced[0]);
Assert.Equal(43, sliced[1]);
Assert.Equal(44, sliced[2]);
Assert.Equal(bytearray[2], sliced[0]);
Assert.Equal(bytearray[3], sliced[1]);
Assert.Equal(bytearray[4], sliced[2]);
sliced[3] = 44; // IndexOutOfRangeException

In above example I am changing the original array I did not need to make copies to deal with subsets of the original array. I spend a lot of time analyzing hang dumps and it might honestly surprise you how inefficiently we code even with the best of intentions.

There is much more to the original article (Memory<T> for example), I need more time to absorb it, but I wanted an initial searchable reference here.



December 23, 2017 3:21  Comments [0]
Tagged in C#
Share on Twitter, Facebook and Google+

A colleague was making a really compelling case today for moving our batch based processes from bat files and cmdlets over to npm packages. The wonderful irony is this possibility has been brought about by the generally warm acceptance of VS Code as light weight JavaScript editor (Is this the strategy tax we hear about?)

Honestly I am somewhat of a luddite in that I still default to cracking open Visual Studio and creating an exe that does my bidding, I have only recently got used to using Powershell to create cmdlets and then only when I intend to share.

I guess I am just getting ready to taking a side and the battle has probably already been fought.



December 19, 2017 1:10  Comments [0]
Tagged in Musings | Node
Share on Twitter, Facebook and Google+

When you are in a medium to large size company the yearly reviews become a really important opportunity to reflect on your own work year, just as importantly is the way in which it allows you to provide necessary feedback on your peers. We all know this is important but it is also very stressful, you have to try summarize a year and like most critical tasks it can feel overwhelming the closer you get to missing your deadline.

This year I am once again summarizing some of the ways I approach work reviews with my extended team. In our company this process is not the sole responsibility of the manager, but each team member gets to make positive comments on their peers to help develop a complete picture of the year.

This year I have elected to summarize the comments by technical role, and I will look back at this list not just for a cynical copy and paste, but as way to get a bit of inspiration for appropriate wording and phrasing for deserving team mates. I hope it helps you also!

Technical Engineer

  • Possesses that rare set of skills necessary to turn unique and useful ideas into reality.
  • An exceptional technical talent with a consistent, positive and bright attitude.
  • <name here> brings a combination of gregarious personality, customer service, and technical capability to any critical task she is assigned to.
  • Her commitment to meeting complicated and detailed customer needs, combined with her tenacity and strong technical knowledge truly stand out.
  • Most important of all <name here> is a decent and caring person who treats others with the utmost respect. This reflects in the quality of works she produces and the positive way our team interacts.
  • She is an extremely talented software engineer and a quality person. Her ability to recognize complex yet hidden patterns in software requirements and design always stands out, and she has proven many times her ability to innovate to meet business needs.

Technical Lead/Architect

  • Her ability to distill complex problems to their root causes and to prioritize competing needs have been critical to our success.
  • As a technology leader she has repeatedly integrated cutting edge technology into a consistent and reliable developer operations. Constantly driving toward a standard of excellence and continuous improvement. Her hard work was expressed in the outstanding results that reflected positively on the entire division.
  • <name here> is an innovative, creative, tireless and dedicated person with a strong entrepreneurial spirit and acumen.
  • <name here> designed a wide variety of complex network and infrastructure systems, providing substantive improvements in reliability, availability, cost and services.

Technology Manager/Director

  • Her professional, calm demeanor and the respect generated by her technical expertise were critical to our success. Her ability to evaluate a situation, deliberately share responsibility and carefully ensure success is rare commodity among technical staff. It is this ability to balance technical requirements against business knowledge and insight that causes her to stand head and shoulders above her peers.
  • <name here> reported to me and was a driving force for positive change in the security of our software development lifecycle. Her innovative and business-savvy approach sets her apart.
  • <name here> is an stand out manager and consummate professional. Her expertise in the broad field of security, especially as related to Internet and electronic applications, is rarely paralleled by others in the industry.
  • Professional, attentive and proactive manager who knows how to strikes the precise balance between technical leadership and people leadership. As a leader of people she has earned the respect of every one of her reports and succeeds in motivating them to excellence.
  • She has provided expert leadership for years across industries, and is relied upon as a person who can help solve the most complex and difficult business problems.


November 28, 2017 1:58  Comments [0]
Tagged in Musings
Share on Twitter, Facebook and Google+

Our VP was talking to our extended teams a few months back and he said something that stuck with me about how he intends to promote a unified strategy for the team. It was simple and elegant and applies to most any project you might be involved in:

  1. Clearly define a strategy so that you know what you are doing and why you are doing it.
  2. Create simple and unambiguous measurements for success.
  3. Repeat steps 1 and 2 until it is second nature to everyone.


November 20, 2017 1:31  Comments [0]
Tagged in Development Process
Share on Twitter, Facebook and Google+