Пример #1
0
        public JsonResult AddFile(string models)
        {
            JsonResult result = new JsonResult();
            Download bll = new Download();
            List<sd_download> fileList = new List<sd_download>();
            sd_download info = new sd_download();
            if (models != null)
            {

                fileList = JsonConvert.DeserializeObject<List<sd_download>>(models);
                if (fileList.Count > 0)
                {
                  bll.Add(fileList);
                    result.Data = fileList;
                }
            }
            return result;
        }
Пример #2
0
        private static Script genDownload(ScriptContext context, List <string> filteredArgs)
        {
            Script script;

            script    = createEmptyScript(context, "xsharper //download");
            script.Id = "download";
            filteredArgs.AddRange(context.GetStringArray(xs.download));
            script.Usage.Options = UsageOptions.IfHelp | UsageOptions.IfNoArguments | UsageOptions.UsageLine | UsageOptions.AutoSuffix;
            script.Parameters.Add(new CommandLineParameter("uri", CommandLineValueCount.Single, null, null)
            {
                Required = true, Value = "Source URL"
            });
            script.Parameters.Add(new CommandLineParameter("file", CommandLineValueCount.Single, ".", null)
            {
                Value = "Destination file or directory"
            });
            script.Parameters.Add(new CommandLineParameter(null, "cache", CommandLineValueCount.Single, Utils.LowercaseFirstLetter(RequestCacheLevel.Default.ToString()), null)
            {
                Description = "cache-level", Value = "Cache level, one of " + Utils.AllEnumValuesToString(typeof(RequestCacheLevel), " / ")
            });
            script.Parameters.Add(new CommandLineParameter("passive", "activeFtp", CommandLineValueCount.None, true, false)
            {
                Value = "Use active FTP"
            });
            script.Parameters.Add(new CommandLineParameter("userAgent", "userAgent", CommandLineValueCount.Single, null, null)
            {
                Value = "User agent string (http://)"
            });
            script.Parameters.Add(new CommandLineParameter("post", "post", CommandLineValueCount.Single, null, null)
            {
                Value = "HTTP Post string (evaluated as XSharper expression)"
            });
            script.Parameters.Add(new CommandLineParameter("postContentType", "postContentType", CommandLineValueCount.Single, null, null)
            {
                Value = "HTTP Post content type (default is application/x-www-form-urlencoded)"
            });
            script.Parameters.Add(new CommandLineParameter("timeout", "timeout", CommandLineValueCount.Single, null, null)
            {
                Value = "Timeout"
            });
            script.Parameters.Add(new CommandLineParameter("ignoreCertificateErrors", "ignoreCertificateErrors", CommandLineValueCount.None, true, false)
            {
                Value = "Ignore SSL certificate errors "
            });

            script.Add(new Set("oldReceived", "0"));
            script.Add(new SetAttr("d", "cacheLevel", "${cache}"));
            script.Add(new SetAttr("d", "passiveFtp", "${passive}"));
            script.Add(new Set("fn", "${=XS.Download.UrlToLocalFilename($uri,$file)}", TransformRules.Expand));
            script.Add(new Print {
                Value = "Downloading ${=XS.Utils.SecureUri($uri)} => ${fn} ... "
            });
            If ifs1 = new If()
            {
                IsTrue = "${ignoreCertificateErrors}"
            };

            ifs1.Add(new Code("System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };")
            {
                Dynamic = true
            });
            script.Add(ifs1);
            Download d = new Download
            {
                Id              = "d",
                From            = "${uri}",
                To              = "${file}",
                UserAgent       = "${userAgent|=null}",
                Post            = "${=.Expand(${post|=null})}",
                PostContentType = "${postContentType|=null}",
                Timeout         = "${timeout|=null}",
                Transform       = TransformRules.Expand
            };

            If ifs = new If()
            {
                Condition = "${= $.bytesReceived/1024/100 #GT# $oldReceived/1024/100}"
            };

            ifs.Add(new Print(".")
            {
                OutTo = "^info", NewLine = false
            });
            d.Add(ifs);


            d.Add(new Set("oldReceived", "${= $.bytesReceived}", TransformRules.Expand));


            script.Add(d);
            script.Add(new Print {
                Value = "Completed. ${oldReceived} bytes downloaded."
            });
            return(script);
        }
Пример #3
0
 public ActionResult UploadFiles(string models)
 {
     JsonResult result = new JsonResult();
     Download bll = new Download();
     if (models != null)
     {
         try
         {
             sd_download download = JsonConvert.DeserializeObject<sd_download>(models);
             if (!string.IsNullOrEmpty(download.filesize))
             {
                 download.filesize = Math.Round(float.Parse(download.filesize) / 1024, 2).ToString();
             }
             result.Data = bll.Add(download);
         }
         catch (Exception ex)
         {
             result.Data = false;
         }
     }
     return result;
 }