-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPage.cs
More file actions
572 lines (524 loc) · 19.7 KB
/
Page.cs
File metadata and controls
572 lines (524 loc) · 19.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Text.RegularExpressions;
using System.Net;
using System.IO;
namespace RustyLogic.RedDotNet
{
public class Page : RedDotObject
{
public enum PageType { All = 0, Released = 1, Unlinked = 8192, Draft = 262144 };
public enum PageReleaseStatus { Draft = 65536, WorkFlow = 32768, Released = 4096, NotSet = 0, Rejected = 16384, ResetToDraft = 134217728 };
[Flags] enum PageFlags
{
NotSet = 0,
NotForBreadcrumb = 4,
Workflow = 64,
WaitingForTranslation = 1024,
Unlinked = 8192,
WaitingForCorrection = 131072,
Draft = 262144,
Released = 524288,
BreadCrumbStaringPoint = 2097152,
ContainsExternalReference = 8388608,
OwnPageWaitingForRelease = 134217728,
Locked = 268435456,
Null = -1
}
private PageFlags _pageFlags = PageFlags.Null;
internal Page(XmlNode xmlNode) : base(xmlNode) { }
public Page(Guid guid) : base(guid) { }
private string _headline;
public string Headline
{
get { return _headline; }
set
{
Save("headline", value);
_headline = value;
}
}
private string _mainLinkGuidString;
public string MainLinkGuidString
{
get
{
if (_mainLinkGuidString == null)
{
_mainLinkGuidString = XmlNode.Attributes.GetNamedItem("mainlinkguid").Value;
}
return _mainLinkGuidString;
}
set
{
throw new Exception("Not implemented.");
}
}
private string _fileName;
public string FileName
{
get
{
if (_fileName == null)
{
try { _fileName = XmlNode.Attributes.GetNamedItem("name").Value; }
catch { }
if (string.IsNullOrEmpty(_fileName))
{
_fileName = Id.ToString();
}
}
if (!_fileName.Contains("."))
{
_fileName += ".aspx"; // TODO: Get this dynamically
}
return _fileName;
}
set
{
throw new Exception("Not implemented.");
}
}
public string FolderPath
{
get
{
string folderPath = XmlNode.SelectSingleNode(
"//LANGUAGEVARIANT[@guid=\"" + LanguageVariant.Default.GuidString + "\"]" +
"//PROJECTVARIANT[@guid=\"" + ProjectVariant.Default.GuidString + "\"]" +
// TODO: not sure about hardcoding the folder name ("Published pages"), will only work for pages.
// It seems to be correct and constant for all pages so can stay for now.
"//EXPORTFOLDER[@foldername=\"Published pages\"]").Attributes.GetNamedItem("folderpath").Value;
folderPath = folderPath.Replace('\\', '/');
if (folderPath.Length != 0)
{
folderPath = "/" + folderPath + "/";
}
else
{
folderPath = "/";
}
return folderPath;
}
set
{
throw new Exception("Not implemented.");
}
}
public string PublicationPath
{
get
{
// Main link publication target
string publishingTargetName = XmlNode.SelectSingleNode(
"//LANGUAGEVARIANT[@guid=\"" + LanguageVariant.Default.GuidString + "\"]" +
"//PROJECTVARIANT[@guid=\"" + ProjectVariant.Default.GuidString + "\"]").Attributes.GetNamedItem("exportname").Value;
// Split dual names... either will do.
if (publishingTargetName.Contains(","))
{
publishingTargetName = publishingTargetName.Remove(publishingTargetName.IndexOf(','));
}
/* IGNORE THE PUBLISHING PREFIX!!
string urlPrefix = null;
foreach (PublishingTarget publishingTarget in PublishingTarget.List())
{
if (publishingTarget.Name == publishingTargetName)
{
urlPrefix = publishingTarget.UrlPrefix;
break;
}
}
return urlPrefix + FolderPath + FileName;
*/
return FolderPath + FileName;
}
set
{
throw new Exception("Not implemented.");
}
}
private string _parentGuidString;
public string ParentGuidString
{
get
{
if (_parentGuidString == null)
{
_parentGuidString = XmlNode.Attributes.GetNamedItem("parentguid").Value;
}
return _parentGuidString;
}
set
{
throw new Exception("Not implemented.");
}
}
public void DisconnectFromParent()
{
Link.DisconnectFromParent(this);
}
public User ChangeUser
{
get
{
return new User(new Guid(XmlNode.Attributes.GetNamedItem("changeuserguid").Value));
}
}
public int Id
{
get
{
return int.Parse(XmlNode.Attributes.GetNamedItem("id").Value);
}
}
public void SkipWorkflow()
{
XmlDocument rqlXml = new XmlDocument();
XmlElement ioDataElement = rqlXml.CreateElement("IODATA");
XmlElement pageElement = rqlXml.CreateElement("PAGE");
pageElement.SetAttribute("action", "save");
pageElement.SetAttribute("guid", GuidString);
pageElement.SetAttribute("globalsave", "0");
pageElement.SetAttribute("skip", "1");
pageElement.SetAttribute("actionflag", ((int)PageReleaseStatus.WorkFlow).ToString());
ioDataElement.AppendChild(pageElement);
rqlXml.AppendChild(ioDataElement);
Session.Execute(rqlXml);
}
public void Release()
{
Release(false);
}
public void Release(bool globalRelease)
{
XmlDocument rqlXml = new XmlDocument();
XmlElement ioDataElement = rqlXml.CreateElement("IODATA");
XmlElement pageElement = rqlXml.CreateElement("PAGE");
pageElement.SetAttribute("action", "save");
pageElement.SetAttribute("guid", GuidString);
pageElement.SetAttribute("actionflag", ((int)PageReleaseStatus.Released).ToString());
if (globalRelease)
{
pageElement.SetAttribute("globalrelease", "1");
}
ioDataElement.AppendChild(pageElement);
rqlXml.AppendChild(ioDataElement);
Session.Execute(rqlXml, Session.Info.SessionKey);
}
public void Reject()
{
XmlDocument rqlXml = new XmlDocument();
XmlElement ioDataElement = rqlXml.CreateElement("IODATA");
XmlElement pageElement = rqlXml.CreateElement("PAGE");
pageElement.SetAttribute("action", "save");
pageElement.SetAttribute("guid", GuidString);
pageElement.SetAttribute("actionflag", ((int)PageReleaseStatus.Rejected).ToString());
ioDataElement.AppendChild(pageElement);
rqlXml.AppendChild(ioDataElement);
Session.Execute(rqlXml, Session.Info.SessionKey);
}
/// <summary>
/// Deprecated.
/// </summary>
public PageReleaseStatus ReleaseStatus
{
get
{
if (_pageFlags == PageFlags.Null)
{
try
{
_pageFlags = (PageFlags)int.Parse(XmlNode.Attributes.GetNamedItem("flags").Value);
}
catch
{ }
}
if ((_pageFlags & PageFlags.Draft) == PageFlags.Draft)
{
return PageReleaseStatus.Draft;
}
else if ((_pageFlags & PageFlags.Workflow) == PageFlags.Workflow)
{
return PageReleaseStatus.WorkFlow;
}
else if ((_pageFlags & PageFlags.WaitingForCorrection) == PageFlags.WaitingForCorrection)
{
return PageReleaseStatus.Rejected;
}
else
{
return PageReleaseStatus.NotSet;
/*
public enum PageReleaseStatus { Draft = 65536, WorkFlow = 32768, Released = 4096, NotSet = 0, Rejected = 16384, ResetToDraft = 134217728 };
[Flags]
enum PageFlags
{
NotSet = 0,
NotForBreadcrumb = 4,
Workflow = 64,
WaitingForTranslation = 1024,
Unlinked = 8192,
WaitingForCorrection = 131072,
Draft = 262144,
Released = 524288,
BreadCrumbStaringPoint = 2097152,
ContainsExternalReference = 8388608,
OwnPageWaitingForRelease = 134217728,
Locked = 268435456
*/
}
throw new Exception("Method not completely implemented");
}
set
{
XmlDocument rqlXml = new XmlDocument();
XmlElement ioDataElement = rqlXml.CreateElement("IODATA");
XmlElement pageElement = rqlXml.CreateElement("PAGE");
pageElement.SetAttribute("action", "save");
pageElement.SetAttribute("guid", GuidString);
if (value == PageReleaseStatus.WorkFlow)
{
pageElement.SetAttribute("globalsave", "1");
}
if (value == PageReleaseStatus.Released)
{
pageElement.SetAttribute("globalrelease", "1");
}
pageElement.SetAttribute("actionflag", ((int)value).ToString());
ioDataElement.AppendChild(pageElement);
rqlXml.AppendChild(ioDataElement);
Session.Execute(rqlXml);
// TODO: RESET XML contents
}
}
public Workflow Workflow
{
get
{
return Workflow.Get(new Guid(XmlNode.SelectSingleNode("descendant::WORKFLOW").Attributes.GetNamedItem("guid").Value));
}
}
public List<Keyword> Keywords()
{
return Keyword.Get(this);
}
public void UnlinkKeyword(Keyword keyword)
{
keyword.UnlinkKeyword(this);
}
public Template Template
{
get
{
return Template.Get(TemplateGuid);
}
}
protected Guid TemplateGuid
{
get
{
return new Guid(XmlNode.Attributes.GetNamedItem("templateguid").Value);
}
}
override protected void LoadBasics(XmlNode xmlNode)
{
_headline = xmlNode.Attributes.GetNamedItem("headline").Value;
}
protected override XmlNode LoadXml()
{
string rqlStatement =
"<IODATA>" +
"<PAGE action=\"load\" guid=\"" + GuidString + "\" option=\"extendedinfo\" " + "/>" +
"</IODATA>";
xmlDoc.LoadXml(Session.Execute(rqlStatement));
return xmlDoc.GetElementsByTagName("PAGE")[0];
}
public List<Element> Elements()
{
return Element.List(this);
}
public List<Link> Links()
{
return Link.List(this);
}
public string Preview(Project project)
{
return Preview(project, ProjectVariant.Default, LanguageVariant.Default);
}
public string Preview(Project project, ProjectVariant projectVariant, LanguageVariant languageVariant)
{
string rqlStatement =
"<IODATA>" +
"<PREVIEW " +
"url=\"/cms/ioRD.asp\" " +
"webcompliance=\"1\" " +
"querystring=\"Action=Preview&projectguid=" + project.GuidString + "&" +
"pageguid=" + GuidString + "&" +
"projectvariantguid=" + projectVariant.GuidString + "&" +
"languagevariantid=" + languageVariant.Language + "&\" />" +
"</IODATA>";
return Session.Execute(rqlStatement);
}
/*
public void CheckValidationRules()
{
string rqlStatement =
"<IODATA>" +
"<WEBCOMPLIANCE>" +
"<VALIDATE action=\"load\" projectvariantguid=\"" + ProjectVariant.Default.GuidString +"\"/>" +
"</WEBCOMPLIANCE>" +
"</IODATA>";
string main = Session.Execute(rqlStatement);
}
*/
public WebCompliance Validate()
{
WebCompliance compliance = new WebCompliance(this, false);
return compliance;
}
public WebCompliance Validate(bool force)
{
WebCompliance compliance = new WebCompliance(this, force);
return compliance;
}
private void Save(string attributeName, string attributeValue)
{
string rqlStatement =
"<IODATA>" +
"<PAGE action=\"save\" guid=\"" + GuidString + "\" " +
attributeName + "=\"" + attributeValue + "\"/>" +
"</IODATA>";
Session.Execute(rqlStatement);
}
/*
public void SaveValidationRules()
{
string rqlStatement =
"<IODATA>" +
"<WEBCOMPLIANCE>" +
"<VALIDATE action=\"save\" projectvariantguid=\"" + ProjectVariant.Default.GuidString + "\" " +
"rule=\"wcag1.0_AA_dil\" " +
"useragent=\"BIKA Checker\" " +
"doctype=\"HTML 4.01 Transitional\" allowederrors=\"0\" " +
"allowedwarnings=\"99\" " +
"/>" +
"</WEBCOMPLIANCE>" +
"</IODATA>";
string main = Session.Execute(rqlStatement);
}
*/
/*
public static Page New(string headline, Template template) //, Link link)
{
//TODO: Add Link link parameter
string rqlStatement =
"<IODATA>" +
"<LINK action=\"assign\" guid=\"" + link.GuidString + "\">" +
"<PAGE action=\"addnew\" templateguid=\"" + template.GuidString + "\" headline=\"" + headline + "\"/>" +
"</LINK>" +
"</IODATA>";
}
*/
public static List<Page> List()
{
List<Page> pages = new List<Page>();
string rqlStatement =
"<IODATA>" +
"<PROJECT>" +
"<PAGES action=\"list\"/>" +
"</PROJECT>" +
"</IODATA>";
xmlDoc.LoadXml(Session.Execute(rqlStatement));
XmlNodeList xmlNodes = xmlDoc.GetElementsByTagName("PAGE");
foreach (XmlNode xmlNode in xmlNodes)
{
pages.Add(new Page(xmlNode));
}
return pages;
}
/// <summary>
/// Debugging fn
/// </summary>
/// <param name="pageGuid"></param>
/// <returns></returns>
private static Page Get(string pageGuid)
{
string rqlStatement =
"<IODATA>" +
"<PAGE action=\"load\" guid=\"" + pageGuid + "\"/>" +
"</IODATA>";
xmlDoc.LoadXml(Session.Execute(rqlStatement,Session.Info.SessionKey));
XmlNodeList xmlNodes = xmlDoc.GetElementsByTagName("PAGE");
return new Page(xmlNodes[0]);
}
public static Page Get(int pageId)
{
return Get(pageId, pageId)[0];
}
public static List<Page> Get(int pageIdFrom, int pageIdTo)
{
PageSearch search = new PageSearch();
search.PageIdFrom = pageIdFrom;
search.PageIdTo = pageIdTo;
search.MaxRecords = ((pageIdTo - pageIdFrom) + 1);
return search.Execute();
}
public static List<Page> SearchByText(string searchText)
{
PageSearch search = new PageSearch();
search.Text = searchText;
return search.Execute();
}
public static List<Page> SearchByHeadline(string headline)
{
PageSearch search = new PageSearch();
search.Headline = headline;
return search.Execute();
}
public static List<Page> PagesWaitingForCorrection()
{
List<Page> pages = new List<Page>();
string rqlStatement =
"<IODATA>" +
"<PAGE action=\"xsearch\" pagesize=\"-1\" maxhits=\"-1\">" +
"<SEARCHITEMS>" +
"<SEARCHITEM key=\"pagestate\" value=\"waitingforcorrection\" operator=\"eq\" users=\"all\"/>" +
"</SEARCHITEMS>" +
"</PAGE>" +
"</IODATA>";
xmlDoc.LoadXml(Session.Execute(rqlStatement, Session.Info.SessionKey));
XmlNodeList xmlNodes = xmlDoc.GetElementsByTagName("PAGE");
foreach (XmlNode xmlNode in xmlNodes)
{
pages.Add(new Page(xmlNode));
}
return pages;
}
public static List<Page> PagesWaitingForRelease()
{
return PagesWaitingForRelease(false);
}
public static List<Page> PagesWaitingForRelease(bool allUsers)
{
List<Page> pages = new List<Page>();
string rqlStatement =
"<IODATA>" +
"<PAGE action=\"xsearch\" pagesize=\"-1\" maxhits=\"-1\">" +
"<SEARCHITEMS>" +
"<SEARCHITEM key=\"pagestate\" value=\"waitingforrelease\" operator=\"eq\" " +
"users=\"" + (allUsers ? "all" : "myself") + "\"/>" +
"</SEARCHITEMS>" +
"</PAGE>" +
"</IODATA>";
xmlDoc.LoadXml(Session.Execute(rqlStatement, Session.Info.SessionKey));
XmlNodeList xmlNodes = xmlDoc.GetElementsByTagName("PAGE");
foreach (XmlNode xmlNode in xmlNodes)
{
pages.Add(new Page(xmlNode));
}
return pages;
}
}
}