SmartAPI
Open Source .NET RQL library for RedDot CMS / OpenText WSM Management Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
DateTimeFormat.cs
Go to the documentation of this file.
1 ï»¿// SmartAPI - .Net programmatic access to RedDot servers
2 //
3 // Copyright (C) 2013 erminas GbR
4 //
5 // This program is free software: you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License as published by the Free Software Foundation,
7 // either version 3 of the License, or (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 // See the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program.
14 // If not, see <http://www.gnu.org/licenses/>.
15 
16 using System;
17 using System.Xml;
18 using erminas.SmartAPI.Utils;
19 
20 namespace erminas.SmartAPI.CMS
21 {
22  public interface IDateTimeFormat
23  {
27  string Example { get; }
28 
29  bool IsDateFormat { get; }
30  bool IsDateTimeFormat { get; }
31  bool IsTimeFormat { get; }
32  bool IsUserDefined { get; }
33 
37  string Name { get; }
38 
42  int TypeId { get; }
43  }
44 
49  {
50  public static readonly IDateTimeFormat USER_DEFINED_DATE_FORMAT = new DateTimeFormat(DateTimeFormatTypes.Date);
51  public static readonly IDateTimeFormat USER_DEFINED_TIME_FORMAT = new DateTimeFormat(DateTimeFormatTypes.Time);
52 
53  public static readonly IDateTimeFormat USER_DEFINED_DATE_TIME_FORMAT =
54  new DateTimeFormat(DateTimeFormatTypes.DateTime);
55 
56  private readonly DateTimeFormatTypes _formatTypes;
57 
58  internal DateTimeFormat(DateTimeFormatTypes dateTimeFormatTypes, XmlElement xmlElement)
59  {
60  Name = xmlElement.GetAttributeValue("name");
61  TypeId = int.Parse(xmlElement.GetAttributeValue("type"));
62  Example = xmlElement.GetAttributeValue("example");
63  _formatTypes = dateTimeFormatTypes;
64  }
65 
66  private DateTimeFormat(DateTimeFormatTypes dateTimeFormatTypes)
67  {
68  Name = "user defined";
69  TypeId = -1;
70  Example = "";
71  _formatTypes = dateTimeFormatTypes;
72  }
73 
77  public string Example { get; private set; }
78 
79  public bool IsDateFormat
80  {
81  get { return (_formatTypes & DateTimeFormatTypes.Date) == DateTimeFormatTypes.Date; }
82  }
83 
84  public bool IsDateTimeFormat
85  {
86  get { return (_formatTypes & DateTimeFormatTypes.DateTime) == DateTimeFormatTypes.DateTime; }
87  }
88 
89  public bool IsTimeFormat
90  {
91  get
92  {
93  //Nothing can be combined with time formats.
94  return _formatTypes == DateTimeFormatTypes.Time;
95  }
96  }
97 
98  public bool IsUserDefined
99  {
100  get
101  {
102  return this == USER_DEFINED_DATE_FORMAT || this == USER_DEFINED_DATE_TIME_FORMAT ||
103  this == USER_DEFINED_TIME_FORMAT;
104  }
105  }
106 
110  public string Name { get; private set; }
111 
115  public int TypeId { get; private set; }
116  }
117 
118  [Flags]
120  {
121  Date = 1,
122  Time = 2,
123  DateTime = 4
124  }
125 }