//--------------------------------------------------------------------------------------------------------------------- public static void SetAccountStatus(IfyContext context, int[] ids, int accountStatus) { if (context.AccessLevel != EntityAccessLevel.Administrator) { throw new EntityUnauthorizedException("You are not authorized to enable or disable user accounts", null, null, 0); } string idsStr = ""; for (int i = 0; i < ids.Length; i++) { idsStr += (idsStr == "" ? "" : ",") + ids[i]; } string sql = String.Format("UPDATE usr SET status={0}{1} WHERE id{2};", accountStatus.ToString(), accountStatus == AccountStatusType.Enabled ? ", failed_logins=0" : String.Empty, ids.Length == 1 ? "=" + idsStr : " IN (" + idsStr + ")" ); int count = context.Execute(sql); if (count > 0) { context.WriteInfo(count + " user account" + (count == 1 ? " was " : "s were ") + (accountStatus == AccountStatusType.Enabled ? "enabled" : "disabled")); } else { context.WriteWarning("No user account has been " + (accountStatus == AccountStatusType.Enabled ? "enabled" : "disabled")); } //OnItemProcessed(OperationType.Other, 0); // TODO }
//--------------------------------------------------------------------------------------------------------------------- /// <summary>Executes the background agent action <b>Computing Element status refresh</b>.</summary> /// <param name="context">The execution environment context.</param> /// <remarks> /// <p>This method is called periodically if the action is active and the background agent is running according to the action's execution interval specified in the portal configuration.</p> /// <p>The background agent action <b>Computing Element status refresh</b> refreshes task, job and node status information for active tasks.</p> /// </remarks> public static void ExecuteComputingResourceStatusRefresh(IfyContext context) { IDataReader reader; ComputingResource computingResource; List <int> computingResourceIds = new List <int>(); int unknownCount = 0; // Add computing resources into status table if not yet there context.Execute("INSERT INTO crstate (id_cr) SELECT id FROM cr AS t LEFT JOIN crstate AS t1 ON t.id=t1.id_cr WHERE t1.id_cr IS NULL;"); // Get computing resources with actual status Active (10) reader = null; string sql = "SELECT t.id FROM ce AS t WHERE status_method IS NOT NULL ORDER BY t.id;"; // WHERE status=" + ProcessingStatus.Active + " AND remote_id IS NOT NULL ORDER BY t.id;"; IDbConnection dbConnection = context.GetDbConnection(); reader = context.GetQueryResult(sql, dbConnection); while (reader.Read()) { computingResourceIds.Add(reader.GetInt32(0)); } context.CloseQueryResult(reader, dbConnection); //context.WriteInfo(String.Format("Active tasks: {0}{1}", computingResourceIds.Count, computingResourceIds.Count == 0 ? String.Empty : " - status display format: created/active/failed/incomplete/completed")); // Get available computing resource information for (int i = 0; i < computingResourceIds.Count; i++) { computingResource = ComputingResource.FromId(context, computingResourceIds[i]); //computingResource.Restricted = false; computingResource.GetStatus(); if (computingResource.Refreshed) { context.WriteInfo( String.Format("{0}: total: {1}, free: {2}", computingResource.Name, computingResource.TotalCapacity, computingResource.FreeCapacity ) ); } else { unknownCount++; } } if (unknownCount != 0) { context.WriteWarning(String.Format("Computing resources with unavailable status: {0} (out of {1})", unknownCount, computingResourceIds.Count)); } computingResourceIds.Clear(); }