示例#1
0
 public async void CreatecompressSYBDPostg(string Adres_Server, string Way, string Name_SYBD, int id1, string MustBeEx)
 {
     try
     {
         Загрузитьфайл    загрузитьфайл = new Загрузитьфайл(Link, IdUser, client);
         NpgsqlConnection conn1         = new NpgsqlConnection(con1);
         conn1.Open();
         NpgsqlCommand    npgsqlCommand1 = new NpgsqlCommand("SELECT lo_import('" + Name_SYBD + ".bak" + "')", conn1);
         var              oid            = npgsqlCommand1.ExecuteScalar();
         NpgsqlCommand    npgsqlCommand2 = new NpgsqlCommand("SELECT data FROM pg_largeobject WHERE loid =  " + oid + "  ORDER BY pageno", conn1);
         byte[]           s = new byte[] { };
         NpgsqlDataReader npgsqlDataReader = npgsqlCommand2.ExecuteReader();
         int              position         = 0;
         while (npgsqlDataReader.Read())
         {
             s = (byte[])npgsqlDataReader[0];
             DoStuff(s, Name_SYBD, position);
             position = position + s.Length;
         }
         string path            = "./Uploads/" + "/" + Name_SYBD + ".bak";
         string dirName         = new DirectoryInfo(path).Name;
         string time            = DateTime.Now.ToString();
         string archivePath     = "./ToSend/";
         string archivename     = dirName.Remove(dirName.Length - 4, 4) + " " + time.Replace(":", "-");
         string destinationpath = archivePath + archivename + ".gz";
         Compress(path, destinationpath);
         await System.Threading.Tasks.Task.Run(() => загрузитьфайл.загрузитьФайлToolStripMenuItem_Click1(destinationpath, false, id1, MustBeEx));
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message);
     }
 }
示例#2
0
 public async void CreatecompressFile(string a, int id, string MustBeEx)
 {
     try
     {
         Загрузитьфайл загрузитьфайл   = new Загрузитьфайл(Link, IdUser, client);
         string        path            = a;
         string        dirName         = new DirectoryInfo(path).Name;
         string        time            = DateTime.Now.ToString();
         string        archivePath     = "./ToSend/";
         string        archivename     = dirName + " " + time.Replace(":", "-") + ".zip";
         string        destinationpath = archivePath + archivename;
         ZipFile.CreateFromDirectory(path, destinationpath, CompressionLevel.Optimal, true);
         await System.Threading.Tasks.Task.Run(() => загрузитьфайл.загрузитьФайлToolStripMenuItem_Click1(destinationpath, true, id, MustBeEx));
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message);
     }
 }
示例#3
0
 public async void CreatecompressSYBD(string Adres_Server, string Way, string Name_SYBD, int id1, string MustBeEx)
 {
     try
     {
         Загрузитьфайл загрузитьфайл   = new Загрузитьфайл(Link, IdUser, client);
         string        path            = @"\\" + Adres_Server + Way.Remove(0, 2) + "\\" + Name_SYBD + ".bak";
         string        dirName         = new DirectoryInfo(path).Name;
         string        time            = DateTime.Now.ToString();
         string        archivePath     = "./ToSend/";
         string        archivename     = dirName.Remove(dirName.Length - 4, 4) + " " + time.Replace(":", "-");
         string        destinationpath = archivePath + archivename + ".gz";
         Compress(path, destinationpath);
         await System.Threading.Tasks.Task.Run(() => загрузитьфайл.загрузитьФайлToolStripMenuItem_Click1(destinationpath, false, id1, MustBeEx));
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message);
     }
 }
