コード例 #1
0
        //---------------------------------------------------------------------------------------------------------------------

        public static void LoadPrivileges(IfyContext context)
        {
            privileges.Clear();
            IDataReader reader = context.GetQueryResult("SELECT t.id, t.identifier, t.name, t.id_type, t.operation, t.enable_log FROM priv AS t ORDER BY t.pos;");

            while (reader.Read())
            {
                int                 id           = context.GetIntegerValue(reader, 0);
                int                 entityTypeId = context.GetIntegerValue(reader, 3);
                EntityType          entityType   = entityTypeId == 0 ? null : EntityType.GetEntityTypeFromId(entityTypeId);
                EntityOperationType operation    = GetOperationType(context.GetValue(reader, 4));

                Privilege privilege = new Privilege(
                    id,
                    context.GetValue(reader, 1),
                    context.GetValue(reader, 2),
                    entityType,
                    operation,
                    context.GetBooleanValue(reader, 5)
                    );
                privileges[id] = privilege;
            }
            reader.Close();
        }
コード例 #2
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();
        }