Monday, December 9, 2013

From concept to reality in 6 weeks - part 16

Today is thankfully a new day as I just want to completely forget everything that happened this weekend as it was all just a bad dream, or at least that is what I want to tell myself. It was all personal problems with my family that is just getting worse with every passing day. That is the challenge of balancing family and work life. No client of mine pays me to moan and groan about my personal and family issues. They are paying me for super first class high quality results. Part of experience of getting old is to be able to separate family and work and put 100% effort into work every when things are going terribly at home. I really learned this two jobs ago when my best friend was dying of cancer in front of me daily at work. He definitely rose above his circumstances and did his absolute best even when feeling horrible from chemotherapy or radiation. He was a trooper until the end and I have to remember those 3 years for the rest of my life.

Now it is time to refocus on the task at hand as I am half way thru the project. Elapsed time wise I have 4 calendar weeks left to go. I realize that does not mean I have 20 days as I want to spend time with my family during Christmas and New Year's Day. Today my task is to finish off the final layer and resolve the layer icon issues so they all look correct by color and size. Before I start on that I need to check the label changes I made and learn about latitude for the millionth time it seems. I quickly go to Wikipedia so I can see a visual picture in my head so maybe just maybe I will remember this time that longitudes or meridians go thru the poles and latitudes are parallel to the equator. I change my debug statements to show the extend of the markers for N/S latitudes and E/W longitudes. I then need to fix my labels to show altitudes as whole numbers as I see decimal points being displayed, so I switch back over to the C# number formatting documentation asI have been there before. The secret was to use "N0" to show a number with no values after the decimal point. Two problems resolved just like that.

Now to solve the markers. I have decided to automate this whole process by using ImageMagick convert program since I don't want to edit the SVG files and generate PNGs each manually as that is too time consuming. I had to regenerate the triangle in Inkscape so I had to look that up as it is not obvious how to do that. The first thing is how to set the transparent pixel which is done with -transparent option. The second thing is how to account for the case when the background color is not an exact single color and that is fixed by using the -fuzz option. Then I need a way to change the default foreground pixel color as it needs to change for each marker depending on elevation and that is done with the -fill option. Now I just need to figure out the colors that match each of the icons and I am done. ImageMagick definitely helps me here as it supports many color syntax values. I have RGBA values stored in C# so I am going to use those values in my Bash script that will auto-image-magickally do every thing for me. As an aside, this has to be one of the worst names in all of UNIX, the shebang marker at the top of the UNIX shell script which I add to my script. I always run it with the time command so I know how long it takes to run:
$ time ./convert.sh 

real 0m1.388s
user 0m0.443s
sys 0m0.278s
This is what my script looks like in general:
convert -fill 'rgba(181,13,33,235)' -fuzz 20% -transparent white A.svg A.png
The last thing I had to do in my script was copy each output PNG file into the Windows Store project Assets folder so I can easily add them into the VSE project on my Windows laptop. I am still not happy with the icons as I need to find a way to use vector icons as generating the PNG files just don't look good at all. The functionality is working, but it looks bad, so I need to address that somehow.

The whole rest of the day was fixing, changing, editing and resizing icons to make sure they look really good as they are essential to the app. Gimp and Inkscape were my constant companions all day long. It took way too long to fix all of the images it had to be done either programatically or manually. I am just glad that it all looks good and I can call it a day.

Saturday, December 7, 2013

From concept to reality in 6 weeks - part 15+

With my customer visit yesterday I did not have time to record my thoughts all day long. This means I get to try to remember every thing that happened yesterday and this morning. I woke up early this morning so that should be pretty easy to recall.

The first task I completely failed on yesterday was switching from Kanbanery to Trello for the Kanban project management board. It is just so hard to switch tools like that in the middle of a project. I would need to export all of the tasks from Kanbanery and import then into Trello. That is just not going to happen easily as I have almost 50 tasks in 4 different columns. Something is going to get lost and I don't have time to fix stuff like that.

Part of this story is going to be easy as I can look at the Git log and see what I did yesterday! The big news for yesterday is that I got a new build for the mapping engine and was able to get it all working and showing 3 out of the 4 layers. I definitely like it when things just work. I tried a couple of times to get the images working and then just gave up and colorized the ones I needed to a fixed color. I looked at the iPad app Objective-C code to find the colors and the layer settings since we are using the same mapping engine. That exercise just reminded me how verbose and challenging Objective-C is to write an enterprise application. The code just hurts my head and is painful to read and to follow the flow of what is going on. On the other hand C# is very much like Java or ActionScript where you need to understand the framework, threads and events and you are done.

