Beispiel #1
0
        protected void btnExport_Click(object sender, EventArgs e)
        {
            RockContext        rockContext        = new RockContext();
            WidgityTypeService widgityTypeService = new WidgityTypeService(rockContext);
            var widgityType = widgityTypeService.Get(PageParameter(PageParameterKey.WidgityTypeId).AsInteger());

            if (widgityType == null)
            {
                return;
            }

            var coder = new EntityCoder(new RockContext());

            coder.EnqueueEntity(widgityType, new WidgityTypeExporter());

            var container = coder.GetExportedEntities();

            Page.EnableViewState = false;
            Page.Response.Clear();
            Page.Response.ContentType = "application/json";
            Page.Response.AppendHeader("Content-Disposition", string.Format("attachment; filename=\"{0}_{1}.json\"", widgityType.Name.MakeValidFileName(), RockDateTime.Now.ToString("yyyyMMddHHmm")));
            Page.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(container, Newtonsoft.Json.Formatting.Indented));
            Page.Response.Flush();
            Page.Response.End();
        }
Beispiel #2
0
        /// <summary>
        /// Handles the Click event of the btnPreview control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void btnPreview_Click(object sender, EventArgs e)
        {
            // Clean-up UI
            gPreview.Visible     = true;
            ltImportResults.Text = string.Empty;

            RockContext rockContext         = new RockContext();
            var         workflowTypeService = new WorkflowTypeService(rockContext);
            var         workflowType        = workflowTypeService.Get(wtpExport.SelectedValueAsId().Value);
            var         coder    = new EntityCoder(new RockContext());
            var         exporter = new WorkflowTypeExporter();

            coder.EnqueueEntity(workflowType, exporter);

            List <PreviewEntity> previewEntities = new List <PreviewEntity>();

            foreach (var qe in coder.Entities)
            {
                string shortType = CodingHelper.GetEntityType(qe.Entity).Name;

                if (shortType == "Attribute" || shortType == "AttributeValue" || shortType == "AttributeQualifier" || shortType == "WorkflowActionFormAttribute")
                {
                    continue;
                }

                var preview = new PreviewEntity
                {
                    Guid       = qe.Entity.Guid,
                    Name       = EntityFriendlyName(qe.Entity),
                    ShortType  = shortType,
                    IsCritical = qe.IsCritical,
                    IsNewGuid  = qe.RequiresNewGuid,
                    Paths      = qe.ReferencePaths.Select(p => p.ToString()).ToList()
                };

                previewEntities.Add(preview);
            }

            ViewState["PreviewEntities"] = previewEntities;

            BindPreviewGrid();
        }
        /// <summary>
        /// Handles the Click event of the btnExport control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void btnExport_Click(object sender, EventArgs e)
        {
            RockContext rockContext         = new RockContext();
            var         workflowTypeService = new WorkflowTypeService(rockContext);
            var         workflowType        = workflowTypeService.Get(wtpExport.SelectedValueAsId().Value);
            var         coder = new EntityCoder(new RockContext());

            coder.EnqueueEntity(workflowType, new WorkflowTypeExporter());

            var container = coder.GetExportedEntities();

            // TODO: This should probably be stored as a BinaryFile and the user given a link to
            // click to download.
            Page.EnableViewState = false;
            Page.Response.Clear();
            Page.Response.ContentType = "application/json";
            Page.Response.AppendHeader("Content-Disposition", string.Format("attachment; filename=\"{0}_{1}.json\"", workflowType.Name.MakeValidFileName(), RockDateTime.Now.ToString("yyyyMMddHHmm")));
            Page.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(container, Newtonsoft.Json.Formatting.Indented));
            Page.Response.Flush();
            Page.Response.End();
        }
