Beispiel #1
0
 public static void SerializeEventMessage(string pathname, EventMessage details)
 {
     XmlSerializer serializer = new XmlSerializer(typeof(EventMessage));
     using (TextWriter writer = new StreamWriter(pathname))
     {
         serializer.Serialize(writer, details);
     }
 }
Beispiel #2
0
        static void Start(IBus bus)
        {
            Console.WriteLine("This will publish IEvent, EventMessage, and AnotherEventMessage alternately.");
            Console.WriteLine("Press 'Enter' to publish a message.To exit, Ctrl + C");

            var nextEventToPublish = 0;
            while (Console.ReadLine() != null)
            {
                var eventId = Guid.NewGuid();

                switch (nextEventToPublish)
                {
                    case 0:
                        bus.Publish<IMyEvent>(m =>
                        {
                            m.EventId = eventId;
                            m.Time = DateTime.Now.Second > 30 ? (DateTime?) DateTime.Now : null;
                            m.Duration = TimeSpan.FromSeconds(99999D);
                        });

                        nextEventToPublish = 1;

                        break;
                    case 1:
                        var eventMessage = new EventMessage
                        {
                            EventId = eventId,
                            Time = DateTime.Now.Second > 30 ? (DateTime?) DateTime.Now : null,
                            Duration = TimeSpan.FromSeconds(99999D)
                        };

                        bus.Publish(eventMessage);

                        nextEventToPublish = 2;

                        break;
                    default:
                        var anotherEventMessage = new AnotherEventMessage
                        {
                            EventId = eventId,
                            Time = DateTime.Now.Second > 30 ? (DateTime?) DateTime.Now : null,
                            Duration = TimeSpan.FromSeconds(99999D)
                        };

                        bus.Publish(anotherEventMessage);

                        nextEventToPublish = 0;

                        break;
                }

                Console.WriteLine("Published event with Id {0}.", eventId);

                Console.WriteLine("==========================================================================");
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            string path = @"c:\Load_XML_Files\";

            /*****
             *
             * If Diretory not there,
             * then create
             *
             * *****/
               if(!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            /*****
             * Create 5 Sample XML Files
             * *****/
            for (int index = 0; index < 5; index++)
            {
                string filename = @"temp" + (index + 1) + ".xml";
                EventMessage details = new EventMessage();
                details.EventId = Guid.NewGuid();
                details.paymentReq = new PaymentReq();
                details.paymentReq.billerGroupId = "ORDER";
                details.paymentReq.billerId = "USER";
                details.paymentReq.bankAccountNumber = "555555555";
                details.paymentReq.bankRoutingNumber = "444444444";
                details.paymentReq.firstName = "ATTN";
                details.paymentReq.lastName = "BILLING";
                details.paymentReq.companyName = "Money Company";
                details.paymentReq.nameOnAccount = "John Doe";
                details.paymentReq.phone = "3033333333";

                details.paymentReq.paymentReferenceId = Guid.NewGuid();
                details.paymentReq.address = new Address();
                details.paymentReq.address.streetAddress1 = "Accounting Building";
                details.paymentReq.address.streetAddress2 = "123 Gold Street";
                details.paymentReq.address.city = "Denver";
                details.paymentReq.address.state = "CO";

                SerializeEventMessage(path+filename, details);

            }
        }
Beispiel #4
0
        public void Start()
        {
            Console.WriteLine("This will publish IEvent, EventMessage, and AnotherEventMessage alternately.");
            Console.WriteLine("Press 'Enter' to publish a message.To exit, Ctrl + C");

            var nextEventToPublish = 0;
            while (Console.ReadLine() != null)
            {
                IMyEvent eventMessage;

                switch (nextEventToPublish)
                {
                    case 0 :
                        eventMessage = Bus.CreateInstance<IMyEvent>();
                        nextEventToPublish = 1;
                        break;
                    case 1 :
                        eventMessage = new EventMessage();
                        nextEventToPublish = 2;
                        break;
                    default:
                        eventMessage = new AnotherEventMessage();
                        nextEventToPublish = 0;
                        break;
                }

                eventMessage.EventId = Guid.NewGuid();
                eventMessage.Time = DateTime.Now.Second > 30 ? (DateTime?)DateTime.Now : null;
                eventMessage.Duration = TimeSpan.FromSeconds(99999D);

                Bus.Publish(eventMessage);

                // Do a custom check
                MyCustomCheck myCheck = new MyCustomCheck();

                Console.WriteLine("Published event with Id {0}.", eventMessage.EventId);
                Console.WriteLine("==========================================================================");
            }
        }
        public void writeEventMsg(EventMessage details)
        {
            using (var context = new PayQueueEntities())
            {

                // Get the payment rows
                var payment_rows = context.Payments;
                // Fluent API, check to see if there already is a payment with this EventId (PK)
                Payment payment = payment_rows.Where(x => (x.EventId == details.EventId)).FirstOrDefault();
                   /***
                 * If no payment in rows
                 * Add row
                 * Otherwise update row
                  * *****/
                if (payment == null)
                {

                    /**
                     * Walk through the details object
                     * USing Reflection
                     * ***/
                    Payment newPayment = new Payment();  // Create a new payment row
                    PropertyInfo[] newPayProperty = newPayment.GetType().GetProperties();
                    PropertyInfo[] mProperty = details.GetType().GetProperties();

                    /*****
                     *
                     * Walk through all the fields in the details object
                     *
                     * *******/
                    for (int index = 0; index < mProperty.Length; index++)
                    {
                        PropertyInfo mPropertyInformation = mProperty[index];
                        string mName = mPropertyInformation.Name.ToString();
                        switch (mName)
                        {
                            case "EventId":
                                Guid eventId = (Guid)mPropertyInformation.GetValue(details, null);
                                var field = newPayProperty.Where(x => (x.Name == mName)).FirstOrDefault();
                                field.SetValue(newPayment, eventId, null);
                                break;
                            case "paymentReq":
                                /****
                                 * Walk through the payment request object
                                 * setting in the values from this object into the table
                                 * *******/
                                PaymentReq paymentReq = (PaymentReq)mPropertyInformation.GetValue(details, null);
                                PropertyInfo[] payProperty = paymentReq.GetType().GetProperties();
                                for (int index2 = 0; index2 < payProperty.Length; index2++)
                                {
                                    PropertyInfo payPropertyInformation = payProperty[index2];
                                    string payName = payPropertyInformation.Name.ToString();
                                    // copy all the fileds, except the address fields,
                                    // we will drill down one more level down the object
                                    if (payName != "address")
                                    {
                                        var payField = payPropertyInformation.GetValue(paymentReq, null);
                                        var field2 = newPayProperty.Where(x => (x.Name == payName)).FirstOrDefault();
                                        field2.SetValue(newPayment, payField, null);
                                    }
                                    else
                                    {
                                        /*****
                                         * Copy the values of the old Address object
                                         * to the address fields in the database
                                         * *******/
                                        Address address = (Address)payPropertyInformation.GetValue(paymentReq, null);
                                        PropertyInfo[] addressProperty = address.GetType().GetProperties();
                                        for (int index4 = 0; index4 < addressProperty.Length; index4++)
                                        {
                                            PropertyInfo addressPropertyInformation = addressProperty[index4];
                                            string addressName = addressPropertyInformation.Name.ToString();
                                            var addressField = addressPropertyInformation.GetValue(address, null);
                                            var field3 = newPayProperty.Where(x => (x.Name == addressName)).FirstOrDefault();
                                            field3.SetValue(newPayment, addressField, null);
                                        }
                                    }
                                }
                                break;
                            default:
                                break;
                        }
                    }
                    payment_rows.Add(newPayment);
                    context.SaveChanges();
                }
                else
                {
                    /**
                     * Walk through the details object
                     * USing Reflection
                     * ***/
                     PropertyInfo[] newPayProperty = payment.GetType().GetProperties();
                    PropertyInfo[] mProperty = details.GetType().GetProperties();

                    /*****
                     *
                     * Walk through all the fields in the details object
                     *
                     * *******/
                    for (int index = 0; index < mProperty.Length; index++)
                    {
                        PropertyInfo mPropertyInformation = mProperty[index];
                        string mName = mPropertyInformation.Name.ToString();
                        switch (mName)
                        {
                            case "EventId":
                                Guid eventId = (Guid)mPropertyInformation.GetValue(details, null);
                                var field = newPayProperty.Where(x => (x.Name == mName)).FirstOrDefault();
                                field.SetValue(payment, eventId, null);
                                break;
                            case "paymentReq":
                                /****
                                 * Walk through the payment request object
                                 * setting in the values from this object into the table
                                 * *******/
                                PaymentReq paymentReq = (PaymentReq)mPropertyInformation.GetValue(details, null);
                                PropertyInfo[] payProperty = paymentReq.GetType().GetProperties();
                                for (int index2 = 0; index2 < payProperty.Length; index2++)
                                {
                                    PropertyInfo payPropertyInformation = payProperty[index2];
                                    string payName = payPropertyInformation.Name.ToString();
                                    // copy all the fileds, except the address fields,
                                    // we will drill down one more level down the object
                                    if (payName != "address")
                                    {
                                        var payField = payPropertyInformation.GetValue(paymentReq, null);
                                        var field2 = newPayProperty.Where(x => (x.Name == payName)).FirstOrDefault();
                                        field2.SetValue(payment, payField, null);
                                    }
                                    else
                                    {
                                        /*****
                                         *
                                         * Create an Address Object
                                         * Copy the values of the old Address object
                                         * to the new Address object
                                         *
                                         * *******/
                                        Address address = (Address)payPropertyInformation.GetValue(paymentReq, null);
                                        PropertyInfo[] addressProperty = address.GetType().GetProperties();
                                        for (int index4 = 0; index4 < addressProperty.Length; index4++)
                                        {
                                            PropertyInfo addressPropertyInformation = addressProperty[index4];
                                            string addressName = addressPropertyInformation.Name.ToString();
                                            var addressField = addressPropertyInformation.GetValue(address, null);
                                            var field3 = newPayProperty.Where(x => (x.Name == addressName)).FirstOrDefault();
                                            field3.SetValue(payment, addressField, null);
                                        }

                                    }
                                }
                                break;
                            default:
                                break;
                        }
                    }
                    context.SaveChanges();
                }
            }
        }