コード例 #1
0
ファイル: DBCookie.cs プロジェクト: Terradue/DotNetPortalCore
        /*****************************************************************************************************************/

        /// <summary>Stores the DB cookie.</summary>
        public void Store()
        {
            if (string.IsNullOrEmpty(Session))
            {
                throw new Exception("Empty Session ID");
            }
            if (string.IsNullOrEmpty(Identifier))
            {
                throw new Exception("Empty Identifier");
            }
            if (string.IsNullOrEmpty(Value))
            {
                throw new Exception("Empty value");
            }

            //delete old value if exists
            Delete(false);

            string sql = string.Format("INSERT INTO cookie (session, identifier, value, expire, creation_date) VALUES ({0},{1},{2},{3},{4});",
                                       StringUtils.EscapeSql(Session),
                                       StringUtils.EscapeSql(Identifier),
                                       StringUtils.EscapeSql(Value),
                                       Expire.Equals(DateTime.MinValue) ? StringUtils.EscapeSql(DateTime.UtcNow.AddDays(1).ToString(@"yyyy\-MM\-dd\THH\:mm\:ss")) : StringUtils.EscapeSql(Expire.ToString(@"yyyy\-MM\-dd\THH\:mm\:ss")),
                                       StringUtils.EscapeSql(DateTime.UtcNow.ToString(@"yyyy\-MM\-dd\THH\:mm\:ss"))
                                       );

            Context.Execute(sql);
            Console.WriteLine(sql);
        }
コード例 #2
0
        //---------------------------------------------------------------------------------------------------------------------

        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
        }
コード例 #3
0
        //---------------------------------------------------------------------------------------------------------------------

        /// <summary>Executes the scheduler-related part of the background agent action <b>%Task&nbsp;and&nbsp;scheduler&nbsp;cleanup</b>.</summary>

        /*
         *  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.
         *
         *  The background agent action <b>%Task&nbsp;cleanup</b> deletes the tasks that have been marked for deletion and no longer consume Grid engine resources, together with all data related to these tasks (jobs, node information etc.), from the database.
         *  This is the case for tasks that have the value <i>Deleted</i> in the database field <i>task.status</i>.
         *  %Tasks deletions are pending if they were requested while the portal configuration variable <i>SynchronousTaskOperations</i> was set to <i>false</i>.
         *
         * /// <param name="context">The execution environment context.</param>
         * /// \xrefitem rmodp "RM-ODP" "RM-ODP Documentation"
         */
        public static void ExecuteCleanup(IfyContext context)
        {
            IDataReader reader;
            List <int>  schedulerIds = new List <int>();

            // Abort tasks (next_status = Deleted)
            reader = context.GetQueryResult(String.Format("SELECT t.id FROM scheduler AS t WHERE status={0} ORDER BY t.id;", ProcessingStatus.Deleted));
            while (reader.Read())
            {
                schedulerIds.Add(reader.GetInt32(0));
            }
            reader.Close();

            int count = 0, taskCount = 0;

            foreach (int schedulerId in schedulerIds)
            {
                Scheduler scheduler = FromId(context, schedulerId);
                taskCount += scheduler.DoAbortAllTasks();
                context.Execute(String.Format("DELETE FROM scheduler WHERE id={0};", schedulerId));
                count++;
            }
            schedulerIds.Clear();

            if (count > 0)
            {
                context.WriteInfo(String.Format("Deleted schedulers {0}: (aborted tasks: {1})", count, taskCount));
            }
        }
コード例 #4
0
ファイル: DBCookie.cs プロジェクト: Terradue/DotNetPortalCore
        /*****************************************************************************************************************/

        /// <summary>Deletes all DB cookies from a session.</summary>
        /// <param name="context">The execution environment context.</param>
        /// <param name="session">The related session ID.</param>
        public static void DeleteDBCookies(IfyContext context, string session)
        {
            if (string.IsNullOrEmpty(session))
            {
                return;
            }
            string sql = string.Format("DELETE FROM cookie WHERE session='{0}';", session);

            context.Execute(sql);
        }
コード例 #5
0
        //---------------------------------------------------------------------------------------------------------------------

        /// <summary>Executes the background agent action <b>Computing&nbsp;Element&nbsp;status&nbsp;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&nbsp;Element&nbsp;status&nbsp;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();
        }
コード例 #6
0
        //---------------------------------------------------------------------------------------------------------------------

        /// <summary>Performs the background action for the password expiration check.</summary>
        /// <param name="context">The execution environment context.</param>
        /// <remarks>
        ///     The background agent action <em>Password expiration check</em> deactivates user accounts for which the password has not been set for longer than the password expiration time (see <see cref="PasswordExpireTime"/>.
        ///     Users can still use their accounts after setting a new password.
        /// </remarks>
        public static void ExecutePasswordExpirationCheck(IfyContext context)
        {
            if (context.DebugLevel >= 3)
            {
                context.WriteDebug(3, "PasswordExpireTime seconds: " + passwordExpireTime);
            }

            if (passwordExpireTime <= 0)
            {
                return;
            }
            DateTime earliestTime = context.Now.AddSeconds(-passwordExpireTime);

            string sql = String.Format("UPDATE usr SET status={0} WHERE status={1} AND allow_password AND (last_password_change_time IS NULL OR last_password_change_time<'{2}');", AccountStatusType.Deactivated, AccountStatusType.Enabled, earliestTime.ToString(@"yyyy\-MM\-dd HH\:mm\:ss"));

            context.WriteDebug(3, sql);
            int count = context.Execute(sql);

            context.WriteInfo("Deactivated user accounts: " + (count <= 0 ? "0" : count.ToString()));
        }
