Skip to content
Navigation Menu
{{ message }}
This repository was archived by the owner on Jul 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 140
Expand file tree
/
Copy pathEdgeViewGraphViewCodeTemplate.cs
More file actions
1110 lines (910 loc) · 43.8 KB
/
Copy pathEdgeViewGraphViewCodeTemplate.cs
File metadata and controls
1110 lines (910 loc) · 43.8 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
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
// ------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version: 12.0.0.0
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
// ------------------------------------------------------------------------------
namespace GraphView
{
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System;
/// <summary>
/// Class to produce the template output
/// </summary>
#line 1 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "12.0.0.0")]
public partial class EdgeViewGraphViewCodeTemplate : EdgeViewGraphViewCodeTemplateBase
{
#line hidden
/// <summary>
/// Create the template output
/// </summary>
public virtual string TransformText()
{
this.Write(" ");
this.Write(" ");
this.Write(" ");
this.Write(" ");
this.Write(" ");
this.Write("\r\n");
#line 8 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
var typeDictionary = new Dictionary<string, Tuple<string, string>>
{
{"int", new Tuple<string, string>("int", "Int32")},
{"long", new Tuple<string, string>("bigint", "Int64")},
{"double", new Tuple<string, string>("float", "Double")},
{"string", new Tuple<string, string>("nvarchar(4000)", "String")},
{"bool", new Tuple<string, string>("bit", "Boolean")}
};
#line default
#line hidden
this.Write(@" using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Data.SqlTypes;
using System.Text;
using Microsoft.SqlServer.Server;
public partial class UserDefinedFunctions
{
private class ");
#line 27 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(EdgeName));
#line default
#line hidden
this.Write("DecoderResult\r\n {\r\n\t\tpublic long Sink { get; set; }\r\n\t\tpublic int ColumnId { g" +
"et; set; }\r\n\t\tpublic int EdgeId{ get; set; }\r\n\t\tpublic string _EdgeType {get; se" +
"t;}\r\n");
#line 33 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
foreach (var variable in AttributeTypeDict) {
#line default
#line hidden
this.Write("\t\tpublic Sql");
#line 34 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(typeDictionary[variable.Value].Item2));
#line default
#line hidden
this.Write(" ");
#line 34 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(variable.Key));
#line default
#line hidden
this.Write(" { get; set; }\r\n");
#line 35 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
}
#line default
#line hidden
this.Write("\t}\r\n\r\n public static void ");
#line 38 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(EdgeName));
#line default
#line hidden
this.Write("Decoder_FillRow(\r\n object tableTypeObject,\r\n out SqlInt64 sink, out SqlInt3" +
"2 columnId, out SqlInt32 edgeid, out SqlString _EdgeType");
#line 40 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
var indent = " ";
foreach (var variable in AttributeTypeDict) {
WriteLine(",");
Write(indent + "out Sql" + typeDictionary[variable.Value].Item2 + " " + variable.Key);
}
#line default
#line hidden
this.Write(")\r\n {\r\n var decoderResult = (");
#line 47 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(EdgeName));
#line default
#line hidden
this.Write("DecoderResult)tableTypeObject;\r\n sink = decoderResult.Sink;\r\n colum" +
"nId = decoderResult.ColumnId;\r\n edgeid = decoderResult.EdgeId;\r\n\t\t_EdgeTy" +
"pe = new SqlString(decoderResult._EdgeType);\r\n");
#line 52 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
foreach (var variable in AttributeTypeDict) {
#line default
#line hidden
this.Write("\t\t");
#line 53 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(variable.Key));
#line default
#line hidden
this.Write(" = decoderResult.");
#line 53 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(variable.Key));
#line default
#line hidden
this.Write(";\r\n");
#line 54 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
}
#line default
#line hidden
this.Write(" }\r\n\r\n [SqlFunction(\r\n DataAccess = DataAccessKind.None,\r\n TableDefin" +
"ition = \"Sink bigint, ColumnId int, EdgeId int, _EdgeType string");
#line 59 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
foreach(var variable in AttributeTypeDict)
Write(", " + variable.Key + " " + typeDictionary[variable.Value].Item1);
#line default
#line hidden
this.Write("\",\r\n FillRowMethodName = \"");
#line 63 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(EdgeName));
#line default
#line hidden
this.Write("Decoder_FillRow\",\r\n IsDeterministic = true,\r\n IsPrecise = false\r\n )]\r\n\r\n" +
"\tpublic static IEnumerable ");
#line 68 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(EdgeName));
#line default
#line hidden
this.Write("Decoder(\r\n");
#line 69 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
if (Mapping.Count() != 0){
Write(indent + "SqlBytes array0");
WriteLine(",");
Write(indent + "SqlBytes dele0");
}
for (int i = 1; i < Mapping.Count(); i++) {
WriteLine(",");
Write(indent + "SqlBytes array" + i.ToString());
WriteLine(",");
Write(indent + "SqlBytes dele" + i.ToString());
}
WriteLine(",");
Write(indent + "long dumb = 0");
#line default
#line hidden
this.Write(")\r\n {\r\n var edgeid = (Int32)0;\r\n\t\tvar deleDict = new Dictionary<Int32, " +
"bool>();\r\n");
#line 86 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
var calc = 0;
indent += " ";
foreach(var it in Mapping) {
var array = "array" + calc.ToString();
var dele = "dele" + calc.ToString();
calc++;
var variables = it.Value;
var columnId = ColumnId[it.Key];
var attributeSize = variables.Count();
var byteSize = (attributeSize - 1) / 8 + 1;
if (attributeSize == 0) {
byteSize = 0;
}
#line default
#line hidden
this.Write("\t\tedgeid = 0;\r\n\t\tdeleDict.Clear();\r\n\t\tif (");
#line 103 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(dele));
#line default
#line hidden
this.Write(" != null && !");
#line 103 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(dele));
#line default
#line hidden
this.Write(".IsNull) \r\n\t\t{\r\n\t\t\t//var brdele = new BinaryReader(new MemoryStream(");
#line 105 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(dele));
#line default
#line hidden
this.Write(".Value));\r\n\t\t\tvar brdele = new BinaryReader(");
#line 106 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(dele));
#line default
#line hidden
this.Write(".Stream);\r\n\t\t\twhile (brdele.BaseStream.Position != brdele.BaseStream.Length)\r\n\t\t\t" +
"{\r\n\t\t\t\tdeleDict[brdele.ReadInt32()] = true;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (");
#line 112 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(array));
#line default
#line hidden
this.Write(" != null && !");
#line 112 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(array));
#line default
#line hidden
this.Write(".IsNull)\r\n\t\t{\r\n //var br = new BinaryReader(new MemoryStream(");
#line 114 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(array));
#line default
#line hidden
this.Write(".Value));\r\n var br = new BinaryReader(");
#line 115 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(array));
#line default
#line hidden
this.Write(".Stream);\r\n while (br.BaseStream.Position != br.BaseStream.Length)\r\n " +
" {\r\n edgeid++;\r\n");
#line 119 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
if (byteSize != 0) {
#line default
#line hidden
this.Write(" byte[] bitmap = br.ReadBytes(");
#line 120 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(byteSize));
#line default
#line hidden
this.Write(");\r\n");
#line 121 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
}
#line default
#line hidden
this.Write(" var sink = br.ReadInt64();\r\n object temp;\r\n");
#line 124 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
var count = 0;
foreach (var iterator in AttributeTypeDict) {
WriteLine(indent + "var _" + iterator.Key + " = Sql" + typeDictionary[iterator.Value].Item2 + ".Null;"); }
foreach (var variable in variables)
{
var variableName = (variable.Item2 == "") ? "temp": "_" + variable.Item2;
var variableType = variable.Item1;
var str = "((bitmap["+ (count / 8).ToString() + "]" + " & " + (1 << (count%8)).ToString() + ") == 0)? Sql" + typeDictionary[variableType].Item2 + ".Null" +" :";
if (attributeSize == 0) {
str = "";
}
WriteLine(indent + variableName + " = " + str + "br.Read" + typeDictionary[variableType].Item2 + "();");
count++;
}
#line default
#line hidden
this.Write("\t\t\tif (!deleDict.ContainsKey(edgeid)) {\r\n\t\t\t\tyield return new ");
#line 141 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(EdgeName));
#line default
#line hidden
this.Write("DecoderResult\r\n\t\t\t\t{\r\n\t\t\t\t\tSink = sink, ColumnId = ");
#line 143 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(columnId));
#line default
#line hidden
this.Write(", EdgeId = edgeid, _EdgeType = \"");
#line 143 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(it.Key.Item2));
#line default
#line hidden
this.Write("\",\r\n");
#line 144 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
foreach (var variable in AttributeTypeDict)
{
WriteLine(indent + " " + variable.Key + " = _" + variable.Key + ",");
}
#line default
#line hidden
this.Write("\t\t\t\t};\r\n\t\t\t}\r\n }\r\n\t\t}\r\n");
#line 154 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
}
#line default
#line hidden
this.Write("\t\tyield break;\r\n }\r\n\r\n\r\n //Path Decoder\r\n private class ");
#line 160 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(EdgeName));
#line default
#line hidden
this.Write("ExclusiveEdgeGeneratorResult \r\n {\r\n public int EdgeId{get; set;}\r\n " +
" public long SinkId{get; set;}\r\n public int ColumnId{get; set;}\r\n " +
" public string _EdgeType {get; set;}\r\n");
#line 166 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
foreach (var variable in AttributeTypeDict) {
#line default
#line hidden
this.Write(" public Sql");
#line 167 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(typeDictionary[variable.Value].Item2));
#line default
#line hidden
this.Write(" ");
#line 167 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(variable.Key));
#line default
#line hidden
this.Write(" { get; set; }\r\n");
#line 168 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
}
#line default
#line hidden
this.Write(" }\r\n\r\n public static void ");
#line 171 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(EdgeName));
#line default
#line hidden
this.Write("ExclusiveEdgeGenerator_FillRow(\r\n object tableTypeObject,\r\n out Sql" +
"Int32 EdgeId, out SqlInt32 ColumnId, out SqlInt64 SinkId, out SqlString _EdgeTyp" +
"e");
#line 173 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
foreach (var variable in AttributeTypeDict) {
WriteLine(",");
Write(indent + "out Sql" + typeDictionary[variable.Value].Item2 + " " + variable.Key);
}
#line default
#line hidden
this.Write(" )\r\n {\r\n var decoderResult = (");
#line 181 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(EdgeName));
#line default
#line hidden
this.Write("ExclusiveEdgeGeneratorResult)tableTypeObject;\r\n EdgeId = decoderResult.Edg" +
"eId;\r\n ColumnId = decoderResult.ColumnId;\r\n\t\t_EdgeType = decoderResult._E" +
"dgeType;\r\n SinkId = decoderResult.SinkId;\r\n");
#line 186 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
foreach (var variable in AttributeTypeDict) {
#line default
#line hidden
this.Write(" ");
#line 187 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(variable.Key));
#line default
#line hidden
this.Write(" = decoderResult.");
#line 187 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(variable.Key));
#line default
#line hidden
this.Write(";\r\n");
#line 188 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
}
#line default
#line hidden
this.Write(" }\r\n \r\n [SqlFunction(\r\n DataAccess = DataAccessKind.None,\r\n " +
" TableDefinition = \"EdgeId int, ColumnId int, SinkId bigint, _EdgeType Stri" +
"ng\",\r\n FillRowMethodName = \"");
#line 194 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(EdgeName));
#line default
#line hidden
this.Write("ExclusiveEdgeGenerator_FillRow\",\r\n IsDeterministic = true,\r\n IsPrec" +
"ise = false\r\n )]\r\n public static IEnumerable ");
#line 198 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(EdgeName));
#line default
#line hidden
this.Write("ExclusiveEdgeGenerator(\r\n\t\tSqlBytes PathVarbinary,\r\n\t\tSqlInt64 nodeid,\r\n");
#line 201 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
indent = " ";
if (Mapping.Count() != 0){
Write(indent + "SqlBytes array0");
WriteLine(",");
Write(indent + "SqlBytes dele0");
}
for (int i = 1; i < Mapping.Count(); i++) {
WriteLine(",");
Write(indent + "SqlBytes array" + i.ToString());
WriteLine(",");
Write(indent + "SqlBytes dele" + i.ToString());
}
#line default
#line hidden
this.Write(")\r\n {\r\n //Stream PathMemory = (PathVarbinary != null && !PathVarbinary." +
"IsNull) ? PathVarbinary.Stream : new MemoryStream();\r\n\t\t//var brPath = new Binar" +
"yReader(PathMemory);\r\n //var PathDict = new Dictionary<Tuple<long, long," +
" Int32>, bool>();\r\n //if (PathVarbinary != null && !PathVarbinary.IsNull)" +
" {\r\n // while (brPath.BaseStream.Position != brPath.BaseStream.Length)" +
"\r\n // {\r\n // var Edgeid = Tuple.Create(brPath.ReadInt64(" +
"), brPath.ReadInt64(), brPath.ReadInt32());\r\n // PathDict[Edgeid] " +
"= true;\r\n // }\r\n //}\r\n \r\n\t\t//var len = (int) PathVarbina" +
"ry.Length;\r\n\t\t//var PathDict = new Dictionary<Tuple<long, long, Int32>, bool>()" +
";\r\n\t\t//if (PathVarbinary != null && !PathVarbinary.IsNull) {\r\n\t\t//\tfor (int i = " +
"0; i < len; i += 24) \r\n\t\t//\t{\r\n\t\t//\t\tvar Edgeid = Tuple.Create(BitConverter.ToIn" +
"t64(PathVarbinary.Buffer, i),\r\n\t\t//\t\t\t\t\t\t\t\tBitConverter.ToInt64(PathVarbinary.Bu" +
"ffer, i + 8),\r\n\t\t//\t\t\t\t\t\t\t\t(int)BitConverter.ToInt64(PathVarbinary.Buffer, i + 1" +
"6));\r\n\t\t//\t\tPathDict[Edgeid] = true;\r\n\t\t//\t}\r\n\t\t//}\r\n\r\n\t\tvar len = (int) PathVar" +
"binary.Length;\r\n\t\tvar longArray = new long[len >> 3];\r\n\t\tBuffer.BlockCopy(PathVa" +
"rbinary.Buffer, 0, longArray, 0, len);\r\n\t\tvar PathDict = new Dictionary<long, b" +
"ool>();\r\n\t\tlen = len >> 3;\r\n\t\tif (PathVarbinary != null && !PathVarbinary.IsNull" +
") {\r\n\t\t\tfor (int i = 0; i < len; i += 2) \r\n\t\t\t{\r\n\t\t\t\tif (longArray[i] == nodeid." +
"Value) {\r\n\t\t\t\t\tvar Edgeid = longArray[i+1];\r\n\t\t\t\t\tPathDict[Edgeid] = true;\r\n\t\t\t\t" +
"}\r\n\t\t\t}\r\n\t\t}\r\n\r\n foreach (var it in ");
#line 253 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(EdgeName));
#line default
#line hidden
this.Write("Decoder(\r\n");
#line 254 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
indent += " ";
if (Mapping.Count() != 0){
Write(indent + "array0");
WriteLine(",");
Write(indent + "dele0");
}
for (int i = 1; i < Mapping.Count(); i++) {
WriteLine(",");
Write(indent + "array" + i.ToString());
WriteLine(",");
Write(indent + "dele" + i.ToString());
}
WriteLine(",");
Write(indent + "0");
#line default
#line hidden
this.Write("))\r\n {\r\n var adjacent = it as ");
#line 270 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(EdgeName));
#line default
#line hidden
this.Write("DecoderResult;\r\n long EdgeId = ((long) adjacent.ColumnId << 32) | adja" +
"cent.EdgeId;\r\n if (!PathDict.ContainsKey(EdgeId))\r\n {\r\n " +
" yield return new ");
#line 274 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(EdgeName));
#line default
#line hidden
this.Write("ExclusiveEdgeGeneratorResult\r\n {\r\n EdgeId = adj" +
"acent.EdgeId,\r\n\t\t\t\t\tColumnId = adjacent.ColumnId,\r\n SinkId = " +
"adjacent.Sink,\r\n\t\t\t\t\t_EdgeType = adjacent._EdgeType,\r\n");
#line 280 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
indent += " ";
foreach (var variable in AttributeTypeDict) {
WriteLine(indent + variable.Key + " = adjacent." + variable.Key + ",");
}
#line default
#line hidden
this.Write(" };\r\n }\r\n }\r\n yield break;\r\n }\r\n}\r\n\r\np" +
"ublic partial class UserDefinedFunctions\r\n{\r\n\t//path message encoder\r\n");
#line 296 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
var attributeInfo= AttributeTypeDict.Select(x => Tuple.Create(x.Key, x.Value)).ToList();
var size = (attributeInfo.Count()) / 8 + 1;
#line default
#line hidden
this.Write("\r\n\t[Microsoft.SqlServer.Server.SqlFunction]\r\n\tpublic static SqlBytes ");
#line 302 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(EdgeName));
#line default
#line hidden
this.Write("_PathMessageEncoder(SqlString nodeType, SqlString Id,\r\n\t\tSqlString edgeType");
#line 303 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
indent = " ";
for (var i = 0; i < attributeInfo.Count; ++i)
{
WriteLine(",");
Write(indent + "Sql" + typeDictionary[attributeInfo[i].Item2].Item2 + " " + attributeInfo[i].Item1);
}
#line default
#line hidden
this.Write(")\r\n\t{\r\n\t\tMemoryStream _stream = new MemoryStream();\r\n\t\tBinaryWriter _writer = new" +
" BinaryWriter(_stream);\r\n\r\n\t\tByte[] bitmap = new Byte[");
#line 313 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(size));
#line default
#line hidden
this.Write("];\r\n\t\tArray.Clear(bitmap, 0, bitmap.Length);\r\n\t\tif (!Id.IsNull)\r\n\t\t{\r\n\t\t\tbitmap[0" +
"] |= 1;\r\n\t\t}\r\n");
#line 319 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
var count2 = 1;
foreach (var variable in attributeInfo)
{
var variableName = variable.Item1;
var variableType = variable.Item2;
var pos = count2 / 8;
var bit = (1 << (count2 % 8));
#line default
#line hidden
this.Write("\t\tif (!");
#line 328 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(variableName));
#line default
#line hidden
this.Write(".IsNull) {\r\n\t\t\tbitmap[");
#line 329 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(pos));
#line default
#line hidden
this.Write("] |= ");
#line 329 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(bit));
#line default
#line hidden
this.Write("; \r\n\t\t}\r\n");
#line 331 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
count2++;
}
#line default
#line hidden
this.Write("\t\t_writer.Write(bitmap);\r\n\t\t_writer.Write(nodeType.Value);\r\n\t\tif (!Id.IsNull) \r\n\t" +
"\t{\r\n\t\t\t_writer.Write(Id.Value);\r\n\t\t}\r\n\t\t_writer.Write(edgeType.Value);\r\n");
#line 342 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
foreach (var variable in attributeInfo)
{
var variableName = variable.Item1;
var variableType = variable.Item2;
#line default
#line hidden
this.Write("\t\tif (!");
#line 348 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(variableName));
#line default
#line hidden
this.Write(".IsNull) {\r\n\t\t\t_writer.Write(");
#line 349 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(variableName));
#line default
#line hidden
this.Write(".Value);\r\n\t\t}\r\n");
#line 351 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
}
#line default
#line hidden
this.Write("\t\treturn new SqlBytes(_stream);\r\n\t}\r\n\r\n\t//path message decoder\r\n\t[Microsoft.SqlSe" +
"rver.Server.SqlFunction]\r\n\tpublic static SqlString ");
#line 359 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(EdgeName));
#line default
#line hidden
this.Write(@"_PathMessageDecoder(SqlBytes array, SqlString nodeType, SqlString id)
{
if (array == null || array.IsNull)
return new SqlString(""["" +
(nodeType.Value + (id.IsNull ? """" : id.Value.ToString())) +""]"");
var br = new BinaryReader(array.Stream);
string res = ""["";
while (br.BaseStream.Position != br.BaseStream.Length)
{
byte[] bitmap = br.ReadBytes(");
#line 368 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(size));
#line default
#line hidden
this.Write(@");
res += ""{\""NodeType\"":\"""";
res += br.ReadString() + ""\"", \""Id\"":"";
if ((bitmap[0] & 1) != 0) {
res += ""\"""" + br.ReadString() + ""\""}, {\""EdgeType\"":\"""";
} else {
res += ""null}, {\""EdgeType\"":\"""";
}
res += br.ReadString() + ""\"""";
");
#line 377 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
if (attributeInfo.Count != 0) {
#line default
#line hidden
this.Write("\t\t\tres += \", \\\"Attribute\\\":{\";\r\n");
#line 379 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
indent += " ";
count2 = 1;
foreach (var variable in attributeInfo)
{
var variableName = variable.Item1;
var variableType = variable.Item2;
if (count2 != 1)
{
#line default
#line hidden
this.Write("\t\t\t\t\tres += \",\";\r\n");
#line 389 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
}
#line default
#line hidden
this.Write("\t\t\t\tres += \"\\\"");
#line 391 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(variableName));
#line default
#line hidden
this.Write("\\\":\";\r\n\t\t\t\tif ((bitmap[");
#line 392 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture((count2 / 8).ToString()));
#line default
#line hidden
this.Write("] & ");
#line 392 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture((1 << (count2 %8)).ToString()));
#line default
#line hidden
this.Write(") != 0) {\r\n");
#line 393 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
if (variableType.ToLower() == "string") {
#line default
#line hidden
this.Write("\t\t\t\t\tres += \"\\\"\" + br.Read");
#line 394 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(typeDictionary[variableType].Item2));
#line default
#line hidden
this.Write("().ToString() + \"\\\"\";\r\n");
#line 395 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
} else {
#line default
#line hidden
this.Write("\t\t\t\t\tres += br.Read");
#line 396 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(typeDictionary[variableType].Item2));
#line default
#line hidden
this.Write("().ToString().ToLower();\r\n");
#line 397 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
}
#line default
#line hidden
this.Write("\t\t\t\t} else {\r\n\t\t\t\t\tres += \"null\";\r\n\t\t\t\t}\r\n");
#line 401 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
count2++;
}
#line default
#line hidden
this.Write("\t\t\tres += \"}\";\r\n\t\t\t");
#line 404 "D:\Source\GraphView\EdgeViewGraphViewCodeTemplate.tt"
}
#line default
#line hidden
this.Write("\t\t\tres += \"}, \";\r\n\t\t}\r\n\t\t\tres += \"{\\\"NodeType\\\":\\\"\";\r\n\t\t\tres += nodeType.Value + " +
"\"\\\", \\\"Id\\\":\";\r\n\t\t\tif (!id.IsNull) {\r\n\t\t\t\tres += \"\\\"\" + id.Value + \"\\\"}\";\r\n\t\t\t} " +
"else {\r\n\t\t\t\tres += \"null}\";\r\n\t\t\t}\r\n\r\n\t\tres += \"]\";\r\n\t\treturn new SqlString(res);" +
"\r\n\t}\r\n}");
return this.GenerationEnvironment.ToString();
}
}
#line default
#line hidden
#region Base class
/// <summary>
/// Base class for this transformation
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "12.0.0.0")]
public class EdgeViewGraphViewCodeTemplateBase
{
#region Fields
private global::System.Text.StringBuilder generationEnvironmentField;
private global::System.CodeDom.Compiler.CompilerErrorCollection errorsField;
private global::System.Collections.Generic.List<int> indentLengthsField;
private string currentIndentField = "";
private bool endsWithNewline;
private global::System.Collections.Generic.IDictionary<string, object> sessionField;
#endregion
#region Properties
/// <summary>
/// The string builder that generation-time code is using to assemble generated output
/// </summary>
protected System.Text.StringBuilder GenerationEnvironment
{
get
{
if ((this.generationEnvironmentField == null))
{
this.generationEnvironmentField = new global::System.Text.StringBuilder();
}
return this.generationEnvironmentField;
}
set
{
this.generationEnvironmentField = value;
}
}
/// <summary>
/// The error collection for the generation process
/// </summary>
public System.CodeDom.Compiler.CompilerErrorCollection Errors
{
get
{
if ((this.errorsField == null))
{
this.errorsField = new global::System.CodeDom.Compiler.CompilerErrorCollection();
}
return this.errorsField;
}
}
/// <summary>
/// A list of the lengths of each indent that was added with PushIndent
/// </summary>
private System.Collections.Generic.List<int> indentLengths
{
get
{
if ((this.indentLengthsField == null))
{
this.indentLengthsField = new global::System.Collections.Generic.List<int>();
}
return this.indentLengthsField;
}
}
/// <summary>
/// Gets the current indent we use when adding lines to the output
/// </summary>
public string CurrentIndent
{
get
{
return this.currentIndentField;
}
}
/// <summary>
/// Current transformation session
/// </summary>
public virtual global::System.Collections.Generic.IDictionary<string, object> Session
{
get
{
return this.sessionField;
}
set
{
this.sessionField = value;
}
}
#endregion
#region Transform-time helpers
/// <summary>
/// Write text directly into the generated output
/// </summary>
public void Write(string textToAppend)
{
if (string.IsNullOrEmpty(textToAppend))
{
return;
}
// If we're starting off, or if the previous text ended with a newline,
// we have to append the current indent first.
if (((this.GenerationEnvironment.Length == 0)
|| this.endsWithNewline))
{
this.GenerationEnvironment.Append(this.currentIndentField);
this.endsWithNewline = false;
}
// Check if the current text ends with a newline
if (textToAppend.EndsWith(global::System.Environment.NewLine, global::System.StringComparison.CurrentCulture))
{
this.endsWithNewline = true;
}
// This is an optimization. If the current indent is "", then we don't have to do any
// of the more complex stuff further down.
if ((this.currentIndentField.Length == 0))
{
this.GenerationEnvironment.Append(textToAppend);
return;
}
// Everywhere there is a newline in the text, add an indent after it
textToAppend = textToAppend.Replace(global::System.Environment.NewLine, (global::System.Environment.NewLine + this.currentIndentField));
// If the text ends with a newline, then we should strip off the indent added at the very end
// because the appropriate indent will be added when the next time Write() is called
if (this.endsWithNewline)
{
this.GenerationEnvironment.Append(textToAppend, 0, (textToAppend.Length - this.currentIndentField.Length));
}
else
{
this.GenerationEnvironment.Append(textToAppend);
}
}
/// <summary>
/// Write text directly into the generated output
/// </summary>
public void WriteLine(string textToAppend)
{
this.Write(textToAppend);
this.GenerationEnvironment.AppendLine();
this.endsWithNewline = true;
}
/// <summary>
/// Write formatted text directly into the generated output
/// </summary>
public void Write(string format, params object[] args)
{
this.Write(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args));
}
/// <summary>
/// Write formatted text directly into the generated output
/// </summary>
public void WriteLine(string format, params object[] args)
{
this.WriteLine(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args));
}
/// <summary>
/// Raise an error
/// </summary>
public void Error(string message)
{
System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError();
error.ErrorText = message;
this.Errors.Add(error);
}
/// <summary>
You can’t perform that action at this time.
