Ejemplo n.º 1
0
        public MappedProductMessage Handle(ProductMessage message)
        {
            var mapped = new MappedProductMessage()
            {
                ProductId  = message.ProductId,
                CustomerId = message.CustomerId,
                Data       = new Dictionary <string, Dictionary <string, object> >()
            };

            var sourceFieldsMaps = _fieldMaps.Where(s => s.SourceField.Source.Id == message.SourceId)
                                   .ToList();

            foreach (var data in message.Data)
            {
                var values = new Dictionary <string, object>();

                foreach (var item in sourceFieldsMaps.Where(fm => fm.SourceField.FieldName == data.Key))
                {
                    if (item.ProductTypeField != null)
                    {
                        values.Add(message.SourceId.ToString(), Convert.ChangeType(data.Value, item.ProductTypeField.FieldType));
                        mapped.Data.Add(item.ProductTypeField.FieldName, values);
                    }
                }
            }

            return(mapped);
        }
        public void ProductMessageTest()
        {
            const string   line    = "  4083.735 { 187281906} Rx - [A4][14][4E][02][51][FF][27][10][89][E0][41][D3][E0][89][E0][11][05][10][00][68][00][CD][C0][76]";
            ProductMessage message = (ProductMessage)MessageFactory.MessageFromLine(line);

            Assert.IsTrue(message.Version == "1.0.39");
        }
