Non-Domain Management of Hyper-V Server 2016 with Windows 10 Hyper-V Manager

While Microsoft lays out the process in an MSDN article, I felt the article left out a bit of information.  Especially for any developer who may not have prior systems administration experience.   So below I’ll attempt to expand on the content MS has provided in this article

Step 1:  Enable PS Remoting on the Host.

In order to do this properly you need to be in powershell on the Hyper-V Server.   So login to the Server

hv-desktop
Hyper-V Server’s glorious desktop

Now that you are logged in, you need to launch powershell.  You can either enter 14 to Exit to the command line, or you can simply toggle to the cmd.exe window that is already opened behind the sconfig window.  Once you are at the command line simply type powershell and press enter.  This will start powershell.

Starting Powershell
Starting Powershell

Once you have the PS command prompt you are ready to enable your environment for connectivity.

Now you enter the command Enable-PSRemoting  at the Powershell prompt. This will not provide feedback. It will simply do its job then drop you back at the PS prompt.  After which you will enter Enable-WSManCredSSP -Role server to enable Remote Management.  This one will provide feedback and a confirmation prompt.

Step 2:  Configure the Windows 10 client to support the host connection.

Since the machine is not on the domain, I don’t actually use a FQDN. Instead I use NetBios.  However, I typically include the entry in my hosts file because I find NetBios to be a little flaky.   Even so, I also sometimes find it easy to just connect using the IP address.  Since this Windows 10 + Hyper-V 2016 setup supports that, I configure it both ways (Note: I’ve never actually tested the IP address connection so I don’t know if it works).

As listed in the article, you have 2 commands and a gpedit in your future. First, as instructed in the article, issue the following command:

Then, optionally for IP support, issue this command as well:

With the Trusted Hosts added, now you enable credssp on the client, exactly as the article indicates.

I think this is supposed to add an entry to the server list in the group policy for Allow delegating fresh credentials with NTLM-only server authentication. However, it seems that it sometimes adds it under Allow delegating fresh credentials instead.  So I found it was necessary to manually edit both of these and ensure the following entries were in my server list.  Again, if you don’t want to include IP support you can drop that one.

Policy editor allowing delegation of fresh credentials
Policy editor allowing delegation of fresh credentials

If you are not familiar with group policy, you simply click start and type gpedit and it will appear in your search results.  Both of these group policy settings are found under Computer Configuration > Administrative Templates > System > Credentials Delegation 

After this I was finally able to get into the machine remotely to manage Hyper-V.

This was a little bearish to setup even with the instructions.  I hope this will help someone else who encounters the same struggle.

Entity Framework Power Tools for Visual Studio 2015

Recently I needed to do a quick diagram of my code first entity framework project.   I went out to grab the latest version of the Entity Framework Power Tools.  Rather quickly I realized that it didn’t explicitly support Visual Studio 2015.

efpt-screenshot-1

After some futile searches I couldn’t find an updated version from a trustworthy source.   However, I did find a nice blog post that outlined the process for editing the manifest of the vsix file to support 2015 to add support for it.

I deviated from that slightly.  Specifically I didn’t bother with the renaming of the file, I simply opened the vsix file in 7-zip and edited the manifest file directly, then told it to update the content of the package.

I proceeded to install the updated vsix just like any other and restarted my IDE.  Upon restart I was able to right click my dbcontext object and sure enough, there was my old reliable Entity Framework menu.

efpt-screenshot-2

And upon clicking the View Entity Data Model (Read-only) option, I immediately saw my diagram.

To save the extra steps, I’ve linked a copy of my modified vsix file.

Turtle Copy

Turtle copy is a tool I recently created for the sake of copying files slowly.  Why would you ever want to copy files slowly you ask?  Because some test scenarios make it necessary.  For example: “How would this file processing subsystem work if the incoming file was transferred over with a CPU that was near max usage?  Or maybe a network connection that is troubled?”

It’s not polished or fancy, purely a command line utility and at the time of this writing I know of at least one minor bug.   However, it serves me well enough and I thought it may help someone else.   So here’s the source code.

WiX Custom Actions and Entity Framework Migrations

Working on a new project I had a need to integrate Entity Framework 6 migrations as part of the installation package.   My goal is simple, a single installer that migrates and rolls back the database as part of it’s installation procedure.   The key to making this work is a utility that is part of the EF6 Nuget package – Migrate.exe.

path to migrate

To find this tool, simply navigate to your solution folder, then packages, then EntityFramework.<version>, then tools.   Here you will find several files, one of which is the migrate.exe tool being referenced here.

MSDN provides a healthy dose of information on the specifics of how to use migrate.exe, but for my purposes, I am going to collect the connection string from the user.   The software in my case supports only SQL Server, so I can default the provider as such.  So, this makes the “provide connection string” approach — the last one in the linked article — the perfect option for my needs.

provide connection string example

Armed with this tool I went to work creating my UI dialog for WiX.   This dialog will allow me to capture the connection string information.   I had previously used an article from code project to learn about the WiX dialogs.   I used that same code here in order to create my connection string dialog.

With the dialog fragment in place.  It was a fairly simple matter to integrate it into the WiX workflow.   Note: I am using WixUI_Mondo as my UI.

This created the desired result.

Now it was a matter of using Migrate.exe to push the entity information out.  In order to do this I needed a custom action.  So I added a new CA project to my solution, and referenced it in my installer.   For brevity of this post, I’ve removed all of the logging from this object.

A few key points about this method:

  1. It requires some property values to be passed into the custom action as part of the WiX markup, particularly the connection string – which comes from our custom dialog, and the executable path – which comes from the directory structure definition.
  2. Because I’m working with a connection string, I have to do some trickery as the ‘;’ plays havoc on the property values being passed in because the CA uses this same sentinel as a delimiter for the values.   This basically means if I have a connection string “data source=localhost;initial catalog=database_name;integrated security=true” it will come through as multiple values into the custom action, splitting on the ‘;’.
  3. It will execute a shell (i.e. a command prompt window will popup during installation).  For me this was ok, and beats the alternative – which is:  You can opt to not use shell execute.  However, this means you also cannot redirect output, which means you cannot log output in a verbose debugger session (msiexec /l switch).

 

When I get the chance, I’ll try to post a sample on my github page, and update this post with the link.

Adding Recaptcha to ASP.NET MVC with no baggage

When I decided to add recaptcha, to an email contact form, I naturally started looking online at options for completing the task. There were many routes I could have gone, but it seemed that most of the blog sources out there all pointed me to a nuget package, or to “go to codeplex and get this thing” . Then, when reviewing the documentation for those ‘helper’ projects, all of the processes seemed convoluted, and disappointing. I knew there had to be a simple, and pure, approach and so I decided to go to the source: Google.

Google is great at many things. I generally think their documentation is solid as well, but honestly, the docs for recaptcha are fairly weak. They contain all of the needed information, but in a way that is only slightly clearer than mud.

However, using what they gave me, and some creativity, I was able to arrive at a working solution. I will explain it all below:

Inserting the Captcha

First, as Google instructs you to do, add the following html where you want the captcha to appear. Along with the JavaScript (at the end of your html body). Note: Pay attention to the data-callback attribute that is not shown in Google’s example, but described in their surrounding text.

So that will actually show you the captcha if you try it just as it is. However, we have to validate it as well.

Working with the Captcha Client Side

In order to do that you really have a two step process. When the user interacts, the callback method you specify in that data-callback attribute is triggered. However, the value is simply an encoded response, and you will pass it back to the server as-is. To best accommodate this, I added a @Html.Hidden field to my page, and mapped it to a string property in my view model. Then, using the handleCaptcha() call back method, I set the response from Google into that hidden field.

