diff --git a/main/Libs/WP7 Isolated Storage Explorer/Library/IsolatedStorageExplorer.dll b/main/Libs/WP7 Isolated Storage Explorer/Library/IsolatedStorageExplorer.dll new file mode 100644 index 0000000..516d4c8 Binary files /dev/null and b/main/Libs/WP7 Isolated Storage Explorer/Library/IsolatedStorageExplorer.dll differ diff --git a/main/Libs/WPImageCaching/ImageDownloadHelper.cs b/main/Libs/WPImageCaching/ImageDownloadHelper.cs index f06092e..8b93d77 100644 --- a/main/Libs/WPImageCaching/ImageDownloadHelper.cs +++ b/main/Libs/WPImageCaching/ImageDownloadHelper.cs @@ -59,10 +59,17 @@ namespace WPImageCaching try { var response = (HttpWebResponse)transfer.WebRequest.EndGetResponse(result); + string newKey = transfer.WebRequest.RequestUri.ToString(); //Bild wurde nicht geƤndert seit dem letzten Aufruf if (response.StatusCode == HttpStatusCode.NotModified) { + if (ImageCache.imageCache.ContainsKey(newKey)) + { + ImageCache.imageCache[newKey].Expiration = (response.Headers["Expires"] != null) ? DateTime.Parse(response.Headers["Expires"]) : DateTime.Now.AddDays(EXPIRATIONDAYS); + //save updated + ImageCache.SaveCachedImageInfo(); + } Deployment.Current.Dispatcher.BeginInvoke(() => { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) @@ -80,22 +87,40 @@ namespace WPImageCaching } lock (ImageCache._lock) { - string newKey = transfer.WebRequest.RequestUri.ToString(); if (ImageCache.imageCache.ContainsKey(newKey)) { - //Setzen des Bildes - Deployment.Current.Dispatcher.BeginInvoke( - () => - { - using (IsolatedStorageFile ifs = IsolatedStorageFile.GetUserStoreForApplication()) - { - using (IsolatedStorageFileStream fs = ifs.OpenFile(transfer.Item.LocalFilename, FileMode.Open)) + bool isExpired = (DateTime.Compare(DateTime.Now, ImageCache.imageCache[newKey].Expiration) >= 0); + if (!isExpired) + { + //Setzen des Bildes + Deployment.Current.Dispatcher.BeginInvoke( + () => { - transfer.Image.SetSource(fs); - } - } - }); - return; + using ( + IsolatedStorageFile ifs = IsolatedStorageFile.GetUserStoreForApplication()) + { + using ( + IsolatedStorageFileStream fs = ifs.OpenFile( + transfer.Item.LocalFilename, FileMode.Open)) + { + transfer.Image.SetSource(fs); + } + } + }); + return; + } + else + { + if (IsolatedStorageFile.GetUserStoreForApplication().FileExists(ImageCache.imageCache[newKey].LocalFilename)) + { + //remove old image + IsolatedStorageFile.GetUserStoreForApplication().DeleteFile(ImageCache.imageCache[newKey].LocalFilename); + // + ImageCache.imageCache.Remove(newKey); + //Speichern der Bildinformationen + ImageCache.SaveCachedImageInfo(); + } + } } //Hat das Bild eine neue ID? if (response.Headers["ETag"] != null) diff --git a/main/MyFriendsAround.WP7/App.xaml.cs b/main/MyFriendsAround.WP7/App.xaml.cs index 8862abe..faa8c34 100644 --- a/main/MyFriendsAround.WP7/App.xaml.cs +++ b/main/MyFriendsAround.WP7/App.xaml.cs @@ -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(new LocationService(), "LocationService"); + + NetworkDetector.Instance.OnNetworkOFF += new EventHandler(Instance_OnNetworkOFF); + NetworkDetector.Instance.OnNetworkON += new EventHandler(Instance_OnNetworkON); + } + + void Instance_OnNetworkON(object sender, NetworkAvailableEventArgs e) + { + ViewModelLocator locator = Container.Instance.Resolve("ViewModelLocator"); + locator.Main.IsBusy = true; + } + + void Instance_OnNetworkOFF(object sender, NetworkAvailableEventArgs e) + { + ViewModelLocator locator = Container.Instance.Resolve("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(); if (mainModel != null) { - mainModel.IsBusy = false; - mainModel.GpsLocation = Location.Unknown; - mainModel.GpsStatus = GeoPositionStatus.NoData; Container.Instance.RegisterInstance(mainModel, Constants.VM_MAIN); } else { Container.Instance.RegisterInstance(new MainViewModel(), Constants.VM_MAIN); } + Container.Instance.Resolve("ViewModelLocator").Main.GpsLocation = Location.Unknown; + Container.Instance.Resolve("ViewModelLocator").Main.GpsStatus = GeoPositionStatus.NoData; + Container.Instance.Resolve("ViewModelLocator").Main.RefreshMyLocationPushPins(); + Container.Instance.Resolve("ViewModelLocator").Main.IsBusy = false; //(NetworkDetector.Instance.GetCurrentNetworkType() == NetworkInterfaceType.None) || !NetworkDetector.Instance.GetZuneStatus(); // SettingsViewModel settingsModel = this.RetrieveFromIsolatedStorage(); 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) { diff --git a/main/MyFriendsAround.WP7/MyFriendsAround.WP7.csproj b/main/MyFriendsAround.WP7/MyFriendsAround.WP7.csproj index f1a30fe..8c41e3b 100644 --- a/main/MyFriendsAround.WP7/MyFriendsAround.WP7.csproj +++ b/main/MyFriendsAround.WP7/MyFriendsAround.WP7.csproj @@ -102,6 +102,9 @@ ..\Libs\Hammock-Binaries\.NET 4.0\Windows Phone 7\ICSharpCode.SharpZipLib.WindowsPhone.dll + + ..\Libs\WP7 Isolated Storage Explorer\Library\IsolatedStorageExplorer.dll + ..\packages\Hammock.1.2.1\lib\sl4\Microsoft.CSharp.dll diff --git a/main/MyFriendsAround.WP7/Service/ServiceAgent.cs b/main/MyFriendsAround.WP7/Service/ServiceAgent.cs index f4b7102..c09ca6a 100644 --- a/main/MyFriendsAround.WP7/Service/ServiceAgent.cs +++ b/main/MyFriendsAround.WP7/Service/ServiceAgent.cs @@ -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!") }); } } diff --git a/main/MyFriendsAround.WP7/ViewModel/MainViewModel.cs b/main/MyFriendsAround.WP7/ViewModel/MainViewModel.cs index 56b9458..3cc773b 100644 --- a/main/MyFriendsAround.WP7/ViewModel/MainViewModel.cs +++ b/main/MyFriendsAround.WP7/ViewModel/MainViewModel.cs @@ -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 _mynewlocation = new ObservableCollection(); - _mynewlocation.Add(new PushPinModel() - { - Location = new GeoCoordinate(GpsLocation.Latitude, GpsLocation.Longitude), - PinUserName = "Me" - }); - MyLocationPushPins = _mynewlocation; - } - else - { - MyLocationPushPins = new ObservableCollection(); - } + 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 _mynewlocation = new ObservableCollection(); + _mynewlocation.Add(new PushPinModel() + { + Location = new GeoCoordinate(GpsLocation.Latitude, GpsLocation.Longitude), + PinUserName = "Me" + }); + MyLocationPushPins = _mynewlocation; + } + else + { + MyLocationPushPins = new ObservableCollection(); + } + } + + 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 diff --git a/main/MyFriendsAround.sln b/main/MyFriendsAround.sln index cbaabc0..dfbfc93 100644 --- a/main/MyFriendsAround.sln +++ b/main/MyFriendsAround.sln @@ -113,7 +113,6 @@ Global {67CBC824-A49E-4E9B-A947-360F3DFE65C3}.Debug|Any CPU.Build.0 = Debug|Any CPU {67CBC824-A49E-4E9B-A947-360F3DFE65C3}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU {67CBC824-A49E-4E9B-A947-360F3DFE65C3}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {67CBC824-A49E-4E9B-A947-360F3DFE65C3}.Debug|Mixed Platforms.Deploy.0 = Debug|Any CPU {67CBC824-A49E-4E9B-A947-360F3DFE65C3}.Debug|x86.ActiveCfg = Debug|Any CPU {67CBC824-A49E-4E9B-A947-360F3DFE65C3}.GPS_EMULATOR|Any CPU.ActiveCfg = GPS_EMULATOR|Any CPU {67CBC824-A49E-4E9B-A947-360F3DFE65C3}.GPS_EMULATOR|Any CPU.Build.0 = GPS_EMULATOR|Any CPU @@ -227,7 +226,6 @@ Global {BF7316A8-A2C5-4176-8D7F-672AD12F474D}.Debug|Any CPU.Deploy.0 = Debug|Any CPU {BF7316A8-A2C5-4176-8D7F-672AD12F474D}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU {BF7316A8-A2C5-4176-8D7F-672AD12F474D}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {BF7316A8-A2C5-4176-8D7F-672AD12F474D}.Debug|Mixed Platforms.Deploy.0 = Debug|Any CPU {BF7316A8-A2C5-4176-8D7F-672AD12F474D}.Debug|x86.ActiveCfg = Debug|Any CPU {BF7316A8-A2C5-4176-8D7F-672AD12F474D}.GPS_EMULATOR|Any CPU.ActiveCfg = GPS_EMULATOR|Any CPU {BF7316A8-A2C5-4176-8D7F-672AD12F474D}.GPS_EMULATOR|Any CPU.Build.0 = GPS_EMULATOR|Any CPU