public void Execute()
        {
            try
            {
                StartSpb = new ServiceParameterBuffer();

                // Configure Spb
                StartSpb.Append(IscCodes.isc_action_svc_db_stats);
                StartSpb.Append(IscCodes.isc_spb_dbname, Database);
                StartSpb.Append(IscCodes.isc_spb_options, (int)_options);

                Open();

                // Start execution
                StartTask();

                // Process service output
                ProcessServiceOutput();
            }
            catch (Exception ex)
            {
                throw new FbException(ex.Message, ex);
            }
            finally
            {
                Close();
            }
        }
        public void Query(
            ServiceParameterBuffer spb,
            int requestLength,
            byte[] requestBuffer,
            int bufferLength,
            byte[] buffer)
        {
            ClearStatusVector();

            int svcHandle = Handle;
            int reserved  = 0;

            _fbClient.isc_service_query(
                _statusVector,
                ref svcHandle,
                ref reserved,
                spb.Length,
                spb.ToArray(),
                (short)requestLength,
                requestBuffer,
                (short)buffer.Length,
                buffer);

            ProcessStatusVector(_statusVector);
        }
Example #3
0
        public void Start(string sessionName)
        {
            var version = _version;

            if (version == FbTraceVersion.Detect)
            {
                version = DetectVersion();
            }
            try
            {
                var config = string.Join(Environment.NewLine, DatabasesConfigurations.BuildConfiguration(version), ServiceConfiguration?.BuildConfiguration(version) ?? string.Empty);

                StartSpb = new ServiceParameterBuffer();
                StartSpb.Append(IscCodes.isc_action_svc_trace_start);
                if (!string.IsNullOrEmpty(sessionName))
                {
                    StartSpb.Append(IscCodes.isc_spb_trc_name, sessionName);
                }
                StartSpb.Append(IscCodes.isc_spb_trc_cfg, config);

                Open();
                StartTask();
                ProcessServiceOutput();
            }
            catch (Exception ex)
            {
                throw new FbException(ex.Message, ex);
            }
            finally
            {
                Close();
            }
        }
        public void Attach(ServiceParameterBuffer spb, string dataSource, int port, string service)
        {
            GenericResponse response = null;

            lock (this)
            {
                try
                {
                    this.database.Write(IscCodes.op_service_attach);
                    this.database.Write(0);
                    this.database.Write(service);
                    this.database.WriteBuffer(spb.ToArray());
                    this.database.Flush();

                    response = this.database.ReadGenericResponse();

                    this.handle = response.ObjectHandle;
                }
                catch (IOException)
                {
                    this.database.Detach();

                    throw new IscException(IscCodes.isc_net_write_err);
                }
            }
        }
Example #5
0
        private async Task ExecuteImpl(AsyncWrappingCommonArgs async)
        {
            EnsureDatabase();

            try
            {
                await Open(async).ConfigureAwait(false);

                var startSpb = new ServiceParameterBuffer();
                startSpb.Append(IscCodes.isc_action_svc_backup);
                startSpb.Append(IscCodes.isc_spb_dbname, Database, SpbFilenameEncoding);
                startSpb.Append(IscCodes.isc_spb_bkp_file, "stdout", SpbFilenameEncoding);
                if (!string.IsNullOrEmpty(SkipData))
                {
                    startSpb.Append(IscCodes.isc_spb_bkp_skip_data, SkipData);
                }
                startSpb.Append(IscCodes.isc_spb_options, (int)Options);
                await StartTask(startSpb, async).ConfigureAwait(false);
                await ReadOutput(async).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                throw new FbException(ex.Message, ex);
            }
            finally
            {
                await Close(async).ConfigureAwait(false);
            }
        }
Example #6
0
        private byte[] QueryService(byte[] items)
        {
            var shouldClose = false;

            if (State == FbServiceState.Closed)
            {
                Open();
                shouldClose = true;
            }
            if (QuerySpb == null)
            {
                QuerySpb = new ServiceParameterBuffer();
            }
            try
            {
                var buffer = new byte[QueryBufferSize];
                _svc.Query(QuerySpb, items.Length, items, buffer.Length, buffer);
                return(buffer);
            }
            finally
            {
                if (shouldClose)
                {
                    Close();
                }
            }
        }
Example #7
0
        public void Query(
            ServiceParameterBuffer spb,
            int requestLength,
            byte[] requestBuffer,
            int bufferLength,
            byte[] buffer)
        {
            int[] statusVector = FesConnection.GetNewStatusVector();
            int   svcHandle    = this.Handle;
            int   reserved     = 0;

            FbClient.isc_service_query(
                statusVector,
                ref svcHandle,
                ref reserved,
                (short)spb.Length,
                spb.ToArray(),
                (short)requestLength,
                requestBuffer,
                (short)buffer.Length,
                buffer);

            // Parse status	vector
            this.ParseStatusVector(statusVector);
        }
