Exemplo n.º 1
0
        public List <customer> ListaClientes()
        {
            List <customer> customers = new List <customer>();

            try
            {
                customers = customerFactory.GetAll();
                return(customers);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
 // GET: /<controller>/
 public async Task <IActionResult> Customers()
 {
     return(Ok(_customerFactory.GetAll()));
 }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            List <Bukimedia.PrestaSharp.Entities.customer> actual_list = new List <Bukimedia.PrestaSharp.Entities.customer>();

            //NOTIFY NEW CUSTOMERS
            while (true)
            {
                //Get all users from HMS
                CustomerFactory customers = new CustomerFactory(BASE_URL, ACCOUNT, PASSWORD);
                List <Bukimedia.PrestaSharp.Entities.customer> result_list = customers.GetAll();

                //CHECK FOR NEW DATA
                //Check
                IEnumerable <Bukimedia.PrestaSharp.Entities.customer> tmp = new List <Bukimedia.PrestaSharp.Entities.customer>();
                if (actual_list.Count() == 0)
                {
                    tmp = result_list;
                }
                else
                {
                    //tmp = result_list.Where(
                    //    item => actual_list.Any(i => !i.id.Equals(item.id))).ToList();

                    foreach (Bukimedia.PrestaSharp.Entities.customer c in result_list)
                    {
                        bool contain = false;
                        foreach (Bukimedia.PrestaSharp.Entities.customer c1 in actual_list)
                        {
                            if (c.id == c1.id)
                            {
                                contain = true;
                                break;
                            }
                        }
                        if (contain == false)
                        {
                            List <Bukimedia.PrestaSharp.Entities.customer> tmp1 = tmp.ToList <Bukimedia.PrestaSharp.Entities.customer>();
                            tmp1.Add(c);
                            tmp = tmp1.ToList();
                        }
                    }
                }

                //Pull messages from data
                Message[] messages = new Message[tmp.Count()];
                if (tmp.Count() != 0 || actual_list.Count() == 0)
                {
                    int index = 0;
                    foreach (Bukimedia.PrestaSharp.Entities.customer c in tmp)
                    {
                        //Message
                        Bukimedia.PrestaSharp.Entities.address customer_address = getAdres(c.id);
                        Message message = new Message()
                        {
                            firstname    = c.firstname,
                            lastname     = c.lastname,
                            email        = c.email,
                            birthday     = c.birthday,
                            address1     = (customer_address.address1 != null) ? customer_address.address1.ToString() : "",
                            address2     = (customer_address.address2 != null) ? customer_address.address2.ToString() : "",
                            postcode     = (customer_address.postcode != null) ? customer_address.postcode.ToString() : "",
                            city         = (customer_address.city != null) ? customer_address.city.ToString() : "",
                            phone        = (customer_address.phone != null) ? customer_address.phone.ToString() : "",
                            phone_mobile = (customer_address.phone_mobile != null) ? customer_address.phone_mobile.ToString() : "",
                        };
                        messages[index] = message;
                        index++;
                    }
                }

                //SEND NEW DATA
                if (messages.Count() != 0)
                {
                    //RabbitMq
                    ConnectionFactory factory = new ConnectionFactory();
                    factory.UserName = "******";
                    factory.Password = "******";
                    factory.HostName = "10.3.51.37";

                    IConnection conn    = factory.CreateConnection();
                    IModel      channel = conn.CreateModel();

                    channel.ExchangeDeclare(
                        exchange: "new_customer_exchange",
                        type: ExchangeType.Direct);
                    channel.QueueDeclare(
                        queue: "new_customer_queue",
                        durable: true,
                        exclusive: false,
                        autoDelete: false,
                        arguments: null);
                    channel.QueueBind(
                        queue: "new_customer_queue",
                        exchange: "new_customer_exchange",
                        routingKey: "new_customer_queue");

                    string messageBody      = JsonConvert.SerializeObject(messages);
                    byte[] messageBodyBytes = Encoding.UTF8.GetBytes(messageBody);

                    //Send
                    channel.BasicPublish(
                        exchange: "new_customer_exchange",
                        routingKey: "new_customer_queue",
                        basicProperties: null,
                        body: messageBodyBytes);

                    Console.WriteLine("new data sended.");
                    channel.Dispose();
                    conn.Dispose();
                }

                actual_list = result_list;
            }
        }
Exemplo n.º 4
0
 public IActionResult Index()
 {
     return(Ok(_customerfactory.GetAll()));
 }