Improve images caching

Improve error reporting
Implemented IsolatedStorageExplorer feature
This commit is contained in:
2011-04-13 06:52:25 +03:00
parent a297460f37
commit 72c1bbdcfc
7 changed files with 144 additions and 50 deletions
+47 -5
View File
@@ -16,6 +16,7 @@ using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Phone;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Net.NetworkInformation;
using Microsoft.Phone.Shell;
using MyFriendsAround.WP7.Model;
using MyFriendsAround.WP7.ViewModel;
@@ -53,6 +54,21 @@ namespace MyFriendsAround.WP7
//register ViewModelLocator
Container.Instance.RegisterInstance(typeof(ViewModelLocator), "ViewModelLocator");
Container.Instance.RegisterInstance<ILocationService>(new LocationService(), "LocationService");
NetworkDetector.Instance.OnNetworkOFF += new EventHandler<NetworkAvailableEventArgs>(Instance_OnNetworkOFF);
NetworkDetector.Instance.OnNetworkON += new EventHandler<NetworkAvailableEventArgs>(Instance_OnNetworkON);
}
void Instance_OnNetworkON(object sender, NetworkAvailableEventArgs e)
{
ViewModelLocator locator = Container.Instance.Resolve<ViewModelLocator>("ViewModelLocator");
locator.Main.IsBusy = true;
}
void Instance_OnNetworkOFF(object sender, NetworkAvailableEventArgs e)
{
ViewModelLocator locator = Container.Instance.Resolve<ViewModelLocator>("ViewModelLocator");
locator.Main.IsBusy = false;
}
@@ -68,6 +84,9 @@ namespace MyFriendsAround.WP7
// This code will not execute when the application is reactivated
private void Application_Launching(object sender, LaunchingEventArgs e)
{
#if GPS_EMULATOR
IsolatedStorageExplorer.Explorer.Start("localhost");
#endif
DispatcherHelper.Initialize();
LoadModel();
}
@@ -76,6 +95,9 @@ namespace MyFriendsAround.WP7
// This code will not execute when the application is first launched
private void Application_Activated(object sender, ActivatedEventArgs e)
{
#if GPS_EMULATOR
IsolatedStorageExplorer.Explorer.RestoreFromTombstone();
#endif
DispatcherHelper.Initialize();
LoadModel();
}
@@ -104,15 +126,16 @@ namespace MyFriendsAround.WP7
MainViewModel mainModel = this.RetrieveFromIsolatedStorage<MainViewModel>();
if (mainModel != null)
{
mainModel.IsBusy = false;
mainModel.GpsLocation = Location.Unknown;
mainModel.GpsStatus = GeoPositionStatus.NoData;
Container.Instance.RegisterInstance<MainViewModel>(mainModel, Constants.VM_MAIN);
}
else
{
Container.Instance.RegisterInstance<MainViewModel>(new MainViewModel(), Constants.VM_MAIN);
}
Container.Instance.Resolve<ViewModelLocator>("ViewModelLocator").Main.GpsLocation = Location.Unknown;
Container.Instance.Resolve<ViewModelLocator>("ViewModelLocator").Main.GpsStatus = GeoPositionStatus.NoData;
Container.Instance.Resolve<ViewModelLocator>("ViewModelLocator").Main.RefreshMyLocationPushPins();
Container.Instance.Resolve<ViewModelLocator>("ViewModelLocator").Main.IsBusy = false; //(NetworkDetector.Instance.GetCurrentNetworkType() == NetworkInterfaceType.None) || !NetworkDetector.Instance.GetZuneStatus();
//
SettingsViewModel settingsModel = this.RetrieveFromIsolatedStorage<SettingsViewModel>();
if (settingsModel != null)
@@ -138,7 +161,14 @@ namespace MyFriendsAround.WP7
void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
//LittleWatson.ReportException(e.Exception, string.Empty);
ShowException(e.Exception);
if (e.Exception is WebException)
{
MessageBox.Show(e.Exception.Message);
}
else
{
ShowException(e.Exception);
}
if (System.Diagnostics.Debugger.IsAttached)
{
@@ -150,8 +180,20 @@ namespace MyFriendsAround.WP7
// Code to execute on Unhandled Exceptions
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
#region Error Logging
//LittleWatson.ReportException(e.ExceptionObject, string.Empty);
ShowException(e.ExceptionObject);
if (e.ExceptionObject is WebException)
{
MessageBox.Show(e.ExceptionObject.Message);
}
else
{
ShowException(e.ExceptionObject);
}
#endregion
if (System.Diagnostics.Debugger.IsAttached)
{
@@ -102,6 +102,9 @@
<Reference Include="ICSharpCode.SharpZipLib.WindowsPhone">
<HintPath>..\Libs\Hammock-Binaries\.NET 4.0\Windows Phone 7\ICSharpCode.SharpZipLib.WindowsPhone.dll</HintPath>
</Reference>
<Reference Include="IsolatedStorageExplorer, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\Libs\WP7 Isolated Storage Explorer\Library\IsolatedStorageExplorer.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp">
<HintPath>..\packages\Hammock.1.2.1\lib\sl4\Microsoft.CSharp.dll</HintPath>
</Reference>
@@ -52,7 +52,7 @@ namespace MyFriendsAround.WP7.Service
}
catch (Exception ex)
{
friendscallback.Invoke(null, new FriendsListEventArgs() { Friends = null, Error = ex });
friendscallback.Invoke(null, new FriendsListEventArgs() { Friends = null, Error = new WebException("Communication Error!", ex) });
}
}
@@ -66,7 +66,7 @@ namespace MyFriendsAround.WP7.Service
}
else
{
friendscallback.Invoke(null, new FriendsListEventArgs() { Friends = null, Error = new Exception("Communication Error!") });
friendscallback.Invoke(null, new FriendsListEventArgs() { Friends = null, Error = new WebException("Communication Error!") });
}
}
@@ -102,7 +102,7 @@ namespace MyFriendsAround.WP7.Service
}
catch (Exception ex)
{
publishlocationcallback.Invoke(null, new PublishLocationEventArgs() { IsSuccess = false, Error = ex });
publishlocationcallback.Invoke(null, new PublishLocationEventArgs() { IsSuccess = false, Error = new WebException("Communication Error!", ex) });
}
}
@@ -116,7 +116,7 @@ namespace MyFriendsAround.WP7.Service
}
else
{
publishlocationcallback.Invoke(null, new PublishLocationEventArgs() { IsSuccess = false, Error = new Exception("Communication Error!")});
publishlocationcallback.Invoke(null, new PublishLocationEventArgs() { IsSuccess = false, Error = new WebException("Communication Error!") });
}
}
@@ -155,7 +155,7 @@ namespace MyFriendsAround.WP7.Service
}
catch (Exception ex)
{
publishmypicturecallback.Invoke(null, new PublishLocationEventArgs() { IsSuccess = false, Error = ex });
publishmypicturecallback.Invoke(null, new PublishLocationEventArgs() { IsSuccess = false, Error = new WebException("Communication Error!", ex) });
}
}
@@ -169,7 +169,7 @@ namespace MyFriendsAround.WP7.Service
}
else
{
publishmypicturecallback.Invoke(null, new PublishLocationEventArgs() { IsSuccess = false, Error = new Exception("Communication Error!") });
publishmypicturecallback.Invoke(null, new PublishLocationEventArgs() { IsSuccess = false, Error = new WebException("Communication Error!") });
}
}
@@ -677,29 +677,34 @@ namespace MyFriendsAround.WP7.ViewModel
if (e.Location != Location.Unknown)
{
GpsLocation = e.Location;
if (LastBoundRect != null && LastBoundRect.Intersects(new LocationRect(
new GeoCoordinate(GpsLocation.Latitude, GpsLocation.Longitude),
.5,
.5)))
{
ObservableCollection<PushPinModel> _mynewlocation = new ObservableCollection<PushPinModel>();
_mynewlocation.Add(new PushPinModel()
{
Location = new GeoCoordinate(GpsLocation.Latitude, GpsLocation.Longitude),
PinUserName = "Me"
});
MyLocationPushPins = _mynewlocation;
}
else
{
MyLocationPushPins = new ObservableCollection<PushPinModel>();
}
RefreshMyLocationPushPins();
}
System.Diagnostics.Debug.WriteLine("watcher_PositionChanged + " + DateTime.Now.Second);
}
public void RefreshMyLocationPushPins()
{
if (LastBoundRect != null && LastBoundRect.Intersects(new LocationRect(
new GeoCoordinate(GpsLocation.Latitude, GpsLocation.Longitude),
.5,
.5)))
{
ObservableCollection<PushPinModel> _mynewlocation = new ObservableCollection<PushPinModel>();
_mynewlocation.Add(new PushPinModel()
{
Location = new GeoCoordinate(GpsLocation.Latitude, GpsLocation.Longitude),
PinUserName = "Me"
});
MyLocationPushPins = _mynewlocation;
}
else
{
MyLocationPushPins = new ObservableCollection<PushPinModel>();
}
}
private void ShowMyLocation()
{
//
@@ -936,8 +941,15 @@ namespace MyFriendsAround.WP7.ViewModel
DispatcherHelper.CheckBeginInvokeOnUI(() =>
{
IsBusy = false;
var exception = new ExceptionPrompt();
exception.Show(args.Error);
if (args.Error is WebException)
{
MessageBox.Show(args.Error.Message);
}
else
{
var exception = new ExceptionPrompt();
exception.Show(args.Error);
}
}
);
}
@@ -950,8 +962,15 @@ namespace MyFriendsAround.WP7.ViewModel
DispatcherHelper.CheckBeginInvokeOnUI(() =>
{
IsBusy = false;
var exception = new ExceptionPrompt();
exception.Show(args.Error);
if (args.Error is WebException)
{
MessageBox.Show(args.Error.Message);
}
else
{
var exception = new ExceptionPrompt();
exception.Show(args.Error);
}
});
}
else
@@ -997,8 +1016,15 @@ namespace MyFriendsAround.WP7.ViewModel
DispatcherHelper.CheckBeginInvokeOnUI(() =>
{
IsBusy = false;
var exception = new ExceptionPrompt();
exception.Show(args.Error);
if (args.Error is WebException)
{
MessageBox.Show(args.Error.Message);
}
else
{
var exception = new ExceptionPrompt();
exception.Show(args.Error);
}
});
}
else