Esempio n. 1
0
 private void buttonPutevoiSave_Click(object sender, EventArgs e)
 {
     putevoi.driver_id        = Convert.ToInt64(comboSelectDriver.SelectedValue);
     putevoi.engine_id        = Convert.ToInt64(comboSelectEngine.SelectedValue);
     putevoi.car_id           = Convert.ToInt64(comboSelectCar.SelectedValue);
     putevoi.fuel_start       = Convert.ToInt64(textBoxFuelStart.Text);
     putevoi.fuel_zapravka    = Convert.ToInt64(textBoxFuelZapravka.Text);
     putevoi.fuel_cash        = Convert.ToInt64(textBoxFuelCash.Text);
     putevoi.fuel_karta       = Convert.ToInt64(textBoxFuelKarta.Text);
     putevoi.fuel_end         = Convert.ToInt64(textBoxFuelEnd.Text);
     putevoi.fuel_norma       = Convert.ToSingle(textBoxFuelNorma.Text.Replace(".", ","));
     putevoi.probeg_s_gruzom  = Convert.ToInt64(textBoxProbegSGruzom.Text);
     putevoi.probeg_bez_gruza = Convert.ToInt64(textBoxProbegBezGruza.Text);
     putevoi.probeg_start     = Convert.ToInt64(textBoxProbegStart.Text);
     putevoi.probeg_end       = Convert.ToInt64(textBoxProbegEnd.Text);
     putevoi.date_start       = UnixTime.To(dateTimePutevoiDateStart.Value);
     putevoi.date_end         = UnixTime.To(dateTimePutevoiDateEnd.Value);
     try
     {
         putevoi.Save(conn);
         MessageBox.Show("Путевой лист сохранен в базе данных", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
     }
     catch
     {
         MessageBox.Show("Не удалось сохранить в базу данных", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Esempio n. 2
0
        public async Task <RpcMessage> RpcExec(string queueName, string message)
        {
            var taskCompletion = new TaskCompletionSource <RpcMessage>();

            var id          = Guid.NewGuid().ToString();
            var returnQueue = ReturnQueueName(queueName, id);

            _connection.recieveChannel.QueueDeclare(returnQueue, false, false, true, null);

            var consumer = new EventingBasicConsumer(_connection.recieveChannel);

            _connection.recieveChannel.BasicConsume(returnQueue, false, "", false, true, null, consumer);

            var expiration = UnixTime.To(DateTime.Now.AddSeconds(TimeoutSeconds));
            var request    = new RpcRequestMessage(message, returnQueue, expiration);

            var r = RpcMessages.ToByte(request);

            Thread.Sleep(TimeSpan.FromTicks(1));
            var rpcQueueName = RpcQueueName(queueName);

            var properties = _connection.sendChannel.CreateBasicProperties();

            properties.ContentType = "application/json";
            properties.Expiration  = expiration.ToString();

            _connection.sendChannel.BasicPublish("", rpcQueueName, false, properties, r);

            consumer.Received += (model, ea) =>
            {
                _connection.recieveChannel.QueueDelete(returnQueue, false, true);
                if (DateTime.Now > (UnixTime.From(expiration)))
                {
                    //TODO: Error RPC timeout
                    taskCompletion.SetException(new Exception());
                }
                else
                {
                    var m = RpcMessages.FromByte(ea.Body);
                    _connection.recieveChannel.BasicAck(ea.DeliveryTag, false);

                    taskCompletion.SetResult(m);
                }
            };

            return(await taskCompletion.Task);
        }