A couple of new challenges occurred yesterday. The first one was I had to learn how to split strings but that was very easy by reading the documentation. Then I needed to figure out how to create a new LINQ query with multiple where clauses. Back to the documentation and within minutes I yet again fell in love with LINQ. As I was adding this new LINQ statement, I was chatting with the mapping engine developer and he told me he worked on LINQ while at Microsoft. I quickly told him, he was now in the circle of trust as my favorite Microsoft developer. I have only met a handful of Microsofties but I have never lived in that part of the country either. Doesn't matter as still anyone involved with LINQ is near the top of useful people.

Another lesson while changing to use the new mapping engine API, was to learn how to read a file from the file system using Windows.ApplicationModel.Package.Current.InstalledLocation. That is interesting since working on web sites for so long you just forget that you can actually read and write files!

Everything considered, yesterday was a huge success so it was a very happy day. I was able to take a break and play tennis also since it was a nice spring day in the middle of December.

The hardest thing all day this morning was fixing images. I still do not have them working as I would like but I quickly made PNG files so I could verify my layers were displaying properly for the data values. I find that the easiest thing to do is use Gimp or Inkscape on my Mac, check the files in and then go to Windows and use Git to retrieve the files and then add them to my project. So much easier than waiting for SkyDrive which is not the speediest tool in the shed.

Thursday, December 5, 2013

From concept to reality in 6 weeks - part 14

Whoever came up with the idea that 13 is an unlucky number? What does luck have to do with anything? I just don't believe in luck has to do with anything. I used to avoid even saying the word. All I know is that yesterday was the 13th day on this Windows 8 app and it was my most productive day so far!

Today is the big day when I switch from using Bing Maps to a different 3rd party mapping engine. I received new DLLs yesterday for the mapping engine but ran out of time to try it out in my app. I did try it out late last night to make sure the sample project I was given definitely works. This morning when I woke up early I found a newer version waiting for me, including a new vector map that is much better than the one we used in the iPad app. There is a lot more working today than yesterday and I was told that I would receive new builds each morning. The lead developer basically works all night long and I work all day long, so we have 24 hour coverage on this app.

I looked at the mapping engine example code and know exactly what I need to do. The one big exception is I must figure out how to add dynamic images which I create from a my icomoon custom font that contains the map marker symbols. I ran out of time yesterday to get that working on Bing Maps. The code I wrote will work in both cases, so that is where I will begin this morning.

But first now that I have two different maps, it is time to learn how to use C# interfaces. I want a single interface implemented in two different ways. I would also like to store some static properties in the interface that are constants I need in all implementations. To the documentation I go and I find a good explanation of how interfaces work in C#. I also find that C# supports properties in interfaces so that is all I need to begin. Turns out that you cannot have properties in an interface after all. Not exactly what I meant by static properties across all implementations so that is not going to work for me.

Now I am back on the task of figuring out how to create a dynamic image bitmap. The problem is that this is very easy in Windows desktop apps as I have done this before many years ago and I find articles explaining how to do create dynamic images but it does not work in Windows Store apps. I also cannot use the Bitmap class directly as it is not supported either. Bummer. Basically I cannot use anything in System.Windows.Media.Imaging as Windows Store app can only use Windows.UI.Xaml.Media.Imaging. The good news is that I learned that lesson already, so now all I need to do it figure out how to do what I want. In the correct package I see something promising called WriteableBitmap class. It appears that this is a very common question and the only solution I have found so far is to use DirectX, which just seems so wrong. I am giving up and creating images that I can then transform to whatever color I want as I just have not found any solution to my problem.

The big decision today was to go ahead and purchase the Hobbyist license of Telerik XAML Windows 8 controls since I can use that for the range slider without writing one from scratch.

I was able to get some of the data displaying on the mapping engine. I have been struggling all day trying to get images to display correctly on the map and now I am getting a very odd runtime exception that I do not know where it is coming from. That all will have to wait until tomorrow as it is time to go running for the 4th day in a row as I seriously need a break right now.

Wednesday, December 4, 2013

From concept to reality in 6 weeks - part 13

Today is a brand new day and several things are planned for the day. I need to create some new SVG symbols for my map markers and then added them to my custom font. I then need to get the rest of the data to display on the map with dynamic colors per each marker. I then need to load the latest build for the mapping engine and see if I can get the markers to display on it. I then need to look into buying a 3rd party set of controls from Telerik since they have a dual range slider that may just work out of the box. I downloaded the RadControls demo trial on my Windows laptop and it looks like it will work. I also like their date picker as it looks good and is very similar to the Apple iOS7 date selector.

First thing up is to get the rest of the map markers displaying in different colors. It was easy to put the markers on another layer on the Bing Map. It was a bit of work to get the push pins to be different colors depending on the elevation. I have not gotten custom images on the map yet as that will be my first chore for tomorrow morning. I have my font ready to go but ran out of time to use it. I really want to use the FontIcon class but really wonder if the Bing Map will allow it as a child of a map layer. I may have to use one of the Windows.Graphics.Imaging classes instead and learn how to draw into a bitmap from a font symbol, now that does not really sound like fun.

