3
3
using System . IO ;
4
4
using System . Linq ;
5
5
using BcfToolkit . Builder . Bcf30 ;
6
+ using BcfToolkit . Utils ;
6
7
7
8
namespace BcfToolkit . Converter . Bcf21 ;
8
9
@@ -20,10 +21,13 @@ public static Model.Bcf30.Bcf Convert(Model.Bcf21.Bcf from) {
20
21
var builder = new BcfBuilder ( ) ;
21
22
builder
22
23
. AddMarkups ( from . Markups . Select ( ConvertMarkup ) . ToList ( ) , true )
23
- . SetDocument ( UpdateDocumentInfo ( from . Markups
24
- . SelectMany ( m => m . Topic . DocumentReference )
25
- . Where ( r => ! r . IsExternal )
26
- . ToList ( ) ) ) ;
24
+ . SetDocument ( dI => dI
25
+ . AddDocuments ( from . Markups
26
+ . SelectMany ( m => m . Topic . DocumentReference )
27
+ . Where ( r => ! r . IsExternal )
28
+ . ToList ( )
29
+ . Select ( ConvertDocument )
30
+ . ToList ( ) ) ) ;
27
31
28
32
var project = from . Project ;
29
33
@@ -120,11 +124,15 @@ private static Model.Bcf30.DocumentReference ConvertDocumentReference(
120
124
Model . Bcf21 . TopicDocumentReference from ) {
121
125
var builder = new DocumentReferenceBuilder ( ) ;
122
126
127
+ var guid = from . Guid ??= Guid . NewGuid ( ) . ToString ( ) ;
123
128
builder
124
- . SetGuid ( from . Guid ??= Guid . NewGuid ( ) . ToString ( ) )
129
+ . SetGuid ( guid )
125
130
. SetUrl ( from . IsExternal ? from . ReferencedDocument : null )
126
- //TODO: generate guid based on guid and description
127
- . SetDocumentGuid ( Guid . NewGuid ( ) . ToString ( ) ) ;
131
+ // pattern for document guid
132
+ // {guid of the referenced document}{name of the referenced document}
133
+ . SetDocumentGuid ( ! from . IsExternal
134
+ ? GuidUtils . NewGuidByContent ( $ "{ guid } { from . ReferencedDocument } ")
135
+ : null ) ;
128
136
129
137
if ( from . Description != string . Empty ) {
130
138
builder . SetDescription ( from . Description ) ;
@@ -336,7 +344,7 @@ private static Model.Bcf30.Bitmap ConvertBitmap(
336
344
. Build ( ) ;
337
345
}
338
346
339
- private static Action < DocumentInfoBuilder > UpdateDocumentInfo (
347
+ private static Action < DocumentInfoBuilder > ConvertDocumentInfo (
340
348
List < Model . Bcf21 . TopicDocumentReference > docReferences ) {
341
349
return dI => dI
342
350
. AddDocuments ( docReferences . Select ( ConvertDocument ) . ToList ( ) ) ;
@@ -347,7 +355,10 @@ private static Model.Bcf30.Document ConvertDocument(
347
355
var builder = new DocumentBuilder ( ) ;
348
356
builder
349
357
. SetFileName ( Path . GetFileName ( docReference . ReferencedDocument ) )
350
- . SetGuid ( docReference . Guid )
358
+ // pattern for document guid
359
+ // {guid of the referenced document}{name of the referenced document}
360
+ . SetGuid ( GuidUtils . NewGuidByContent (
361
+ $ "{ docReference . Guid } { docReference . ReferencedDocument } ") )
351
362
. SetDocumentData ( docReference . DocumentData ) ;
352
363
353
364
if ( docReference . Description != string . Empty ) {
0 commit comments