SmartAPI
Open Source .NET RQL library for RedDot CMS / OpenText WSM Management Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
ISubFolders.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;
18 using System.Collections.Generic;
19 using System.Linq;
20 using erminas.SmartAPI.Exceptions;
21 using erminas.SmartAPI.Utils.CachedCollections;
22 
23 namespace erminas.SmartAPI.CMS.Project.Folder
24 {
25  internal class EmptySubFolders : ISubFolders
26  {
27  internal EmptySubFolders(IAssetManagerFolder parentFolder)
28  {
29  ParentFolder = parentFolder;
30  }
31 
32  public bool Contains(IAssetManagerFolder element)
33  {
34  return false;
35  }
36 
37  public bool ContainsGuid(Guid guid)
38  {
39  return false;
40  }
41 
42  public bool ContainsKey(string key)
43  {
44  return false;
45  }
46 
47  public bool ContainsName(string name)
48  {
49  return false;
50  }
51 
52  public int Count
53  {
54  get { return 0; }
55  }
56 
57  public IAssetManagerFolder Get(string key)
58  {
59  throw new SmartAPIException(Session.ServerLogin, "Subfolders cannot contain other subfolders");
60  }
61 
62  public IAssetManagerFolder GetByGuid(Guid guid)
63  {
64  throw new SmartAPIException(Session.ServerLogin, "Subfolders cannot contain other subfolders");
65  }
66 
67  public IAssetManagerFolder GetByName(string name)
68  {
69  throw new SmartAPIException(Session.ServerLogin, "Subfolders cannot contain other subfolders");
70  }
71 
72  public IAssetManagerFolder GetByPosition(int pos)
73  {
74  throw new SmartAPIException(Session.ServerLogin, "Subfolders cannot contain other subfolders");
75  }
76 
77  public IEnumerator<IAssetManagerFolder> GetEnumerator()
78  {
79  return Enumerable.Empty<IAssetManagerFolder>().GetEnumerator();
80  }
81 
82  public void InvalidateCache()
83  {
84  }
85 
86  public bool IsCachingEnabled { get; set; }
87 
88  public IAssetManagerFolder this[string key]
89  {
90  get { throw new SmartAPIException(Session.ServerLogin, "Subfolders cannot contain other subfolders"); }
91  }
92 
93  public IAssetManagerFolder ParentFolder { get; private set; }
94 
95  public IProject Project
96  {
97  get { return ParentFolder.Project; }
98  }
99 
100  public void Refresh()
101  {
102  }
103 
104  public IIndexedCachedList<string, IAssetManagerFolder> Refreshed()
105  {
106  return this;
107  }
108 
109  public ISession Session
110  {
111  get { return ParentFolder.Session; }
112  }
113 
114  public bool TryGet(string name, out IAssetManagerFolder obj)
115  {
116  obj = null;
117  return false;
118  }
119 
120  public bool TryGetByGuid(Guid guid, out IAssetManagerFolder output)
121  {
122  output = null;
123  return false;
124  }
125 
126  public bool TryGetByName(string name, out IAssetManagerFolder output)
127  {
128  output = null;
129  return false;
130  }
131 
132  public void WaitFor(Predicate<IIndexedCachedList<string, IAssetManagerFolder>> predicate, TimeSpan maxWait,
133  TimeSpan retryPeriod)
134  {
135  if (!predicate(this))
136  {
137  throw new TimeoutException(
138  string.Format(
139  "Predicate is a contradiction on subfolders of {0} as it cannot contain other subdirectories.",
140  ParentFolder));
141  }
142  }
143 
144  public void WaitFor(Func<IIndexedRDList<string, IAssetManagerFolder>, bool> predicate, TimeSpan maxWait,
145  TimeSpan retryEverySecond)
146  {
147  if (!predicate(this))
148  {
149  throw new TimeoutException(
150  string.Format(
151  "Predicate is a contradiction on subfolders of {0} as it cannot contain other subdirectories.",
152  ParentFolder));
153  }
154  }
155 
156  public void WaitFor(Predicate<IRDList<IAssetManagerFolder>> predicate, TimeSpan wait, TimeSpan retryPeriod)
157  {
158  if (!predicate(this))
159  {
160  throw new TimeoutException(
161  string.Format(
162  "Predicate is a contradiction on subfolders of {0} as it cannot contain other subdirectories.",
163  ParentFolder));
164  }
165  }
166 
167  public void WaitFor(Predicate<ICachedList<IAssetManagerFolder>> predicate, TimeSpan wait, TimeSpan retryPeriod)
168  {
169  if (!predicate(this))
170  {
171  throw new TimeoutException(
172  string.Format(
173  "Predicate is a contradiction on subfolders of {0} as it cannot contain other subdirectories.",
174  ParentFolder));
175  }
176  }
177 
178  IEnumerator IEnumerable.GetEnumerator()
179  {
180  return GetEnumerator();
181  }
182 
183  ISubFolders ISubFolders.Refreshed()
184  {
185  return this;
186  }
187 
188  IRDList<IAssetManagerFolder> IRDList<IAssetManagerFolder>.Refreshed()
189  {
190  return this;
191  }
192 
193  IIndexedRDList<string, IAssetManagerFolder> IIndexedRDList<string, IAssetManagerFolder>.Refreshed()
194  {
195  return this;
196  }
197 
198  ICachedList<IAssetManagerFolder> ICachedList<IAssetManagerFolder>.Refreshed()
199  {
200  return this;
201  }
202  }
203 
204  public interface ISubFolders : IIndexedRDList<string, IAssetManagerFolder>, IProjectObject
205  {
206  IAssetManagerFolder ParentFolder { get; }
207  new ISubFolders Refreshed();
208  }
209 }