SmartAPI
Open Source .NET RQL library for RedDot CMS / OpenText WSM Management Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
IWorkflow.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.Exceptions;
19 using erminas.SmartAPI.Utils;
20 using erminas.SmartAPI.Utils.CachedCollections;
21 
22 namespace erminas.SmartAPI.CMS.Project.Workflows
23 {
25  {
26  IWorkflowActions Actions { get; }
27  bool CanBeInherited { get; }
28  bool IsGlobal { get; }
29  bool IsStructureWorkflow { get; }
30  }
31 
32  internal class Workflow : PartialRedDotProjectObject, IWorkflow
33  {
34  private bool _canBeInherited;
35  private bool _isGlobal;
36  private bool _isStructureWorkflow;
37 
38  internal Workflow(IProject project, XmlElement xmlElement) : base(project, xmlElement)
39  {
40  LoadXml();
41  Actions = new WorkflowActions(this, Caching.Enabled);
42  }
43 
44  public Workflow(IProject project, Guid guid) : base(project, guid)
45  {
46  Actions = new WorkflowActions(this, Caching.Enabled);
47  }
48 
49  // TODO: Add a more useful action method which retains the 'flow' of the workflow!
50  public IWorkflowActions Actions { get; private set; }
51 
52  public bool CanBeInherited
53  {
54  get { return LazyLoad(ref _canBeInherited); }
55  }
56 
57  public void Delete()
58  {
59  const string DELETE_WORKFLOW = @"<WORKFLOW sessionkey=""{0}"" action=""delete"" guid=""{1}""/>";
60  var session = Project.Session;
61  var reply = session.ExecuteRQLRaw(DELETE_WORKFLOW.RQLFormat(session, this), RQL.IODataFormat.LogonGuidOnly);
62 
63  if (!reply.Contains("ok"))
64  {
65  throw new SmartAPIException(Session.ServerLogin, string.Format("Could not delete workflow {0}", this));
66  }
67  }
68 
69  public bool IsGlobal
70  {
71  get { return LazyLoad(ref _isGlobal); }
72  }
73 
74  public bool IsStructureWorkflow
75  {
76  get { return LazyLoad(ref _isStructureWorkflow); }
77  }
78 
79  protected override void LoadWholeObject()
80  {
81  LoadXml();
82  }
83 
84  protected override XmlElement RetrieveWholeObject()
85  {
86  const string LOAD_WORKFLOW = @"<WORKFLOW action=""load"" guid=""{0}""/>";
87 
88  return
89  (XmlElement)
90  Project.ExecuteRQL(String.Format(LOAD_WORKFLOW, Guid.ToRQLString())).GetElementsByTagName("WORKFLOW")[0];
91  }
92 
93  internal XmlElement RetrieveObjectInternal()
94  {
95  return RetrieveWholeObject();
96  }
97 
98  private void LoadXml()
99  {
100  InitIfPresent(ref _canBeInherited, "inherit", BoolConvert);
101  if (Project.Session.ServerVersion < new Version(11, 2))
102  {
103  EnsuredInit(ref _isStructureWorkflow, "structureworkflow", BoolConvert);
104  }
105  else
106  {
107  EnsuredInit(ref _isStructureWorkflow, "wftype", BoolConvert);
108  }
109  InitIfPresent(ref _isGlobal, "global", BoolConvert);
110  }
111  }
112 }