From ac42cca415d25d89c63ba3a6c1fb6a2af160987c Mon Sep 17 00:00:00 2001 From: stubbfel Date: Tue, 19 Nov 2013 14:18:29 +0100 Subject: [PATCH 1/2] ad to Appointment --- .../Pages/Lecture/ResultDetailPage.xaml.cs | 223 +++++++++++++++++- .../CampusAppWP8/Utility/ICSObjectConst.cs | 76 ++++-- .../CampusAppWP8/Utility/Wp8StringManager.cs | 2 - .../Model/Lecture/LectureActivity.cs | 22 ++ .../Utility/DefaultStringManager.cs | 62 ++++- 5 files changed, 345 insertions(+), 40 deletions(-) diff --git a/CampusAppWP8/CampusAppWP8/Pages/Lecture/ResultDetailPage.xaml.cs b/CampusAppWP8/CampusAppWP8/Pages/Lecture/ResultDetailPage.xaml.cs index b2ac67bc..0f0b5749 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/Lecture/ResultDetailPage.xaml.cs +++ b/CampusAppWP8/CampusAppWP8/Pages/Lecture/ResultDetailPage.xaml.cs @@ -8,16 +8,31 @@ //----------------------------------------------------------------------- namespace CampusAppWP8.Pages.Lecture { + using System; + using System.Collections.Generic; + using System.Globalization; + using System.Windows; using System.Windows.Navigation; using CampusAppWP8.Model.Lecture; + using CampusAppWP8.Model.TimeTable; using CampusAppWP8.Resources; - using Microsoft.Phone.Controls; + using CampusAppWP8.Utility; + using CampusAppWP8.Utility.ICSProperties; + using CampusAppWPortalLib8.Model.Lecture; + using Microsoft.Phone.Controls; /// Class for the page which shows details of an activity. /// Stubbfel, 15.10.2013. /// public partial class ResultDetailPage : PhoneApplicationPage { + #region Member + + /// The activity. + private LectureWp8Activity activity; + + #endregion + #region Constructor /// Initializes a new instance of the class. @@ -54,25 +69,219 @@ namespace CampusAppWP8.Pages.Lecture /// Method load a certain Activity from the model. /// Stubbfel, 15.10.2013. /// id of the activity. - private void LoadActivity(int activityId) + private void LoadActivity(int activityId) { LectureWp8List list = App.LoadFromIsolatedStorage(Constants.IsolatedStorage_LectureModel); if (list != null) { - LectureWp8Activity activity = list.GetActivity(activityId); - activity.CreateLectureString(); - activity.CreateCourseString(); - this.ContentPanel.DataContext = activity; + this.activity = list.GetActivity(activityId); + this.activity.CreateLectureString(); + this.activity.CreateCourseString(); + this.ContentPanel.DataContext = this.activity; } } - /// Event handler. Called by AddCalender for click events. + /// Event handler. Called by AddCalendar for click events. /// Stubbfel, 18.11.2013. /// Source of the event. /// Routed event information. private void AddCalender_Click(object sender, System.Windows.RoutedEventArgs e) { + FrameworkElement btn = sender as FrameworkElement; + if (btn == null) + { + return; + } + string dateId = btn.Tag.ToString(); + LectureDate date = this.activity.GetDate(dateId); + AppointmentModel appoinment = this.CreateAppointment(date); + string urlString = Constants.PathTimeTable_AppointmentEdit; + + if (appoinment != null) + { + App.SaveToIsolatedStorage("LectureAppointment", ICSManager.ExportToICS(appoinment.CalendarObj)); + // urlString += "?" + this.QuerryStringName + "=" + this.QuerryStringValue; + } + + Uri url = new Uri(urlString as string, UriKind.Relative); + NavigationService.Navigate(url); + } + + /// Creates an appointment. + /// Stubbfel, 19.11.2013. + /// The date. + /// The new appointment. + private AppointmentModel CreateAppointment(LectureDate date) + { + if (date == null) + { + return null; + } + + CultureInfo german = Wp8StringManager.GermanCultur; + AppointmentModel appoinment = new AppointmentModel(); + DTStart start; + DateTime dtStart; + TimeSpan fromTime; + DTEnd end; + DateTime dtEnd; + TimeSpan toTime; + TimeSpan duration = TimeSpan.FromTicks(0); + RecurrenceRule rRule; + + // set the room + string dateValue = date.Room; + if (dateValue != null) + { + Location location = new Location(); + location.Value = dateValue; + appoinment.SetValue(location); + } + + if (this.activity != null) + { + // set Tilte + dateValue = this.activity.Title; + + if (dateValue != null) + { + Summary summary = new Summary(); + summary.Value = dateValue; + appoinment.SetValue(summary); + } + + // set cat + dateValue = this.activity.Type; + if (dateValue != null) + { + Categories category = new Categories(); + category.AddCategory(dateValue); + appoinment.SetValue(category); + } + + // set description + dateValue = this.activity.Topic; + if (dateValue != null) + { + Description desc = new Description(); + desc.Value = dateValue; + appoinment.SetValue(desc); + } + + // set orignazier + dateValue = this.activity.LecturerString; + if (dateValue != null) + { + Organizer org = new Organizer(); + org.Value = dateValue; + appoinment.SetValue(org); + } + } + + // set the startdate + dateValue = date.StartDate; + start = new DTStart(); + if (dateValue != null) + { + try + { + dtStart = DateTime.Parse(dateValue, german); + } + catch + { + dtStart = DateTime.Today; + } + } + else + { + dtStart = DateTime.Today; + } + + dateValue = date.From; + if (dateValue != null) + { + try + { + fromTime = TimeSpan.Parse(dateValue, german); + dtStart = dtStart.Add(fromTime); + duration = fromTime; + } + catch + { + } + } + + start.Value = dtStart; + appoinment.SetValue(start); + + // set the end date + dateValue = date.EndDate; + end = new DTEnd(); + if (dateValue != null) + { + try + { + dtEnd = DateTime.Parse(dateValue, german); + } + catch + { + dtEnd = DateTime.Today; + } + } + else + { + dtEnd = DateTime.Today; + } + + dateValue = date.To; + if (dateValue != null) + { + try + { + toTime = TimeSpan.Parse(dateValue, german); + dtEnd = dtEnd.Add(toTime); + duration = toTime - duration; + } + catch + { + } + } + + end.Value = dtEnd; + appoinment.SetValue(end); + + // set the duration + CampusAppWP8.Utility.ICSProperties.Duration icsDuration = new Utility.ICSProperties.Duration(); + icsDuration.Value = duration; + appoinment.SetValue(icsDuration); + + // set the RRule + rRule = new RecurrenceRule(); + rRule.Value.Add(new Tuple>(ICSValue.FREQ, new List() { ICSValueValue.WEEKLY })); + + // set by the week + dateValue = date.WeekDay; + if (dateValue != null) + { + DayOfWeek weekDay = Wp8StringManager.ToDayofWeek(dateValue, german); + rRule.Value.Add(new Tuple>(ICSValue.BY_DAY, new List() { ICSValueValue.ToICSWeekDay(weekDay) })); + } + + // set interval + dateValue = date.Interval; + if (dateValue != null) + { + string lowVal = dateValue.ToLower(); + if (lowVal.Contains("a") ^ lowVal.Contains("b")) + { + rRule.Value.Add(new Tuple>(ICSValue.INTERVAL, new List() { "2" })); + } + } + + appoinment.SetValue(rRule); + + return appoinment; } #endregion diff --git a/CampusAppWP8/CampusAppWP8/Utility/ICSObjectConst.cs b/CampusAppWP8/CampusAppWP8/Utility/ICSObjectConst.cs index 7652bf37..e63d51d0 100644 --- a/CampusAppWP8/CampusAppWP8/Utility/ICSObjectConst.cs +++ b/CampusAppWP8/CampusAppWP8/Utility/ICSObjectConst.cs @@ -15,7 +15,7 @@ namespace CampusAppWP8.Utility public class ICSDesc { private string name = string.Empty; - + public ICSDesc() { } @@ -32,7 +32,7 @@ namespace CampusAppWP8.Utility } } - public bool Is(string tag) + public bool Is(string tag) { return this.name.Equals(tag); } @@ -41,14 +41,15 @@ namespace CampusAppWP8.Utility public class ICSParamDesc : ICSDesc { private List types = null; - - public ICSParamDesc(string name, string[] typeList) : base() + + public ICSParamDesc(string name, string[] typeList) + : base() { this.Name = name; - if((typeList != null) && (typeList.Length > 0)) + if ((typeList != null) && (typeList.Length > 0)) { - this.types = new List(); + this.types = new List(); this.types.AddRange(types); } } @@ -75,11 +76,12 @@ namespace CampusAppWP8.Utility { private List subs = null; - public ICSValueDesc(string name, ICSElemDesc[] elemList) : base() + public ICSValueDesc(string name, ICSElemDesc[] elemList) + : base() { this.Name = name; - if((elemList != null) && (elemList.Length > 0)) + if ((elemList != null) && (elemList.Length > 0)) { this.subs = new List(); this.subs.AddRange(elemList); @@ -146,11 +148,12 @@ namespace CampusAppWP8.Utility private List value = null; private Type objType; - public ICSElemDesc(Type t, ICSValueDesc[] valueList) : base() + public ICSElemDesc(Type t, ICSValueDesc[] valueList) + : base() { this.objType = t; this.Name = (this.CreateObj() as ICSClasses.Interface).GetName(); - + if ((valueList != null) && (valueList.Length > 0)) { this.value = new List(); @@ -221,7 +224,7 @@ namespace CampusAppWP8.Utility object retValue = this.CreateObj(); (retValue as ICSClasses.Interface).Set(valueString, paramString); - + return retValue; } @@ -450,7 +453,7 @@ namespace CampusAppWP8.Utility { public const string BEGIN = "BEGIN"; - public const string END = "END"; + public const string END = "END"; // Calendar Components public const string VCALENDAR = "VCALENDAR"; @@ -462,7 +465,7 @@ namespace CampusAppWP8.Utility public const string METHOD = "METHOD"; // 0-* public const string X_WR_CALNAME = "X-WR-CALNAME"; - + // Event Component public const string VEVENT = "VEVENT"; // 1-1 @@ -523,7 +526,7 @@ namespace CampusAppWP8.Utility // DT_MODIFIED public const string TIME_ZONE_URL = "TZURL"; // one of both MUST occure: 1-* - + // Time Zone: Standardc/Daylightc public const string STANDARD = "STANDARD"; public const string DAYLIGHT = "DAYLIGHT"; @@ -570,14 +573,14 @@ namespace CampusAppWP8.Utility // REPEAT // 0-* // ATTACH - - - - - - + + + + + + // ??? - + // public const string RELATED_TO = "RELATED-TO"; public const string SEQUENCE = "SEQUENCE"; } @@ -585,7 +588,7 @@ namespace CampusAppWP8.Utility public class ICSParam { // see http://tools.ietf.org/html/rfc5545 3.2. - + public const string ALT_REPRESENTATION = "ALTREP"; public const string COMMON_NAME = "CN"; public const string CALENDAR_USER_TYPE = "CUTYPE"; @@ -730,12 +733,39 @@ namespace CampusAppWP8.Utility public const string DATE = "DATE"; public const string DATE_TIME = "DATE-TIME"; // ... - public const string DAY_SU = "SU"; + public const string DAY_SU = "SU"; public const string DAY_MO = "MO"; public const string DAY_TU = "TU"; public const string DAY_WE = "WE"; public const string DAY_TH = "TH"; public const string DAY_FR = "FR"; public const string DAY_SA = "SA"; + + /// Converts a day to the ics week day. + /// Stubbfel, 19.11.2013. + /// The day. + /// day as a string. + public static string ToICSWeekDay(DayOfWeek day) + { + switch (day) + { + case DayOfWeek.Sunday: + return ICSValueValue.DAY_SU; + case DayOfWeek.Monday: + return ICSValueValue.DAY_MO; + case DayOfWeek.Tuesday: + return ICSValueValue.DAY_TU; + case DayOfWeek.Wednesday: + return ICSValueValue.DAY_WE; + case DayOfWeek.Thursday: + return ICSValueValue.DAY_TH; + case DayOfWeek.Friday: + return ICSValueValue.DAY_FR; + case DayOfWeek.Saturday: + return ICSValueValue.DAY_SA; + default: + return null; + } + } } } diff --git a/CampusAppWP8/CampusAppWP8/Utility/Wp8StringManager.cs b/CampusAppWP8/CampusAppWP8/Utility/Wp8StringManager.cs index 27c5b2a5..9eb1fbfb 100644 --- a/CampusAppWP8/CampusAppWP8/Utility/Wp8StringManager.cs +++ b/CampusAppWP8/CampusAppWP8/Utility/Wp8StringManager.cs @@ -8,8 +8,6 @@ //----------------------------------------------------------------------- namespace CampusAppWP8.Utility { - using System; - using System.Text.RegularExpressions; using CampusAppWP8.Resources; /// Class provides some special StringMethods. diff --git a/CampusAppWP8/CampusAppWPortalLib8/Model/Lecture/LectureActivity.cs b/CampusAppWP8/CampusAppWPortalLib8/Model/Lecture/LectureActivity.cs index f822f57a..98a14af8 100644 --- a/CampusAppWP8/CampusAppWPortalLib8/Model/Lecture/LectureActivity.cs +++ b/CampusAppWP8/CampusAppWPortalLib8/Model/Lecture/LectureActivity.cs @@ -210,6 +210,28 @@ namespace CampusAppWPortalLib8.Model.Lecture this.CourseString = DefaultStringManager.RemoveNewLine(result); } + /// Gets a date. + /// Stubbfel, 19.11.2013. + /// The identifier. + /// The date. + public LectureDate GetDate(string id) + { + if (this.Dates == null || id == null) + { + return null; + } + + foreach (LectureDate date in this.Dates) + { + if (id.Equals(date.Id)) + { + return date; + } + } + + return null; + } + #endregion #endregion diff --git a/CampusAppWP8/CampusAppWPortalLib8/Utility/DefaultStringManager.cs b/CampusAppWP8/CampusAppWPortalLib8/Utility/DefaultStringManager.cs index b8c3bd38..07cee518 100644 --- a/CampusAppWP8/CampusAppWPortalLib8/Utility/DefaultStringManager.cs +++ b/CampusAppWP8/CampusAppWPortalLib8/Utility/DefaultStringManager.cs @@ -9,6 +9,7 @@ namespace CampusAppWPortalLib8.Utility { using System; + using System.Globalization; using System.Text.RegularExpressions; using CampusAppWPortalLib8.Resources; @@ -18,6 +19,9 @@ namespace CampusAppWPortalLib8.Utility { #region Members + /// The german culture. + public static readonly CultureInfo GermanCulture = new CultureInfo("de-DE"); + /// Patter for Html-Tags. private static readonly string HtmlTagPattern = "<.*?>"; @@ -127,7 +131,7 @@ namespace CampusAppWPortalLib8.Utility /// the id if it was found it in the string otherwise null. public static string FilterPlaceIdinQRResultString(string qrcodeResult) { - if (qrcodeResult == null) + if (qrcodeResult == null) { return null; } @@ -197,18 +201,18 @@ namespace CampusAppWPortalLib8.Utility return null; } - /// Count character. - /// Fiedler, 27.08.2013. - /// input string. - /// The character. - /// The total number of the specified character in the string. + /// Count a certain character. + /// Fiedler, 27.08.2013. + /// input string. + /// The character. + /// The total number of the specified character in the string. public static int CountChar(string str, char c) { int retValue = 0; - foreach(char tc in str) + foreach (char tc in str) { - if(tc.Equals(c) == true) + if (tc.Equals(c) == true) { retValue++; } @@ -216,6 +220,48 @@ namespace CampusAppWPortalLib8.Utility return retValue; } + + /// Converts this object to a day of the week. + /// Stubbfel, 19.11.2013. + /// The input day. + /// The culture. + /// The given data converted to a DayOfWeek. + public static DayOfWeek ToDayofWeek(string inputDay, CultureInfo culture) + { + if (inputDay == null || culture == null) + { + return 0; + } + + inputDay = inputDay.Trim().ToLower(); + string[] days = culture.DateTimeFormat.DayNames; + + int i = 0; + foreach (string day in days) + { + if (inputDay.Equals(day.ToLower())) + { + return (DayOfWeek)i; + } + + i++; + } + + // look for AbbreviatedDayNames + days = culture.DateTimeFormat.AbbreviatedDayNames; + i = 0; + foreach (string day in days) + { + if (inputDay.Equals(day.ToLower())) + { + return (DayOfWeek)i; + } + + i++; + } + + return 0; + } #endregion } } From 697256e49dff4ebdda45d70233d35e3684b0cadc Mon Sep 17 00:00:00 2001 From: stubbfel Date: Tue, 19 Nov 2013 15:21:49 +0100 Subject: [PATCH 2/2] add appointment to eventpage --- .../Pages/Events/EventPage.xaml.cs | 89 ++++++++++++++++++- .../Pages/Lecture/ResultDetailPage.xaml.cs | 4 +- .../CampusAppWP8/Resources/Constants.resx | 6 ++ .../Resources/Constants1.Designer.cs | 18 ++++ 4 files changed, 113 insertions(+), 4 deletions(-) diff --git a/CampusAppWP8/CampusAppWP8/Pages/Events/EventPage.xaml.cs b/CampusAppWP8/CampusAppWP8/Pages/Events/EventPage.xaml.cs index 8f9829bb..a764eb2f 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/Events/EventPage.xaml.cs +++ b/CampusAppWP8/CampusAppWP8/Pages/Events/EventPage.xaml.cs @@ -10,15 +10,19 @@ namespace CampusAppWP8.Pages.Events { using System; using System.Collections.Generic; + using System.Globalization; using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Navigation; - using Windows.Phone.Speech.Synthesis; + using CampusAppWP8.Model.TimeTable; using CampusAppWP8.Resources; + using CampusAppWP8.Utility; + using CampusAppWP8.Utility.ICSProperties; using CampusAppWP8.Utility.Lui.Page; using CampusAppWPortalLib8.Model.RSS; using Microsoft.Phone.Shell; + using Windows.Phone.Speech.Synthesis; /// EventPage, where every event feed has his own PivotItem. /// Stubbfel, 22.10.2013. @@ -39,6 +43,9 @@ namespace CampusAppWP8.Pages.Events /// The is in speech. private volatile bool isInSpeech = false; + /// The event model. + private RSSModel eventModel; + #endregion #region Constructor @@ -57,10 +64,16 @@ namespace CampusAppWP8.Pages.Events ApplicationBarIconButton ttsBtn = new ApplicationBarIconButton(); ttsBtn.IconUri = new Uri(Icons.TextToSpeech, UriKind.Relative); - ttsBtn.Text = AppResources.TextToSpeech_Btn; + ttsBtn.Text = AppResources.Add; ttsBtn.Click += new EventHandler(this.EventTextToSpeech_Click); ApplicationBar.Buttons.Add(ttsBtn); + ApplicationBarIconButton addCalBtn = new ApplicationBarIconButton(); + addCalBtn.IconUri = new Uri(Icons.Calendar_Add, UriKind.Relative); + addCalBtn.Text = AppResources.TextToSpeech_Btn; + addCalBtn.Click += new EventHandler(this.AddCalender_Click); + ApplicationBar.Buttons.Add(addCalBtn); + this.isNewInstance = true; this.synth = new SpeechSynthesizer(); @@ -229,6 +242,78 @@ namespace CampusAppWP8.Pages.Events } } + /// Event handler. Called by AddCalendar for click events. + /// Stubbfel, 19.11.2013. + /// parent pivot object. + /// Routed event information. + private void AddCalender_Click(object sender, EventArgs e) + { + this.eventModel = EventIndexPage.GetEventFeed().Model.Channel[0].Item[this.EventPivot.SelectedIndex]; + AppointmentModel appoinment = this.CreateAppointment(this.eventModel); + string urlString = Constants.PathTimeTable_AppointmentEdit; + + if (appoinment != null) + { + App.SaveToIsolatedStorage(Constants.IsolatedStorage_EventAppointment, ICSManager.ExportToICS(appoinment.CalendarObj)); + urlString += "?" + Constants.ParamIsoKey + "=" + Constants.IsolatedStorage_EventAppointment; + } + + Uri url = new Uri(urlString as string, UriKind.Relative); + NavigationService.Navigate(url); + } + + /// Creates an appointment. + /// Stubbfel, 19.11.2013. + /// The event model. + /// The new appointment. + private AppointmentModel CreateAppointment(RSSModel eventModel) + { + if (eventModel == null) + { + return null; + } + + CultureInfo german = Wp8StringManager.GermanCultur; + AppointmentModel appoinment = new AppointmentModel(); + DateTime time = eventModel.DTTimestamp; + DTStart start = new DTStart(); + start.Value = time; + + string dateValue = eventModel.Title; + + if (dateValue != null) + { + Summary summary = new Summary(); + summary.Value = dateValue; + appoinment.SetValue(summary); + } + + // set cat + Categories category = new Categories(); + category.AddCategory("Veranstaltung"); + appoinment.SetValue(category); + + // set description + dateValue = this.eventModel.Text; + if (dateValue != null) + { + Description desc = new Description(); + desc.Value = dateValue; + appoinment.SetValue(desc); + } + + // set url + dateValue = this.eventModel.Link; + if (dateValue != null) + { + Url url = new Url(); + url.Value = dateValue; + appoinment.SetValue(url); + } + + return appoinment; + } + #endregion #endregion diff --git a/CampusAppWP8/CampusAppWP8/Pages/Lecture/ResultDetailPage.xaml.cs b/CampusAppWP8/CampusAppWP8/Pages/Lecture/ResultDetailPage.xaml.cs index 0f0b5749..6f242356 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/Lecture/ResultDetailPage.xaml.cs +++ b/CampusAppWP8/CampusAppWP8/Pages/Lecture/ResultDetailPage.xaml.cs @@ -100,8 +100,8 @@ namespace CampusAppWP8.Pages.Lecture if (appoinment != null) { - App.SaveToIsolatedStorage("LectureAppointment", ICSManager.ExportToICS(appoinment.CalendarObj)); - // urlString += "?" + this.QuerryStringName + "=" + this.QuerryStringValue; + App.SaveToIsolatedStorage(Constants.IsolatedStorage_LectureAppointment, ICSManager.ExportToICS(appoinment.CalendarObj)); + urlString += "?" + Constants.ParamIsoKey + "=" + Constants.IsolatedStorage_LectureAppointment; } Uri url = new Uri(urlString as string, UriKind.Relative); diff --git a/CampusAppWP8/CampusAppWP8/Resources/Constants.resx b/CampusAppWP8/CampusAppWP8/Resources/Constants.resx index 6b2f5fd3..aff32e18 100644 --- a/CampusAppWP8/CampusAppWP8/Resources/Constants.resx +++ b/CampusAppWP8/CampusAppWP8/Resources/Constants.resx @@ -612,4 +612,10 @@ isolated + + LectureAppointment + + + EventAppointment + \ No newline at end of file diff --git a/CampusAppWP8/CampusAppWP8/Resources/Constants1.Designer.cs b/CampusAppWP8/CampusAppWP8/Resources/Constants1.Designer.cs index 27b94665..c0ded70b 100644 --- a/CampusAppWP8/CampusAppWP8/Resources/Constants1.Designer.cs +++ b/CampusAppWP8/CampusAppWP8/Resources/Constants1.Designer.cs @@ -474,6 +474,15 @@ namespace CampusAppWP8.Resources { } } + /// + /// Sucht eine lokalisierte Zeichenfolge, die EventAppointment ähnelt. + /// + public static string IsolatedStorage_EventAppointment { + get { + return ResourceManager.GetString("IsolatedStorage_EventAppointment", resourceCulture); + } + } + /// /// Sucht eine lokalisierte Zeichenfolge, die IsolatedStorage_EventRSSModel ähnelt. /// @@ -483,6 +492,15 @@ namespace CampusAppWP8.Resources { } } + /// + /// Sucht eine lokalisierte Zeichenfolge, die LectureAppointment ähnelt. + /// + public static string IsolatedStorage_LectureAppointment { + get { + return ResourceManager.GetString("IsolatedStorage_LectureAppointment", resourceCulture); + } + } + /// /// Sucht eine lokalisierte Zeichenfolge, die LectureModel ähnelt. ///