17 using System.Collections.Generic;
18 using System.Collections.ObjectModel;
21 using erminas.SmartAPI.CMS.Project.Workflows;
22 using erminas.SmartAPI.Utils;
24 namespace erminas.SmartAPI.CMS.Project.ContentClasses.Elements
28 void DisconnectFromLinkCompletely();
29 void DisconnectFromLinkForLanguages(IEnumerable<ILanguageVariant> languageVariants);
30 void DisconnectFromLinkForLanguages(params
string[] languageVariants);
32 IEnumerable<ILanguageVariant> LanguageVariantsPreassignedTo {
get; }
35 internal class PreassignedWorkflow : IPreassignedWorkflow
37 private readonly Workflow _workflow;
38 private ReadOnlyCollection<ILanguageVariant> _languageVariants;
40 internal PreassignedWorkflow(IWorkflowAssignable elementPreassignedTo, Workflow workflow)
42 ElementPreassignedTo = elementPreassignedTo;
48 get {
return _workflow.Actions; }
51 public bool CanBeInherited
53 get {
return _workflow.CanBeInherited; }
61 public void DisconnectFromLinkCompletely()
63 DisconnectFromLinkForLanguages(LanguageVariantsPreassignedTo);
66 public void DisconnectFromLinkForLanguages(IEnumerable<ILanguageVariant> languageVariants)
68 const string UNLINK_WORKFLOW =
69 @"<WORKFLOW sessionkey=""{0}""><LINK action=""unlink"" guid=""{1}""><WORKFLOW guid=""{2}""><LANGUAGEVARIANTS>{3}</LANGUAGEVARIANTS></WORKFLOW></LINK></WORKFLOW>";
71 ISession session = ElementPreassignedTo.Session;
73 string query = UNLINK_WORKFLOW.RQLFormat(session.SessionKey, ElementPreassignedTo, _workflow,
76 session.ExecuteRQLRaw(query, RQL.IODataFormat.LogonGuidOnly);
81 public void DisconnectFromLinkForLanguages(params
string[] languageVariants)
83 IProject project = ElementPreassignedTo.Project;
85 IEnumerable<ILanguageVariant> languages =
86 languageVariants.Select(language => project.LanguageVariants[language]);
87 DisconnectFromLinkForLanguages(languages);
90 public IWorkflowAssignable ElementPreassignedTo {
get;
private set; }
92 public void EnsureInitialization()
94 _workflow.EnsureInitialization();
97 public override bool Equals(
object o)
99 var workflow = o as Workflow;
100 return workflow != null && workflow.Guid == Guid;
103 public override int GetHashCode()
105 return _workflow.GetHashCode();
110 get {
return _workflow.Guid; }
111 set { _workflow.Guid = value; }
116 get {
return _workflow.IsGlobal; }
119 public bool IsStructureWorkflow
121 get {
return _workflow.IsStructureWorkflow; }
124 public IEnumerable<ILanguageVariant> LanguageVariantsPreassignedTo
128 if (_languageVariants == null)
130 RefreshLanguageVariants();
133 return _languageVariants;
139 get {
return _workflow.Name; }
140 set { _workflow.Name = value; }
143 public IProject Project
145 get {
return _workflow.Project; }
148 public void Refresh()
151 RefreshLanguageVariants();
154 public ISession Session
156 get {
return _workflow.Session; }
159 public XmlElement XmlElement
161 get {
return _workflow.XmlElement; }
162 set { _workflow.XmlElement = value; }
165 private ReadOnlyCollection<ILanguageVariant> GetPreAssignmentLanguageVariants()
167 const string LOAD_LANGUAGES =
168 @"<WORKFLOW guid=""{0}""><LANGUAGEVARIANTS action=""workflowexisting"" linkguid=""{1}""/></WORKFLOW>";
170 IProject project = ElementPreassignedTo.Project;
172 var xmlDoc = project.ExecuteRQL(LOAD_LANGUAGES.RQLFormat(_workflow, ElementPreassignedTo));
173 var languageVariants = xmlDoc.GetElementsByTagName(
"LANGUAGEVARIANT");
175 return (from XmlElement curLanguage in languageVariants
176 select project.LanguageVariants[curLanguage.GetAttributeValue(
"language")]).ToList().AsReadOnly();
179 private void InvalidateCache()
181 _languageVariants = null;
184 private void RefreshLanguageVariants()
186 _languageVariants = GetPreAssignmentLanguageVariants();