Ejemplo n.º 3
0
        public void MessageSave(ProductMessage entity)
        {
            //如果回复内容不为空,则表示已经回复过
            entity.Pm_IsAns = entity.Pm_Answer != null && entity.Pm_Answer.Trim() != "";

            Gateway.Default.Save <ProductMessage>(entity);
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            try
            {
                while (true)
                {
                    var id  = Guid.NewGuid();
                    var obj = new ProductMessage
                    {
                        Id          = id,
                        CreatedDate = DateTime.Now
                    };

                    Console.WriteLine("Enqueuing: " + JsonConvert.SerializeObject(obj));

                    _messageQueue.Enqueue(QUEUE_NAME, obj);
                    Thread.Sleep(100);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.ReadKey();
        }
Ejemplo n.º 5
0
    private void GetFavoriteProduct()
    {
        string db = ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString;

        Product product = Product.GetProductById(this.productId, db);

        ProductMessage msg = new ProductMessage();

        string pos = "left";

        switch (position)
        {
        case 1:
            pos = "left";
            break;

        case 2:
            pos = "right";
            break;
        }

        Panel productPanel = WebHelper.GetProductPanel(pos, product);

        msg.ProductId   = product.id;
        msg.ProductHtml = WebHelper.RenderHtml(productPanel);
        msg.Panel       = position;

        string callbackName = Request.QueryString["callback"];

        Response.Write(callbackName + "(" + SerializationHelper.ToJSONString(typeof(ProductMessage), msg) + ");");
    }
Ejemplo n.º 6
0
        private void uxCloseButton_Click(object sender, EventArgs e)
        {
            ProductMessage selectedProduct = uxProductList.SelectedItem as ProductMessage;

            MessageBox.Show("Closing product");

            OnCloseProduct(selectedProduct);
        }
Ejemplo n.º 7
0
        public void Handle_InvalidParam_Throws()
        {
            var mockRepository = new Mock <IRepository <ProductTypeFieldSourceMap, EntityFrameworkProductContext> >();
            var productMapper  = new ProductMapper(mockRepository.Object);
            var productMessage = new ProductMessage();

            Assert.Throws <NullReferenceException>(() => productMapper.Handle(productMessage));
        }
Ejemplo n.º 8
0
 private ProductViewModel CreateProductViewModel(ProductMessage p)
 {
     return(new ProductViewModel
     {
         Category = p.Category,
         Name = p.Name,
         Price = p.Price
     });
 }
Ejemplo n.º 9
0
        public void AddProduct(ProductMessage product)
        {
            p.Add(product);

            foreach (var i in p)
            {
                Console.WriteLine(i.ProductName);
            }
        }
Ejemplo n.º 10
0
        public async override Task <ProductMessage> DeleteProduct(ProductMessage request, ServerCallContext context)
        {
            var productToDel = _context.Products.Find(request.Id);

            _context.Products.Remove(productToDel);
            await _context.SaveChangesAsync();

            return(new ProductMessage());
        }
        static ProductMessage SetProducts()
        {
            var product = new ProductMessage();

            product.ProductId = Guid.NewGuid();
            //product.Price = 10.2;

            return(product);
        }
Ejemplo n.º 12
0
        public void Product_Message_should_not_be_null()
        {
            var p = new ProductMessage {
                Name = "bla"
            };

            p.Should().NotBeNull();
            p.Name.Should().NotBeNull();
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> AddAsync([FromBody] ProductMessage product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            return(Ok(await _productsService.AddProductAsync(product)));
        }
Ejemplo n.º 14
0
        public void SendProduct(ProductMessage message)
        {
            var host = new DefaultHost();

            host.Start <PriceNotifierBootstrapper>();
            var bus = host.Bus as IServiceBus;

            bus.Send(message);
        }
Ejemplo n.º 15
0
        public async Task <IActionResult> EditAsync(ProductMessage editedProductMsg)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            await _productsService.UpdateProductAsync(editedProductMsg);

            return(Ok());
        }
Ejemplo n.º 16
0
 private void newProductArrived(ProductMessage msg)
 {
     if (packageWasExpected(msg))
     {
         Product p = msg.ProductInfo;
         lock (buyed)
         {
             buyed.Add(p);
             Console.WriteLine("Client {0} bought {1}, for {2}$ and {3} copies", AgentId, p.Info, p.UnitPrice, p.Quantity);
         }
     }
 }
Ejemplo n.º 17
0
        public async override Task <ProductMessage> UpdateProduct(ProductMessage request, ServerCallContext context)
        {
            var product = _mapper.Map <ProductModel>(request);

            _context.Attach(product);
            _context.Entry(product).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            await _context.SaveChangesAsync();

            var productMessage = _mapper.Map <ProductMessage>(product);

            return(productMessage);
        }
Ejemplo n.º 18
0
        public async override Task <ProductMessage> AddProduct(ProductMessage request, ServerCallContext context)
        {
            var product = _mapper.Map <ProductModel>(request);

            product.CreatedDate = DateTime.Now;
            _context.Products.Add(product);
            await _context.SaveChangesAsync();

            var productMessage = _mapper.Map <ProductMessage>(product);

            return(productMessage);
        }
        private SendRequest CreateSendRequest(Product product)
        {
            var message = new ProductMessage {
                EventName = "Created", ProductId = product.Id, EventDate = product.CreatedUtc
            };

            var request = new SendRequest
            {
                Body = JsonSerializer.Serialize(message)
            };

            return(request);
        }
Ejemplo n.º 20
0
        public void OnCloseProduct(object source, ProductMessage msg)
        {
            string message = "CloseProduct#" + JsonConvert.SerializeObject(msg);

            p.GetProduct.Remove(msg);
            string val;

            TopBids.TryGetValue(msg.ProductName, out val);
            string userName;

            Users.TryGetValue(val, out userName);
            wss.WebSocketServices.Broadcast("Winner#Winner for the " + msg.ProductName + " is " + userName);
            wss.WebSocketServices.Broadcast(message);
        }
Ejemplo n.º 21
0
        private void uxAddBtn_Click(object sender, EventArgs e)
        {
            //Gets selected item
            ProductMessage pp = uxProductList.SelectedItems[0] as ProductMessage;

            if (p != null)
            {
                p.GetProduct.Add(pp);
            }
            p.GetAddedProduct.Remove(pp);
            OnShowServerForm();
            addProduct(pp);
            this.Hide();
        }
Ejemplo n.º 22
0
        public async Task ProductQueuer(ProductMessage message)
        {
            var bus = Bus.Factory.CreateUsingRabbitMq(x =>
                                                      x.Host(new Uri("rabbitmq://localhost/"), h =>
            {
            }));

            bus.Start();
            var sender = await bus.GetSendEndpoint(new Uri("rabbitmq://localhost/product_queue"));

            await sender.Send <IProductMessage>(message);

            //bus.Publish<IProductMessage>(message);
        }
Ejemplo n.º 23
0
        public async Task <ProductResponse[]> CreateAsync(ProductMessage productMessage, string token, string filtro = null)
        {
            if (filtro != null)
            {
                var retorno = await GetAsync <ProductResponse[]>(null, filtro, token).ConfigureAwait(false);

                return(retorno);
            }
            else
            {
                var retorno = await GetAsync <ProductResponse[]>(productMessage.id, null, token).ConfigureAwait(false);

                return(retorno);
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// 库房下面的库区详情
        /// </summary>
        /// <returns></returns>
        public static List <ProductMessage> HouseDetail(string id)
        {
            Database db  = DatabaseFactory.CreateDatabase("Constr");
            string   sql = "select * from t_StoreHouseDetail where HouseID=" + id;
            DataSet  ds  = db.ExecuteDataSet(CommandType.Text, sql);
            List <ProductMessage> list = new List <ProductMessage>();

            foreach (DataRow item in ds.Tables[0].Rows)
            {
                ProductMessage p = new ProductMessage();
                p.HouseID     = int.Parse(item["ID"].ToString());
                p.SubareaName = item["SubareaName"].ToString();
                list.Add(p);
            }
            return(list);
        }
Ejemplo n.º 25
0
    protected void Page_Load(object sender, EventArgs e)
    {
        bool setupVariables = SetupVariables();

        if (!setupVariables)
        {
            ProductMessage message = new ProductMessage()
            {
                ErrorMessage = "Sorry, we\'ve encountered an unknown error.<br />Please try again."
            };
            Response.Write(SerializationHelper.ToJSONString(typeof(ProductMessage), message));
        }

        //Get product
        GetFavoriteProduct();
    }
Ejemplo n.º 26
0
        public async Task <int> AddProductAsync(ProductMessage productMsg)
        {
            using (var context = _factory.GetContext())
            {
                if (productMsg == null)
                {
                    throw new ArgumentNullException();
                }

                var product = _mapper.Map <Product>(productMsg);

                var e = context.Products.Add(product);
                await context.SaveChangesAsync();

                return(product.Id);
            }
        }
Ejemplo n.º 27
0
 public int MessageAdd(ProductMessage entity)
 {
     if (entity.Pd_Id >= 0)
     {
         Song.Entities.Product p = new ContentsCom().ProductSingle((int)entity.Pd_Id);
         if (p != null)
         {
             entity.Pd_Name = p.Pd_Name;
         }
     }
     Song.Entities.Organization org = Business.Do <IOrganization>().OrganCurrent();
     if (org != null)
     {
         entity.Org_ID   = org.Org_ID;
         entity.Org_Name = org.Org_Name;
     }
     return(Gateway.Default.Save <ProductMessage>(entity));
 }
Ejemplo n.º 28
0
        public async Task Post_resturns_success()
        {
            //Arrange
            var productMessage = new ProductMessage
            {
                Name = "Test"
            };

            //Act
            var response = await TestClient.PostAsync("/Product", new StringContent(
                                                          JsonConvert.SerializeObject(productMessage),
                                                          Encoding.UTF8,
                                                          "application/json"));

            //Assert
            response.StatusCode.Should().Be(StatusCodes.Status200OK);
            await Task.FromResult(true);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// 添加评价信息
        /// </summary>
        /// <param name="msg"></param>
        public void WareMessageAdd(ProductMessage msg)
        {
            if (msg == null)
            {
                return;
            }
            OtDB db = GetDb();

            try
            {
                db.Begin();
                //db.Exec(string.Format("delete from ProductMessage where PID = '{0}'", msg.PID));
                db.ExecInsert(msg, "ProductMessage", new string[] { "PID", "MsgType", "MsgContent", "MsgUser", "MsgUserLevel", "MsgProvince", "MsgDate" });
                db.Commit();
            }
            catch (Exception ex)
            {
                OtCom.XLogErr(ex.Message);
                db.Rollback();
            }
        }
Ejemplo n.º 30
0
        public async Task UpdateProductAsync(ProductMessage editedProductMsg)
        {
            using (var context = _factory.GetContext())
            {
                if (editedProductMsg == null)
                {
                    throw new ArgumentNullException();
                }

                var product = await context.Products.SingleOrDefaultAsync(a => a.Id == editedProductMsg.Id);

                if (product == null)
                {
                    throw new ArgumentException($"{editedProductMsg.Id} is wrong Id");
                }

                var editedProduct = _mapper.Map <Product>(editedProductMsg);
                context.Entry(product).CurrentValues.SetValues(editedProduct);
                await context.SaveChangesAsync();
            }
        }