Exemple #1
0
        public bool IssueId <T>(IdContext_I context, T identifier)
            where T : Identifier_I
        {
            lock (context.SyncRoot)
            {
                bool availableRangeUpdated = false;

                if (context.AvailableRange == null || context.AvailableRange.LastIssuedId >= context.AvailableRange.EndInclusive || context.AvailableRange.StartInclusive == 0 || context.AvailableRange.EndInclusive == 0)
                {
                    context.AvailableRange = IssueNextAvailableRange(context);

                    XSettings.SetAndPersist(LastIdIssuedKey, context.AvailableRange.EndInclusive.ToString());

                    availableRangeUpdated = true;
                }

                identifier.Value = (++context.AvailableRange.LastIssuedId);

                return(availableRangeUpdated);
            }
        }
Exemple #2
0
        public void Initialize(IdContext_I context)
        {
            if (XSettings.GetString(LastIdIssuedKey, out string lastIdIssued) &&
                !string.IsNullOrEmpty(lastIdIssued) &&
                Int64.TryParse(lastIdIssued, out long lastId))
            {
                context.AvailableRange = new AvailableIdRange()
                {
                    LastIssuedId = lastId
                };

                return;
            }

            XSettings.SetAndPersist(LastIdIssuedKey, "0");

            context.AvailableRange = new AvailableIdRange()
            {
                LastIssuedId = 0
            };
        }