/// <summary> /// Opens objects for read. /// </summary> /// <param name="ids">The object IDs.</param> /// <returns>The opened object.</returns> public static DBObject[] QOpenForRead(this IEnumerable <ObjectId> ids) // newly 20120915 { using (var trans = DbHelper.GetDatabase(ids).TransactionManager.StartTransaction()) { return(ids.Select(id => trans.GetObject(id, OpenMode.ForRead)).ToArray()); } }
/// <summary> /// Opens objects for read. /// </summary> /// <typeparam name="T">The type of object.</typeparam> /// <param name="ids">The object IDs.</param> /// <returns>The opened object.</returns> public static T[] QOpenForRead <T>(this IEnumerable <ObjectId> ids) where T : DBObject // newly 20130122 { using (var trans = DbHelper.GetDatabase(ids).TransactionManager.StartTransaction()) { return(ids.Select(id => trans.GetObject(id, OpenMode.ForRead) as T).ToArray()); } }
/// <summary> /// Opens objects for write (for each). /// </summary> /// <typeparam name="T">The type of object.</typeparam> /// <param name="ids">The object IDs.</param> /// <param name="action">The action.</param> public static void QForEach <T>(this IEnumerable <ObjectId> ids, Action <T> action) where T : DBObject // newly 20130520 { using (var trans = DbHelper.GetDatabase(ids).TransactionManager.StartTransaction()) { ids.Select(id => trans.GetObject(id, OpenMode.ForWrite) as T).ToList().ForEach(action); trans.Commit(); } }
/// <summary> /// Opens objects for write (for each). /// </summary> /// <param name="ids">The object IDs.</param> /// <param name="action">The action.</param> public static void QForEach(this IEnumerable <ObjectId> ids, Action <DBObject> action) { using (var trans = DbHelper.GetDatabase(ids).TransactionManager.StartTransaction()) { ids.Select(id => trans.GetObject(id, OpenMode.ForWrite)).ToList().ForEach(action); trans.Commit(); } }
/// <summary> /// Opens objects for write. /// </summary> /// <typeparam name="T">The type of object.</typeparam> /// <param name="ids">The object IDs.</param> /// <param name="action">The action.</param> public static void QOpenForWrite <T>(this IEnumerable <ObjectId> ids, Action <T[]> action) where T : DBObject // newly 20130411 { using (var trans = DbHelper.GetDatabase(ids).TransactionManager.StartTransaction()) { var list = ids.Select(id => trans.GetObject(id, OpenMode.ForWrite) as T).ToArray(); action(list); trans.Commit(); } }
/// <summary> /// Opens objects for write. /// </summary> /// <param name="ids">The object IDs.</param> /// <param name="action">The action.</param> public static void QOpenForWrite(this IEnumerable <ObjectId> ids, Action <DBObject[]> action) // newly 20120908 { using (var trans = DbHelper.GetDatabase(ids).TransactionManager.StartTransaction()) { var list = ids.Select(x => trans.GetObject(x, OpenMode.ForWrite)).ToArray(); action(list); trans.Commit(); } }
public static ObjectId QMaxEntity(this IEnumerable <ObjectId> ids, Func <Entity, double> mapper) { // Bad implementation. using (var trans = DbHelper.GetDatabase(ids).TransactionManager.StartOpenCloseTransaction()) { var entities = ids.Select(id => trans.GetObject(id, OpenMode.ForRead) as Entity).ToList(); double value = entities.Max(mapper); return(entities.First(entity => mapper(entity) == value).ObjectId); } }
/// <summary> /// Opens objects for write. /// </summary> /// <typeparam name="T">The type of object.</typeparam> /// <param name="ids">The object IDs.</param> /// <param name="action">The action.</param> public static void QOpenForWrite <T>(this IEnumerable <ObjectId> ids, Func <T[], DBObject[]> action) where T : DBObject { using (var trans = DbHelper.GetDatabase(ids).TransactionManager.StartTransaction()) { var list = ids.Select(id => trans.GetObject(id, OpenMode.ForWrite) as T).ToArray(); var newObjects = action(list).ToList(); newObjects.ForEach(newObject => trans.AddNewlyCreatedDBObject(newObject, true)); trans.Commit(); } }