120 lines
3.7 KiB
C#
120 lines
3.7 KiB
C#
//-----------------------------------------------------------------------
|
|
// <copyright file="ExamFile.cs" company="BTU/IIT">
|
|
// The MIT License (MIT). Copyright (c) 2013 BTU/IIT.
|
|
// </copyright>
|
|
// <author>Stubbfel</author>
|
|
// <date>14.10.2013</date>
|
|
// <summary>Implements the exam file class</summary>
|
|
//-----------------------------------------------------------------------
|
|
namespace CampusAppWP8.File.Exams
|
|
{
|
|
using System.IO;
|
|
using CampusAppWP8.Model;
|
|
using Windows.Storage;
|
|
|
|
/// <summary> Exam file. </summary>
|
|
/// <remarks> Stubbfel, 03.09.2013. </remarks>
|
|
/// <seealso cref="T:CampusAppWP8.Model.BinaryModel"/>
|
|
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
|
|
|
|
/// <summary> Executes the file operation. </summary>
|
|
/// <remarks> Stubbfel, 14.10.2013. </remarks>
|
|
public async void LaunchFile()
|
|
{
|
|
if (this.storageFile == null)
|
|
{
|
|
this.storageFile = await 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
|
|
}
|
|
}
|