So now you can present the captcha to the user, and capture the response contained in the call back, and send it to your controller for further validation. For this final validation you make a final api call (as described by Google) to get a yes or no answer.

Bringing it all back to the server to validate securely

For that I simply added a subroutine that returns a boolean, and call that in my controller passing the Google response string. Note: The response from the API call is a JSON object that .NET deserializes to a hashtable (technically a dictionary<string, object>). You find the “success key” and its value is your boolean success indicator.

That was it, it works exactly as I would have expected, and is quick and painless. I also added logic to disable my submit button until the captcha callback took place, that way the user couldn’t accidentally submit the form without that response.

 

 

SVG Manipulation using JQuery

This started out as a simple idea. I have an Scalable Vector Graphics (SVG) image of the United States. I have data for several of those states. I want the state to be colored for the data, and to show the data in a Bootstrap popover on hover.

After doing a limited amount of research, one thing was clear, I needed to make sure I had the IDs set on my image correctly, and to do that I had two options. One was to edit the svg in a text editor – which would be fine except that I don’t know which path is Kentucky and which path is Oregon. So this could have created some serious confusion when you hover over California and see a popover for Maryland. Option two, was to use an SVG editor, and for me that is Inkscape. To do this in Inkscape, you simply select an element and press CTRL + SHIFT + O. This will bring up the object properties dialog (also accessible via the Object menu), and here you can provide an ID and a label for the shape. I had to do this for every shape with which I wished to interact. So, there were 50 total.

Attempt #1: (Note, this one was only a partial success – hence, the #1):

I pulled in the SVG as an object. Then using JQuery I was able to load the contents of the object. From there I was able to use selectors to access the id’s I added, and I could change the colors of the items – however I couldn’t get the popovers to fire. I tried several different approaches, and each one failed. My theory is that while I can traverse the SVG document object model to update fill styles, I can not tie it back to my HTML DOM in a meaningful way.

Arriving at this conclusion, I decided to paste that beast of SVG code into my HTML markup, which leads me to Attempt #2.

Attempt #2: (Success, but not my final solution)

So, now my HTML is huge, because it contains a massive amount of SVG data, but all of the elements and their id’s are part of the same DOM as my HTML markup now. Using the following HTML + JQuery I am able to access the document and do pretty much whatever I want with it.

First, the HTML

And the Script

 

Attempt #2.1 (My final solution)

So, for the final solution I wanted to get that nasty SVG code out of the markup. Because I realize that, while it doesn’t ease any bandwidth burden, it’s still more readable if you are viewing the HTML source. The only change there is to add a div, with a custom (in my case data-svg) attribute that points to your SVG file, then with JQuery you do the following

 

I created a similar project, specifically to share here, and it can be found on GitHub. I will try to post a demo and update this post in the near future.

Simple windows script to delay application startup

I created an application that needed to run on startup, and needed to run as admin, and do it all on XP. The post about it was started a while back, but is yet to come – once it’s finished proving itself worthy. However, when executed on certain machines there have been issues where the startup process for the OS wasn’t finished in time for the application launch. These issues resulted in permissions errors. These errors didn’t occur if you closed and reopened the application seconds later.

The simple solution became obvious after a few moments of consideration. I simply needed to delay the startup of the application. To do this I crafted a very simple VBScript and placed it in the all user’s startup folder, replacing the shortcut that my installer had placed there previously.

Note: To simplify the example below uses calculator as the application to launch, and it assumes the Windows Directory is c:windows. In the real implementation this was simply the same path that was referenced by the original shortcut.

And that is it. A very simple script that solved a major problem. After the delay, the application starts every time without issue. This small endeavor was the first time that I’d every truly realized the potential in visual basic scripting in a Windows environment. I’ve used PowerShell, and Batch files, and Console applications many times, but this scenario

Java to WCF Service Error: Two declarations cause a collision in the ObjectFactory class.

