@@ -78,7 +78,7 @@ public CodecRegistration(string encoding, int version)
78
78
}
79
79
static Dictionary < CodecRegistration , Type > Codecs = new Dictionary < CodecRegistration , Type > ( ) ;
80
80
81
- public static IEnumerable < Codec_t > CodecsRegistered { get { return Codecs . Select ( t => new Codec_t ( t . Key . Encoding , t . Key . Version ) ) ; } }
81
+ public static IEnumerable < Codec_t > CodecsRegistered { get { return Codecs . Select ( t => new Codec_t ( t . Key . Encoding , t . Key . Version ) ) ; } }
82
82
83
83
/// <summary>
84
84
/// Registers a new <see cref="ICodec"/> with an encoding name and one or more encoding versions.
@@ -195,7 +195,7 @@ static Datamodel Load_Internal(Stream stream, DeferredMode defer_mode = Deferred
195
195
var match = System . Text . RegularExpressions . Regex . Match ( header , CodecUtilities . HeaderPattern_Regex ) ;
196
196
197
197
if ( ! match . Success || match . Groups . Count != 5 )
198
- throw new InvalidOperationException ( String . Format ( "Could not read DMX header ({0})." , header ) ) ;
198
+ throw new InvalidOperationException ( String . Format ( "Could not read DMX header ({0})." , header ) ) ;
199
199
200
200
string encoding = match . Groups [ 1 ] . Value ;
201
201
int encoding_version = int . Parse ( match . Groups [ 2 ] . Value ) ;
@@ -217,7 +217,7 @@ static Datamodel Load_Internal(Stream stream, DeferredMode defer_mode = Deferred
217
217
218
218
dm . Encoding = encoding ;
219
219
dm . EncodingVersion = encoding_version ;
220
-
220
+
221
221
return dm ;
222
222
}
223
223
@@ -348,6 +348,14 @@ public void Dispose()
348
348
}
349
349
350
350
#region Properties
351
+
352
+ public bool AllowRandomIDs
353
+ {
354
+ get { return _AllowRandomIDs ; }
355
+ set { _AllowRandomIDs = value ; NotifyPropertyChanged ( "AllowRandomIDs" ) ; }
356
+ }
357
+ bool _AllowRandomIDs = true ;
358
+
351
359
/// <summary>
352
360
/// Gets or sets a <see cref="FileInfo"/> object associated with this Datamodel.
353
361
/// </summary>
@@ -524,10 +532,13 @@ public Element CreateStubElement(Guid id)
524
532
/// Creates a new Element with a random ID.
525
533
/// </summary>
526
534
/// <param name="name">The Element's name. Duplicates allowed.</param>
527
- /// <param name="id ">The Element's ID. Must be unique within the Datamodel .</param>
535
+ /// <param name="class_name ">The Element's class .</param>
528
536
/// <returns>The new Element.</returns>
529
537
public Element CreateElement ( string name , string class_name = "DmElement" )
530
538
{
539
+ if ( ! AllowRandomIDs )
540
+ throw new InvalidOperationException ( "Random IDs are not allowed in this Datamodel." ) ;
541
+
531
542
Guid id ;
532
543
do { id = Guid . NewGuid ( ) ; }
533
544
while ( AllElements [ id ] != null ) ;
@@ -539,7 +550,7 @@ public Element CreateElement(string name, string class_name = "DmElement")
539
550
/// </summary>
540
551
/// <param name="name">The Element's name. Duplicates allowed.</param>
541
552
/// <param name="id">The Element's ID. Must be unique within the Datamodel.</param>
542
- /// <param name="class_name">the Element's class.</param>
553
+ /// <param name="class_name">The Element's class.</param>
543
554
/// <returns>The new Element.</returns>
544
555
public Element CreateElement ( string name , Guid id , string class_name = "DmElement" )
545
556
{
@@ -549,15 +560,16 @@ public Element CreateElement(string name, Guid id, string class_name = "DmElemen
549
560
internal int ElementsAdded = 0 ; // used to optimise de-stubbing
550
561
internal Element CreateElement ( string name , Guid id , bool stub , string classname = "DmElement" )
551
562
{
552
- if ( AllElements . Count == Int32 . MaxValue ) // jinkies!
553
- throw new InvalidOperationException ( "Maximum Element count reached." ) ;
554
-
555
563
lock ( AllElements . ChangeLock )
556
564
{
565
+ if ( AllElements . Count == Int32 . MaxValue ) // jinkies!
566
+ throw new InvalidOperationException ( "Maximum Element count reached." ) ;
567
+
557
568
if ( AllElements [ id ] != null )
558
569
throw new ElementIdException ( String . Format ( "Element ID {0} already in use in this Datamodel." , id . ToString ( ) ) ) ;
570
+
571
+ if ( ! stub ) ElementsAdded ++ ;
559
572
}
560
- if ( ! stub ) ElementsAdded ++ ;
561
573
return new Element ( this , id , name , classname , stub ) ;
562
574
}
563
575
#endregion
0 commit comments