예제 #1
0
        public ServerInfo.SiRoot ReceiveAutoconfig()
        {
            try
            {
                if (!_isInit)
                {
                    throw new RevEmptySourceException();
                }
                try
                {
                    string outpath = this.__outFileName(_tftpAutoconfigFileName, null);
                    __delTmpFileName(outpath);
                    try
                    {
                        _xftp.Get(_tftpAutoconfigFileName, outpath);
                    }
                    catch (XFTPException e)
                    {
#if NET_DEBUG_TO_LOG
                        this.Fire_ProcessLog(
                            new RevErrorEventArgs(
                                new Exception(
                                    string.Format(
                                        Properties.Resources.fmtXFTPReciveError,
                                        e.ErrorCode,
                                        e.ErrorMessage
                                        )
                                    ),
                                MethodBase.GetCurrentMethod().Name
                                )
                            );
#endif
                        throw new RevEmptySourceException();
                    }
#if NET_DEBUG_TO_LOG
                    catch (Exception e)
                    {
                        this.Fire_ProcessLog(
                            new RevErrorEventArgs(
                                new Exception(string.Format(Properties.Resources.fmtXFTPAllError, e.Message)),
                                MethodBase.GetCurrentMethod().Name
                                )
                            );
#else
                    catch (Exception)
                    {
#endif
                        this.Fire_ProcessLog(
                            new RevErrorEventArgs(
                                new Exception(Properties.Resources.txtAutoconfigError),
                                MethodBase.GetCurrentMethod().Name
                                )
                            );
                        throw new RevEmptySourceException();
                    }
                    if (File.Exists(outpath))
                    {
                        ServerInfo.SiRoot sr = this.__DeserializeXml <ServerInfo.SiRoot>(outpath);
                        if (sr == null)
                        {
                            throw new RevEmptySourceException();
                        }
                        _siroot = sr;
                        __delTmpFileName(outpath);
                        {
                            _siroot.Ipfw             = ((_siroot.Ipfw.Equals("1")) ? Properties.Resources.txtSupport : Properties.Resources.txtNotSupport);
                            _siroot.Ips              = ((_siroot.Ips.Equals("1")) ? Properties.Resources.txtSupport : Properties.Resources.txtNotSupport);
                            _siroot.Ipt              = ((_siroot.Ipt.Equals("1")) ? Properties.Resources.txtSupport : Properties.Resources.txtNotSupport);
                            _siroot.Dnsfilter.Enable = ((_siroot.Dnsfilter.Enable.Equals("1")) ? Properties.Resources.txtSupport : Properties.Resources.txtNotSupport);
                            _siroot.Urlfilter.Enable = ((_siroot.Urlfilter.Enable.Equals("1")) ? Properties.Resources.txtSupport : Properties.Resources.txtNotSupport);
                            _siroot.Xmlparser.Enable = ((_siroot.Xmlparser.Enable.Equals("1")) ? Properties.Resources.txtSupport : Properties.Resources.txtNotSupport);
                        }
                    }
                }
                catch (RevEmptySourceException e)
                {
                    throw e;
                }
                catch (Exception e)
                {
                    this.Fire_ProcessLog(new RevErrorEventArgs(e, MethodBase.GetCurrentMethod().Name));
                    throw new RevEmptySourceException();
                }
            }
            catch (RevEmptySourceException)
            {
                _siroot = new ServerInfo.SiRoot();
            }
            catch (Exception e)
            {
                this.Fire_ProcessLog(new RevErrorEventArgs(e, MethodBase.GetCurrentMethod().Name));
                _siroot = new ServerInfo.SiRoot();
            }
            return(_siroot);
        }
예제 #2
0
        private bool __InitEngine(bool srvType, string srvName, string srvLogin, string srvPwd)
        {
            if (string.IsNullOrEmpty(srvName))
            {
                this.Fire_ProcessLog(
                    new RevErrorEventArgs(
                        new Exception(Properties.Resources.txtServNameEmpty),
                        MethodBase.GetCurrentMethod().Name
                        )
                    );
                return(false);
            }
            if ((srvType) && (string.IsNullOrEmpty(srvLogin)))
            {
                this.Fire_ProcessLog(
                    new RevErrorEventArgs(
                        new Exception(Properties.Resources.txtSrvLoginEmpty),
                        MethodBase.GetCurrentMethod().Name
                        )
                    );
                return(false);
            }
            if ((srvType) && (string.IsNullOrEmpty(srvPwd)))
            {
                this.Fire_ProcessLog(
                    new RevErrorEventArgs(
                        new Exception(Properties.Resources.txtSrvPwdEmpty),
                        MethodBase.GetCurrentMethod().Name
                        )
                    );
                return(false);
            }

            string srvIp = String.Empty;

            _srvType  = srvType;
            _srvLogin = srvLogin;
            _srvPwd   = srvPwd;

            try
            {
                IPAddress[] addrlst = Dns.GetHostAddresses(srvName);
                foreach (IPAddress addr in addrlst)
                {
                    srvIp = addr.ToString();
                    break;
                }
            }
            catch (Exception e)
            {
                this.Fire_ProcessLog(new RevErrorEventArgs(e, MethodBase.GetCurrentMethod().Name));
            }
            if (!string.IsNullOrWhiteSpace(srvIp))
            {
                _srvName = srvIp;
            }
            else
            {
                _srvName = srvName;
            }
            this.Fire_ProcessLog(
                new RevErrorEventArgs(
                    new Exception(
                        string.Format(
                            Properties.Resources.fmtTestConnection,
                            ((_srvType) ? "FTP" : "TFTP"),
                            _srvName
                            )
                        ),
                    MethodBase.GetCurrentMethod().Name
                    )
                );
            try
            {
                if (_srvType)
                {
                    _xftp = new FTPClient(_srvName, _srvLogin, _srvPwd);
                }
                else
                {
                    _xftp = new TFTPClient(_srvName);
                }
                this._siroot = new ServerInfo.SiRoot();
            }
            catch (Exception e)
            {
#if NET_DEBUG_TO_LOG
                this.Fire_ProcessLog(
                    new RevErrorEventArgs(
                        new Exception(string.Format(Properties.Resources.fmtXFTPAllError, e.Message)),
                        MethodBase.GetCurrentMethod().Name
                        )
                    );
#endif
                this.Fire_ProcessLog(new RevErrorEventArgs(e, MethodBase.GetCurrentMethod().Name));
                return(false);
            }
            return(true);
        }