mirror of
https://github.com/farcasclaudiu/myfriendsaround.git
synced 2026-06-22 07:01:41 +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.IsolatedStorage;
|
||||
using System.Runtime.Serialization;
|
||||
using Microsoft.Phone;
|
||||
|
||||
namespace WPImageCaching
|
||||
{
|
||||
@@ -20,8 +21,66 @@ namespace WPImageCaching
|
||||
{
|
||||
private const string IMAGECACHEFILE = "imagecachefile.nfo";
|
||||
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)
|
||||
{
|
||||
string url = image.UriSource.ToString();
|
||||
@@ -65,31 +124,49 @@ namespace WPImageCaching
|
||||
//Laden der Bildinformationen
|
||||
private static void LoadCachedImageInfo()
|
||||
{
|
||||
if (IsolatedStorageFile.GetUserStoreForApplication().FileExists(IMAGECACHEFILE))
|
||||
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
|
||||
{
|
||||
IsolatedStorageFileStream fs =
|
||||
IsolatedStorageFile.GetUserStoreForApplication().OpenFile(IMAGECACHEFILE,FileMode.Open);
|
||||
lock (_lock)
|
||||
{
|
||||
if (isf.FileExists(IMAGECACHEFILE))
|
||||
{
|
||||
using (IsolatedStorageFileStream fs = isf.OpenFile(IMAGECACHEFILE, FileMode.Open))
|
||||
{
|
||||
using (StreamReader sr = new StreamReader(fs))
|
||||
{
|
||||
string serObj = sr.ReadToEnd();
|
||||
imageCache = SerializationHelper.Deserialize<Dictionary<string, ImageCacheItem>>(serObj);
|
||||
}
|
||||
|
||||
DataContractSerializer dcs = new DataContractSerializer(typeof(Dictionary<string, ImageCacheItem>));
|
||||
imageCache = (Dictionary<string, ImageCacheItem>)dcs.ReadObject(fs);
|
||||
fs.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
imageCache = new Dictionary<string, ImageCacheItem>();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (imageCache == null)
|
||||
{
|
||||
imageCache = new Dictionary<string, ImageCacheItem>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Speichern der Bildinformationen
|
||||
internal static void SaveCachedImageInfo()
|
||||
{
|
||||
IsolatedStorageFileStream fs =
|
||||
IsolatedStorageFile.GetUserStoreForApplication().CreateFile(IMAGECACHEFILE);
|
||||
|
||||
DataContractSerializer dcs = new DataContractSerializer(typeof(Dictionary<string, ImageCacheItem>));
|
||||
dcs.WriteObject(fs, imageCache);
|
||||
fs.Flush();
|
||||
fs.Close();
|
||||
using (IsolatedStorageFile sf = IsolatedStorageFile.GetUserStoreForApplication())
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (sf.FileExists(IMAGECACHEFILE))
|
||||
sf.DeleteFile(IMAGECACHEFILE);
|
||||
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);
|
||||
}
|
||||
if (value is string && !string.IsNullOrEmpty(value as string))
|
||||
{
|
||||
return ImageCache.GetImage((string)value);
|
||||
}
|
||||
else
|
||||
{
|
||||
return value;
|
||||
|
||||
@@ -8,14 +8,23 @@ using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Animation;
|
||||
using System.Windows.Shapes;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace WPImageCaching
|
||||
{
|
||||
//Beinhaltet die Informationen eines Bildes
|
||||
internal class ImageCacheItem
|
||||
[DataContract]
|
||||
public class ImageCacheItem
|
||||
{
|
||||
public ImageCacheItem()
|
||||
{
|
||||
}
|
||||
|
||||
[DataMember]
|
||||
public string LocalFilename { get; set; }
|
||||
[DataMember]
|
||||
public string ImageID { get; set; }
|
||||
[DataMember]
|
||||
public DateTime Expiration { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ using System.Collections.Generic;
|
||||
using System.IO.IsolatedStorage;
|
||||
using System.IO;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace WPImageCaching
|
||||
{
|
||||
@@ -35,7 +36,7 @@ namespace WPImageCaching
|
||||
|
||||
//Erstellen der Abfrage
|
||||
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
|
||||
wc.Headers["If-None-Match"] = item.ImageID;
|
||||
@@ -62,53 +63,103 @@ namespace WPImageCaching
|
||||
//Bild wurde nicht geändert seit dem letzten Aufruf
|
||||
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;
|
||||
}
|
||||
//Hat das Bild eine neue ID?
|
||||
if (response.Headers["ETag"] != null)
|
||||
lock (ImageCache._lock)
|
||||
{
|
||||
transfer.Item.ImageID = response.Headers["ETag"];
|
||||
}
|
||||
else
|
||||
{
|
||||
transfer.Item.ImageID = null;
|
||||
}
|
||||
//Gibt es ein Ablaufdatum?
|
||||
if (response.Headers["Expires"] != null)
|
||||
{
|
||||
transfer.Item.Expiration = DateTime.Parse(response.Headers["Expires"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
transfer.Item.Expiration = DateTime.Now.AddDays(EXPIRATIONDAYS);
|
||||
}
|
||||
|
||||
var responseStream = response.GetResponseStream();
|
||||
|
||||
//Schreiben der Bilddatei
|
||||
using (var bw = new BinaryWriter(IsolatedStorageFile.GetUserStoreForApplication().CreateFile(transfer.Item.LocalFilename)))
|
||||
{
|
||||
byte[] b = new byte[4096];
|
||||
int read = 0;
|
||||
while ((read = responseStream.Read(b, 0, b.Length)) > 0)
|
||||
string newKey = transfer.WebRequest.RequestUri.ToString();
|
||||
if (ImageCache.imageCache.ContainsKey(newKey))
|
||||
{
|
||||
bw.Write(b, 0, read);
|
||||
//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;
|
||||
}
|
||||
//Hat das Bild eine neue ID?
|
||||
if (response.Headers["ETag"] != null)
|
||||
{
|
||||
transfer.Item.ImageID = response.Headers["ETag"];
|
||||
}
|
||||
else
|
||||
{
|
||||
transfer.Item.ImageID = null;
|
||||
}
|
||||
//Gibt es ein Ablaufdatum?
|
||||
if (response.Headers["Expires"] != null)
|
||||
{
|
||||
transfer.Item.Expiration = DateTime.Parse(response.Headers["Expires"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
transfer.Item.Expiration = DateTime.Now.AddDays(EXPIRATIONDAYS);
|
||||
}
|
||||
|
||||
var responseStream = response.GetResponseStream();
|
||||
|
||||
//Schreiben der Bilddatei
|
||||
using ( var bw = new BinaryWriter( IsolatedStorageFile.GetUserStoreForApplication().CreateFile(transfer.Item.LocalFilename)) )
|
||||
{
|
||||
byte[] b = new byte[4096];
|
||||
int read = 0;
|
||||
while ((read = responseStream.Read(b, 0, b.Length)) > 0)
|
||||
{
|
||||
bw.Write(b, 0, read);
|
||||
}
|
||||
bw.Flush();
|
||||
bw.Close();
|
||||
}
|
||||
//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);
|
||||
}
|
||||
}
|
||||
});
|
||||
//Hinzufügen der Bildinformationen
|
||||
if (!ImageCache.imageCache.ContainsKey(newKey))
|
||||
{
|
||||
ImageCache.imageCache.Add(newKey, transfer.Item);
|
||||
//Speichern der Bildinformationen
|
||||
ImageCache.SaveCachedImageInfo();
|
||||
}
|
||||
bw.Flush();
|
||||
bw.Close();
|
||||
}
|
||||
//Setzen des Bildes
|
||||
Deployment.Current.Dispatcher.BeginInvoke(() => transfer.Image.SetSource(IsolatedStorageFile.GetUserStoreForApplication().OpenFile(transfer.Item.LocalFilename, FileMode.Open)));
|
||||
//Hinzufügen der Bildinformationen
|
||||
ImageCache.imageCache.Add(transfer.WebRequest.RequestUri.ToString(), transfer.Item);
|
||||
//Speichern der Bildinformationen
|
||||
ImageCache.SaveCachedImageInfo();
|
||||
}
|
||||
catch
|
||||
catch (WebException webException)
|
||||
{
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//Nichts machen, da Bild nicht heruntergeladen werden konnte
|
||||
Debug.WriteLine(ex.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Erstellt einen eindeutigen Namen für das zu ladende Bild
|
||||
@@ -118,7 +169,7 @@ namespace WPImageCaching
|
||||
byte[] textToHash = Encoding.UTF8.GetBytes(url);
|
||||
SHA1Managed sa = new SHA1Managed();
|
||||
byte[] hash = sa.ComputeHash(textToHash);
|
||||
return BitConverter.ToString(hash)+extension;
|
||||
return BitConverter.ToString(hash) + extension;
|
||||
}
|
||||
}
|
||||
//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>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</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>
|
||||
<Reference Include="Microsoft.Phone" />
|
||||
<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.Windows" />
|
||||
<Reference Include="system" />
|
||||
@@ -55,6 +76,7 @@
|
||||
<Compile Include="ImageCacheItem.cs" />
|
||||
<Compile Include="ImageDownloadHelper.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SerializationHelper.cs" />
|
||||
</ItemGroup>
|
||||
<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" />
|
||||
|
||||
@@ -52,13 +52,14 @@ namespace MyFriendsAround.WP7
|
||||
|
||||
//register 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
|
||||
{
|
||||
get {
|
||||
get
|
||||
{
|
||||
return Container.Instance.Resolve<ILocationService>("LocationService");
|
||||
}
|
||||
}
|
||||
@@ -137,12 +138,7 @@ namespace MyFriendsAround.WP7
|
||||
void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
|
||||
{
|
||||
//LittleWatson.ReportException(e.Exception, string.Empty);
|
||||
DispatcherHelper.CheckBeginInvokeOnUI(() =>
|
||||
{
|
||||
var exception = new ExceptionPrompt();
|
||||
exception.Show(e.Exception);
|
||||
}
|
||||
);
|
||||
ShowException(e.Exception);
|
||||
|
||||
if (System.Diagnostics.Debugger.IsAttached)
|
||||
{
|
||||
@@ -155,13 +151,7 @@ namespace MyFriendsAround.WP7
|
||||
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
|
||||
{
|
||||
//LittleWatson.ReportException(e.ExceptionObject, string.Empty);
|
||||
|
||||
DispatcherHelper.CheckBeginInvokeOnUI(() =>
|
||||
{
|
||||
var exception = new ExceptionPrompt();
|
||||
exception.Show(e.ExceptionObject);
|
||||
}
|
||||
);
|
||||
ShowException(e.ExceptionObject);
|
||||
|
||||
if (System.Diagnostics.Debugger.IsAttached)
|
||||
{
|
||||
@@ -172,6 +162,16 @@ namespace MyFriendsAround.WP7
|
||||
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
|
||||
|
||||
|
||||
@@ -16,9 +16,14 @@ namespace MyFriendsAround.WP7.Service
|
||||
|
||||
static ServiceAgent()
|
||||
{
|
||||
baseUrl = "http://myfriendsaround.cloudapp.net/myfriends";//live azure
|
||||
//baseUrl = "http://127.0.0.1:80/myfriends";//running in local azure emulator
|
||||
#if GPS_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
|
||||
#else
|
||||
baseUrl = "http://myfriendsaround.cloudapp.net/myfriends";//live azure
|
||||
//baseUrl = "http://localhost:80/myfriends";
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#region GetFriends
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Device.Location;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
@@ -57,8 +58,18 @@ namespace MyFriendsAround.WP7.ViewModel
|
||||
public MainViewModel()
|
||||
{
|
||||
GpsLocation = Location.Unknown;
|
||||
_SelectedFriend = null;
|
||||
|
||||
//
|
||||
MainLoadCommand = new RelayCommand(() => MainLoad());
|
||||
BackKeyPressCommand = new RelayCommand<CancelEventArgs>((args) =>
|
||||
{
|
||||
if (IsSelectFriend)
|
||||
{
|
||||
IsSelectFriend = !IsSelectFriend;
|
||||
args.Cancel = true;
|
||||
}
|
||||
});
|
||||
PublishLocationCommand = new RelayCommand(() => PublishLocationAction());
|
||||
NavigateToSettingsCommand = new RelayCommand(() => NavigateToSettings());
|
||||
RefreshFriendsCommand = new RelayCommand(() => RefreshFriends());
|
||||
@@ -194,12 +205,8 @@ namespace MyFriendsAround.WP7.ViewModel
|
||||
/// </summary>
|
||||
public const string SelectedFriendPropertyName = "SelectedFriend";
|
||||
|
||||
private PushPinModel _SelectedFriend = new PushPinModel()
|
||||
{
|
||||
Location = GeoCoordinate.Unknown,
|
||||
PinUserName = "Guest",
|
||||
PinImageUrl = string.Empty
|
||||
};
|
||||
private PushPinModel _SelectedFriend;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the SelectedFriend property.
|
||||
@@ -562,12 +569,6 @@ namespace MyFriendsAround.WP7.ViewModel
|
||||
|
||||
set
|
||||
{
|
||||
if (_isBusy == value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var oldValue = _isBusy;
|
||||
_isBusy = value;
|
||||
|
||||
// Update bindings, no broadcast
|
||||
@@ -616,6 +617,7 @@ namespace MyFriendsAround.WP7.ViewModel
|
||||
#region Commands
|
||||
|
||||
public ICommand MainLoadCommand { get; set; }
|
||||
public ICommand BackKeyPressCommand { get; set; }
|
||||
public ICommand PublishLocationCommand { get; set; }
|
||||
public ICommand NavigateToSettingsCommand { get; set; }
|
||||
public ICommand ShowMyLocationCommand { get; set; }
|
||||
@@ -876,7 +878,7 @@ namespace MyFriendsAround.WP7.ViewModel
|
||||
result.Add(new PushPinModel()
|
||||
{
|
||||
PinSource = "/ApplicationIcon.png",
|
||||
Location = new GeoCoordinate(f.Latitude, f.Longitude),
|
||||
Location = new GeoCoordinate(f.Latitude, f.Longitude, 0),
|
||||
PinUserName = f.FriendName,
|
||||
PinImageUrl =
|
||||
string.Format(
|
||||
@@ -923,21 +925,21 @@ namespace MyFriendsAround.WP7.ViewModel
|
||||
{
|
||||
List<Friend> list = args.Friends;
|
||||
DispatcherHelper.CheckBeginInvokeOnUI(() =>
|
||||
{
|
||||
PopulatePushPins(list);
|
||||
IsBusy = false;
|
||||
}
|
||||
);
|
||||
{
|
||||
IsBusy = false;
|
||||
PopulatePushPins(list);
|
||||
}
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
DispatcherHelper.CheckBeginInvokeOnUI(() =>
|
||||
{
|
||||
IsBusy = false;
|
||||
var exception = new ExceptionPrompt();
|
||||
exception.Show(args.Error);
|
||||
}
|
||||
);
|
||||
{
|
||||
IsBusy = false;
|
||||
var exception = new ExceptionPrompt();
|
||||
exception.Show(args.Error);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -958,6 +960,7 @@ namespace MyFriendsAround.WP7.ViewModel
|
||||
{
|
||||
DispatcherHelper.CheckBeginInvokeOnUI(() =>
|
||||
{
|
||||
IsBusy = false;
|
||||
var message = new DialogMessage(
|
||||
"Communication error!", DialogMessageCallback)
|
||||
{
|
||||
@@ -1004,6 +1007,7 @@ namespace MyFriendsAround.WP7.ViewModel
|
||||
{
|
||||
DispatcherHelper.CheckBeginInvokeOnUI(() =>
|
||||
{
|
||||
IsBusy = false;
|
||||
var message = new DialogMessage(
|
||||
"Communication error!", DialogMessageCallback)
|
||||
{
|
||||
|
||||
@@ -74,7 +74,11 @@
|
||||
<i:EventTrigger EventName="Loaded">
|
||||
<cmd:EventToCommand Command="{Binding MainLoadCommand}" />
|
||||
</i:EventTrigger>
|
||||
<i:EventTrigger EventName="BackKeyPress">
|
||||
<cmd:EventToCommand Command="{Binding BackKeyPressCommand}" PassEventArgsToCommand="True" />
|
||||
</i:EventTrigger>
|
||||
</i:Interaction.Triggers>
|
||||
|
||||
|
||||
<Grid x:Name="LayoutRoot"
|
||||
Background="Transparent">
|
||||
@@ -252,6 +256,31 @@
|
||||
|
||||
</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"
|
||||
VerticalAlignment="Stretch"
|
||||
Grid.RowSpan="2"
|
||||
@@ -320,28 +349,7 @@
|
||||
</StackPanel>
|
||||
</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>
|
||||
|
||||
</phone:PhoneApplicationPage>
|
||||
@@ -316,8 +316,8 @@ Global
|
||||
{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.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.Build.0 = 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 = GPS_EMULATOR|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.Build.0 = Release|Any CPU
|
||||
|
||||
Reference in New Issue
Block a user