Exemple #1
0
        public async Task ExecuteAsync(CancellationToken cancellationToken = default)
        {
            EnsureDatabase();

            try
            {
                await OpenAsync(cancellationToken).ConfigureAwait(false);

                var startSpb = new ServiceParameterBuffer2();
                startSpb.Append(IscCodes.isc_action_svc_restore);
                foreach (var bkpFile in BackupFiles)
                {
                    startSpb.Append2(IscCodes.isc_spb_bkp_file, bkpFile.BackupFile, SpbFilenameEncoding);
                }
                startSpb.Append2(IscCodes.isc_spb_dbname, Database, SpbFilenameEncoding);
                if (Verbose)
                {
                    startSpb.Append(IscCodes.isc_spb_verbose);
                }
                if (PageBuffers.HasValue)
                {
                    startSpb.Append(IscCodes.isc_spb_res_buffers, (int)PageBuffers);
                }
                if (_pageSize.HasValue)
                {
                    startSpb.Append(IscCodes.isc_spb_res_page_size, (int)_pageSize);
                }
                startSpb.Append(IscCodes.isc_spb_res_access_mode, (byte)(ReadOnly ? IscCodes.isc_spb_res_am_readonly : IscCodes.isc_spb_res_am_readwrite));
                if (!string.IsNullOrEmpty(SkipData))
                {
                    startSpb.Append2(IscCodes.isc_spb_res_skip_data, SkipData);
                }
                startSpb.Append(IscCodes.isc_spb_options, (int)Options);
                startSpb.Append2(IscCodes.isc_spb_res_stat, Statistics.BuildConfiguration());
                await StartTaskAsync(startSpb, cancellationToken).ConfigureAwait(false);

                if (Verbose)
                {
                    await ProcessServiceOutputAsync(ServiceParameterBufferBase.Empty, cancellationToken).ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                throw FbException.Create(ex);
            }
            finally
            {
                await CloseAsync(cancellationToken).ConfigureAwait(false);
            }
        }
    public async Task ExecuteAsync(CancellationToken cancellationToken = default)
    {
        EnsureDatabase();

        try
        {
            await OpenAsync(cancellationToken).ConfigureAwait(false);

            var startSpb = new ServiceParameterBuffer2();
            startSpb.Append(IscCodes.isc_action_svc_backup);
            startSpb.Append2(IscCodes.isc_spb_dbname, Database, SpbFilenameEncoding);
            foreach (var file in BackupFiles)
            {
                startSpb.Append2(IscCodes.isc_spb_bkp_file, file.BackupFile, SpbFilenameEncoding);
                if (file.BackupLength.HasValue)
                {
                    startSpb.Append(IscCodes.isc_spb_bkp_length, (int)file.BackupLength);
                }
            }
            if (Verbose)
            {
                startSpb.Append(IscCodes.isc_spb_verbose);
            }
            if (Factor > 0)
            {
                startSpb.Append(IscCodes.isc_spb_bkp_factor, Factor);
            }
            if (!string.IsNullOrEmpty(SkipData))
            {
                startSpb.Append2(IscCodes.isc_spb_bkp_skip_data, SkipData);
            }
            startSpb.Append(IscCodes.isc_spb_options, (int)Options);
            startSpb.Append2(IscCodes.isc_spb_bkp_stat, Statistics.BuildConfiguration());
            await StartTaskAsync(startSpb, cancellationToken).ConfigureAwait(false);

            if (Verbose)
            {
                await ProcessServiceOutputAsync(ServiceParameterBufferBase.Empty, cancellationToken).ConfigureAwait(false);
            }
        }
        catch (Exception ex)
        {
            throw FbException.Create(ex);
        }
        finally
        {
            await CloseAsync(cancellationToken).ConfigureAwait(false);
        }
    }
Exemple #3
0
        public async Task <FbUserData[]> DisplayUsersAsync(CancellationToken cancellationToken = default)
        {
            await OpenAsync(cancellationToken).ConfigureAwait(false);

            var startSpb = new ServiceParameterBuffer2();

            startSpb.Append(IscCodes.isc_action_svc_display_user);
            await StartTaskAsync(startSpb, cancellationToken).ConfigureAwait(false);

            var info = await QueryAsync(new byte[] { IscCodes.isc_info_svc_get_users }, ServiceParameterBufferBase.Empty, cancellationToken).ConfigureAwait(false);

            await CloseAsync(cancellationToken).ConfigureAwait(false);

            return((FbUserData[])info.FirstOrDefault());
        }
    public void Execute()
    {
        EnsureDatabase();

        try
        {
            Open();
            var startSpb = new ServiceParameterBuffer2();
            startSpb.Append(IscCodes.isc_action_svc_backup);
            startSpb.Append2(IscCodes.isc_spb_dbname, Database, SpbFilenameEncoding);
            foreach (var file in BackupFiles)
            {
                startSpb.Append2(IscCodes.isc_spb_bkp_file, file.BackupFile, SpbFilenameEncoding);
                if (file.BackupLength.HasValue)
                {
                    startSpb.Append(IscCodes.isc_spb_bkp_length, (int)file.BackupLength);
                }
            }
            if (Verbose)
            {
                startSpb.Append(IscCodes.isc_spb_verbose);
            }
            if (Factor > 0)
            {
                startSpb.Append(IscCodes.isc_spb_bkp_factor, Factor);
            }
            if (!string.IsNullOrEmpty(SkipData))
            {
                startSpb.Append2(IscCodes.isc_spb_bkp_skip_data, SkipData);
            }
            startSpb.Append(IscCodes.isc_spb_options, (int)Options);
            startSpb.Append2(IscCodes.isc_spb_bkp_stat, Statistics.BuildConfiguration());
            StartTask(startSpb);
            if (Verbose)
            {
                ProcessServiceOutput(ServiceParameterBufferBase.Empty);
            }
        }
        catch (Exception ex)
        {
            throw FbException.Create(ex);
        }
        finally
        {
            Close();
        }
    }
Exemple #5
0
        public async Task AddUserAsync(FbUserData user, CancellationToken cancellationToken = default)
        {
            if (string.IsNullOrEmpty(user.UserName))
            {
                throw new InvalidOperationException("Invalid user name.");
            }

            await OpenAsync(cancellationToken).ConfigureAwait(false);

            var startSpb = new ServiceParameterBuffer2();

            startSpb.Append(IscCodes.isc_action_svc_add_user);
            startSpb.Append2(IscCodes.isc_spb_sec_username, user.UserName);
            startSpb.Append2(IscCodes.isc_spb_sec_password, user.UserPassword);
            if ((user.FirstName?.Length ?? 0) != 0)
            {
                startSpb.Append2(IscCodes.isc_spb_sec_firstname, user.FirstName);
            }
            if ((user.MiddleName?.Length ?? 0) != 0)
            {
                startSpb.Append2(IscCodes.isc_spb_sec_middlename, user.MiddleName);
            }
            if ((user.LastName?.Length ?? 0) != 0)
            {
                startSpb.Append2(IscCodes.isc_spb_sec_lastname, user.LastName);
            }
            if (user.UserID != 0)
            {
                startSpb.Append(IscCodes.isc_spb_sec_userid, user.UserID);
            }
            if (user.GroupID != 0)
            {
                startSpb.Append(IscCodes.isc_spb_sec_groupid, user.GroupID);
            }
            if ((user.GroupName?.Length ?? 0) != 0)
            {
                startSpb.Append2(IscCodes.isc_spb_sec_groupname, user.GroupName);
            }
            if ((user.RoleName?.Length ?? 0) != 0)
            {
                startSpb.Append2(IscCodes.isc_spb_sql_role_name, user.RoleName);
            }
            await StartTaskAsync(startSpb, cancellationToken).ConfigureAwait(false);
            await CloseAsync(cancellationToken).ConfigureAwait(false);
        }
Exemple #6
0
        public void AddUser(FbUserData user)
        {
            if (string.IsNullOrEmpty(user.UserName))
            {
                throw new InvalidOperationException("Invalid user name.");
            }

            Open();
            var startSpb = new ServiceParameterBuffer2();

            startSpb.Append(IscCodes.isc_action_svc_add_user);
            startSpb.Append2(IscCodes.isc_spb_sec_username, user.UserName);
            startSpb.Append2(IscCodes.isc_spb_sec_password, user.UserPassword);
            if ((user.FirstName?.Length ?? 0) != 0)
            {
                startSpb.Append2(IscCodes.isc_spb_sec_firstname, user.FirstName);
            }
            if ((user.MiddleName?.Length ?? 0) != 0)
            {
                startSpb.Append2(IscCodes.isc_spb_sec_middlename, user.MiddleName);
            }
            if ((user.LastName?.Length ?? 0) != 0)
            {
                startSpb.Append2(IscCodes.isc_spb_sec_lastname, user.LastName);
            }
            if (user.UserID != 0)
            {
                startSpb.Append(IscCodes.isc_spb_sec_userid, user.UserID);
            }
            if (user.GroupID != 0)
            {
                startSpb.Append(IscCodes.isc_spb_sec_groupid, user.GroupID);
            }
            if ((user.GroupName?.Length ?? 0) != 0)
            {
                startSpb.Append2(IscCodes.isc_spb_sec_groupname, user.GroupName);
            }
            if ((user.RoleName?.Length ?? 0) != 0)
            {
                startSpb.Append2(IscCodes.isc_spb_sql_role_name, user.RoleName);
            }
            StartTask(startSpb);
            Close();
        }
Exemple #7
0
    public async Task ExecuteAsync(CancellationToken cancellationToken = default)
    {
        EnsureDatabase();

        try
        {
            await OpenAsync(cancellationToken).ConfigureAwait(false);

            var startSpb = new ServiceParameterBuffer2();
            startSpb.Append(IscCodes.isc_action_svc_validate);
            startSpb.Append2(IscCodes.isc_spb_dbname, Database, SpbFilenameEncoding);
            if (!string.IsNullOrEmpty(TablesInclude))
            {
                startSpb.Append2(IscCodes.isc_spb_val_tab_incl, TablesInclude);
            }
            if (!string.IsNullOrEmpty(TablesExclude))
            {
                startSpb.Append2(IscCodes.isc_spb_val_tab_excl, TablesExclude);
            }
            if (!string.IsNullOrEmpty(IndicesInclude))
            {
                startSpb.Append2(IscCodes.isc_spb_val_idx_incl, IndicesInclude);
            }
            if (!string.IsNullOrEmpty(IndicesExclude))
            {
                startSpb.Append2(IscCodes.isc_spb_val_idx_excl, IndicesExclude);
            }
            if (LockTimeout.HasValue)
            {
                startSpb.Append(IscCodes.isc_spb_val_lock_timeout, (int)LockTimeout);
            }
            await StartTaskAsync(startSpb, cancellationToken).ConfigureAwait(false);
            await ProcessServiceOutputAsync(ServiceParameterBufferBase.Empty, cancellationToken).ConfigureAwait(false);
        }
        catch (Exception ex)
        {
            throw FbException.Create(ex);
        }
        finally
        {
            await CloseAsync(cancellationToken).ConfigureAwait(false);
        }
    }
Exemple #8
0
        public void DeleteUser(FbUserData user)
        {
            if (string.IsNullOrEmpty(user.UserName))
            {
                throw new InvalidOperationException("Invalid user name.");
            }

            Open();
            var startSpb = new ServiceParameterBuffer2();

            startSpb.Append(IscCodes.isc_action_svc_delete_user);
            startSpb.Append2(IscCodes.isc_spb_sec_username, user.UserName);
            if ((user.RoleName?.Length ?? 0) != 0)
            {
                startSpb.Append2(IscCodes.isc_spb_sql_role_name, user.RoleName);
            }
            StartTask(startSpb);
            Close();
        }
Exemple #9
0
    public void Execute()
    {
        EnsureDatabase();

        try
        {
            Open();
            var startSpb = new ServiceParameterBuffer2();
            startSpb.Append(IscCodes.isc_action_svc_validate);
            startSpb.Append2(IscCodes.isc_spb_dbname, Database, SpbFilenameEncoding);
            if (!string.IsNullOrEmpty(TablesInclude))
            {
                startSpb.Append2(IscCodes.isc_spb_val_tab_incl, TablesInclude);
            }
            if (!string.IsNullOrEmpty(TablesExclude))
            {
                startSpb.Append2(IscCodes.isc_spb_val_tab_excl, TablesExclude);
            }
            if (!string.IsNullOrEmpty(IndicesInclude))
            {
                startSpb.Append2(IscCodes.isc_spb_val_idx_incl, IndicesInclude);
            }
            if (!string.IsNullOrEmpty(IndicesExclude))
            {
                startSpb.Append2(IscCodes.isc_spb_val_idx_excl, IndicesExclude);
            }
            if (LockTimeout.HasValue)
            {
                startSpb.Append(IscCodes.isc_spb_val_lock_timeout, (int)LockTimeout);
            }
            StartTask(startSpb);
            ProcessServiceOutput(ServiceParameterBufferBase.Empty);
        }
        catch (Exception ex)
        {
            throw FbException.Create(ex);
        }
        finally
        {
            Close();
        }
    }
Exemple #10
0
    public void SetForcedWrites(bool forcedWrites)
    {
        EnsureDatabase();

        Open();
        var startSpb = new ServiceParameterBuffer2();

        startSpb.Append(IscCodes.isc_action_svc_properties);
        startSpb.Append2(IscCodes.isc_spb_dbname, Database, SpbFilenameEncoding);
        if (forcedWrites)
        {
            startSpb.Append(IscCodes.isc_spb_prp_write_mode, (byte)IscCodes.isc_spb_prp_wm_sync);
        }
        else
        {
            startSpb.Append(IscCodes.isc_spb_prp_write_mode, (byte)IscCodes.isc_spb_prp_wm_async);
        }
        StartTask(startSpb);
        Close();
    }
Exemple #11
0
    public void SetReserveSpace(bool reserveSpace)
    {
        EnsureDatabase();

        Open();
        var startSpb = new ServiceParameterBuffer2();

        startSpb.Append(IscCodes.isc_action_svc_properties);
        startSpb.Append2(IscCodes.isc_spb_dbname, Database, SpbFilenameEncoding);
        if (reserveSpace)
        {
            startSpb.Append(IscCodes.isc_spb_prp_reserve_space, (byte)IscCodes.isc_spb_prp_res);
        }
        else
        {
            startSpb.Append(IscCodes.isc_spb_prp_reserve_space, (byte)IscCodes.isc_spb_prp_res_use_full);
        }
        StartTask(startSpb);
        Close();
    }
Exemple #12
0
        public async Task DeleteUserAsync(FbUserData user, CancellationToken cancellationToken = default)
        {
            if (string.IsNullOrEmpty(user.UserName))
            {
                throw new InvalidOperationException("Invalid user name.");
            }

            await OpenAsync(cancellationToken).ConfigureAwait(false);

            var startSpb = new ServiceParameterBuffer2();

            startSpb.Append(IscCodes.isc_action_svc_delete_user);
            startSpb.Append2(IscCodes.isc_spb_sec_username, user.UserName);
            if ((user.RoleName?.Length ?? 0) != 0)
            {
                startSpb.Append2(IscCodes.isc_spb_sql_role_name, user.RoleName);
            }
            await StartTaskAsync(startSpb, cancellationToken).ConfigureAwait(false);
            await CloseAsync(cancellationToken).ConfigureAwait(false);
        }
Exemple #13
0
    public void Execute()
    {
        EnsureDatabase();

        try
        {
            Open();
            var startSpb = new ServiceParameterBuffer2();
            startSpb.Append(IscCodes.isc_action_svc_restore);
            startSpb.Append2(IscCodes.isc_spb_bkp_file, "stdin", SpbFilenameEncoding);
            startSpb.Append2(IscCodes.isc_spb_dbname, Database, SpbFilenameEncoding);
            if (Verbose)
            {
                startSpb.Append(IscCodes.isc_spb_verbose);
            }
            if (PageBuffers.HasValue)
            {
                startSpb.Append(IscCodes.isc_spb_res_buffers, (int)PageBuffers);
            }
            if (_pageSize.HasValue)
            {
                startSpb.Append(IscCodes.isc_spb_res_page_size, (int)_pageSize);
            }
            startSpb.Append(IscCodes.isc_spb_res_access_mode, (byte)(ReadOnly ? IscCodes.isc_spb_res_am_readonly : IscCodes.isc_spb_res_am_readwrite));
            if (!string.IsNullOrEmpty(SkipData))
            {
                startSpb.Append2(IscCodes.isc_spb_res_skip_data, SkipData);
            }
            startSpb.Append(IscCodes.isc_spb_options, (int)Options);
            StartTask(startSpb);
            ReadInput();
        }
        catch (Exception ex)
        {
            throw FbException.Create(ex);
        }
        finally
        {
            Close();
        }
    }
Exemple #14
0
    public async Task SetReserveSpaceAsync(bool reserveSpace, CancellationToken cancellationToken = default)
    {
        EnsureDatabase();

        await OpenAsync(cancellationToken).ConfigureAwait(false);

        var startSpb = new ServiceParameterBuffer2();

        startSpb.Append(IscCodes.isc_action_svc_properties);
        startSpb.Append2(IscCodes.isc_spb_dbname, Database, SpbFilenameEncoding);
        if (reserveSpace)
        {
            startSpb.Append(IscCodes.isc_spb_prp_reserve_space, (byte)IscCodes.isc_spb_prp_res);
        }
        else
        {
            startSpb.Append(IscCodes.isc_spb_prp_reserve_space, (byte)IscCodes.isc_spb_prp_res_use_full);
        }
        await StartTaskAsync(startSpb, cancellationToken).ConfigureAwait(false);
        await CloseAsync(cancellationToken).ConfigureAwait(false);
    }
Exemple #15
0
    public async Task SetForcedWritesAsync(bool forcedWrites, CancellationToken cancellationToken = default)
    {
        EnsureDatabase();

        await OpenAsync(cancellationToken).ConfigureAwait(false);

        var startSpb = new ServiceParameterBuffer2();

        startSpb.Append(IscCodes.isc_action_svc_properties);
        startSpb.Append2(IscCodes.isc_spb_dbname, Database, SpbFilenameEncoding);
        if (forcedWrites)
        {
            startSpb.Append(IscCodes.isc_spb_prp_write_mode, (byte)IscCodes.isc_spb_prp_wm_sync);
        }
        else
        {
            startSpb.Append(IscCodes.isc_spb_prp_write_mode, (byte)IscCodes.isc_spb_prp_wm_async);
        }
        await StartTaskAsync(startSpb, cancellationToken).ConfigureAwait(false);
        await CloseAsync(cancellationToken).ConfigureAwait(false);
    }
Exemple #16
0
 void DoSimpleAction(int action, int?sessionID)
 {
     try
     {
         Open();
         var startSpb = new ServiceParameterBuffer2();
         startSpb.Append(action);
         if (sessionID.HasValue)
         {
             startSpb.Append(IscCodes.isc_spb_trc_id, (int)sessionID);
         }
         StartTask(startSpb);
         ProcessServiceOutput(ServiceParameterBufferBase.Empty);
     }
     catch (Exception ex)
     {
         throw FbException.Create(ex);
     }
     finally
     {
         Close();
     }
 }
Exemple #17
0
        public void Execute()
        {
            EnsureDatabase();

            try
            {
                Open();
                var startSpb = new ServiceParameterBuffer2();
                startSpb.Append(IscCodes.isc_action_svc_repair);
                startSpb.Append2(IscCodes.isc_spb_dbname, Database, SpbFilenameEncoding);
                startSpb.Append(IscCodes.isc_spb_options, (int)Options);
                StartTask(startSpb);
                ProcessServiceOutput(ServiceParameterBufferBase.Empty);
            }
            catch (Exception ex)
            {
                throw FbException.Create(ex);
            }
            finally
            {
                Close();
            }
        }
Exemple #18
0
    async Task ReadInputAsync(CancellationToken cancellationToken = default)
    {
        var items    = new byte[] { IscCodes.isc_info_svc_stdin, IscCodes.isc_info_svc_line };
        var spb      = ServiceParameterBufferBase.Empty;
        var response = await QueryAsync(items, spb, cancellationToken).ConfigureAwait(false);

        var requestedLength = GetLength(response);

        while (true)
        {
            if (requestedLength > 0)
            {
                var data = new byte[requestedLength];
                var read = InputStream.Read(data, 0, requestedLength);
                if (read > 0)
                {
                    Array.Resize(ref data, read);
                    var dataSpb = new ServiceParameterBuffer2();
                    dataSpb.Append2(IscCodes.isc_info_svc_line, data);
                    spb = dataSpb;
                }
            }
            response = await QueryAsync(items, spb, cancellationToken).ConfigureAwait(false);

            if (response.Count == 1)
            {
                break;
            }
            if (response[1] is string message)
            {
                OnServiceOutput(message);
            }
            requestedLength = GetLength(response);
            spb             = ServiceParameterBufferBase.Empty;
        }
    }
Exemple #19
0
        async Task DoSimpleActionAsync(int action, int?sessionID, CancellationToken cancellationToken = default)
        {
            try
            {
                await OpenAsync(cancellationToken).ConfigureAwait(false);

                var startSpb = new ServiceParameterBuffer2();
                startSpb.Append(action);
                if (sessionID.HasValue)
                {
                    startSpb.Append(IscCodes.isc_spb_trc_id, (int)sessionID);
                }
                await StartTaskAsync(startSpb, cancellationToken).ConfigureAwait(false);
                await ProcessServiceOutputAsync(ServiceParameterBufferBase.Empty, cancellationToken).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                throw FbException.Create(ex);
            }
            finally
            {
                await CloseAsync(cancellationToken).ConfigureAwait(false);
            }
        }
Exemple #20
0
        public async Task ExecuteAsync(CancellationToken cancellationToken = default)
        {
            EnsureDatabase();

            try
            {
                await OpenAsync(cancellationToken).ConfigureAwait(false);

                var startSpb = new ServiceParameterBuffer2();
                startSpb.Append(IscCodes.isc_action_svc_repair);
                startSpb.Append2(IscCodes.isc_spb_dbname, Database, SpbFilenameEncoding);
                startSpb.Append(IscCodes.isc_spb_options, (int)Options);
                await StartTaskAsync(startSpb, cancellationToken).ConfigureAwait(false);
                await ProcessServiceOutputAsync(ServiceParameterBufferBase.Empty, cancellationToken).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                throw FbException.Create(ex);
            }
            finally
            {
                await CloseAsync(cancellationToken).ConfigureAwait(false);
            }
        }