Beispiel #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);
        }
Beispiel #2
0
        public static bool IsIdInUse(string id, IIdentifiedObject obj, string group)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            if (group == null)
            {
                throw new ArgumentNullException(nameof(@group));
            }

            HashSet <IIdentifiedObject> itemGroup = UniqueIDCache.GetGroupCollection(group);

            return(itemGroup.Any(t => t.ID == id && t != obj));
        }
Beispiel #3
0
        public static void RemoveItem(IIdentifiedObject item, string group)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            if (group == null)
            {
                throw new ArgumentNullException(nameof(@group));
            }

            HashSet <IIdentifiedObject> itemGroup = UniqueIDCache.GetGroupCollection(group);

            if (itemGroup.Contains(item))
            {
                itemGroup.Remove(item);
            }
        }
Beispiel #4
0
        public static void AddItem(IIdentifiedObject item, string group)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            if (group == null)
            {
                throw new ArgumentNullException(nameof(@group));
            }

            HashSet <IIdentifiedObject> itemGroup = UniqueIDCache.GetGroupCollection(group);

            if (itemGroup.Any(t => t.ID == item.ID))
            {
                throw new ArgumentException(string.Format("The specified id '{0}' is already in use in group {1}", item.ID, group));
            }
            else
            {
                itemGroup.Add(item);
            }
        }
Beispiel #5
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);
        }
Beispiel #6
0
        public static bool CanChangeId(string group, IIdentifiedObject item, string newId)
        {
            HashSet <IIdentifiedObject> itemGroup = UniqueIDCache.GetGroupCollection(group);

            return(!itemGroup.Any(t => t.ID == newId && t != item));
        }
Beispiel #7
0
 public static void ClearIdCache(string group)
 {
     UniqueIDCache.GetGroupCollection(group).Clear();
 }
Beispiel #8
0
 public static bool HasObject(string group, IIdentifiedObject item)
 {
     return(UniqueIDCache.GetGroupCollection(group).Contains(item));
 }