Wednesday, January 15, 2014

From concept to reality in 6 weeks - part 36

This was not the way today was supposed to start out. I have had issues with my Mac Mail app and when I tried to send email this morning, I keep seeing the emails pile up in my Outbox. That was not supposed to be doing that for sure. I have two email accounts that I use that are tied to my HostMonster domains. After a struggle, I decided to delete the two internet accounts and just start over. I first went into HostMonster and changed the email passwords just to be safe that it was not password issues. I added both email accounts back in and they still did not work. I then went back into my HostMonster account and decided to look more closely at the settings and I had added the non-SSL accounts so once again I deleted both accounts and added them back in as SSL accounts. Then after Mail.app crashing multiple times, which I assume were due to the email account changes, I finally have my email back up and running and the emails sitting in my Outbox were all Sent. Hopefully this is not a sign for my day.

And I am going to try to restart the day by listening to "Of Monsters and Men" on Spotify since it was very nice listening to their songs while watching "The secret life of Walter Mitty" the other day. That should put me in the right frame of mind to get my tasks done early today - or at least I can hope.

My first new thing to learn about today was now to merge two list collections into a single collection. And what came to my rescue but LINQ yet again. It is THE most useful part of C# that I have encountered so far. If I think about collections in Java, ActionScript, Ruby, and Objective-C, then LINQ is definitely number one as it makes writing code so much more readable and just makes sense to me with very little training or reading documentation.

I keep forgetting that I am using a Windows machine. Today my Windows laptop was acting really strange so I remembered that I need to reboot it occasionally. I have only reboot a hand full of times in the months since I got the machine, which sounds really good, except for the fact when I rebooted today I had several updates that were waiting for a reboot to install. Last week when I reboot I have some SONY VAIO specific patches to install and since that day I have not had the problems with my display where the touch sensors stopped working after a while. I just get in the zone after using my Mac for so long that I forget about things like that. When I logged back into my laptop this time I saw a notification that I had a new Adobe Reader available also. All kinds of updates are happening - must be the full moon day coming up tonight.

Today was pretty much testing day as I wanted to make sure the live updates were working and when new data arrives every thing still works as expected. This requires loading the initial data and then waiting for the minimum live update time for updates to arrive and do stuff while the update is happening.

Tuesday, January 14, 2014

From concept to reality in 6 weeks - part 35

The project is definitely winding down now as the end is definitely in sight. I am so immersed in this project that I think of things at night in my sleep to fix the next day and the shocking thing is that they are good ideas and have been helping.

The first thing I need to do is verify that the very same data loaded from the server on the original Java app matching the iPad app which matches the Windows Store app. The first thing that got my attention was the heading I was using on the Windows Store app seemed off. I kept looking at the app running on my iPad mini and compared it to my Windows Store app and just could not figure it out. Finally I looked at the mathematics one more time and found the problem. The font used in VSE hid the fact that a zero (0) and eight (8) look very similar. For an angle I had 100 instead of 180 which will make a big difference. I finally had all of the data loading correctly and matching so that was a major accomplishment for today. These changes also will make one of the final tasks much easier to finish. But there is more that needs to be done...

Today's task was to finish what has been bothering me for 5 days now. I got a new mapping engine build and that fixed several of my problems. I looked at the documentation and found a much better way to simulate a flight path and so finally I am done with the task that has been bothering me way to long. What made it even better was that the code was about half the number of lines and so much easier to read. Mission complete.

The end of the day has come and I have a new page for all aviation formulas that I would ever need to know or care about, even though I was told by the mapping engine lead developer that some of them are incorrect and he has 100,000 pilots that back up his argument. Let's see who shall I believe? That is not hard at all as I pick the mapping engine developer every time as he has been wonderful in every way!

Monday, January 13, 2014

From concept to reality in 6 weeks - part 34

This week means it is time to start ramping down on this project for this current phase. I have a bunch of small tasks that would be nice to have completed, but they are going to have to be delayed to the end of this phase when I am sure I have more time left. The number one priority now is to complete the last 4 tasks that have to be down and leave all of the others to the end.