Example #8
0
        public void Execute()
        {
            try
            {
                // Configure Spb
                StartSpb = new ServiceParameterBuffer();

                StartSpb.Append(IscCodes.isc_action_svc_nrest);
                StartSpb.Append(IscCodes.isc_spb_dbname, Database);

                foreach (var file in BackupFiles)
                {
                    StartSpb.Append(IscCodes.isc_spb_nbk_file, file);
                }

                StartSpb.Append(IscCodes.isc_spb_nbk_direct, DirectIO ? "ON" : "OFF");

                Open();

                // Start execution
                StartTask();

                ProcessServiceOutput();
            }
            catch (Exception ex)
            {
                throw new FbException(ex.Message, ex);
            }
            finally
            {
                // Close
                Close();
            }
        }
Example #9
0
        public void Query(
            ServiceParameterBuffer spb,
            int requestLength,
            byte[] requestBuffer,
            int bufferLength,
            byte[] buffer)
        {
            // Clear the status vector
            this.ClearStatusVector();

            int svcHandle = this.Handle;
            int reserved  = 0;

            fbClient.isc_service_query(
                this.statusVector,
                ref svcHandle,
                ref reserved,
                (short)spb.Length,
                spb.ToArray(),
                (short)requestLength,
                requestBuffer,
                (short)buffer.Length,
                buffer);

            // Parse status	vector
            this.ParseStatusVector(this.statusVector);
        }
        private async Task ExecuteImpl(AsyncWrappingCommonArgs async)
        {
            EnsureDatabase();

            try
            {
                await Open(async).ConfigureAwait(false);

                var startSpb = new ServiceParameterBuffer();
                startSpb.Append(IscCodes.isc_action_svc_nbak);
                startSpb.Append(IscCodes.isc_spb_dbname, Database, SpbFilenameEncoding);
                startSpb.Append(IscCodes.isc_spb_nbk_level, _level);
                startSpb.Append(IscCodes.isc_spb_nbk_file, BackupFile, SpbFilenameEncoding);
                startSpb.Append(IscCodes.isc_spb_nbk_direct, DirectIO ? "ON" : "OFF");
                startSpb.Append(IscCodes.isc_spb_options, (int)Options);
                await StartTask(startSpb, async).ConfigureAwait(false);
                await ProcessServiceOutput(EmptySpb, async).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                throw new FbException(ex.Message, ex);
            }
            finally
            {
                await Close(async).ConfigureAwait(false);
            }
        }
        public void Execute()
        {
            try
            {
                // Configure Spb
                StartSpb = new ServiceParameterBuffer();

                StartSpb.Append(IscCodes.isc_action_svc_get_ib_log);

                Open();

                // Start execution
                StartTask();

                // Process service output
                ProcessServiceOutput();
            }
            catch (Exception ex)
            {
                throw new FbException(ex.Message, ex);
            }
            finally
            {
                Close();
            }
        }
 protected virtual void SendAttachToBuffer(ServiceParameterBuffer spb, string service)
 {
     _database.Xdr.Write(IscCodes.op_service_attach);
     _database.Xdr.Write(0);
     _database.Xdr.Write(service);
     _database.Xdr.WriteBuffer(spb.ToArray());
 }
        public void Execute()
        {
            if (string.IsNullOrEmpty(Database))
            {
                throw new FbException("Validation should be used against a specific database");
            }

            try
            {
                StartSpb = new ServiceParameterBuffer();

                // Configure Spb
                StartSpb.Append(IscCodes.isc_action_svc_repair);
                StartSpb.Append(IscCodes.isc_spb_dbname, Database);
                StartSpb.Append(IscCodes.isc_spb_options, (int)_options);

                Open();

                // Start execution
                StartTask();

                // Process service output
                ProcessServiceOutput();
            }
            catch (Exception ex)
            {
                throw new FbException(ex.Message, ex);
            }
            finally
            {
                Close();
            }
        }
Example #14
0
        public override Task Query(
            ServiceParameterBuffer spb,
            int requestLength,
            byte[] requestBuffer,
            int bufferLength,
            byte[] buffer,
            AsyncWrappingCommonArgs async)
        {
            ClearStatusVector();

            var svcHandle = Handle;
            var reserved  = 0;

            _fbClient.isc_service_query(
                _statusVector,
                ref svcHandle,
                ref reserved,
                spb.Length,
                spb.ToArray(),
                (short)requestLength,
                requestBuffer,
                (short)buffer.Length,
                buffer);

            ProcessStatusVector(_statusVector);

            return(Task.CompletedTask);
        }
