SmartAPI
Open Source .NET RQL library for RedDot CMS / OpenText WSM Management Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
VersionAttribute.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.Exceptions;
18 using erminas.SmartAPI.Utils;
19 
20 namespace erminas.SmartAPI.CMS
21 {
22  public abstract class VersionAttribute : Attribute
23  {
24  protected VersionAttribute(int major, int minor, int build, int rev)
25  {
26  Version = new Version(major, minor, build, rev);
27  }
28 
29  public abstract void Validate(ServerLogin login, Version actualVersion, string method);
30 
31  public Version Version { get; set; }
32 
33  public string VersionName { get; set; }
34  }
35 
36  [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
38  {
39  public VersionIsGreaterThanOrEqual(int major, int minor = 0, int build = 0, int rev = 0)
40  : base(major, minor, build, rev)
41  {
42  }
43 
44  public override void Validate(ServerLogin login, Version actualVersion, string method)
45  {
46  if (actualVersion < Version)
47  {
48  string versionNameString = string.IsNullOrEmpty(VersionName) ? "" : " (" + VersionName + ")";
49  throw new InvalidServerVersionException(login,
50  string.Format(
51  "Invalid server version. {0} only works on servers with version greater than or equal {1}{3}, but the current server version is {2}",
52  method, Version, actualVersion, versionNameString));
53  }
54  }
55  }
56 
57  [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
59  {
60  public VersionIsLessThan(int major, int minor = 0, int build = 0, int rev = 0) : base(major, minor, build, rev)
61  {
62  }
63 
64  public override void Validate(ServerLogin login, Version actualVersion, string method)
65  {
66  if (actualVersion >= Version)
67  {
68  string versionNameString = string.IsNullOrEmpty(VersionName) ? "" : " (" + VersionName + ")";
69  throw new InvalidServerVersionException(login,
70  string.Format(
71  "Invalid server version. {0} only works on servers with version less than {1}{3}, but the current server version is {2}",
72  method, Version, actualVersion, versionNameString));
73  }
74  }
75  }
76 }