From f73d722555bf7ce3a8bf34a88ef459605ae721ed Mon Sep 17 00:00:00 2001 From: Christian Fiedler Date: Tue, 3 Sep 2013 18:49:52 +0200 Subject: [PATCH] ics classes, statics --- .../CampusAppWP8/Utility/ICSClasses.cs | 1031 ++++++++++++----- .../CampusAppWP8/Utility/ICSObject.cs | 7 + .../CampusAppWP8/Utility/ICSObjectConst.cs | 6 +- 3 files changed, 724 insertions(+), 320 deletions(-) diff --git a/CampusAppWP8/CampusAppWP8/Utility/ICSClasses.cs b/CampusAppWP8/CampusAppWP8/Utility/ICSClasses.cs index bd8e5dc9..935ea5a4 100644 --- a/CampusAppWP8/CampusAppWP8/Utility/ICSClasses.cs +++ b/CampusAppWP8/CampusAppWP8/Utility/ICSClasses.cs @@ -18,19 +18,38 @@ namespace CampusAppWP8.Utility public class ICSClasses { - private abstract class Interface + public abstract class Interface { - public void Set(string valueStr, string paramStr); - public void Set(string valueStr, string[] paramStrList); - public byte[] Get(); - public string Get(); + public virtual void Set(string valueStr, string paramStr) + { + this.Set(valueStr, paramStr.Split(';')); + } + + public abstract void Set(string valueStr, string[] paramStrList); + + public virtual byte[] GetBytes() + { + return Encoding.UTF8.GetBytes(this.GetString()); + } + + public abstract string GetString(); } public class Attachment : Interface { // 3.8.1.1. - public const string Name = ICSTag.ATTACHMENT; - public readonly List ParamList = null; + public static readonly string Name = ICSTag.ATTACHMENT; + public static readonly List> PParams + = new List>(new Tuple[] { + new Tuple(ICSParam.FORMAT_TYPE, null), + new Tuple(ICSParam.ENCODING, new string[] { + ICSParamValue.BIT8, + ICSParamValue.BASE64 + }), + new Tuple(ICSParam.VALUE_TYPE, new string[] { + ICSParamValue.BINARY + }) + }); private string valueType = string.Empty; private string encodingType = string.Empty; @@ -39,21 +58,9 @@ namespace CampusAppWP8.Utility public Attachment() { - this.ParamList = new List(); - this.ParamList.AddRange(new string[] { - ICSParam.NONE, - ICSParam.FORMAT_TYPE, - ICSParam.ENCODING, - ICSParam.VALUE_TYPE - }); } - public void Set(string valueStr, string paramStr) - { - this.Set(valueStr, paramStr.Split(';')); - } - - public void Set(string valueStr, string[] paramStrList) + public override void Set(string valueStr, string[] paramStrList) { foreach (string p in paramStrList) { @@ -91,12 +98,7 @@ namespace CampusAppWP8.Utility } } - public byte[] GetBytes() - { - return Encoding.UTF8.GetBytes(this.GetString()); - } - - public string GetString() + public override string GetString() { string retValue = string.Empty; @@ -120,7 +122,7 @@ namespace CampusAppWP8.Utility return retValue; } - public byte[] Value + public byte[] ValueBytes { get { @@ -132,7 +134,7 @@ namespace CampusAppWP8.Utility } } - public string Value + public string ValueString { get { @@ -190,33 +192,25 @@ namespace CampusAppWP8.Utility public class Categories : Interface { // 3.8.1.2 - public const string Name = ICSTag.CATEGORIES; - public readonly List ParamList = null; + public static readonly string Name = ICSTag.CATEGORIES; + public static readonly List> PParams + = new List>(new Tuple[] { + new Tuple(ICSParam.LANGUAGE, null) + }); private List valueList = null; private string languageType = string.Empty; public Categories() { - this.ParamList = new List(); - this.ParamList.AddRange(new string[] { - ICSParam.NONE, - ICSParam.LANGUAGE - }); - this.valueList = new List(); } - public void Set(string valueStr, string paramStr) - { - this.Set(valueStr, paramStr.Split(';')); - } - - public void Set(string valueStr, string[] paramStrList) + public override void Set(string valueStr, string[] paramStrList) { if (paramStrList.Count() > 1) { - throw new NotSupportedException("in (" + ICSTag.CATEGORIES + ") is only the (" + ICSParam.LANGUAGE + ") param supported"); + throw new NotSupportedException("in (" + Name + ") is only the (" + ICSParam.LANGUAGE + ") param supported"); } else if (paramStrList.Count() == 1) { @@ -241,12 +235,7 @@ namespace CampusAppWP8.Utility this.valueList.AddRange(valueStr.Split(',')); } - public byte[] GetBytes() - { - return Encoding.UTF8.GetBytes(this.GetString()); - } - - public string GetString() + public override string GetString() { string retValue = string.Empty; @@ -307,8 +296,11 @@ namespace CampusAppWP8.Utility public class AccessClass : Interface { - // 3.8.1.3 - public const string Name = ICSTag.ACCESS_CLASS; + // 3.8.1.3. + public static readonly string Name = ICSTag.ACCESS_CLASS; + public static readonly List> PParams + = new List>(); + public readonly List ValueList = null; private string value = string.Empty; @@ -323,16 +315,11 @@ namespace CampusAppWP8.Utility }); } - public void Set(string valueStr, string paramStr) - { - this.Set(valueStr, paramStr.Split(';')); - } - - public void Set(string valueStr, string[] paramStrList) + public override void Set(string valueStr, string[] paramStrList) { if (paramStrList.Count() > 0) { - throw new NotSupportedException("in (" + ICSTag.ACCESS_CLASS + ") is no param supported"); + throw new NotSupportedException("in (" + Name + ") is no param supported"); } if (this.ValueList.IndexOf(valueStr) >= 0) @@ -345,14 +332,9 @@ namespace CampusAppWP8.Utility } } - public byte[] GetBytes() + public override string GetString() { - return Encoding.UTF8.GetBytes(this.GetString()); - } - - public string GetString() - { - return (ICSTag.ACCESS_CLASS + ":" + this.value); + return (Name + ":" + this.value); } public string Value @@ -379,8 +361,12 @@ namespace CampusAppWP8.Utility public class Comment : Interface { // 3.8.1.4 - public const string Name = ICSTag.COMMENT; - public readonly List ParamList = null; + public static readonly string Name = ICSTag.COMMENT; + public static readonly List> PParams + = new List>(new Tuple[] { + new Tuple(ICSParam.ALT_REPRESENTATION, null), + new Tuple(ICSParam.LANGUAGE, null) + }); private string altrep = string.Empty; private string languageType = string.Empty; @@ -388,20 +374,9 @@ namespace CampusAppWP8.Utility public Comment() { - this.ParamList = new List(); - this.ParamList.AddRange(new string[] { - ICSParam.NONE, - ICSParam.ALT_REPRESENTATION, - ICSParam.LANGUAGE - }); } - public void Set(string valueStr, string paramStr) - { - this.Set(valueStr, paramStr.Split(';')); - } - - public void Set(string valueStr, string[] paramStrList) + public override void Set(string valueStr, string[] paramStrList) { foreach (string p in paramStrList) { @@ -430,12 +405,7 @@ namespace CampusAppWP8.Utility this.value = valueStr; } - public byte[] GetBytes() - { - return Encoding.UTF8.GetBytes(this.GetString()); - } - - public string GetString() + public override string GetString() { string retValue = string.Empty; @@ -496,7 +466,7 @@ namespace CampusAppWP8.Utility public class Description : Comment // because the structure is the same { // 3.8.1.5 - public const string Name = ICSTag.DESCRIPTION; + public static readonly string Name = ICSTag.DESCRIPTION; public Description() : base() { @@ -506,7 +476,9 @@ namespace CampusAppWP8.Utility public class Geo : Interface { // 3.8.1.6 - public const string Name = ICSTag.GEO; + public static readonly string Name = ICSTag.GEO; + public static readonly List> PParams + = new List>(); private Tuple value = null; @@ -514,7 +486,7 @@ namespace CampusAppWP8.Utility { } - public void Set(string valueStr, string paramStr) + public override void Set(string valueStr, string paramStr) { if ((paramStr == null) || (paramStr.Equals(string.Empty))) { @@ -522,15 +494,15 @@ namespace CampusAppWP8.Utility } else { - throw new NotSupportedException("parameter are not supported in (" + ICSTag.GEO + ")"); + throw new NotSupportedException("parameter are not supported in (" + Name + ")"); } } - public void Set(string valueStr, string[] paramStrList = null) + public override void Set(string valueStr, string[] paramStrList = null) { if (paramStrList != null) { - throw new NotSupportedException("parameter are not supported in (" + ICSTag.GEO + ")"); + throw new NotSupportedException("parameter are not supported in (" + Name + ")"); } string[] valSplit = valueStr.Split(';'); @@ -543,12 +515,7 @@ namespace CampusAppWP8.Utility this.value = new Tuple(float.Parse(valSplit[0]), float.Parse(valSplit[1])); } - public byte[] GetBytes() - { - return Encoding.UTF8.GetBytes(this.GetString()); - } - - public string GetString() + public override string GetString() { string retValue = string.Empty; @@ -556,7 +523,7 @@ namespace CampusAppWP8.Utility if (this.value == null) { - throw new NotSupportedException("there is no value set for (" + ICSTag.GEO + ")"); + throw new NotSupportedException("there is no value set for (" + Name + ")"); } retValue += ":" + this.value.Item1.ToString() + ";" + this.value.Item2.ToString(); @@ -580,7 +547,7 @@ namespace CampusAppWP8.Utility public class Location : Comment // because the structure is the same { // 3.8.1.7. - public const string Name = ICSTag.LOCATION; + public static readonly string Name = ICSTag.LOCATION; public Location() : base() { @@ -590,7 +557,9 @@ namespace CampusAppWP8.Utility public class PercentComplete : Interface { // 3.8.1.8 - public const string Name = ICSTag.PERCENT; + public static readonly string Name = ICSTag.PERCENT; + public static readonly List> PParams + = new List>(); private int value = -1; @@ -598,7 +567,7 @@ namespace CampusAppWP8.Utility { } - public void Set(string valueStr, string paramStr) + public override void Set(string valueStr, string paramStr) { if ((paramStr == null) || (paramStr.Equals(string.Empty))) { @@ -606,26 +575,21 @@ namespace CampusAppWP8.Utility } else { - throw new NotSupportedException("parameter are not supported in (" + ICSTag.PERCENT + ")"); + throw new NotSupportedException("parameter are not supported in (" + Name + ")"); } } - public void Set(string valueStr, string[] paramStrList = null) + public override void Set(string valueStr, string[] paramStrList = null) { if (paramStrList != null) { - throw new NotSupportedException("parameter are not supported in (" + ICSTag.PERCENT + ")"); + throw new NotSupportedException("parameter are not supported in (" + Name + ")"); } this.value = int.Parse(valueStr); } - public byte[] GetBytes() - { - return Encoding.UTF8.GetBytes(this.GetString()); - } - - public string GetString() + public override string GetString() { string retValue = string.Empty; @@ -633,7 +597,7 @@ namespace CampusAppWP8.Utility if (this.value < 0) { - throw new NotSupportedException("there is no value set for (" + ICSTag.PERCENT + ")"); + throw new NotSupportedException("there is no value set for (" + Name + ")"); } retValue += ":" + this.value.ToString(); @@ -655,7 +619,7 @@ namespace CampusAppWP8.Utility } else { - throw new ArgumentOutOfRangeException("value must be in rang of [0..100] in (" + ICSTag.PERCENT + ")"); + throw new ArgumentOutOfRangeException("value must be in rang of [0..100] in (" + Name + ")"); } } } @@ -664,7 +628,9 @@ namespace CampusAppWP8.Utility public class Priority : Interface { // 3.8.1.9. - public const string Name = ICSTag.PRIORITY; + public static readonly string Name = ICSTag.PRIORITY; + public static readonly List> PParams + = new List>(); private int value = -1; @@ -672,7 +638,7 @@ namespace CampusAppWP8.Utility { } - public void Set(string valueStr, string paramStr) + public override void Set(string valueStr, string paramStr) { if ((paramStr == null) || (paramStr.Equals(string.Empty))) { @@ -680,31 +646,26 @@ namespace CampusAppWP8.Utility } else { - throw new NotSupportedException("parameter are not supported in (" + ICSTag.PRIORITY + ")"); + throw new NotSupportedException("parameter are not supported in (" + Name + ")"); } } - public void Set(string valueStr, string[] paramStrList = null) + public override void Set(string valueStr, string[] paramStrList = null) { if (paramStrList != null) { - throw new NotSupportedException("parameter are not supported in (" + ICSTag.PRIORITY + ")"); + throw new NotSupportedException("parameter are not supported in (" + Name + ")"); } this.value = int.Parse(valueStr); if ((this.value < 0) || (this.value > 9)) { - throw new ArgumentOutOfRangeException("value must be in the range of [0..9] in (" + ICSTag.PRIORITY + ")"); + throw new ArgumentOutOfRangeException("value must be in the range of [0..9] in (" + Name + ")"); } } - public byte[] GetBytes() - { - return Encoding.UTF8.GetBytes(this.GetString()); - } - - public string GetString() + public override string GetString() { string retValue = string.Empty; @@ -712,7 +673,7 @@ namespace CampusAppWP8.Utility if (this.value < 0 || this.value > 9) { - throw new NotSupportedException("there is no value set for (" + ICSTag.PRIORITY + ")"); + throw new NotSupportedException("there is no value set for (" + Name + ")"); } retValue += ":" + this.value.ToString(); @@ -734,7 +695,7 @@ namespace CampusAppWP8.Utility } else { - throw new ArgumentOutOfRangeException("value must be in rage of [0..9] in (" + ICSTag.PRIORITY + ")"); + throw new ArgumentOutOfRangeException("value must be in rage of [0..9] in (" + Name + ")"); } } } @@ -743,7 +704,7 @@ namespace CampusAppWP8.Utility public class Resources : Comment // because the structure is the same { // 3.8.1.10. - public const string Name = ICSTag.RESOURCES; + public static readonly string Name = ICSTag.RESOURCES; public Resources() : base() { @@ -753,7 +714,9 @@ namespace CampusAppWP8.Utility public class Status : Interface { // 3.8.1.11. - public const string Name = ICSTag.STATUS; + public static readonly string Name = ICSTag.STATUS; + public static readonly List> PParams + = new List>(); public readonly List ValueListEvent = null; public readonly List ValueListToDo = null; @@ -786,7 +749,7 @@ namespace CampusAppWP8.Utility }); } - public void Set(string valueStr, string paramStr) + public override void Set(string valueStr, string paramStr) { if ((paramStr == null) || (paramStr.Equals(string.Empty))) { @@ -794,38 +757,32 @@ namespace CampusAppWP8.Utility } else { - throw new NotSupportedException("parameter are not supported in (" + ICSTag.STATUS + ")"); + throw new NotSupportedException("parameter are not supported in (" + Name + ")"); } } - public void Set(string valueStr, string[] paramStrList = null) + public override void Set(string valueStr, string[] paramStrList = null) { if (paramStrList != null) { - throw new NotSupportedException("parameter are not supported in (" + ICSTag.PRIORITY + ")"); + throw new NotSupportedException("parameter are not supported in (" + Name + ")"); } if ((this.ValueListEvent.IndexOf(valueStr) < 0) && (this.ValueListToDo.IndexOf(valueStr) < 0) && (this.ValueListJournal.IndexOf(valueStr) < 0)) { - throw new NotSupportedException("value (" + valueStr + ") is not supported in (" + ICSTag.STATUS + ")"); + throw new NotSupportedException("value (" + valueStr + ") is not supported in (" + Name + ")"); } this.value = valueStr; } - - public byte[] GetBytes() - { - return Encoding.UTF8.GetBytes(this.GetString()); - } - - public string GetString() + public override string GetString() { string retValue = string.Empty; - retValue += ICSTag.STATUS + ":" + this.value; + retValue += Name + ":" + this.value; return retValue; } @@ -846,7 +803,7 @@ namespace CampusAppWP8.Utility } else { - throw new NotSupportedException("value (" + value + ") is not supported in (" + ICSTag.STATUS + ")"); + throw new NotSupportedException("value (" + value + ") is not supported in (" + Name + ")"); } } } @@ -855,7 +812,7 @@ namespace CampusAppWP8.Utility public class Summary : Comment // because the structure is the same { // 3.8.1.12. - public const string Name = ICSTag.SUMMARY; + public static readonly string Name = ICSTag.SUMMARY; public Summary() : base() @@ -866,7 +823,9 @@ namespace CampusAppWP8.Utility public class DTCompleted : Interface { // 3.8.2.1. - public readonly string Name = ICSTag.COMPLETED; + public static readonly string Name = ICSTag.COMPLETED; + public static readonly List> PParams + = new List>(); private DateTime value = DateTime.MinValue; @@ -874,7 +833,7 @@ namespace CampusAppWP8.Utility { } - public void Set(string valueStr, string paramStr) + public override void Set(string valueStr, string paramStr) { if ((paramStr == null) || (paramStr.Equals(string.Empty))) { @@ -882,30 +841,25 @@ namespace CampusAppWP8.Utility } else { - throw new NotSupportedException("parameter are not supported in (" + this.Name + ")"); + throw new NotSupportedException("parameter are not supported in (" + Name + ")"); } } - public void Set(string valueStr, string[] paramStrList = null) + public override void Set(string valueStr, string[] paramStrList = null) { if (paramStrList != null) { - throw new NotSupportedException("parameter are not supported in (" + this.Name + ")"); + throw new NotSupportedException("parameter are not supported in (" + Name + ")"); } this.value = UTCStringToDateTime(valueStr); } - public byte[] GetBytes() - { - return Encoding.UTF8.GetBytes(this.GetString()); - } - - public string GetString() + public override string GetString() { string retValue = string.Empty; - retValue += this.Name + ":" + string.Format("{0:yyyyMMdd}T{0:HHmmss}Z", this.value.ToUniversalTime()); + retValue += Name + ":" + string.Format("{0:yyyyMMdd}T{0:HHmmss}Z", this.value.ToUniversalTime()); return retValue; } @@ -926,43 +880,31 @@ namespace CampusAppWP8.Utility public class DTEnd : Interface { // 3.8.2.2. - public readonly string Name = ICSTag.DT_END; - - public readonly List ParamList = null; - public readonly List ParamValueList = null; + public static readonly string Name = ICSTag.DT_END; + public static readonly List> PParams + = new List>(new Tuple[] { + new Tuple(ICSParam.VALUE_TYPE, new string[] { + ICSParamValue.DATE_TIME, + ICSParamValue.DATE + }), + new Tuple(ICSParam.TIME_ZONE_ID, null) + }); private DateTime value = DateTime.MinValue; - private string timeZone = string.Empty; - private bool isDate = false; + private List> paramList = null; public DTEnd() { - this.ParamList = new List(); - this.ParamList.AddRange(new string[] { - ICSParam.NONE, - ICSParam.VALUE_TYPE, - ICSParam.TIME_ZONE_ID - }); - - this.ParamValueList = new List(); - this.ParamValueList.AddRange(new string[] { - ICSParamValue.DATE_TIME, - ICSParamValue.DATE - }); + this.paramList = new List>(); } - public void Set(string valueStr, string paramStr) - { - this.Set(valueStr, paramStr.Split(';')); - } - - public void Set(string valueStr, string[] paramStrList = null) + public override void Set(string valueStr, string[] paramStrList = null) { if (paramStrList != null) { if (paramStrList.Count() > 2) { - throw new NotSupportedException("too many params in (" + this.Name + ")"); + throw new NotSupportedException("too many params in (" + Name + ")"); } for(int i = 0; i < paramStrList.Count(); i++) @@ -971,69 +913,68 @@ namespace CampusAppWP8.Utility if (p.Count() != 2) { - throw new NotSupportedException("incorrect param string (" + paramStrList[0] + ")"); + throw new FormatException("incorrect param string (" + paramStrList[0] + ")"); } - if (p[0].Equals(ICSParam.VALUE_TYPE)) + if (CheckParamAndParamValue(p[0], p[1], PParams.ToArray())) { - if (p[1].Equals(ICSParamValue.DATE)) + int pos = CheckParam(p[0], this.paramList.ToArray()); + + if(pos < 0) { - this.isDate = true; - } - else if (p[1].Equals(ICSParamValue.DATE_TIME)) - { - this.isDate = false; + this.paramList.Add(new Tuple(p[0], p[1])); } else { - throw new NotSupportedException("param value (" + p[1] + ") is not supported in (" + this.Name + ")"); + throw new FormatException("param (" + p[0] + ") sould only occure once"); } } - else if(p[0].Equals(ICSParam.TIME_ZONE_ID)) - { - this.timeZone = p[1]; - } else { - throw new NotSupportedException("param (" + p[0] + ") is not supported in (" + this.Name + ")"); + throw new NotSupportedException("param (" + p[0] + ") is not supported in (" + Name + ")"); } } } bool tempIsDate = IsDate(valueStr); + bool isDate = false; + int posVal = CheckParam(ICSParam.VALUE_TYPE, this.paramList.ToArray()); - if (this.isDate != tempIsDate) + if(posVal >= 0 && this.paramList[posVal].Item2.Equals(ICSParamValue.DATE)) { - throw new NotSupportedException("time value has not the same type as declared in param in(" + this.Name + ")"); + isDate = true; + } + + if (isDate != tempIsDate) + { + throw new NotSupportedException("time value has not the same type as declared in param in(" + Name + ")"); } this.value = UTCStringToDateTime(valueStr); } - public byte[] GetBytes() - { - return Encoding.UTF8.GetBytes(this.GetString()); - } - - public string GetString() + public override string GetString() { string retValue = string.Empty; - retValue += this.Name; + retValue += Name; - if(!this.timeZone.Equals(string.Empty)) + for(int i = 0; i < this.paramList.Count(); i++) { - retValue += ";" + this.timeZone; - } - - if (this.isDate) - { - retValue += ";" + ICSParam.VALUE_TYPE + "=" + ICSParamValue.DATE; + retValue += ";" + this.paramList[i].Item1 + "=" + this.paramList[i].Item2; } retValue += ":"; - if (this.isDate) + int pos = CheckParam(ICSParam.VALUE_TYPE, this.paramList.ToArray()); + bool isDate = false; + + if (pos >= 0 && this.paramList[pos].Item2.Equals(ICSParamValue.DATE)) + { + isDate = true; + } + + if (isDate) { retValue += string.Format("{0:yyyyMMdd}", this.value.ToUniversalTime()); } @@ -1061,11 +1002,28 @@ namespace CampusAppWP8.Utility { get { - return this.isDate; + bool isDate = false; + int pos = CheckParam(ICSParam.VALUE_TYPE, this.paramList.ToArray()); + + if (pos >= 0 && this.paramList[pos].Item2.Equals(ICSParamValue.DATE)) + { + isDate = true; + } + + return isDate; } set { - this.isDate = value; + int pos = CheckParam(ICSParam.VALUE_TYPE, this.paramList.ToArray()); + + if (pos < 0) + { + this.paramList.Add(new Tuple(ICSParam.VALUE_TYPE, (value == true) ? ICSParamValue.DATE : ICSParamValue.DATE_TIME)); + } + else + { + this.paramList[pos] = new Tuple(ICSParam.VALUE_TYPE, (value == true) ? ICSParamValue.DATE : ICSParamValue.DATE_TIME); + } } } @@ -1073,11 +1031,29 @@ namespace CampusAppWP8.Utility { get { - return this.timeZone; + int pos = CheckParam(ICSParam.TIME_ZONE_ID, this.paramList.ToArray()); + + if (pos >= 0) + { + return this.paramList[pos].Item2; + } + else + { + return string.Empty; + } } set { - this.timeZone = value; + int pos = CheckParam(ICSParam.TIME_ZONE_ID, this.paramList.ToArray()); + + if (pos < 0) + { + this.paramList.Add(new Tuple(ICSParam.TIME_ZONE_ID, value)); + } + else + { + this.paramList[pos] = new Tuple(ICSParam.TIME_ZONE_ID, value); + } } } } @@ -1085,7 +1061,7 @@ namespace CampusAppWP8.Utility public class DTDue : DTEnd // because the structure is the same { // 3.8.2.3. - public readonly string Name = ICSTag.DUE; + public static readonly string Name = ICSTag.DUE; public DTDue() : base() @@ -1096,7 +1072,7 @@ namespace CampusAppWP8.Utility public class DTStart : DTEnd // because the structure is the same { // 3.8.2.4. - public readonly string Name = ICSTag.DT_START; + public static readonly string Name = ICSTag.DT_START; public DTStart() : base() @@ -1107,7 +1083,9 @@ namespace CampusAppWP8.Utility public class Duration : Interface { // 3.8.2.5. - public readonly string Name = ICSTag.DURATION; + public static readonly string Name = ICSTag.DURATION; + public static readonly List> PParams + = new List>(); private TimeSpan value = TimeSpan.Zero; private bool isNegative = false; @@ -1116,31 +1094,26 @@ namespace CampusAppWP8.Utility { } - public void Set(string valueStr, string paramStr) + public override void Set(string valueStr, string paramStr) { this.Set(valueStr); } - public void Set(string valueStr, string[] paramStrList = null) + public override void Set(string valueStr, string[] paramStrList = null) { if (paramStrList != null) { - throw new NotSupportedException("params are not supported in (" + this.Name + ")"); + throw new NotSupportedException("params are not supported in (" + Name + ")"); } this.value = StringToTimeSpan(valueStr); } - public byte[] GetBytes() - { - return Encoding.UTF8.GetBytes(this.GetString()); - } - - public string GetString() + public override string GetString() { string retValue = string.Empty; - retValue += this.Name + ":" + TimeSpanToString(this.value, this.isNegative); + retValue += Name + ":" + TimeSpanToString(this.value, this.isNegative); return retValue; } @@ -1173,9 +1146,16 @@ namespace CampusAppWP8.Utility public class FreeBusyTime : Interface { // 3.8.2.6. - public readonly string Name = ICSTag.FREEBUSY; - public readonly List ParamList = null; - public readonly List ParamValueList = null; + public static readonly string Name = ICSTag.FREEBUSY; + public static readonly List> PParams + = new List>(new Tuple[] { + new Tuple(ICSParam.FREE_BUSY_TIME_TYPE, new string[] { + ICSParamValue.FREE, + ICSParamValue.BUSY, + ICSParamValue.BUSY_UNAVAILABLE, + ICSParamValue.BUSY_TENTATIVE + }) + }); private string freebusyType = string.Empty; private List> valueList = null; @@ -1183,34 +1163,15 @@ namespace CampusAppWP8.Utility public FreeBusyTime() { this.valueList = new List>(); - - this.ParamList = new List(); - this.ParamList.AddRange(new string[] { - ICSParam.NONE, - ICSParam.FREE_BUSY_TIME_TYPE - }); - - this.ParamValueList = new List(); - this.ParamValueList.AddRange(new string[] { - ICSParamValue.FREE, - ICSParamValue.BUSY, - ICSParamValue.BUSY_UNAVAILABLE, - ICSParamValue.BUSY_TENTATIVE - }); } - public void Set(string valueStr, string paramStr) - { - this.Set(valueStr, paramStr.Split(';')); - } - - public void Set(string valueStr, string[] paramStrList = null) + public override void Set(string valueStr, string[] paramStrList = null) { if (paramStrList != null && paramStrList.Count() > 0) { if (paramStrList.Count() > 1) { - throw new NotSupportedException("there is only 1 param in (" + this.Name + ") supported"); + throw new NotSupportedException("there is only 1 param in (" + Name + ") supported"); } string[] pSplit = paramStrList[0].Split('='); @@ -1220,15 +1181,15 @@ namespace CampusAppWP8.Utility throw new FormatException("parameter string (" + paramStrList[0] + ") is wrong"); } - if (pSplit[0].Equals(ICSParam.FREE_BUSY_TIME_TYPE)) + if (CheckParamAndParamValue(pSplit[0], pSplit[1], PParams.ToArray())) { - if (this.ParamValueList.IndexOf(pSplit[1]) < 0) + if (this.freebusyType.Equals(string.Empty)) { - throw new NotSupportedException("unsupported param value (" + pSplit[1] + ")"); + this.freebusyType = pSplit[1]; } else { - this.freebusyType = pSplit[1]; + throw new FormatException("param (" + pSplit[0] + ") sould only occure once"); } } else @@ -1266,16 +1227,11 @@ namespace CampusAppWP8.Utility } } - public byte[] GetBytes() - { - return Encoding.UTF8.GetBytes(this.GetString()); - } - - public string GetString() + public override string GetString() { string retValue = string.Empty; - retValue += this.Name; + retValue += Name; if (!this.freebusyType.Equals(string.Empty)) { @@ -1326,7 +1282,7 @@ namespace CampusAppWP8.Utility } set { - if (this.ParamValueList.IndexOf(value) < 0) + if (!CheckParamAndParamValue(ICSParam.FREE_BUSY_TIME_TYPE, value, PParams.ToArray())) { throw new NotSupportedException("param value (" + value + ") is not supported"); } @@ -1351,7 +1307,10 @@ namespace CampusAppWP8.Utility public class TimeTransparency : Interface { // 3.8.2.7. - public readonly string Name = ICSTag.TRANSP; + public static readonly string Name = ICSTag.TRANSP; + public static readonly List> PParams + = new List>(); + public readonly List ValueList = null; private string value = ICSValue.OPAQUE; @@ -1365,16 +1324,16 @@ namespace CampusAppWP8.Utility }); } - public void Set(string valueStr, string paramStr) + public override void Set(string valueStr, string paramStr) { this.Set(valueStr); } - public void Set(string valueStr, string[] paramStrList = null) + public override void Set(string valueStr, string[] paramStrList = null) { if (paramStrList != null) { - throw new NotSupportedException("params are not supported in (" + this.Name + ")"); + throw new NotSupportedException("params are not supported in (" + Name + ")"); } if (this.ValueList.IndexOf(valueStr) < 0) @@ -1385,16 +1344,11 @@ namespace CampusAppWP8.Utility this.value = valueStr; } - public byte[] GetBytes() - { - return Encoding.UTF8.GetBytes(this.GetString()); - } - - public string GetString() + public override string GetString() { string retValue = string.Empty; - retValue += this.Name + ":" + this.value; + retValue += Name + ":" + this.value; return retValue; } @@ -1422,7 +1376,9 @@ namespace CampusAppWP8.Utility public class TimeZoneIdentifier : Interface { // 3.8.3.1. - public readonly string Name = ICSTag.TIME_ZONE_ID; + public static readonly string Name = ICSTag.TIME_ZONE_ID; + public static readonly List> PParams + = new List>(); private string value = string.Empty; @@ -1430,31 +1386,26 @@ namespace CampusAppWP8.Utility { } - public void Set(string valueStr, string paramStr) + public override void Set(string valueStr, string paramStr) { this.Set(valueStr); } - public void Set(string valueStr, string[] paramStrList = null) + public override void Set(string valueStr, string[] paramStrList = null) { if (paramStrList != null) { - throw new NotSupportedException("params are not supported in (" + this.Name + ")"); + throw new NotSupportedException("params are not supported in (" + Name + ")"); } this.value = valueStr; } - public byte[] GetBytes() - { - return Encoding.UTF8.GetBytes(this.GetString()); - } - - public string GetString() + public override string GetString() { string retValue = string.Empty; - retValue += this.Name + ":" + this.value; + retValue += Name + ":" + this.value; return retValue; } @@ -1475,33 +1426,26 @@ namespace CampusAppWP8.Utility public class TimeZoneName : Interface { // 3.8.3.2. - public readonly string Name = ICSTag.TIME_ZONE_NAME; - public readonly List ParamList = null; + public static readonly string Name = ICSTag.TIME_ZONE_NAME; + public static readonly List> PParams + = new List>(new Tuple[] { + new Tuple(ICSParam.LANGUAGE, null) + }); private string language = string.Empty; private string value = string.Empty; public TimeZoneName() { - this.ParamList = new List(); - this.ParamList.AddRange(new string[] { - ICSParam.NONE, - ICSParam.LANGUAGE - }); } - public void Set(string valueStr, string paramStr) - { - this.Set(valueStr, paramStr.Split(';')); - } - - public void Set(string valueStr, string[] paramStrList = null) + public override void Set(string valueStr, string[] paramStrList = null) { if (paramStrList != null) { if (paramStrList.Count() > 1) { - throw new NotSupportedException("ther is only 1 param supported in (" + this.Name + ")"); + throw new NotSupportedException("there is only 1 param supported in (" + Name + ")"); } if (paramStrList.Count() == 1) @@ -1527,16 +1471,11 @@ namespace CampusAppWP8.Utility this.value = valueStr; } - public byte[] GetBytes() - { - return Encoding.UTF8.GetBytes(this.GetString()); - } - - public string GetString() + public override string GetString() { string retValue = string.Empty; - retValue += this.Name; + retValue += Name; if (!this.language.Equals(string.Empty)) { @@ -1576,7 +1515,9 @@ namespace CampusAppWP8.Utility public class TimeZoneOffsetFrom : Interface { // 3.8.3.3. - public readonly string Name = ICSTag.TIME_ZONE_OFFSET_FROM; + public static readonly string Name = ICSTag.TIME_ZONE_OFFSET_FROM; + public static readonly List> PParams + = new List>(); private bool isNegative = false; private TimeSpan value = TimeSpan.Zero; @@ -1585,16 +1526,16 @@ namespace CampusAppWP8.Utility { } - public void Set(string valueStr, string paramStr) + public override void Set(string valueStr, string paramStr) { this.Set(valueStr); } - public void Set(string valueStr, string[] paramStrList = null) + public override void Set(string valueStr, string[] paramStrList = null) { if (paramStrList != null) { - throw new NotSupportedException("no param supported in (" + this.Name + ")"); + throw new NotSupportedException("no param supported in (" + Name + ")"); } if(valueStr[0].Equals('+')) @@ -1613,16 +1554,11 @@ namespace CampusAppWP8.Utility this.value = new TimeSpan(int.Parse(valueStr.Substring(1, 2)), int.Parse(valueStr.Substring(3, 2)), ((valueStr.Length > 5) ? int.Parse(valueStr.Substring(5, 2)) : 0)); } - public byte[] GetBytes() - { - return Encoding.UTF8.GetBytes(this.GetString()); - } - - public string GetString() + public override string GetString() { string retValue = string.Empty; - retValue += this.Name + ":" + ((this.isNegative) ? "-" : "+") + string.Format("{0:HHmm}", this.value); + retValue += Name + ":" + ((this.isNegative) ? "-" : "+") + string.Format("{0:HHmm}", this.value); return retValue; } @@ -1652,7 +1588,466 @@ namespace CampusAppWP8.Utility } } + public class TimeZoneOffsetTo : TimeZoneOffsetFrom // because the structure is the same + { + // 3.8.3.4. + public static readonly string Name = ICSTag.TIME_ZONE_OFFSET_TO; + + public TimeZoneOffsetTo() + : base() + { + } + } + + public class TimeZoneUrl : Interface // INTERFACE: string value only + { + // 3.8.3.5. + public static readonly string Name = ICSTag.TIME_ZONE_URL; + public static readonly List> PParams + = new List>(); + + private string value = string.Empty; + + public TimeZoneUrl() + { + } + + public override void Set(string valueStr, string paramStr) + { + this.Set(valueStr); + } + + public override void Set(string valueStr, string[] paramStrList = null) + { + if (paramStrList != null) + { + throw new NotSupportedException("no param supported in (" + Name + ")"); + } + + this.value = valueStr; + } + + public override string GetString() + { + string retValue = string.Empty; + + retValue += Name + ":" + this.value; + + return retValue; + } + + public string Value + { + get + { + return this.value; + } + set + { + this.value = value; + } + } + } + + public class Attendee : Interface + { + // 3.8.4.1. + public static readonly string Name = ICSTag.ATTENDEE; + public static readonly List> PParams + = new List>(new Tuple[] { + new Tuple(ICSParam.CALENDAR_USER_TYPE, new string[] { + ICSParamValue.INDIVIDUAL, + ICSParamValue.GROUP, + ICSParamValue.RESOURCE, + ICSParamValue.ROOM, + ICSParamValue.UNKNOWN + }), + new Tuple(ICSParam.MEMBER, null), + new Tuple(ICSParam.PARTICIPATION_ROLE, new string[] { + ICSParamValue.CHAIR, + ICSParamValue.REQ_PARTICIPANT, + ICSParamValue.OPT_PARTICIPANT, + ICSParamValue.NON_PARTICIPANT + }), + new Tuple(ICSParam.PARTICIPATION_STATUS, new string[] { + // event + ICSParamValue.NEEDS_ACTION, + ICSParamValue.ACCEPTED, + ICSParamValue.DECLINED, + ICSParamValue.TENTATIVE, + ICSParamValue.DELEGATED, + // todo + ICSParamValue.COMPLETED, + ICSParamValue.IN_PROCESS + // journat + }), + new Tuple(ICSParam.REPLY_EXPECTATION, new string[] { + ICSParamValue.TRUE, + ICSParamValue.FALSE + }), + new Tuple(ICSParam.DELEGATEES, null), + new Tuple(ICSParam.DELEGATORS, null), + new Tuple(ICSParam.SENT_BY, null), + new Tuple(ICSParam.COMMON_NAME, null), + new Tuple(ICSParam.DIR_REFERENCE, null), + new Tuple(ICSParam.LANGUAGE, null) + }); + + protected List> paramList = null; + protected string value = string.Empty; + + public Attendee() + { + this.paramList = new List>(); + } + + public override void Set(string valueStr, string[] paramStrList = null) + { + if (paramStrList != null) + { + for (int i = 0; i < paramStrList.Count(); i++) + { + string[] pSplit = paramStrList[i].Split('='); + + if (pSplit.Count() != 2) + { + throw new FormatException("unsupported param format (" + paramStrList + ") in (" + Name + ")"); + } + + if(CheckParamAndParamValue(pSplit[0], pSplit[1], PParams.ToArray())) + { + this.paramList.Add(new Tuple(pSplit[0], pSplit[1])); + } + else + { + throw new NotSupportedException("unsupported param (" + paramStrList[i] + ") in (" + Name + ")"); + } + } + } + + this.value = valueStr; + } + + public override string GetString() + { + string retValue = string.Empty; + + retValue += Name; + + for (int i = 0; i < this.paramList.Count(); i++) + { + retValue += ";" + this.paramList[i].Item1 + "=" + this.paramList[i].Item2; + } + + retValue += ":" + this.value; + + return retValue; + } + + public string Value + { + get + { + return this.value; + } + set + { + this.value = value; + } + } + + public List> Param + { + get + { + return this.paramList; + } + set + { + for (int i = 0; i < value.Count(); i++) + { + if (!CheckParamAndParamValue(value[i].Item1, value[i].Item2, PParams.ToArray())) + { + throw new NotSupportedException("param (" + value[i] + ") is not supported"); + } + } + + this.paramList = value; + } + } + + public void AddParam(string paramStr, string valueStr) + { + if (CheckParamAndParamValue(paramStr, valueStr, PParams.ToArray())) + { + RemoveParam(paramStr); + + this.paramList.Add(new Tuple(paramStr, valueStr)); + } + } + + public void RemoveParam(string paramStr) + { + int pos = CheckParam(paramStr, this.paramList.ToArray()); + + if (pos >= 0) + { + this.paramList.RemoveAt(pos); + } + } + } + + public class Contact : Comment // because the structure is the same + { + // 3.8.4.2. + public static readonly string Name = ICSTag.CONTACT; + + public Contact() + : base() + { + } + } + + public class Organizer : Attendee // nearly the same structure + { + // 3.8.4.3. + public static readonly string Name = ICSTag.ORGANIZER; + public static readonly List> PParams + = new List>(new Tuple[] { + new Tuple(ICSParam.COMMON_NAME, null), + new Tuple(ICSParam.DIR_REFERENCE, null), + new Tuple(ICSParam.SENT_BY, null), + new Tuple(ICSParam.LANGUAGE, null) + }); + + public Organizer() : base() + { + } + } + + public class RecurrenceID : DTEnd // because the structure is the same + { + // 3.8.4.4. + public static readonly string Name = ICSTag.RECURRENCE_ID; + + public RecurrenceID() + : base() + { + } + } + + public class RelatedTo : Interface + { + // 3.8.4.5. + public static readonly string Name = ICSTag.RELATED; + public static readonly List> PParams + = new List>(new Tuple[] { + new Tuple(ICSParam.RELATIONSHIP_TYPE, new string[] { + ICSParamValue.PARENT, + ICSParamValue.CHILD, + ICSParamValue.SIBLING + }) + }); + + private string value = string.Empty; + private string realType = string.Empty; + + public RelatedTo() + { + } + + public override void Set(string valueStr, string[] paramStrList = null) + { + if (paramStrList != null && paramStrList.Count() > 0) + { + if (paramStrList.Count() > 1) + { + throw new NotSupportedException("there is only 1 param supported"); + } + else + { + string[] pSplit = paramStrList[0].Split('='); + + if (pSplit.Count() != 2) + { + throw new FormatException("unsupported param format (" + paramStrList + ") in (" + Name + ")"); + } + + if (CheckParamAndParamValue(pSplit[0], pSplit[1], PParams.ToArray())) + { + this.realType = pSplit[1]; + } + else + { + throw new NotSupportedException("unsupported param (" + paramStrList[0] + ") in (" + Name + ")"); + } + } + } + + this.value = valueStr; + } + + public override string GetString() + { + string retValue = string.Empty; + + retValue += Name; + + if(!this.realType.Equals(string.Empty)) + { + retValue += ";" + ICSParam.RELATIONSHIP_TYPE + "=" + this.realType; + } + + retValue += ":" + this.value; + + return retValue; + } + + public string Value + { + get + { + return this.value; + } + set + { + this.value = value; + } + } + + public string RealType + { + get + { + return this.realType; + } + set + { + if (CheckParamAndParamValue(ICSParam.RELATIONSHIP_TYPE, value, PParams.ToArray())) + { + this.realType = value; + } + else + { + throw new NotSupportedException("param value (" + value + ") is not supported"); + } + } + } + } + + public class Url : TimeZoneUrl // because structure is the same + { + // 3.8.4.6. + public static readonly string Name = ICSTag.URL; + + public Url() + : base() + { + } + } + + public class UniqueID : TimeZoneUrl // because structure is the same + { + // 3.8.4.7. + public static readonly string Name = ICSTag.UNIQUE_ID; + + public UniqueID() + : base() + { + } + } + + public class DTException : DTEnd // because structure is the same + { + // 3.8.5.1. + public static readonly string Name = ICSTag.EXDATE; + + public DTException() + : base() + { + } + } + + public class DTRecurrence : Interface + { + // 3.8.5.2. + public static readonly string Name = ICSTag.RDATE; + public static readonly List> PParams + = new List>(new Tuple[] { + new Tuple(ICSParam.VALUE_TYPE, new string[] { + ICSParamValue.DATE_TIME, + ICSParamValue.DATE, + ICSParamValue.PERIOD + }), + new Tuple(ICSParam.TIME_ZONE_ID, null) + }); + + public DTRecurrence() + { +// CONTINUE + } + } + + // functions + private static int CheckParam(string paramStr, Tuple[] list) + { + int retValue = -1; + + for (int i = 0; i < list.Count(); i++) + { + if (paramStr.Equals(list[i].Item1)) + { + retValue = i; + } + } + + return retValue; + } + + private static int CheckParam(string paramStr, Tuple[] list) + { + int retValue = -1; + + for(int i = 0; i < list.Count(); i++) + { + if(paramStr.Equals(list[i].Item1)) + { + retValue = i; + } + } + + return retValue; + } + + private static bool CheckParamAndParamValue(string paramStr, string paramValueStr, Tuple[] list) + { + bool retValue = false; + + int paramPos = CheckParam(paramStr, list); + + if (paramPos >= 0) + { + if (list[paramPos].Item2 == null) + { + retValue = true; + } + else + { + for (int i = 0; i < list[paramPos].Item2.Count(); i++) + { + if (paramValueStr.Equals(list[paramPos].Item2[i])) + { + retValue = true; + } + } + } + } + + return retValue; + } + + private static DateTime UTCStringToDateTime(string timeStr) { // see http://tools.ietf.org/html/rfc5545 3.3.5. diff --git a/CampusAppWP8/CampusAppWP8/Utility/ICSObject.cs b/CampusAppWP8/CampusAppWP8/Utility/ICSObject.cs index 2e4fa63a..eee65a89 100644 --- a/CampusAppWP8/CampusAppWP8/Utility/ICSObject.cs +++ b/CampusAppWP8/CampusAppWP8/Utility/ICSObject.cs @@ -64,6 +64,13 @@ namespace CampusAppWP8.Utility public void ImportFromICS(string icsData) { + string t1 = ICSClasses.Attachment.Name; + string t2 = ICSClasses.Categories.Name; + ICSClasses.Attachment o1 = new ICSClasses.Attachment(); + ICSClasses.Categories o2 = new ICSClasses.Categories(); + List> l1 = ICSClasses.Attachment.PParams; + List> l2 = ICSClasses.Categories.PParams; + string[] elems = Regex.Split(this.Unfold(icsData), "\r\n"); List parentList = new List(); diff --git a/CampusAppWP8/CampusAppWP8/Utility/ICSObjectConst.cs b/CampusAppWP8/CampusAppWP8/Utility/ICSObjectConst.cs index d4e56490..9b4fcc02 100644 --- a/CampusAppWP8/CampusAppWP8/Utility/ICSObjectConst.cs +++ b/CampusAppWP8/CampusAppWP8/Utility/ICSObjectConst.cs @@ -442,7 +442,7 @@ namespace CampusAppWP8.Utility public const string VEVENT = "VEVENT"; // 1-1 public const string DT_STAMP = "DTSTAMP"; - public const string USER_ID = "UID"; + public const string UNIQUE_ID = "UID"; // if METHOD is NOT set: 1-1 // otherwise: 0-1 public const string DT_START = "DTSTART"; @@ -581,7 +581,7 @@ namespace CampusAppWP8.Utility public const string SENT_BY = "SENT-BY"; public const string TIME_ZONE_ID = "TZID"; public const string VALUE_TYPE = "VALUE"; - public const string NONE = string.Empty; + public const string NONE = ""; } public class ICSValue @@ -671,5 +671,7 @@ namespace CampusAppWP8.Utility public const string TIME = "TIME"; public const string URI = "URI"; public const string UTC_OFFSET = "UTC-OFFSET"; + // PARTSTAT + public const string IN_PROCESS = "IN-PROCESS"; } }