Example #15
0
        public void DatabaseShutdown(FbShutdownMode mode, int seconds)
        {
            EnsureDatabase();

            StartSpb = new ServiceParameterBuffer();
            StartSpb.Append(IscCodes.isc_action_svc_properties);
            StartSpb.Append(IscCodes.isc_spb_dbname, Database);
            switch (mode)
            {
            case FbShutdownMode.Forced:
                StartSpb.Append(IscCodes.isc_spb_prp_shutdown_db, seconds);
                break;

            case FbShutdownMode.DenyTransaction:
                StartSpb.Append(IscCodes.isc_spb_prp_deny_new_transactions, seconds);
                break;

            case FbShutdownMode.DenyConnection:
                StartSpb.Append(IscCodes.isc_spb_prp_deny_new_attachments, seconds);
                break;
            }

            Open();
            StartTask();
            Close();
        }
        public void Query(
            ServiceParameterBuffer spb,
            int requestLength,
            byte[] requestBuffer,
            int bufferLength,
            byte[] buffer)
        {
            int[] statusVector = ExtConnection.GetNewStatusVector();
            int   svcHandle    = Handle;
            int   reserved     = 0;

            SafeNativeMethods.isc_service_query(
                statusVector,
                ref svcHandle,
                ref reserved,
                (short)spb.Length,
                spb.ToArray(),
                (short)requestLength,
                requestBuffer,
                (short)buffer.Length,
                buffer);

            // Parse status	vector
            ParseStatusVector(statusVector);
        }
Example #17
0
        private async Task StartImpl(string sessionName, AsyncWrappingCommonArgs async)
        {
            var version = _version;

            if (version == FbTraceVersion.Detect)
            {
                version = DetectVersion();
            }
            try
            {
                var config = string.Join(Environment.NewLine, DatabasesConfigurations.BuildConfiguration(version), ServiceConfiguration?.BuildConfiguration(version) ?? string.Empty);

                await Open(async).ConfigureAwait(false);

                var startSpb = new ServiceParameterBuffer();
                startSpb.Append(IscCodes.isc_action_svc_trace_start);
                if (!string.IsNullOrEmpty(sessionName))
                {
                    startSpb.Append(IscCodes.isc_spb_trc_name, sessionName);
                }
                startSpb.Append(IscCodes.isc_spb_trc_cfg, config);
                await StartTask(startSpb, async).ConfigureAwait(false);
                await ProcessServiceOutput(EmptySpb, async).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                throw new FbException(ex.Message, ex);
            }
            finally
            {
                await Close(async).ConfigureAwait(false);
            }
        }
        private async Task DatabaseShutdown2Impl(FbShutdownOnlineMode mode, FbShutdownType type, int seconds, AsyncWrappingCommonArgs async)
        {
            EnsureDatabase();

            await Open(async).ConfigureAwait(false);

            var startSpb = new ServiceParameterBuffer();

            startSpb.Append(IscCodes.isc_action_svc_properties);
            startSpb.Append(IscCodes.isc_spb_dbname, Database, SpbFilenameEncoding);
            startSpb.Append(IscCodes.isc_spb_prp_shutdown_mode, FbShutdownOnlineModeToIscCode(mode));
            switch (type)
            {
            case FbShutdownType.ForceShutdown:
                startSpb.Append(IscCodes.isc_spb_prp_force_shutdown, seconds);
                break;

            case FbShutdownType.AttachmentsShutdown:
                startSpb.Append(IscCodes.isc_spb_prp_attachments_shutdown, seconds);
                break;

            case FbShutdownType.TransactionsShutdown:
                startSpb.Append(IscCodes.isc_spb_prp_transactions_shutdown, seconds);
                break;
            }
            await StartTask(startSpb, async).ConfigureAwait(false);
            await Close(async).ConfigureAwait(false);
        }
