Пример #1
0
        // POST api/values
        public Value Post(Value value)
        {
            //queueClient = new QueueClient(ServiceBusConnectionString, QueueName);
            using (IrigationDBEntities1 context = new IrigationDBEntities1())
            {
                value.Timestemp = DateTime.Now;

                //string json = JsonConvert.SerializeObject(value);
                // byte[] messageBody = Encoding.Unicode.GetBytes(json);
                // queueClient.SendAsync(new Message(messageBody));
                if (value.Pompa == null)
                {
                    value.Pompa = "Off";
                }
                Microsoft.ServiceBus.Messaging.QueueClient     client2 = Microsoft.ServiceBus.Messaging.QueueClient.CreateFromConnectionString(ServiceBusConnectionString, QueueName);
                Microsoft.ServiceBus.Messaging.BrokeredMessage message = new Microsoft.ServiceBus.Messaging.BrokeredMessage();
                message.Properties["Temperatura"] = value.Temperatura;
                message.Properties["Umiditate"]   = value.Umiditate;
                message.Properties["Pompa"]       = value.Pompa;
                message.Properties["Id_senzor"]   = value.Id_senzor;
                client2.SendAsync(message);


                //value.Senzori = context.Senzoris.Include(sen => sen.Values).Include(sen => sen.Istorics).Where(sen => sen.Id == value.Id_senzor).First();
                //context.Values.Add(value);
                //context.SaveChanges();
            }
            return(value);
        }
Пример #2
0
        private void EnqueueFailedMessage(MSSB.BrokeredMessage brokeredMessage)
        {
            if (_isClosing)
            {
                return;
            }

            // TODO
        }
Пример #3
0
 public AzureServiceBusMessage()
 {
     _core = new BrokeredMessage();
     //this.FillPropertiesFromBrokeredMessageToServiceMessage();
     _Body = new Lazy <object>(
         () =>
         GetBodyValue(GetBodyType())
         );
     CommonHeaders = new MessageHeader(this);
 }
Пример #4
0
        public AzureServiceBusMessage(BrokeredMessage msg)
        {
            _core = msg ?? new BrokeredMessage();

            this.FillPropertiesFromBrokeredMessageToServiceMessage();

            _Body = new Lazy <object>(
                () =>
                GetBodyValue(GetBodyType())
                );
        }//{
Пример #5
0
        private MSSB.BrokeredMessage CreateBrokeredMessage(LogEventInfo log)
        {
            var message = Layout.Render(log);
            var props   = Properties.Render(log);

            var bm = new MSSB.BrokeredMessage(message);

            foreach (var kv in props)
            {
                bm.Properties.Add(kv.Key, kv.Value);
            }

            return(bm);
        }
Пример #6
0
        /// <summary>
        /// Process a command received from the job host
        /// </summary>
        /// <param name="msg"></param>
        private bool ProcessCommandFromJobHost(Microsoft.ServiceBus.Messaging.BrokeredMessage msg)
        {
            JobHost jobHost = null;

            try
            {
                var senderRoleInstanceId = "unknown";
                try
                {
                    senderRoleInstanceId = msg.Properties[GlobalConstants.SERVICEBUS_MESSAGE_PROP_ROLEINSTANCEID].ToString();
                }
                catch
                {
                    senderRoleInstanceId = "failed retrieving sender from message";
                }

                Geres.Diagnostics.GeresEventSource.Log.AutoScalerWorkerReceivedCommandFromJobHost
                (
                    RoleEnvironment.CurrentRoleInstance.Id,
                    RoleEnvironment.DeploymentId,
                    msg.MessageId,
                    senderRoleInstanceId
                );

                jobHost = msg.GetBody <JobHost>();
                ManageJobHost(jobHost);

                // Processed successfully
                return(true);
            }
            catch (Exception ex)
            {
                string jobHostId = "unknown";
                if (jobHost != null)
                {
                    if (!string.IsNullOrEmpty(jobHost.RoleInstanceId))
                    {
                        jobHostId = jobHost.RoleInstanceId;
                    }
                }

                Geres.Diagnostics.GeresEventSource.Log.AutoScalerWorkerFailedManageJobHost(
                    RoleEnvironment.CurrentRoleInstance.Id, RoleEnvironment.DeploymentId, jobHostId, ex.Message, ex.StackTrace);

                // Failed processing
                return(false);
            }
        }
