/// <summary>
        /// Downloads the update dialog load.
        /// </summary>
        private void DownloadUpdateDialogLoad()
        {
            _webClient = new AutoUpdaterWebClient {
                CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore)
            };
            var uri = new Uri(_downloadURL);

            if (AutoUpdaterPlugin.Proxy != null)
            {
                _webClient.Proxy = AutoUpdaterPlugin.Proxy;
            }

            if (string.IsNullOrEmpty(AutoUpdaterPlugin.DownloadPath))
            {
                _tempFile = Path.GetTempFileName();
            }
            else
            {
                _tempFile = Path.Combine(AutoUpdaterPlugin.DownloadPath, string.Format("{0}.tmp", Guid.NewGuid()));
                if (!Directory.Exists(AutoUpdaterPlugin.DownloadPath))
                {
                    Directory.CreateDirectory(AutoUpdaterPlugin.DownloadPath);
                }
            }
            _webClient.DownloadProgressChanged += OnDownloadProgressChanged;
            _webClient.DownloadFileCompleted   += WebClientOnDownloadFileCompleted;
            _webClient.DownloadFileAsync(uri, _tempFile);
        }
        private void DownloadSQLCompleted(object sender, AsyncCompletedEventArgs asyncCompletedEventArgs)
        {
            string fileName;
            var    contentDisposition = _webClient.ResponseHeaders["Content-Disposition"] ?? string.Empty;

            if (string.IsNullOrEmpty(contentDisposition))
            {
                fileName = Path.GetFileName(_webClient.ResponseUri.LocalPath);
            }
            else
            {
                fileName = TryToFindFileName(contentDisposition, "filename=");
                if (string.IsNullOrEmpty(fileName))
                {
                    fileName = TryToFindFileName(contentDisposition, "filename*=UTF-8''");
                }
            }
            var tempPath = Path.Combine(string.IsNullOrEmpty(AutoUpdaterPlugin.DownloadPath) ? Path.GetTempPath() : AutoUpdaterPlugin.DownloadPath, fileName);

            try
            {
                if (File.Exists(tempPath))
                {
                    File.Delete(tempPath);
                }
                File.Move(_tempFile, tempPath);
                PathSqlFile = tempPath.ToString();
            }
            catch (Exception e)
            {
                LogAutoUpdater.Error(e.Message);
                MessageBox.Show(e.Message, e.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
                _webClient = null;
                Close();
                return;
            }
            DownloadUpdateDialogLoad();//Start download BIN
        }
        /// <summary>
        /// Webs the client on download file completed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="asyncCompletedEventArgs">The <see cref="AsyncCompletedEventArgs"/> instance containing the event data.</param>
        private void WebClientOnDownloadFileCompleted(object sender, AsyncCompletedEventArgs asyncCompletedEventArgs)
        {
            if (asyncCompletedEventArgs.Cancelled)
            {
                return;
            }
            if (asyncCompletedEventArgs.Error != null)
            {
                MessageBox.Show(asyncCompletedEventArgs.Error.Message, asyncCompletedEventArgs.Error.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
                _webClient = null;
                Close();
                return;
            }
            if (!string.IsNullOrEmpty(AutoUpdaterPlugin.Checksum))
            {
                if (!CompareChecksum(_tempFile, AutoUpdaterPlugin.Checksum))
                {
                    _webClient = null;
                    Close();
                    return;
                }
            }

            string fileName;
            var    contentDisposition = _webClient.ResponseHeaders["Content-Disposition"] ?? string.Empty;

            if (string.IsNullOrEmpty(contentDisposition))
            {
                fileName = Path.GetFileName(_webClient.ResponseUri.LocalPath);
            }
            else
            {
                fileName = TryToFindFileName(contentDisposition, "filename=");
                if (string.IsNullOrEmpty(fileName))
                {
                    fileName = TryToFindFileName(contentDisposition, "filename*=UTF-8''");
                }
            }
            var tempPath = Path.Combine(string.IsNullOrEmpty(AutoUpdaterPlugin.DownloadPath) ? Path.GetTempPath() : AutoUpdaterPlugin.DownloadPath, fileName);

            try
            {
                if (File.Exists(tempPath))
                {
                    File.Delete(tempPath);
                }
                File.Move(_tempFile, tempPath);
            }
            catch (Exception e)
            {
                LogAutoUpdater.Error(e.Message);
                MessageBox.Show(e.Message, e.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
                _webClient = null;
                Close();
                return;
            }

            var processStartInfo = new ProcessStartInfo
            {
                FileName        = tempPath,
                UseShellExecute = true,
                Arguments       = AutoUpdaterPlugin.InstallerArgs.Replace("%path%", Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName))
            };
            var extension = Path.GetExtension(tempPath);

            //tam thoi thangnd xu ly file zip truoc da
            if (extension.Equals(".zip", StringComparison.OrdinalIgnoreCase))
            {
                var installerPath = Path.Combine(Path.GetDirectoryName(tempPath), "ZipExtractor.exe");
                File.WriteAllBytes(installerPath, Resources.ZipExtractor);
                var arguments = new StringBuilder(string.Format("\"{0}\" \"{1}\" \"{2}\"", tempPath, Process.GetCurrentProcess().MainModule.FileName, PathSqlFile));
                var args      = Environment.GetCommandLineArgs();
                for (var i = 1; i < args.Length; i++)
                {
                    if (i.Equals(1))
                    {
                        arguments.Append(" \"");
                    }
                    arguments.Append(args[i]);
                    arguments.Append(i.Equals(args.Length - 1) ? "\"" : " ");
                }
                processStartInfo = new ProcessStartInfo
                {
                    FileName        = installerPath,
                    UseShellExecute = true,
                    Arguments       = arguments.ToString()
                };
            }

            if (AutoUpdaterPlugin.RunUpdateAsAdmin)
            {
                processStartInfo.Verb = "runas";
            }

            try
            {
                Process.Start(processStartInfo);
            }
            catch (Win32Exception exception)
            {
                _webClient = null;
                if (exception.NativeErrorCode != 1223)
                {
                    throw;
                }
            }

            Close();
        }