private int GetScore(Activity activity, int userId) { if (activity.OwnerId == userId) { return(context.GetQueryIntegerValue(string.Format("SELECT score_owner FROM priv_score WHERE id_priv={0};", activity.PrivilegeId))); } if (activity.UserId == userId) { return(context.GetQueryIntegerValue(string.Format("SELECT score_usr FROM priv_score WHERE id_priv={0};", activity.PrivilegeId))); } return(0); }
//--------------------------------------------------------------------------------------------------------------------- public static int GetUserId(IfyContext context, string username, AuthenticationType authenticationType) { return(context.GetQueryIntegerValue(String.Format(authenticationType == null ? "SELECT id FROM usr WHERE username={0};" : "SELECT id_usr FROM usr_auth WHERE id_auth={1} AND username={0};", StringUtils.EscapeSql(username), authenticationType == null ? 0 : authenticationType.Id ))); }
//--------------------------------------------------------------------------------------------------------------------- /// <summary> /// Get User from the activation token. /// </summary> /// <returns>The activation token.</returns> /// <param name="context">Context.</param> /// <param name="token">Token.</param> public static User FromActivationToken(IfyContext context, string token) { if (token == null) { throw new ArgumentNullException("token", "No account key or token specified"); } int userId = context.GetQueryIntegerValue(String.Format("SELECT t.id_usr FROM usrreg AS t WHERE t.token={0};", StringUtils.EscapeSql(token))); if (userId == 0) { throw new UnauthorizedAccessException("Invalid account key"); } return(User.ForceFromId(context, userId)); }
//--------------------------------------------------------------------------------------------------------------------- /// <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(); }
//--------------------------------------------------------------------------------------------------------------------- public static int GetIdFromName(IfyContext context, string identifier) { return(context.GetQueryIntegerValue(String.Format("SELECT id FROM series WHERE identifier={0}", StringUtils.EscapeSql(identifier)))); }