示例#4
0
        public void MakeTask()
        {
            try
            {
                // sqlConnection = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + Path.GetFullPath("Database1.mdf") + ";Integrated Security=True");
                //sqlConnection = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\meschaninov\Desktop\3\ClientFileStorage\Database1.mdf;Integrated Security=True");
                sqlConnection = new SqlConnection(@"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename =" + Path.GetDirectoryName(Path.GetDirectoryName(Application.StartupPath)) + "\\Database1.mdf; Integrated Security = True");
                sqlConnection.Open();
                sqlDataAdapter = new SqlDataAdapter("SELECT *,'Delete' AS [Delete] FROM Task", sqlConnection);
                sqlBuilder     = new SqlCommandBuilder(sqlDataAdapter);
                sqlBuilder.GetInsertCommand();
                sqlBuilder.GetUpdateCommand();
                sqlBuilder.GetDeleteCommand();
                dataSet = new DataSet();
                sqlDataAdapter.Fill(dataSet, "Task");
                Загрузитьфайл загрузитьфайл = new Загрузитьфайл(Link, IdUser, client);

                var Time = DateTime.Now;
                for (int i = 0; i < dataSet.Tables["Task"].Rows.Count; i++)
                {
                    var t = Convert.ToDateTime(dataSet.Tables["Task"].Rows[i][17]).Date;
                    /// ЕСЛИ ФАЙЛ
                    if (Convert.ToBoolean(dataSet.Tables["Task"].Rows[i]["IsFile"]))
                    {
                        int        id1      = (int)dataSet.Tables["Task"].Rows[i]["Id"];
                        string     sql      = "SELECT [FileName] FROM [File] " + "WHERE Idfile = @IdFile";
                        SqlCommand command1 = new SqlCommand(sql, sqlConnection);
                        command1.Parameters.AddWithValue("@IdFile", id1);
                        string a          = command1.ExecuteScalar().ToString();
                        bool   isPeriodic = Convert.ToBoolean(Convert.ToInt32(dataSet.Tables["Task"].Rows[i]["IsPeriodic"]));
                        if (!isPeriodic)
                        {
                            if (Convert.ToDateTime(dataSet.Tables["Task"].Rows[i][17]).Date == Time.Date && Convert.ToDateTime(dataSet.Tables["Task"].Rows[i][17]).Hour == Time.Hour && Convert.ToDateTime(dataSet.Tables["Task"].Rows[i][17]).Minute == Time.Minute)
                            {
                                int    id2      = (int)dataSet.Tables["Task"].Rows[i]["Id"];
                                string MustBeEx = dataSet.Tables["Task"].Rows[i][17].ToString();
                                CreatecompressFile(a, id2, MustBeEx);
                                string     sql1     = "DELETE FROM [File] " + "WHERE IdFile = @IdFile";
                                SqlCommand command3 = new SqlCommand(sql1, sqlConnection);
                                command3.Parameters.AddWithValue("@IdFile", id2);
                                command3.ExecuteNonQuery();
                                dataSet.Tables["Task"].Rows[i].Delete();
                                sqlDataAdapter.Update(dataSet, "Task");
                            }
                        }

                        if (isPeriodic)
                        {
                            if (Time.DayOfWeek == DayOfWeek.Monday)
                            {
                                if (Convert.ToString(dataSet.Tables["Task"].Rows[i][6]).Contains("Понедельник;"))
                                {
                                    bool AOneTimeJob = Convert.ToBoolean(dataSet.Tables["Task"].Rows[i][7]);
                                    if (AOneTimeJob)
                                    {
                                        FileOneTimeJob(a, i);
                                    }
                                    if (!AOneTimeJob)
                                    {
                                        FileRegularJob(a, i);
                                    }
                                }
                            }
                            if (Time.DayOfWeek == DayOfWeek.Tuesday)
                            {
                                if (Convert.ToString(dataSet.Tables["Task"].Rows[i][6]).Contains("Вторник;"))
                                {
                                    bool AOneTimeJob = Convert.ToBoolean(dataSet.Tables["Task"].Rows[i][7]);
                                    if (AOneTimeJob)
                                    {
                                        FileOneTimeJob(a, i);
                                    }
                                    if (!AOneTimeJob)
                                    {
                                        FileRegularJob(a, i);
                                    }
                                }
                            }
                            if (Time.DayOfWeek == DayOfWeek.Wednesday)
                            {
                                if (Convert.ToString(dataSet.Tables["Task"].Rows[i][6]).Contains("Среда;"))
                                {
                                    bool AOneTimeJob = Convert.ToBoolean(dataSet.Tables["Task"].Rows[i][7]);
                                    if (AOneTimeJob)
                                    {
                                        FileOneTimeJob(a, i);
                                    }
                                    if (!AOneTimeJob)
                                    {
                                        FileRegularJob(a, i);
                                    }
                                }
                            }
                            if (Time.DayOfWeek == DayOfWeek.Thursday)
                            {
                                if (Convert.ToString(dataSet.Tables["Task"].Rows[i][6]).Contains("Четверг;"))
                                {
                                    bool AOneTimeJob = Convert.ToBoolean(dataSet.Tables["Task"].Rows[i][7]);
                                    if (AOneTimeJob)
                                    {
                                        FileOneTimeJob(a, i);
                                    }
                                    if (!AOneTimeJob)
                                    {
                                        FileRegularJob(a, i);
                                    }
                                }
                            }
                            if (Time.DayOfWeek == DayOfWeek.Friday)
                            {
                                if (Convert.ToString(dataSet.Tables["Task"].Rows[i][6]).Contains("Пятница;"))
                                {
                                    bool AOneTimeJob = Convert.ToBoolean(dataSet.Tables["Task"].Rows[i][7]);
                                    if (AOneTimeJob)
                                    {
                                        FileOneTimeJob(a, i);
                                    }
                                    if (!AOneTimeJob)
                                    {
                                        FileRegularJob(a, i);
                                    }
                                }
                            }
                            if (Time.DayOfWeek == DayOfWeek.Saturday)
                            {
                                if (Convert.ToString(dataSet.Tables["Task"].Rows[i][6]).Contains("Суббота;"))
                                {
                                    bool AOneTimeJob = Convert.ToBoolean(dataSet.Tables["Task"].Rows[i][7]);
                                    if (AOneTimeJob)
                                    {
                                        FileOneTimeJob(a, i);
                                    }
                                    if (!AOneTimeJob)
                                    {
                                        FileRegularJob(a, i);
                                    }
                                }
                            }
                            if (Time.DayOfWeek == DayOfWeek.Sunday)
                            {
                                if (Convert.ToString(dataSet.Tables["Task"].Rows[i][6]).Contains("Воскресенье;"))
                                {
                                    bool AOneTimeJob = Convert.ToBoolean(dataSet.Tables["Task"].Rows[i][7]);
                                    if (AOneTimeJob)
                                    {
                                        FileOneTimeJob(a, i);
                                    }
                                    if (!AOneTimeJob)
                                    {
                                        FileRegularJob(a, i);
                                    }
                                }
                            }
                        }
                    }
                    /// ИНАЧЕ ( ПАПКА )
                    else
                    {
                        int        id1      = (int)dataSet.Tables["Task"].Rows[i]["Id"];
                        string     sql      = "SELECT [The_Supplier],[Adres_Server],[Port_Server],[Instance_Server],[Login_SYBD],[Password_SYBD],[Way],[Name_SYBD],[Integrated_Security] FROM [SYBD] " + "WHERE IdSYBD = @IdSYBD";
                        SqlCommand command1 = new SqlCommand(sql, sqlConnection);
                        command1.Parameters.AddWithValue("@IdSYBD", id1);
                        SqlDataReader reader = command1.ExecuteReader();
                        while (reader.Read())
                        {
                            The_Supplier = (string)reader[0];
                            Adres_Server = (string)reader[1];
                            if (reader[2].ToString() != null)
                            {
                                Port_Server = (string)reader[2];
                            }
                            if (reader[3].ToString() != null)
                            {
                                Instance_Server = (string)reader[3];
                            }
                            if (reader[4].ToString() != null && reader[5].ToString() != null)
                            {
                                Login_SYBD    = (string)reader[4];
                                Password_SYBD = (string)reader[5];
                            }
                            Way                 = (string)reader[6];
                            Name_SYBD           = (string)reader[7];
                            Integrated_Security = (bool)reader[8];
                        }
                        reader.Close();


                        bool isPeriodic = Convert.ToBoolean(Convert.ToInt32(dataSet.Tables["Task"].Rows[i]["IsPeriodic"]));
                        if (!isPeriodic)
                        {
                            if (Convert.ToDateTime(dataSet.Tables["Task"].Rows[i][15]).Date == Time.Date && Convert.ToDateTime(dataSet.Tables["Task"].Rows[i][16]).TimeOfDay.TotalMinutes >= Time.TimeOfDay.TotalMinutes && Convert.ToDateTime(dataSet.Tables["Task"].Rows[i][16]).TimeOfDay.TotalMinutes <= Time.AddMinutes(1).TimeOfDay.TotalMinutes)
                            {
                                if (The_Supplier == "Microsoft")
                                {
                                    sqlConnection1 = new SqlConnection(@con1);
                                    sqlConnection1.Open();
                                    SqlCommand command2 = new SqlCommand("BACKUP DATABASE[" + Name_SYBD + "] TO  DISK = N'" + Way + "\\" + Name_SYBD + ".bak" + "' WITH NOFORMAT, INIT, NAME = N'" + Name_SYBD + "-Полная База данных Резервное копирование', SKIP, NOREWIND, NOUNLOAD, STATS = 10", sqlConnection1);
                                    command2.CommandTimeout = 10000;
                                    command2.ExecuteNonQuery();
                                    sqlConnection1.Close();
                                    string MustBeEx = dataSet.Tables["Task"].Rows[i][17].ToString();
                                    CreatecompressSYBD(Adres_Server, Way, Name_SYBD, id1, MustBeEx);
                                }
                                if (The_Supplier == "PostgreSQL")
                                {
                                    NpgsqlConnection conn = new NpgsqlConnection(con1);
                                    conn.Open();
                                    NpgsqlCommand npgsqlCommand1 = new NpgsqlCommand("show data_directory", conn);
                                    string        path           = (string)npgsqlCommand1.ExecuteScalar();
                                    NpgsqlCommand npgsqlCommand  = new NpgsqlCommand("select * from public.xp_pg_dump(@dbName, @backupName)", conn);
                                    npgsqlCommand.Parameters.AddWithValue("@dbName", Name_SYBD);
                                    npgsqlCommand.Parameters.AddWithValue("@backupName", path + "/" + Name_SYBD + ".bak");
                                    npgsqlCommand.ExecuteNonQuery();
                                    conn.Close();
                                    string MustBeEx = dataSet.Tables["Task"].Rows[i][17].ToString();
                                    CreatecompressSYBDPostg(Adres_Server, path, Name_SYBD, id1, MustBeEx);
                                }
                                int        id2      = (int)dataSet.Tables["Task"].Rows[i]["Id"];
                                string     sql1     = "DELETE FROM [SYBD] " + "WHERE IdSYBD = @IdSYBD";
                                SqlCommand command3 = new SqlCommand(sql1, sqlConnection);
                                command3.Parameters.AddWithValue("@IdSYBD", id2);
                                command3.ExecuteNonQuery();
                                dataSet.Tables["Task"].Rows[i].Delete();
                                sqlDataAdapter.Update(dataSet, "Task");
                                sqlConnection1.Close();
                            }
                        }

                        if (isPeriodic)
                        {
                            if (Time.DayOfWeek == DayOfWeek.Monday)
                            {
                                if (Convert.ToString(dataSet.Tables["Task"].Rows[i][6]).Contains("Понедельник;"))
                                {
                                    bool AOneTimeJob = Convert.ToBoolean(dataSet.Tables["Task"].Rows[i][7]);
                                    if (AOneTimeJob)
                                    {
                                        FolderOneTimeJob(id1, i);
                                    }
                                    if (!AOneTimeJob)
                                    {
                                        FolderRegularJob(id1, i);
                                    }
                                }
                            }
                            if (Time.DayOfWeek == DayOfWeek.Tuesday)
                            {
                                if (Convert.ToString(dataSet.Tables["Task"].Rows[i][6]).Contains("Вторник;"))
                                {
                                    bool AOneTimeJob = Convert.ToBoolean(dataSet.Tables["Task"].Rows[i][7]);
                                    if (AOneTimeJob)
                                    {
                                        FolderOneTimeJob(id1, i);
                                    }
                                    if (!AOneTimeJob)
                                    {
                                        FolderRegularJob(id1, i);
                                    }
                                }
                            }
                            if (Time.DayOfWeek == DayOfWeek.Wednesday)
                            {
                                if (Convert.ToString(dataSet.Tables["Task"].Rows[i][6]).Contains("Среда;"))
                                {
                                    bool AOneTimeJob = Convert.ToBoolean(dataSet.Tables["Task"].Rows[i][7]);
                                    if (AOneTimeJob)
                                    {
                                        FolderOneTimeJob(id1, i);
                                    }
                                    if (!AOneTimeJob)
                                    {
                                        FolderRegularJob(id1, i);
                                    }
                                }
                            }
                            if (Time.DayOfWeek == DayOfWeek.Thursday)
                            {
                                if (Convert.ToString(dataSet.Tables["Task"].Rows[i][6]).Contains("Четверг;"))
                                {
                                    bool AOneTimeJob = Convert.ToBoolean(dataSet.Tables["Task"].Rows[i][7]);
                                    if (AOneTimeJob)
                                    {
                                        FolderOneTimeJob(id1, i);
                                    }
                                    if (!AOneTimeJob)
                                    {
                                        FolderRegularJob(id1, i);
                                    }
                                }
                            }
                            if (Time.DayOfWeek == DayOfWeek.Friday)
                            {
                                if (Convert.ToString(dataSet.Tables["Task"].Rows[i][6]).Contains("Пятница;"))
                                {
                                    bool AOneTimeJob = Convert.ToBoolean(dataSet.Tables["Task"].Rows[i][7]);
                                    if (AOneTimeJob)
                                    {
                                        FolderOneTimeJob(id1, i);
                                    }
                                    if (!AOneTimeJob)
                                    {
                                        FolderRegularJob(id1, i);
                                    }
                                }
                            }
                            if (Time.DayOfWeek == DayOfWeek.Saturday)
                            {
                                if (Convert.ToString(dataSet.Tables["Task"].Rows[i][6]).Contains("Суббота;"))
                                {
                                    bool AOneTimeJob = Convert.ToBoolean(dataSet.Tables["Task"].Rows[i][7]);
                                    if (AOneTimeJob)
                                    {
                                        FolderOneTimeJob(id1, i);
                                    }
                                    if (!AOneTimeJob)
                                    {
                                        FolderRegularJob(id1, i);
                                    }
                                }
                            }
                            if (Time.DayOfWeek == DayOfWeek.Sunday)
                            {
                                if (Convert.ToString(dataSet.Tables["Task"].Rows[i][6]).Contains("Воскресенье;"))
                                {
                                    bool AOneTimeJob = Convert.ToBoolean(dataSet.Tables["Task"].Rows[i][7]);
                                    if (AOneTimeJob)
                                    {
                                        FolderOneTimeJob(id1, i);
                                    }
                                    if (!AOneTimeJob)
                                    {
                                        FolderRegularJob(id1, i);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (sqlConnection != null)
                {
                    sqlConnection.Close();
                }
                if (sqlConnection1 != null)
                {
                    sqlConnection1.Close();
                }
            }
        }