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.

Sunday, December 1, 2013

From concept to reality in 6 weeks - part 9.5

After an shockingly bad Thanksgiving break, I need to quickly recover and focus on the task at hand of getting the app done as I have exactly five weeks left before the deadline hits. Really I am at day 10 since I have day 8.5 and now today is day 9.5. Of course that is not 25 days like it would seem as I have Christmas and New Year's Day breaks in there to deal with. I do have the weekends if I have to catch up for lost time. So let's just pretend I have 25 days left. Let's quickly recap what is working I have done so far:

  • Day 1 - working Windows 8 laptop
  • Day 2 - development environment Windows 8.1 SDK working on laptop
  • Day 3 - Bing Maps displaying
  • Day 4 - retrieve data from remote server
  • Day 5 - learn Metro UI & 3rd party component libraries
  • Day 6 - use single bottom AppBar
  • Day 6.5 - learn how to submit app to Windows Store
  • Day 7 - custom icons & fonts + deliver 1st iteration to customer
  • Day 8 - component framework lifecycle to learn about dialogs
  • Day 9 - retrieve live data from secure server and process as JSON
So that brings us up to today as I need to finish the JSON parsing, but first I need to make sure I understand how to get the free 3rd party component library I downloaded to work in my app. Last week I downloaded the free license and was not able to get the Perpetuum demos to work. This morning I am going to start that process one more time. There are a couple of reasons why I need to get this working today. I have received daily messages from the developer working on our 3rd party mapping engine and I need to meet him this evening to try to get his stuff working on my machine. I really need to make sure I know how to do this with another 3rd party library first.

I went back to look at the two emails I received from Perpetuum Software which were in response to me not getting their demos to work. It was a free license which means I get no support, but I really thought it was in their best interest to at least help me a bit with their demos since they came with no documentation. The first thing I did was add the original demo project and license files on my SkyDrive from my Mac. Then I deleted the project I had on Windows and started over. I had to retarget the project to Windows 8.1. I then opened the "App.xaml.cs" file and added my free license on the correct line and uncommented out the line. I rebuilt the project and saw the same error but then it went on to build the project.
Error occurred while restoring NuGet packages: System.ArgumentException: The path is not of a legal form
I pretended to not see that error and then ran the project file and it worked. Now I am feeling like I am off to a good start for my half day today!

I then went back into my email to look at the 2nd message on how to get the Perpetuum components to work in my app. I was told to find the DLL folder in the PerpetuumSoft.Controls.Demo project and copy that into my app project, so I followed those directions. I then right clicked on References and clicked on "Add Reference..." and then opened the Browse section on the left and clicked on the "Browse..." button. I then navigated to the PerpetummDll folder I created and added the PerpetuumSoft.Controls.dll and PerpetuumSoft.WinRT.Framework.dll, which resulted in PerpetuumSoft.Controls and PerpetuumSoft.WinRT.Framework showing up on the References section. I then opened my App.xaml.cs file and on the first line in the App constructor, I started typing "perp" and VSE completed PerpetuumSoft and kept completing until I had the following:
PerpetuumSoft.WinRT.Framework.Licensing.LicenseManager.SetKey(@"");
I then added the contents of the email I received with my license key between the double quotes. I rebuilt my app and received no errors. I did not use any of the components but at least it is building. That is good enough for now but eventually I will use their calendar and dual range selectors, so I switch back to finishing off the JSON parsing...

A couple of new lessons to learn at the beginning before I start. First is how to create an abstract method that I implement in subclass? I need to declare the method as "public abstract Process(string text)" in the parent class and then in all subclasses I need to declare it as "public override Process(string text)". That makes sense - I just needed to re-learn how to do it. Next I have to learn how to compare two strings. I first tried string.Equals(string) but that was a failure to compile. I looked up the String class and found a static Compare method so I tried that but it failed in the very same way:
The best overloaded method match for "string.Compare(string, string)" has some invalid arguments
 That is an odd message since this is exactly how the documentation says it should work. Then I look at the second error associated with the same line, which is
