웹 관련 함수 생성기
정작 만들고나서 보니까 괜찮기도 하고, 유용하지 않은것 같기도 하고 그러네요.
상당히 발코딩 & 노가다.. (세밀한 구문 하이라이팅 처리는 하지 않았습니다)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Net;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication8
{
public partial class Form1 : Form
{
bool isBack = false;
string ExampleCode = String.Empty;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
richTextBox1.BackColor = BackColor;
comboBox1.SelectedIndex = 0;
}
private void button2_Click(object sender, EventArgs e)
{
richTextBox1.Text = " "; ExampleCode = "";
richTextBox1.SelectionStart = richTextBox1.SelectionStart;
richTextBox1.SelectionColor = Color.Black; richTextBox1.Text = "";
ExampleCode += "private static bool " + (textBox7.Text == String.Empty?"ExampleFunction":textBox7.Text) + "(" + textBox8.Text + (checkBox1.Checked==true?(textBox8.Text!=String.Empty?", ":"") + "CookieContainer cookie":"") + ")" + Environment.NewLine + "{" + Environment.NewLine;
ExampleCode += "\tHttpWebRequest request = (HttpWebRequest)WebRequest.Create(\"" + textBox1.Text + "\");" + Environment.NewLine;
ExampleCode += (radioButton1.Checked == true ? "" : "\trequest.Method = \"POST\";" + Environment.NewLine);
ExampleCode += (textBox2.Text == String.Empty ? "" : "\trequest.Accept = \"" + textBox2.Text + "\";" + Environment.NewLine);
ExampleCode += (textBox3.Text == String.Empty ? "" : "\trequest.ContentType = \"" + textBox3.Text + "\";" + Environment.NewLine);
ExampleCode += (textBox4.Text == String.Empty ? "" : "\trequest.Referer = \"" + textBox4.Text + "\";" + Environment.NewLine);
ExampleCode += (textBox5.Text == String.Empty ? "" : "\trequest.UserAgent = \"" + textBox5.Text + "\";" + Environment.NewLine);
ExampleCode += (checkBox1.Checked == true ? "\trequest.CookieContainer = cookie;" + Environment.NewLine : "") + Environment.NewLine;
string temp = textBox6.Text;
if (textBox6.Text != String.Empty)
{
MatchCollection colMatches;
Regex objRegExp = new Regex("(\\(.+?\\))", RegexOptions.Compiled | RegexOptions.IgnoreCase);
if (objRegExp.IsMatch(textBox6.Text))
{
int cnt = 0;
colMatches = objRegExp.Matches(textBox6.Text);
foreach (Match M in colMatches)
{ cnt++; temp = temp.Replace(M.Value, "\" + " + M.Value.Substring(1, M.Length - 2) + (textBox6.Text.LastIndexOf('(') == M.Index ? (textBox6.Text.LastIndexOf(')') + 1 == textBox6.Text.Length ? "" : " + \"") : " + \"")); }
}
ExampleCode += "\tStreamWriter swriter = new StreamWriter(request.GetRequestStream());" + Environment.NewLine;
ExampleCode += "\tswriter.Write(\"" + temp + (textBox6.Text.LastIndexOf(')') + 1 == textBox6.Text.Length ? "" : "\"") + ");" + Environment.NewLine;
ExampleCode += "\tswriter.Close();" + Environment.NewLine + Environment.NewLine;
}
ExampleCode += "\tHttpWebResponse response = (HttpWebResponse)request.GetResponse();" + Environment.NewLine + Environment.NewLine;
ExampleCode += "\tif (response.StatusCode == HttpStatusCode.OK)" + Environment.NewLine;
ExampleCode += "\t{" + Environment.NewLine;
ExampleCode += "\t\tStream resStream = response.GetResponseStream();" + Environment.NewLine;
ExampleCode += "\t\tStreamReader readStream = new StreamReader(resStream, Encoding." + comboBox1.Text + ");" + Environment.NewLine;
ExampleCode += "\t\tstring result = readStream.ReadToEnd();" + Environment.NewLine + Environment.NewLine;
ExampleCode += "\t\tresStream.Close();" + Environment.NewLine;
ExampleCode += "\t\treadStream.Close();" + Environment.NewLine;
ExampleCode += "\t\tif(조건식) return true;" + Environment.NewLine;
ExampleCode += "\t}" + Environment.NewLine;
ExampleCode += "\treturn false;" + Environment.NewLine;
ExampleCode += "}";
richTextBox1.Text = ExampleCode;
string tokens = "(\\b(private|static|bool|return|false|true|string|" +
"new|StreamReader|StreamWriter|Stream|if|HttpWebResponse|" +
"CookieContainer|HttpWebRequest))";
Regex regXP = new Regex(tokens);
MatchCollection mc = regXP.Matches(richTextBox1.Text);
int sp = richTextBox1.SelectionStart;
foreach (Match M in mc)
{
int startindex = M.Index;
int endindex = M.Length;
richTextBox1.Select(startindex, endindex);
richTextBox1.SelectionColor = Color.RoyalBlue;
}
if (isBack == false) timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (!isBack)
{ Width-=2; if (Width == 458) isBack = true; }
else { Width =(int)((double)Width + 0.1 * (1010 - Width)); }
}
}
}
'소스 관련' 카테고리의 다른 글
| C# 네이버 메일 이미지 업로드 코드 (0) | 2013.02.09 |
|---|---|
| Visual Basic 6으로 만들어진 추첨기 코드 (0) | 2013.02.05 |
| 정규 표현식 테스터(Regular Expression Tester) (3) | 2013.01.03 |
| 헤더를 VB6 코드로 쉽게 변환! (HEADER -> VB6 CODE CONVERTER) (2) | 2013.01.02 |
| POST 데이터 비교(POST Data Compare) (0) | 2013.01.02 |
WindowsFormsApplication8.7z