Ejemplo n.º 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="conn"></param>
        private static void ProcessMemberQueue(SqlConnection conn)
        {
            Console.WriteLine("Checking Member Queue...");
            SqlTransaction tran = conn.BeginTransaction();

            var queue = new MemberQueue(conn);
            SqlCommand command = queue.CreateReadCommand(tran);

            int rows = command.ExecuteNonQuery();
            if (rows > 0)
            {
                var bodyXml = (System.Data.SqlTypes.SqlXml)command.Parameters["@message_body"].SqlValue;
                if (!bodyXml.IsNull)
                {
                    string messageType = (string)command.Parameters["@message_type"].Value;
                    Console.WriteLine(" -> Message: [" + messageType + "]");
                    switch (messageType)
                    {
                        case "//Member/Email/WelcomePackMessage":
                            XElement messageBodyXml = XElement.Parse(bodyXml.Value);
                            string name = messageBodyXml.Elements().Where(p => p.Name == "name").First().Value;
                            string email = messageBodyXml.Elements().Where(p => p.Name == "email").First().Value;

                            /* Invoke CRM API using name & email to request enrolemant in welcome pack workflow. */
                            Console.WriteLine("     -> Name: {0}, Email: {1}", name, email);
                            tran.Commit();
                            break;

                        default:
                            tran.Rollback();
                            throw new InvalidOperationException("Unknown message type " + messageType);
                    }
                }
            } else
            {
                tran.Rollback();
            }
        }