Пример #1
0
        void InitializeIdData(GalacticProperties gp)
        {
            foreach (var idd in gp.IdProperties.Values)
            {
                IdData idData = new IdData(idd.IDType,
                                           idd.LastIDAdded,
                                           new HashSet <int>(Enumerable.Range(0, idd.LastIDAdded + 1).Where(i => !idd.ReservedIDs.Contains(i))),
                                           new HashSet <int>(),
                                           idd.ReservedIDs);

                DbIdIoService.SaveIdDataAsync(idData).Wait();
            }
        }
Пример #2
0
        void _generateNewIDs(int numIDs)
        {
            lock (IDLOCK)
            {
                try
                {
                    ConsoleManager.WriteLine("Generating new ids of type " + IDType, ConsoleMessageType.Notification);

                    int n = checked (numIDs + _minIDCount);
                    //If this statement throws an exception, congratulations! Freecon has grown
                    //large enough to run out of 32bit galaxy IDs. Now you as the developer
                    //are in line for the pleasure of implementing 64bit galaxy IDs! Have fun,
                    //and try not to kill yourself!

                    for (int i = _lastIdGenerated + 1; i < numIDs + _lastIdGenerated + 1; i++)
                    {
                        if (_reservedIDs.Contains(i))
                        {
                            n = checked (numIDs + _minIDCount); //Throws exception if numIDs + _minIDCount > int.MAX
                            numIDs++;
                            continue;
                        }

                        _freeIDs.Push(i);
                    }
                    _lastIdGenerated = numIDs + _lastIdGenerated;

                    var idData = new IdData(IDType, _lastIdGenerated, new HashSet <int>(_freeIDs), new HashSet <int>(_generatedIDs), new HashSet <int>(_reservedIDs));
                    _dbIdIoService.SaveIdDataAsync(idData);
                }
                catch
                {
                    throw new Exception("Ran out of 32 bit ints for IDs. Time for a 64 bit server!");
                }
            }
        }