SmartAPI
Open Source .NET RQL library for RedDot CMS / OpenText WSM Management Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
ContentClasses/Elements/IStandardFieldTime.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.Linq;
18 using System.Xml;
19 using erminas.SmartAPI.CMS.Converter;
20 
21 namespace erminas.SmartAPI.CMS.Project.ContentClasses.Elements
22 {
24  {
25  bool IsUserDefinedTimeFormat(string languageAbbreviation);
26 
27  ILanguageDependentValue<ISystemLocale> Locale { get; }
28 
29  ILanguageDependentValue<IDateTimeFormat> TimeFormat { get; }
30 
31  ILanguageDependentValue<string> UserDefinedTimeFormat { get; }
32  }
33 
34  internal class LanguageDependendTimeFormat : LanguageDependentValue<IDateTimeFormat>
35  {
36  public LanguageDependendTimeFormat(IPartialRedDotProjectObject parent, RedDotAttribute attribute)
37  : base(parent, attribute)
38  {
39  }
40 
41  public override IDateTimeFormat this[string languageAbbreviation]
42  {
43  get { return base[languageAbbreviation] ?? DateTimeFormat.USER_DEFINED_TIME_FORMAT; }
44  set
45  {
46  if (!value.IsTimeFormat)
47  {
48  throw new ArgumentException(string.Format(
49  "DateTimeFormat {1} with type id {0} is not a time format", value.TypeId, value.Name));
50  }
51  base[languageAbbreviation] = value;
52  }
53  }
54  }
55 
56  internal class StandardFieldTime : StandardFieldNonDate, IStandardFieldTime
57  {
58  internal StandardFieldTime(IContentClass contentClass, XmlElement xmlElement) : base(contentClass, xmlElement)
59  {
60  }
61 
62  public bool IsUserDefinedTimeFormat(string languageAbbreviation)
63  {
64  return TimeFormat[languageAbbreviation] == DateTimeFormat.USER_DEFINED_TIME_FORMAT;
65  }
66 
67  [RedDot("eltlcid", ConverterType = typeof (LocaleConverter))]
68  public ILanguageDependentValue<ISystemLocale> Locale
69  {
70  get { return GetAttributeValue<ILanguageDependentValue<ISystemLocale>>(); }
71  }
72 
73  [RedDot("eltformatno", ConverterType = typeof (DateTimeFormatConverter))]
74  public ILanguageDependentValue<IDateTimeFormat> TimeFormat
75  {
76  get
77  {
78  var redDotAttribute =
79  (RedDotAttribute)
80  GetType().GetProperty("TimeFormat").GetCustomAttributes(typeof (RedDotAttribute), false).Single();
81  return new LanguageDependendTimeFormat(this, redDotAttribute);
82  }
83  }
84 
85  [RedDot("eltformatting")]
86  public ILanguageDependentValue<string> UserDefinedTimeFormat
87  {
88  get { return GetAttributeValue<ILanguageDependentValue<string>>(); }
89  }
90  }
91 }