I tried a couple of things this morning that did not go so well. I thought I would try to change one of the styles in the SearchBox but since this is a new component I found little information on the style classes so had to refer to an article outside the standard MSDN network. I wanted to style the selected text in the SearchBox so it was not the default bright purple color. It is a pretty minor issue, so after trying a couple of different properties I gave up.

Then I thought it would be nice to place the search popup on the right hand side and that was not possible in the XAML as it required code behind window size calculations (after referring to the Popup Placement documentation), to I made an executive decision to leave it on the top left where all of the other popup dialogs are placed in this app.

The only simple success so far this morning was figuring out how to remove elements from a List Collection. One of the lists of data I am getting from the server contains data but it is not relevant for the other data I am getting from the server, so I need to trim the non-relevent data from the collection. A really bad idea is to loop thru the collection and call Remove as that messes up the next element retrieved. I waded thru one of the MSDN blogs and found the easiest solution to understand was to loop thru all of the collection finding the bad elements and then in a separate loop remove those elements. There is probably a more elegant way but it works and I only call this method once on a small set of data so it is good enough for me.

While on a success roll, I decided I wanted to change the SeachBox queries to not match at the start but anywhere in the string. I just switched "StartsWith" to IndexOf and that was pretty much done. Before leaving the search one last time I re-read the Quick Start guide on adding a search and using a SearchBox is much more flexible than the SearchPane so that was definitely the correct decision. Time to move on...

I contacted the mapping engine lead developer to discuss a couple of missing API's late last week so I am still waiting on them. This morning I sent him one more problem as I am able to crash the Windows Store app every time when I use the Settings service. Hopefully that will be resolved this week also before I wrap up the project.

Now I get to resume working on my geographic mathematics skills by reviewing the code at the bottom of the same page I was look at last week as I need to finish the task I have been working on and off for the last 4 working days.

This is a helpful site to help me figure out the distance in nautical miles between two points to check my calculations. Then I need to do some more Date arithmetic since the server always returns dates in UTC format and I have to always show them in local time. Just before I started on that I noticed that each of my threads exit with a code of 250 (0x103), so I looked that up to make sure nothing evil was happening. The documentation said that it was "ERROR_NO_MORE_ITEMS" so that is perfectly fine since those are my server requests ending.

I had another detour as I needed to send the system dump to the mapping engineer lead developer so he can be working on the crash. I can duplicate it easily so when the app crashes, I just went to the DEBUG menu and clicked on "Save Dump As..." at bottom of the menu. The only problem was that the resulting dump file was 262 MB. The compressed size was 79 MB so both are way too large for sending it by email. They have an FTP site set up so I transferred the file from my Windows laptop using my new $9.95 8 GB thumb drive to my Mac and then used a secure copy command using the port he gave me and the username/password combination.

Back to UTC problems. If you search for "utc time" using Ms. Google then she shows the current time in UTC time. This helps me debug my UTC server issues. As I expected there is a -5 hour time difference between where I am and Greenwich, England. All I had to do to fix all of my UTC problems was always pass a UTC time to get data from the server but when displaying the date/time information, I just do the following:

DateTimeFormatter formatter = new DateTimeFormatter(Preferences.DateTimeFormat);
string startDate = formatter.Format(data.First().Add(DateTimeOffset.Now.Offset));

This is not the normal way of using the Windows Store DateTimeOffset class as it supports ways to convert time from a UTC time to local time as long as the Kind property is set correctly, but in my case that is not set so I have to do special processing. As typically happens the above code looks so simple but that took me a while to reduce what I was doing to that simple level. The first thing I did was use the Subtract method instead of the Add method and what is amusing about that is that I was debugging this problem around noon and so the numbers looked very close but were off by two hours or so it seemed. It was actually off by by 5 hours in the wrong direction.


Saturday, January 11, 2014

From concept to reality in 6 weeks - part 33

