-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathOverridesLing_Lex.cs
More file actions
10152 lines (9434 loc) · 343 KB
/
OverridesLing_Lex.cs
File metadata and controls
10152 lines (9434 loc) · 343 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
// Copyright (c) 2002-2018 SIL International
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)
//
// <remarks>
// This file holds the overrides of the generated classes for the Ling module.
// </remarks>
using SIL.LCModel.Application;
using SIL.LCModel.Core.Cellar;
using SIL.LCModel.Core.KernelInterfaces;
using SIL.LCModel.Core.Phonology;
using SIL.LCModel.Core.Text;
using SIL.LCModel.Core.WritingSystems;
using SIL.LCModel.DomainServices;
using SIL.LCModel.Infrastructure;
using SIL.LCModel.Infrastructure.Impl;
using SIL.LCModel.Utils;
using SIL.ObjectModel;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
namespace SIL.LCModel.DomainImpl
{
internal partial class LexDb
{
/// ------------------------------------------------------------------------------------
/// <summary>
/// Gets the Entries
/// </summary>
/// ------------------------------------------------------------------------------------
[VirtualProperty(CellarPropertyType.ReferenceSequence, "LexEntry")]
public IEnumerable<ILexEntry> Entries
{
get { return Services.GetInstance<ILexEntryRepository>().AllInstances(); }
}
/// <summary>
/// Gets all the bulk-editable things that might be used as the destination of a bulk edit to
/// example sentence properties. This includes the senses that do not have examples.
/// Note that this implementation is only possible because there are no other possible owners for LexExampleSentence.
/// </summary>
[VirtualProperty(CellarPropertyType.ReferenceSequence, "CmObject")]
public IEnumerable<ICmObject> AllExampleSentenceTargets
{
get
{
// Optimize JohnT: are we likely to modify any of the iterators while iterating? If not
// we may not need the ToList().
return Cache.ServiceLocator.GetInstance<ILexExampleSentenceRepository>().AllInstances().Cast<ICmObject>()
.Concat((from sense in Cache.ServiceLocator.GetInstance<ILexSenseRepository>().AllInstances()
where sense.ExamplesOS.Count == 0
select sense).Cast<ICmObject>())
.ToList();
}
}
/// <summary>
/// Gets all the bulk-editable things that might be used as the destination of a bulk edit to
/// example translation properties. This includes the examples that do not have translations.
/// </summary>
[VirtualProperty(CellarPropertyType.ReferenceSequence, "CmObject")]
public IEnumerable<ICmObject> AllExampleTranslationTargets
{
get
{
var examples = Cache.ServiceLocator.GetInstance<ILexExampleSentenceRepository>().AllInstances().ToList();
// Optimize JohnT: are we likely to modify any of the iterators while iterating? If not
// we may not need the ToList().
return (from ex in examples from trans in ex.TranslationsOC select trans).Cast<ICmObject>()
.Concat((from ex in examples
where ex.TranslationsOC.Count == 0
select ex).Cast<ICmObject>())
.ToList();
}
}
/// <summary>
/// Gets all the bulk-editable things that might be used as the destination of a bulk edit to
/// LexEntryRef properties for complex forms. This includes the entries that do not have any
/// EntryRefs with the right type.
/// Note that this implementation only works because LexEntryRef has no other possible owners.
/// </summary>
[VirtualProperty(CellarPropertyType.ReferenceSequence, "CmObject")]
public IEnumerable<ICmObject> AllComplexEntryRefPropertyTargets
{
get
{
// Optimize JohnT: are we likely to modify any of the iterators while iterating? If not
// we may not need the ToList().
return Cache.ServiceLocator.GetInstance<ILexEntryRefRepository>().AllInstances()
.Where(ler => ler.RefType == LexEntryRefTags.krtComplexForm).Cast<ICmObject>()
.Concat((from entry in Cache.ServiceLocator.GetInstance<ILexEntryRepository>().AllInstances()
where entry.EntryRefsOS.Where(ler => ler.RefType == LexEntryRefTags.krtComplexForm).Count() == 0
select entry).Cast<ICmObject>())
.ToList();
}
}
/// <summary>
/// Gets all the bulk-editable things that might be used as the destination of a bulk edit to
/// LexEntryRef properties for variants. This includes the entries that do not have any
/// EntryRefs with the right type.
/// Note that this implementation only works because LexEntryRef has no other possible owners.
/// </summary>
[VirtualProperty(CellarPropertyType.ReferenceSequence, "CmObject")]
public IEnumerable<ICmObject> AllVariantEntryRefPropertyTargets
{
get
{
// Optimize JohnT: are we likely to modify any of the iterators while iterating? If not
// we may not need the ToList().
return Cache.ServiceLocator.GetInstance<ILexEntryRefRepository>().AllInstances()
.Where(ler => ler.RefType == LexEntryRefTags.krtVariant).Cast<ICmObject>()
.Concat((from entry in Cache.ServiceLocator.GetInstance<ILexEntryRepository>().AllInstances()
where entry.EntryRefsOS.Where(ler => ler.RefType == LexEntryRefTags.krtVariant).Count() == 0
select entry).Cast<ICmObject>())
.ToList();
}
}
/// <summary>
/// Gets all the bulk-editable things that might be used as the destination of a bulk edit to
/// pronunciation. This includes the entries that do not have pronunciations.
/// Note that this implementation is only possible because there are no other possible owners for LexPronunciation.
/// </summary>
[VirtualProperty(CellarPropertyType.ReferenceSequence, "CmObject")]
public IEnumerable<ICmObject> AllPossiblePronunciations
{
get
{
// Optimize JohnT: are we likely to modify any of the iterators while iterating? If not
// we may not need the ToList().
return Cache.ServiceLocator.GetInstance<ILexPronunciationRepository>().AllInstances().Cast<ICmObject>()
.Concat((from entry in Cache.ServiceLocator.GetInstance<ILexEntryRepository>().AllInstances()
where entry.PronunciationsOS.Count == 0
select entry).Cast<ICmObject>())
.ToList();
}
}
/// <summary>
/// Gets all the bulk-editable things that might be used as the destination of a bulk edit to
/// etymology. This includes the entries that do not have etymologies.
/// Note that this implementation is only possible because there are no other possible owners for LexEtymology.
/// </summary>
[VirtualProperty(CellarPropertyType.ReferenceSequence, "CmObject")]
public IEnumerable<ICmObject> AllPossibleEtymologies
{
get
{
// Optimize JohnT: are we likely to modify any of the iterators while iterating? If not
// we may not need the ToList().
return Cache.ServiceLocator.GetInstance<ILexEtymologyRepository>().AllInstances().Cast<ICmObject>()
.Concat((from entry in Cache.ServiceLocator.GetInstance<ILexEntryRepository>().AllInstances()
where entry.EtymologyOS.Count == 0
select entry).Cast<ICmObject>())
.ToList();
}
}
/// <summary>
/// Gets all the bulk-editable things that might be used as the destination of a bulk edit to
/// extended note. This includes the senses that do not have extended notes.
/// Note that this implementation is only possible because there are no other possible owners for LexExtendedNote.
/// </summary>
[VirtualProperty(CellarPropertyType.ReferenceSequence, "CmObject")]
public IEnumerable<ICmObject> AllExtendedNoteTargets
{
get
{
return Cache.ServiceLocator.GetInstance<ILexExtendedNoteRepository>().AllInstances().Cast<ICmObject>()
.Concat((from sense in Cache.ServiceLocator.GetInstance<ILexSenseRepository>().AllInstances()
where sense.ExtendedNoteOS.Count == 0
select sense))
.ToList();
}
}
/// <summary>
/// Gets all the bulk-editable things that might be used as the destination of a bulk edit to
/// pictures. This includes the senses that do not have extended notes.
/// Note that this implementation is only possible because there are no other possible owners for LexExtendedNote.
/// </summary>
[VirtualProperty(CellarPropertyType.ReferenceSequence, "CmObject")]
public IEnumerable<ICmObject> AllPossiblePictures
{
get
{
return Cache.ServiceLocator.GetInstance<ICmPictureRepository>().AllInstances().Cast<ICmObject>()
.Concat((from sense in Cache.ServiceLocator.GetInstance<ILexSenseRepository>().AllInstances()
where sense.PicturesOS.Count == 0
select sense))
.ToList();
}
}
/// <summary>
/// Gets all the bulk-editable things that might be used as the destination of a bulk edit to
/// Allomorphs/MoForms. This includes MoForms that are the LexemeForm of some entry.
/// </summary>
[VirtualProperty(CellarPropertyType.ReferenceSequence, "CmObject")]
public IEnumerable<ICmObject> AllPossibleAllomorphs
{
get
{
var entries = Cache.ServiceLocator.GetInstance<ILexEntryRepository>().AllInstances().ToList();
// Optimize JohnT: are we likely to modify any of the iterators while iterating? If not
// we may not need the ToList().
return (from entry in entries from morph in entry.AlternateFormsOS select morph).Cast<ICmObject>()
.Concat((from entry in entries select entry.LexemeFormOA).Cast<ICmObject>())
.ToList();
}
}
/// <summary>
/// All the senses in existence. Sometimes convenient to have as a virtual property.
/// </summary>
[VirtualProperty(CellarPropertyType.ReferenceCollection, "LexSense")]
public IEnumerable<ILexSense> AllSenses
{
get
{
return m_cache.ServiceLocator.GetInstance<ILexSenseRepository>().AllInstances();
}
}
/// <summary>
/// All the Complex and Variant entries
/// </summary>
[VirtualProperty(CellarPropertyType.ReferenceCollection, "LexEntryRef")]
public IEnumerable<ILexEntryRef> AllEntryRefs
{
get
{
return m_cache.ServiceLocator.GetInstance<ILexEntryRefRepository>().AllInstances();
}
}
/// <summary>
/// Allows user to convert LexEntryType to LexEntryInflType.
/// </summary>
public void ConvertLexEntryInflTypes(IProgress progressBar, IEnumerable<ILexEntryType> list)
{
progressBar.Minimum = 0;
progressBar.Maximum = list.Count();
progressBar.StepSize = 1;
foreach (var lexEntryType in list)
{
var leitFactory = m_cache.ServiceLocator.GetInstance<ILexEntryInflTypeFactory>();
var leit = leitFactory.Create();
leit.ConvertLexEntryType(lexEntryType);
lexEntryType.Delete();
progressBar.Step(1);
}
}
/// <summary>
/// Allows user to convert LexEntryInflType to LexEntryType.
/// </summary>
public void ConvertLexEntryTypes(IProgress progressBar, IEnumerable<ILexEntryType> list)
{
progressBar.Minimum = 0;
progressBar.Maximum = list.Count();
progressBar.StepSize = 1;
foreach (var lexEntryInflType in list)
{
var leit = lexEntryInflType as ILexEntryInflType;
if (leit != null)
{
var letFactory = m_cache.ServiceLocator.GetInstance<ILexEntryTypeFactory>();
var lexEntryType = letFactory.Create();
lexEntryType.ConvertLexEntryType(leit);
leit.Delete();
}
progressBar.Step(1);
}
}
/// <summary>
/// Resets the homograph numbers for all entries but can take a null progress bar.
/// </summary>
public void ResetHomographNumbers(IProgress progressBar)
{
if (progressBar != null)
{
progressBar.Minimum = 0;
progressBar.Maximum = Entries.Count();
progressBar.StepSize = 1;
}
var processedEntryIds = new List<int>();
UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(Strings.ksUndoResetHomographs, Strings.ksRedoResetHomographs, Cache.ActionHandlerAccessor,
() =>
{
foreach (var le in Entries)
{
if (processedEntryIds.Contains(le.Hvo))
{
if (progressBar != null)
progressBar.Step(1);
continue;
}
var homographs = Services.GetInstance<ILexEntryRepository>().CollectHomographs(
le.HomographFormKey,
le.PrimaryMorphType);
if (le.HomographFormKey == Strings.ksQuestions)
{
homographs.ForEach(lex => lex.HomographNumber = 0);
le.HomographNumber = 0; // just to be sure if homographs is empty
}
else
CorrectHomographNumbers(homographs);
foreach (var homograph in homographs)
{
processedEntryIds.Add(homograph.Hvo);
if (progressBar != null)
progressBar.Step(1);
}
}
});
}
///// <summary>
///// Answer true if the input set of homographs is ordered correctly.
///// </summary>
//public static bool ValidateExistingHomographs(List<ILexEntry> rgHomographs)
//{
// if (rgHomographs.Count == 0)
// return true; // Nothing to check.
// if (rgHomographs.Count == 1)
// {
// return (rgHomographs[0].HomographNumber == 0); // exactly one in set, should be numbered zero.
// }
// // More than one, should be numbered 1..n.
// var sortedHomographs = rgHomographs.OrderBy(h => h.HomographNumber).ToList();
// for (int n = 0; n < sortedHomographs.Count; ++n)
// {
// if (sortedHomographs[n].HomographNumber != n + 1)
// return false;
// }
// return true;
//}
/// <summary>
/// Ensure that homograph numbers from 1 to N are set for these N homographs.
/// This is called on both Insert Entry and Delete Entry.
/// Caller should create unit of work.
/// </summary>
/// <returns>true if homographs were already valid, false if they had to be renumbered. (That is, we couldn't fix by just filing in.)
/// </returns>
public static bool CorrectHomographNumbers(List<ILexEntry> rgHomographs)
{
bool fOk = true;
if (rgHomographs.Count == 0)
return fOk; // Nothing to renumber.
if (rgHomographs.Count == 1)
{
// Handle case where it is being set to 0.
ILexEntry lexE = rgHomographs[0];
if (lexE.HomographNumber != 0)
{
lexE.HomographNumber = 0;
return true; // renumbered
}
return false; // no change
}
// For each possible homograph number, we first try to find an existing one that has that number.
// If so, we leave it alone.
// If not, and there's one without a number that can be given that number, we do so, filling in the gap
// without renumbering others.
// If we can't fill in all the gaps we renumber them all, and return false.
// (Note that if two have the same number, we will certainly not be able to find one for every number,
// so we will end up doing a total renumbering.)
for (int n = 1; n <= rgHomographs.Count; ++n)
{
fOk = false;
foreach (ILexEntry le in rgHomographs)
{
if (le.HomographNumber == n)
{
fOk = true;
break; // from inner loop, we found one numbered n
}
}
if (!fOk)
{
// See if one has a missing number. If so, fill it in with the
// next needed number.
foreach (ILexEntry le in rgHomographs)
{
if (le.HomographNumber == 0)
{
le.HomographNumber = n;
fOk = true;
}
}
}
if (!fOk)
break;
}
if (!fOk)
{
// Should we notify the user that we're doing this helpful renumbering for him?
// We do our best to keep them in the same order.
// Tie-break on DateCreated then Guid so the result is deterministic and reasonable.
int n = 1;
foreach (ILexEntry le in rgHomographs
.OrderBy(h => h.HomographNumber)
.ThenBy(h => h.DateCreated)
.ThenBy(h => h.Guid)
.ToList())
{
if (le.HomographNumber != n)
le.HomographNumber = n;
n++;
}
}
return fOk;
}
/// <summary>
/// Get a filtered list of reversal indices that correspond to the current writing systems being used.
/// </summary>
public List<IReversalIndex> CurrentReversalIndices
{
get
{
var indices = new List<IReversalIndex>();
foreach (var ri in ReversalIndexesOC)
{
if (!Cache.LanguageProject.CurrentAnalysisWritingSystems.Contains(Services.WritingSystemManager.Get(ri.WritingSystem))) continue;
indices.Add(ri);
}
return indices;
}
}
/// <summary>
/// used when dumping the lexical database for the automated Parser
/// </summary>
/// <remarks> Note that you may not find this method in source code,
/// since it will be used from XML template and accessed dynamically.</remarks>
[VirtualProperty(CellarPropertyType.ReferenceCollection, "MoForm")]
public IEnumerable<IMoForm> AllAllomorphs
{
get
{
//old system: "select id, class$ from MoForm_ order by class$";
IMoFormRepository repo = Services.GetInstance<IMoFormRepository>();
return
from IMoForm mf in repo.AllInstances()
orderby mf.ClassID
select mf;
}
}
/// <summary>
/// used when dumping the lexical database for the automated Parser
/// </summary>
/// <remarks> Note that you may not find this method in source code,
/// since it will be used from XML template and accessed dynamically.</remarks>
[VirtualProperty(CellarPropertyType.ReferenceCollection, "MoMorphSynAnalysis")]
public IEnumerable<IMoMorphSynAnalysis> AllMSAs
{
get
{
//old system: "select id, class$ from MoMorphSynAnalysis_ order by class$";
IMoMorphSynAnalysisRepository repo = Services.GetInstance<IMoMorphSynAnalysisRepository>();
return
from IMoMorphSynAnalysis msa in repo.AllInstances()
orderby msa.ClassID
select msa;
}
}
partial void ValidateIntroductionOA(ref IStText newObjValue)
{
if (newObjValue == null)
throw new InvalidOperationException("New value must not be null.");
}
}
/// <summary>
///
/// </summary>
internal partial class LexExampleSentence
{
protected override void AddObjectSideEffectsInternal(AddObjectEventArgs e)
{
if (e.Flid == LexExampleSentenceTags.kflidDoNotPublishIn)
{
var uowService = ((IServiceLocatorInternal)Services).UnitOfWorkService;
uowService.RegisterVirtualAsModified(this, "PublishIn", PublishIn.Cast<ICmObject>());
}
base.AddObjectSideEffectsInternal(e);
}
protected override void RemoveObjectSideEffectsInternal(RemoveObjectEventArgs e)
{
if (e.Flid == LexExampleSentenceTags.kflidDoNotPublishIn)
{
var uowService = ((IServiceLocatorInternal)Services).UnitOfWorkService;
uowService.RegisterVirtualAsModified(this, "PublishIn", PublishIn.Cast<ICmObject>());
}
base.RemoveObjectSideEffectsInternal(e);
}
public override ICmObject ReferenceTargetOwner(int flid)
{
if (flid == Cache.MetaDataCacheAccessor.GetFieldId2(LexExampleSentenceTags.kClassId, "PublishIn", false))
return Cache.LangProject.LexDbOA.PublicationTypesOA;
return base.ReferenceTargetOwner(flid);
}
/// <summary>
/// Object owner. This virtual may seem redundant with CmObject.Owner, but it is important,
/// because we can correctly indicate the destination class. This is used (at least) in
/// PartGenerator.GeneratePartsFromLayouts to determine that it needs to generate parts for LexSense.
/// </summary>
[VirtualProperty(CellarPropertyType.ReferenceAtomic, "LexSense")]
public ILexSense OwningSense
{
// If the Owner is not a ILexSense then try to return Owner.Owner (LT-21034).
get
{
if (Owner is ILexSense)
return Owner as ILexSense;
else if (Owner?.Owner is ILexSense)
return Owner.Owner as ILexSense;
else
return null;
}
}
/// <summary>
/// The publications from which this is not excluded, that is, the ones in which it
/// SHOULD be published.
/// </summary>
[VirtualProperty(CellarPropertyType.ReferenceCollection, "CmPossibility")]
public ILcmSet<ICmPossibility> PublishIn
{
get
{
return new LcmInvertSet<ICmPossibility>(DoNotPublishInRC, Cache.LangProject.LexDbOA.PublicationTypesOA.PossibilitiesOS);
}
}
/// <summary>
/// This is the string
/// which is displayed in the Delete Pronunciation dialog.
/// </summary>
public override ITsString DeletionTextTSS
{
get
{
var userWs = m_cache.WritingSystemFactory.UserWs;
var tisb = TsStringUtils.MakeIncStrBldr();
tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs);
tisb.Append(String.Format(Strings.ksDeleteLexExampleSentence));
return tisb.GetString();
}
}
/// <summary>
/// The LiftResidue field stores XML with an outer element <lift-residue> enclosing
/// the actual residue. This returns the actual residue, minus the outer element.
/// </summary>
public string LiftResidueContent
{
get
{
string sResidue = LiftResidue;
if (String.IsNullOrEmpty(sResidue))
return null;
if (sResidue.IndexOf("<lift-residue") != sResidue.LastIndexOf("<lift-residue"))
sResidue = RepairLiftResidue(sResidue);
return LexEntry.ExtractLiftResidueContent(sResidue);
}
}
private string RepairLiftResidue(string sResidue)
{
int idx = sResidue.IndexOf("</lift-residue>");
if (idx > 0)
{
// Remove the repeated occurrences of <lift-residue>...</lift-residue>.
// See LT-10302.
sResidue = sResidue.Substring(0, idx + 15);
NonUndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(m_cache.ActionHandlerAccessor,
() => { LiftResidue = sResidue; });
}
return sResidue;
}
/// <summary>
/// Get the dateCreated value stored in LiftResidue (if it exists).
/// </summary>
public string LiftDateCreated
{
get { return LexEntry.ExtractAttributeFromLiftResidue(LiftResidue, "dateCreated"); }
}
/// <summary>
/// Get the dateModified value stored in LiftResidue (if it exists).
/// </summary>
public string LiftDateModified
{
get { return LexEntry.ExtractAttributeFromLiftResidue(LiftResidue, "dateModified"); }
}
}
internal partial class LexExtendedNote
{
public override ICmObject ReferenceTargetOwner(int flid)
{
if (flid == Cache.MetaDataCacheAccessor.GetFieldId2(LexExtendedNoteTags.kClassId, "ExtendedNoteType", false))
return Cache.LangProject.LexDbOA.ExtendedNoteTypesOA;
return base.ReferenceTargetOwner(flid);
}
/// <summary>
/// Object owner. This virtual may seem redundant with CmObject.Owner, but it is important,
/// because we can correctly indicate the destination class. This is used (at least) in
/// PartGenerator.GeneratePartsFromLayouts to determine that it needs to generate parts for LexSense.
/// </summary>
[VirtualProperty(CellarPropertyType.ReferenceAtomic, "LexSense")]
public ILexSense OwningSense
{
get { return (ILexSense)Owner; }
}
}
/// <summary>
///
/// </summary>
internal partial class LexPronunciation
{
protected override void AddObjectSideEffectsInternal(AddObjectEventArgs e)
{
if (e.Flid == LexPronunciationTags.kflidDoNotPublishIn)
{
var uowService = ((IServiceLocatorInternal)Services).UnitOfWorkService;
uowService.RegisterVirtualAsModified(this, "PublishIn", PublishIn.Cast<ICmObject>());
}
base.AddObjectSideEffectsInternal(e);
}
protected override void RemoveObjectSideEffectsInternal(RemoveObjectEventArgs e)
{
if (e.Flid == LexPronunciationTags.kflidDoNotPublishIn)
{
var uowService = ((IServiceLocatorInternal)Services).UnitOfWorkService;
uowService.RegisterVirtualAsModified(this, "PublishIn", PublishIn.Cast<ICmObject>());
}
base.RemoveObjectSideEffectsInternal(e);
}
/// <summary>
/// Object owner. This virtual may seem redundant with CmObject.Owner, but it is important,
/// because we can correctly indicate the destination class. This is used (at least) in
/// PartGenerator.GeneratePartsFromLayouts to determine that it needs to generate parts for LexEntry.
/// </summary>
[VirtualProperty(CellarPropertyType.ReferenceAtomic, "LexEntry")]
public ILexEntry OwningEntry
{
get { return (ILexEntry)Owner; }
}
/// <summary>
/// The publications from which this is not excluded, that is, the ones in which it
/// SHOULD be published.
/// </summary>
[VirtualProperty(CellarPropertyType.ReferenceCollection, "CmPossibility")]
public ILcmSet<ICmPossibility> PublishIn
{
get
{
return new LcmInvertSet<ICmPossibility>(DoNotPublishInRC, Cache.LangProject.LexDbOA.PublicationTypesOA.PossibilitiesOS);
}
}
/// <summary>
/// This is the string
/// which is displayed in the Delete Pronunciation dialog.
/// </summary>
public override ITsString DeletionTextTSS
{
get
{
var userWs = m_cache.WritingSystemFactory.UserWs;
var tisb = TsStringUtils.MakeIncStrBldr();
tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs);
tisb.Append(String.Format(Strings.ksDeleteLexPronunciation));
return tisb.GetString();
}
}
/// <summary>
/// The LiftResidue field stores XML with an outer element <lift-residue> enclosing
/// the actual residue. This returns the actual residue, minus the outer element.
/// </summary>
public string LiftResidueContent
{
get
{
var sResidue = LiftResidue;
if (String.IsNullOrEmpty(sResidue))
return null;
if (sResidue.IndexOf("<lift-residue") != sResidue.LastIndexOf("<lift-residue"))
sResidue = RepairLiftResidue(sResidue);
return LexEntry.ExtractLiftResidueContent(sResidue);
}
}
private string RepairLiftResidue(string sResidue)
{
int idx = sResidue.IndexOf("</lift-residue>");
if (idx > 0)
{
// Remove the repeated occurrences of <lift-residue>...</lift-residue>.
// See LT-10302.
sResidue = sResidue.Substring(0, idx + 15);
NonUndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(m_cache.ActionHandlerAccessor,
() => { LiftResidue = sResidue; });
}
return sResidue;
}
/// <summary>
/// Get the dateCreated value stored in LiftResidue (if it exists).
/// </summary>
public string LiftDateCreated
{
get { return LexEntry.ExtractAttributeFromLiftResidue(LiftResidue, "dateCreated"); }
}
/// <summary>
/// Get the dateModified value stored in LiftResidue (if it exists).
/// </summary>
public string LiftDateModified
{
get { return LexEntry.ExtractAttributeFromLiftResidue(LiftResidue, "dateModified"); }
}
/// <summary>
/// Overridden to handle ref props of this class.
/// </summary>
public override ICmObject ReferenceTargetOwner(int flid)
{
if (flid == m_cache.MetaDataCacheAccessor.GetFieldId2(LexPronunciationTags.kClassId, "PublishIn", false))
return m_cache.LangProject.LexDbOA.PublicationTypesOA;
if (flid == LexPronunciationTags.kflidLocation)
return m_cache.LangProject.LocationsOA;
return base.ReferenceTargetOwner(flid);
}
}
/// <summary></summary>
internal partial class LexEntry
{
protected override void SetDefaultValuesAfterInit()
{
base.SetDefaultValuesAfterInit();
RegisterVirtualsModifiedForObjectCreation(((IServiceLocatorInternal)m_cache.ServiceLocator).UnitOfWorkService);
// For a new lexical entry, default to only publish in the Main Dictionary.
// Note: The Main Dictionary can be renamed, but not deleted, so look for the publication that can't be deleted.
var allCanNotDelete = this.PublishIn.ToList().FindAll(pub => pub.CanDelete == false);
if (allCanNotDelete.Count != 1)
{
throw new Exception("None, or more than one publication is blocked from being deleted. Expecting only the Main Dictionary to block deletion.");
}
else
{
var mainDictIndex = this.PublishIn.ToList().FindIndex(pub => pub.CanDelete == false);
var flid = Cache.MetaDataCacheAccessor.GetFieldId2(LexEntryTags.kClassId, "PublishIn", true);
// Remove the publications after Main Dictionary.
if (mainDictIndex < PublishIn.Count() - 1)
{
m_cache.DomainDataByFlid.Replace(this.Hvo, flid, mainDictIndex+1, PublishIn.Count(), new int[0], 0);
}
// Remove the publications before Main Dictionary (not sure if this condition can ever occure).
if (mainDictIndex > 0)
{
m_cache.DomainDataByFlid.Replace(this.Hvo, flid, 0, mainDictIndex, new int[0], 0);
}
}
}
public override ICmObject ReferenceTargetOwner(int flid)
{
if (flid == LexEntryTags.kflidDialectLabels)
return Cache.LangProject.LexDbOA.DialectLabelsOA;
if (flid == Cache.MetaDataCacheAccessor.GetFieldId2(LexEntryTags.kClassId, "PublishIn", false) ||
flid == Cache.MetaDataCacheAccessor.GetFieldId2(LexEntryTags.kClassId, "ShowMainEntryIn", false))
return Cache.LangProject.LexDbOA.PublicationTypesOA;
return base.ReferenceTargetOwner(flid);
}
/// <summary>
/// Answer true if the entry is, directly or indirectly, a component of this entry.
/// The intent is to use this in reporting that it would be incorrect to make this
/// a component of the specified entry.
/// Accordingly, as a special case, it answers true if the entry is the recipient,
/// even if it has no components.
/// </summary>
public bool IsComponent(ILexEntry entry)
{
return AllComponents.Contains(entry);
}
/// <summary>
/// Return all the entries which this may not be a component of since they
/// are or are related to components of this.
/// </summary>
IEnumerable<ILexEntry> AllComponents
{
get
{
yield return this;
foreach (var ler in EntryRefsOS)
{
if (ler.RefType != LexEntryRefTags.krtComplexForm && ler.RefType != LexEntryRefTags.krtVariant)
continue;
foreach (var obj in ler.ComponentLexemesRS)
{
if (obj is ILexEntry)
{
var entry = (LexEntry) obj;
yield return entry;
foreach (var le in entry.AllComponents)
yield return le;
}
else
yield return ((ILexSense) obj).Entry;
}
}
}
}
internal override void RegisterVirtualsModifiedForObjectCreation(IUnitOfWorkService uow)
{
base.RegisterVirtualsModifiedForObjectCreation(uow);
var cache = Cache; // need to make the Func use this local variable, because on Undo, Cache may return null.
uow.RegisterVirtualCollectionAsModified(Cache.LangProject.LexDbOA,
Cache.ServiceLocator.GetInstance<Virtuals>().LexDbEntries,
() => cache.ServiceLocator.GetInstance<ILexEntryRepository>().AllInstances(),
new[] { this }, new ILexEntry[0]);
}
/// <summary>
/// Make the other lexentry a component of this. This becomes a complex form if it is not already.
/// If it already has components other is added and primary lexemes is not affected.
/// If it has no components other is also put in primary lexemes.
/// If it the complex form is not (already known to be) a derivative, also add to ShowComplexFormIn.
/// If we need to make a new LexEntryRef it should by default not show as a minor entry.
/// </summary>
public void AddComponent(ICmObject other)
{
if (!(other is ILexEntry) && !(other is ILexSense))
throw new ArgumentException("components of a lex entry must be entries or senses", "other");
ILexEntryRef ler = (from item in EntryRefsOS where item.RefType == LexEntryRefTags.krtComplexForm select item).FirstOrDefault();
if (ler == null)
{
ler = Services.GetInstance<ILexEntryRefFactory>().Create();
EntryRefsOS.Add(ler);
ler.ComplexEntryTypesRS.Add(Cache.LangProject.LexDbOA.ComplexEntryTypesOA.PossibilitiesOS[0] as ILexEntryType);
ler.RefType = LexEntryRefTags.krtComplexForm;
ler.HideMinorEntry = 0; // LT-10928
ChangeRootToStem();
}
if (!ler.ComponentLexemesRS.Contains(other))
ler.ComponentLexemesRS.Add(other);
if (ler.PrimaryLexemesRS.Count == 0)
ler.PrimaryLexemesRS.Add(other);
if (!ler.ComplexEntryTypesRS.Contains(Services.GetInstance<ILexEntryTypeRepository>().GetObject(LexEntryTypeTags.kguidLexTypDerivation)) &&
!ler.ShowComplexFormsInRS.Contains(other)) // Don't add it twice! See LT-11562.
{
ler.ShowComplexFormsInRS.Add(other);
}
}
internal IEnumerable<ILexEntryRef> EntryRefsWithThisMainEntry
{
get
{
((ICmObjectRepositoryInternal)Services.ObjectRepository).EnsureCompleteIncomingRefsFrom(LexEntryRefTags.kflidComponentLexemes);
foreach (var item in m_incomingRefs)
{
var sequence = item as LcmReferenceSequence<ICmObject>;
if (sequence == null)
continue;
if (sequence.Flid == LexEntryRefTags.kflidComponentLexemes)
yield return sequence.MainObject as ILexEntryRef;
}
}
}
/// <summary>
/// Returns ALL ComplexForms referring to this entry as one of its ComponentLexemes.
/// ComponentLexemes is a superset of PrimaryLexemes, so the ComplexForms data entry field
/// needs to show references to all ComponentLexemes that are ComplexForms.
/// </summary>
internal IEnumerable<ILexEntryRef> ComplexFormRefsWithThisComponentEntry
{
get
{
((ICmObjectRepositoryInternal)Services.ObjectRepository).EnsureCompleteIncomingRefsFrom(LexEntryRefTags.kflidComponentLexemes);
foreach (var item in m_incomingRefs)
{
var sequence = item as LcmReferenceSequence<ICmObject>;
if (sequence == null)
continue;
if (sequence.Flid == LexEntryRefTags.kflidComponentLexemes &&
((ILexEntryRef)sequence.MainObject).RefType == LexEntryRefTags.krtComplexForm)
{
yield return sequence.MainObject as ILexEntryRef;
}
}
}
}
/// <summary>
/// Returns all ComplexForms that will be listed as subentries for this entry.
/// </summary>
internal IEnumerable<ILexEntryRef> ComplexFormRefsWithThisPrimaryEntry
{
get
{
((ICmObjectRepositoryInternal)Services.ObjectRepository).EnsureCompleteIncomingRefsFrom(LexEntryRefTags.kflidPrimaryLexemes);
foreach (var item in m_incomingRefs)
{
var sequence = item as LcmReferenceSequence<ICmObject>;
if (sequence == null)
continue;
if (sequence.Flid == LexEntryRefTags.kflidPrimaryLexemes &&
((ILexEntryRef)sequence.MainObject).RefType == LexEntryRefTags.krtComplexForm)
{
yield return sequence.MainObject as ILexEntryRef;
}
}
}
}
internal IEnumerable<ILexEntryRef> ComplexFormRefsVisibleInThisEntry
{
get
{
((ICmObjectRepositoryInternal)Services.ObjectRepository).EnsureCompleteIncomingRefsFrom(LexEntryRefTags.kflidShowComplexFormsIn);
foreach (var item in m_incomingRefs)
{
var sequence = item as LcmReferenceSequence<ICmObject>;
if (sequence == null)
continue;
if (sequence.Flid == LexEntryRefTags.kflidShowComplexFormsIn &&
((ILexEntryRef)sequence.MainObject).RefType == LexEntryRefTags.krtComplexForm)
{
yield return sequence.MainObject as ILexEntryRef;
}
}
}
}
internal IEnumerable<ILexReference> ReferringLexReferences
{
get
{
((ICmObjectRepositoryInternal)Services.ObjectRepository).EnsureCompleteIncomingRefsFrom(LexReferenceTags.kflidTargets);
foreach (var item in m_incomingRefs)
{
var sequence = item as LcmReferenceSequence<ICmObject>;
if (sequence == null)
continue;
if (sequence.Flid == LexReferenceTags.kflidTargets)
yield return sequence.MainObject as ILexReference;
}
}
}
/// <summary>
/// Replace all incoming references to objOld with references to 'this'.
/// This override allows special handling of certain groups of reference sequences that interact