// Brian DeMarzo
// brian@demarzo.net
#region Copyright � 2003 The Favalias Group
/*
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the
* use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not claim
* that you wrote the original software. If you use this software in a product,
* an acknowledgment in the product documentation is required, as shown here:
*
* Portions Copyright � 2003 The Favalias Group (http://sourceforge.net/projects/favalias).
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source distribution.
*/
#endregion
using Favalias.Common;
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Reflection;
using System.Text;
using System.Web;
using System.Windows.Forms;
using Genghis;
using clp = Genghis.CommandLineParser;
namespace Favalias.ConverterAddins
{
[Serializable]
/// <summary>
/// Translates a URL-encoded text string into a text string. Returns output to the clipboard.
/// </summary>
public class UrlDecoder : Favalias.Interfaces.IFavaliasAddin
{
#region CLP
[clp.ParserUsage("URL decoder. Generates a URL decoded string from the input string.", AllowArgumentFile=false)]
private class argsParser : CommandLineParser
{
[clp.FlagUsage( "silent mode", Name="s", AllowOnOff = false ) ]
public bool silent = false;
[clp.ValueUsage("URL string to decode (if not specified, decode the string copied in memory)", Name = "inputString", MatchPosition = true, Optional = true )]
public StringCollection inputString = new StringCollection();
}
#endregion
#region Initialization
public UrlDecoder()
{
}
#endregion
#region IFavaliasAddin Members
public void Execute(string[] args, Hashtable parameters)
{
string inputString = null;
bool silent = false;
argsParser parser = new argsParser();
if ( !parser.ParseAndContinue(args, (string)parameters["aliasName"], Assembly.GetExecutingAssembly()))
return;
silent = parser.silent;
inputString = Utilities.StringCollectionToString(parser.inputString);
if ( ( inputString.Length == 0 ) )
inputString = Utilities.ClipboardContent;
string outputString = HttpUtility.UrlDecode( inputString );
if ( !silent )
{ //MessageBox.Show("The URL decoded string is : \r\n\r\n" + outputString + "\r\n\r\n(It is already copied in memory,\r\n you can paste it with ctrl+V)", "URL decoded string", MessageBoxButtons.OK, MessageBoxIcon.Information);
Utilities.ShowAnimateMessageWithTextBox("The URL decoded string is :", outputString, (string)parameters["skin"]);
}
Utilities.ClipboardContent = outputString;
}
#endregion
}
[Serializable]
/// <summary>
/// Translates a text string into a URL-encoded text string. Returns output to the clipboard.
/// </summary>
public class UrlEncoder : Favalias.Interfaces.IFavaliasAddin
{
#region CLP
[clp.ParserUsage("URL encoder. Generates a URL encoded string from the input string", AllowArgumentFile=false)]
private class argsParser : CommandLineParser
{
[clp.FlagUsage( "silent mode", Name="s", AllowOnOff = false, Optional = true ) ]
public bool silent = false;
[clp.ValueUsage( "URL string to encode (if not specified, encode the string copied in memory)", Name = "inputString", MatchPosition = true, Optional = true )]
public StringCollection inputString = new StringCollection();
}
#endregion
#region Initialization
public UrlEncoder()
{
}
#endregion
#region IFavaliasAddin Members
public void Execute(string[] args, Hashtable parameters)
{
string inputString = null;
bool silent = false;
argsParser parser = new argsParser();
if ( !parser.ParseAndContinue(args, (string)parameters["aliasName"], Assembly.GetExecutingAssembly()))
return;
silent = parser.silent;
inputString = Utilities.StringCollectionToString(parser.inputString);
if ( ( inputString.Length == 0 ) )
inputString = Utilities.ClipboardContent;
string outputString = HttpUtility.UrlEncode( inputString );
if ( !silent )
{
//MessageBox.Show("The URL encoded string is : \r\n\r\n" + outputString + "\r\n\r\n(It is already copied in memory,\r\n you can paste it with ctrl+V)", "URL encoded string", MessageBoxButtons.OK, MessageBoxIcon.Information);
Utilities.ShowAnimateMessageWithTextBox("The URL encoded string is : ", outputString, (string)parameters["skin"]);
}
Utilities.ClipboardContent = outputString;
}
#endregion
}
}