Ejemplo n.º 1
0
        /// <summary>Загрузка выбранных файлов в БД</summary>
        private void _cmdUpLoad_Click(object sender, EventArgs e)
        {
            if (_lstFiles.Items.Count == 0)
            {
                return;
            }

            String connString;

            connString = ConfigurationSettings.AppSettings["ConnectionString"];
            var FM = new FilesManager(connString);

            var progress = new frmProgress(_lstFiles.Items.Count);

            progress.Show();

            for (Int32 i = 0; i <= _lstFiles.Items.Count - 1; i++)
            {
                progress.Tick(1, _lstFiles.Items[i].ToString());
                FM.Upload(_lstFiles.Items[i].ToString());
            }

            progress.Close();
            _lstFiles.Items.Clear();
        }
Ejemplo n.º 2
0
        /// <summary>Первоначальная проверка наличия необходимости запуска процедуры обновления
        /// с последующим запуском обновления</summary>
        public void StartDownload(ref bool breaked)
        {
            try
            {
                if (FilesForUpdate.Count == 0)
                {
                    if (!IsNeedUpdate())
                    {
                        return;
                    }
                }

                var filesManager         = new FilesManager(_connectionString);
                var clientVersionManager = new ClientVersionManager(_xmlFileName);

                long totalSize = 0;
                FilesForUpdate.ForEach(fileInfo => totalSize += fileInfo.FileSize);

                var progressForm = new frmProgress((int)totalSize);
                progressForm.Show();
                progressForm.BringToFront();

                var downloadProgress = new DownloadProgress(totalSize);

                downloadProgress.ProgressChanged +=
                    (sender, e) => progressForm.Tick(e.ChangeSize, string.Format("{0,3:#.#}/{1,3:#.#} MБ ({2})", (decimal)downloadProgress.DownloadedSize / BytesInMegabyte,
                                                                                 (decimal)downloadProgress.TotalSize / BytesInMegabyte, downloadProgress.CurrentFileName));

                foreach (FileInfo fileInfo in FilesForUpdate)
                {
                    try
                    {
                        downloadProgress.SetCurrentFileName(fileInfo.FileName);
                        filesManager.Download(fileInfo.FileName, downloadProgress);
                        clientVersionManager.SetVersion(fileInfo.FileName, fileInfo.ServerVersion);

                        if (progressForm.FormKeyCode == Keys.Escape)
                        {
                            breaked = true;
                            break;
                        }
                    }
                    catch (Exception)
                    {
                        progressForm.Fail();
                        throw;
                    }
                }

                progressForm.Close();
            }
            catch (Exception exception)
            {
                string _errorMessage = string.Format("Ошибка. {0}{1}{2}", exception.Message, Environment.NewLine, exception.StackTrace);
                MessageBox.Show("Ошибка запуска приложения:\r\n", _errorMessage);
            }
        }
Ejemplo n.º 3
0
        private void _cmdInLoad_Click(object sender, EventArgs e)
        {
            String connString;

            connString = ConfigurationSettings.AppSettings["ConnectionString"];
            String versionStorageName;

            versionStorageName = ConfigurationSettings.AppSettings["VersionStorage"];

            SqlConnection cnn    = MiscFunction.OpenConnection(connString);
            const string  sqlStr = "SELECT idFile, version, name, DATALENGTH(binaryData) AS fileSize FROM Srv_ProgramFile";
            var           cmd    = new SqlCommand(sqlStr, cnn);
            SqlDataReader sdr    = cmd.ExecuteReader();

            int version  = sdr.GetOrdinal("version");
            int fileName = sdr.GetOrdinal("name");
            int fileSize = sdr.GetOrdinal("fileSize");

            var clientVersionManager = new ClientVersionManager(versionStorageName);

            FilesForLoad.Clear();
            while (sdr.Read())
            {
                var fileInfo = new FileInfo(sdr.GetString(fileName), clientVersionManager.GetVersion(sdr.GetString(fileName)), sdr.GetInt32(version), sdr.GetInt32(fileSize));

                if (fileInfo.NeedUpdate)
                {
                    FilesForLoad.Add(fileInfo);
                }
            }
            sdr.Close();
            cnn.Close();

            //Вывод в таблицу информации при загрузке файлов из БД
            using (SqlDataAdapter a = new SqlDataAdapter("SELECT version, name, Date FROM Srv_ProgramFile", cnn))
            {
                SqlCommandBuilder cb = new SqlCommandBuilder(a);
                DataSet           ds = new DataSet();
                a.Fill(ds, "Srv_ProgramFile");
                dataGridView1.DataSource = ds.Tables[0];
            }

            #region Процесс загрузки
            try
            {
                var filesManager = new FilesManager(connString);
                var CVManager    = new ClientVersionManager(versionStorageName);

                long totalSize = 0;
                FilesForLoad.ForEach(fileInfo => totalSize += fileInfo.FileSize);

                var progressForm = new frmProgress((int)totalSize);
                progressForm.Show();
                progressForm.BringToFront();

                var downloadProgress = new DownloadProgress(totalSize);

                downloadProgress.ProgressChanged +=
                    (senders, ex) => progressForm.Tick(ex.ChangeSize, string.Format("{0,3:#.#}/{1,3:#.#} MБ ({2})", (decimal)downloadProgress.DownloadedSize / BytesInMegabyte,
                                                                                    (decimal)downloadProgress.TotalSize / BytesInMegabyte, downloadProgress.CurrentFileName));

                foreach (FileInfo fileInfo in FilesForLoad)
                {
                    try
                    {
                        downloadProgress.SetCurrentFileName(fileInfo.FileName);
                        filesManager.Download(fileInfo.FileName, downloadProgress);
                        CVManager.SetVersion(fileInfo.FileName, fileInfo.ServerVersion);
                    }
                    catch (Exception)
                    {
                        progressForm.Fail();
                        throw;
                    }
                }

                progressForm.Close();
            }
            catch (Exception exception)
            {
                string _errorMessage = string.Format("Ошибка. {0}{1}{2}", exception.Message, Environment.NewLine, exception.StackTrace);
                MessageBox.Show("Ошибка запуска приложения:\r\n", _errorMessage);
            }
        }