コード例 #1
0
        public static bool DeviceLogFile_View(string appName, ConnectInfo connectInfo)
        {
            using (var client = new TimeoutWebClient())
            {
                client.Credentials = new NetworkCredential(connectInfo.User, connectInfo.Password);
                try
                {
                    // Setup
                    string logFile = Application.temporaryCachePath + @"/deviceLog.txt";

                    // Download the file
                    string query = string.Format(kAPI_FileQuery, connectInfo.IP);
                    query += "?knownfolderid=LocalAppData";
                    query += "&filename=UnityPlayer.log";
                    query += "&packagefullname=" + QueryAppDetails(appName, connectInfo).PackageFullName;
                    query += "&path=%5C%5CTempState";
                    client.DownloadFile(query, logFile);

                    // Open it up in default text editor
                    System.Diagnostics.Process.Start(logFile);
                }
                catch (System.Exception ex)
                {
                    Debug.LogError(ex.ToString());
                    return(false);
                }
            }

            return(true);
        }
コード例 #2
0
        /// <summary>
        /// 通过ticket换取二维码
        /// </summary>
        /// <param name="ticket"></param>
        /// <param name="filepath"></param>
        /// <returns></returns>
        public static MediaGetRes Showqrcode(string ticket, string filepath)
        {
            string filename = null;
            string url      = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=";

            url += ticket;

            TimeoutWebClient wc = ThreadWebClientFactory.GetWebClient();

            wc.DownloadFile(url, filepath);

            string disposition = wc.ResponseHeaders["Content-disposition"];

            if (string.IsNullOrEmpty(disposition))
            {
                string json = System.IO.File.ReadAllText(filepath);
                return(JsonConvert.DeserializeObject <MediaGetRes>(json));
            }
            else
            {
                filename = StringHelper.SubString(disposition, "filename=\"", "\"");
            }

            return(new MediaGetRes()
            {
                errcode = "0", filename = filename
            });
        }
コード例 #3
0
        /// <summary>
        /// 获取临时素材
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="media_id"></param>
        /// <param name="filepath"></param>
        /// <returns></returns>
        public static MediaGetRes Media_Get(string access_token, string media_id, string filepath)
        {
            string filename = null;

            string url = "https://api.weixin.qq.com/cgi-bin/media/get?access_token={0}&media_id={1}";

            url = string.Format(url, access_token, media_id);

            TimeoutWebClient wc = ThreadWebClientFactory.GetWebClient();

            wc.DownloadFile(url, filepath);

            string disposition = wc.ResponseHeaders["Content-disposition"];

            if (string.IsNullOrEmpty(disposition))
            {
                string json = System.IO.File.ReadAllText(filepath);
                return(JsonConvert.DeserializeObject <MediaGetRes>(json));
            }
            else
            {
                filename = StringHelper.SubString(disposition, "filename=\"", "\"");
            }

            return(new MediaGetRes()
            {
                errcode = "0", filename = filename
            });
        }
コード例 #4
0
        public static bool DeviceLogFile_View(string appName, ConnectInfo connectInfo)
        {
            using (var client = new TimeoutWebClient())
            {
                client.Credentials = new NetworkCredential(connectInfo.User, connectInfo.Password);
                try
                {
                    // Setup
                    string logFile = Application.temporaryCachePath + @"/deviceLog.txt";

                    // Download the file
                    string query = string.Format(kAPI_FileQuery, connectInfo.IP);
                    query += "?knownfolderid=LocalAppData";
                    query += "&filename=UnityPlayer.log";
                    query += "&packagefullname=" + QueryAppDetails(appName, connectInfo).PackageFullName;
                    query += "&path=%5C%5CTempState";
                    client.DownloadFile(query, logFile);

                    // Open it up in default text editor
                    System.Diagnostics.Process.Start(logFile);
                }
                catch (System.Exception ex)
                {
                    Debug.LogError(ex.ToString());
                    return false;
                }
            }

            return true;
        }
