Merge branch 'hotfix/#126' into develop

This commit is contained in:
Christian Fiedler
2013-08-14 12:49:01 +02:00
5 changed files with 88 additions and 10 deletions

View File

@@ -441,7 +441,7 @@
<ItemGroup>
<Reference Include="Microsoft.Phone.Controls, Version=8.0.0.0, Culture=neutral, PublicKeyToken=24eec0d8c86cda1e, processorArchitecture=MSIL" />
<Reference Include="Microsoft.Phone.Controls.Toolkit">
<HintPath>..\packages\WPtoolkit.4.2012.10.30\lib\wp8\Microsoft.Phone.Controls.Toolkit.dll</HintPath>
<HintPath>..\packages\WPToolkit.4.2013.06.11\lib\wp8\Microsoft.Phone.Controls.Toolkit.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>

View File

@@ -116,6 +116,11 @@ namespace CampusAppWP8
/// </summary>
public delegate void OnSaved();
/// <summary>
/// Delegate of the OnFailed(File/Web) callback function.
/// </summary>
public delegate void OnFailed();
/// <summary>
/// Delegate of the IsModelUpToDate callback function.
/// </summary>
@@ -151,6 +156,22 @@ namespace CampusAppWP8
/// </summary>
public event OnSaved onSaved = null;
/// <summary>
/// Callback pointer, called after failed file loading.
/// </summary>
public event OnFailed onFailedFile = null;
/// <summary>
/// Callback pointer, called after failed web loading.
/// </summary>
public event OnFailed onFailedWeb = null;
/// <summary>
/// Callback pointer, called after failed file or web loading, if there
/// is no specialized onFailed callback set.
/// </summary>
public event OnFailed onFailed = null;
/// <summary>
/// Callback pointer, for checking if file is up to date at loading.
/// </summary>
@@ -294,7 +315,18 @@ namespace CampusAppWP8
{
string data = this.file.ReadFile();
if (data != null && !data.Equals(string.Empty))
if (data == null)
{
if (this.onFailedFile != null)
{
this.onFailedFile();
}
else if (this.onFailed != null)
{
this.onFailed();
}
}
else if (!data.Equals(string.Empty))
{
this.DeserializeModel(Encoding.UTF8.GetBytes(data));
}
@@ -486,6 +518,15 @@ namespace CampusAppWP8
Exception downloadError = e.Error;
if (downloadError != null)
{
if (this.onFailedWeb != null)
{
this.onFailedWeb();
}
else if (this.onFailed != null)
{
this.onFailed();
}
return;
}

View File

@@ -220,20 +220,48 @@ namespace CampusAppWP8.Utility
/// <param name="data">data array</param>
private async void WriteAsync(byte[] data)
{
Logger.LogMsg("writeasync file: " + this.filename);
StorageFile file = null;
Stream s = null;
// try opening the file
while (file == null)
{
try
{
file = await File.LocalFolder.CreateFileAsync(this.filename, CreationCollisionOption.ReplaceExisting);
}
catch (Exception)
{
System.Threading.Thread.Sleep(10);
}
}
// try to get a stream on the file
while (s == null)
{
try
{
s = await file.OpenStreamForWriteAsync();
}
catch (Exception)
{
System.Threading.Thread.Sleep(10);
}
}
// writing data
try
{
var file = await File.LocalFolder.CreateFileAsync(this.filename, CreationCollisionOption.ReplaceExisting);
using (var s = await file.OpenStreamForWriteAsync())
{
await s.WriteAsync(data, 0, data.Length);
}
await s.WriteAsync(data, 0, data.Length);
await s.FlushAsync();
}
catch (Exception e)
{
// log write Error
Logger.LogException(e);
}
s.Dispose();
}
}
}

View File

@@ -22,5 +22,14 @@ namespace CampusAppWP8.Utility
{
Console.WriteLine(exception);
}
/// <summary>
/// Log a message.
/// </summary>
/// <param name="msg">to be logged message</param>
public static void LogMsg(string msg)
{
Console.WriteLine(msg);
}
}
}

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="WPtoolkit" version="4.2012.10.30" targetFramework="wp80" />
<package id="WPToolkit" version="4.2013.06.11" targetFramework="wp80" />
</packages>