I don’t talk about java on here too much, because I avoid it most of the time. I was never a big fan, but concede that it has it’s usefulness. After all: It powers devices of many shapes and sizes, it is platform agnostic, and it has a ton of community support. However, I’ve always found the IDEs to come up short of expectations — Visual Studio set this bar very high. Anyway, it was just recently that I had a good reason to dig into consuming a WCF service from a java client. This foray into the deep dark recesses of JAX had me ranting about the evils of java.

“As a .NET guy, I am convinced that JAVA was spawned in the depths of a cavernous inferno. A place where the pervasive stench, of all things unholy and unclean, consumes all it contacts. A place so vile that the darkness remains unerringly fast, even as the sun illuminates the surrounding lands.” — Me via Facebook

What powerful force could have driven me to such frustration, that I would publicly make such statements? This obscure error message:

[ERROR] Two declarations cause a collision in the ObjectFactory class. Line 1 of file...

The error in and of itself is innocuous enough, two proxy objects are trying to generate with the same name. However, I do not have two objects named the same thing, even if I was foolish enough to create that scenario, C# would not allow it. Perhaps I could have created the collision by assigning data attributes incorrectly. However, since the WSDL came across as a single line, I didn’t have a hint as to where to look.

Eventually I copied the WSDL to a text file, broke it out line by line, and attempted to regenerate the proxies. After this exercise, I finally had something to work with. The two lines were there, but they certainly were not named the same thing, not even close. One was named MailingAddress, the other was named MailingAddressZipCode. What madness is this?

So I popped open my service source to discover the following object definitions (shortened for brevity).

When I realized the problem, I second guessed it. Surely the proxies would not be generated in such a way that they drop scope resolution on the floor. MailingAddress.ZipCode is not the same thing as MailingAddressZipCode. However, the voodoo that JAX employs when generating these proxies fails to care. After a quick renaming of the properties I confirmed this to be true. I renamed the MailingAddress object to PostalAddress, and viola proxy generation succeeded.

So the lesson here is simple. When creating a WCF service, if you expect connectivity from java clients, you must not name classes anything that may potentially clash with a concatenated class + property elsewhere in code.

For a language that runs on so many devices, and has – and has had for so many years – so much potential in the marketplace, it’s things like this that makes me and many other developers run away from java except when it is the only choice. Well this and the fact that an equivalency operator is not valid for string comparison.

Making Bootstrap Even Easier, with MVC HTML Helpers

Inspired, more than a little, by a blog post over at mvcdiary.com, I decided that I could make my life with bootstrap even easier. I had the idea to create HTML Helpers for MVC that would enable the use of some of the display attributes to add more auto-magic goodness to the page.

My goal was to be able to simply use @Html.BootstrapTextBoxFor(m => m.description) in my markup, but the rendered output would include the bootstrap placeholder, and the title attribute would be set to allow for automatic tooltips on mouse over.

I decided that it would make a lot of sense, to use the “description” value of the display attribute for the tooltip, and the “prompt” value of the same attribute for the placeholder. So I started off — as I usually do — to see if anyone had already done this. Sure enough, I found the blog post, which gave me an incredible head start. The grunt work was already done, it was just assigning the additional properties. Here is the final result (feel free to compare to the original).

The result is exactly my desired result.

Markup:

Model:

Output:
screen-snag-post-62

It was all very easy to implement, and extend even further and to other standard helpers, such as the textareafor helper.

Opening Illustrator Generated SVG in Inkscape

I have a file that was sent to me from a friend, and it was saved as .svg, but wouldn’t open in Inkscape.

I attempted to both, open it directly, and to “import” it, with no success. So I opened it up in notepad++ and found that it was generated with Adobe Illustrator 11. Armed with that information I renamed the extension to .ai.svg, which I had previously noticed was a special import option in Inkscape. Once it was named as .ai.svg it imported just fine using the Adobe SVG import option.

I just thought I’d share this tidbit in case anyone else runs into it. It was a super simple work around, and now I can tweak the SVG in inkscape.