SmartAPI
Open Source .NET RQL library for RedDot CMS / OpenText WSM Management Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
RQLException.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.Collections.Generic;
18 using System.Linq;
19 
20 namespace erminas.SmartAPI.Exceptions
21 {
22 
23  #region ErrorCode
24 
25  public enum ErrorCode
26  {
27  Unknown = 0,
28  NoRight,
29  PleaseLogin,
30  RDError1,
31  RDError2,
32  RDError3,
33  RDError4,
34  RDError5,
35  RDError6,
36  RDError7,
37  RDError8,
38  RDError9,
39  RDError10,
40  RDError11,
41  RDError12,
42  RDError13,
43  RDError14,
44  RDError15,
45  RDError16,
46  RDError17,
47  RDError101,
48  RDError110,
49  RDError201,
50  RDError301,
51  RDError401,
52  RDError510,
53  RDError511,
54  RDError707,
55  RDError800,
56  RDError2910,
57  RDError2911,
58  RDError3000,
59  RDError3032,
60  Error3049,
61  RDError4005,
62  RDError5001,
63  RDError6001,
64  RDError15805,
65  RDError16997
66  }
67 
68  internal static class ErrorCodeUtils
69  {
70  internal static ErrorCode ToErrorCode(this string value)
71  {
72  if (value == "Please Login")
73  {
74  return ErrorCode.PleaseLogin;
75  }
76  if (value.Trim() == "No right")
77  {
78  return ErrorCode.NoRight;
79  }
80  return (ErrorCode) Enum.Parse(typeof (ErrorCode), value);
81  }
82  }
83 
84  #endregion
85 
86  [Serializable]
88  {
89  private const string RESPONSE = "response";
90  private const string SERVER = "server";
91  private const string ERROR_MESSAGE = "error_message";
92 
93  #region error codes
94 
95  private readonly List<Tuple<string, string>> _errorCodes = new List<Tuple<string, string>>
96  {
97  Tuple.Create("No right", "The user does not have the required privileges."),
98  Tuple.Create("Please Login",
99  "The user session has timed out or the Login GUID is no longer valid. Please login again."),
100  Tuple.Create("RDError1", "The number of modules in the license key does not correspond to the checksum."),
101  Tuple.Create("RDError2", "The license key is only valid for the Beta test."),
102  Tuple.Create("RDError3",
103  "The license key is not correct. An error which could not be classified has occurred during the check."),
104  Tuple.Create("RDError4", "License is no longer valid."),
105  Tuple.Create("RDError5", "The server IP address is different than specified in the license."),
106  Tuple.Create("RDError6", "License is not yet valid."),
107  Tuple.Create("RDError7",
108  "License is a cluster license. This error message is no longer supported beginning with CMS 6.0."),
109  Tuple.Create("RDError8", "The IP address check in the license key is not correct."),
110  Tuple.Create("RDError9", "Invalid version of the license key."),
111  Tuple.Create("RDError10", "There are duplicate modules in the license."),
112  Tuple.Create("RDError11", "A module in the license is flawed."),
113  Tuple.Create("RDError12", "There are illegal characters in the license."),
114  Tuple.Create("RDError13", "The checksum is not correct."),
115  Tuple.Create("RDError14", "The serial number in the license is not correct."),
116  Tuple.Create("RDError15",
117  "The serial number of the license key is different from the serial number of the previous license key."),
118  Tuple.Create("RDError16", "The IP address of the Loopback adapter is not supported in this license."),
119  Tuple.Create("RDError17", "The license key contains no valid serial number."),
120  Tuple.Create("RDError101", "The user is already logged on."),
121  Tuple.Create("RDError110",
122  "The user does not have the required privileges to execute the RQL. The cause of this situation may be that the logon GUID or session key has expired or the session has timed out."),
123  Tuple.Create("RDError201", "Access to database \"ioAdministration\" has failed."),
124  Tuple.Create("RDError301", "Defective asynchronous component."),
125  Tuple.Create("RDError401", "A project is locked for the executing user or the user level."),
126  Tuple.Create("RDError510", "The application server is not available."),
127  Tuple.Create("RDError511", "The application server or the Management Server databases are updated."),
128  Tuple.Create("RDError707", "The Login GUID does not correspond to the logged on user."),
129  Tuple.Create("RDError800", "The maximum number of logins for a user has been reached."),
130  Tuple.Create("RDError2910", "References still point to elements of this page."),
131  Tuple.Create("RDError2911", "At least one element is still assigned as target container to a link."),
132  Tuple.Create("RDError3000", "Package already exists."),
133  Tuple.Create("RDError3032",
134  "You have tried to delete a content class on the basis of which pages have already been created."),
135  Tuple.Create("Error3049", "Too many users to a license. Login to CMS failed. Please login again later."),
136  Tuple.Create("RDError4005", "This user name already exists."),
137  Tuple.Create("RDError5001", "The folder path could not be found or the folder does no longer exist."),
138  Tuple.Create("RDError6001", "A file is already being used in the CMS."),
139  Tuple.Create("RDError15805", "You have no right to delete this page."),
140  Tuple.Create("RDError16997",
141  "You cannot delete the content class. There are pages which were created on the basis of this content class in other projects.")
142  };
143 
144  #endregion
145 
146  public RQLException(string server, string reason, string responseXML) : base(server, reason)
147  {
148  Server = server;
149  //use lastordefault because the numbers are increasing/more specific at the end. E.g. RDError1 is also contained in RDError110.
150  Tuple<string, string> msg = _errorCodes.LastOrDefault(x => reason.Contains(x.Item1));
151  ErrorMessage = msg != null ? msg.Item2 : reason;
152  ErrorCode = msg != null ? msg.Item1.ToErrorCode() : ErrorCode.Unknown;
153  Response = responseXML;
154  }
155 
156  protected RQLException(RQLException rqlException)
157  : this(rqlException.Server, rqlException.ErrorMessage, rqlException.Response)
158  {
159  ErrorCode = rqlException.ErrorCode;
160  }
161 
162  public ErrorCode ErrorCode { get; set; }
163 
164  public string ErrorMessage
165  {
166  get { return (Data[ERROR_MESSAGE] ?? "").ToString(); }
167  private set { Data.Add(ERROR_MESSAGE, value); }
168  }
169 
170  public override string Message
171  {
172  get { return string.Format("RQL request to '{0}' failed. Error message: '{1}'", Server, ErrorMessage); }
173  }
174 
175  public string Response
176  {
177  get { return (Data[RESPONSE] ?? "").ToString(); }
178  private set { Data.Add(RESPONSE, value); }
179  }
180  }
181 }