I am resuming where I left off yesterday with writing C# code using the Objective-C code as a reference - within a couple of hours I should be done and then I have the rest of the day to test and validate every thing is working correctly. I have a couple of missing mapping engine APIs so that may be a challenge but I will get it as close as possible. I contacted the mapping engine lead developer and sent him an email of the missing APIs. He said he would add them for me in the next couple of weeks so I will be patient in that regard and trust him since he is totally trustworthy and is a great developer. I am happy I got to know him better during this project.

My first attempt was a pretty big failure as the mapping engine displayed a spinning globe looking down from the north pole. At least I can learn something from this. I looked that up and the north pole means a location of 90° N so somehow my location is messed up. I got into the debugger and check the location value I was setting and it was way off, so much so I am do not even want to mention what the lat/long values are. OK, for the sake of confession I will say the value was (770+, 4337+) - I am pretty sure there is no planet where those values are correct. Now I get to track down what I did wrong. At least the heading value was correct at 255°, so at least something is correct. I think the best plan of action is to go line by line and recheck what I did and maybe I will find some problems. As I was creating the C# code yesterday I was wondering about the order of the points so maybe that is different from the iPad app, but that is not my immediate problem. There is no utility I can use so I just need to take some time and compare the files. I have Xcode up on my Mac and VSE on Windows and need to slowly look at the 330 lines of Objective-C code and compare it with the 291 of C# code.

The above two paragraphs describe what I was able to do in 3 hours of work time. Not that great, as I had so many distractions yesterday and fixing this task requires complete concentration. Today is yet another new day and it is pretty quiet around work so just the environment I need for this task. I have a late day meeting so yesterday and today will count for a full day's work so I am reusing this post.

Comparing the Objective-C to C# line by line did not immediately uncover any problems until I saw the line that I was using as a work around since the version of the mapping engine that I am using is missing a method I need. The version I borrowed from http://www.movable-type.co.uk/scripts/latlong.html required a closer look and then I found the major bug that was causing most of my problems. I was passing the latitude and longitude in degrees instead of radians, so that obviously is going to be bad news when calling trig functions! I moved all of the trig functions to a separate class so I don't have to remember such things ever again. Then as I inspected location values in the debugger I noticed NaN being returned, so that is pretty evil. In the approximation function I was using I was getting the evil NaN when I passed in the same location twice. That was easy to fix as I went back to original and that problem was fixed as quick as you can say "Not a Number".

Again I did not get to finish the feature I was working on but at last I fixe most of the problems and now it is working partially so it will have to wait for next week.

Wednesday, January 8, 2014

From concept to reality in 6 weeks - part 32

For the first time I need to really study the iPad app code to see how this one feature was implemented as it is specific to the mapping engine and I really need to do the very same thing in the Windows Store app. It is not really that difficult a feature but unlike other parts of the app, this one should be able to be duplicated by rewriting the code in C# by looking at the Objective-C code. Again when you compare the languages, they are just nothing alike. I am just going to read the Objective-C code a couple of times to understand what was done and then create the same idea in C#. My estimate is that I should be able to finish this completely in one day.

Before I got started I had to review some changes that came in last night and send feedback on them to make sure I understand the code and that the UI works correctly. It sure is nice to have someone else helping me with an isolated part of the app as creating a custom component is definitely extremely time consuming.

The toughest part of this feature is figuring out how to use a Timer in a Windows Store app in C#. Thankfully again MSDN comes to the rescue with an example. Again the hardest problem is finding where Microsoft moved the class for Windows Store app. I see numerous code examples that refer to System.Windows.Threading but that is not available in a Windows Store app, so that has been moved to Windows.UI.Xaml since this class is used in the foreground UI threads. The example had the correct code by I had to figure out the using statement that matched the timer class. I should have just copied them all into my example, but I read documentation on my Mac and then edit the code on my Windows laptop obviously. I still have not learned how to use the help within VSE to allow me to look this kind of stuff on while in the IDE. Maybe some other day for that one.

Just when I was cruising alone I got one of those crazy compiler errors that just make you wonder what in the world is going on. I have gotten so used to not seeing these kinds of errors that I forgot about them. My problem is I want to handle when a tick fires in the DispatcherTimer which is easy to define a handler but then the method signature is so different from all of the other even handlers I have used. After struggling with the code not compiling by passing in EventArgs as the second argument I looked at the documentation and found this handler requires and "object" type as the second argument. Then I had to set up another Stopwatch class so I can monitor the elapsed time to simulate movement on the map so that meant I also had to look up how to figure out the number of elapsed seconds using the returned TimeSpan class.

