-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathT4SP.tt
1386 lines (1230 loc) · 79.1 KB
/
T4SP.tt
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
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ output extension=".cs" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="Microsoft.VisualStudio.Shell.Interop.8.0" #>
<#@ assembly name="EnvDTE" #>
<#@ assembly name="EnvDTE80" #>
<#@ assembly name="VSLangProj" #>
<#@ assembly name="System.Xml.Linq" #>
<#@ assembly name="System.Xml" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Text.RegularExpressions" #>
<#@ import namespace="Microsoft.VisualStudio.Shell.Interop" #>
<#@ import namespace="EnvDTE" #>
<#@ import namespace="EnvDTE80" #>
<#@ import namespace="Microsoft.VisualStudio.TextTemplating" #>
<#@ import namespace="System.Xml.Linq" #>
<#@ import namespace="System.Xml" #>
<#@ import namespace="System.Reflection" #>
<#@ Include File="T4SP.tt.settings.t4" #>
// <auto-generated />
// This file was generated by a T4 template.
// Don't change it directly as your change would get overwritten. Instead, make changes
// to the .tt file (i.e. the T4 template) and save it to regenerate this file.
<# Prepare(); #>
#pragma warning disable 1591
namespace <#= DefaultNamespace #>
{
#region T4SP
using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using System.CodeDom.Compiler;
using System.Diagnostics;
using System.Reflection;
using System.Collections.Generic;
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public static class <#= HelperPrefix #>HelperConfigurator
{
public static bool _isInitialized;
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public static void EnsureListIdsInitialized(SPWeb web)
{
if(_isInitialized) return;
if(web == null) return;
var ids = new Dictionary<string, Guid>();
var lists = typeof(T4SPListCollection).GetProperties();
foreach(var info in lists)
{
var listField = (T4SPListBase)info.GetValue(<#= HelperPrefix #>.Lists, null);
var list = web.Lists[listField.Title];
ids.Add(listField.Url, list.ID);
}
var idsField = typeof(T4SPListBase).GetField("_ids", BindingFlags.NonPublic | BindingFlags.Static);
idsField.SetValue(null, ids);
_isInitialized = true;
}
}
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public static class <#= HelperPrefix #>
{
private static readonly T4SPContentTypeCollection _contentTypes = new T4SPContentTypeCollection();
private static readonly T4SPListCollection _lists = new T4SPListCollection();
private static readonly T4SPBuiltInFieldCollection _builtInFields = new T4SPBuiltInFieldCollection();
private static readonly T4SPBuiltInContentTypeCollection _builtInContentTypes = new T4SPBuiltInContentTypeCollection();
private static readonly T4SPSiteGroupCollection _siteGroups = new T4SPSiteGroupCollection();
private static readonly T4SPRoleCollection _roles = new T4SPRoleCollection();
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public static T4SPContentTypeCollection ContentTypes { get { return _contentTypes; } }
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public static T4SPListCollection Lists { get { return _lists; } }
<# if (GenerateBuiltInFields) { #>
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public static T4SPBuiltInFieldCollection BuiltInFields { get { return _builtInFields; } }
<# } #>
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public static T4SPBuiltInContentTypeCollection BuiltInContentTypes { get { return _builtInContentTypes; } }
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public static T4SPSiteGroupCollection SiteGroups { get { return _siteGroups; } }
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public static T4SPRoleCollection Roles { get { return _roles; } }
}
#region ContentTypes
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public class T4SPContentTypeCollection
{
<# var i = 0; foreach (var contentType in ContentTypes) { #>
// ContentType: <#= contentType.Name #>
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
<# var ctResourceString = contentType.Name.Replace(" ", string.Empty); if(IsResourceString(ctResourceString)) { #>
public class T4SPContentType_<#= i #> : T4SPContentType
{
public T4SPContentType_<#= i #>() : base(<#= GetResourceParameters(ctResourceString) #>, "<#= contentType.Id #>")
{
}
<# } else { #>
public class T4SPContentType_<#= i #> : T4SPContentType
{
public T4SPContentType_<#= i #>() : base("<#= contentType.Name #>", "<#= contentType.Id #>")
{
}
<# } #>
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public class T4SPFieldCollection
{
<# var fi = 0; foreach (var id in contentType.FieldIds) {
if (!Fields.ContainsKey(id)) continue;
var field = Fields[id];
var resourceString = field.DisplayName.Replace(" ", string.Empty);
if (IsResourceString(resourceString)) { #>
private static readonly T4SPFieldWithResource _field_<#= fi #> = new T4SPFieldWithResource("<#= field.Name #>", <#= GetResourceParameters(resourceString) #>, "<#= field.Id #>");
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public T4SPFieldWithResource <#= field.SanitizedName #> { get { return _field_<#= fi #>; } }
<# } else { #>
private static readonly T4SPField _field_<#= fi #> = new T4SPField("<#= field.Name #>", "<#= field.DisplayName #>", "<#= field.Id #>");
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public T4SPField <#= field.SanitizedName #> { get { return _field_<#= fi #>; } }
<# } #>
<# fi++; } #>
}
public static readonly T4SPFieldCollection _fields = new T4SPFieldCollection();
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public T4SPFieldCollection Fields { get { return _fields; } }
}
private static readonly T4SPContentType_<#= i #> _contentType_<#= i #> = new T4SPContentType_<#= i #>();
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public T4SPContentType_<#= i #> <#= contentType.SanitizedName #> { get { return _contentType_<#= i #>; } }
<# i++; } #>
}
#endregion
#region Lists
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public class T4SPListCollection
{
<# i = 0; foreach (var listInstance in ListInstances) {
var listTemplate = ListTemplates[listInstance.Type];
var list = Lists[listTemplate.ParentPath]; #>
// List instance: <#= listInstance.Name #>
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public class T4SPList_<#= i #> : T4SPListBase
{
public T4SPList_<#= i #>() : base("<#= listInstance.Name #>", "<#= listInstance.Url #>")
{
}
private static readonly T4SPFieldCollection _fields = new T4SPFieldCollection();
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public T4SPFieldCollection Fields { get { return _fields; } }
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public class T4SPFieldCollection
{
<# var fi = 0; foreach (var field in list.Fields) {
var resourceString = field.DisplayName.Replace(" ", string.Empty);
if (IsResourceString(resourceString)) { #>
private static readonly T4SPFieldWithResource _field_<#= fi #> = new T4SPFieldWithResource("<#= field.Name #>", <#= GetResourceParameters(resourceString) #>, "<#= field.Id #>");
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public T4SPFieldWithResource <#= field.SanitizedName #> { get { return _field_<#= fi #>; } }
<# } else { #>
private static readonly T4SPField _field_<#= fi #> = new T4SPField("<#= field.Name #>", "<#= field.DisplayName #>", "<#= field.Id #>");
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public T4SPField <#= field.SanitizedName #> { get { return _field_<#= fi #>; } }
<# } #>
<# fi++; } #>
}
private static readonly T4SPViewCollection _views = new T4SPViewCollection();
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public T4SPViewCollection Views { get { return _views; } }
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public class T4SPViewCollection
{
<# var vi = 0; foreach (var view in list.Views) {
var resourceString = view.DisplayName.Replace(" ", string.Empty);
if (IsResourceString(resourceString)) { #>
private static readonly T4SPViewWithResource _view_<#= vi #> = new T4SPViewWithResource(<#= GetResourceParameters(resourceString) #>);
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public T4SPViewWithResource ViewWithBaseID<#= view.BaseViewID #> { get { return _view_<#= vi #>; } }
<# } else { #>
private static readonly T4SPView _view_<#= vi #> = new T4SPView("<#= view.DisplayName #>");
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public T4SPView ViewWithBaseID<#= view.BaseViewID #> { get { return _view_<#= vi #>; } }
<# } #>
<# vi++; } #>
}
}
private static readonly T4SPList_<#= i #> _list_<#= i #> = new T4SPList_<#= i #>();
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public T4SPList_<#= i #> <#= listInstance.SanitizedName #> { get { return _list_<#= i #>; } }
<# i++; } #>
}
#endregion
#region Built-in fields
<# if (GenerateBuiltInFields) { #>
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public class T4SPBuiltInFieldCollection
{
<# foreach (var field in BuiltInFieldInfo) {
var name = field[1];
var displayName = field[2];
var id = field[0];
var resourceString = displayName.Replace(" ", string.Empty);
if(IsResourceString(resourceString)) {#>
private static readonly T4SPFieldWithResource _internal_<#= name #> = new T4SPFieldWithResource("<#= name #>", <#= GetResourceParameters(resourceString) #>, "<#= id #>");
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public T4SPFieldWithResource <#= name #> { get { return _internal_<#= name #>; } }
<# } else { #>
private static readonly T4SPField _internal_<#= name #> = new T4SPField("<#= name #>", "<#= displayName #>", "<#= id #>");
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public T4SPField <#= name #> { get { return _internal_<#= name #>; } }
<# }#>
<# } #>
}
<# } #>
#endregion
#region Built-in content types
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public class T4SPBuiltInContentTypeCollection
{
<# foreach (var contentType in BuiltInContentTypeInfo) {
var name = contentType[2];
var id = contentType[0];
var propertyName = contentType[1];
var resourceString = name.Replace(" ", string.Empty);
if(IsResourceString(resourceString)) {#>
private static readonly T4SPContentTypeWithResource _internal_<#= propertyName #> = new T4SPContentTypeWithResource(<#= GetResourceParameters(resourceString) #>, "<#= id #>");
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public T4SPContentTypeWithResource <#= propertyName #> { get { return _internal_<#= propertyName #>; } }
<# } else { #>
private static readonly T4SPContentType _internal_<#= propertyName #> = new T4SPContentType("<#= name #>", "<#= id #>");
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public T4SPContentType <#= propertyName #> { get { return _internal_<#= propertyName #>; } }
<# }#>
<# } #>
}
#endregion
#region Groups
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public class T4SPSiteGroupCollection
{
<# for (i = 0; i < SiteGroups.GetLength(0); i++) {
var name = SiteGroups[i, 0];
var displayName = SiteGroups[i, 1]; #>
private readonly T4SPGroup _group_<#= i #> = new T4SPGroup("<#= displayName #>");
public T4SPGroup <#= name #> { get { return _group_<#= i #>; } }
<# } #>
}
#endregion
#region Roles
public class T4SPRoleCollection
{
<# foreach (var role in Roles) { #>
private readonly T4SPRole _role_<#= role #> = new T4SPRole("<#= role #>");
public T4SPRole <#= role #> { get { return _role_<#= role #>; } }
<# } #>
}
#endregion
#region Model classes
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public abstract class T4SPFieldBase
{
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
protected T4SPFieldBase(string name, string id)
{
Name = name;
Id = new Guid(id);
}
public readonly string Name;
public readonly Guid Id;
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public abstract string DisplayName { get; }
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public static implicit operator Guid(T4SPFieldBase field)
{
return field.Id;
}
}
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public class T4SPField : T4SPFieldBase
{
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public T4SPField(string name, string displayName, string id) : base(name, id)
{
_displayName = displayName;
}
private readonly string _displayName;
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public override string DisplayName { get { return _displayName; } }
}
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public class T4SPFieldWithResource : T4SPFieldBase
{
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public T4SPFieldWithResource(string name, string key, string file, string id) : base(name, id)
{
_key = key;
_file = file;
}
private readonly string _key;
private readonly string _file;
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public override string DisplayName { get { return SPUtility.GetLocalizedString(_key, _file, (uint)System.Threading.Thread.CurrentThread.CurrentUICulture.LCID); } }
}
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public abstract class T4SPContentTypeBase
{
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
protected T4SPContentTypeBase(string id)
{
_id = new SPContentTypeId(id);
}
private readonly SPContentTypeId _id;
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public SPContentTypeId Id { get { return _id; } }
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public abstract string Name { get; }
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public static implicit operator SPContentTypeId(T4SPContentTypeBase contentType)
{
return contentType.Id;
}
}
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public class T4SPContentType : T4SPContentTypeBase
{
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public T4SPContentType(string name, string id) : base(id)
{
_name = name;
}
private readonly string _name;
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public override string Name { get { return _name; } }
}
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public class T4SPContentTypeWithResource : T4SPContentTypeBase
{
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public T4SPContentTypeWithResource(string key, string file, string id) : base(id)
{
_key = key;
_file = file;
}
private readonly string _key;
private readonly string _file;
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public override string Name { get { return SPUtility.GetLocalizedString(_key, _file, (uint)System.Threading.Thread.CurrentThread.CurrentUICulture.LCID); } }
}
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public abstract class T4SPListBase
{
static T4SPListBase()
{
_ids = new Dictionary<string, Guid>();
}
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
protected T4SPListBase(string title, string url)
{
Title = title;
Url = url;
}
public readonly string Title;
public readonly string Url;
static Dictionary<string, Guid> _ids;
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public Guid Id
{
get
{
if(_ids == null || !_ids.ContainsKey(Url))
{
<#= HelperPrefix #>HelperConfigurator.EnsureListIdsInitialized(SPContext.Current.Web);
}
return _ids[Url];
}
}
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public static implicit operator string(T4SPListBase list)
{
return list.Title;
}
}
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public abstract class T4SPViewBase
{
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public abstract string DisplayName { get; }
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public static implicit operator string(T4SPViewBase view)
{
return view.DisplayName;
}
}
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public class T4SPView : T4SPViewBase
{
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public T4SPView(string displayName)
{
_displayName = displayName;
}
private readonly string _displayName;
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public override string DisplayName { get { return _displayName; } }
}
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public class T4SPViewWithResource : T4SPViewBase
{
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public T4SPViewWithResource(string key, string file)
{
_key = key;
_file = file;
}
private readonly string _key;
private readonly string _file;
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public override string DisplayName { get { return SPUtility.GetLocalizedString(_key, _file, (uint)System.Threading.Thread.CurrentThread.CurrentUICulture.LCID); } }
}
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public class T4SPGroup
{
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public T4SPGroup(string name)
{
_name = name;
}
private readonly string _name;
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public string Name { get { return _name; } }
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public static implicit operator string(T4SPGroup @group)
{
return @group.Name;
}
}
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public class T4SPRole
{
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public T4SPRole(string name)
{
_name = name;
}
private readonly string _name;
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public string Name { get { return _name; } }
[GeneratedCode("T4SP", "1.0"), DebuggerNonUserCode]
public static implicit operator string(T4SPRole role)
{
return role.Name;
}
}
#endregion
#endregion
}
#pragma warning restore 1591
<#+
static DTE Dte;
static string DefaultNamespace;
List<XmlFile> XmlSchemas;
List<ContentTypeInfo> ContentTypes;
List<ListInstanceInfo> ListInstances;
Dictionary<string, ListInfo> Lists;
Dictionary<string, ListTemplateInfo> ListTemplates;
Dictionary<string, FieldInfo> Fields;
XNamespace spNs = "http://schemas.microsoft.com/sharepoint/";
static bool ExtendFieldsAdded;
void Prepare()
{
XmlSchemas = new List<XmlFile>();
ContentTypes = new List<ContentTypeInfo>();
Fields = new Dictionary<string, FieldInfo>();
Lists = new Dictionary<string, ListInfo>();
ListTemplates = new Dictionary<string, ListTemplateInfo>();
ListInstances = new List<ListInstanceInfo>();
var serviceProvider = Host as IServiceProvider;
if (serviceProvider != null) {
Dte = serviceProvider.GetService(typeof(SDTE)) as DTE;
}
var project = GetProjectContainingT4File(Dte);
DefaultNamespace = project.Properties.Item("DefaultNamespace").Value.ToString();
GetSchemaFiles(null, project.ProjectItems);
ProcessSchemaFiles();
AddExtendedFields();
}
void AddExtendedFields()
{
if (ExtendFieldsAdded) return;
for (int i = 0; i < ExtendBuiltInFields.GetLength(0); i++)
{
BuiltInFieldInfo.Add(new string[]{ ExtendBuiltInFields[i, 0], ExtendBuiltInFields[i, 1], ExtendBuiltInFields[i, 2] });
}
ExtendFieldsAdded = true;
}
void GetSchemaFiles(string parentPath, ProjectItems collection)
{
if(collection == null || collection.Count == 0)
{
return;
}
foreach (ProjectItem item in collection)
{
for (short i = 0; i < item.FileCount; i++)
{
string filePath = item.FileNames[i];
if (Path.GetExtension(filePath) == ".xml")
{
XmlSchemas.Add(new XmlFile { FilePath = filePath, ParentPath = parentPath });
}
}
GetSchemaFiles(item.FileNames[0], item.ProjectItems);
}
}
Project GetProjectContainingT4File(DTE dte)
{
// Find the .tt file's ProjectItem
ProjectItem projectItem = dte.Solution.FindProjectItem(Host.TemplateFile);
// If the .tt file is not opened, open it
if (projectItem.Document == null)
projectItem.Open(Constants.vsViewKindCode);
return projectItem.ContainingProject;
}
void ProcessSchemaFiles()
{
foreach (var file in XmlSchemas)
{
var document = XDocument.Load(file.FilePath);
var root = document.Root;
if (root.Name == spNs + "Elements")
{
BuildFields(root);
BuildContentTypes(root);
BuildListInstances(root);
BuildListTemplates(root, file.ParentPath);
}
if (root.Name == spNs + "List")
{
BuildList(root, file.ParentPath);
}
}
}
void BuildContentTypes(XElement element)
{
foreach (var ctElement in element.Descendants(spNs + "ContentType"))
{
var contentType = new ContentTypeInfo();
contentType.Name = (string)ctElement.Attribute("Name");
var comment = ctElement.Nodes().Where(n => n.NodeType == XmlNodeType.Comment && ((XComment)n).Value.Trim().StartsWith("T4SPName")).FirstOrDefault() as XComment;
if(comment != null)
{
contentType.SanitizedName = Helpers.RemoveDiacriticsAndSymbols(comment.Value.Remove(0, 9));
}
else
{
contentType.SanitizedName = Helpers.RemoveDiacriticsAndSymbols(contentType.Name);
}
contentType.Id = (string)ctElement.Attribute("ID");
foreach (var fieldRef in ctElement.Descendants(spNs + "FieldRef"))
{
var id = (string)fieldRef.Attribute("ID");
contentType.FieldIds.Add(id);
}
ContentTypes.Add(contentType);
}
}
void BuildFields(XElement element)
{
foreach (var field in element.Descendants(spNs + "Field"))
{
var fieldInfo = new FieldInfo();
fieldInfo.Id = (string)field.Attribute("ID");
fieldInfo.Name = (string)field.Attribute("Name");
fieldInfo.DisplayName = (string)field.Attribute("DisplayName");
fieldInfo.SanitizedName = Helpers.RemoveDiacriticsAndSymbols(fieldInfo.Name);
Fields.Add(fieldInfo.Id, fieldInfo);
}
}
void BuildListInstances(XElement element)
{
foreach (var listInstance in element.Descendants(spNs + "ListInstance"))
{
var listInstanceInfo = new ListInstanceInfo();
listInstanceInfo.Name = (string)listInstance.Attribute("Title");
listInstanceInfo.Url = (string)listInstance.Attribute("Url");
listInstanceInfo.Type = (string)listInstance.Attribute("TemplateType");
var comment = listInstance.Nodes().Where(n => n.NodeType == XmlNodeType.Comment && ((XComment)n).Value.Trim().StartsWith("T4SPName")).FirstOrDefault() as XComment;
if(comment != null)
{
listInstanceInfo.SanitizedName = Helpers.RemoveDiacriticsAndSymbols(comment.Value.Remove(0, 9));
}
else
{
listInstanceInfo.SanitizedName = Helpers.RemoveDiacriticsAndSymbols(listInstanceInfo.Name);
}
ListInstances.Add(listInstanceInfo);
}
}
void BuildListTemplates(XElement element, string parentPath)
{
foreach (var listTemplate in element.Descendants(spNs + "ListTemplate"))
{
var listTemplateInfo = new ListTemplateInfo();
listTemplateInfo.ParentPath = parentPath;
var type = (string)listTemplate.Attribute("Type");
ListTemplates.Add(type, listTemplateInfo);
}
}
void BuildList(XElement element, string parentPath)
{
var fields = element.Element(spNs + "MetaData").Element(spNs + "Fields");
if (fields == null) return;
var list = new ListInfo();
foreach (var field in fields.Descendants(spNs + "Field"))
{
var fieldInfo = new FieldInfo();
fieldInfo.Id = (string)field.Attribute("ID");
fieldInfo.Name = (string)field.Attribute("Name");
fieldInfo.DisplayName = (string)field.Attribute("DisplayName");
fieldInfo.SanitizedName = Helpers.RemoveDiacriticsAndSymbols(fieldInfo.Name);
list.Fields.Add(fieldInfo);
}
var views = element.Element(spNs + "MetaData").Element(spNs + "Views");
foreach (var view in views.Descendants(spNs + "View"))
{
var displayName = (string)view.Attribute("DisplayName");
if(string.IsNullOrEmpty(displayName)) continue;
var viewInfo = new ViewInfo();
viewInfo.DisplayName = displayName;
viewInfo.BaseViewID = (string)view.Attribute("BaseViewID");
list.Views.Add(viewInfo);
}
Lists.Add(parentPath, list);
}
public class XmlFile
{
public string FilePath;
public string ParentPath;
}
class ContentTypeInfo
{
public ContentTypeInfo()
{
FieldIds = new List<string>();
}
public string Id { get; set; }
public string Name { get; set; }
public string FileName { get; set; }
public string SanitizedName { get; set; }
public List<string> FieldIds { get; set; }
}
class FieldInfo
{
public string Id { get; set; }
public string Name { get; set; }
public string DisplayName { get; set; }
public string SanitizedName { get; set; }
}
class ListInfo
{
public ListInfo()
{
Fields = new List<FieldInfo>();
Views = new List<ViewInfo>();
}
public List<FieldInfo> Fields { get; set; }
public List<ViewInfo> Views { get; set; }
}
class ViewInfo
{
public string DisplayName { get; set; }
public string BaseViewID { get; set; }
}
class ListInstanceInfo
{
public string Type { get; set; }
public string Name { get; set; }
public string Url { get; set; }
public string SanitizedName { get; set; }
}
class ListTemplateInfo
{
public string ParentPath { get; set; }
}
public static class Helpers
{
public static string RemoveDiacriticsAndSymbols(string s)
{
var stripped = Capitalize(s);
stripped = RemoveSymbols(stripped);
stripped = RemoveDiacritics(stripped);
return stripped;
}
public static string Capitalize(string s)
{
bool wasSpace = true;
var builder = new StringBuilder();
foreach (var c in s)
{
if (wasSpace)
{
if (char.IsLetter(c))
{
builder.Append(char.ToUpper(c));
wasSpace = false;
}
else if (!char.IsWhiteSpace(c))
{
builder.Append(c);
wasSpace = false;
}
else
{
builder.Append(c);
wasSpace = true;
}
}
else
{
if (char.IsWhiteSpace(c))
{
wasSpace = true;
}
builder.Append(c);
}
}
return builder.ToString();
}
public static string RemoveDiacritics(string s)
{
var normalizedString = s.Normalize(NormalizationForm.FormD);
var stringBuilder = new StringBuilder();
foreach(var c in normalizedString)
{
if (System.Globalization.CharUnicodeInfo.GetUnicodeCategory(c) != System.Globalization.UnicodeCategory.NonSpacingMark)
stringBuilder.Append(c);
}
return stringBuilder.ToString();
}
public static string RemoveSymbols(string s)
{
var builder = new StringBuilder();
foreach (var c in s)
{
if (char.IsLetterOrDigit(c))
builder.Append(c);
}
return builder.ToString();
}
}
bool IsResourceString(string s)
{
return s.StartsWith("$Resources");
}
string GetResourceParameters(string s)
{
var fileStart = s.IndexOf(':') + 1;
var fileEnd = s.IndexOf(',');
var fileLen = fileEnd - fileStart;
var file = s.Substring(fileStart, fileLen);
var resource = s.Remove(fileStart - 1, fileLen + 1).Replace(";", string.Empty);
return string.Format("\"{0}\", \"{1}\"", resource, file);
}
static readonly List<string[]> BuiltInFieldInfo = new List<string[]> {
new string[]{ "{3C0E9E00-8FCC-479f-9D8D-3447CDA34C5B}", "OtherAddressCountry", "$Resources:core,Other_Address_Country_OL;" },
new string[]{ "{9EBCD900-9D05-46c8-8F4D-E46E87328844}", "Categories", "$Resources:core,Categories_OL;" },
new string[]{ "{BA934502-D68D-4960-A54B-51E15FEF5FD3}", "ManagersName", "$Resources:core,Managers_Name_OL;" },
new string[]{ "{6440B402-8EC5-4d7a-83F4-AFCCB556B5CC}", "ChildrensNames", "$Resources:core,Childrens_Names_OL;" },
new string[]{ "{810DBD02-BBF5-4c67-B1CE-5AD7C5A512B2}", "_DCDateModified", "$Resources:core,_DCDateModified;" },
new string[]{ "{038D1503-4629-40f6-ADAF-B47D1AB2D4FE}", "Company", "$Resources:core,Company;" },
new string[]{ "{B8BBE503-BB22-4237-8D9E-0587756A2176}", "EventCanceled", "$Resources:core,Event_Canceled;" },
new string[]{ "{63055D04-01B5-48f3-9E1E-E564E7C6B23B}", "UID", "$Resources:core,UID;" },
new string[]{ "{F5B36006-69B0-418c-BD4A-F25CA7E096BB}", "HomeAddressStateOrProvince", "$Resources:core,Home_Address_State_Or_Province_OL;" },
new string[]{ "{63fc6806-db53-4d0d-b18b-eaf90e96ddf5}", "CallTime", "$Resources:core,GBW_CT_CallTime_Field;" },
new string[]{ "{9b12fb06-254e-43b3-bfc8-8eea422ebc9f}", "Break", "$Resources:core,GBW_TC_Break_Field;" },
new string[]{ "{246D0907-637C-46b7-9AA0-0BB914DAA832}", "_Author", "$Resources:core,Author;" },
new string[]{ "{aaa68c08-6276-4337-9bce-b9cd852c7328}", "NightWork", "$Resources:core,GBW_TC_NightWork_Field;" },
new string[]{ "{04b29608-b1e8-4ff9-90d5-5328096dd5ac}", "End", "$Resources:core,GBW_TC_End_Field;" },
new string[]{ "{63c1c608-df6f-4cfa-bcab-fdbf9c223e31}", "Oof", "$Resources:core,GBW_TC_Oof_Field;" },
new string[]{ "{5263CD09-A770-4549-B012-D9F3DF3D8DF6}", "WorkflowDisplayName", "$Resources:core,WorkflowDisplayName;" },
new string[]{ "{3881510a-4e4a-4ee8-b102-8ee8e2d0dd4b}", "CheckoutUser", "$Resources:core,Checked_out_User;" },
new string[]{ "{e451420d-4e62-43e3-af83-010d36e353a2}", "ToggleQuotedText", "$Resources:core,Toggle_Quoted_Text;" },
new string[]{ "{D69BCC0E-57C3-4f3b-BBC5-B090EDF21F0F}", "PrimaryNumber", "$Resources:core,Primary_Phone_OL;" },
new string[]{ "{b5a7350f-2716-46ca-9c42-66bb39d042ec}", "HolidayWork", "$Resources:core,GBW_TC_HolidayWork_Field;" },
new string[]{ "{fa564e0f-0c70-4ab9-b863-0177e6ddd247}", "Title", "$Resources:core,Title;" },
new string[]{ "{475c2610-c157-4b91-9e2d-6855031b3538}", "FullName", "$Resources:core,Full_Name;" },
new string[]{ "{3f155110-a6a2-4d70-926c-94648101f0e8}", "Description", "$Resources:core,GBW_FC_Description_Field;" },
new string[]{ "{39360f11-34cf-4356-9945-25c44e68dade}", "File_x0020_Type", "$Resources:core,File_Type;" },
new string[]{ "{3DFB3E11-9CCD-4404-B44A-A71F6399EA56}", "XSLStyleIconUrl", "$Resources:core,XSLStyleIconUrl;" },
new string[]{ "{1d22ea11-1e32-424e-89ab-9fedbadb6ce1}", "ID", "$Resources:core,ID;" },
new string[]{ "{7B2B1712-A73D-4ad7-A9D0-662F0291713D}", "HealthRuleCheckEnabled", "$Resources:core,HealthRules_CheckEnabled;" },
new string[]{ "{53a2a512-d395-4852-8714-d4c27e7585f3}", "MobileContent", "$Resources:core,GBW_WN_MobileContent_Field;" },
new string[]{ "{6CC1C612-748A-48d8-88F2-944F477F301B}", "TimeZone", "$Resources:core,TimeZone;" },
new string[]{ "{F0753A13-44B1-4269-82AF-5C34C57B0C67}", "Profession", "$Resources:core,Profession_OL;" },
new string[]{ "{94f89715-e097-4e8b-ba79-ea02aa8b7adb}", "FileRef", "$Resources:core,URL_Path;" },
new string[]{ "{E9359D15-261B-48f6-A302-01419A68D4DE}", "BaseAssociationGuid", "$Resources:core,BaseAssociationGuid;" },
new string[]{ "{0850AE15-19DD-431f-9C2F-3AFF3AE292CE}", "OrganizationalIDNumber", "$Resources:core,Organizational_ID_Number_OL;" },
new string[]{ "{58ca6516-51cd-41fb-a908-dd2a4aeea8bc}", "Threading", "$Resources:core,Threading;" },
new string[]{ "{E2C93917-CF32-4b29-BE5C-D71F1BAC7714}", "IMEComment2", "$Resources:core,ImeFieldComment2;" },
new string[]{ "{7650d41a-fa26-4c72-a641-af4e93dc7053}", "Content", "$Resources:core,GBW_WN_Content_Field;" },
new string[]{ "{7C52F61A-E1E0-4341-9E2F-9B36CDDFDD7C}", "IMEComment3", "$Resources:core,ImeFieldComment3;" },
new string[]{ "{7111aa1b-e7ae-4b69-acaf-db669b76e03a}", "V4CallTo", "$Resources:core,GBW_CT_CallTo_Field;" },
new string[]{ "{43bdd51b-3c5b-4e78-90a8-fb2087f71e70}", "_Level", "$Resources:core,Level;" },
new string[]{ "{baf7091c-01fb-4831-a975-08254f87f234}", "IsNonWorkingDay", "$Resources:core,GBW_HL_IsNonWorkingDay_Field;" },
new string[]{ "{c5c4b81c-f1d9-4b43-a6a2-090df32ebb68}", "ProgId", "$Resources:core,ProgId;" },
new string[]{ "{F08AB41D-9A03-49ae-9413-6CD284A15625}", "wic_System_Copyright", "$Resources:core,Copyright;" },
new string[]{ "{b4ab471e-0262-462a-8b3f-c1dfc9e2d5fd}", "PersonViewMinimal", "$Resources:core,Posted_By;" },
new string[]{ "{caa2cb1e-a124-4068-9496-14feef1a901f}", "EmailTo", "$Resources:core,E-Mail_To;" },
new string[]{ "{dcde7b1f-918b-4ed5-819f-9798f8abac37}", "Outcome", "$Resources:core,Outcome;" },
new string[]{ "{960ff01f-2b6d-4f1b-9c3f-e19ad8927341}", "FolderChildCount", "$Resources:core,Folder_Child_Count;" },
new string[]{ "{5928ff1f-daa1-406c-b4a9-190485a448cb}", "User", "$Resources:core,User_ID;" },
new string[]{ "{dddd2420-b270-4735-93b5-92b713d0944d}", "ScopeId", "$Resources:core,ScopeId;" },
new string[]{ "{D2433B20-3F02-4432-817D-369F104A2DCD}", "IMEComment1", "$Resources:core,ImeFieldComment1;" },
new string[]{ "{274b7e21-284a-4c49-bec6-f1f2cb6fc344}", "CallBack", "$Resources:core,GBW_CT_CallBack_Field;" },
new string[]{ "{1F43CD21-53C5-44c5-8675-B8BB86083244}", "ThumbnailExists", "$Resources:core,ThumbnailExists;" },
new string[]{ "{17CA3A22-FDFE-46eb-99B5-9646BAED3F16}", "FormURN", "$Resources:core,Form_URN;" },
new string[]{ "{A5D2F824-BC53-422e-87FD-765939D863A5}", "ImageCreateDate", "$Resources:core,Date_Picture_Taken;" },
new string[]{ "{ae069f25-3ac2-4256-b9c3-15dbc15da0e0}", "GUID", "$Resources:core,GUID;" },
new string[]{ "{C4C7D925-BC1B-4f37-826D-AC49B4FB1BC1}", "Birthday", "$Resources:core,Birthday_OL;" },
new string[]{ "{4dd7e525-8d6b-4cb4-9d3e-44ee25f973eb}", "Created_x0020_By", "$Resources:core,Document_Created_By;" },
new string[]{ "{BD716B26-546D-43f2-B229-62699581FA9F}", "Preview", "$Resources:core,Web_Preview;" },
new string[]{ "{9d30f126-ba48-446b-b8f9-83745f322ebe}", "LinkFilenameNoMenu", "$Resources:core,Name;" },
new string[]{ "{875FAB27-6E95-463b-A4A6-82544F1027FB}", "RelatedIssues", "$Resources:core,Related_Issues;" },
new string[]{ "{fd630629-c165-4513-b43c-fdb16b86a14d}", "WorkPhone", "$Resources:core,Business_Phone;" },
new string[]{ "{76A81629-44D4-4ce1-8D4D-6D7EBCD885FC}", "Subject", "$Resources:core,Subject;" },
new string[]{ "{418C8D29-6F2E-44c3-8955-2CD7EC3E2151}", "MiddleName", "$Resources:core,Middle_Name_OL;" },
new string[]{ "{A579062A-6C1D-4ad3-9D5E-035F9F2C1882}", "ISDNNumber", "$Resources:core,ISDN_OL;" },
new string[]{ "{9941082A-4160-46a1-A5B2-03394BFDF7EE}", "ThumbnailOnForm", "$Resources:core,ThumbnailOnForm;" },
new string[]{ "{dce8262a-3ae9-45aa-aab4-83bd75fb738a}", "_UIVersionString", "$Resources:core,Version_Number;" },
new string[]{ "{7a0cb12b-c70c-4f99-99f1-a232783a87d7}", "EmailCalendarSequence", "$Resources:core,E-Mail_Calendar_Sequence;" },
new string[]{ "{1b89212c-1c67-487a-8c14-4d30bf4ef223}", "ConfirmedTo", "$Resources:core,GBW_CT_ConfirmedTo_Field;" },
new string[]{ "{9D76802C-13C4-484a-9872-D7F9641C4672}", "Anniversary", "$Resources:core,Anniversary_OL;" },
new string[]{ "{7662cd2c-f069-4dba-9e35-082cf976e170}", "Body", "$Resources:core,Body;" },
new string[]{ "{bfc6f32c-668c-43c4-a903-847cca2f9b3c}", "Name", "$Resources:core,Account;" },
new string[]{ "{FBF29B2D-CAE5-49aa-8E0A-29955B540122}", "xd_Signature", "$Resources:core,Xml_signed;" },
new string[]{ "{2ead592e-f05c-41a2-9817-e06dac25bc19}", "GoingHome", "$Resources:core,GBW_WA_GoingHome_Field;" },
new string[]{ "{16B6952F-3CE6-45e0-8F4E-42DAC6E12441}", "OffsiteParticipant", "$Resources:core,OffsiteParticipant;" },
new string[]{ "{086F2B30-460C-4251-B75A-DA88A5B205C1}", "ShowCombineView", "$Resources:core,ShowCombineView;" },
new string[]{ "{288F5F32-8462-4175-8F09-DD7BA29359A9}", "Location", "$Resources:core,Location;" },
new string[]{ "{F55DE332-074E-4e71-A71A-B90ABFAD51AE}", "AssistantNumber", "$Resources:core,Assistants_Phone_OL;" },
new string[]{ "{5602dc33-a60a-4dec-bd23-d18dfcef861d}", "Occurred", "$Resources:core,Date_Occurred;" },
new string[]{ "{1944C034-D61B-42af-AA84-647F2E74CA70}", "ImageHeight", "$Resources:core,Picture_Height;" },
new string[]{ "{566DA236-762B-4a76-AD1F-B08B3C703FCE}", "XomlUrl", "$Resources:core,XomlUrl;" },
new string[]{ "{bc91a437-52e7-49e1-8c4e-4698904b2b6d}", "LinkTitleNoMenu", "$Resources:core,Title;" },
new string[]{ "{53101f38-dd2e-458c-b245-0c236cc13d1a}", "AssignedTo", "$Resources:core,Assigned_To;" },
new string[]{ "{AC7BB138-02DC-40eb-B07A-84C15575B6E9}", "Thumbnail", "$Resources:core,Thumbnail;" },