public DeferredProcessExitCode Run(MessageBroker msgbroker, string msgheader)
 {
     return(Run(msgbroker, false, this.GetType().Name + " " + msgheader));
 }
        //protected void LogEvent(string shortDescription, string details, WorkItemEventType eventType)
        //{
        //    if (eventClient == null)
        //    {
        //        eventClient = new WorkItemEventClient(this.GetType().Name);
        //    }
        //    eventClient.AddNewItem(new WorkItemEvent { Type = eventType.ToString(), ShortDescription = shortDescription, Details = details, PartitionKey = ID, RowKey = ShortGuidGenerator.NewGuid(), ClassName = this.GetType().Name });
        //}


        public virtual DeferredProcessExitCode Execute(MessageBroker messageBroker)
        {
            throw new NotImplementedException();
        }
 public DeferredProcessExitCode Run(MessageBroker msgbroker)
 {
     return(Run(msgbroker, false, this.GetType().Name));
 }
        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);
        }