Exemplo n.º 1
0
        internal void InitFileServerInfo(TransferInfo transferInfo)
        {
            HostName = transferInfo.FileServerInfo.HostName;
            if (string.IsNullOrEmpty(HostName))
            {
                throw new ApplicationException(FileServerIsNotSetting);
            }

            string localname = Dns.GetHostName();

            _isLocalMachine = (HostName.ToLower() == localname.ToLower());

            VirtualDirectory = transferInfo.FileServerInfo.VirtualDirectory;
            FileDirectory    = transferInfo.FileServerInfo.FileDirectory;
            FileDirectory    = string.IsNullOrEmpty(FileDirectory) ? "Accessories" : FileDirectory;
            ProtocolType     = transferInfo.FileServerInfo.Connect;
            UploadPostUrl    = transferInfo.FileServerInfo.UploadPostUrl;
            HostPort         = int.Parse(transferInfo.FileServerInfo.Port);
            if (HostPort <= 0)
            {
                switch (ProtocolType.ToUpper())
                {
                case "HTTP":
                    HostPort = 80;
                    break;

                case "FTP":
                    HostPort = 21;
                    break;
                }
                HostUrl = ProtocolType + @"://" + HostName;
            }
            else
            {
                HostUrl = ProtocolType + @"://" + HostName + ":" + HostPort;
            }

            ProtocolType = transferInfo.FileServerInfo.Connect;

            bool isUseProxy = TypeConvert.ToBool(transferInfo.FileServerProxy.IsUsed, false);

            _supportDebug        = TypeConvert.ToBool(transferInfo.FileServerInfo.SupportDebug, true);
            _supportBorkenResume = TypeConvert.ToBool(transferInfo.FileServerInfo.SupportBrokenResume, true);

            if (isUseProxy)
            {
                if (_environment == null)
                {
                    _environment = new WebEnvironment();
                }

                _environment.UseProxy = true;
                _environment.ProxyUrl = transferInfo.FileServerProxy.UriAddress;
                int proxyPort = Int32.Parse(transferInfo.FileServerProxy.Port);
                if (proxyPort != 80 && proxyPort != 21)
                {
                    _environment.ProxyUrl += ":" + proxyPort;
                }
            }

            bool isUserAuth = TypeConvert.ToBool(transferInfo.FileServerAuth.IsUsed, false);

            if (isUserAuth)
            {
                if (_environment == null)
                {
                    _environment = new WebEnvironment();
                }
                if (isUseProxy)
                {
                    _environment.ProxyUsername = transferInfo.FileServerAuth.UserName;
                    _environment.ProxyPassword = transferInfo.FileServerAuth.Password;
                }
                else
                {
                    _environment.Username = transferInfo.FileServerAuth.UserName;
                    _environment.Password = transferInfo.FileServerAuth.Password;
                }
            }
        }