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.


No comments: