Tech Blog

Jay's Technical blog

To the Cloud!

21 April 2015
Jay Kimble

My Experiment with Azure

In my last post, I mentioned my plan that I had to put into high gear. I read a post by Scott Hanselman a while back about penny pinching while using Azure to host your web site. It's a great read and it got me thinking that I wanted to try to host all my web sites on Azure, but decided to not do what everyone else does (which is host inside a VM). I don't like maintaining the OS. It's not what I do, so this blog is a bit of an experiment. We'll see how the first month goes to decide if I stick with Azure Web sites or if I go with a VM.

Mostly I need a blog and a couple web sites (actually 3), and that is it. With some of my stuff I can live with the using free azure web sites (although the ones with domains require something non-free).

Anyway, I went through the set up and used a stock content manager for everything (Composite C1). This content manager doesn't require SQL Server (it actually uses XML files behind the scenes). You may or may not like that. It really doesn't matter to me. I'm not interested in maintaining the blog's software only the content. It seems like this is the right idea. Although I did have to temporarily increase to a basic site as opposed to the shared option (I put quite a bit of traffic on this in the midst of my initial edits).

[With that we are ready for my new series of posts on "Being a .NET Developer in an Ever Increasing JavaScript World" ]

  About  Cloud

Perspective

21 April 2015
Jay Kimble

Looking back on my blog...

I recently had a bunch of crazy things happen. First of all, a little over a year ago I went to work for AgileThought. I lost my final client and was no longer an independent developer. My web site was still hosted with the client's stuff (as we had hopes of continuing the project, but he was limited on funds).. so we were/are on good terms.

Fast forward to the beginning of April (and the beginnings of the craziness), my former client decided to just shut things down. In his mind no sense in spending money for something he wasn't using, so he had shut things down. I had been thinking for months that I needed to vacate the premises of his servers, but had gotten around to it. Strangely enough it was a warning from some Google Webmaster services that I signed up that told me that my domains were down.

