private void CompleteUndefinedColors(IEnumerable <ObjectClass> objectClasses) { #region validation if (objectClasses == null) { throw new ArgumentNullException(nameof(objectClasses)); } #endregion foreach (ObjectClass objectClassWithUndefinedColor in objectClasses.Where(o => o.Color == ObjectClass.UNDEFINED_COLOR)) { objectClassWithUndefinedColor.ColorCode = ObjectClassColorUtil.GetDefaultColorCode(objectClassWithUndefinedColor.Id); } }
/// <summary> /// Create objectclass with given name if currently not exists in collection of object classes. /// Returns newly generated object class or objectclass with given name. /// </summary> /// <param name="objectClassService">Objectclass service</param> /// <param name="topic">Topic for object classes</param> /// <param name="objectClassName">Name of object class</param> /// <returns>Newly created object class</returns> public static ObjectClass CreateIfNotExists(this IObjectClassService objectClassService, Topic topic, string objectClassName) { #region validation if (topic == null) { throw new ArgumentNullException(nameof(topic)); } if (string.IsNullOrEmpty(objectClassName)) { throw new ArgumentNullException(nameof(objectClassName)); } #endregion objectClassName = objectClassName.Replace('\\', '_').Replace('/', '_').Replace(':', '_').Replace('*', '_') .Replace('?', '_').Replace('^', '_').Replace('<', '_').Replace('<', '_').Replace('|', '_'); // get list of all object classes IEnumerable <ObjectClass> objectClasses = objectClassService.GetObjectClasses(topic); // find object class with name ObjectClass objectClass = objectClasses.SingleOrDefault(o => o.Name.Equals(objectClassName, StringComparison.CurrentCultureIgnoreCase)); if (objectClass == null) { // create object class objectClass = new ObjectClass() { Name = objectClassName, ColorCode = ObjectClassColorUtil.GetDefaultColorCode((uint)objectClasses.Count()) }; objectClass = objectClassService.CreateObjectClass(topic, objectClass); } return(objectClass); }