116 lines
3.5 KiB
C#
116 lines
3.5 KiB
C#
//-----------------------------------------------------------------------
|
|
// <copyright file="ExamFile.cs" company="BTU/IIT">
|
|
// Company copyright tag.
|
|
// </copyright>
|
|
// <author>stubbfel</author>
|
|
// <sience>03.09.2013</sience>
|
|
//----------------------------------------------------------------------
|
|
|
|
namespace CampusAppWP8.File.Exams
|
|
{
|
|
using System.IO;
|
|
using CampusAppWP8.Model;
|
|
using Windows.Storage;
|
|
|
|
/// <summary>Exam file.</summary>
|
|
/// <remarks>Stubbfel, 03.09.2013.</remarks>
|
|
public class ExamFile : BinaryModel
|
|
{
|
|
#region Member
|
|
|
|
/// <summary>The storage file.</summary>
|
|
private StorageFile storageFile;
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
/// <summary>Initializes a new instance of the ExamFile class.</summary>
|
|
/// <remarks>Stubbfel, 03.09.2013.</remarks>
|
|
/// <param name="fileName">Filename of the file.</param>
|
|
/// <param name="url"> URL of the document.</param>
|
|
public ExamFile(string fileName, string url)
|
|
: base(CampusAppWPortalLib8.Model.ModelType.FileAndFeed, fileName, url)
|
|
{
|
|
this.IsFileUpToDateOnLoad += new IsFileUpToDate(this.CheckIsFileUpToDate);
|
|
this.IsModelUpToDateOnLoad += new IsModelUpToDate(this.CheckIsModelUpToDate);
|
|
this.IsFileUpToDateOnSave += new IsFileUpToDate(this.CheckIsFileUpToDate);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Method
|
|
|
|
#region public
|
|
|
|
/// <summary>Executes the file operation.</summary>
|
|
/// <remarks>Stubbfel, 03.09.2013.</remarks>
|
|
#pragma warning disable 4014
|
|
public async void LaunchFile()
|
|
{
|
|
if (this.storageFile == null)
|
|
{
|
|
this.storageFile = await ((CampusAppWP8.Utility.File)(this.file)).AsStorageFile();
|
|
}
|
|
|
|
if (this.storageFile != null)
|
|
{
|
|
var options = new Windows.System.LauncherOptions();
|
|
Windows.System.Launcher.LaunchFileAsync(this.storageFile);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
/// <summary>Saves the and launch file.</summary>
|
|
/// <remarks>Stubbfel, 03.09.2013.</remarks>
|
|
public void SaveAndLaunchFile()
|
|
{
|
|
if (this.file.Exist())
|
|
{
|
|
this.LaunchFile();
|
|
}
|
|
else
|
|
{
|
|
this.OnSaved += new ExamFile.OnIO(this.LaunchFile);
|
|
this.SaveData();
|
|
}
|
|
}
|
|
|
|
#region private
|
|
|
|
/// <summary>Check is model up to date.</summary>
|
|
/// <remarks>Stubbfel, 03.09.2013.</remarks>
|
|
/// <param name="model">The model.</param>
|
|
/// <returns>true if it succeeds, false if it fails.</returns>
|
|
private bool CheckIsModelUpToDate(byte[] model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/// <summary>Check is file up to date.</summary>
|
|
/// <remarks>Stubbfel, 03.09.2013.</remarks>
|
|
/// <param name="model"> The model.</param>
|
|
/// <param name="fileInfo">Information describing the file.</param>
|
|
/// <returns>true if it succeeds, false if it fails.</returns>
|
|
private bool CheckIsFileUpToDate(byte[] model, FileInfo fileInfo)
|
|
{
|
|
if (fileInfo == null || !fileInfo.Exists || fileInfo.Length < 1 || model != null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
}
|
|
}
|