Пример #7
0
        public ActionResult SubmitOrder(ProductOrder productOrder)
        {
            //if (ModelState.IsValid)
            {
                try
                {
                    ViewBag.SubmitResponse = string.Empty;
                    AzureGuidance.Domain.Order order = new AzureGuidance.Domain.Order();
                    order.CustomerName            = productOrder.order.CustomerName;
                    order.OrderDate               = DateTime.Now;
                    order.EmailId                 = productOrder.order.EmailId;
                    order.ProductOrderDetailsList = new List <ProductDetails>();
                    foreach (AddProduct p in productOrder.lstProducts)
                    {
                        if (true == p.SelectProduct)
                        {
                            ProductDetails productDetails = new ProductDetails();
                            productDetails.ProductName     = p.ProductName;
                            productDetails.ProductQuantity = p.ProductQuantity;
                            order.TotalDue   += p.UnitPrice * p.ProductQuantity;
                            order.orderStatus = "Processed";
                            order.OrderId     = Guid.NewGuid();
                            order.ProductOrderDetailsList.Add(productDetails);
                            p.ProductQuantity = 0;
                            p.SelectProduct   = false;
                        }
                    }
                    var message = new Microsoft.ServiceBus.Messaging.BrokeredMessage(order);
                    if (null == ServiceBusTopicHelper.OrdersTopicClient)
                    {
                        ServiceBusTopicHelper.Initialize();
                    }
                    ServiceBusTopicHelper.OrdersTopicClient.Send(message);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            ProductOrder      pOrder      = new ProductOrder();
            List <AddProduct> lstProducts = new List <AddProduct>();

            pOrder.lstProducts = productOrder.lstProducts;
            ModelState.Clear();
            ViewBag.SubmitResponse = "Order proccessed successfully.";
            return(View("DisplayProducts", pOrder));
        }
Пример #8
0
        public ActionResult SubmitOrder(ProductOrder productOrder)
        {

            //if (ModelState.IsValid)
            {
                try
                {
                    ViewBag.SubmitResponse = string.Empty;
                    Order order = new Order();
                    order.CustomerName = productOrder.order.CustomerName;
                    order.OrderDate = DateTime.Now;
                    order.EmailId = productOrder.order.EmailId;
                    order.ProductOrderDetailsList = new List<ProductDetails>();
                    foreach (AddProduct p in productOrder.lstProducts)
                    {
                        if (true == p.SelectProduct)
                        {
                            ProductDetails productDetails = new ProductDetails();
                            productDetails.ProductName = p.ProductName;
                            productDetails.ProductQuantity = p.ProductQuantity;
                            order.TotalDue += p.UnitPrice * p.ProductQuantity;
                            order.orderStatus = "Processed";
                            order.OrderId  = Guid.NewGuid();
                            order.ProductOrderDetailsList.Add(productDetails);
                            p.ProductQuantity = 0;
                            p.SelectProduct = false;
                        }

                    }
                    var message = new Microsoft.ServiceBus.Messaging.BrokeredMessage(order);
                    ServiceBusTopicHelper.OrdersTopicClient.Send(message);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            ProductOrder pOrder = new ProductOrder();
            List<AddProduct> lstProducts = new List<AddProduct>();

            pOrder.lstProducts = productOrder.lstProducts;
            ModelState.Clear();
            ViewBag.SubmitResponse = "Order proccessed successfully.";
            return View("DisplayProducts", pOrder);
        }
Пример #9
0
        public AzureServiceBusMessage(object body)
        {
            if (body == null)
            {
                _core = new BrokeredMessage();
            }

            else
            {
                _core = new BrokeredMessage(body);
                HeadersBag.MessageType = body.GetType().GetTypeAsmNameWithNoVersionAndSign();
            }

            this.FillPropertiesFromBrokeredMessageToServiceMessage();

            _Body = new Lazy <object>(
                () =>
                GetBodyValue(GetBodyType())
                );
        }