示例#1
0
        public uint GetNextUid()
        {
            //go thru the array list and see if any of the values arent in use
            IEnumerator UidEnum = UidList.GetEnumerator();

            while (UidEnum.MoveNext())
            {
                if (UidEnum.Current is UidListItem)
                {
                    UidListItem CurrentUid = UidEnum.Current as UidListItem;
                    if (CurrentUid.InUse == false)
                    {
                        CurrentUid.InUse = true;
                        return(CurrentUid.Value);
                    }
                }
                else
                {
                    throw new Exception("UidList should only contain UidListItem's");
                }
            }

            //There are no free id's in the array so make one
            UidListItem NewUid = new UidListItem();

            NewUid.InUse = true;
            NewUid.Value = this.NextValueForArray;
            this.NextValueForArray++;
            this.UidList.Add(NewUid);
            return(NewUid.Value);
        }
示例#2
0
        public void FreeUid(uint UidToFree)
        {
            bool DeleteUid = false;

            if (UidToFree == this.NextValueForArray - 1)
            {
                DeleteUid = true;
            }

            //Get the Uid item
            IEnumerator UidEnum = UidList.GetEnumerator();

            while (UidEnum.MoveNext())
            {
                if (UidEnum.Current is UidListItem)
                {
                    UidListItem CurrentUid = UidEnum.Current as UidListItem;
                    if (CurrentUid.Value == UidToFree)
                    {
                        if (CurrentUid.InUse == false)
                        {
                            throw new Exception("The Uid already is free");
                        }

                        if (DeleteUid)
                        {
                            this.UidList.Remove(CurrentUid);
                            this.NextValueForArray--;
                            if ((this.NextValueForArray == 0) && (this.IncludeZero == false))
                            {
                                this.NextValueForArray = 1;
                            }

                            return;
                        }
                        else
                        {
                            CurrentUid.InUse = false;
                            return;
                        }
                    }
                }
                else
                {
                    throw new Exception("UidList should only contain UidListItem's");
                }
            }

            throw new Exception("The Uid already is free");
        }
示例#3
0
        public uint GetNextUid()
        {
            //go thru the array list and see if any of the values arent in use
            IEnumerator UidEnum = UidList.GetEnumerator();
            while( UidEnum.MoveNext() )
            {
                if( UidEnum.Current is UidListItem )
                {
                    UidListItem CurrentUid = UidEnum.Current as UidListItem;
                    if( CurrentUid.InUse == false )
                    {
                        CurrentUid.InUse = true;
                        return CurrentUid.Value;
                    }
                }
                else
                    throw new Exception("UidList should only contain UidListItem's");
            }

            //There are no free id's in the array so make one
            UidListItem NewUid = new UidListItem();
            NewUid.InUse = true;
            NewUid.Value = this.NextValueForArray;
            this.NextValueForArray++;
            this.UidList.Add(NewUid);
            return NewUid.Value;
        }