Beispiel #1
0
        /// <summary>
        /// Return True if can init db connection
        /// </summary>
        /// <returns></returns>
        bool Init_DbConnection()
        {
            var cs = ConfigurationManager.AppSettings.Get("ConnectionString");

            // fix the bug Dialect Postgresql provider wrong datetime
            SqlServerOrmLiteDialectProvider dialect = SqlServerOrmLiteDialectProvider.Instance;

            dialect.UseUnicode = true;
            dialect.UseDatetime2(true);
            dialect.StringColumnDefinition                       = "nvarchar(MAX)";
            dialect.StringLengthColumnDefinitionFormat           = dialect.StringColumnDefinition;
            dialect.StringLengthNonUnicodeColumnDefinitionFormat = dialect.StringColumnDefinition;
            dialect.StringLengthUnicodeColumnDefinitionFormat    = dialect.StringColumnDefinition;
            dialect.NamingStrategy = new ABNamingStrategy();
            dbFactory = new OrmLiteConnectionFactory(cs, dialect);
            dbFactory.AutoDisposeConnection = true;

            // now we try to open a connection to check
            try
            {
                PATH_DECRYPTION_INPUT  = Db_GetSetting(Enum_Settings_Key.WEBSITE_DGL_AUTODECRYPT_INPUT, System.IO.Path.GetTempPath(), Enum_Settings_DataType.String).ToString();
                PATH_DECRYPTION_OUTPUT = Db_GetSetting(Enum_Settings_Key.WEBSITE_DGL_AUTODECRYPT_OUTPUT, System.IO.Path.GetTempPath(), Enum_Settings_DataType.String).ToString();

                log.Log(string.Format("Auto Decryption: Input folder = {0}, Output = {1}", PATH_DECRYPTION_INPUT, PATH_DECRYPTION_OUTPUT));
            }
            catch (Exception ex)
            {
                log.Log("Auto Decryption");
                log.Log(ex);
                return(false);
            }

            return(true);
        }
Beispiel #2
0
        private void InitFTPConnection()
        {
            try
            {
                ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
                { return(true); };

                ftpClient = new FtpClient();

                ftpClient.Host = config.FTPHost;

                ftpClient.Port = config.Port;

                ftpClient.SocketKeepAlive = true;

                // connection mode
                switch (config.ConnectionMode)
                {
                case 0:
                    // auto
                    break;

                case 1:
                    // Active
                    ftpClient.DataConnectionType = FtpDataConnectionType.AutoActive;
                    break;

                case 2:
                    // passive
                    ftpClient.DataConnectionType = FtpDataConnectionType.EPSV;
                    break;

                default:
                    //ftpClient.DataConnectionType = FtpDataConnectionType.AutoPassive;
                    break;
                }

                ftpClient.EncryptionMode = (FtpEncryptionMode)config.SSLEncryptionMode;

                ftpClient.Credentials = new NetworkCredential(config.UserName, config.Password);

                if (!config.FTPDefaultPath.EndsWith("/"))
                {
                    config.FTPDefaultPath += "/";
                }

                ftpClient.ValidateCertificate += new FtpSslValidation(ftpClient_ValidateCertificate);
                syncDurationLength             = (24 * 60) / config.SyncsTime;

                log.Log("Connecting to FTP Server " + config.FTPHost + " with username " + config.UserName);
                ftpClient.Connect();
                ftpClient.SetWorkingDirectory(config.FTPDefaultPath);
                log.Log("Connected to FTP Server " + config.FTPHost);
                log.Log("Server HASH support: " + ftpClient.HashAlgorithms.ToString());
            }
            catch (Exception ex)
            {
                log.Log("Can not connect to FTP host" + config.FTPHost);
                log.Log(ex);
            }
        }