-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHCStructuredStorageDoc.vb
More file actions
2179 lines (1710 loc) · 82.4 KB
/
HCStructuredStorageDoc.vb
File metadata and controls
2179 lines (1710 loc) · 82.4 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
' https://support.sw.siemens.com/en-US/knowledge-base/PL8758767
' https://community.sw.siemens.com/s/question/0D5Vb000006uL9iKAE/how-to-repair-corrupt-daft-drawing-file
Option Strict On
Imports System.IO
Imports System.Text
Imports System.Text.RegularExpressions
Imports System.Xml
'Imports Microsoft.PowerShell.Commands.Internal.Format
Imports OpenMcdf
Imports OpenMcdf.Extensions
Imports OpenMcdf.Extensions.OLEProperties
'Imports PanoramicData.NCalcExtensions
Public Class HCStructuredStorageDoc
Public Property FullName As String
Public Property OpenReadWrite As Boolean
Private Property PropSets As PropertySets
Private Property fs As FileStream
Private Property cf As CompoundFile
Private Property LinkNames As LinkFullNames
Private Property LinkManagementOrder As List(Of String)
Private Property PropertiesData As HCPropertiesData
Private Property MatTable As MaterialTable
Private Property DocType As String 'asm, dft, par, psm, mtl
Public Enum StatusSecurityMapping
ssmAvailable = 0
ssmInWork = 0
ssmInReview = 0
ssmReleased = 4
ssmBaselined = 4
ssmObsolete = 4
End Enum
Public Sub New(_FullName As String, Optional _OpenReadWrite As Boolean = True)
Me.FullName = _FullName
Me.OpenReadWrite = _OpenReadWrite
Try
If _OpenReadWrite Then
Me.fs = New FileStream(Me.FullName, FileMode.Open, FileAccess.ReadWrite)
Else
Me.fs = New FileStream(Me.FullName, FileMode.Open, FileAccess.Read)
End If
Catch ex As Exception
'Dim L As Integer = Me.FullName.Count
Throw New Exception(String.Format("Unable to open file. {0}", ex.Message))
End Try
Me.cf = Nothing
Try
Dim cfg As CFSConfiguration = CFSConfiguration.SectorRecycle Or CFSConfiguration.EraseFreeSectors
Me.cf = New CompoundFile(fs, CFSUpdateMode.Update, cfg)
Catch ex As Exception
If Me.fs IsNot Nothing Then Me.fs.Close()
Me.fs = Nothing
Throw New Exception(String.Format("Unable to open file. {0}", ex.Message))
End Try
Me.DocType = IO.Path.GetExtension(FullName).ToLower.Replace(".", "")
End Sub
Public Sub ReadProperties(_PropertiesData As HCPropertiesData)
Me.PropertiesData = _PropertiesData
Me.PropSets = New PropertySets(Me.cf, Me.FullName, Me.OpenReadWrite)
End Sub
Public Sub ReadLinks(_LinkManagementOrder As List(Of String))
Me.LinkManagementOrder = _LinkManagementOrder
Me.LinkNames = New LinkFullNames(cf, IsFOA(), Me.LinkManagementOrder, Me.FullName)
End Sub
Public Sub ReadMaterialTable()
Dim Extension As String = IO.Path.GetExtension(Me.FullName)
If Not Extension = ".mtl" Then
Throw New Exception(String.Format("'{0}' is not a material table file", IO.Path.GetFileName(Me.FullName)))
End If
Me.MatTable = New MaterialTable(Me.cf)
End Sub
Public Function IsFOA() As Boolean
If IO.Path.GetExtension(Me.FullName) = ".asm" Then
Return Me.cf.RootStorage.ContainsStorage("Master")
Else
Return False
End If
End Function
Public Function IsFOPMaster() As Boolean
Return Me.cf.RootStorage.ContainsStorage("FamilyOfParts")
End Function
Public Function IsMaterialTable(cf As CompoundFile) As Boolean
Return cf.RootStorage.ContainsStream("MaterialDataEx")
End Function
Public Sub Save()
If Me.PropSets IsNot Nothing Then
For Each PropSet In Me.PropSets.Items
' The Custom stream gets saved with DocumentSummaryInformation
If Not PropSet.Name.ToLower = "custom" Then
PropSet.Save()
End If
Next
End If
Me.cf.Commit()
End Sub
Public Sub Close()
If Me.cf IsNot Nothing Then Me.cf.Close()
Me.cf = Nothing
If Me.fs IsNot Nothing Then Me.fs.Close()
Me.fs = Nothing
End Sub
Public Function GetPropValue(PropSetName As String, PropNameEnglish As String) As Object
' Return Nothing if a value is not found
Dim Value As Object = Nothing
If Me.PropSets Is Nothing Then
Throw New Exception("Properties not initialized")
End If
PropNameEnglish = PropNameEnglish.ToLower
Value = ProcessSpecialProperty(PropSetName, PropNameEnglish)
If Value Is Nothing Then
Dim Prop As Prop = GetProp(PropSetName, PropNameEnglish)
If Prop IsNot Nothing Then
Value = Prop.Value
End If
End If
Return Value
End Function
Public Function GetPropTypeName(PropSetName As String, PropNameEnglish As String) As String
' Returns Nothing if the property is not found
Dim TypeName As String = Nothing
Dim VTType As VTPropertyType = Nothing
If Me.PropSets Is Nothing Then
Throw New Exception("Properties not initialized")
End If
PropNameEnglish = PropNameEnglish.ToLower
Dim Prop As Prop = GetProp(PropSetName, PropNameEnglish)
If Prop IsNot Nothing Then
VTType = Prop.VTType
Select Case VTType
Case = VTPropertyType.VT_BOOL
TypeName = "Boolean"
Case = VTPropertyType.VT_I4
TypeName = "Integer"
Case = VTPropertyType.VT_LPSTR, VTPropertyType.VT_LPWSTR
TypeName = "String"
Case = VTPropertyType.VT_FILETIME
TypeName = "Date"
Case = VTPropertyType.VT_R8
TypeName = "Double"
Case Else
Dim s = GetType(HCStructuredStorageDoc).FullName
MsgBox(String.Format("In {0}: Property type {1} not recognized", s, VTType.ToString))
End Select
End If
Return TypeName
End Function
Public Function SetPropValue(PropSetName As String, PropNameEnglish As String, Value As Object, AddProperty As Boolean) As Boolean
' Returns False if unsuccessful
Dim Success As Boolean = False
If Me.PropSets Is Nothing Then
Throw New Exception("Properties not initialized")
End If
PropNameEnglish = PropNameEnglish.ToLower
If ProcessSpecialProperty(PropSetName, PropNameEnglish) Is Nothing Then
Dim Prop = GetProp(PropSetName, PropNameEnglish)
If Prop IsNot Nothing Then
Success = Prop.SetValue(Value)
ElseIf AddProperty Then
Success = AddProp(PropSetName, PropNameEnglish, Value)
End If
End If
Return Success
End Function
Public Function AddProp(PropSetName As String, PropNameEnglish As String, Value As Object) As Boolean
Dim Success As Boolean = False
If Me.PropSets Is Nothing Then
Throw New Exception("Properties not initialized")
End If
Dim PropSet As PropertySet = Me.PropSets.GetItem(PropSetName)
PropNameEnglish = PropNameEnglish.ToLower
If PropSetName.ToLower = "custom" Then
Dim Prop = GetProp(PropSetName, PropNameEnglish)
If Prop Is Nothing Then
Success = PropSet.AddProp(PropNameEnglish, Value)
End If
End If
Return Success
End Function
Public Function DeleteProp(PropSetName As String, PropNameEnglish As String) As Boolean
Dim Success As Boolean = False
If Me.PropSets Is Nothing Then
Throw New Exception("Properties not initialized")
End If
Dim PropSet As PropertySet = Me.PropSets.GetItem(PropSetName)
PropNameEnglish = PropNameEnglish.ToLower
If PropSetName.ToLower = "custom" Then
Dim Prop = GetProp(PropSetName, PropNameEnglish)
If Prop IsNot Nothing Then
Success = PropSet.DeleteProp(PropNameEnglish)
End If
End If
Return Success
End Function
Public Function ExistsProp(PropSetName As String, PropNameEnglish As String) As Boolean
Dim Success As Boolean = False
If Me.PropSets Is Nothing Then
Throw New Exception("Properties not initialized")
End If
PropNameEnglish = PropNameEnglish.ToLower
If ProcessSpecialProperty(PropSetName, PropNameEnglish) Is Nothing Then
Dim Prop = GetProp(PropSetName, PropNameEnglish)
Success = Prop IsNot Nothing
Else
Success = True
End If
Return Success
End Function
Public Function GetStatus() As String
Dim Status As String = Nothing
Dim StatusConstant As SolidEdgeConstants.DocumentStatus
StatusConstant = CType(GetPropValue("System", "Status"), SolidEdgeConstants.DocumentStatus)
Select Case StatusConstant
Case SolidEdgeConstants.DocumentStatus.igStatusAvailable
Status = "Available"
Case SolidEdgeConstants.DocumentStatus.igStatusBaselined
Status = "Baselined"
Case SolidEdgeConstants.DocumentStatus.igStatusInReview
Status = "InReview"
Case SolidEdgeConstants.DocumentStatus.igStatusInWork
Status = "InWork"
Case SolidEdgeConstants.DocumentStatus.igStatusObsolete
Status = "Obsolete"
Case SolidEdgeConstants.DocumentStatus.igStatusReleased
Status = "Released"
End Select
Return Status
End Function
Public Function SetStatus(Status As String) As Boolean
Dim Success As Boolean
Dim CurrentStatus As String
Dim NewStatusConstant As SolidEdgeConstants.DocumentStatus
Dim NewSecurity As StatusSecurityMapping
CurrentStatus = GetStatus()
If Status.ToLower = CurrentStatus.ToLower Then
Success = True
Else
Select Case Status.ToLower
Case "Available".ToLower
NewStatusConstant = SolidEdgeConstants.DocumentStatus.igStatusAvailable
NewSecurity = StatusSecurityMapping.ssmAvailable
Case "Baselined".ToLower
NewStatusConstant = SolidEdgeConstants.DocumentStatus.igStatusBaselined
NewSecurity = StatusSecurityMapping.ssmBaselined
Case "InReview".ToLower
NewStatusConstant = SolidEdgeConstants.DocumentStatus.igStatusInReview
NewSecurity = StatusSecurityMapping.ssmInReview
Case "InWork".ToLower
NewStatusConstant = SolidEdgeConstants.DocumentStatus.igStatusInWork
NewSecurity = StatusSecurityMapping.ssmInWork
Case "Obsolete".ToLower
NewStatusConstant = SolidEdgeConstants.DocumentStatus.igStatusObsolete
NewSecurity = StatusSecurityMapping.ssmObsolete
Case "Released".ToLower
NewStatusConstant = SolidEdgeConstants.DocumentStatus.igStatusReleased
NewSecurity = StatusSecurityMapping.ssmReleased
End Select
Success = SetPropValue("System", "Doc_Security", NewSecurity, AddProperty:=False)
Success = Success And SetPropValue("System", "Status", NewStatusConstant, AddProperty:=False)
End If
Return Success
End Function
Public Function GetPropNames() As List(Of String)
Dim PropNames As New List(Of String)
For Each _PropSet As PropertySet In Me.PropSets.Items
If Not _PropSet.Name = "Custom" Then
For Each _Prop As Prop In _PropSet.Items
If Not PropNames.Contains(_Prop.Name) Then PropNames.Add(String.Format("{0}, {1}, {2}", _PropSet.Name, CStr(_Prop.PropertyIdentifier), _Prop.Name))
Next
End If
Next
Return PropNames
End Function
Public Function SubstitutePropertyFormulas(
InString As String,
ErrorLogger As Logger,
Optional IsExpression As Boolean = False
) As String
' Replaces property formulas in a string.
' Returns Nothing if an error occurs
' Examples
' "Material: %{System.Material}, Engineer: %{Custom.Engineer}" --> "Material: STEEL, Engineer: FRED"
' "%{System.Titulo}" --> "Ciao Pizza!"
' "%{Custom.Engineer|R1}" --> "Fred" (From index reference 1)
' "%{Server.Query|R3}" --> "Some response from server" (From server query 3)
If Me.PropSets Is Nothing Then
Throw New Exception("Properties not initialized")
End If
Dim OutString As String = Nothing
Dim UC As New UtilsCommon
Dim Proceed As Boolean = True
Dim DocValues As New List(Of String)
Dim DocValue As String
Dim Formulas As New List(Of String)
Dim Formula As String
Dim Matches As MatchCollection
Dim MatchString As Match
Dim Pattern As String
Dim ExpressionLanguage As String = ""
If IsExpression And InString.StartsWith("EXPRESSION_") Then
Dim TextToRemove As String = InString.Split(CChar(vbCrLf))(0) ' EXPRESSION_VB, EXPRESSION_SQL
Select Case TextToRemove
Case "EXPRESSION_VB"
ExpressionLanguage = "VB"
Case "EXPRESSION_NCalc"
ExpressionLanguage = "NCalc"
Case Else
ErrorLogger.AddMessage($"SubstitutePropertyFormulas: Expression header not recognized '{TextToRemove}'")
'MsgBox($"SubstitutePropertyFormulas: Expression header not recognized '{TextToRemove}'")
Return Nothing
End Select
InString = InString.Replace($"{TextToRemove}{vbCrLf}", "")
End If
' Any number of substrings that start with "%{" and end with the first encountered "}".
Pattern = "%{[^}]*}"
Matches = Regex.Matches(InString, Pattern)
If Matches.Count = 0 Then
OutString = InString
Proceed = False
Else
For Each MatchString In Matches
Formulas.Add(MatchString.Value)
Next
End If
If Proceed Then
For Each Formula In Formulas
DocValue = ProcessFormula(Formula, ErrorLogger)
If DocValue Is Nothing Then
ErrorLogger.AddMessage($"Could not process formula '{Formula}'")
Return Nothing
Else
DocValues.Add(DocValue)
End If
Next
End If
If Proceed Then
OutString = InString
For i = 0 To DocValues.Count - 1
OutString = OutString.Replace(Formulas(i), DocValues(i))
Next
End If
'If Proceed Then
' If IsExpression Then
' If ExpressionLanguage = "" Or ExpressionLanguage = "NCalc" Then
' Dim nCalcExpression As New ExtendedExpression(OutString)
' Try
' Dim A = nCalcExpression.Evaluate()
' OutString = A.ToString
' Catch ex As Exception
' ErrorLogger.AddMessage($"Could not process expression '{OutString}'")
' OutString = Nothing
' End Try
' Else ' Must be VB
' Dim UPS As New UtilsPowerShell
' Dim PowerShellFileContents As List(Of String) = UPS.BuildExpressionFile(OutString.Split(CChar(vbCrLf)).ToList)
' Dim PowerShellFilename As String = $"{IO.Path.GetTempPath}\HousekeeperExpression.ps1"
' IO.File.WriteAllLines(PowerShellFilename, PowerShellFileContents)
' Try
' OutString = UPS.RunExpressionScript(PowerShellFilename)
' Catch ex As Exception
' ErrorLogger.AddMessage($"Could not process expression '{OutString}'")
' OutString = Nothing
' End Try
' End If
' End If
'End If
Return OutString
End Function
Public Function GetAllProps() As List(Of Tuple(Of String, String, String, Object))
' Returns a list of tuples. Each tuple contains these values.
' (
' PropertySetActualName as String,
' PropertyNameEnglish as String,
' PropertyTypeName as String,
' PropertyValue as Object
' )
Dim PropTuples As New List(Of Tuple(Of String, String, String, Object))
Dim PropTuple As Tuple(Of String, String, String, Object)
Dim TypeName As String = Nothing
For Each _PropSet As PropertySet In Me.PropSets.Items
For Each _Prop As Prop In _PropSet.Items
Select Case _Prop.VTType
Case = VTPropertyType.VT_BOOL
TypeName = "boolean"
Case = VTPropertyType.VT_I4
TypeName = "int32"
Case = VTPropertyType.VT_LPSTR, VTPropertyType.VT_LPWSTR
TypeName = "string"
Case = VTPropertyType.VT_FILETIME
TypeName = "datetime"
Case = VTPropertyType.VT_R8
TypeName = "double"
End Select
PropTuple = Tuple.Create(_PropSet.Name, _Prop.Name, TypeName, _Prop.Value)
PropTuples.Add(PropTuple)
Next
Next
Return PropTuples
End Function
Private Function ProcessFormula(Formula As String, ErrorLogger As Logger) As String
Dim DocValue As String = Nothing
Dim UC As New UtilsCommon
Dim UFC As New UtilsFilenameCharmap
Dim PropertySetName As String
Dim PropertyName As String
Dim PropertyNameEnglish As String = Nothing
Dim ModelIdx As Integer
Dim LinkName As String
PropertySetName = UC.PropSetFromFormula(Formula)
PropertyName = UC.PropNameFromFormula(Formula)
ModelIdx = UC.ModelIdxFromFormula(Formula)
If Not ((PropertySetName = "System") Or (PropertySetName = "Custom") Or (PropertySetName = "Server")) Then
ErrorLogger.AddMessage($"PropertySet not recognized '{PropertySetName}'")
Return Nothing
End If
'If (PropertySetName = "Server") And (PropertyName = "Query") Then
' 'Return Form_Main.ExecuteQuery(FullName, Form_Main.ServerQuery, ModelIdx).Replace(vbCrLf, " ")
' Dim tmpServerQuery = SubstitutePropertyFormulas(Form_Main.ServerQuery, ErrorLogger)
' Return Form_Main.ExecuteQuery(FullName, tmpServerQuery, ModelIdx).Replace(vbCrLf, " ")
'End If
Dim tmpPropertyData As PropertyData = Me.PropertiesData.GetPropertyData(PropertyName)
If tmpPropertyData IsNot Nothing Then
PropertyNameEnglish = tmpPropertyData.EnglishName
Else
ErrorLogger.AddMessage($"Property not recognized '{PropertyName}'")
Return Nothing
End If
If Not IsNothing(PropertyNameEnglish) Then
If ModelIdx = 0 Then
DocValue = CStr(GetPropValue(PropertySetName, PropertyNameEnglish))
If DocValue Is Nothing Then
ErrorLogger.AddMessage($"No value found for '{PropertySetName}.{PropertyNameEnglish}'")
Return Nothing
Else
'If ValidFilenameRequired Then
' DocValue = UFC.SubstituteIllegalCharacters(DocValue, New List(Of String))
'End If
End If
Else
If Me.LinkNames Is Nothing Then
Throw New Exception("LinkNames not initialized")
End If
If ModelIdx > Me.LinkNames.Items.Count - 1 Then
Return Nothing
End If
LinkName = Me.LinkNames.Items(ModelIdx - 1)
Dim SSDoc As HCStructuredStorageDoc = Nothing
Try
SSDoc = New HCStructuredStorageDoc(LinkName)
SSDoc.ReadProperties(Me.PropertiesData)
Catch ex As Exception
If SSDoc IsNot Nothing Then SSDoc.Close()
Return Nothing
End Try
DocValue = CStr(SSDoc.GetPropValue(PropertySetName, PropertyNameEnglish))
If DocValue Is Nothing Then
SSDoc.Close()
Return Nothing
Else
'If ValidFilenameRequired Then
' DocValue = UFC.SubstituteIllegalCharacters(DocValue, New List(Of String))
'End If
End If
SSDoc.Close()
End If
Else
' Changing back to returning Nothing.
' This routine is called by SubstitutePropertyFormulas, which is used in many places.
' They all already have ways of handling return values of Nothing.
'DocValue = "*** PROPERTY NOT FOUND ***" '<-------- IS THIS ACCETTABLE ?
End If
Return DocValue
End Function
Private Function GetProp(
PropSetName As String,
PropNameEnglish As String,
Optional ByRef PropSets As PropertySets = Nothing,
Optional ByRef PropSet As PropertySet = Nothing
) As Prop
If Me.PropSets Is Nothing Then
Return Nothing
End If
PropNameEnglish = PropNameEnglish.ToLower
Dim Prop As Prop = Nothing
If (PropSetName.ToLower = "system") Or (PropSetName.ToLower = "duplicate") Then
' Need to search for it
For Each PropSet In Me.PropSets.Items
If Not PropSet.Name.ToLower = "custom" Then
For Each P As Prop In PropSet.Items
If P.Name = PropNameEnglish Then
Prop = P
Exit For
End If
Next
If Prop IsNot Nothing Then
Exit For
End If
End If
Next
Else
PropSet = Me.PropSets.GetItem(PropSetName)
If PropSet IsNot Nothing Then
Prop = PropSet.GetItem(PropNameEnglish)
End If
End If
Return Prop
End Function
Private Function ProcessSpecialProperty(PropSetName As String, PropNameEnglish As String) As String
' Returns Nothing if not a special property
' Special properties:
' "System.File Name (full path)" ' C:\project\part.par -> C:\project\part.par
' "System.File Name" ' C:\project\part.par -> part.par
' "System.File Name (no extension)" ' C:\project\part.par -> part
PropNameEnglish = PropNameEnglish.ToLower
Dim SpecialProperty As String = Nothing
If PropSetName.ToLower = "system" Then
If PropNameEnglish = "File Name".ToLower Then
SpecialProperty = System.IO.Path.GetFileName(Me.FullName)
ElseIf PropNameEnglish = "File Name (full path)".ToLower Then
SpecialProperty = Me.FullName
ElseIf PropNameEnglish = "File Name (no extension)".ToLower Then
SpecialProperty = System.IO.Path.GetFileNameWithoutExtension(Me.FullName)
End If
End If
Return SpecialProperty
End Function
Private Sub OutputPropList()
' Utility if needed for testing. Not used in production.
Dim Outfile As String = ".\ole_props.csv"
Dim OutList As New List(Of String)
If IO.File.Exists(Outfile) Then
Try
OutList = IO.File.ReadAllLines(Outfile).ToList
Catch ex As Exception
MsgBox("Error reading Outfile")
End Try
End If
OutList = Me.PropSets.PrepOutput(OutList, Me.FullName)
Try
IO.File.WriteAllLines(Outfile, OutList)
Catch ex As Exception
MsgBox("Error saving Outfile")
End Try
End Sub
Public Function IsFileEmpty() As Boolean
Dim IsEmpty As Boolean
Select Case Me.DocType
Case "par", "psm"
Dim ParasolidStorage As CFStorage = Me.cf.RootStorage.GetStorage("PARASOLID")
Dim StreamList As New List(Of CFStream)
ParasolidStorage.VisitEntries(Sub(item) If item.IsStream Then StreamList.Add(CType(item, CFStream)), recursive:=False)
IsEmpty = StreamList.Count = 0
Case "asm", "dft"
If Me.LinkNames IsNot Nothing Then
IsEmpty = (Me.LinkNames.Items.Count = 0) And (Me.LinkNames.BadLinks.Count = 0)
Else
Dim tmpLinkManagmentOrder As List(Of String) = {"CONTAINER", "RELATIVE", "ABSOLUTE"}.ToList
Dim tmpLinkNames = New LinkFullNames(Me.cf, IsFOA(), tmpLinkManagmentOrder, Me.FullName)
IsEmpty = (tmpLinkNames.Items.Count = 0) And (tmpLinkNames.BadLinks.Count = 0)
End If
End Select
Return IsEmpty
End Function
Public Function GetLinkNames() As List(Of String)
If Me.LinkNames Is Nothing Then
Throw New Exception("Links not initialized")
End If
Return Me.LinkNames.Items
End Function
Public Function GetBadLinkNames() As List(Of String)
If Me.LinkNames Is Nothing Then
Throw New Exception("Links not initialized")
End If
Return Me.LinkNames.BadLinks
End Function
Public Function MaterialInTable(Name As String) As Boolean
If Me.MatTable Is Nothing Then
Throw New Exception("Material table is not initialized")
End If
Return MatTable.GetMaterial(Name) IsNot Nothing
End Function
Public Function MaterialUpToDate(SSDoc As HCStructuredStorageDoc) As Boolean
If Me.MatTable Is Nothing Then
Throw New Exception("Material table is not initialized")
End If
Return Me.MatTable.MaterialUpToDate(SSDoc)
End Function
Public Function UpdateMaterial(SSDoc As HCStructuredStorageDoc) As Boolean
If Me.MatTable Is Nothing Then
Throw New Exception("Material table is not initialized")
End If
Return Me.MatTable.UpdateMaterial(SSDoc)
End Function
Private Class PropertySets
Public Property Items As List(Of PropertySet)
Public Property OpenReadWrite As Boolean
Private Property cf As CompoundFile
Private Property FullName As String
Private Property PropertySetNames As List(Of String)
Public Sub New(
_cf As CompoundFile,
_FullName As String,
_OpenReadWrite As Boolean)
Me.cf = _cf
Me.FullName = _FullName
Me.OpenReadWrite = _OpenReadWrite
Me.Items = New List(Of PropertySet)
Me.PropertySetNames = New List(Of String)
Dim tmpPropertySetNames As New List(Of String)
tmpPropertySetNames.AddRange({"SummaryInformation", "DocumentSummaryInformation", "ExtendedSummaryInformation"})
tmpPropertySetNames.AddRange({"ProjectInformation", "MechanicalModeling", "Custom"})
Dim cs As CFStream = Nothing
Dim co As OLEPropertiesContainer = Nothing
For Each PropertySetName As String In tmpPropertySetNames
If Not PropertySetName = "Custom" Then
'Not all files have every PropertySet
'Properties of some very old files appear to be organized differently
Try
Me.Items.Add(New PropertySet(Me.cf, PropertySetName, Me.OpenReadWrite))
Me.PropertySetNames.Add(PropertySetName)
Catch ex As Exception
End Try
If (PropertySetName = "DocumentSummaryInformation") And (PropertySetNames.Contains(PropertySetName)) Then
cs = GetItem("DocumentSummaryInformation").cs
co = GetItem("DocumentSummaryInformation").co
End If
Else
' The Custom PropertySet needs the same cs and co as DocumentSummaryInformation, not copies.
'If (cs IsNot Nothing) And (cs IsNot Nothing) Then
If (cs IsNot Nothing) And (co IsNot Nothing) Then
Me.Items.Add(New PropertySet(Me.cf, PropertySetName, Me.OpenReadWrite, cs, co))
PropertySetNames.Add(PropertySetName)
End If
End If
Next
End Sub
Public Function PrepOutput(InList As List(Of String), FullName As String) As List(Of String)
Dim OutList As New List(Of String)
Dim tmpList As List(Of String)
Dim s As String
OutList.AddRange(InList)
For Each PS As PropertySet In Me.Items
tmpList = PS.PrepOutput()
For Each s In tmpList
If Not OutList.Contains(s) Then
OutList.Add(s)
If (Not s.Contains("Custom")) And (OutList.Count > 100) Then
OutList.Add(FullName)
End If
End If
Next
Next
Return OutList
End Function
Public Function GetItem(PropertySetName As String) As PropertySet
Dim idx As Integer = PropertySetNames.IndexOf(PropertySetName)
If idx = -1 Then
Return Nothing
Else
Return Items(idx)
End If
End Function
End Class
Private Class PropertySet
Public Property Items As New List(Of Prop)
Public Property Name As String
Public Property OpenReadWrite As Boolean
Private Property cf As CompoundFile
Public Property cs As CFStream
Public Property co As OLEPropertiesContainer
Private Property PropNames As New List(Of String)
Private Property PropertySetNameToStreamName As New Dictionary(Of String, String)
Public Sub New(
_cf As CompoundFile,
PropertySetName As String,
_OpenReadWrite As Boolean,
Optional _cs As CFStream = Nothing,
Optional _co As OLEPropertiesContainer = Nothing)
Me.cf = _cf
Me.Name = PropertySetName
Me.OpenReadWrite = _OpenReadWrite
Me.PropertySetNameToStreamName("SummaryInformation") = "SummaryInformation"
Me.PropertySetNameToStreamName("DocumentSummaryInformation") = "DocumentSummaryInformation"
Me.PropertySetNameToStreamName("ProjectInformation") = "Rfunnyd1AvtdbfkuIaamtae3Ie"
Me.PropertySetNameToStreamName("ExtendedSummaryInformation") = "C3teagxwOttdbfkuIaamtae3Ie"
Me.PropertySetNameToStreamName("MechanicalModeling") = "K4teagxwOttdbfkuIaamtae3Ie"
Me.PropertySetNameToStreamName("Custom") = "DocumentSummaryInformation"
Dim StreamName As String = Me.PropertySetNameToStreamName(PropertySetName)
If Not Me.Name.ToLower = "custom" Then
If Me.cf.RootStorage.ContainsStorage("Master") Then
Me.cs = Me.cf.RootStorage.GetStorage("Master").GetStream(StreamName)
Else
Me.cs = Me.cf.RootStorage.GetStream(StreamName)
End If
Me.co = Me.cs.AsOLEPropertiesContainer
Else
Me.cs = _cs
Me.co = _co
End If
Dim CorrectedName As String
If PropertySetName.ToLower = "custom" Then
If co.HasUserDefinedProperties Then
For Each OLEProp As OLEProperty In co.UserDefinedProperties.Properties
CorrectedName = CorrectedOLEPropName(PropertySetName, OLEProp)
Me.PropNames.Add(CorrectedName)
Me.Items.Add(New Prop(co, OLEProp, CorrectedName, OpenReadWrite))
Next
End If
Else
For Each OLEProp As OLEProperty In co.Properties
CorrectedName = CorrectedOLEPropName(PropertySetName, OLEProp)
Me.PropNames.Add(CorrectedName)
Me.Items.Add(New Prop(co, OLEProp, CorrectedName, OpenReadWrite))
Next
End If
End Sub
Private Function CorrectedOLEPropName(PropertySetName As String, OLEProp As OLEProperty) As String
Dim CorrectedName As String = ""
Select Case PropertySetName
Case "SummaryInformation"
Select Case OLEProp.PropertyIdentifier
Case 8
CorrectedName = "Last Author"
Case 12
CorrectedName = "Origination Date"
Case 13
CorrectedName = "Last Save Date"
Case 19
CorrectedName = "Security"
Case Else
CorrectedName = OLEProp.PropertyName.Replace("PIDSI_", "")
End Select
Case "DocumentSummaryInformation"
CorrectedName = OLEProp.PropertyName.Replace("PIDDSI_", "")
Case "ExtendedSummaryInformation"
Select Case OLEProp.PropertyIdentifier
' These properties have names like '0x00000019' in Structured Storage
Case 19
CorrectedName = "StatusChangeDate"
Case 20
CorrectedName = "FriendlyUserName"
Case 22
CorrectedName = "User Profile Name (created by)"
Case 23
CorrectedName = "User Profile Initials (created by)"
Case 24
CorrectedName = "User Profile Mailing address (created by)"
Case 25
CorrectedName = "User Profile Name (modified by)"
Case 26
CorrectedName = "User Profile Initials (modified by)"
Case 27
CorrectedName = "User Profile Mailing address (modified by)"
Case Else
CorrectedName = OLEProp.PropertyName
End Select
Case "MechanicalModeling"
Select Case OLEProp.PropertyIdentifier
Case 3
CorrectedName = "Material"
Case 8
CorrectedName = "TubeBendRadius"
Case 9
CorrectedName = "TubeOuterDiameter"
Case 10
CorrectedName = "TubeMinimumFlatLength"
Case 11
CorrectedName = "TubeWallThickness"
Case 12
CorrectedName = "TubeFlatLength"
Case 13
CorrectedName = "TubeAreaInsideDiameter"
Case 14
CorrectedName = "TubeVolumeInsideDiameter"
Case 15
CorrectedName = "TubeEndTreatmentTypeEnd1"
Case 16
CorrectedName = "TubeEndTreatmentTypeEnd2"
Case 19
CorrectedName = "Sheet Metal Gage"
Case 20
CorrectedName = "Face Style"
Case 21
CorrectedName = "Fill Style"