mirror of
https://github.com/farcasclaudiu/myfriendsaround.git
synced 2026-06-29 05:01:59 +03:00
friends caching
small improvements
This commit is contained in:
@@ -13,6 +13,7 @@ using System.Windows.Media.Imaging;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.IsolatedStorage;
|
using System.IO.IsolatedStorage;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
|
using Microsoft.Phone;
|
||||||
|
|
||||||
namespace WPImageCaching
|
namespace WPImageCaching
|
||||||
{
|
{
|
||||||
@@ -20,8 +21,66 @@ namespace WPImageCaching
|
|||||||
{
|
{
|
||||||
private const string IMAGECACHEFILE = "imagecachefile.nfo";
|
private const string IMAGECACHEFILE = "imagecachefile.nfo";
|
||||||
internal static Dictionary<string, ImageCacheItem> imageCache;
|
internal static Dictionary<string, ImageCacheItem> imageCache;
|
||||||
|
internal static object _lock = new object();
|
||||||
|
|
||||||
|
|
||||||
|
public static BitmapImage GetImage(string url)
|
||||||
|
{
|
||||||
|
BitmapImage image = new BitmapImage();
|
||||||
|
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
|
||||||
|
{
|
||||||
|
//Wenn im Designmodus von Blend oder Visual Studio
|
||||||
|
image.UriSource = new Uri(url);
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (imageCache == null)
|
||||||
|
{
|
||||||
|
LoadCachedImageInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Prüfen auf ein vorhandenes gespeichertes Bild
|
||||||
|
if (imageCache.ContainsKey(url))
|
||||||
|
{
|
||||||
|
//Prüfen auf Gültigkeit des Bildes
|
||||||
|
if (DateTime.Compare(DateTime.Now, imageCache[url].Expiration) >= 0)
|
||||||
|
{
|
||||||
|
ImageDownloadHelper.DownloadImage(url, image, imageCache[url]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (IsolatedStorageFile.GetUserStoreForApplication().FileExists(imageCache[url].LocalFilename))
|
||||||
|
{
|
||||||
|
//Bild ist noch gültig
|
||||||
|
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
|
||||||
|
{
|
||||||
|
lock (_lock)
|
||||||
|
{
|
||||||
|
using (
|
||||||
|
IsolatedStorageFileStream fs = isf.OpenFile(imageCache[url].LocalFilename,
|
||||||
|
FileMode.Open))
|
||||||
|
{
|
||||||
|
image.SetSource(fs);
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ImageDownloadHelper.DownloadImage(url, image, imageCache[url]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//Bild noch nicht gespeichert
|
||||||
|
ImageCacheItem item = new ImageCacheItem();
|
||||||
|
ImageDownloadHelper.DownloadImage(url, image, item);
|
||||||
|
}
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
public static BitmapImage GetImage(BitmapImage image)
|
public static BitmapImage GetImage(BitmapImage image)
|
||||||
{
|
{
|
||||||
string url = image.UriSource.ToString();
|
string url = image.UriSource.ToString();
|
||||||
@@ -65,31 +124,49 @@ namespace WPImageCaching
|
|||||||
//Laden der Bildinformationen
|
//Laden der Bildinformationen
|
||||||
private static void LoadCachedImageInfo()
|
private static void LoadCachedImageInfo()
|
||||||
{
|
{
|
||||||
if (IsolatedStorageFile.GetUserStoreForApplication().FileExists(IMAGECACHEFILE))
|
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
|
||||||
{
|
{
|
||||||
IsolatedStorageFileStream fs =
|
lock (_lock)
|
||||||
IsolatedStorageFile.GetUserStoreForApplication().OpenFile(IMAGECACHEFILE,FileMode.Open);
|
{
|
||||||
|
if (isf.FileExists(IMAGECACHEFILE))
|
||||||
DataContractSerializer dcs = new DataContractSerializer(typeof(Dictionary<string, ImageCacheItem>));
|
{
|
||||||
imageCache = (Dictionary<string, ImageCacheItem>)dcs.ReadObject(fs);
|
using (IsolatedStorageFileStream fs = isf.OpenFile(IMAGECACHEFILE, FileMode.Open))
|
||||||
fs.Close();
|
{
|
||||||
|
using (StreamReader sr = new StreamReader(fs))
|
||||||
|
{
|
||||||
|
string serObj = sr.ReadToEnd();
|
||||||
|
imageCache = SerializationHelper.Deserialize<Dictionary<string, ImageCacheItem>>(serObj);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (imageCache == null)
|
||||||
{
|
{
|
||||||
imageCache = new Dictionary<string, ImageCacheItem>();
|
imageCache = new Dictionary<string, ImageCacheItem>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Speichern der Bildinformationen
|
//Speichern der Bildinformationen
|
||||||
internal static void SaveCachedImageInfo()
|
internal static void SaveCachedImageInfo()
|
||||||
{
|
{
|
||||||
IsolatedStorageFileStream fs =
|
using (IsolatedStorageFile sf = IsolatedStorageFile.GetUserStoreForApplication())
|
||||||
IsolatedStorageFile.GetUserStoreForApplication().CreateFile(IMAGECACHEFILE);
|
{
|
||||||
|
lock (_lock)
|
||||||
DataContractSerializer dcs = new DataContractSerializer(typeof(Dictionary<string, ImageCacheItem>));
|
{
|
||||||
dcs.WriteObject(fs, imageCache);
|
if (sf.FileExists(IMAGECACHEFILE))
|
||||||
fs.Flush();
|
sf.DeleteFile(IMAGECACHEFILE);
|
||||||
fs.Close();
|
using (IsolatedStorageFileStream fs = sf.CreateFile(IMAGECACHEFILE))
|
||||||
|
{
|
||||||
|
using (StreamWriter sw = new StreamWriter(fs))
|
||||||
|
{
|
||||||
|
string serObj = SerializationHelper.Serialize(imageCache);
|
||||||
|
sw.Write(serObj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ namespace WPImageCaching
|
|||||||
{
|
{
|
||||||
return ImageCache.GetImage((BitmapImage)value);
|
return ImageCache.GetImage((BitmapImage)value);
|
||||||
}
|
}
|
||||||
|
if (value is string && !string.IsNullOrEmpty(value as string))
|
||||||
|
{
|
||||||
|
return ImageCache.GetImage((string)value);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return value;
|
return value;
|
||||||
|
|||||||
@@ -8,14 +8,23 @@ using System.Windows.Input;
|
|||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Animation;
|
using System.Windows.Media.Animation;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
namespace WPImageCaching
|
namespace WPImageCaching
|
||||||
{
|
{
|
||||||
//Beinhaltet die Informationen eines Bildes
|
//Beinhaltet die Informationen eines Bildes
|
||||||
internal class ImageCacheItem
|
[DataContract]
|
||||||
|
public class ImageCacheItem
|
||||||
{
|
{
|
||||||
|
public ImageCacheItem()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
[DataMember]
|
||||||
public string LocalFilename { get; set; }
|
public string LocalFilename { get; set; }
|
||||||
|
[DataMember]
|
||||||
public string ImageID { get; set; }
|
public string ImageID { get; set; }
|
||||||
|
[DataMember]
|
||||||
public DateTime Expiration { get; set; }
|
public DateTime Expiration { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ using System.Collections.Generic;
|
|||||||
using System.IO.IsolatedStorage;
|
using System.IO.IsolatedStorage;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace WPImageCaching
|
namespace WPImageCaching
|
||||||
{
|
{
|
||||||
@@ -35,7 +36,7 @@ namespace WPImageCaching
|
|||||||
|
|
||||||
//Erstellen der Abfrage
|
//Erstellen der Abfrage
|
||||||
var wc = (HttpWebRequest)HttpWebRequest.Create(url);
|
var wc = (HttpWebRequest)HttpWebRequest.Create(url);
|
||||||
if (item.ImageID!=null)
|
if (item.ImageID != null)
|
||||||
{
|
{
|
||||||
//Prüfen, ob das Bild im Web immer noch aktuell ist
|
//Prüfen, ob das Bild im Web immer noch aktuell ist
|
||||||
wc.Headers["If-None-Match"] = item.ImageID;
|
wc.Headers["If-None-Match"] = item.ImageID;
|
||||||
@@ -62,7 +63,38 @@ namespace WPImageCaching
|
|||||||
//Bild wurde nicht geändert seit dem letzten Aufruf
|
//Bild wurde nicht geändert seit dem letzten Aufruf
|
||||||
if (response.StatusCode == HttpStatusCode.NotModified)
|
if (response.StatusCode == HttpStatusCode.NotModified)
|
||||||
{
|
{
|
||||||
Deployment.Current.Dispatcher.BeginInvoke(() => transfer.Image.SetSource(IsolatedStorageFile.GetUserStoreForApplication().OpenFile(transfer.Item.LocalFilename, FileMode.Open)));
|
Deployment.Current.Dispatcher.BeginInvoke(() =>
|
||||||
|
{
|
||||||
|
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
|
||||||
|
{
|
||||||
|
lock (ImageCache._lock)
|
||||||
|
{
|
||||||
|
using (IsolatedStorageFileStream fs =isf.OpenFile(transfer.Item.LocalFilename,FileMode.Open))
|
||||||
|
{
|
||||||
|
transfer.Image.SetSource(fs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
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))
|
||||||
|
{
|
||||||
|
transfer.Image.SetSource(fs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//Hat das Bild eine neue ID?
|
//Hat das Bild eine neue ID?
|
||||||
@@ -87,7 +119,7 @@ namespace WPImageCaching
|
|||||||
var responseStream = response.GetResponseStream();
|
var responseStream = response.GetResponseStream();
|
||||||
|
|
||||||
//Schreiben der Bilddatei
|
//Schreiben der Bilddatei
|
||||||
using (var bw = new BinaryWriter(IsolatedStorageFile.GetUserStoreForApplication().CreateFile(transfer.Item.LocalFilename)))
|
using ( var bw = new BinaryWriter( IsolatedStorageFile.GetUserStoreForApplication().CreateFile(transfer.Item.LocalFilename)) )
|
||||||
{
|
{
|
||||||
byte[] b = new byte[4096];
|
byte[] b = new byte[4096];
|
||||||
int read = 0;
|
int read = 0;
|
||||||
@@ -99,16 +131,35 @@ namespace WPImageCaching
|
|||||||
bw.Close();
|
bw.Close();
|
||||||
}
|
}
|
||||||
//Setzen des Bildes
|
//Setzen des Bildes
|
||||||
Deployment.Current.Dispatcher.BeginInvoke(() => transfer.Image.SetSource(IsolatedStorageFile.GetUserStoreForApplication().OpenFile(transfer.Item.LocalFilename, FileMode.Open)));
|
Deployment.Current.Dispatcher.BeginInvoke(
|
||||||
|
() =>
|
||||||
|
{
|
||||||
|
using (IsolatedStorageFile ifs = IsolatedStorageFile.GetUserStoreForApplication())
|
||||||
|
{
|
||||||
|
using (IsolatedStorageFileStream fs = ifs.OpenFile( transfer.Item.LocalFilename,FileMode.Open))
|
||||||
|
{
|
||||||
|
transfer.Image.SetSource(fs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
//Hinzufügen der Bildinformationen
|
//Hinzufügen der Bildinformationen
|
||||||
ImageCache.imageCache.Add(transfer.WebRequest.RequestUri.ToString(), transfer.Item);
|
if (!ImageCache.imageCache.ContainsKey(newKey))
|
||||||
|
{
|
||||||
|
ImageCache.imageCache.Add(newKey, transfer.Item);
|
||||||
//Speichern der Bildinformationen
|
//Speichern der Bildinformationen
|
||||||
ImageCache.SaveCachedImageInfo();
|
ImageCache.SaveCachedImageInfo();
|
||||||
}
|
}
|
||||||
catch
|
}
|
||||||
|
}
|
||||||
|
catch (WebException webException)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
//Nichts machen, da Bild nicht heruntergeladen werden konnte
|
//Nichts machen, da Bild nicht heruntergeladen werden konnte
|
||||||
|
Debug.WriteLine(ex.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Erstellt einen eindeutigen Namen für das zu ladende Bild
|
//Erstellt einen eindeutigen Namen für das zu ladende Bild
|
||||||
@@ -118,7 +169,7 @@ namespace WPImageCaching
|
|||||||
byte[] textToHash = Encoding.UTF8.GetBytes(url);
|
byte[] textToHash = Encoding.UTF8.GetBytes(url);
|
||||||
SHA1Managed sa = new SHA1Managed();
|
SHA1Managed sa = new SHA1Managed();
|
||||||
byte[] hash = sa.ComputeHash(textToHash);
|
byte[] hash = sa.ComputeHash(textToHash);
|
||||||
return BitConverter.ToString(hash)+extension;
|
return BitConverter.ToString(hash) + extension;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Hilfsklasse für den asynchronen Aufruf
|
//Hilfsklasse für den asynchronen Aufruf
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace WPImageCaching
|
||||||
|
{
|
||||||
|
public static class SerializationHelper
|
||||||
|
{
|
||||||
|
public static T Deserialize<T>(string serialized)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(serialized))
|
||||||
|
return default(T);
|
||||||
|
|
||||||
|
return JsonConvert.DeserializeObject<T>(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string Serialize<T>(T obj)
|
||||||
|
{
|
||||||
|
return JsonConvert.SerializeObject(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -40,8 +40,29 @@
|
|||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'GPS_EMULATOR|AnyCPU'">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<OutputPath>bin\GPS_EMULATOR\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
|
||||||
|
<NoStdLib>true</NoStdLib>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<CodeAnalysisLogFile>Bin\Debug\WPImageCaching.dll.CodeAnalysisLog.xml</CodeAnalysisLogFile>
|
||||||
|
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
|
||||||
|
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||||
|
<CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
|
||||||
|
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
|
||||||
|
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
|
||||||
|
<CodeAnalysisFailOnMissingRules>false</CodeAnalysisFailOnMissingRules>
|
||||||
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="Microsoft.Phone" />
|
||||||
<Reference Include="mscorlib" />
|
<Reference Include="mscorlib" />
|
||||||
|
<Reference Include="Newtonsoft.Json.WindowsPhone">
|
||||||
|
<HintPath>..\Json40r1\WindowsPhone\Newtonsoft.Json.WindowsPhone.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System.Runtime.Serialization" />
|
<Reference Include="System.Runtime.Serialization" />
|
||||||
<Reference Include="System.Windows" />
|
<Reference Include="System.Windows" />
|
||||||
<Reference Include="system" />
|
<Reference Include="system" />
|
||||||
@@ -55,6 +76,7 @@
|
|||||||
<Compile Include="ImageCacheItem.cs" />
|
<Compile Include="ImageCacheItem.cs" />
|
||||||
<Compile Include="ImageDownloadHelper.cs" />
|
<Compile Include="ImageDownloadHelper.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="SerializationHelper.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.$(TargetFrameworkProfile).Overrides.targets" />
|
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.$(TargetFrameworkProfile).Overrides.targets" />
|
||||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.CSharp.targets" />
|
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.CSharp.targets" />
|
||||||
|
|||||||
@@ -52,13 +52,14 @@ namespace MyFriendsAround.WP7
|
|||||||
|
|
||||||
//register ViewModelLocator
|
//register ViewModelLocator
|
||||||
Container.Instance.RegisterInstance(typeof(ViewModelLocator), "ViewModelLocator");
|
Container.Instance.RegisterInstance(typeof(ViewModelLocator), "ViewModelLocator");
|
||||||
Container.Instance.RegisterInstance<ILocationService>( new LocationService(), "LocationService");
|
Container.Instance.RegisterInstance<ILocationService>(new LocationService(), "LocationService");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static ILocationService LocationService
|
public static ILocationService LocationService
|
||||||
{
|
{
|
||||||
get {
|
get
|
||||||
|
{
|
||||||
return Container.Instance.Resolve<ILocationService>("LocationService");
|
return Container.Instance.Resolve<ILocationService>("LocationService");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -137,12 +138,7 @@ namespace MyFriendsAround.WP7
|
|||||||
void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
|
void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
|
||||||
{
|
{
|
||||||
//LittleWatson.ReportException(e.Exception, string.Empty);
|
//LittleWatson.ReportException(e.Exception, string.Empty);
|
||||||
DispatcherHelper.CheckBeginInvokeOnUI(() =>
|
ShowException(e.Exception);
|
||||||
{
|
|
||||||
var exception = new ExceptionPrompt();
|
|
||||||
exception.Show(e.Exception);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if (System.Diagnostics.Debugger.IsAttached)
|
if (System.Diagnostics.Debugger.IsAttached)
|
||||||
{
|
{
|
||||||
@@ -155,13 +151,7 @@ namespace MyFriendsAround.WP7
|
|||||||
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
|
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
|
||||||
{
|
{
|
||||||
//LittleWatson.ReportException(e.ExceptionObject, string.Empty);
|
//LittleWatson.ReportException(e.ExceptionObject, string.Empty);
|
||||||
|
ShowException(e.ExceptionObject);
|
||||||
DispatcherHelper.CheckBeginInvokeOnUI(() =>
|
|
||||||
{
|
|
||||||
var exception = new ExceptionPrompt();
|
|
||||||
exception.Show(e.ExceptionObject);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if (System.Diagnostics.Debugger.IsAttached)
|
if (System.Diagnostics.Debugger.IsAttached)
|
||||||
{
|
{
|
||||||
@@ -172,6 +162,16 @@ namespace MyFriendsAround.WP7
|
|||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ShowException(Exception ex)
|
||||||
|
{
|
||||||
|
DispatcherHelper.CheckBeginInvokeOnUI(() =>
|
||||||
|
{
|
||||||
|
Container.Instance.Resolve<ViewModelLocator>("ViewModelLocator").Main.IsBusy = false;
|
||||||
|
var exception = new ExceptionPrompt();
|
||||||
|
exception.Show(ex);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#region Phone application initialization
|
#region Phone application initialization
|
||||||
|
|
||||||
|
|||||||
@@ -16,9 +16,14 @@ namespace MyFriendsAround.WP7.Service
|
|||||||
|
|
||||||
static ServiceAgent()
|
static ServiceAgent()
|
||||||
{
|
{
|
||||||
baseUrl = "http://myfriendsaround.cloudapp.net/myfriends";//live azure
|
#if GPS_EMULATOR
|
||||||
//baseUrl = "http://127.0.0.1:80/myfriends";//running in local azure emulator
|
baseUrl = "http://127.0.0.1:80/myfriends";//running in local azure emulator
|
||||||
//baseUrl = "http://localhost.:55672/myfriends";//for local asp.net mvc use
|
//baseUrl = "http://localhost.:55672/myfriends";//for local asp.net mvc use
|
||||||
|
#else
|
||||||
|
baseUrl = "http://myfriendsaround.cloudapp.net/myfriends";//live azure
|
||||||
|
//baseUrl = "http://localhost:80/myfriends";
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region GetFriends
|
#region GetFriends
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Device.Location;
|
using System.Device.Location;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
@@ -57,8 +58,18 @@ namespace MyFriendsAround.WP7.ViewModel
|
|||||||
public MainViewModel()
|
public MainViewModel()
|
||||||
{
|
{
|
||||||
GpsLocation = Location.Unknown;
|
GpsLocation = Location.Unknown;
|
||||||
|
_SelectedFriend = null;
|
||||||
|
|
||||||
//
|
//
|
||||||
MainLoadCommand = new RelayCommand(() => MainLoad());
|
MainLoadCommand = new RelayCommand(() => MainLoad());
|
||||||
|
BackKeyPressCommand = new RelayCommand<CancelEventArgs>((args) =>
|
||||||
|
{
|
||||||
|
if (IsSelectFriend)
|
||||||
|
{
|
||||||
|
IsSelectFriend = !IsSelectFriend;
|
||||||
|
args.Cancel = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
PublishLocationCommand = new RelayCommand(() => PublishLocationAction());
|
PublishLocationCommand = new RelayCommand(() => PublishLocationAction());
|
||||||
NavigateToSettingsCommand = new RelayCommand(() => NavigateToSettings());
|
NavigateToSettingsCommand = new RelayCommand(() => NavigateToSettings());
|
||||||
RefreshFriendsCommand = new RelayCommand(() => RefreshFriends());
|
RefreshFriendsCommand = new RelayCommand(() => RefreshFriends());
|
||||||
@@ -194,12 +205,8 @@ namespace MyFriendsAround.WP7.ViewModel
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public const string SelectedFriendPropertyName = "SelectedFriend";
|
public const string SelectedFriendPropertyName = "SelectedFriend";
|
||||||
|
|
||||||
private PushPinModel _SelectedFriend = new PushPinModel()
|
private PushPinModel _SelectedFriend;
|
||||||
{
|
|
||||||
Location = GeoCoordinate.Unknown,
|
|
||||||
PinUserName = "Guest",
|
|
||||||
PinImageUrl = string.Empty
|
|
||||||
};
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the SelectedFriend property.
|
/// Gets the SelectedFriend property.
|
||||||
@@ -562,12 +569,6 @@ namespace MyFriendsAround.WP7.ViewModel
|
|||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (_isBusy == value)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var oldValue = _isBusy;
|
|
||||||
_isBusy = value;
|
_isBusy = value;
|
||||||
|
|
||||||
// Update bindings, no broadcast
|
// Update bindings, no broadcast
|
||||||
@@ -616,6 +617,7 @@ namespace MyFriendsAround.WP7.ViewModel
|
|||||||
#region Commands
|
#region Commands
|
||||||
|
|
||||||
public ICommand MainLoadCommand { get; set; }
|
public ICommand MainLoadCommand { get; set; }
|
||||||
|
public ICommand BackKeyPressCommand { get; set; }
|
||||||
public ICommand PublishLocationCommand { get; set; }
|
public ICommand PublishLocationCommand { get; set; }
|
||||||
public ICommand NavigateToSettingsCommand { get; set; }
|
public ICommand NavigateToSettingsCommand { get; set; }
|
||||||
public ICommand ShowMyLocationCommand { get; set; }
|
public ICommand ShowMyLocationCommand { get; set; }
|
||||||
@@ -876,7 +878,7 @@ namespace MyFriendsAround.WP7.ViewModel
|
|||||||
result.Add(new PushPinModel()
|
result.Add(new PushPinModel()
|
||||||
{
|
{
|
||||||
PinSource = "/ApplicationIcon.png",
|
PinSource = "/ApplicationIcon.png",
|
||||||
Location = new GeoCoordinate(f.Latitude, f.Longitude),
|
Location = new GeoCoordinate(f.Latitude, f.Longitude, 0),
|
||||||
PinUserName = f.FriendName,
|
PinUserName = f.FriendName,
|
||||||
PinImageUrl =
|
PinImageUrl =
|
||||||
string.Format(
|
string.Format(
|
||||||
@@ -924,8 +926,8 @@ namespace MyFriendsAround.WP7.ViewModel
|
|||||||
List<Friend> list = args.Friends;
|
List<Friend> list = args.Friends;
|
||||||
DispatcherHelper.CheckBeginInvokeOnUI(() =>
|
DispatcherHelper.CheckBeginInvokeOnUI(() =>
|
||||||
{
|
{
|
||||||
PopulatePushPins(list);
|
|
||||||
IsBusy = false;
|
IsBusy = false;
|
||||||
|
PopulatePushPins(list);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -958,6 +960,7 @@ namespace MyFriendsAround.WP7.ViewModel
|
|||||||
{
|
{
|
||||||
DispatcherHelper.CheckBeginInvokeOnUI(() =>
|
DispatcherHelper.CheckBeginInvokeOnUI(() =>
|
||||||
{
|
{
|
||||||
|
IsBusy = false;
|
||||||
var message = new DialogMessage(
|
var message = new DialogMessage(
|
||||||
"Communication error!", DialogMessageCallback)
|
"Communication error!", DialogMessageCallback)
|
||||||
{
|
{
|
||||||
@@ -1004,6 +1007,7 @@ namespace MyFriendsAround.WP7.ViewModel
|
|||||||
{
|
{
|
||||||
DispatcherHelper.CheckBeginInvokeOnUI(() =>
|
DispatcherHelper.CheckBeginInvokeOnUI(() =>
|
||||||
{
|
{
|
||||||
|
IsBusy = false;
|
||||||
var message = new DialogMessage(
|
var message = new DialogMessage(
|
||||||
"Communication error!", DialogMessageCallback)
|
"Communication error!", DialogMessageCallback)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -74,8 +74,12 @@
|
|||||||
<i:EventTrigger EventName="Loaded">
|
<i:EventTrigger EventName="Loaded">
|
||||||
<cmd:EventToCommand Command="{Binding MainLoadCommand}" />
|
<cmd:EventToCommand Command="{Binding MainLoadCommand}" />
|
||||||
</i:EventTrigger>
|
</i:EventTrigger>
|
||||||
|
<i:EventTrigger EventName="BackKeyPress">
|
||||||
|
<cmd:EventToCommand Command="{Binding BackKeyPressCommand}" PassEventArgsToCommand="True" />
|
||||||
|
</i:EventTrigger>
|
||||||
</i:Interaction.Triggers>
|
</i:Interaction.Triggers>
|
||||||
|
|
||||||
|
|
||||||
<Grid x:Name="LayoutRoot"
|
<Grid x:Name="LayoutRoot"
|
||||||
Background="Transparent">
|
Background="Transparent">
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
@@ -252,6 +256,31 @@
|
|||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
|
|
||||||
|
<Preview:BindableApplicationBar x:Name="AppBar"
|
||||||
|
BarOpacity="0.8">
|
||||||
|
<Preview:BindableApplicationBarIconButton Command="{Binding ShowMyLocationCommand}"
|
||||||
|
IconUri="/icons/appbar.location.png"
|
||||||
|
Text="{Binding AppBarTextMyLocation}" />
|
||||||
|
<Preview:BindableApplicationBarIconButton Command="{Binding RefreshFriendsCommand}"
|
||||||
|
IconUri="/icons/appbar.sync.rest.png"
|
||||||
|
Text="{Binding AppBarTextRefresh}"
|
||||||
|
IsEnabled="{Binding Path=IsBusy, Converter={StaticResource InvertValueConverter1}}" />
|
||||||
|
<Preview:BindableApplicationBarIconButton Command="{Binding PublishLocationCommand}"
|
||||||
|
IconUri="/icons/appbar.publish.png"
|
||||||
|
Text="{Binding AppBarTextPublish}"
|
||||||
|
IsEnabled="{Binding Path=IsBusy, Converter={StaticResource InvertValueConverter1}}" />
|
||||||
|
<Preview:BindableApplicationBarIconButton Command="{Binding NavigateToSettingsCommand}"
|
||||||
|
IconUri="/icons/appbar.feature.settings.rest.png"
|
||||||
|
Text="{Binding AppBarTextSettings}" />
|
||||||
|
|
||||||
|
<Preview:BindableApplicationBar.MenuItems>
|
||||||
|
<Preview:BindableApplicationBarMenuItem Text="{Binding AppBarTextAbout}"
|
||||||
|
Command="{Binding ShowAboutCommand}" />
|
||||||
|
</Preview:BindableApplicationBar.MenuItems>
|
||||||
|
</Preview:BindableApplicationBar>
|
||||||
|
|
||||||
|
|
||||||
<Grid Background="Transparent"
|
<Grid Background="Transparent"
|
||||||
VerticalAlignment="Stretch"
|
VerticalAlignment="Stretch"
|
||||||
Grid.RowSpan="2"
|
Grid.RowSpan="2"
|
||||||
@@ -320,28 +349,7 @@
|
|||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<Preview:BindableApplicationBar x:Name="AppBar"
|
|
||||||
BarOpacity="0.8">
|
|
||||||
<Preview:BindableApplicationBarIconButton Command="{Binding ShowMyLocationCommand}"
|
|
||||||
IconUri="/icons/appbar.location.png"
|
|
||||||
Text="{Binding AppBarTextMyLocation}" />
|
|
||||||
<Preview:BindableApplicationBarIconButton Command="{Binding RefreshFriendsCommand}"
|
|
||||||
IconUri="/icons/appbar.sync.rest.png"
|
|
||||||
Text="{Binding AppBarTextRefresh}"
|
|
||||||
IsEnabled="{Binding Path=IsBusy, Converter={StaticResource InvertValueConverter1}}" />
|
|
||||||
<Preview:BindableApplicationBarIconButton Command="{Binding PublishLocationCommand}"
|
|
||||||
IconUri="/icons/appbar.publish.png"
|
|
||||||
Text="{Binding AppBarTextPublish}"
|
|
||||||
IsEnabled="{Binding Path=IsBusy, Converter={StaticResource InvertValueConverter1}}" />
|
|
||||||
<Preview:BindableApplicationBarIconButton Command="{Binding NavigateToSettingsCommand}"
|
|
||||||
IconUri="/icons/appbar.feature.settings.rest.png"
|
|
||||||
Text="{Binding AppBarTextSettings}" />
|
|
||||||
|
|
||||||
<Preview:BindableApplicationBar.MenuItems>
|
|
||||||
<Preview:BindableApplicationBarMenuItem Text="{Binding AppBarTextAbout}"
|
|
||||||
Command="{Binding ShowAboutCommand}" />
|
|
||||||
</Preview:BindableApplicationBar.MenuItems>
|
|
||||||
</Preview:BindableApplicationBar>
|
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
</phone:PhoneApplicationPage>
|
</phone:PhoneApplicationPage>
|
||||||
@@ -316,8 +316,8 @@ Global
|
|||||||
{17158FD9-80FD-49C1-9E3F-C5633602A4D9}.Debug|x86.ActiveCfg = Debug|Any CPU
|
{17158FD9-80FD-49C1-9E3F-C5633602A4D9}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
{17158FD9-80FD-49C1-9E3F-C5633602A4D9}.GPS_EMULATOR|Any CPU.ActiveCfg = Release|Any CPU
|
{17158FD9-80FD-49C1-9E3F-C5633602A4D9}.GPS_EMULATOR|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{17158FD9-80FD-49C1-9E3F-C5633602A4D9}.GPS_EMULATOR|Any CPU.Build.0 = Release|Any CPU
|
{17158FD9-80FD-49C1-9E3F-C5633602A4D9}.GPS_EMULATOR|Any CPU.Build.0 = Release|Any CPU
|
||||||
{17158FD9-80FD-49C1-9E3F-C5633602A4D9}.GPS_EMULATOR|Mixed Platforms.ActiveCfg = Release|Any CPU
|
{17158FD9-80FD-49C1-9E3F-C5633602A4D9}.GPS_EMULATOR|Mixed Platforms.ActiveCfg = GPS_EMULATOR|Any CPU
|
||||||
{17158FD9-80FD-49C1-9E3F-C5633602A4D9}.GPS_EMULATOR|Mixed Platforms.Build.0 = Release|Any CPU
|
{17158FD9-80FD-49C1-9E3F-C5633602A4D9}.GPS_EMULATOR|Mixed Platforms.Build.0 = GPS_EMULATOR|Any CPU
|
||||||
{17158FD9-80FD-49C1-9E3F-C5633602A4D9}.GPS_EMULATOR|x86.ActiveCfg = Release|Any CPU
|
{17158FD9-80FD-49C1-9E3F-C5633602A4D9}.GPS_EMULATOR|x86.ActiveCfg = Release|Any CPU
|
||||||
{17158FD9-80FD-49C1-9E3F-C5633602A4D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{17158FD9-80FD-49C1-9E3F-C5633602A4D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{17158FD9-80FD-49C1-9E3F-C5633602A4D9}.Release|Any CPU.Build.0 = Release|Any CPU
|
{17158FD9-80FD-49C1-9E3F-C5633602A4D9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
|||||||
Reference in New Issue
Block a user