add pdflaunch

This commit is contained in:
stubbfel
2013-09-03 14:04:29 +02:00
parent 90a11179bd
commit 54ce4e6ee1
12 changed files with 286 additions and 77 deletions

View File

@@ -105,6 +105,8 @@
<Compile Include="Feed\Mensa\MensaFeedCBSouth.cs" />
<Compile Include="Feed\Mensa\MensaFeedCBNorth.cs" />
<Compile Include="Feed\Mensa\MensaFeedCBMain.cs" />
<Compile Include="File\Exams\ExamFile.cs" />
<Compile Include="Model\BinaryModel.cs" />
<Compile Include="Model\Campusmap\CBMainMapModel.cs" />
<Compile Include="Model\Campusmap\CurrentPositionPinModel.cs" />
<Compile Include="Model\Campusmap\HiddenPinPlaceModel.cs" />

View File

@@ -0,0 +1,94 @@
//-----------------------------------------------------------------------
// <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
{
/// <summary>The storage file.</summary>
private StorageFile storageFile;
/// <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(ModelType.FileAndFeed, fileName, url)
{
this.IsFileUpToDateOnLoad += new IsFileUpToDate(this.CheckIsFileUpToDate);
this.IsModelUpToDateOnLoad += new IsModelUpToDate(this.CheckIsModelUpToDate);
this.IsFileUpToDateOnSave += new IsFileUpToDate(this.CheckIsFileUpToDate);
}
/// <summary>Executes the file operation.</summary>
/// <remarks>Stubbfel, 03.09.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);
}
}
/// <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();
}
}
/// <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)
{
return false;
}
return true;
}
}
}

View File

@@ -0,0 +1,62 @@
//-----------------------------------------------------------------------
// <copyright file="BinaryModel.cs" company="BTU/IIT">
// Company copyright tag.
// </copyright>
// <author>stubbfel</author>
// <sience>03.09.2013</sience>
//----------------------------------------------------------------------
namespace CampusAppWP8.Model
{
/// <summary>Binary model.</summary>
/// <remarks>Stubbfel, 03.09.2013.</remarks>
public abstract class BinaryModel : MainModel<byte[]>
{
/// <summary>Initializes a new instance of the BinaryModel class.</summary>
/// <remarks>Stubbfel, 03.09.2013.</remarks>
/// <param name="modelType">Type of the model.</param>
/// <param name="fileName"> Filename of the file.</param>
/// <param name="url"> URL of the document.</param>
public BinaryModel(ModelType modelType, string fileName, string url)
: base(modelType, fileName, url)
{
}
/// <summary>Initializes a new instance of the BinaryModel class.</summary>
/// <remarks>Stubbfel, 03.09.2013.</remarks>
/// <param name="modelType"> Type of the model.</param>
/// <param name="sourceName">Name of the source.</param>
public BinaryModel(ModelType modelType, string sourceName)
: base(modelType, sourceName)
{
}
/// <summary>Deserialize model.</summary>
/// <remarks>Stubbfel, 03.09.2013.</remarks>
/// <param name="modelData">Information describing the model.</param>
/// <returns>true if it succeeds, false if it fails.</returns>
protected override bool DeserializeModel(byte[] modelData)
{
bool retValue = true;
if (modelData != null)
{
this.Model = modelData;
}
else
{
retValue = false;
}
return retValue;
}
/// <summary>Gets the serialize model.</summary>
/// <remarks>Stubbfel, 03.09.2013.</remarks>
/// <returns>an byte Array.</returns>
protected override byte[] SerializeModel()
{
return this.Model;
}
}
}

View File

