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.

Friday, January 3, 2014

From concept to reality in 6 weeks - part 29

I will have to work on the filter changes again today as I was not able to finish them all yesterday. The big problem I encountered yesterday was that I switched the Telerik RangeSlider from "PointerReleased" to "PointerMoved". Doesn't sound like a big deal as it actually does what I want but I receive tons of extra events when the pointer in fact has not moved so now my #1 priority to figure out why and prevent that bad behavior.

Turns out that the event arguments I get in this callback is a standard Windows event called PointerRoutedEventArgs. So the real issue is that the pointer did in fact move by the slider thumb value did not changed. Time to read up on Telerik events and see if there is a custom event where I can get this information. I found absolutely no information on Telerik custom events so that must mean they always use the standard Microsoft Windows Store events. Time to read up on the pointers quick start guide as I am hoping to find a gem in there to help me get over the hump. That was interesting reading but did not help me as I am getting every pointer change, so I have to recognize within my code when the RangeSlider thumb has changed. That is pretty sad as I should be able to use the built in INotifyPropertyChange interface but if the RangeSlider does not implement it then listening to property changes for selection start and end will do me no good. In protest I went into my Telerik account to contact customer support and then realized the cheap license we got to save money did not come with support after the initial 30 days, so much for that. I am moving on as I have a solution not an elegant one I was hoping for.

There is nothing like taking time to test thoroughly all of the options. The last two days I have been testing all of the filtering from every imaginable angle. This is something I did not get a chance to do when in hurry up get everything working quickly mode. I must admit it feels really good to know with confidence that the filtering code is working exactly as it should be. It would not have been possible without the fixed TestData that I created previously with all know values. That was time well worth spent.


From concept to reality in 6 weeks - part 28

It is time to resume working on some of the features that I did not have time to complete for the conference that are needed in the final product. The last time I looked at this code it was 12 days ago so I need to try to remember where I was. Thankfully I recorded all of the outstanding issues in Kanbanery so I just need to resume where I left off. I worked on a couple of other projects in the meantime so I have to settle back into this Windows Store stuff as it requires a paradigm shift.

To start off the day, I picked a couple of the simple tasks so I can warm up to working in VSE and the Windows environment. It is funny how quickly your brain reverts to comfortable things like Command-C/Command-V on my Mac versus Ctrl-C/Ctrl-V on Windows. For my first issue I had to bring up Xcode and look at the Objective-C iOS implementation so that is a crazy way to start the day by then switching to VSE and C#. I survived the simple tasks so now onto the hard ones I ignored because of time pressures...

I decided to tackle all of the Telerik slider related bugs today as those seem to be the most important parts as that is where the Windows Store app deviates the most from the iPad app. Everything I ever wanted to know is in the Telerik RangeSlider documentation as the problems I am seeing are all related to configuration issues and not issues in the Telerik control itself, mostly related to snapping and tick mark locations. I did not actually write any of that code as I farmed that out to someone else when I got in a time crunch so now it is time to learn how it was built using reusable components and style resources. This is going to be a good lesson to learn as I skipped that part of building a Windows Store app.