Exemplo n.º 1
0
        /**
         * create
         * Create instance and set required parameters.
         *
         * @param string apiKey
         * @param string testMode
         * @return self
         */
        public static OnlineConvert create(string apiKey, bool testMode = true, String targetType = "")
        {
            OnlineConvert instance = new OnlineConvert(targetType);

            instance.apiKey   = apiKey;
            instance.testMode = testMode;
            return(instance);
        }
Exemplo n.º 2
0
        static void Main(String[] args)
        {
            OnlineConvert.OnlineConvert oc = OnlineConvert.OnlineConvert.create("YOUR API KEY HERE", true, "convert-to-png");

            var a    = oc.convert("convert-to-png", "URL", "http://upload.wikimedia.org/wikipedia/commons/thumb/9/90/Colonial_Williamsburg_%283205781804%29.jpg/100px-Colonial_Williamsburg_%283205781804%29.jpg", "a.png");
            var dica = oc.getXml2Dic(a);

            var directDownloadURL = "";
            Dictionary <int, Dictionary <string, string> > dicb = new Dictionary <int, Dictionary <string, string> >();

            if (dica[1].ContainsKey("hash") && dica[1]["hash"] != "")
            {
                while (true)
                {
                    var b = oc.getProgress(dica[1]["hash"]);
                    dicb = oc.getXml2Dic(b);
                    if (dicb[2].ContainsKey("code") && dicb[2]["code"] == "100")
                    {
                        break;
                    }
                    System.Threading.Thread.Sleep(5000);
                }
                directDownloadURL = dicb[1]["directDownload"];
            }

            if (directDownloadURL != "")
            {
                using (WebClient Client = new WebClient())
                {
                    var webClient = new WebClient();
                    webClient.OpenRead(directDownloadURL);

                    string header_contentDisposition = webClient.ResponseHeaders["content-disposition"];
                    string filename = new ContentDisposition(header_contentDisposition).FileName;

                    filename = filename.Replace("\"", "");
                    webClient.DownloadFile(directDownloadURL, filename);
                }
            }
        }
 /**
  * create
  * Create instance and set required parameters.
  *
  * @param string apiKey
  * @param string testMode
  * @return self
  */
 public static OnlineConvert create(string apiKey, bool testMode = true, String targetType = "")
 {
     OnlineConvert instance = new OnlineConvert(targetType);
     instance.apiKey = apiKey;
     instance.testMode = testMode;
     return instance;
 }