My favorites | Sign in
Project Logo
       
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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
{
/// <summary>
///
/// </summary>
public class PostQueryStringRuleAction : IRuleAction
{
#region IRuleAction Members

/// <summary>
/// Gets the text.
/// </summary>
/// <value>The text.</value>
public string Text
{
get;
private set;
}

/// <summary>
/// Processes the specified log level.
/// </summary>
/// <param name="logLevel">The log level.</param>
/// <param name="logCategory">The log category.</param>
/// <param name="context">The context.</param>
/// <param name="pattern">The pattern.</param>
/// <param name="url">The URL.</param>
/// <param name="conditionValues">The condition values.</param>
/// <param name="flags">The flags.</param>
/// <returns></returns>
public Uri Execute(int logLevel, string logCategory, HttpContext context, Pattern pattern, Uri url, string[] conditionValues, IDictionary<string, string> 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);
}

/// <summary>
/// Inits the specified text.
/// </summary>
/// <param name="text">The text.</param>
public void Init(string text)
{
Text = text;
}

#endregion
}
}
Show details Hide details

Change log

r26 by nberardi on Dec 09, 2008   Diff
added for post done on 12/9/2009
Go to: 

Older revisions

All revisions of this file

File info

Size: 2132 bytes, 80 lines
Hosted by Google Code