/// <summary> /// Builds and returns the list of object types that can contain macros. /// </summary> /// <param name="include">Object types to include in the list</param> /// <param name="exclude">Object types to exclude from the list</param> /// <remarks> /// Excludes the object types that cannot contain macros. /// </remarks> public static IEnumerable <string> GetObjectTypesWithMacros(IEnumerable <string> include = null, IEnumerable <string> exclude = null) { // Get the system object types var objectTypes = ObjectTypeManager.ObjectTypesWithMacros; // Include custom table object types objectTypes = objectTypes.Union(GetCustomTableObjectTypes()); // Include biz form object types objectTypes = objectTypes.Union(GetFormObjectTypes()); // Include object types if (include != null) { objectTypes = objectTypes.Union(include); } // Exclude object types if (exclude != null) { objectTypes = objectTypes.Except(exclude); } objectTypes = objectTypes.Where(t => { try { var typeInfo = ObjectTypeManager.GetRegisteredTypeInfo(t); return(!typeInfo.Inherited && typeInfo.ContainsMacros); } catch (Exception) { return(false); } }); return(objectTypes); }
/// <summary> /// Gets the macros from the system /// </summary> /// <param name="startIndex">Start index</param> /// <param name="endIndex">End index</param> /// <param name="maxTotalRecords">Maximum number of total records to process</param> /// <param name="totalRecords">Returns the total number of records found</param> private IEnumerable <MacroExpr> GetMacros(int startIndex, int endIndex, int maxTotalRecords, ref int totalRecords) { var index = 0; IEnumerable <string> objectTypes = null; // Get object types to search var selectedType = ValidationHelper.GetString(selObjectType.Value, ""); if (!String.IsNullOrEmpty(selectedType)) { if (ObjectTypeManager.GetRegisteredTypeInfo(selectedType) != null) { objectTypes = new List <string> { selectedType }; } } if (objectTypes == null) { objectTypes = ObjectTypeManager.ObjectTypesWithMacros; } var result = new List <MacroExpr>(); var search = txtFilter.Text; var invalid = chkInvalid.Checked; var skipTesting = SystemContext.DevelopmentMode && chkSkipTesting.Checked; var type = drpType.Text; foreach (var objectType in objectTypes) { // Skip certain object types switch (objectType) { case ObjectVersionHistoryInfo.OBJECT_TYPE: case VersionHistoryInfo.OBJECT_TYPE: case StagingTaskInfo.OBJECT_TYPE: case IntegrationTaskInfo.OBJECT_TYPE: continue; } // Process all objects of the given type var infos = new ObjectQuery(objectType) .TopN(maxTotalRecords) .BinaryData(false); var typeInfo = infos.TypeInfo; if (skipTesting) { ExcludeTestingObjects(infos); } if (!String.IsNullOrEmpty(search)) { // Search particular expression infos.WhereAnyColumnContains(search); } else { // Search just type infos.WhereAnyColumnContains("{" + type); } Action <DataRow> collectMacros = dr => { var drc = new DataRowContainer(dr); // Process all expressions MacroProcessor.ProcessMacros(drc, (expression, colName) => { var originalExpression = expression; // Decode macro from XML if (MacroProcessor.IsXMLColumn(colName)) { expression = HTMLHelper.HTMLDecode(expression); } MacroExpr e = null; bool add = false; if (String.IsNullOrEmpty(search) || (expression.IndexOfCSafe(search, true) >= 0)) { // If not tracking errors, count immediately if (!invalid) { // Apply paging. Endindex is -1 when paging is off if ((endIndex < 0) || ((index >= startIndex) && (index <= endIndex))) { e = GetMacroExpr(expression); add = true; } index++; } else { e = GetMacroExpr(expression); // Filter invalid signature / syntax var pass = !e.SignatureValid || e.Error; if (pass) { // Apply paging. Endindex is -1 when paging is off if ((endIndex < 0) || ((index >= startIndex) && (index <= endIndex))) { add = true; } index++; } } } if (add) { // Fill in the object information e.ObjectType = objectType; e.ObjectID = (typeInfo.IDColumn == ObjectTypeInfo.COLUMN_NAME_UNKNOWN) ? 0 : ValidationHelper.GetInteger(dr[typeInfo.IDColumn], 0); e.Field = colName; result.Add(e); } return(originalExpression); }, new List <string> { type } ); if ((maxTotalRecords != -1) && (index >= maxTotalRecords)) { // Enough data - cancel enumeration throw new ActionCancelledException(); } }; using (var scope = new CMSConnectionScope()) { scope.Connection.CommandTimeout = ConnectionHelper.LongRunningCommandTimeout; infos.ForEachRow(collectMacros); } if (((maxTotalRecords != -1) && (index >= maxTotalRecords)) || !CMSHttpContext.Current.Response.IsClientConnected) { break; } } totalRecords = index; return(result); }