public string SendDeferredProcessAsMessage(DeferredProcess process, string msgheader) { BrokeredMessage message = new BrokeredMessage(msgheader); string id = ShortGuidGenerator.NewGuid(); Type deferredType = process.GetType(); message.Properties["Class"] = deferredType.FullName; message.Properties["ID"] = id; foreach (PropertyInfo pi in deferredType.GetProperties()) { message.Properties[pi.Name] = pi.GetValue(process, null); } SendMessage(message); return(id); }
public static DeferredProcess Reconstruct(BrokeredMessage message) { DeferredProcess newprocess = null; try { Type deferredType = Assembly.GetAssembly(typeof(DeferredProcess)).GetType(message.Properties["Class"].ToString()); if (deferredType == null) { return(null); } newprocess = (DeferredProcess)Activator.CreateInstance(deferredType); newprocess.ID = message.Properties["ID"] != null ? message.Properties["ID"].ToString() : ""; foreach (PropertyInfo pi in deferredType.GetProperties()) { if (pi.Name != "ID") { 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 } } } return(newprocess); } catch { return(null); } }
public static DeferredProcessExitCode ReconstructAndExecute(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); }