示例#1
0
        public static string GetNextId(string id, IIdentifiedObject obj, string group)
        {
            string suggestedId = id;
            int    count       = 1;

            while (UniqueIDCache.IsIdInUse(suggestedId, obj, group))
            {
                suggestedId = id + "-" + count.ToString();
                count++;
            }

            return(suggestedId);
        }
示例#2
0
        public static string SetID(IIdentifiedObject obj, string proposedValue, string groupName, bool canRename)
        {
            string newID = proposedValue;
            string oldID = obj.ID;

            if (proposedValue != null)
            {
                if (obj.ID == null)
                {
                    if (UniqueIDCache.IsIdInUse(proposedValue, obj, groupName))
                    {
                        if (canRename)
                        {
                            newID = UniqueIDCache.GetNextId(proposedValue, obj, groupName);
                        }
                        else
                        {
                            throw new DuplicateIdentifierException();
                        }
                    }
                    else
                    {
                        newID = proposedValue;
                    }
                }
                else if (UniqueIDCache.CanChangeId(groupName, obj, proposedValue))
                {
                    newID = proposedValue;
                }
                else
                {
                    throw new DuplicateIdentifierException();
                }
            }

            return(newID);
        }