Beispiel #1
0
        private DateTime GetDateTimeActivated(WorkflowAction action)
        {
            var dateActivated = RockDateTime.Now;

            // Use the current action type' guid as the key for a 'Delay Activated' attribute
            string AttrKey = action.ActionTypeCache.Guid.ToString();

            // Check to see if the action's activity does not yet have the the 'Delay Activated' attribute.
            // The first time this action runs on any workflow instance using this action instance, the
            // attribute will not exist and need to be created
            if (!action.Activity.Attributes.ContainsKey(AttrKey))
            {
                var attribute = new Rock.Model.Attribute();
                attribute.EntityTypeId = action.Activity.TypeId;
                attribute.EntityTypeQualifierColumn = "ActivityTypeId";
                attribute.EntityTypeQualifierValue  = action.Activity.ActivityTypeId.ToString();
                attribute.Name        = "Delay Activated";
                attribute.Key         = AttrKey;
                attribute.FieldTypeId = FieldTypeCache.Read(Rock.SystemGuid.FieldType.TEXT.AsGuid()).Id;

                // Need to save the attribute now (using different context) so that an attribute id is returned.
                using (var newRockContext = new RockContext())
                {
                    new AttributeService(newRockContext).Add(attribute);
                    newRockContext.SaveChanges();
                    AttributeCache.FlushEntityAttributes();
                    WorkflowActivityTypeCache.Flush(action.Activity.ActivityTypeId);
                }

                action.Activity.Attributes.Add(AttrKey, AttributeCache.Read(attribute));
                var attributeValue = new AttributeValueCache();
                attributeValue.AttributeId = attribute.Id;
                attributeValue.Value       = dateActivated.ToString("o");
                action.Activity.AttributeValues.Add(AttrKey, attributeValue);

                action.AddLogEntry(string.Format("Delay Activated at {0}", dateActivated), true);
            }
            else
            {
                // Check to see if this action instance has a value for the 'Delay Activated' attrbute
                DateTime?activated = action.Activity.GetAttributeValue(AttrKey).AsDateTime();
                if (activated.HasValue)
                {
                    return(activated.Value);
                }
                else
                {
                    // If no value exists, set the value to the current time
                    action.Activity.SetAttributeValue(AttrKey, dateActivated.ToString("o"));
                    action.AddLogEntry(string.Format("Delay Activated at {0}", dateActivated), true);
                }
            }

            return(dateActivated);
        }
Beispiel #2
0
        private double HoursElapsed(WorkflowAction action)
        {
            // Use the current action type' guid as the key for a 'DateTime Sent' attribute
            string AttrKey = action.ActionTypeCache.Guid.ToString() + "_DateTimeSent";

            // Check to see if the action's activity does not yet have the the 'DateTime Sent' attribute.
            // The first time this action runs on any workflow instance using this action instance, the
            // attribute will not exist and need to be created
            if (!action.Activity.Attributes.ContainsKey(AttrKey))
            {
                var attribute = new Rock.Model.Attribute();
                attribute.EntityTypeId = action.Activity.TypeId;
                attribute.EntityTypeQualifierColumn = "ActivityTypeId";
                attribute.EntityTypeQualifierValue  = action.Activity.ActivityTypeId.ToString();
                attribute.Name        = "DateTime Sent";
                attribute.Key         = AttrKey;
                attribute.FieldTypeId = FieldTypeCache.Read(Rock.SystemGuid.FieldType.TEXT.AsGuid()).Id;

                // Need to save the attribute now (using different context) so that an attribute id is returned.
                using (var newRockContext = new RockContext())
                {
                    new AttributeService(newRockContext).Add(attribute);
                    newRockContext.SaveChanges();
                    AttributeCache.FlushEntityAttributes();
                    WorkflowActivityTypeCache.Flush(action.Activity.ActivityTypeId);
                }

                action.Activity.Attributes.Add(AttrKey, AttributeCache.Read(attribute));
                var attributeValue = new AttributeValueCache();
                attributeValue.AttributeId = attribute.Id;
                attributeValue.Value       = RockDateTime.Now.ToString("o");
                action.Activity.AttributeValues.Add(AttrKey, attributeValue);
            }
            else
            {
                // Check to see if this action instance has a value for the 'Delay Activated' attrbute
                DateTime?dateSent = action.Activity.GetAttributeValue(AttrKey).AsDateTime();
                if (dateSent.HasValue)
                {
                    // If a value does exist, check to see if the number of minutes to delay has passed
                    // since the value was saved
                    return(RockDateTime.Now.Subtract(dateSent.Value).TotalHours);
                }
                else
                {
                    // If no value exists, set the value to the current time
                    action.Activity.SetAttributeValue(AttrKey, RockDateTime.Now.ToString("o"));
                }
            }

            return(0.0D);
        }
Beispiel #3
0
        private string EmailStatus(WorkflowAction action)
        {
            // Use the current action type' guid as the key for a 'Email Status' attribute
            string AttrKey = action.ActionTypeCache.Guid.ToString() + "_EmailStatus";

            // Check to see if the action's activity does not yet have the the 'Email Status' attribute.
            // The first time this action runs on any workflow instance using this action instance, the
            // attribute will not exist and need to be created
            if (!action.Activity.Attributes.ContainsKey(AttrKey))
            {
                var attribute = new Rock.Model.Attribute();
                attribute.EntityTypeId = action.Activity.TypeId;
                attribute.EntityTypeQualifierColumn = "ActivityTypeId";
                attribute.EntityTypeQualifierValue  = action.Activity.ActivityTypeId.ToString();
                attribute.Name        = "Email Status";
                attribute.Key         = AttrKey;
                attribute.FieldTypeId = FieldTypeCache.Read(Rock.SystemGuid.FieldType.TEXT.AsGuid()).Id;

                // Need to save the attribute now (using different context) so that an attribute id is returned.
                using (var newRockContext = new RockContext())
                {
                    new AttributeService(newRockContext).Add(attribute);
                    newRockContext.SaveChanges();
                    AttributeCache.FlushEntityAttributes();
                    WorkflowActivityTypeCache.Flush(action.Activity.ActivityTypeId);
                }

                action.Activity.Attributes.Add(AttrKey, AttributeCache.Read(attribute));
                var attributeValue = new AttributeValueCache();
                attributeValue.AttributeId = attribute.Id;
                attributeValue.Value       = string.Empty;
                action.Activity.AttributeValues.Add(AttrKey, attributeValue);
            }
            else
            {
                return(action.Activity.GetAttributeValue(AttrKey));
            }

            return(string.Empty);
        }