using System; using System.Collections.Generic; using System.Data; using System.Web; using ManagedFusion.Rewriter; using MySql.Data.MySqlClient; using System.Diagnostics; namespace CoderJournal.Rewriter.Rules { /// /// /// public class PostQueryStringRuleAction : IRuleAction { #region IRuleAction Members /// /// Gets the text. /// /// The text. public string Text { get; private set; } /// /// Processes the specified log level. /// /// The log level. /// The log category. /// The context. /// The pattern. /// The URL. /// The condition values. /// The flags. /// public Uri Execute(int logLevel, string logCategory, HttpContext context, Pattern pattern, Uri url, string[] conditionValues, IDictionary flags) { string inputUrl = url.GetComponents(UriComponents.PathAndQuery, UriFormat.UriEscaped); string sqlCommand = pattern.Replace(inputUrl, Text, conditionValues); string substituedUrl = String.Empty; using (MySqlConnection connection = new MySqlConnection(Properties.Settings.Default.DatabaseConnection)) { using (MySqlCommand command = connection.CreateCommand()) { command.CommandText = sqlCommand; command.CommandType = CommandType.Text; try { connection.Open(); substituedUrl = command.ExecuteScalar() as string; } finally { connection.Close(); } } } Trace.WriteLineIf(logLevel >= 2, "Output: " + substituedUrl, logCategory); return new Uri(url, substituedUrl); } /// /// Inits the specified text. /// /// The text. public void Init(string text) { Text = text; } #endregion } }