@@ -7,8 +7,8 @@
//----------------------------------------------------------------------
namespace CampusAppWP8.Model.Exams
{
using CampusAppWP8.Utility;
using System.Xml.Serialization;
using CampusAppWP8.Utility;
/// <summary>Exam model.</summary>
/// <remarks>Stubbfel, 02.09.2013.</remarks>

View File

@@ -11,7 +11,6 @@ namespace CampusAppWP8
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using CampusAppWP8.Model.Utility;
using CampusAppWP8.Utility;
@@ -19,8 +18,13 @@ namespace CampusAppWP8
/// Base model io handling class.
/// </summary>
/// <typeparam name="T">model type</typeparam>
public abstract class MainModel<T> : IDisposable
public abstract class MainModel<T>
{
/// <summary>
/// File object.
/// </summary>
protected CampusAppWP8.Utility.File file = null;
/// <summary>
/// Model io type.
/// </summary>
@@ -31,11 +35,6 @@ namespace CampusAppWP8
/// </summary>
private T model = default(T);
/// <summary>
/// File object.
/// </summary>
private CampusAppWP8.Utility.File file = null;
/// <summary>
/// Web object.
/// </summary>
@@ -88,14 +87,6 @@ namespace CampusAppWP8
}
}
/// <summary>
/// Finalizes an instance of the <see cref="MainModel{T}" /> class.
/// </summary>
~MainModel()
{
this.SaveData();
}
/// <summary>
/// Delegate of the OnIO callback function.
/// </summary>
@@ -238,14 +229,6 @@ namespace CampusAppWP8
}
}
/// <summary>
/// Called before finalizing. Can maybe be removed.
/// </summary>
public void Dispose()
{
this.SaveData();
}
/// <summary>
/// Forces a update from web.
/// </summary>

View File