Example #19
0
        public void Execute()
        {
            EnsureDatabase();

            try
            {
                StartSpb = new ServiceParameterBuffer();
                StartSpb.Append(IscCodes.isc_action_svc_nbak);
                StartSpb.Append(IscCodes.isc_spb_dbname, Database);
                StartSpb.Append(IscCodes.isc_spb_nbk_level, _level);
                StartSpb.Append(IscCodes.isc_spb_nbk_file, BackupFile);
                StartSpb.Append(IscCodes.isc_spb_nbk_direct, DirectIO ? "ON" : "OFF");
                StartSpb.Append(IscCodes.isc_spb_options, (int)Options);

                Open();
                StartTask();
                ProcessServiceOutput();
            }
            catch (Exception ex)
            {
                throw new FbException(ex.Message, ex);
            }
            finally
            {
                Close();
            }
        }
        private async Task DatabaseShutdownImpl(FbShutdownMode mode, int seconds, AsyncWrappingCommonArgs async)
        {
            EnsureDatabase();

            await Open(async).ConfigureAwait(false);

            var startSpb = new ServiceParameterBuffer();

            startSpb.Append(IscCodes.isc_action_svc_properties);
            startSpb.Append(IscCodes.isc_spb_dbname, Database, SpbFilenameEncoding);
            switch (mode)
            {
            case FbShutdownMode.Forced:
                startSpb.Append(IscCodes.isc_spb_prp_shutdown_db, seconds);
                break;

            case FbShutdownMode.DenyTransaction:
                startSpb.Append(IscCodes.isc_spb_prp_deny_new_transactions, seconds);
                break;

            case FbShutdownMode.DenyConnection:
                startSpb.Append(IscCodes.isc_spb_prp_deny_new_attachments, seconds);
                break;
            }
            await StartTask(startSpb, async).ConfigureAwait(false);
            await Close(async).ConfigureAwait(false);
        }
        public void Start(ServiceParameterBuffer spb)
        {
            lock (this)
            {
                try
                {
                    this.database.Write(IscCodes.op_service_start);
                    this.database.Write(this.Handle);
                    this.database.Write(0);
                    this.database.WriteBuffer(spb.ToArray(), spb.Length);
                    this.database.Flush();

                    try
                    {
                        this.database.ReadResponse();
                    }
                    catch (IscException)
                    {
                        throw;
                    }
                }
                catch (IOException)
                {
                    throw new IscException(IscCodes.isc_net_write_err);
                }
            }
        }
        public void Execute()
        {
            try
            {
                StartSpb = new ServiceParameterBuffer();
                StartSpb.Append(IscCodes.isc_action_svc_backup);
                StartSpb.Append(IscCodes.isc_spb_dbname, Database);
                StartSpb.Append(IscCodes.isc_spb_bkp_file, "stdout");
                StartSpb.Append(IscCodes.isc_spb_options, (int)Options);

                Open();

                StartTask();

                ReadOutput();
            }
            catch (Exception ex)
            {
                throw new FbException(ex.Message, ex);
            }
            finally
            {
                Close();
            }
        }
Example #23
0
        private byte[] QueryService(byte[] items)
        {
            bool shouldClose = false;

            if (_state == FbServiceState.Closed)
            {
                // Attach to Service Manager
                Open();
                shouldClose = true;
            }

            if (QuerySpb == null)
            {
                QuerySpb = new ServiceParameterBuffer();
            }

            try
            {
                // Response	buffer
                byte[] buffer = new byte[_queryBufferSize];
                _svc.Query(QuerySpb, items.Length, items, buffer.Length, buffer);
                return(buffer);
            }
            finally
            {
                if (shouldClose)
                {
                    Close();
                }
            }
        }
Example #24
0
        void ReadInput()
        {
            var items           = new byte[] { IscCodes.isc_info_svc_stdin, IscCodes.isc_info_svc_line };
            var response        = Query(items);
            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 spb = new ServiceParameterBuffer();
                        spb.Append(IscCodes.isc_info_svc_line, data);
                        QuerySpb = spb;
                    }
                }
                response = Query(items);
                if (response.Count == 1)
                {
                    break;
                }
                var message = response[1] as string;
                if (message != null)
                {
                    OnServiceOutput(message);
                }
                requestedLength = GetLength(response);
                QuerySpb        = null;
            }
        }
