From 4140f2771eac67829637adcd84d5a0544d7cac0b Mon Sep 17 00:00:00 2001 From: Christian Fiedler Date: Wed, 28 Aug 2013 18:05:16 +0200 Subject: [PATCH] dictionary done --- CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj | 2 + .../Model/TimeTable/AppointmentModel.cs | 109 +-- .../Pages/TimeTable/TimeTableDay.xaml.cs | 2 +- .../CampusAppWP8/Utility/ICSObject.cs | 249 +++++++ .../CampusAppWP8/Utility/ICSObjectConst.cs | 653 ++++++++++++++++++ .../CampusAppWP8/Utility/StringManager.cs | 21 + 6 files changed, 930 insertions(+), 106 deletions(-) create mode 100644 CampusAppWP8/CampusAppWP8/Utility/ICSObject.cs create mode 100644 CampusAppWP8/CampusAppWP8/Utility/ICSObjectConst.cs diff --git a/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj b/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj index bf6ce86c..d4831a78 100644 --- a/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj +++ b/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj @@ -120,6 +120,8 @@ TimeTableDay.xaml + + diff --git a/CampusAppWP8/CampusAppWP8/Model/TimeTable/AppointmentModel.cs b/CampusAppWP8/CampusAppWP8/Model/TimeTable/AppointmentModel.cs index 38d5c9fb..ec071ba8 100644 --- a/CampusAppWP8/CampusAppWP8/Model/TimeTable/AppointmentModel.cs +++ b/CampusAppWP8/CampusAppWP8/Model/TimeTable/AppointmentModel.cs @@ -13,6 +13,7 @@ namespace CampusAppWP8.Model.TimeTable using System.Text.RegularExpressions; using System.Windows.Shapes; using System.Xml.Serialization; + using CampusAppWP8.Utility; /// /// Model for appointments. @@ -23,31 +24,17 @@ namespace CampusAppWP8.Model.TimeTable /// The Visual object. private Rectangle rect = null; - private IcsVEvent data; - - private struct IcsVEvent - { - public DateTime created; - public string uid; - public DateTime lastModified; - public DateTime stamp; - public string summary; - public DateTime start; - public DateTime end; - public string accessClass; - public string location; - public string description; - public string categories; - } + private ICSObject icsObj; /// Initializes a new instance of the class. public AppointmentModel() { + this.icsObj = new ICSObject(); } public AppointmentModel(string icsData) : this() { - this.ImportFromICS(icsData); + this.icsObj.ImportFromICS(icsData); } public Rectangle GetRectangle() @@ -55,97 +42,9 @@ namespace CampusAppWP8.Model.TimeTable return this.rect; } - public void ImportFromICS(string icsData) - { - string[] elems = Regex.Split(icsData, "\r\n"); - - foreach (string e in elems) - { - string[] parts = e.Split(':'); - - if (parts.Length != 2) - { - throw new NotImplementedException("error in ics string"); - } - - if (parts[0].Contains(";")) - { - parts[0] = parts[0].Split(';')[0]; - } - - switch (parts[0]) - { - case "BEGIN": - break; - case "CREATED": - this.data.created = this.ParseUTC(parts[1]); - break; - case "UID": - this.data.uid = parts[1]; - break; - case "LAST-MODIFIED": - this.data.lastModified = this.ParseUTC(parts[1]); - break; - case "DTSTAMP": - this.data.stamp = this.ParseUTC(parts[1]); - break; - case "SUMMARY": - this.data.summary = parts[1]; - break; - case "DTSTART": - this.data.start = this.ParseUTC(parts[1]); - break; - case "DTEND": - this.data.end = this.ParseUTC(parts[1]); - break; - case "CLASS": - this.data.accessClass = parts[1]; - break; - case "LOCATION": - this.data.location = parts[1]; - break; - case "DESCRIPTION": - this.data.description = parts[1]; - break; - case "CATEGORIES": - this.data.categories = parts[1]; - break; - case "END": - break; - case "VERSION": - break; - case "PRODID": - break; - case "X-WR-CALNAME": - break; - - default: - throw new NotImplementedException("unknown tag in ics: " + parts[0]); - } - } - } - - public string ExportToICS() - { - string retValue = string.Empty; - - - return retValue; - } private void CreateRect() { - - } - - private DateTime ParseUTC(string datetime) - { - datetime = datetime.Insert(4, "-"); - datetime = datetime.Insert(7, "-"); - datetime = datetime.Insert(13, ":"); - datetime = datetime.Insert(16, ":"); - - return DateTime.Parse(datetime); } } } diff --git a/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTableDay.xaml.cs b/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTableDay.xaml.cs index b84c2d6e..f6e10131 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTableDay.xaml.cs +++ b/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTableDay.xaml.cs @@ -19,7 +19,7 @@ namespace CampusAppWP8.Pages.TimeTable public TimeTableDay() { InitializeComponent(); - this.testMod = new AppointmentModel("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:ownCloud Calendar 0.6.3\r\nX-WR-CALNAME:MyTestAppointment\r\nBEGIN:VEVENT\r\nCREATED;VALUE=DATE-TIME:20130826T142318Z\r\nUID:617332baab\r\nLAST-MODIFIED;VALUE=DATE-TIME:20130826T142318Z\r\nDTSTAMP;VALUE=DATE-TIME:20130826T142318Z\r\nSUMMARY:MyTestAppointment\r\nDTSTART;VALUE=DATE-TIME:20130730T130000Z\r\nDTEND;VALUE=DATE-TIME:20130730T133000Z\r\nCLASS:PUBLIC\r\nLOCATION:BTU Campus\r\nDESCRIPTION:bla\r\nCATEGORIES:Arbeit\r\nEND:VEVENT\r\nEND:VCALENDAR"); + this.testMod = new AppointmentModel("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:ownCloud Calendar 0.6.3\r\nX-WR-CALNAME:Das is der Titel\r\nBEGIN:VEVENT\r\nCREATED;VALUE=DATE-TIME:20130827T113216Z\r\nUID:c9904ea73c\r\nLAST-MODIFIED;VALUE=DATE-TIME:20130827T113216Z\r\nDTSTAMP;VALUE=DATE-TIME:20130827T113216Z\r\nSUMMARY:Das is der Titel\r\nDTSTART;VALUE=DATE:20130828\r\nDTEND;VALUE=DATE:20130829\r\nCLASS:PUBLIC\r\nLOCATION:BTU Campus\r\nDESCRIPTION:For Outlook 2003, the behavior is peculiar. It can save the sa\r\n me calendar entry in both .ics and .vcs format, but it only read & displa\r\n y .vcs file correctly. It can read .ics file but it omits some fields and \r\n does not display it in calendar mode. My guess is that back then Microsoft\r\n wanted to provide .ics to be compatible with Mac's iCal but not quite com\r\n mitted to v2.0 yet.\r\nCATEGORIES:Projekte\r\nEND:VEVENT\r\nEND:VCALENDAR"); } } } \ No newline at end of file diff --git a/CampusAppWP8/CampusAppWP8/Utility/ICSObject.cs b/CampusAppWP8/CampusAppWP8/Utility/ICSObject.cs new file mode 100644 index 00000000..812f09bf --- /dev/null +++ b/CampusAppWP8/CampusAppWP8/Utility/ICSObject.cs @@ -0,0 +1,249 @@ +//----------------------------------------------------------------------------- +// +// Company copyright tag. +// +// fiedlchr +// 27.08.2013 +//----------------------------------------------------------------------------- +namespace CampusAppWP8.Utility +{ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + using System.Text.RegularExpressions; + using System.Threading.Tasks; + using System.Windows.Shapes; + using System.Xml.Serialization; + + /// Ics object. + public class ICSObject + { + private VCalendar data; + + private struct VCalendar + { + public string version; + public VEvent vevent; + } + + private struct VEvent + { + public DateTime created; + public string uid; + public DateTime lastModified; + public DateTime stamp; + public string summary; + public DateTime start; + public DateTime end; + public string accessClass; + public string location; + public string description; + public string categories; + } + + private struct ContentLine + { + public string name; + public List paramList; + public List valueList; + } + + /// Default constructor. + /// Fiedler, 27.08.2013. + public ICSObject() + { + + } + + public ICSObject(string icsData) : this() + { + this.ImportFromICS(icsData); + } + + public void ImportFromICS(string icsData) + { + string[] elems = Regex.Split(this.Unfold(icsData), "\r\n"); + + ICSDict.ICSValueDesc tempRoot = ICSDict.Root; + + foreach (string e in elems) + { + ContentLine obj = this.ToContentLine(e); + ICSDict.ICSElemDesc tempElem = null; + + if ((tempElem = tempRoot.GetValue(obj.name)) != null) + { + ICSDict.ICSValueDesc va = null; + + if (obj.name.Equals(ICSTag.BEGIN)) + { + if ((va = tempElem.GetValue(obj.valueList[0])) != null) + { + tempRoot = va; + } + else + { + throw new NotSupportedException("unsupported BEGIN value (" + obj.valueList[0] + ")"); + } + } + else if (obj.name.Equals(ICSTag.END)) + { + if ((va = tempElem.GetValue(obj.valueList[0])) != null) + { + + } + else + { + throw new NotSupportedException("unsupported END value (" + obj.valueList[0] + ")"); + } + } + } + else + { + if (obj.name.IndexOf("X-") == 0) + { + // TODO + } + else + { + throw new NotSupportedException("Tag (" + obj.name + ") was not found in (" + tempRoot.Name + ")"); + } + } + + /* + switch (obj.name) + { + case ICSTag.BEGIN: + break; + case ICSTag.DT_CREATED: + //this.data.vevent.created = this.ParseUTC(parts[1]); + break; + case ICSTag.USER_ID: + //this.data.vevent.uid = parts[1]; + break; + case "LAST-MODIFIED": + //this.data.vevent.lastModified = this.ParseUTC(parts[1]); + break; + case "DTSTAMP": + //this.data.vevent.stamp = this.ParseUTC(parts[1]); + break; + case "SUMMARY": + //this.data.vevent.summary = parts[1]; + break; + case "DTSTART": + //this.data.vevent.start = this.ParseUTC(parts[1]); + break; + case "DTEND": + //this.data.vevent.end = this.ParseUTC(parts[1]); + break; + case "CLASS": + //this.data.vevent.accessClass = parts[1]; + break; + case "LOCATION": + //this.data.vevent.location = parts[1]; + break; + case "DESCRIPTION": + //this.data.vevent.description = parts[1]; + break; + case "CATEGORIES": + //this.data.vevent.categories = parts[1]; + break; + case "END": + break; + case "VERSION": + //this.data.version = parts[1]; + break; + case "PRODID": + break; + case "X-WR-CALNAME": + break; + + //default: + // throw new NotImplementedException("unknown tag in ics: " + parts[0]); + } + */ + } + } + + public string ExportToICS() + { + string retValue = string.Empty; + + + return retValue; + } + + // TOOLS + + private DateTime ParseUTCDateTime(string datetime) + { + // see http://tools.ietf.org/html/rfc5545 3.3.5. + + datetime = datetime.Insert(4, "-"); + datetime = datetime.Insert(7, "-"); + datetime = datetime.Insert(13, ":"); + datetime = datetime.Insert(16, ":"); + + return DateTime.Parse(datetime); + } + + private DateTime ParseUTCDate(string date) + { + date = date.Insert(4, "-"); + date = date.Insert(7, "-"); + + return DateTime.Parse(date); + } + + private string Unfold(string icsData) + { + return icsData.Replace("\r\n ", "").Replace("\r\n\x09", ""); + } + + /// Converts an icsLine to a content line. + /// Fiedler, 27.08.2013. + /// Thrown when the requested operation is unimplemented. + /// The ics line. + /// icsLine as a ContentLine. + private ContentLine ToContentLine(string icsLine) + { + ContentLine retValue; + + string[] valueSplit = icsLine.Split(':'); + + if (valueSplit.Length != 2) + { + throw new NotImplementedException("ics string has no value"); + } + + // values + retValue.valueList = new List(); + retValue.valueList.AddRange(valueSplit[1].Split(',')); + + // params + int paramNum = StringManager.CountChar(valueSplit[0], ';'); + + if (paramNum > 0) + { + retValue.paramList = new List(); + + string[] paramSplit = valueSplit[0].Split(';'); + + retValue.name = paramSplit[0].ToUpper(); + + for (int i = 1; i < paramSplit.Length; i++) + { + retValue.paramList.Add(paramSplit[i].ToUpper()); + } + } + else + { + retValue.paramList = null; + retValue.name = valueSplit[0].ToUpper(); + } + + return retValue; + } + } +} diff --git a/CampusAppWP8/CampusAppWP8/Utility/ICSObjectConst.cs b/CampusAppWP8/CampusAppWP8/Utility/ICSObjectConst.cs new file mode 100644 index 00000000..e82d64a8 --- /dev/null +++ b/CampusAppWP8/CampusAppWP8/Utility/ICSObjectConst.cs @@ -0,0 +1,653 @@ +//----------------------------------------------------------------------------- +// +// Company copyright tag. +// +// fiedlchr +// 27.08.2013 +//----------------------------------------------------------------------------- +namespace CampusAppWP8.Utility +{ + using System.Collections.Generic; + + public class ICSDict + { + public class ICSDesc + { + private string name = string.Empty; + + public ICSDesc() + { + } + + public string Name + { + get + { + return this.name; + } + protected set + { + this.name = value; + } + } + + public bool Is(string tag) + { + return this.name.Equals(tag); + } + } + + public class ICSParamDesc : ICSDesc + { + private List types = null; + + public ICSParamDesc(string name, string[] typeList) : base() + { + this.Name = name; + + if((typeList != null) && (typeList.Length > 0)) + { + this.types = new List(); + this.types.AddRange(types); + } + } + + public List List + { + get + { + return this.types; + } + private set + { + this.types = value; + } + } + + public bool HasList() + { + return ((this.types != null) && (this.types.Count > 0)); + } + } + + public class ICSValueDesc : ICSDesc + { + private List subs = null; + + public ICSValueDesc(string name, ICSElemDesc[] elemList) : base() + { + this.Name = name; + + if((elemList != null) && (elemList.Length > 0)) + { + this.subs = new List(); + this.subs.AddRange(elemList); + } + } + + public List List + { + get + { + return this.subs; + } + private set + { + this.subs = value; + } + } + + public bool HasList() + { + return ((this.subs != null) && (this.subs.Count > 0)); + } + + public bool IsInList(string tagName) + { + bool retValue = false; + + if (this.HasList() == true) + { + foreach (ICSElemDesc e in this.subs) + { + if (e.Is(tagName) == true) + { + retValue = true; + } + } + } + + return retValue; + } + + public ICSElemDesc GetValue(string tagName) + { + ICSElemDesc retValue = null; + + if (this.HasList() == true) + { + foreach (ICSElemDesc e in this.subs) + { + if (e.Is(tagName) == true) + { + retValue = e; + } + } + } + + return retValue; + } + } + + + public class ICSElemDesc : ICSDesc + { + private List param = null; + private List value = null; + + public ICSElemDesc(string name, ICSParamDesc[] paramList, ICSValueDesc[] valueList) : base() + { + this.Name = name; + + if ((paramList != null) && (paramList.Length > 0)) + { + this.param = new List(); + this.param.AddRange(paramList); + } + + if ((valueList != null) && (valueList.Length > 0)) + { + this.value = new List(); + this.value.AddRange(valueList); + } + } + + public List ParamList + { + get + { + return this.param; + } + private set + { + this.param = value; + } + } + + public List ValueList + { + get + { + return this.value; + } + private set + { + this.value = value; + } + } + + public bool HasParams() + { + return ((this.param != null) && (this.param.Count > 0)); + } + + public bool HasValues() + { + return ((this.value != null) && (this.value.Count > 0)); + } + + public ICSValueDesc GetValue(string tagName) + { + ICSValueDesc retValue = null; + + if (this.HasValues() == true) + { + foreach (ICSValueDesc e in this.value) + { + if (e.Is(tagName) == true) + { + retValue = e; + } + } + } + + return retValue; + } + } + + public static ICSValueDesc Root = new ICSValueDesc("ROOT", new ICSElemDesc[] { + new ICSElemDesc(ICSTag.BEGIN, null, new ICSValueDesc[] { + new ICSValueDesc(ICSTag.VCALENDAR, new ICSElemDesc[] { + new ICSElemDesc(ICSTag.VERSION, null, null), + new ICSElemDesc(ICSTag.PRODUCT_ID, null, null), + new ICSElemDesc(ICSTag.CAL_SCALE, null, new ICSValueDesc[] { + new ICSValueDesc(ICSValue.GREGORIAN, null) + }), + new ICSElemDesc(ICSTag.METHOD, null, null), + new ICSElemDesc(ICSTag.END, null, new ICSValueDesc[] { + new ICSValueDesc(ICSTag.VCALENDAR, null) + }), + new ICSElemDesc(ICSTag.BEGIN, null, new ICSValueDesc[] { + new ICSValueDesc(ICSTag.VEVENT, new ICSElemDesc[] { + new ICSElemDesc(ICSTag.DT_STAMP, null, null), + new ICSElemDesc(ICSTag.USER_ID, null, null), + new ICSElemDesc(ICSTag.DT_START, null, null), + new ICSElemDesc(ICSTag.ACCESS_CLASS, null, null), + new ICSElemDesc(ICSTag.DT_CREATED, null, null), + new ICSElemDesc(ICSTag.DESCRIPTION, null, null), + new ICSElemDesc(ICSTag.GEO, null, null), + new ICSElemDesc(ICSTag.DT_MODIFIED, null, null), + new ICSElemDesc(ICSTag.LOCATION, null, null), + new ICSElemDesc(ICSTag.ORGANIZER, null, null), + new ICSElemDesc(ICSTag.PRIORITY, null, null), + new ICSElemDesc(ICSTag.SEQ, null, null), + new ICSElemDesc(ICSTag.STATUS, null, null), + new ICSElemDesc(ICSTag.TITLE, null, null), + new ICSElemDesc(ICSTag.TRANSP, null, null), + new ICSElemDesc(ICSTag.URL, null, null), + new ICSElemDesc(ICSTag.RECURRENCE_ID, null, null), + new ICSElemDesc(ICSTag.RRULE, null, null), + new ICSElemDesc(ICSTag.DT_END, null, null), + new ICSElemDesc(ICSTag.DURATION, null, null), + new ICSElemDesc(ICSTag.ATTACHMENT, null, null), + new ICSElemDesc(ICSTag.ATTENDEE, null, null), + new ICSElemDesc(ICSTag.CATEGORIES, null, null), + new ICSElemDesc(ICSTag.COMMENT, null, null), + new ICSElemDesc(ICSTag.CONTACT, null, null), + new ICSElemDesc(ICSTag.EXDATE, null, null), + new ICSElemDesc(ICSTag.RSTATUS, null, null), + new ICSElemDesc(ICSTag.RELATED, null, null), + new ICSElemDesc(ICSTag.RESOURCES, null, null), + new ICSElemDesc(ICSTag.RDATE, null, null), + new ICSElemDesc(ICSTag.BEGIN, null, new ICSValueDesc[] { + new ICSValueDesc(ICSTag.VALARM, new ICSElemDesc[] { + new ICSElemDesc(ICSTag.ACTION, null, new ICSValueDesc[] { // audio, display, email + new ICSValueDesc(ICSValue.AUDIO, null), + new ICSValueDesc(ICSValue.DISP, null), + new ICSValueDesc(ICSValue.EMAIL, null) + }), + new ICSElemDesc(ICSTag.TRIGGER, null, null), // audio, display, email + new ICSElemDesc(ICSTag.DURATION, null, null), // audio, display, email + new ICSElemDesc(ICSTag.REPEAT, null, null), // audio, display, email + new ICSElemDesc(ICSTag.ATTACHMENT, null, null), // audio, email + new ICSElemDesc(ICSTag.DESCRIPTION, null, null),// display, eamil + new ICSElemDesc(ICSTag.TITLE, null, null), // email + new ICSElemDesc(ICSTag.ATTENDEE, null, null), // email + new ICSElemDesc(ICSTag.END, null, new ICSValueDesc[] { // audio, display, email + new ICSValueDesc(ICSTag.VALARM, null) + }) + }) + }), + new ICSElemDesc(ICSTag.END, null, new ICSValueDesc[] { + new ICSValueDesc(ICSTag.VEVENT, null) + }) + }), + new ICSValueDesc(ICSTag.VTODO, new ICSElemDesc[] { + new ICSElemDesc(ICSTag.DT_STAMP, null, null), + new ICSElemDesc(ICSTag.USER_ID, null, null), + new ICSElemDesc(ICSTag.ACCESS_CLASS, null, null), + new ICSElemDesc(ICSTag.COMPLETED, null, null), + new ICSElemDesc(ICSTag.DT_CREATED, null, null), + new ICSElemDesc(ICSTag.DESCRIPTION, null, null), + new ICSElemDesc(ICSTag.DT_START, null, null), + new ICSElemDesc(ICSTag.GEO, null, null), + new ICSElemDesc(ICSTag.DT_MODIFIED, null, null), + new ICSElemDesc(ICSTag.LOCATION, null, null), + new ICSElemDesc(ICSTag.ORGANIZER, null, null), + new ICSElemDesc(ICSTag.PERCENT, null, null), + new ICSElemDesc(ICSTag.PRIORITY, null, null), + new ICSElemDesc(ICSTag.RECURRENCE_ID, null, null), + new ICSElemDesc(ICSTag.SEQ, null, null), + new ICSElemDesc(ICSTag.STATUS, null, null), + new ICSElemDesc(ICSTag.TITLE, null, null), + new ICSElemDesc(ICSTag.URL, null, null), + new ICSElemDesc(ICSTag.RRULE, null, null), + new ICSElemDesc(ICSTag.DUE, null, null), + new ICSElemDesc(ICSTag.DURATION, null, null), + new ICSElemDesc(ICSTag.ATTACHMENT, null, null), + new ICSElemDesc(ICSTag.ATTENDEE, null, null), + new ICSElemDesc(ICSTag.CATEGORIES, null, null), + new ICSElemDesc(ICSTag.COMMENT, null, null), + new ICSElemDesc(ICSTag.CONTACT, null, null), + new ICSElemDesc(ICSTag.EXDATE, null, null), + new ICSElemDesc(ICSTag.RSTATUS, null, null), + new ICSElemDesc(ICSTag.RELATED, null, null), + new ICSElemDesc(ICSTag.RESOURCES, null, null), + new ICSElemDesc(ICSTag.RDATE, null, null), + new ICSElemDesc(ICSTag.BEGIN, null, new ICSValueDesc[] { + new ICSValueDesc(ICSTag.VALARM, new ICSElemDesc[] { + new ICSElemDesc(ICSTag.ACTION, null, new ICSValueDesc[] { // audio, display, email + new ICSValueDesc(ICSValue.AUDIO, null), + new ICSValueDesc(ICSValue.DISP, null), + new ICSValueDesc(ICSValue.EMAIL, null) + }), + new ICSElemDesc(ICSTag.TRIGGER, null, null), // audio, display, email + new ICSElemDesc(ICSTag.DURATION, null, null), // audio, display, email + new ICSElemDesc(ICSTag.REPEAT, null, null), // audio, display, email + new ICSElemDesc(ICSTag.ATTACHMENT, null, null), // audio, email + new ICSElemDesc(ICSTag.DESCRIPTION, null, null),// display, eamil + new ICSElemDesc(ICSTag.TITLE, null, null), // email + new ICSElemDesc(ICSTag.ATTENDEE, null, null), // email + new ICSElemDesc(ICSTag.END, null, new ICSValueDesc[] { // audio, display, email + new ICSValueDesc(ICSTag.VALARM, null) + }) + }) + }), + new ICSElemDesc(ICSTag.END, null, new ICSValueDesc[] { + new ICSValueDesc(ICSTag.VTODO, null) + }) + }), + new ICSValueDesc(ICSTag.VJOURNAL, new ICSElemDesc[] { + new ICSElemDesc(ICSTag.DT_STAMP, null, null), + new ICSElemDesc(ICSTag.USER_ID, null, null), + new ICSElemDesc(ICSTag.ACCESS_CLASS, null, null), + new ICSElemDesc(ICSTag.DT_CREATED, null, null), + new ICSElemDesc(ICSTag.DT_START, null, null), + new ICSElemDesc(ICSTag.DT_MODIFIED, null, null), + new ICSElemDesc(ICSTag.ORGANIZER, null, null), + new ICSElemDesc(ICSTag.RECURRENCE_ID, null, null), + new ICSElemDesc(ICSTag.SEQ, null, null), + new ICSElemDesc(ICSTag.STATUS, null, null), + new ICSElemDesc(ICSTag.TITLE, null, null), + new ICSElemDesc(ICSTag.URL, null, null), + new ICSElemDesc(ICSTag.RRULE, null, null), + new ICSElemDesc(ICSTag.ATTACHMENT, null, null), + new ICSElemDesc(ICSTag.ATTENDEE, null, null), + new ICSElemDesc(ICSTag.CATEGORIES, null, null), + new ICSElemDesc(ICSTag.COMMENT, null, null), + new ICSElemDesc(ICSTag.CONTACT, null, null), + new ICSElemDesc(ICSTag.DESCRIPTION, null, null), + new ICSElemDesc(ICSTag.EXDATE, null, null), + new ICSElemDesc(ICSTag.RELATED, null, null), + new ICSElemDesc(ICSTag.RDATE, null, null), + new ICSElemDesc(ICSTag.RSTATUS, null, null), + new ICSElemDesc(ICSTag.END, null, new ICSValueDesc[] { + new ICSValueDesc(ICSTag.VJOURNAL, null) + }) + }), + new ICSValueDesc(ICSTag.VFREEBUSY, new ICSElemDesc[] { + new ICSElemDesc(ICSTag.DT_STAMP, null, null), + new ICSElemDesc(ICSTag.USER_ID, null, null), + new ICSElemDesc(ICSTag.CONTACT, null, null), + new ICSElemDesc(ICSTag.DT_START, null, null), + new ICSElemDesc(ICSTag.DT_END, null, null), + new ICSElemDesc(ICSTag.ORGANIZER, null, null), + new ICSElemDesc(ICSTag.URL, null, null), + new ICSElemDesc(ICSTag.ATTENDEE, null, null), + new ICSElemDesc(ICSTag.COMMENT, null, null), + new ICSElemDesc(ICSTag.FREEBUSY, null, null), + new ICSElemDesc(ICSTag.RSTATUS, null, null), + new ICSElemDesc(ICSTag.END, null, new ICSValueDesc[] { + new ICSValueDesc(ICSTag.VFREEBUSY, null) + }) + }), + new ICSValueDesc(ICSTag.VTIMEZONE, new ICSElemDesc[] { + new ICSElemDesc(ICSTag.TIME_ZONE_ID, null, null), + new ICSElemDesc(ICSTag.DT_MODIFIED, null, null), + new ICSElemDesc(ICSTag.TIME_ZONE_URL, null, null), + new ICSElemDesc(ICSTag.BEGIN, null, new ICSValueDesc[] { + new ICSValueDesc(ICSTag.STANDARD, new ICSElemDesc[] { + new ICSElemDesc(ICSTag.DT_START, null, null), + new ICSElemDesc(ICSTag.TIME_ZONE_OFFSET_TO, null, null), + new ICSElemDesc(ICSTag.TIME_ZONE_OFFSET_FROM, null, null), + new ICSElemDesc(ICSTag.RRULE, null, null), + new ICSElemDesc(ICSTag.COMMENT, null, null), + new ICSElemDesc(ICSTag.RDATE, null, null), + new ICSElemDesc(ICSTag.TIME_ZONE_NAME, null, null), + new ICSElemDesc(ICSTag.END, null, new ICSValueDesc[] { + new ICSValueDesc(ICSTag.STANDARD, null) + }) + }), + new ICSValueDesc(ICSTag.DAYLIGHT, new ICSElemDesc[] { + new ICSElemDesc(ICSTag.DT_START, null, null), + new ICSElemDesc(ICSTag.TIME_ZONE_OFFSET_TO, null, null), + new ICSElemDesc(ICSTag.TIME_ZONE_OFFSET_FROM, null, null), + new ICSElemDesc(ICSTag.RRULE, null, null), + new ICSElemDesc(ICSTag.COMMENT, null, null), + new ICSElemDesc(ICSTag.RDATE, null, null), + new ICSElemDesc(ICSTag.TIME_ZONE_NAME, null, null), + new ICSElemDesc(ICSTag.END, null, new ICSValueDesc[] { + new ICSValueDesc(ICSTag.STANDARD, null) + }) + }) + }), + new ICSElemDesc(ICSTag.END, null, new ICSValueDesc[] { + new ICSValueDesc(ICSTag.VTIMEZONE, null) + }) + }) + }) + }) + }) + }); + } + + public class ICSTag + { + + public const string BEGIN = "BEGIN"; + public const string END = "END"; + + // Calendar Components + public const string VCALENDAR = "VCALENDAR"; + // 1-* + public const string VERSION = "VERSION"; + public const string PRODUCT_ID = "PRODID"; + // 0-1 + public const string CAL_SCALE = "CALSCALE"; + public const string METHOD = "METHOD"; + // 0-* + public const string X_WR_CALNAME = "X-WR-CALNAME"; + + // Event Component + public const string VEVENT = "VEVENT"; + // 1-1 + public const string DT_STAMP = "DTSTAMP"; + public const string USER_ID = "UID"; + // if METHOD is NOT set: 1-1 + // otherwise: 0-1 + public const string DT_START = "DTSTART"; + // 0-1 + public const string ACCESS_CLASS = "CLASS"; + public const string DT_CREATED = "CREATED"; + public const string DESCRIPTION = "DESCRIPTION"; + public const string GEO = "GEO"; + public const string DT_MODIFIED = "LAST-MODIFIED"; + public const string LOCATION = "LOCATION"; + public const string ORGANIZER = "ORGANIZER"; + public const string PRIORITY = "PRIORITY"; + public const string SEQ = "SEQ"; + public const string STATUS = "STATUS"; + public const string TITLE = "SUMMARY"; + public const string TRANSP = "TRANSP"; + public const string URL = "URL"; + public const string RECURRENCE_ID = "RECURID"; // "RECURRENCE-ID"; ??? + public const string RRULE = "RRULE"; + // one of them can (0-1), but NOT both + public const string DT_END = "DTEND"; + public const string DURATION = "DURATION"; + // 0-* + public const string ATTACHMENT = "ATTACH"; + public const string ATTENDEE = "ATTENDEE"; + public const string CATEGORIES = "CATEGORIES"; + public const string COMMENT = "COMMENT"; + public const string CONTACT = "CONTACT"; + public const string EXDATE = "EXDATE"; + public const string RSTATUS = "RSTATUS"; + public const string RELATED = "RELATED"; + public const string RESOURCES = "RESOURCES"; + public const string RDATE = "RDATE"; + + // To-Do Component + public const string VTODO = "VTODO"; + public const string COMPLETED = "COMPLETED"; + public const string PERCENT = "PERCENT"; + public const string DUE = "DUE"; + // Journal Component + public const string VJOURNAL = "VJOURNAL"; + + // Free/Busy Component + public const string VFREEBUSY = "VFREEBUSY"; + // 0-* + public const string FREEBUSY = "FREEBUSY"; + + // Time Zone Component + public const string VTIMEZONE = "VTIMEZONE"; + // 1-1 + public const string TIME_ZONE_ID = "TZID"; + // 0-1 + // 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"; + // 1-1 + // DT_START + public const string TIME_ZONE_OFFSET_TO = "TZOFFSETTO"; + public const string TIME_ZONE_OFFSET_FROM = "TZOFFSETFROM"; + // 0-1 + // RRULE + // 0-* + // COMMENT + // RDATE + public const string TIME_ZONE_NAME = "TZNAME"; + + // Alarm Component + public const string VALARM = "VALARM"; + // Alarm by audio + // 1-1 + public const string TRIGGER = "TRIGGER"; + public const string ACTION = "ACTION"; // (AUDIO) + // 0-1 , when one occure so MUST the other + // DURATION + public const string REPEAT = "REPEAT"; + // 0-1 + // ATTACHMENT + // Alarm by disp + // 1-1 + // ACTION (DISPLAY) + // DESCRIPTION + // TRIGGER + // 0-1, when one occure so MUST the other + // DURATION + // REPEAT + // Alarm by email + // 1-1 + // ACTION (EMAIL) + // DESCRIPTION + // TRIGGER + // SUMMARY + // 1-* + // ATTENDEE + // 0-1, when one occure so MUST the other + // DURATION + // REPEAT + // 0-* + // ATTACH + + + + + + + // ??? + + // public const string RELATED_TO = "RELATED-TO"; + + } + + 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"; + public const string DELEGATORS = "DELEGATED-FROM"; + public const string DELEGATEES = "DELEGATED-TO"; + public const string DIR_REFERENCE = "DIR"; + public const string ENCODING = "ENCODING"; + public const string FORMAT_TYPE = "FMTTYPE"; + public const string FREE_BUSY_TIME_TYPE = "FBTYPE"; + public const string LANGUAGE = "LANGUAGE"; + public const string MEMBER = "MEMBER"; + public const string PARTICIPATION_STATUS = "PARTSTAT"; + public const string RECUR_ID_RANGE = "RANGE"; + public const string ALARM_TRIGGER_RELATIONSHIP = "RELATED"; + public const string RELATIONSHIP_TYPE = "RELTYPE"; + public const string PARTICIPATION_ROLE = "ROLE"; + public const string REPLY_EXPECTATION = "RSVP"; + public const string SENT_BY = "SENT-BY"; + public const string TIME_ZONE_ID = "TZID"; + public const string VALUE_TYPE = "VALUE"; + } + + public class ICSValue + { + // CAL_SCALE (see 3.7.1.) + public const string GREGORIAN = "GREGORIAN"; + // VALARM.ACTION + public const string AUDIO = "AUDIO"; + public const string DISP = "DISPLAY"; + public const string EMAIL = "EMAIL"; + } + + public class ICSParamValue + { + // CALENDAR_USER_TYPE + public const string INDIVIDUAL = "INDIVIDUAL"; // default + public const string GROUP = "GROUP"; + public const string RESOURCE = "RESOURCE"; + public const string ROOM = "ROOM"; + public const string UNKNOWN = "UNKNOWN"; + // ENCODING + public const string BIT8 = "8BIT"; // default + public const string BASE64 = "BASE64"; + // FREE_BUSY_TIME_TYPE + public const string FREE = "FREE"; + public const string BUSY = "BUSY"; + public const string BUSY_UNAVAILABLE = "BUSY-UNAVAILABLE"; + public const string BUSY_TENTATIVE = "BUSY-TENTATIVE"; + // PARTICIPATION_STATUS + public const string NEEDS_ACTION = "NEEDS_ACTION"; // default + public const string ACCEPTED = "ACCEPTED"; + public const string DECLINED = "DECLINED"; + public const string TENTATIVE = "TENTATIVE"; + public const string DELEGATED = "DELEGATED"; + public const string COMPLETED = "COMPLETED"; + // RECUR_ID_RANGE + public const string THIS_AND_FUTURE = "THISANDFUTURE"; + public const string THIS_AND_PRIOR = "THISANDPRIOR"; + // ALARM_TRIGGER_RELATIONSHIP + public const string START = "START"; + public const string END = "END"; + // RELATIONSHIP_TYPE + public const string PARENT = "PARENT"; // default + public const string CHILD = "CHILD"; + public const string SIBLING = "SIBLING"; + // PARTICIPATION_ROLE + public const string CHAIR = "CHAIR"; + public const string REQ_PARTICIPANT = "REQ-PARTICIPANT"; //default + public const string OPT_PARTICIPANT = "OPT-PARTICIPANT"; + public const string NON_PARTICIPANT = "NON-PARTICIPANT"; + // REPLY_EXPECTATION + public const string TRUE = "TRUE"; + public const string FALSE = "FALSE"; // default + // VALUE_TYPE (see http://tools.ietf.org/html/rfc5545 3.3.) + public const string BINARY = "BINARY"; + public const string BOOLEAN = "BOOLEAN"; + public const string CAL_ADDRESS = "CAL-ADDRESS"; + public const string DATE = "DATE"; + public const string DATE_TIME = "DATE-TIME"; + public const string DURATION = "DURATION"; + public const string FLOAT = "FLOAT"; + public const string INTEGER = "INTEGER"; + public const string PERIOD = "PERIOD"; + public const string RECUR = "RECUR"; + public const string TEXT = "TEXT"; + public const string TIME = "TIME"; + public const string URI = "URI"; + public const string UTC_OFFSET = "UTC-OFFSET"; + } +} diff --git a/CampusAppWP8/CampusAppWP8/Utility/StringManager.cs b/CampusAppWP8/CampusAppWP8/Utility/StringManager.cs index 2ead4228..05a32c1a 100644 --- a/CampusAppWP8/CampusAppWP8/Utility/StringManager.cs +++ b/CampusAppWP8/CampusAppWP8/Utility/StringManager.cs @@ -54,6 +54,27 @@ namespace CampusAppWP8.Utility { return str.TrimEnd('\n'); } + + /// Count 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; + + for (int i = 0; i < str.Length; i++) + { + if (str[i].Equals(c)) + { + retValue++; + } + } + + return retValue; + } + #endregion } }