Jump to: navigation, search

Difference between revisions of "Sequence Generator"


(Created page with "Tje Sequence Generator provides a feature that ensures to generate an uniquue sequence number (integer). It is possible to define specific number groups in which the ID is uni...")
 
 
(2 intermediate revisions by the same user not shown)
Line 6: Line 6:
  
 
<source lang="csharp">
 
<source lang="csharp">
 
 
UBIK.Kernel.Utility.SequenceGenerator seqGenerator = new UBIK.Kernel.Utility.SequenceGenerator(this.Environment);    //no "number group" is managed as one group itself
 
UBIK.Kernel.Utility.SequenceGenerator seqGenerator = new UBIK.Kernel.Utility.SequenceGenerator(this.Environment);    //no "number group" is managed as one group itself
 
if (seqGenerator.TryCreateNewSequentialID(out int seqID))
 
if (seqGenerator.TryCreateNewSequentialID(out int seqID))
 
{
 
{
     // do something with the given ID.
+
     // do something with the given ID:
 +
    ContentClass myContent;
 +
    myContent.TrySetValue<int>("SEQUENCE", seqID);
 +
    myContent.Save();
 
}
 
}
 
</source>
 
</source>
Line 19: Line 21:
  
 
<source lang="csharp">
 
<source lang="csharp">
 
 
ContentClass myContent;
 
ContentClass myContent;
 
UBIK.Kernel.Utility.SequenceGenerator seqGenerator = new UBIK.Kernel.Utility.SequenceGenerator(this.Environment, "GROUP01");   
 
UBIK.Kernel.Utility.SequenceGenerator seqGenerator = new UBIK.Kernel.Utility.SequenceGenerator(this.Environment, "GROUP01");   
if (seqGenerator.TryCreateNewSequentialID(myContent, out int seqID))  // handing over myContent is optional. But the reference to the object is persisted with the sequnce (documentation)
+
// handing over myContent is optional. But the reference to the object is persisted with the sequnce (can be used  to navigate from the sequence to the owner)
 +
if (seqGenerator.TryCreateNewSequentialID(myContent, out int seqID)) 
 
{
 
{
 
     myContent.TrySetValue<int>("SEQUENCE", seqID);
 
     myContent.TrySetValue<int>("SEQUENCE", seqID);
 
     myContent.Save();
 
     myContent.Save();
 
}
 
}
 +
</source>
  
// or optional approach
+
 
 +
 
 +
'''Example: Create a new ID and set it to an object using the generator
 +
 
 +
<source lang="csharp">
 +
UBIK.Kernel.Utility.SequenceGenerator seqGenerator = new UBIK.Kernel.Utility.SequenceGenerator(this.Environment, "GROUP01"); 
 
if (seqGenerator.TrySetSequentialID(myContent, "SEQUENCE", out int seqID))  
 
if (seqGenerator.TrySetSequentialID(myContent, "SEQUENCE", out int seqID))  
 
{
 
{

Latest revision as of 09:44, 14 November 2019

Tje Sequence Generator provides a feature that ensures to generate an uniquue sequence number (integer). It is possible to define specific number groups in which the ID is unique. The number (within every group) starts with one and increase by 1 after every generated id.

Example: Create a new ID'

UBIK.Kernel.Utility.SequenceGenerator seqGenerator = new UBIK.Kernel.Utility.SequenceGenerator(this.Environment);    //no "number group" is managed as one group itself
if (seqGenerator.TryCreateNewSequentialID(out int seqID))
{
    // do something with the given ID:
    ContentClass myContent;
    myContent.TrySetValue<int>("SEQUENCE", seqID);
    myContent.Save();
}


Example: Create a new ID and set it to an object'

ContentClass myContent;
UBIK.Kernel.Utility.SequenceGenerator seqGenerator = new UBIK.Kernel.Utility.SequenceGenerator(this.Environment, "GROUP01");  
// handing over myContent is optional. But the reference to the object is persisted with the sequnce (can be used  to navigate from the sequence to the owner)
if (seqGenerator.TryCreateNewSequentialID(myContent, out int seqID))  
{
    myContent.TrySetValue<int>("SEQUENCE", seqID);
    myContent.Save();
}


Example: Create a new ID and set it to an object using the generator

UBIK.Kernel.Utility.SequenceGenerator seqGenerator = new UBIK.Kernel.Utility.SequenceGenerator(this.Environment, "GROUP01");  
if (seqGenerator.TrySetSequentialID(myContent, "SEQUENCE", out int seqID))
{
    myContent.Save();
}