Example #25
0
        public void DatabaseShutdown2(FbShutdownOnlineMode mode, FbShutdownType type, int seconds)
        {
            StartSpb = new ServiceParameterBuffer();
            StartSpb.Append(IscCodes.isc_action_svc_properties);
            StartSpb.Append(IscCodes.isc_spb_dbname, Database);
            StartSpb.Append(IscCodes.isc_spb_prp_shutdown_mode, FbShutdownOnlineModeToIscCode(mode));
            switch (type)
            {
            case FbShutdownType.ForceShutdown:
                StartSpb.Append(IscCodes.isc_spb_prp_force_shutdown, seconds);
                break;

            case FbShutdownType.AttachmentsShutdown:
                StartSpb.Append(IscCodes.isc_spb_prp_attachments_shutdown, seconds);
                break;

            case FbShutdownType.TransactionsShutdown:
                StartSpb.Append(IscCodes.isc_spb_prp_transactions_shutdown, seconds);
                break;
            }

            Open();
            StartTask();
            Close();
        }
        public void Start(string sessionName)
        {
            try
            {
                string config = DatabasesConfigurations.ToString() + (ServiceConfiguration != null ? ServiceConfiguration.ToString() : string.Empty);

                StartSpb = new ServiceParameterBuffer();

                StartSpb.Append(IscCodes.isc_action_svc_trace_start);
                if (!string.IsNullOrEmpty(sessionName))
                {
                    StartSpb.Append(IscCodes.isc_spb_trc_name, sessionName);
                }
                StartSpb.Append(IscCodes.isc_spb_trc_cfg, config);

                Open();
                StartTask();
                ProcessServiceOutput();
            }
            catch (Exception ex)
            {
                throw new FbException(ex.Message, ex);
            }
            finally
            {
                Close();
            }
        }
        public void Query(ServiceParameterBuffer spb, int requestLength, byte[] requestBuffer, int bufferLength, byte[] buffer)
        {
            try
            {
                _database.XdrStream.Write(IscCodes.op_service_info);
                _database.XdrStream.Write(Handle);
                _database.XdrStream.Write(GdsDatabase.Incarnation);
                _database.XdrStream.WriteBuffer(spb.ToArray(), spb.Length);
                _database.XdrStream.WriteBuffer(requestBuffer, requestLength);
                _database.XdrStream.Write(bufferLength);

                _database.XdrStream.Flush();

                GenericResponse response = _database.ReadGenericResponse();

                int responseLength = bufferLength;

                if (response.Data.Length < bufferLength)
                {
                    responseLength = response.Data.Length;
                }

                Buffer.BlockCopy(response.Data, 0, buffer, 0, responseLength);
            }
            catch (IOException ex)
            {
                throw IscException.ForErrorCode(IscCodes.isc_network_error, ex);
            }
        }
        void DoSimpleAction(int action, int?sessionID = null)
        {
            try
            {
                StartSpb = new ServiceParameterBuffer();

                StartSpb.Append(action);
                if (sessionID.HasValue)
                {
                    StartSpb.Append(IscCodes.isc_spb_trc_id, (int)sessionID);
                }

                Open();
                StartTask();
                ProcessServiceOutput();
            }
            catch (Exception ex)
            {
                throw new FbException(ex.Message, ex);
            }
            finally
            {
                Close();
            }
        }
Example #29
0
        public void Execute()
        {
            EnsureDatabase();

            try
            {
                StartSpb = new ServiceParameterBuffer();
                StartSpb.Append(IscCodes.isc_action_svc_backup);
                StartSpb.Append(IscCodes.isc_spb_dbname, Database);
                StartSpb.Append(IscCodes.isc_spb_bkp_file, "stdout");
                if (!string.IsNullOrEmpty(SkipData))
                {
                    StartSpb.Append(IscCodes.isc_spb_bkp_skip_data, SkipData);
                }
                StartSpb.Append(IscCodes.isc_spb_options, (int)Options);

                Open();
                StartTask();
                ReadOutput();
            }
            catch (Exception ex)
            {
                throw new FbException(ex.Message, ex);
            }
            finally
            {
                Close();
            }
        }
Example #30
0
        public virtual async Task Query(ServiceParameterBuffer spb, int requestLength, byte[] requestBuffer, int bufferLength, byte[] buffer, AsyncWrappingCommonArgs async)
        {
            try
            {
                await _database.Xdr.Write(IscCodes.op_service_info, async).ConfigureAwait(false);

                await _database.Xdr.Write(Handle, async).ConfigureAwait(false);

                await _database.Xdr.Write(GdsDatabase.Incarnation, async).ConfigureAwait(false);

                await _database.Xdr.WriteBuffer(spb.ToArray(), spb.Length, async).ConfigureAwait(false);

                await _database.Xdr.WriteBuffer(requestBuffer, requestLength, async).ConfigureAwait(false);

                await _database.Xdr.Write(bufferLength, async).ConfigureAwait(false);

                await _database.Xdr.Flush(async).ConfigureAwait(false);

                var response = (GenericResponse)await _database.ReadResponse(async).ConfigureAwait(false);

                var responseLength = bufferLength;

                if (response.Data.Length < bufferLength)
                {
                    responseLength = response.Data.Length;
                }

                Buffer.BlockCopy(response.Data, 0, buffer, 0, responseLength);
            }
            catch (IOException ex)
            {
                throw IscException.ForErrorCode(IscCodes.isc_network_error, ex);
            }
        }