Now I had a plan already (more on that in another blog post), so I rushed my plan into action bringing my sites back up from the dead (well, everything is up, but I'm not 100% happy yet.. this site is close though). I was able to extract most of my old blog posts (I have a couple that I can get back, but not sure it's worth the effort for a post from 8+ years ago!) The one catch and the real point of this post (man, I'm long winded!) is that I had to go back through every post just to get all the dates right. I left the comments behind (a long time ago). I combined both my old Jay Kimble blog and my TRT/CodeBetter/DotNetJunkies blog posts into a single archive (actually this blog now goes back to those early days).

During this process I discovered a few things:

1. Wow! When I started, I was more than a little grumpy. I could point to a bunch of posts where I just needed to get my emotions out. Now when I started blogging, I had more than a few issues (I'm getting better). I also was in a job that I hated. It showed.

2. Back in the beginning I had a good group of friends who were opinionated but not blogging. I leveraged a number of those conversations to create blog posts. 

3. I was not as good as I thought. I guess too we're talking about content from over 10 years ago. I have grown. I'm a different person and a different developer.

4. Has it really been over a year since I blogged? That's hard to believe! Part of it is that I have been busy in life as well as busy professionally. And honestly, I didn't have that much to say. I have just stepped down from my community involvement and am looking to step up my blogging/speaking efforts again (I'm not really interested in running a user group anymore or at least for now).


Nokia Create – Submission Tips

23 October 2013
Jay Kimble

[WARNING! This is an archived post and as such there may be things broken/missing here.. you have been warned.]

I just wanted to fire off a quick post on entering the Nokia Create contest as there are a few things that can get you.

First of all, you will need to do a video of your app. It must be less than 2 minutes long. If you are doing the NFC Mission (which I did), you’ll need to demo outside of the emulator (since the emulator doesn’t support testing NFC). We filmed my app’s demo at a recent community event (where someone else had a Lumia 1020). My video was (of course) slightly too long, so I had to edit it. I bought Magix Movie Edit Touch for Win8 which worked great for me; it allowed me to remove some extraneous video and apply transitions making things seem smoother. There are some limitations on what video formats are supported (so pay attention.. .MP4 is what I used).

Assuming that your app is already in the store, you will need to fill out the submission form. When it comes to uploading the video, upload the file to skydrive, and get a read-only link to the file (don’t waste your time trying to upload video, as it must have a size limitation of some sort as I tried this 3 times and failed). I tried to do this with DropBox first, but for some reason it told me that the file format was wrong.. Other cloud-based file sharing services may work, but I know that SkyDrive works.


Socket Communicator Intro

17 October 2013
Jay Kimble

[WARNING! This is an archived post and as such there may be things broken/missing here.. you have been warned.]

With my Proximity Helper (intro post here) I quickly discovered that socket communications are a little more involved. After searching around I found a couple extensions methods in the “big complicated wp proximity sample on MSDN” (the code I have criticized as being way too complex for a sample app).

Background

The reason why sockets are a little more complex is because when you are reading from the socket’s stream, you need to tell it how many bytes you want to ready. The easy answer around this is that when you are writing to the stream you pass the size of the data you are writing to the stream first, so when you are reading data, you first read how big the next set of data is. I say data here, because you could be reading a byte array or a long or a double or a date, etc. This also means that as you are reading things need to stay in the proper order (you have to read things in the same manner they are written… so if I write a byte, long, and a byte array, then I need to read those things back in the same order from the other phone).

Anyway, the methods I grabbed have to do with writing a uint, reading a uint, writing a int, reading a int, writing a string, and reading a string. Length of a string is stored as a uint.. so my intention for my apps is to write a JSON or XML string to the socket stream and reading a string (on the other side). This makes things fairly easy to send structured information back and forth. To make things easier for me, I put everything into 2 methods (one for reading and one for writing).

Setup

Setup is easy. If you are using my ProximityHelper and set it up using the intro post, then you are done already (you already copied the necessary class). If not then head to the ProximityToy’s respository, and get the latest code (or navigate to the “ProximityToy\Helpers” folder online). The file you need to add to your project is the “ProximityToy\Helpers\SocketCommunicator.cs.” Once you’ve done that you are ready to go.

Code.. Show Me the Code

First of all you will need to instantiate a SocketCommunicator, and it’s easy to do that. Simply do this:

// If you are using the ProximityHelper you could replace the "socket" argument
/// with "ProximityHelper.Default.Socket"
var socketCommunicator = new SocketCommunicator(socket);

You are now ready to communicate. BTW, SocketCommunicator implements IDisposable so when you are done with it you will want to call “socketCommunicator.Dispose” or use it in a using like this (this is great for quick data exchanges):

using(var socketCommunicator = new SocketCommunicator(socket)) {
// Communication code goes here
} // Dispose is called when execution reaches here

Let’s see how we would send a uint and a string:

int someInt = -1;
UInt32 myUInt = 100;
// Single API call for all the supported types
//(only Int32, UInt32, and String are currently supported)
// send Int32
await socketCommunicator.SendAsync(someInt);
// Send UInt32
await socketCommunicator.SendAsync(myUInt);
// Send String
await socketCommunicator.SendAsync("Some text value");
// Send a json string
await socketCommunicator.SendAsync("{'id':1, 'name':'Dev Theologian', 'isValid':true }");

By sending json, you can see how we could basically get every type of covered, and even send complex types.

Now we need to see how to read all this stuff back in:

var someInt = await socketCommunicator.ReceiveAsync<Int32>();
var myInt = await socketCommunicator.ReceiveAsync<UInt32>();
var myMessage = await socketCommunicator.ReceiveAsync<String>();
var jsonString = await socketCommunicator.ReceiveAsync<String>();
// Next steps would be to either deserialize the json or parse and read the values

Remember after you are done communicating to make sure that you call Dispose on your instance of the SocketCommunicator class.

I also expose the DataReader and DataWriter instances that are ultimately being used, so if you want to do something outside of what my utility exposes, you can of course interact with these objects.

Finally, just as a reminder, you can get the single class you need right here: SocketCommunicator.cs.


WP8 Proximity Simplified

17 October 2013
Jay Kimble

[WARNING! This is an archived post and as such there may be things broken/missing here.. you have been warned.]

This blog post will cover the setup of my ProximityHelper class in your apps and help you implement the various scenarios for making proximity connections. You may want to read my introductory post on proximity and WP8 (which also includes my reasons for creating this “mini” library).

My class makes it easy to set up peer-to-peer (bi-directional) socket connections without having to implement the glue necessary to get the connection off the ground. It handles both the scenarios where you want a tap connection and the ones where you need to browse for a connection.

Setup

Setup is fairly easy. Go to the respository for Proximity Toy and grab the latest files. You need to copy the ProximityResources.* files from under the “ProximityToy\Resources” folder. Additionally copy the “ProximityToy\Helpers” folder  (and subfolders) to your the project (this will get the ProximityHelper class AND the SocketHelper class which will be covered in another blog post; it will also get the UI components that we use to connect to a client during a “polling for clients” scenario). Finally you need the “Coding4Fun.Toolkit.Controls” library from Nuget (we use this to display dialogs in your app).

Implementing Scenarios

If you look at Proximity Toy you see that I have 3 different scenarios. These are roughly the scenarios we need to implement. Proximity Toy uses the words “client” and “server” which is the not best choice of words I have for what is happening. A “server” either polls or initiates the “tap.” The “client” responds to a connection request (initiated by one of these methods). These are not the best uses of the words as once the “conversation” is initiated then the both sides can send and receive asynchronously to the other side. [Maybe “initiator”/”responder” is a better set of names].

Connect (Client) scenario

The “Connect (Client)” sets up a situation where one phone is really listening for a connection and will respond to the connection (client responds to a connect requests). Proximity Helper will actually prompt the user to make sure it’s OK to connect to the other phone (it also identifies the “DisplayName” which is provided to ProximityHelper by “server” phone). You initiate this scenario in code like this:

// In your code make "Client Polling" something meaningful to the other user (like a user name for instance)
ProximityHelper.Default.DisplayName = "Client Polling";
// false below indicates that this is not a server (so monitor for connections)
var result = await ProximityHelper.Default.GetConnectionAndSocket(false);
if(result) {
// ******************************************************
// Do your communication here using ProximityHelper.Default.Socket
// ******************************************************
}
// At some point when you are done with the connection, do this to close it
// NOTE: this might not be in the same routine, just make sure you close the connection before you exit
ProximityHelper.Default.CloseConnection(true);


Connect By Tap scenario

The “Connect By Tap” sets up an NFC initiated (2 phones tapping) connection. In the conversation, the phone using this setting is the “server.” You call code that looks like this (it’s very similar to the last example):

// Again, make "Server Non-Polling" something meaningful to the other user (like a user name)
ProximityHelper.Default.DisplayName = "Server Non-Polling";
// The first parameter (true) in the signature below puts the system in "server" mode where NFC is on, and
// we are awaiting some event that makes this phone aware of a client
// The second parameter (false) tells the Helper that we don't want to poll for clients. If this phone doesn't
// support NFC then this setting will be automatically toggled to true to poll
// (Remember our goal here is to dumb down the mechanism and make it easy to create a connection)
var result = await ProximityHelper.Default.GetConnectionAndSocket(true, false);
if (result)
{
// ******************************************************
// Do your communication here using ProximityHelper.Default.Socket
// ******************************************************
}
// After you are done communicating, close the connection (and the communication) down.
// NOTE: this might not happen in this routine
ProximityHelper.Default.CloseConnection(true);

 
Don’t forget that if the phone doesn’t have NFC and you put it into non-polling server mode, we will still poll because non-polling server mode doesn’t make sense on a phone without NFC.

Connect (Polling Server) scenario

The “Connect (Polling Server)” does everything that the last one does except that it also sets up to poll for “clients” to connect to when it finds one (or more) it will prompt (via a dialog using the ConnectPrompt user control in “Helpers\UI”) the user for a “client” to try a connection with. Once a “client” has been selected the “client” phone will prompt if it’s ok to connect, and if it is then a socket is retrieved. The code to do this looks like this (if you’ve been paying attention it should be easy to guess what it looks like):

// Again, make "Server Polling" something meaningful to the other user (like a user name)
ProximityHelper.Default.DisplayName = "Server Polling";
// The first parameter (true) in the signature below puts the system in "server" mode where NFC is on, and
// we are awaiting some event that makes this phone aware of a client
// The second parameter (true) tells the Helper that we want to poll for clients.
//
// BTW, in most cases this is what you will want to do for the server
var result = await ProximityHelper.Default.GetConnectionAndSocket(true, true);
if(result)
{
// ******************************************************
// Do your communication here using ProximityHelper.Default.Socket
// ******************************************************
}
// After you are done communicating, close the connection (and the communication) down.
// NOTE: this might not happen in this routine
ProximityHelper.Default.CloseConnection(true); // Note: true clears the list containing available clients

 

Client Tap scenario

There is also a fourth scenario that is hidden from the UI where we handle an NFC Tap for connection. In this last situation what happens is that the app on one phone is set in one of the “server” modes, and the other phone is not running the app; when the phones are tapped the phone not running the app will prompt the user to open the app or ignore; when they open the app, it launches with a querystring to your main page. We won’t go into the deep details on this, but ProximityHelper can respond to this type of situation and will automatically set up the connection for you. In most cases you want to respond to a tap and instantly get a connection. Here’s the code for that:

private async void handleTap(NavigationEventArgs e)
{
// We still set the DisplayName
// (by now you should know that you want this to be something that is meaningful)
    ProximityHelper.Default.DisplayName = "Client Tap";
// We pass this routine the NavigationEventArgs as well as a bool value.
// A false for the the bool value indicates we want to just detect that we got the
// tap QueryString.
// A true here indicates that if there was a tap Querystring to go ahead and set up
// a connection           
// True is your most likely value
    var wasTapConnection = await ProximityHelper.Default.DetectTap(e, true);
if(wasTapConnection)
    {
// ***************************************************************
// Do your communication here using ProximityHelper.Default.Socket
// ***************************************************************

										
// At some point when you are done communicating, do this to close down the connection
        ProximityHelper.Default.CloseConnection(true); // true indicates clearing list of
// available clients
    }
}

Customization Opportunities

I did want to mention again that if you don’t like my Prompt for client classes you can make changes by editing the xaml of the “Proximity\Helpers\ProximityUI\ConnectPrompt.xaml” file. The big thing to remember is that we are using a little bit of XAML binding (nothing too tricky). Basically we bind the ClientList to the ItemSource of the peerList control (it’s a listbox in our example, but it could be a different type of control entirely if you like); This the ClientList collection includes an IsSelected value that we use to set visibility (using a Converter), so you can use the same thing. Text blocks in the individual rows are bound to the DisplayName property.

Additionally all the static text is stored in the “ProximityTool\Resources\ProximityResources.resx” file. It is also localizable as a result.

Final thoughts

You now have a library that will make things simple for making Proximity style connections. You are ready for my SocketHelper discussion (look for it later today or early tomorrow). [If you are impatient you can dig into the getData and sendData methods in the codebehind of the MainPage.xaml file to see how this works]. Again the sample project (and helper files) can be found at the Proximity Toy’s Repository.