SmartAPI
Open Source .NET RQL library for RedDot CMS / OpenText WSM Management Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
SpecialDataFieldFormat.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 erminas.SmartAPI.CMS.Converter;
18 using erminas.SmartAPI.Exceptions;
19 
20 namespace erminas.SmartAPI.CMS.Project.ContentClasses.Elements
21 {
22  [EnumConversionHelper]
23  public static class SpecialDataFieldFormatUtils
24  {
25  public static void EnsureValueIsSupportedByServerVersion(IProjectObject obj, SpecialDataFieldFormat value)
26  {
27  var serverVersion = obj.Session.ServerVersion;
28  switch (value)
29  {
30  case SpecialDataFieldFormat.DefaultUserDefined:
31  case SpecialDataFieldFormat.DefaultHTML:
32  case SpecialDataFieldFormat.DefaultImage:
33  return;
34  case SpecialDataFieldFormat.TextUserDefined:
35  case SpecialDataFieldFormat.DateUserDefined:
36  case SpecialDataFieldFormat.CurrencyUserDefined:
37  var version = new Version(11, 0);
38  if (serverVersion < version)
39  {
40  throw new SmartAPIException(obj.Session.ServerLogin,
41  string.Format(
42  "Cannot set {0} to value {1} for server versions older than {2}",
43  RedDotAttributeDescription.GetDescriptionForElement(
44  "eltcolumniotype"), value.ToString(), version));
45  }
46  return;
47  default:
48  throw new ArgumentException(string.Format("Unknown {0} value: {1}",
49  typeof (SpecialDataFieldFormat).Name, value));
50  }
51  }
52 
53  public static string ToRQLString(this SpecialDataFieldFormat value)
54  {
55  switch (value)
56  {
57  case SpecialDataFieldFormat.DefaultUserDefined:
58  return "no";
59  case SpecialDataFieldFormat.DefaultHTML:
60  return "HTML";
61  case SpecialDataFieldFormat.DefaultImage:
62  return "Image";
63  case SpecialDataFieldFormat.TextUserDefined:
64  return "1";
65  case SpecialDataFieldFormat.DateUserDefined:
66  return "5";
67  case SpecialDataFieldFormat.CurrencyUserDefined:
68  return "48";
69  default:
70  throw new ArgumentException(string.Format("Unknown {0} value: {1}",
71  typeof (SpecialDataFieldFormat).Name, value));
72  }
73  }
74 
75  public static SpecialDataFieldFormat ToSpecialDataFieldFormat(this string value)
76  {
77  if (string.IsNullOrEmpty(value))
78  {
79  return SpecialDataFieldFormat.DefaultUserDefined;
80  }
81  switch (value.ToUpperInvariant())
82  {
83  case "DEFAULT":
84  case "NO":
85  return SpecialDataFieldFormat.DefaultUserDefined;
86  case "1":
87  return SpecialDataFieldFormat.TextUserDefined;
88  case "5":
89  return SpecialDataFieldFormat.DateUserDefined;
90  case "48":
91  return SpecialDataFieldFormat.CurrencyUserDefined;
92  case "HTML":
93  return SpecialDataFieldFormat.DefaultHTML;
94  case "IMAGE":
95  return SpecialDataFieldFormat.DefaultImage;
96  default:
97  throw new ArgumentException(string.Format("Cannot convert string value {1} to {0}",
98  typeof (SpecialDataFieldFormat).Name, value));
99  }
100  }
101  }
102 
104  {
105  DefaultUserDefined,
106  DefaultHTML,
107  DefaultImage,
108  DateUserDefined,
109  CurrencyUserDefined,
110  TextUserDefined
111  }
112 }