public bool SendDeferredProcessAsMessage(DeferredProcess process) { BrokeredMessage message = new BrokeredMessage("deferred"); Type deferredType = process.GetType(); message.Properties["Class"] = deferredType.FullName; message.Properties["ID"] = ShortGuidGenerator.NewGuid(); foreach (PropertyInfo pi in deferredType.GetProperties()) { message.Properties[pi.Name] = pi.GetValue(process, null); } return(SendMessage(message)); }
public static DeferredProcessExitCode CreateAndExecute(MessageBroker messageBroker, BrokeredMessage message, int instanceNumber, int threadNumber) { DeferredProcessExitCode retval = DeferredProcessExitCode.NothingToDo; DeferredProcess newprocess = null; try { Type deferredType = Assembly.GetAssembly(typeof(DeferredProcess)).GetType(message.Properties["Class"].ToString()); if (deferredType == null) { return(DeferredProcessExitCode.NothingToDo); } newprocess = (DeferredProcess)Activator.CreateInstance(deferredType); newprocess.ID = message.Properties["ID"] != null ? message.Properties["ID"].ToString() : ""; foreach (PropertyInfo pi in deferredType.GetProperties()) { Type declaringType = pi.PropertyType; try { switch (declaringType.Name) { case "Double": pi.SetValue(newprocess, double.Parse(message.Properties[pi.Name].ToString()), null); break; case "Float": pi.SetValue(newprocess, float.Parse(message.Properties[pi.Name].ToString()), null); break; case "Int64": pi.SetValue(newprocess, Int64.Parse(message.Properties[pi.Name].ToString()), null); break; case "Int32": pi.SetValue(newprocess, Int32.Parse(message.Properties[pi.Name].ToString()), null); break; case "DateTime": pi.SetValue(newprocess, DateTime.Parse(message.Properties[pi.Name].ToString()), null); break; case "Boolean": pi.SetValue(newprocess, Boolean.Parse(message.Properties[pi.Name].ToString()), null); break; default: pi.SetValue(newprocess, message.Properties[pi.Name], null); break; } } catch { //Ignore the property setting error } } //Time the execution long ts = DateTime.UtcNow.Ticks; retval = newprocess.Execute(messageBroker); double milliseconds = (new TimeSpan(DateTime.UtcNow.Ticks - ts)).TotalMilliseconds; } catch { retval = DeferredProcessExitCode.Error; } finally { newprocess = null; } return(retval); }