public override void Run() { var queue = new Queue(); var commandInterface = typeof(ICommand); // NOTE: If no reference is made to the CommandQueue.Domain assembly in this class the following query won't find the classes that implement ICommand. var commandTypes = (from assembly in AppDomain.CurrentDomain.GetAssemblies() from type in assembly.GetTypes() where (commandInterface.IsAssignableFrom(type)) && (commandInterface != type) select type).ToList(); while (true) { try { foreach (var commandType in commandTypes) { var message = queue.GetMessage(commandType.Name, 4); if (message != null) { dynamic command = JsonConvert.DeserializeObject(message.AsString, commandType); command.Execute(); queue.DeleteMessage(commandType.Name, message); } } } catch (Exception exception) { Trace.TraceError(exception.Message); } Thread.Sleep(1000); } }
/// <summary> /// Email the total movie reviews to the noted address. /// </summary> /// <param name="movieTitleAndReleaseYear">Movie title and release year.</param> /// <param name="emailAddress">The email address to send the results to.</param> public void EmailTotalReviews( string movieTitleAndReleaseYear, string emailAddress) { var movieEntity = new MovieEntity { MovieTitleAndReleaseYear = movieTitleAndReleaseYear, EmailAddress = emailAddress }; var movieLookupCommand = new MovieLookupCommand { MovieEntity = movieEntity }; var queue = new Queue(); queue.AddMessage(movieLookupCommand); }
/// <summary> /// Save the complaint, for later processing. /// </summary> /// <param name="fullName">Complaint person's full name.</param> /// <param name="complaint">The complaint.</param> /// <param name="level">Level of complaint.</param> public void ProcessComplaint( string fullName, string complaint, string level) { var complaintEntity = new ComplaintEntity { FullName = fullName, Complaint = complaint, Level = level }; var processComplaintCommand = new ProcessComplaintCommand { ComplaintEntity = complaintEntity }; var queue = new Queue(); queue.AddMessage(processComplaintCommand); }
/// <summary> /// Leave a reply for the designated recipients. /// </summary> /// <param name="reply">Reply to be left.</param> /// <param name="emailAddress">User's email address.</param> public void LeaveReply( string reply, string emailAddress) { // Persist the data to table storage. var blogPostReplyEntity = new BlogPostReplyEntity { Reply = reply, EmailAddress = emailAddress }; var table = new Table(); table.AddEntity(blogPostReplyEntity); // Create the command object. var dispatchMessageCommand = new NewBlogPostReplyCommand { BlogPostReplyEntity = blogPostReplyEntity }; // Add the command into queue storage, for later processing. var queue = new Queue(); queue.AddMessage(dispatchMessageCommand); }