コード例 #1
0
ファイル: Xbmc.File.cs プロジェクト: vageesh79/FrontView
        public bool Download(string fileName, string destination)
        {
            _parent.Trace("----------DOWNLOAD IMAGES ISSUE:  fileNAME is" + fileName + "  : Destination is: " + destination);

            if (!_parent.IsConnected())
            {
                _parent.Trace(" ---------------DOWNLOAD ISSUES ISSUE:  PARENT NOT CONNECTING RETURNING FALSE");
                return(false);
            }

            try
            {
                using (var client = new WebClient())
                {
                    var credentials = _parent.GetCredentials();


                    if (credentials != null)
                    {
                        client.Credentials = credentials;
                    }

                    client.Headers.Add("X-MediaBrowser-Token", Globals.EmbyAuthToken);
                    //Add Header Client - ? helps
                    client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");

                    client.DownloadFile(_parent.GetDownloadPath(fileName), destination);
                }
                _parent.Trace("DOWNLOAD : " + fileName);
                return(true);
            }
            catch (WebException ex)
            {
                _parent.Trace("EMBY DOWNLOAD ERROR - DOWNLOAD : " + _parent.GetDownloadPath(fileName) + " " + ex.Message);
            }
            catch (System.Exception ex)
            {
                _parent.Trace("EMBY DOWNLOAD ISSUE: EXCEPTION CAUGHT:" + ex);
            }
            return(false);
        }