I also had to learn about formatting doubles since I needed to show some details when a map marker was tapped, but I wanted to show numbers in a reasonable format like "12,345" with the thousands separator. I had to look in two places as the Double.ToString method was a great start and then I found this beauty that lists all of the Standard Numeric Format options. That gave me everything I ever wanted to know about formatting in Windows apps.

Next up is learning how to use LINQ to build dynamic queries in-line as I wanted to show some statistics on the data that was loaded. Before I could use them I had to convert my old school Array code to use a List Generic. Then I directed by a co-worker to the LINQ cheat sheet that just made my day. I was then able to find the count of a couple of properties and the date range of the data that was loaded very easily in just a couple of simple and readable statements.

I did not write down much today but I was so excited when I had all of the data showing up on a Bing Map that I forgot to record what I was doing. The above links definitely describe all of the fun I had today.

Tuesday, December 3, 2013

From concept to reality in 6 weeks - part 12

I had to take a break yesterday afternoon to catch up on my physical exercise and then had to help my daughter with her senior class project on Hamlet. I know there are many people who love Shakespeare, but I am not one of them as it is absolute torture to read his stuff. It is not the content because that is absolutely amazing but it is a language issue. It might appear to be English but it is not what I speak or read. The only way I could help her was to use the Sparknotes version that shows the original old English on the left and the what they heck it means in today's real English. This is kind of what I have been dealing with so far in the first 12 days as Windows 8 might appear to be a computer platform but it has changed so much that I need Sparknotes to help me out and the equivalent would be the Microsoft Developer Network (MSDN) documentation.

Today I had to send an email to the mapping engine man on a couple of issues I found around Victoria Island at the Canada - USA border above Washington State. Now I am back to finishing off the JSON processing and today I am going to get the some data showing up on a Bing Map as I am not going to sleep until I do!

I think I am finally getting the hang of this. I can find the C# class or XAML documentation I need. Most of the time I can write the C# code I need to handle strings or doubles or JSON without looking up what I need. One thing I have not tried is to locate the documentation within VSE itself as I normally use Safari on my Mac. I also use my Mac in case I find something interest so I can save it in this blog easily. Yesterday I had to go back to my blog posts three times looking for information that I knew I had encountered previously but could not recall where I found it. It may take extra time to blog but it helping me as I am a Windows 8 team of one.

I am getting the hang of this - I have all of the JSON being parsed and it is only 9 am. Sounds like it is going to be geographic mapping for the rest of the day. These were very useful in setting default empty values for doubles and dates to differentiate between empty and valid values. It took me 2 more hours to validating that I was processing all of the data correctly. The way I finished this that was to read the JSON data asynchronously, processing the data and store into DAO objects and then implement a ToString method that takes the DAO objects and output JSON. The beauty of this method is that I have the whole round trip tested manually at least. Now I am 100% confident that adding the data to a Bing Map will work as everything is GPS coordinates. It is time to re-login into the Bing Maps Portal to learn about the API...

At 1pm in the afternoon I saw my push pins on a Bing Map. There are several keys to success. The first thing is figuring out what classes exist in a Windows Store app. If the class is not listed on under the Windows API reference for Windows Store apps, then forget about it as it will not exist or work. The default markers were light blue with a double thick border with text that was nor readable in the markers. The real ticket was learning how to create Bing MapLayer and then place a bunch of Bing Map Pushpins on the layer. The real beauty of the documentation is that is shows how to add a tap event to the push pin to show more information which is exactly what I need to do. Now I know exactly how to put all of the data on a map as I will create a second layer tomorrow for the rest of the data.

I am going to call it a day and attempt to exercise for two days in a row.

My son's art work

This is what my oldest son Nathan produced in two weeks and these are just the best of highlights:















Monday, December 2, 2013

From concept to reality in 6 weeks - part 11

I am skipping part 10 since yesterday was like a whole day's work when I intended to only work a half day. Since I have worked two half days that has to count for a whole day. Since I was working with someone else yesterday I did not keep up the blog while working with him, so a little catch up first.

