public static bool gopost(string url, string user, string password, string data, TradeLink.API.DebugDelegate deb, out string result) { debs = deb; Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL); Easy easy = new Easy(); rresult = new StringBuilder(); hasresult = false; Easy.WriteFunction wf = new Easy.WriteFunction(OnWritePostData); easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf); Easy.DebugFunction df = new Easy.DebugFunction(OnDebug); easy.SetOpt(CURLoption.CURLOPT_DEBUGFUNCTION, df); // simple post - with a string easy.SetOpt(CURLoption.CURLOPT_POSTFIELDS, data); Slist sl = new Slist(); sl.Append("Content-Type:application/xml"); sl.Append("Accept: application/xml"); easy.SetOpt(CURLoption.CURLOPT_HTTPHEADER, sl); easy.SetOpt(CURLoption.CURLOPT_SSL_VERIFYPEER, false); easy.SetOpt(CURLoption.CURLOPT_USERAGENT, "Mozilla 4.0 (compatible; MSIE 6.0; Win32"); easy.SetOpt(CURLoption.CURLOPT_FOLLOWLOCATION, true); easy.SetOpt(CURLoption.CURLOPT_USERPWD, user + ":" + password); CURLhttpAuth authflag = CURLhttpAuth.CURLAUTH_BASIC; easy.SetOpt(CURLoption.CURLOPT_HTTPAUTH, authflag); easy.SetOpt(CURLoption.CURLOPT_URL,url); easy.SetOpt(CURLoption.CURLOPT_POST, true); if (debs!=null) easy.SetOpt(CURLoption.CURLOPT_VERBOSE, true); CURLcode err = easy.Perform(); int waits = 0; int maxwaits = 200; while (!hasresult && (waits++<maxwaits)) System.Threading.Thread.Sleep(10); int rcodei = 0; CURLcode rcode = easy.GetInfo(CURLINFO.CURLINFO_RESPONSE_CODE, ref rcodei); if (!hasresult && (deb != null)) deb(easy.StrError(err)); easy.Cleanup(); Curl.GlobalCleanup(); result = rresult.ToString(); return hasresult; }
public static bool ConfirmSubmitCapitalRequest(TradeLink.AppKit.Results rs, bool skip, TradeLink.API.DebugDelegate deb) { d = deb; if (skip) { return false; } CapitalRequestConfim crc = new CapitalRequestConfim(); bool ok = false; if (crc.InvokeRequired) crc.Invoke(new capcondel(ConfirmSubmitCapitalRequest), new object[] { rs, skip, deb }); else { DialogResult dr = crc.ShowDialog(); if (!crc.AskAgain) { // disable tracking } ok = dr == DialogResult.Yes; } if (!ok) return false; return CapitalRequest.Submit(crc.Email, rs, deb); }
public static bool ConfirmSubmitCapitalRequest(TradeLink.AppKit.Results rs, bool skip, TradeLink.API.DebugDelegate deb) { d = deb; if (skip) { return(false); } CapitalRequestConfim crc = new CapitalRequestConfim(); bool ok = false; if (crc.InvokeRequired) { crc.Invoke(new capcondel(ConfirmSubmitCapitalRequest), new object[] { rs, skip, deb }); } else { DialogResult dr = crc.ShowDialog(); if (!crc.AskAgain) { // disable tracking } ok = dr == DialogResult.Yes; } if (!ok) { return(false); } return(CapitalRequest.Submit(crc.Email, rs, deb)); }
public static string GetNetworkAddress(TradeLink.API.DebugDelegate deb) { debs = deb; try { List <string> macs = new List <string>(); foreach (System.Net.NetworkInformation.NetworkInterface ni in System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()) { if (ni.OperationalStatus != System.Net.NetworkInformation.OperationalStatus.Up) { debugs("ignoring non-up network interface: " + ni.Name + " / " + ni.Description + " type: " + ni.NetworkInterfaceType.ToString() + " " + ni.Id); continue; } // skip virtual types if ((ni.NetworkInterfaceType == System.Net.NetworkInformation.NetworkInterfaceType.Slip) || (ni.NetworkInterfaceType == System.Net.NetworkInformation.NetworkInterfaceType.Ppp) || (ni.NetworkInterfaceType == System.Net.NetworkInformation.NetworkInterfaceType.Loopback) || (ni.NetworkInterfaceType == System.Net.NetworkInformation.NetworkInterfaceType.Tunnel) || (ni.NetworkInterfaceType == System.Net.NetworkInformation.NetworkInterfaceType.Unknown)) { debugs("ignoring virtual network interface: " + ni.Name + " / " + ni.Description + " type: " + ni.NetworkInterfaceType.ToString() + " " + ni.Id); continue; } string id = ni.Id; if (string.IsNullOrEmpty(id)) { continue; } id = id.Replace("-", string.Empty); id = id.Replace("{", string.Empty); id = id.Replace("}", string.Empty); macs.Add(id); debugs("found network interface: " + ni.Name + " / " + ni.Description + " type: " + ni.NetworkInterfaceType.ToString() + " " + ni.Id); } // sort for determinism var tmp = macs.ToArray(); Array.Sort(tmp); if (tmp.Length == 0) { return(string.Empty); } debugs("using first sorted network address: " + tmp[0]); // return first return(tmp[0]); } catch { } return(string.Empty); }
public static string string2urlparams(string content, TradeLink.API.DebugDelegate ds) { try { return(System.Web.HttpUtility.UrlEncode(content)); } catch (BadImageFormatException ex) { if (ds != null) { ds("Error, install .net 4 from microsoft to correct. Err: " + ex.Message + ex.StackTrace); } } return(string.Empty); }
/// <summary> /// create a milestone /// </summary> /// <param name="space"></param> /// <param name="user"></param> /// <param name="password"></param> /// <param name="name"></param> /// <param name="description"></param> /// <param name="deb"></param> /// <returns></returns> public static AssemblaMilestone Create(string space, string user, string password, string name, string description, TradeLink.API.DebugDelegate deb) { string url = GetMilestonesUrl(space); StringBuilder data = new StringBuilder(); data.AppendLine("<milestone>"); data.AppendLine("<title>" + name + "</title>"); data.AppendLine("<description>"); data.AppendLine(description); data.AppendLine("</description>"); data.AppendLine("</milestone>"); string result = string.Empty; if (qc.gopost(url, user, password, data.ToString(), SendDebug, out result)) { List <AssemblaMilestone> ms = getms(space, result); return(ms[0]); } return(new AssemblaMilestone()); }
public static string GetNetworkAddress(TradeLink.API.DebugDelegate deb) { debs = deb; try { List<string> macs = new List<string>(); foreach (System.Net.NetworkInformation.NetworkInterface ni in System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()) { if (ni.OperationalStatus != System.Net.NetworkInformation.OperationalStatus.Up) { debugs("ignoring non-up network interface: " + ni.Name + " / " + ni.Description + " type: " + ni.NetworkInterfaceType.ToString() + " " + ni.Id); continue; } // skip virtual types if ((ni.NetworkInterfaceType == System.Net.NetworkInformation.NetworkInterfaceType.Slip) || (ni.NetworkInterfaceType == System.Net.NetworkInformation.NetworkInterfaceType.Ppp) || (ni.NetworkInterfaceType == System.Net.NetworkInformation.NetworkInterfaceType.Loopback) || (ni.NetworkInterfaceType == System.Net.NetworkInformation.NetworkInterfaceType.Tunnel) || (ni.NetworkInterfaceType == System.Net.NetworkInformation.NetworkInterfaceType.Unknown)) { debugs("ignoring virtual network interface: " + ni.Name + " / " + ni.Description + " type: " + ni.NetworkInterfaceType.ToString() + " " + ni.Id); continue; } string id = ni.Id; if (string.IsNullOrEmpty(id)) continue; id = id.Replace("-", string.Empty); id = id.Replace("{", string.Empty); id = id.Replace("}", string.Empty); macs.Add(id); debugs("found network interface: " + ni.Name + " / " + ni.Description + " type: " + ni.NetworkInterfaceType.ToString() + " " + ni.Id); } // sort for determinism var tmp = macs.ToArray(); Array.Sort(tmp); if (tmp.Length == 0) return string.Empty; debugs("using first sorted network address: " + tmp[0]); // return first return tmp[0]; } catch { } return string.Empty; }
/// <summary> /// create a milestone /// </summary> /// <param name="space"></param> /// <param name="user"></param> /// <param name="password"></param> /// <param name="name"></param> /// <param name="description"></param> /// <param name="deb"></param> /// <returns></returns> public static AssemblaMilestone Create(string space, string user, string password, string name, string description, TradeLink.API.DebugDelegate deb) { string url = GetMilestonesUrl(space); HttpWebRequest hr = WebRequest.Create(url) as HttpWebRequest; hr.Credentials = new System.Net.NetworkCredential(user, password); hr.PreAuthenticate = true; hr.Method = "POST"; hr.ContentType = "application/xml"; StringBuilder data = new StringBuilder(); data.AppendLine("<milestone>"); data.AppendLine("<title>" + name + "</title>"); data.AppendLine("<description>"); data.AppendLine(description); data.AppendLine("</description>"); data.AppendLine("</milestone>"); // encode byte[] bytes = UTF8Encoding.UTF8.GetBytes(data.ToString()); hr.ContentLength = bytes.Length; // prepare id int id = 0; try { // write it System.IO.Stream post = hr.GetRequestStream(); post.Write(bytes, 0, bytes.Length); // get response System.IO.StreamReader response = new System.IO.StreamReader(hr.GetResponse().GetResponseStream()); // get string version string rs = response.ReadToEnd(); List <AssemblaMilestone> ms = getms(space, rs); if (ms.Count == 0) { return(new AssemblaMilestone()); } return(ms[0]); } catch (Exception ex) { if (deb != null) { deb("Error creating milestone: " + ex.Message + ex.StackTrace); } } return(new AssemblaMilestone()); }
public static bool gomultipartpost(string url, string user, string password, string fname, string fpath, int ticketid, int maxwaitsec, bool showprogress, TradeLink.API.DebugDelegate deb, out string result) { debs = deb; Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL); Easy easy = new Easy(); rresult = new StringBuilder(); hasresult = false; MultiPartForm mf = new MultiPartForm(); // <input name="frmFileOrigPath"> mf.AddSection(CURLformoption.CURLFORM_COPYNAME, "document[name]", CURLformoption.CURLFORM_COPYCONTENTS, fname, CURLformoption.CURLFORM_END); // <input type="File" name="f1"> mf.AddSection(CURLformoption.CURLFORM_COPYNAME, "document[file]", CURLformoption.CURLFORM_FILE, fpath, CURLformoption.CURLFORM_CONTENTTYPE, "application/octet-stream", CURLformoption.CURLFORM_END); // <input name="frmFileDate"> if (ticketid != 0) { mf.AddSection(CURLformoption.CURLFORM_COPYNAME, "document[ticket_id]", CURLformoption.CURLFORM_COPYCONTENTS, ticketid.ToString(), CURLformoption.CURLFORM_END); } if (showprogress) { Easy.ProgressFunction pf = new Easy.ProgressFunction(OnProgress); easy.SetOpt(CURLoption.CURLOPT_PROGRESSFUNCTION, pf); } Easy.WriteFunction wf = new Easy.WriteFunction(OnWritePostData); easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf); easy.SetOpt(CURLoption.CURLOPT_HTTPPOST, mf); Easy.DebugFunction df = new Easy.DebugFunction(OnDebug); easy.SetOpt(CURLoption.CURLOPT_DEBUGFUNCTION, df); // simple post - with a string //easy.SetOpt(CURLoption.CURLOPT_POSTFIELDS,data); Slist sl = new Slist(); //sl.Append("Content-Type:multipart/form-data"); sl.Append("Accept: application/xml"); easy.SetOpt(CURLoption.CURLOPT_HTTPHEADER, sl); easy.SetOpt(CURLoption.CURLOPT_SSL_VERIFYPEER, false); easy.SetOpt(CURLoption.CURLOPT_USERAGENT, "Mozilla 4.0 (compatible; MSIE 6.0; Win32"); easy.SetOpt(CURLoption.CURLOPT_FOLLOWLOCATION, true); easy.SetOpt(CURLoption.CURLOPT_USERPWD, user + ":" + password); CURLhttpAuth authflag = CURLhttpAuth.CURLAUTH_BASIC; easy.SetOpt(CURLoption.CURLOPT_HTTPAUTH, authflag); easy.SetOpt(CURLoption.CURLOPT_URL, url); //easy.SetOpt(CURLoption.CURLOPT_POST, true); if (debs != null) { easy.SetOpt(CURLoption.CURLOPT_VERBOSE, true); } CURLcode err = easy.Perform(); int waits = 0; int maxwaits = 100 * maxwaitsec; while (!hasresult && (waits++ < maxwaits)) { System.Threading.Thread.Sleep(10); } int rcodei = 0; CURLcode rcode = easy.GetInfo(CURLINFO.CURLINFO_RESPONSE_CODE, ref rcodei); if (!hasresult && (deb != null)) { deb(easy.StrError(err)); } easy.Cleanup(); mf.Free(); Curl.GlobalCleanup(); result = rresult.ToString(); return(hasresult && (rcodei == 201)); }
public static bool gopost(string url, string user, string password, string data, TradeLink.API.DebugDelegate deb, out string result) { debs = deb; Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL); Easy easy = new Easy(); rresult = new StringBuilder(); hasresult = false; Easy.WriteFunction wf = new Easy.WriteFunction(OnWritePostData); easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf); Easy.DebugFunction df = new Easy.DebugFunction(OnDebug); easy.SetOpt(CURLoption.CURLOPT_DEBUGFUNCTION, df); // simple post - with a string easy.SetOpt(CURLoption.CURLOPT_POSTFIELDS, data); Slist sl = new Slist(); sl.Append("Content-Type:application/xml"); sl.Append("Accept: application/xml"); easy.SetOpt(CURLoption.CURLOPT_HTTPHEADER, sl); easy.SetOpt(CURLoption.CURLOPT_SSL_VERIFYPEER, false); easy.SetOpt(CURLoption.CURLOPT_USERAGENT, "Mozilla 4.0 (compatible; MSIE 6.0; Win32"); easy.SetOpt(CURLoption.CURLOPT_FOLLOWLOCATION, true); easy.SetOpt(CURLoption.CURLOPT_USERPWD, user + ":" + password); CURLhttpAuth authflag = CURLhttpAuth.CURLAUTH_BASIC; easy.SetOpt(CURLoption.CURLOPT_HTTPAUTH, authflag); easy.SetOpt(CURLoption.CURLOPT_URL, url); easy.SetOpt(CURLoption.CURLOPT_POST, true); if (debs != null) { easy.SetOpt(CURLoption.CURLOPT_VERBOSE, true); } CURLcode err = easy.Perform(); int waits = 0; int maxwaits = 200; while (!hasresult && (waits++ < maxwaits)) { System.Threading.Thread.Sleep(10); } int rcodei = 0; CURLcode rcode = easy.GetInfo(CURLINFO.CURLINFO_RESPONSE_CODE, ref rcodei); if (!hasresult && (deb != null)) { deb(easy.StrError(err)); } easy.Cleanup(); Curl.GlobalCleanup(); result = rresult.ToString(); return(hasresult); }