using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO;
using System.Text.RegularExpressions;
using ZennoLab.CommandCenter;
using ZennoLab.InterfacesLibrary;
using ZennoLab.InterfacesLibrary.ProjectModel;
using ZennoLab.InterfacesLibrary.ProjectModel.Collections;
using ZennoLab.InterfacesLibrary.ProjectModel.Enums;
using ZennoLab.Macros;
using Global.ZennoExtensions;
using ZennoLab.Emulation;
using System.Net.Http;
namespace ZennoLab.OwnCode
{
/// <summary>
/// A simple class of the common code
/// </summary>
public class CommonCode
{
/// <summary>
/// Lock this object to mark part of code for single thread execution
/// </summary>
public static object SyncObject = new object();
// Insert your code here
public static string SendPhoto (string photo, string url_telegram){
var sBoundary = DateTime.Now.Ticks.ToString("x");
var contentType = "multipart/form-data";
string sPostMultiString = "";
// функция сбора данных
Func<string, string, string, string> multiFormDataText = delegate(string key, string value, string boundary) {
var output = string.Format("--{0}\r\n", boundary);
output += string.Format("Content-Disposition: form-data; name=\"{0}\"\r\n\r\n", key);
output += value + "\r\n";
return output;
};
// функция сбора данных
Func<string, string, string, string, string, string> multiFormDataFile = delegate(string key, string value, string fileName, string fileType, string boundary) {
var output = string.Format("--{0}\r\n", boundary);
output += string.Format("Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n", key, fileName);
output += string.Format("Content-Type: {0}\r\n\r\n", fileType);
output += string.Format("{0}\r\n", value);
return output;
};
// другие поля
sPostMultiString += multiFormDataText("action", "upload", sBoundary);
// файл
var fileInfo = new System.IO.FileInfo(photo);
sPostMultiString += multiFormDataText("width", fileInfo.Name, sBoundary);
sPostMultiString += multiFormDataFile("photo", fileInfo.FullName, fileInfo.Name, "image/png", sBoundary);
string str = ZennoPoster.HttpPost(url_telegram, sPostMultiString, contentType,"","",ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.HeaderAndBody,30);
return str;
}
}
}