Thursday

how to add new Service to reference.svcmap

Add a new MetadataSource into the file, save it, and Update the reference, all metadata files will be downloaded automatically.
MetaSource tag will be looking like this:
  
<MetadataSource Address="http://localhost/myservices/Services/Service1.svc?wsdl" Protocol="http" SourceId="1" />


Sunday

csharp post form data

     
public string POST(string url, string username,string password, string postParams)
{


//Our getVars, to test the get of our php.
//We can get a page without any of these vars too though.
//string getVars = "?var1=test1&var2=test2";
//Initialization, we use localhost, change if applicable
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(url);
WebReq.UserAgent = GetRndUserAgent();

string Credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(username + ":" + password));

WebReq.Method = "POST";
WebReq.ContentType = "application/xml";
WebReq.AllowWriteStreamBuffering = true;

WebReq.Headers.Add("Authorization", "Basic " + Credentials);

WebReq.ServicePoint.Expect100Continue = false;



// string postParams = "name=some sort of value";
if (postParams != string.Empty)
{
byte[] buffer = ASCIIEncoding.UTF8.GetBytes(postParams);
WebReq.ContentLength = buffer.Length;
using (Stream writer = WebReq.GetRequestStream())
{

writer.Write(buffer, 0, buffer.Length);

}
}

//From here on, it's all the same as above.
HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
//Let's show some information about the response
//_log(WebResp.StatusCode.ToString());
//_log(WebResp.Server);

//Now, we read the response (the string), and output it.
Stream Answer = WebResp.GetResponseStream();
StreamReader _Answer = new StreamReader(Answer);
return _Answer.ReadToEnd();


}

user agent random

     
public static string GetRndUserAgent()
{
string UserAgnet = "";

Random r = new Random();
int i = r.Next(1, 20);

switch (i)
{
case 1:
UserAgnet = "Mozilla/4.0 (compatible; MSIE 7.0; AOL 9.5; AOLBuild 4337.34; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30618)";
break;

case 2:
UserAgnet = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727)";
break;

case 3:
UserAgnet = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser; .NET CLR 2.0.50727; MAXTHON 2.0)";
break;

case 4:
UserAgnet = "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; Media Center PC 3.0; .NET CLR 1.0.3705; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1)";
break;

case 5:
UserAgnet = "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)";
break;

case 6:
UserAgnet = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; InfoPath.2; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618)";
break;

case 7:
UserAgnet = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; Media Center PC 6.0; InfoPath.2; MS-RTC LM 8)";
break;

case 8:
UserAgnet = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en) AppleWebKit/526.9 (KHTML, like Gecko) Version/4.0dp1 Safari/526.8";
break;

case 9:
UserAgnet = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ja; rv:1.9.2a1pre) Gecko/20090402 Firefox/3.6a1pre (.NET CLR 3.5.30729)";
break;

case 10:
UserAgnet = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.8pre) Gecko/20070928 Firefox/2.0.0.7 Navigator/9.0RC1";
break;

case 11:
UserAgnet = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1b4) Gecko/20090423 Firefox/3.5b4 GTB5 (.NET CLR 3.5.30729)";
break;

case 12:
UserAgnet = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/528.16 (KHTML, like Gecko) Version/4.0 Safari/528.16";
break;

case 13:
UserAgnet = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.7pre) Gecko/20070815 Firefox/2.0.0.6 Navigator/9.0b3";
break;

case 14:
UserAgnet = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.2) Gecko/20121223 Ubuntu/9.25 (jaunty) Firefox/3.8";
break;

case 15:
UserAgnet = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.100 Safari/534.30";
break;

case 16:
UserAgnet = "Opera 9.7 (Windows NT 5.2; U; en)";
break;

case 17:
UserAgnet = "Opera/9.64 (X11; Linux x86_64; U; en) Presto/2.1.1";
break;

case 18:
UserAgnet = "Mozilla/5.0 (X11; Linux i686; rv:2.0.1) Gecko/20100101 Firefox/4.0.1)";
break;

case 19:
UserAgnet = "Opera/9.70 (Linux i686 ; U; zh-cn) Presto/2.2.0";
break;

case 20:
UserAgnet = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C; .NET4.0E; Tablet PC 2.0; MALC)";
break;

default:
UserAgnet = "MMozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0";
break;
}

return UserAgnet;
}

imagemagic add text to image

rem different types of text annotations on existing images rem cyan yellow orange gold rem -gravity SouthWest rem draw text and anno...