Argument 2: cannot convert from 'method group' to 'string'
Then I remember that I forgot to add "()" when calling a method as it was trying to pass a method to the Compare function. That is going to get me every time until I remember it unfortunately. But the good news is that all of my changes compile. Now I need to implement one of the process methods to make sure the JSON I retrieve from the server will be stored correctly in my DAO objects I created on Day 9. That means I need to learn how to process and array of JSON objects as well as how to change the ToString method so I can see the results of my parsing. I also need to know how to work with C# Arrays. If I can going to do all that then I need to know how to concatenate strings to show arrays within my ToString method. That should take care of my learning for the day as I will put all of that into action for my JSON parsing and checking the results.

I definitely fixed one bug where I was calling "await" in the wrong place. I found this article which describes how to determine the state of the app in the main App.xaml.cs file. In that method I called:
MainPage.Current.WaitForDownloads();
Which is very simple and checks for out standings running tasks:
public async void WaitForDownloads() { await DiscoverActionDownloadsAsync(); }
The method being called is very similar to the code I found in the Background Transfer sample code, with the primary different being how to output is logged.

Unfortunately, now two of my remote server calls are returning JSON but when I process the first JSON response I am getting a "System.NullReferenceException", but I have no clue where that occurred since the VSE debugger stops in a place that does not help me at all as it is in an "await" block. I went to the DEBUG menu and look under the Windows sub-menu and selected "Call Stack" to see that helped me but it did not. I went back into the debugger and inspected DownloadOperation variable to see the RequestedUri and now I know which server request is the one that fails. It turns out that is the one I have not written yet but I double checked the code and I don't see what the problem is. I set a break point in the code where I parse the results and it did not get to there yet.

Time for tennis so this will have to wait until tomorrow.


Wednesday, November 27, 2013

From concept to reality in 6 weeks - part 9

I am starting to get a bit worried about my abilities to deal with Windows 8 as it is quite overwhelming at the moment. There is just too much to learn and not enough time, which means if I panic about this fact then it will only get worse. This has happened to me many times before in my 30 years so I just need to calm down and take it one day at a time. Eventually it will all fall into place. The good news for today is that I received email late last night that the mapping engine is partially working on Windows 8. I have full confidence in that team as I have worked with 3D geniuses before and they have to be the smartest people on the earth. There is just something about thinking in 3D and dealing with transformations and matrix algebra for a living that elevates their minds!

Right now I have to come back to the practical and make a decision. Do I load the data from a button click or try to finish the full API to load the data? Since the mapping engine is progressing so quickly, I think I need to get some data working on the map, which means I need to read the data from the server and populate some objects so I can draw them on a map. I don't need the UI right now as I can hardcode the data retrieval for now. Time to switch gears. Before I do that I need to get the project building again as I was so tired yesterday that I just had to give up and call it a night. Plus I had several of hours in the evening that I had to work on some marketing literature to give to a potential client. But today is a new day so time to start out on a positive note. Since I am a morning person it is much easier for me to thing clearly in the early morning so starting out at 5am when it is dark and quite suits me just fine.

I need to read a bit more about Data Binding before I totally give up on the UI changes I was trying to make to show the data load dialog. New plan - I have tons of working examples to compare to my project and find out what I am doing wrong in loading multiple pages from a selection list. That is a common paradigm that runs thru all of the example so this should be solvable by looking at any complex example. Even newer plan - bring up the example code on my Mac and then compare the project code on my Windows laptop since I am still at home and do not have the super fancy monitors like at work. That did not take long to find the missing piece. The Microsoft examples all come with the common folder that contains a class called "LayoutAwarePage" which contains all of the logic that I was missing to navigate between two pages. It is very involved so I certainly do not want to reinvent the wheel and just need to use it so I can get past my compile issues and see my pages working. But wait, there is way more to this than it appears on the surface. The example code uses a whole different paradigm to load secondary pages so I need to learn how to do this the correct way using VSE. Now I am giving up temporarily and going to get the data loading without a UI.

