Esempio n. 1
0
        internal static void MoveFile(SqliteConnection connection, UPath source, UPath destination)
        {
            var now = Date.Now;

            using (var command = new SqliteCommand(MoveFileQuery, connection))
            {
                command.Parameters.AddWithValue(FilesPath, source.FullName);
                command.Parameters.AddWithValue(FilesDestPath, destination.FullName);

                int affected;
                try
                {
                    affected = command.ExecuteNonQuery();
                }
                catch (SqliteException sex) when(sex.SqliteErrorCode == SQLitePCL.raw.SQLITE_CONSTRAINT)
                {
                    throw FileSystemExceptionHelper.NewFileExistsException(destination, sex);
                }

                if (affected != 1)
                {
                    throw new InvalidOperationException(
                              $"Copying file form {source} to {destination} failed because affected rows did not equal 1.");
                }
            }
        }
Esempio n. 2
0
        internal static void DeleteDirectory(SqliteConnection connection, UPath source)
        {
            using (var command = new SqliteCommand(DeleteDirectoryQuery, connection))
            {
                command.Parameters.AddWithValue(FilesPath, source.FullName);

                int affected = command.ExecuteNonQuery();

                if (affected == 0)
                {
                    throw FileSystemExceptionHelper.NewDirectoryNotFoundException(source);
                }

                if (affected < 1)
                {
                    throw new InvalidOperationException(
                              $"Deleting file form {source} failed because affected rows did not equal 1.");
                }
            }
        }
Esempio n. 3
0
        internal static void MoveDirectory(SqliteConnection connection, UPath source, UPath destination)
        {
            using (var command = new SqliteCommand(MoveDirectoryQuery, connection))
            {
                command.Parameters.AddWithValue(FilesPath, source.FullName);
                command.Parameters.AddWithValue(FilesDestPath, destination.FullName);

                int affected;
                try
                {
                    affected = command.ExecuteNonQuery();
                }
                catch (SqliteException sex) when(sex.SqliteErrorCode == SQLitePCL.raw.SQLITE_CONSTRAINT)
                {
                    throw FileSystemExceptionHelper.NewDestinationDuplicateException(destination, sex);
                }

                if (affected < 2)
                {
                    throw new InvalidOperationException(
                              $"Moving directory file form {source} to {destination} failed because affected rows were not greater or equal than 2.");
                }
            }
        }