I just ran into a road block as I need some methods in the mapping engine that I have not used before. Since I have no documentation, I need to figure out what was available in the DLL's that I added to my project. After searching around using Ms. Google and not finding anything I gave up and opened the "References" section within VSE and double clicked on the DLL and what should appear but the Object Browser window that I could open each DLL and inspect symbols for classes and methods in my DLL's - now that is nice. Even I am allowed to search for anything in any DDLL included in my project references. But the real problem is that the functions I need do not exist, so that means I have to talk to the mapping engine lead developer or find a way around this by looking up the math myself as an estimate. So on looking around I found this absolutely wonderful site that describes mathematical formulas for everything GPS related. Once again I had to remind myself how to do a modulus in C# since Math.Mod does not exist and I am supposed to use the "%" operator instead. Maybe one day I will remember that when I no longer need to!

It is so interesting how you learn new things all the time when using a new VSE. I added a comment in the code to link to that article on the web and I saw the underline in the source code. When I hovered over the link, VSE said CTRL+click to follow the link and when I did that it opened that article in a tab within VSE. That is nice if I ever need to see that article again and so I don't need to copy-n-paste that into IE.

Another big lesson of the day is getting a range within an existing List collection which is very easy as it already supported in the millions of methods in that template class. Tons of code written today but it is going to have to wait for tomorrow to see if it is all working...

Tuesday, January 7, 2014

From concept to reality in 6 weeks - part 31

Today I need to go back and clean up the way I did the Settings as I need to move everything into it's own Preferences class so all of those settings are in one place. Then I can move onto my favorite topic of internationalization (I18N) and localization (L10N) for date/time settings. I am using a single set of default whenever I display any date/time to the user but I need to use the standard Windows Store globalization strings instead and then as the locale changes on the device it will just work perfectly so I don't need a special Setting for the time zone and date/time format. I am pretty excited about that but first I need to quickly clean up the Settings to prepare for that changes.

It took longer to completely test the change that it took to add the new class and move the code into it. So as I was reading about the ToggleSwitch yesterday there were a couple of things I wanted to try as I took the defaults for the first pass. The first thing I want to try is to customize the on/off labels and then I can use the header label and get rid of my labels. That really cleaned up my code and now I can move onto my favorite task of date/time localization.

The quick start guide is the place to start yet again as there is one called Global-Ready Formats. The place I have to start is the Remarks within the DateTimeFormatter class as it lists all of the allowed string values. The best thing about the Remarks documentation is that it also shows examples of how to use the strings. That is the best class documentation I have seen so far as it is just what I need to get my job done. The only tricky part is that the JSON data coming from the server has Date/Time information and so I need to have that format fixed to match the data and it is in a standard form of "MM/dd/yyyy HH:mm:ss", so I kept that in place but all of the other date/time output needs to be localized. For that case I had to hard code the CultureInfo to be "en-US" as documented in the IFormatProvider class, which I found by looking at the ParseExtract method which I was already using.

Then it was just a matter of switching my code from using "DateTime.ToString(format)" to call "Windows.Globalization.DateTimeFormatting.DateTimeFormatter("shortdate longtime").Format(DateTime)" - piece of cake as that was right out of the DateTimeFormatter documentation under the Examples section. Now that is all done, it is time to completely switch gears and look into a new UI component.

That means it is time to look at the List of Windows Store controls again. I think I like the Menu Flyout so I am going to use that one and see how I like the look and interaction. My other alternative is to use a ComboBox. I need a menu to be associated with a button for a couple of choices so one of those is going to work. I am pretty happy with the Button Menu Flyout so that is what I am going with. The UI is complete so now I just need to hook that up, which should be very easy because I have my friend LINQ to help me.

