Jump to: navigation, search

Sequence Generator


Revision as of 09:41, 14 November 2019 by MHM (Talk | contribs) (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...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.
}


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");  
if (seqGenerator.TryCreateNewSequentialID(myContent, out int seqID))   // handing over myContent is optional. But the reference to the object is persisted with the sequnce (documentation)
{
    myContent.TrySetValue<int>("SEQUENCE", seqID);
    myContent.Save();
}

// or optional approach
if (seqGenerator.TrySetSequentialID(myContent, "SEQUENCE", out int seqID))
{
    myContent.Save();
}