コード例 #5
0
    public bool Download(string url, string filename)
    {
        bool flag = false;

        try
        {
            if (!Directory.Exists(Path.GetDirectoryName(filename)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(filename));
            }

            using (var client = new TimeoutWebClient())
            {
                ServicePointManager.ServerCertificateValidationCallback = MyRemoteCertificateValidationCallback;

                //authorization needed to acces github
                if (Path.GetExtension(filename).Contains("png"))
                {
                    //client.Headers.Add(HttpRequestHeader.Authorization, string.Concat("token ", RepoData.GetToken()));
                }
                client.DownloadFile(new Uri(url), filename + ".tmp");
            }
            flag = true;
            if (File.Exists(filename))
            {
                File.Delete(filename);
            }
            File.Move(filename + ".tmp", filename);
        }
        catch (Exception)
        {
            flag = false;
        }
        return(flag);
    }
コード例 #6
0
ファイル: HttpDldFile.cs プロジェクト: z-one11/ygopro2
    public bool Download(string url, string filename)
    {
        bool flag = false;

        try
        {
            if (!Directory.Exists(Path.GetDirectoryName(filename)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(filename));
            }
            if (File.Exists(filename + ".tmp"))
            {
                File.Delete(filename + ".tmp");
            }
            using (var client = new TimeoutWebClient())
            {
                ServicePointManager.ServerCertificateValidationCallback = MyRemoteCertificateValidationCallback;

                if (Path.GetExtension(filename).Contains("png"))
                {
                    client.Timeout = 6500;
                }
                if (Path.GetExtension(filename).Contains("jpg"))
                {
                    client.Timeout = 3500;
                }
                if (Path.GetExtension(filename).Contains("cdb"))
                {
                    client.Timeout = 30000;
                }
                if (Path.GetExtension(filename).Contains("conf"))
                {
                    client.Timeout = 3000;
                }
                client.DownloadFile(new Uri(url), filename + ".tmp");
            }
            flag = true;
            if (File.Exists(filename))
            {
                File.Delete(filename);
            }
            File.Move(filename + ".tmp", filename);
        }
        catch (Exception)
        {
            if (File.Exists(filename + ".tmp"))
            {
                File.Delete(filename + ".tmp");
            }
            flag = false;
        }
        return(flag);
    }
コード例 #7
0
        private bool DownloadFile(string Url, string SavePath)
        {
            try {
                TimeoutWebClient client = new TimeoutWebClient();
                client.TimeOut = 5000;
                client.DownloadFile(Url, SavePath);

                return(true);
            } catch (Exception e) {
                System.Diagnostics.Debug.WriteLine(e);
                return(false);
            }
        }
コード例 #8
0
ファイル: FilePuller.cs プロジェクト: machinechina/CDN
        protected override void DoWork()
        {
            using (var session = _queue.OpenSession())
            {
                byte[] data;
                while ((data = session.Dequeue()) != null)
                {
                    var url = Encoding.UTF8.GetString(data);
                    try
                    {
                        Info("Begin download:" + url);

                        //下载资源 比较修改日期
                        //默认是最新,如果获取不到当作最新的
                        DateTime lastModified; string fileName;
                        GetHeaderFromUrl(url, out fileName, out lastModified);

                        var filePathName = GetPhysicalPathByOriginalUrl(url, _fileStorePath, fileName);
                        if (lastModified > File.GetLastWriteTime(filePathName))
                        {
                            //同步下载直到完成
                            var _retry = _maxRetryTimes;
                            while (_retry >= 0)
                            {
                                try
                                {
                                    using (var webClient = new TimeoutWebClient(_downloadTimeout))
                                        webClient.DownloadFile(url, filePathName);

                                    //使文件修改时间和服务器一致,以比较是否更新
                                    File.SetLastWriteTime(filePathName, lastModified);
                                }
                                catch (Exception)
                                {
                                    if (_retry == 0)
                                    {
                                        throw;
                                    }
                                    Thread.Sleep(5000);
                                    Info($"Retry download:({_retry})" + url);
                                    _retry--;
                                }
                                _retry = -1;
                            }

                            Info("Finish download:" + url);
                        }
                        else
                        {
                            Info("File already exists:" + url);
                        }
                    }
                    catch (TimeoutException ex)
                    {
                        Info("Timeout downloading:" + url);
                        throw new Exception("Timeout downloading:" + url, ex);
                    }
                    catch (Exception ex)
                    {
                        Info("Error downloading:" + url);
                        throw new Exception("Error downloading:" + url, ex);
                    }
                    finally
                    {
                        session.Flush();
                    }
                }
            }
        }