@@ -15,7 +15,7 @@ namespace CampusAppWP8.Model
/// Xml model io handler class.
/// </summary>
/// <typeparam name="T">model type</typeparam>
public class XmlModel<T> : MainModel<T>
public abstract class XmlModel<T> : MainModel<T>
{
/// <summary>
/// Initializes a new instance of the <see cref="XmlModel{T}" /> class.

View File

@@ -29,12 +29,9 @@
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<lui:ToggleButton ToggleContentTag="{Binding Path=Constants.ToggleContent, Source={StaticResource Const}}" Style="{StaticResource ListButtonStyle}">
<Button Tag="{Binding Link}" Style="{StaticResource ListButtonStyle}" Click="Button_Click">
<TextBlock Text="{Binding Caption}" TextWrapping="Wrap"/>
</lui:ToggleButton>
<StackPanel Tag="{Binding Path=Constants.ToggleContent, Source={StaticResource Const}}" Orientation="Horizontal" HorizontalAlignment="Center" Visibility="Collapsed">
<lui:LinkButton Height="75" Url="{Binding Link}" />
</StackPanel>
</Button>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
@@ -51,12 +48,9 @@
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<lui:ToggleButton ToggleContentTag="{Binding Path=Constants.ToggleContent, Source={StaticResource Const}}" Style="{StaticResource ListButtonStyle}">
<Button Tag="{Binding Link}" Style="{StaticResource ListButtonStyle}" Click="Button_Click">
<TextBlock Text="{Binding Caption}" TextWrapping="Wrap"/>
</lui:ToggleButton>
<StackPanel Tag="{Binding Path=Constants.ToggleContent, Source={StaticResource Const}}" Orientation="Horizontal" HorizontalAlignment="Center" Visibility="Collapsed">
<lui:LinkButton Height="75" Url="{Binding Link}" />
</StackPanel>
</Button>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
@@ -73,12 +67,9 @@
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<lui:ToggleButton ToggleContentTag="{Binding Path=Constants.ToggleContent, Source={StaticResource Const}}" Style="{StaticResource ListButtonStyle}">
<Button Tag="{Binding Link}" Style="{StaticResource ListButtonStyle}" Click="Button_Click">
<TextBlock Text="{Binding Caption}" TextWrapping="Wrap"/>
</lui:ToggleButton>
<StackPanel Tag="{Binding Path=Constants.ToggleContent, Source={StaticResource Const}}" Orientation="Horizontal" HorizontalAlignment="Center" Visibility="Collapsed">
<lui:LinkButton Height="75" Url="{Binding Link}" />
</StackPanel>
</Button>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>

View File

@@ -8,22 +8,25 @@ namespace CampusAppWP8.Pages.Exams
{
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using CampusAppWP8.Feed.Exams;
using CampusAppWP8.File.Exams;
using CampusAppWP8.Resources;
using CampusAppWP8.Utility;
using CampusAppWP8.Utility.Lui.MessageBoxes;
using Microsoft.Phone.Controls;
using System.Net;
using System.IO;
/// <summary>Exams.</summary>
/// <summary>class of ExamsPage.</summary>
/// <remarks>Stubbfel, 02.09.2013.</remarks>
public partial class Exams : PhoneApplicationPage
{
/// <summary>The feed.</summary>
private ExamFeed feed;
/// <summary>The exam file.</summary>
private ExamFile file;
/// <summary>Initializes a new instance of the Exams class.</summary>
/// <remarks>Stubbfel, 02.09.2013.</remarks>
public Exams()
@@ -56,8 +59,13 @@ namespace CampusAppWP8.Pages.Exams
{
if (NavigationMode.Back == e.NavigationMode)
{
App.SaveToIsolatedStorage<int>(Constants.ExamPageModelKey, -1);
this.feed.SaveData();
}
else
{
App.SaveToIsolatedStorage<int>(Constants.ExamPageModelKey, this.ExamPivot.SelectedIndex);
}
}
/// <summary>Method initialize the Feed.</summary>
@@ -76,7 +84,14 @@ namespace CampusAppWP8.Pages.Exams
{
this.SetupExamList();
this.ProgressBar.Visibility = System.Windows.Visibility.Collapsed;
HttpRequest api = new HttpRequest();
}
/// <summary>Executes the PDF reader operation.</summary>
/// <remarks>Stubbfel, 03.09.2013.</remarks>
private void LaunchPDFReader()
{
this.ProgressBar.Visibility = System.Windows.Visibility.Collapsed;
this.file.SaveAndLaunchFile();
}
/// <summary>Sets up the exam list.</summary>
@@ -109,24 +124,28 @@ namespace CampusAppWP8.Pages.Exams
/// <returns>The calculated selected index.</returns>
private int CalcSelectedIndex()
{
int result = 0;
Model.Setting.UserProfilModel.DegreeType degree = Settings.UserProfil.Degree;
switch (degree)
int result = App.LoadFromIsolatedStorage<int>(Constants.ExamPageModelKey);
if (result < 0 || result > 2)
{
case Model.Setting.UserProfilModel.DegreeType.BACHELOR:
result = 0;
break;
case Model.Setting.UserProfilModel.DegreeType.MASTER:
result = 1;
break;
case Model.Setting.UserProfilModel.DegreeType.DIPLOM:
result = 2;
break;
default:
result = 0;
break;
Model.Setting.UserProfilModel.DegreeType degree = Settings.UserProfil.Degree;
switch (degree)
{
case Model.Setting.UserProfilModel.DegreeType.BACHELOR:
result = 0;
break;
case Model.Setting.UserProfilModel.DegreeType.MASTER:
result = 1;
break;
case Model.Setting.UserProfilModel.DegreeType.DIPLOM:
result = 2;
break;
default:
result = 0;
break;
}
}
return result;
}
@@ -145,5 +164,40 @@ namespace CampusAppWP8.Pages.Exams
MessageBoxResult result = MessageBoxes.ShowMainModelErrorMessageBox(AppResources.MsgBox_ErrorMainModelLoadFile);
this.ProgressBar.Visibility = System.Windows.Visibility.Collapsed;
}
/// <summary>Event handler. Called by Button for click events.</summary>
/// <remarks>Stubbfel, 03.09.2013.</remarks>
/// <param name="sender">Source of the event.</param>
/// <param name="e"> Routed event information.</param>
private void Button_Click(object sender, RoutedEventArgs e)
{
Button button = sender as Button;
if (button == null)
{
return;
}
string url = button.Tag as string;
if (url == null)
{
return;
}
// create filename
string[] filenames = url.Split('/');
string filename = url;
if (filenames.Length > 0)
{
filename = filenames[filenames.Length - 1];
}
this.file = new ExamFile(filename, url);
this.file.OnLoaded += new ExamFile.OnIO(this.LaunchPDFReader);
this.file.OnFailedWeb += new ExamFile.OnFailed(this.FeedIsFailWeb);
this.file.OnFailedFile += new ExamFile.OnFailed(this.FeedIsFailFile);
this.file.LoadData();
this.ProgressBar.Visibility = System.Windows.Visibility.Visible;
}
}
}