Beispiel #4
0
        /// <summary>
        /// Evaluate the list of referenced entities. This is a list of key value pairs that identify
        /// the property that the reference came from as well as the referenced entity itself. Implementations
        /// of this method may add or remove from this list. For example, an AttributeValue has
        /// the entity it is referencing in a EntityId column, but there is no general use information for
        /// what kind of entity it is. The processor can provide that information.
        /// </summary>
        /// <param name="entity">The parent entity of the references.</param>
        /// <param name="references"></param>
        /// <param name="helper">The helper class for this export.</param>
        /// <exception cref="System.Exception"></exception>
        protected override void EvaluateReferencedEntities(Rock.Model.Attribute entity, List <KeyValuePair <string, IEntity> > references, EntityCoder helper)
        {
            //
            // Only process if the entity qualifier column looks to be a reference to an Entity.
            //
            if (entity.EntityTypeQualifierColumn == null || !entity.EntityTypeQualifierColumn.EndsWith("Id"))
            {
                return;
            }

            //
            // Get the EntityType and Id of the qualifiers.
            //
            int?entityId   = entity.EntityTypeQualifierValue.AsIntegerOrNull();
            var entityType = helper.FindEntityType(entity.EntityType.Name);

            if (!entityId.HasValue || entityType == null)
            {
                return;
            }

            //
            // Try to get the property mentioned by the qualifier.
            //
            var property = entityType.GetProperty(entity.EntityTypeQualifierColumn.ReplaceLastOccurrence("Id", string.Empty));

            if (property == null)
            {
                return;
            }

            //
            // If the property is of type IEntity, then it is a reference we want to add.
            //
            if (typeof(IEntity).IsAssignableFrom(property.PropertyType))
            {
                var target = helper.GetExistingEntity(property.PropertyType.FullName, entityId.Value);

                if (target != null)
                {
                    references.Add(new KeyValuePair <string, IEntity>("EntityTypeQualifierValue", target));
                }
                else
                {
                    throw new Exception(string.Format("Could not find referenced qualifier of Attribute {0}", entity.Guid));
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Evaluate the list of child entities. This is a list of key value pairs that identify
        /// the property that the child came from as well as the child entity itself. Implementations
        /// of this method may add or remove from this list. For example, a WorkflowActionForm has
        /// it's actions encoded in a single string. This must processed to include any other
        /// objects that should exist (such as a DefinedValue for the button type).
        /// </summary>
        /// <param name="entity">The parent entity of the children.</param>
        /// <param name="children">The child entities and what properties of the parent they came from.</param>
        /// <param name="helper">The helper class for this export.</param>
        protected override void EvaluateChildEntities(WidgityType entity, List <KeyValuePair <string, IEntity> > children, EntityCoder helper)
        {
            var attributeService = new AttributeService(helper.RockContext);

            var entityIds = new List <int?> {
                EntityTypeCache.GetId(typeof(Widgity)), EntityTypeCache.GetId(typeof(WidgityItem))
            };

            var items = attributeService
                        .Queryable()
                        .Where(a =>
                               entityIds.Contains(a.EntityTypeId) &&
                               a.EntityTypeQualifierColumn.Equals("WidgityTypeId", StringComparison.OrdinalIgnoreCase) &&
                               a.EntityTypeQualifierValue.Equals(entity.Id.ToString()))
                        .ToList();

            //
            // We have to special process the attributes since we modify them.
            //
            foreach (var item in items)
            {
                children.Add(new KeyValuePair <string, IEntity>("AttributeTypes", item));
            }
        }
        /// <summary>
        /// Evaluate the list of child entities. This is a list of key value pairs that identify
        /// the property that the child came from as well as the child entity itself. Implementations
        /// of this method may add or remove from this list. For example, a WorkflowActionForm has
        /// it's actions encoded in a single string. This must processed to include any other
        /// objects that should exist (such as a DefinedValue for the button type).
        /// </summary>
        /// <param name="entity">The parent entity of the children.</param>
        /// <param name="children">The child entities and what properties of the parent they came from.</param>
        /// <param name="helper">The helper class for this export.</param>
        protected override void EvaluateChildEntities(WorkflowType entity, List <KeyValuePair <string, IEntity> > children, EntityCoder helper)
        {
            var attributeService = new AttributeService(helper.RockContext);

            var items = attributeService
                        .GetByEntityTypeId(new Model.Workflow().TypeId).AsQueryable()
                        .Where(a =>
                               a.EntityTypeQualifierColumn.Equals("WorkflowTypeId", StringComparison.OrdinalIgnoreCase) &&
                               a.EntityTypeQualifierValue.Equals(entity.Id.ToString()))
                        .ToList();

            //
            // We have to special process the attributes since we modify them.
            //
            foreach (var item in items)
            {
                children.Add(new KeyValuePair <string, IEntity>("AttributeTypes", item));
            }
        }
Beispiel #7
0
        /// <summary>
        /// Evaluate the list of referenced entities. This is a list of key value pairs that identify
        /// the property that the reference came from as well as the referenced entity itself. Implementations
        /// of this method may add or remove from this list. For example, an AttributeValue has
        /// the entity it is referencing in a EntityId column, but there is no general use information for
        /// what kind of entity it is. The processor can provide that information.
        /// </summary>
        /// <param name="entity">The parent entity of the references.</param>
        /// <param name="references"></param>
        /// <param name="helper">The helper class for this export.</param>
        /// <exception cref="System.Exception"></exception>
        protected override void EvaluateReferencedEntities(AttributeValue entity, List <KeyValuePair <string, IEntity> > references, EntityCoder helper)
        {
            if (!entity.EntityId.HasValue || entity.Attribute == null)
            {
                return;
            }

            var target = helper.GetExistingEntity(entity.Attribute.EntityType.Name, entity.EntityId.Value);

            if (target != null)
            {
                references.Add(new KeyValuePair <string, IEntity>("EntityId", target));
            }
            else
            {
                throw new Exception(string.Format("Cannot export AttributeValue {0} because we cannot determine what entity it references.", entity.Guid));
            }
        }
Beispiel #8
0
 /// <summary>
 /// An entity has been exported and can now have any post-processing done to it
 /// that is needed. For example a processor might remove some properties that shouldn't
 /// actually have been exported.
 /// </summary>
 /// <param name="entity">The source entity that was exported.</param>
 /// <param name="encodedEntity">The exported data from the entity.</param>
 /// <param name="helper">The helper that is doing the exporting.</param>
 /// <returns>
 /// An object that will be encoded with the entity and passed to the ProcessImportEntity method later, or null.
 /// </returns>
 protected override object ProcessExportedEntity(WorkflowActionForm entity, EncodedEntity encodedEntity, EntityCoder helper)
 {
     //
     // Return the Actions data that we will pre-process on import to fixup any references.
     //
     return(entity.Actions);
 }
Beispiel #9
0
        /// <summary>
        /// Evaluate the list of referenced entities. This is a list of key value pairs that identify
        /// the property that the reference came from as well as the referenced entity itself. Implementations
        /// of this method may add or remove from this list. For example, an AttributeValue has
        /// the entity it is referencing in a EntityId column, but there is no general use information for
        /// what kind of entity it is. The processor can provide that information.
        /// </summary>
        /// <param name="entity">The parent entity of the references.</param>
        /// <param name="references"></param>
        /// <param name="helper">The helper class for this export.</param>
        protected override void EvaluateReferencedEntities(WorkflowActionForm entity, List <KeyValuePair <string, IEntity> > references, EntityCoder helper)
        {
            //
            // Workflow Action Forms have a string field of "Actions" that contains references
            // to Defined Values for the button types.
            //
            List <string> actions = entity.Actions.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).ToList();

            for (int i = 0; i < actions.Count; i++)
            {
                var details = actions[i].Split(new char[] { '^' });

                if (details.Length > 2)
                {
                    Guid    definedValueGuid = details[1].AsGuid();
                    IEntity definedValue     = helper.GetExistingEntity("Rock.Model.DefinedValue", definedValueGuid);

                    if (definedValue != null)
                    {
                        references.Add(new KeyValuePair <string, IEntity>("Actions", definedValue));
                    }
                }
            }
        }