So far having spent half of the day trying to get the data from the secure server within the project I created. I keep getting a build error 'Could not copy the file "obj\x86\Debug\Bing.Maps\Themes\Generic.xbf" because it was not found'. I find if I try the use F7 to rebuild that most times it will work. Only two times did that not work so in those cases I had to clean the project and rebuild it from scratch. Odd that I have been seeing these messages today. I wonder if it has something to do with me running multiple VSE and apps in the debugger at the same time? I don't believe that is it because only my project uses Bing Maps.

Many hours later I have the the code completed that retrieves the 3 parts of the data from the secure server and saving the results to 3 different files. I have been learning way more about C# than I ever thought or wanted to know. In order to get the model code to work I had to learn about calling a super class, which has to be the most odd syntax I have ever see. On the method you have to add " : base()" and if the parent method or constructor requires then those have to be passed into "base()". Creating an abstract class, and protected variables is very straight forward. I kept struggling with how to show debug statements to the debugger output window. The code really changes depending on the target platform and the language used to build the Windows app. I kept finding code that did not compile. Finally I discovered the correct package as I had to add "System.Diagnostics" and then I could call "Debug.WriteLine". I then had to learn about "String.Format", which is very similar to other languages on formatting string given arguments. I then had to learn about DateTimeOffset class as I had to do some time math. It was not the easiest way I have seen as Ruby beats them all with beautiful things like "3.days.ago" or "2.hours.from_now". That is just so easy as it should be. I had to learn about switch statements, well I didn't actually have to but I wanted to instead of using a series of IF/ELSE statements. I spent way too much time trying to debug a problem with using a MessageDialog from within a background thread. I was close but then I would encounter a run-time error occasionally so I abandoned that for Debug.WriteLine as it was only for debug. Eventually I need to add a progress bar to show as data is being retrieved and loaded onto the map, but NOT today. There is only way to show a message dialog and that is using an "await" statement preceding the "ShowAsync()" method call. To make sure this can be done in a background thread you have to add this magic code:
var ignore = this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () => { await messageDialog.ShowAsync(); } 
I know it is complicated to do such things as it is not much easier in iOS as there is special Apple magic there as well. This kind of code just makes me want to start my Thanksgiving break earlier!

I also learn about Exceptions and try/catch/throw, which is basically the same in all languages I have used, so that knowledge transferred nicely. I went back into my C# class files and cleaned up all of the imports, which is very similar to how that is done in Java. I am kind of disappointed that VSE does not add the "using" statements automatically as that would be very helpful. As it is I have to go searching all over the planet for the location of the class I want to use. That is why it took me so long to find the Debug statement.

Now that I have the data on downloaded from the server, I need to process the JSON data and store it into objects. It is amusing how every framework has it's own terminology for the model objects. Windows loves the term DAO. I am not a fan but I just don't run in those circles. Turns out it is pretty easy to get the data into objects as Windows 8.1 has a very nice JSON supporting library. I even saw a reference to the Apple iOS documents in one of the Microsoft class library document pages today. I cannot remember which one it was but I found it amusing. The only tricky part was getting the JSON list of objects to be stored in an ObjectCollection. I may have to wake up a bit early tomorrow so I can finish it off before going to a special Thanksgiving meal.

It just never fails. I was super frustrated yesterday and felt little progress was made. I tried to calm down and start all over today by throwing away most of what I had done yesterday and chalking it up to a learning experience and it certainly helped. Today I got the API working as I wanted to finish that this week. I still have nothing showing up on the map so that will have to wait for another day next week. The only unsolvable problem I had today was I wanted to show my customer what I had working but GoToMeeting works on my Mac but when I downloaded the app from the Windows Store it only let me join the meeting. I could not change presenter to my Windows laptop. I tried to exit and it still showed me as being off line. I will have to try to solve that problem before our iteration meeting next week.