コード例 #7
0
        //---------------------------------------------------------------------------------------------------------------------

        /// <summary>.</summary>
        public static void ExecuteCatalogueSeriesRefresh(IfyContext context)
        {
            string      sql    = "SELECT t.id, t.identifier, t.cat_description, t1.base_url FROM series AS t LEFT JOIN catalogue AS t1 ON t.id_catalogue=t1.id WHERE t.auto_refresh ORDER BY t.identifier;";
            int         count  = 0;
            IDataReader reader = context.GetQueryResult(sql);

            while (reader.Read())
            {
                int    id   = reader.GetInt32(0);
                string name = reader.GetString(1);
                string catalogueDescriptionUrl = reader.GetString(2);
                string catalogueBaseUrl        = context.GetValue(reader, 3);
                if (catalogueDescriptionUrl == null || catalogueDescriptionUrl == String.Empty)
                {
                    context.AddError("No catalogue description URL defined for \"" + name + "\"");
                    continue;
                }
                bool usePlaceholder = (catalogueDescriptionUrl.Contains("$(CATALOGUE)") && catalogueBaseUrl != null);
                if (usePlaceholder)
                {
                    catalogueDescriptionUrl = catalogueDescriptionUrl.Replace("$(CATALOGUE)", catalogueBaseUrl);
                }
                string catalogueUrlTemplate = null;
                try {
                    catalogueUrlTemplate = Terradue.Metadata.OpenSearch.OpenSearchDescription.GetUrlTemplate(catalogueDescriptionUrl, new string[] { "application/rdf+xml", "application/xhtml+xml" });
                } catch (XmlException) {
                    context.AddError("Catalogue description URL for \"" + name + "\" returns invalid description");
                } catch (Exception) {
                    context.AddError("No catalogue URL template found for series \"" + name + "\"");
                }
                if (catalogueUrlTemplate == null)
                {
                    continue;
                }
                if (usePlaceholder)
                {
                    catalogueUrlTemplate = catalogueUrlTemplate.Replace(catalogueBaseUrl, "$(CATALOGUE)" + (catalogueBaseUrl.EndsWith("/") ? "/" : String.Empty));
                }
                context.Execute(String.Format("UPDATE series SET cat_template={1} WHERE id={0};", id, StringUtils.EscapeSql(catalogueUrlTemplate)));
                count++;
            }
            context.AddInfo(String.Format("Updated series: {0}", count));

            count = context.GetQueryIntegerValue("SELECT COUNT(*) FROM series WHERE NOT auto_refresh;");
            if (count != 0)
            {
                context.AddInfo(String.Format("Ignored series: {0}", count));
            }

            sql    = "SELECT t.id, t.identifier, t.cat_description, t1.base_url FROM producttype AS t LEFT JOIN catalogue AS t1 ON t.id_catalogue=t1.id ORDER BY t.identifier;";
            reader = context.GetQueryResult(sql);
            while (reader.Read())
            {
                int    id   = reader.GetInt32(0);
                string name = reader.GetString(1);
                string catalogueDescriptionUrl = reader.GetString(2);
                string catalogueBaseUrl        = context.GetValue(reader, 3);
                if (catalogueDescriptionUrl == null || catalogueDescriptionUrl == String.Empty)
                {
                    context.AddError("No catalogue description URL defined for product type \"" + name + "\"");
                    continue;
                }
                bool usePlaceholder = (catalogueDescriptionUrl.Contains("$(CATALOGUE)") && catalogueBaseUrl != null);
                if (usePlaceholder)
                {
                    catalogueDescriptionUrl = catalogueDescriptionUrl.Replace("$(CATALOGUE)", catalogueBaseUrl);
                }
                string catalogueUrlTemplate = null;
                try {
                    catalogueUrlTemplate = Terradue.Metadata.OpenSearch.OpenSearchDescription.GetUrlTemplate(catalogueDescriptionUrl, new string[] { "application/rdf+xml", "application/xhtml+xml" });
                } catch (XmlException) {
                    context.AddError("Catalogue description URL for product type \"" + name + "\" returns invalid description");
                } catch (Exception) {
                    context.AddError("No catalogue URL template found for product type \"" + name + "\"");
                }
                if (catalogueUrlTemplate == null)
                {
                    continue;
                }
                if (usePlaceholder)
                {
                    catalogueUrlTemplate = catalogueUrlTemplate.Replace(catalogueBaseUrl, "$(CATALOGUE)" + (catalogueBaseUrl.EndsWith("/") ? "/" : String.Empty));
                }
                context.Execute(String.Format("UPDATE producttype SET cat_template={1} WHERE id={0};", id, StringUtils.EscapeSql(catalogueUrlTemplate)));
            }
            reader.Close();
        }