I committed the cardinal sin of Windows development in that I had no rebooted my computer a single time since installing the initial patches to get the machine working. What was I thinking? Did I think that things were magically fixed by moving to Windows 8? It finally bit me as I could not build a deployable Windows 8 app as VSE complained that the simulator was running. I doubled checked all of the processes using Task Manager and it was definitely not running. I closed VSE and reopened it and nothing was fixed. I was working with the mapping engine lead developer and I showed him the message. He immediately told me to reboot my Windows laptop. He said he has to reboot his machine multiple times a day as the Visual Studio Professional that he uses gets slower and slower during the day's usage. Then I remembered what I was working on. I used to work at a company that had a policy that every one had to reboot their computer each evening - the justification was so they could install nightly patches on the whole company intranet and did not want anything running that would prevent the installers from succeeding. I am going to have to remember to reboot my Windows 8 machine every weekend whether I want to do it or not.

Rebooting definitely fixed part of my problem, but I had to look up the error code on the MSDN error page to determine what the message meant and it showed 0x80073D05 as the error code. The last error I saw when I gave up was 'Could not copy the file "obj\x86\Release\Bing.Maps\Themes\Generic.xbf"'. That message is odd since I had commented out the Bing Maps to switch temporarily to the mapping engine in my MainPage.xaml file. I am going to forget about that for now as I was trying to make a release build to give to the mapping engine developer to see if it worked for him. He did the amazing thing of getting Windows 8.1 to work from BootCamp on his Mac. He did say if he had to do it all over again he would not do it as it was very painful and not worth it. He also made an executive decision to use the ANGLE open source project which maps OpenGL on top of DirectX on Windows, which greatly sped up his development time.

When I clean my VSE project, I have to remember that I must manually copy the mapping engine DLL files from "bin\x86\Debug" to "bin\x86\Debug\AppX" folder temporarily until they fix the reference dependencies to work correctly in VSE. Now I am getting another seemingly unrelated error so I am reboot to start from a fresh slate this morning since we were doing all kinds of interesting things last night to get the mapping engine working and for me to make a release build.

After rebooting I was able to run the app once and the second time I ran it I got a dreaded error message:
An unhandled exception of type 'System.AccessViolationException' occurred in ...
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
What that means is that it is time to send this to the mapping engine developer and switch back to Bing Maps so I can finish the JSON parsing today.

As of this morning, I have someone else helping me build a custom component for a dual range slider! That is great news since he is also a Windows developer and can help me when I get stuck on other tasks. Now I am feeling better already. We connected using Skype from my Mac but I could not get the microphone to work on Skype on my Windows laptop. That is when I gave up and switched to GoToMeeting as I knew he could help me get that to work where I failed last week. We also worked thru issues of me showing my screen from the Windows laptop. I was trying to use the GoToMeeting from the Windows Store, but when I switched to using the http://gotomeeting.com site then I was able to login and then change presenter from my Mac to my Windows machine. The only problem I encountered was the display was truncated at the bottom so I had to go into the PC Settings for the Display and reduce the resolution. It was good enough for a short demo.

Now I have the fun of trying to find my NullReferenceException that is causing the app to crash when I download the server data. I search for help in Mrs. Google and found an article that has the great keyboard accelerator that is really hard to type : Esc + Ctrl + Alt + E. I added a checkbox for "Common Language Runtime Exceptions". Enabling that immediately found the problem - I remember having to do that a long time ago in a Java land far far away. I also had to do it with Adobe Flex development. That just seems like a very long time ago and I am not happy to have to go back there again.

Once I fixed the problem with my initialization of the active downloads array by moving it into the constructor, I moved onto the parsing the JSON which I had written but could not verify yet because of the exception. I had a couple of conversion issues that I had to deal with as I thought the JSON had numbers but they were strings and vice versa. Nothing a couple of IF statements won't fix like the following by looking at the JsonObject Class documentation:
JsonValue value = jsonObject.GetNamedValue("id");
Id = (jsonValue.ValueType == JsonValueType.Number) ? value.GetNumber() : value.GetString();
The next JSON issue I had to deal with was one of the values can have a value of "null". It is a shame I have to deal with all of these edges cases, but if I don't then I have to deal with exceptions. Let me see, that is a hard decision. OK - I decided I need to check for NULLs like this:

jsonObject["id"] = (Id == null) ? JsonValue.CreateStringValue("") : jsonValue.CreateStringValue(Id);
Now I have 2 of the 3 APIs working by calling the server asynchronously, process the response as JSON, store into DAO objects and then call ToString() to verify they look OK. Now I am making serious progress, except I left the most difficult one for the end. I was building up my confidence to make sure I understood how to process JSON before tackling the tough one.

I must say that listening to Mark Knopfler and Chet Atkins playing together on "Neck and Neck" definitely makes working on Windows more pleasant. I used to listen to Chet Aktins when I was a kid and he got me hooked on playing guitar.

The last JSON is definitely non-standard but at least now that I am an C# JSON parsing expert, I can definitely finish the parsing later today when I get home. A couple of interesting things I learned today, how to parse a DateTimeOffset and the standard date time formats available in C#.

I need to take a break and do some physical exercise like running.