View File

@@ -132,6 +132,15 @@ namespace CampusAppWP8.Resources {
}
}
/// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die ExamsPage.LastPivotIndex ähnelt.
/// </summary>
public static string ExamPageModelKey {
get {
return ResourceManager.GetString("ExamPageModelKey", resourceCulture);
}
}
/// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die links ähnelt.
/// </summary>

View File

@@ -447,4 +447,7 @@
<data name="UrlExamApp_ExamFeed" xml:space="preserve">
<value>https://www.zv.tu-cottbus.de/CMS-Webservice/Pruefungsordnung/Uebersicht</value>
</data>
<data name="ExamPageModelKey" xml:space="preserve">
<value>ExamsPage.LastPivotIndex</value>
</data>
</root>

View File

@@ -10,6 +10,7 @@ namespace CampusAppWP8.Utility
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Windows.Storage;
/// <summary>
@@ -27,12 +28,9 @@ namespace CampusAppWP8.Utility
/// </summary>
private string filename = string.Empty;
/// <summary>
/// Initializes a new instance of the <see cref="File" /> class.
/// </summary>
/// <param name="filename">file name</param>
/// <param name="read">read type</param>
/// <param name="write">write type</param>
/// <summary>Initializes a new instance of the <see cref="File" /> class.</summary>
/// <remarks>Stubbfel, 03.09.2013.</remarks>
/// <param name="filename"> file name.</param>
public File(string filename)
{
this.filename = filename;
@@ -43,11 +41,9 @@ namespace CampusAppWP8.Utility
/// </summary>
public delegate void WriteCallbackFunc();
/// <summary>
/// Read data from file to a string.
/// </summary>
/// <param name="ioType">read type</param>
/// <returns>data string</returns>
/// <summary>Read data from file to a string.</summary>
/// <remarks>Stubbfel, 03.09.2013.</remarks>
/// <returns>data string.</returns>
public byte[] ReadFile()
{
byte[] retValue = null;
@@ -60,13 +56,11 @@ namespace CampusAppWP8.Utility
return retValue;
}
/// <summary>
/// Write bytes to the file.
/// </summary>
/// <param name="data">data byte array.</param>
/// <param name="onSavedCallback">callback function, called after writing is done.</param>
/// <summary>Write bytes to the file.</summary>
/// <remarks>Stubbfel, 03.09.2013.</remarks>
/// <param name="data"> data byte array.</param>
/// <param name="onSavedCallback"> callback function, called after writing is done.</param>
/// <param name="onFailedCallback">callback function, called when writing failed.</param>
/// <param name="ioType">write type.</param>
public void WriteFile(byte[] data, WriteCallbackFunc onSavedCallback, WriteCallbackFunc onFailedCallback)
{
Thread th = new Thread(delegate() { this.WriteAsync(data, onSavedCallback, onFailedCallback); });
@@ -92,6 +86,19 @@ namespace CampusAppWP8.Utility
return this.GetFileInfo().Exists;
}
/// <summary>Converts this object to a storage file.</summary>
/// <remarks>Stubbfel, 03.09.2013.</remarks>
/// <returns>Storage File</returns>
public async Task<StorageFile> AsStorageFile()
{
if (this.Exist())
{
return await File.LocalFolder.GetFileAsync(this.filename);
}
return null;
}
/// <summary>
/// Read data synchronous from file.
/// </summary>

View File

@@ -60,6 +60,10 @@ namespace CampusAppWP8.Utility
client.DownloadStringAsync(url);
}
/// <summary>Method realize the http-get-method resource.</summary>
/// <remarks>Stubbfel, 03.09.2013.</remarks>
/// <param name="url"> Url of the resource.</param>
/// <param name="action">The action.</param>
public void HttpGet(Uri url, Action<object, OpenReadCompletedEventArgs> action)
{
WebClient client = new WebClient();