SmartAPI
Open Source .NET RQL library for RedDot CMS / OpenText WSM Management Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
IRecycleBin.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.Collections.Generic;
17 using System.Linq;
18 using erminas.SmartAPI.CMS.Project.Pages;
19 using erminas.SmartAPI.Utils;
20 
21 namespace erminas.SmartAPI.CMS.Project
22 {
23  public interface IRecycleBin : IProjectObject
24  {
25  void DeleteAllPages();
26  void DeleteAllPagesOfLanguageVariant(string language);
27  bool IsEmpty { get; }
28  IEnumerable<IPage> Pages();
29  IEnumerable<IPage> PagesOfLanguageVariant(string language);
30  }
31 
32  internal class RecycleBin : IRecycleBin
33  {
34  private readonly IProject _project;
35 
36  internal RecycleBin(IProject project)
37  {
38  _project = project;
39  }
40 
41  public void DeleteAllPages()
42  {
43  const string DELETE_ALL = @"<PAGES action=""deleteallfinally"" alllanguages=""1""/>";
44  _project.ExecuteRQL(DELETE_ALL);
45  }
46 
47  public void DeleteAllPagesOfLanguageVariant(string language)
48  {
49  using (new LanguageContext(_project.LanguageVariants[language]))
50  {
51  const string DELETE_ALL_IN_CURRENT_LANGUAGE = @"<PAGES action=""deleteallfinally"" alllanguages=""0""/>";
52  _project.ExecuteRQL(DELETE_ALL_IN_CURRENT_LANGUAGE);
53  }
54  }
55 
56  public bool IsEmpty
57  {
58  get { return !Pages().Any(); }
59  }
60 
61  public IEnumerable<IPage> Pages()
62  {
63  List<ResultGroup> searchForPagesExtended = CreatePageSearchForRecycleBin().Execute();
64  return searchForPagesExtended[0].Results.Select(pageResult => pageResult.Page);
65  }
66 
67  public IEnumerable<IPage> PagesOfLanguageVariant(string language)
68  {
69  IExtendedPageSearch search = CreatePageSearchForRecycleBin();
70  search.LanguageVariant = _project.LanguageVariants[language];
71 
72  IEnumerable<Result> results = search.Execute()[0].Results;
73  return results.Select(pageResult => pageResult.Page);
74  }
75 
76  public IProject Project
77  {
78  get { return _project; }
79  }
80 
81  public ISession Session
82  {
83  get { return Project.Session; }
84  }
85 
86  private IExtendedPageSearch CreatePageSearchForRecycleBin()
87  {
88  var search = _project.Pages.CreateExtendedSearch();
89  search.Filters.Add(new SpecialPageFilter(SpecialPageFilter.PageCategoryType.RecycleBin));
90  return search;
91  }
92  }
93 }