Just when I thought this was going to be easy, I find out that C# is not going to help me with a deep copy of the data so I have to do it myself. At least I found a StackOverflow article that helped me do this. I also get to learn about the alternate LINQ method or lambda syntax as presented in that article as this one makes more sense to me that the syntax I have been using - but just in this case as I like the SQL like syntax in all of the other cases so far. I then went back to review all of the other LINQ statements I created to make sure they were valid and I noticed that my distinct count statements were wrong and needed to be rewritten using the lambda syntax which made a lot more sense for those cases. I used this StackOverflow article to help me.

So far yesterday was a big feature completed and today was another so I am definitely going to complete this list of new features in the allotted time and budget as if that was ever in doubt. It turns out that it is in doubt with every estimate as there are always unforeseen things that come up. I also need extra time to verify everything is absolutely correct and the data presented matches what is shown in the original Java app for the same time period.

One more small task before the day ends to create a play and stop button. I want to use the standard Segoe UI Symbol font so all I needed to know what how to set the font on the button and then the actual symbol, which resulted in the following:

                         
                           

Monday, January 6, 2014

From concept to reality in 6 weeks - part 30

After a weekend break, which was not a real break since I continued to work on filtering issues for half a day on Saturday, it is now the day to complete the two remaining filter bugs. I wish I could have been done with these issues but this is such an important part of the app that I want to make sure it is all working perfectly. The last two problems as visual and relate to the location of the tick marks and labels on the Telerik RangeSliders customized for the Windows Store app. After continued struggles this weekend, I am beginning to think that maybe I am trying to force the control to do something it was no intended to do. From my experience I have done this same thing with other controls in the past so I know the request is not totally unusual. I may just have to get the tick marks and labels close enough as the working filters are the most important part and that is all working as it should be. I am going to leave that alone for today and move on.

So the big task for day is working with Windows Store app settings. So the first place to start is the generic Windows Store guidelines of Settings. Once that was read then I found probably the best quick start guide so far on how to use the new Windows 8.1 Settings service. I had to look up the ToogleSwitch class as I had not used that before and it is highly customizable. I had to look up how to set the default switch value as the IsOn property was a bit odd for me as I just assumed it I needed a slight refresher on how to define get/set accessors since the break away from C# must have caused some memory loss. I also needed to look up the best way to compare strings as well. This is kind of getting depressing that I did not remember those two things. The hardest part was figuring out how to know when the Settings flyout was closed. There is a BackClick which was easy to handle in the SettingsFlyout class.

Then in testing I found out that you can use Escape key while the Settings is up so I need to handle that case. I searched for a solution and found a sample app that did just this which really proved helpful as that just was not obvious at all. In a way it makes sense that to know when the Escape key was pressed that a global listener was needed but defining it on "Window.Current.CoreWindow" was not my first guess, second guess or ay guess for that matter. The sample app should how to have multiple pages of settings that depend on each other, which I did not need, but learning how to handle key events was a new lesson. It also required learning about Virtual Keys to check for the specific Escape key in the handler.

I then found an odd issue when the Escape was used on the keyboard and the Settings flyout went away I had a nice white outline around by AppBarToggleButton. Naturally I tried the obvious thing to do, which was remove the focus. My intuition let me down as that immediately caused an exception and when I looked up the Focus State documentation that was in the first line that doing so would cause an exception. As a work around I set focus to the main window and that fixed my problem from a keyboard stand point.

The next issue to figure out is how to know when my toggle switches have been changed in the Settings flyout. It is time again to use Data Bindings so I go back to that quick start guide. This requires a single INotifyPropertyChange interface by adding a PropertyChangedEventHandler and a very simple PropertyChangedEventArgs with the name of the property that was changed. That was not a big deal as I had dealt with those before.

The last problem was figuring out how to save my Settings once I had the flyout working correctly. That took a bit of searching but yet another great quick start article helped me understand how to solve that problem by using Windows.Storage.ApplicationData.Current.LocalSettings. After a short break in Windows Store app coding, it makes the documentation seem even better as I have had two new things I needed to do and I found the documentation to solve both quickly.

I am pretty happy that it only took me one short day to add custom preferences for my Windows Store app.