Пример #1
0
        /// <summary>
        /// Handles the Click event of the btnSave 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 btnSave_Click(object sender, EventArgs e)
        {
            BlockType        blockType;
            var              rockContext      = new RockContext();
            BlockTypeService blockTypeService = new BlockTypeService(rockContext);

            int blockTypeId = int.Parse(hfBlockTypeId.Value);

            if (blockTypeId == 0)
            {
                blockType = new BlockType();
                blockTypeService.Add(blockType);
            }
            else
            {
                BlockTypeCache.Flush(blockTypeId);
                blockType = blockTypeService.Get(blockTypeId);
            }

            blockType.Name        = tbName.Text;
            blockType.Path        = tbPath.Text;
            blockType.Description = tbDescription.Text;

            if (!blockType.IsValid)
            {
                // Controls will render the error messages
                return;
            }

            rockContext.SaveChanges();

            NavigateToParentPage();
        }
Пример #2
0
        /// <summary>
        /// Handles the Click event of the btnSave 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 btnSave_Click(object sender, EventArgs e)
        {
            BlockType        blockType;
            BlockTypeService blockTypeService = new BlockTypeService();

            int blockTypeId = int.Parse(hfBlockTypeId.Value);

            if (blockTypeId == 0)
            {
                blockType = new BlockType();
                blockTypeService.Add(blockType, CurrentPersonId);
            }
            else
            {
                BlockTypeCache.Flush(blockTypeId);
                blockType = blockTypeService.Get(blockTypeId);
            }

            blockType.Name        = tbName.Text;
            blockType.Path        = tbPath.Text;
            blockType.Description = tbDescription.Text;

            if (!blockType.IsValid)
            {
                // Controls will render the error messages
                return;
            }

            blockTypeService.Save(blockType, CurrentPersonId);

            BindGrid();

            pnlDetails.Visible = false;
            pnlList.Visible    = true;
        }
Пример #3
0
        /// <summary>
        /// Handles the Click event of the btnSave 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 btnSave_Click(object sender, EventArgs e)
        {
            BlockType        blockType;
            BlockTypeService blockTypeService = new BlockTypeService();

            int blockTypeId = int.Parse(hfBlockTypeId.Value);

            if (blockTypeId == 0)
            {
                blockType = new BlockType();
                blockTypeService.Add(blockType, CurrentPersonId);
            }
            else
            {
                BlockTypeCache.Flush(blockTypeId);
                blockType = blockTypeService.Get(blockTypeId);
            }

            blockType.Name        = tbName.Text;
            blockType.Path        = tbPath.Text;
            blockType.Description = tbDescription.Text;

            if (!blockType.IsValid)
            {
                // Controls will render the error messages
                return;
            }

            RockTransactionScope.WrapTransaction(() =>
            {
                blockTypeService.Save(blockType, CurrentPersonId);
            });

            NavigateToParentPage();
        }
Пример #4
0
        /// <summary>
        /// Scans for unregistered blocks.
        /// </summary>
        private void ScanForUnregisteredBlocks()
        {
            BlockTypeService blockTypeService = new BlockTypeService();

            foreach (Rock.Model.BlockType blockType in blockTypeService.GetUnregisteredBlocks(Request.MapPath("~")))
            {
                try
                {
                    Control control = LoadControl(blockType.Path);
                    if (control is Rock.Web.UI.RockBlock)
                    {
                        blockType.Name        = Path.GetFileNameWithoutExtension(blockType.Path).SplitCase();
                        blockType.Description = Rock.Reflection.GetDescription(control.GetType()) ?? string.Empty;

                        blockTypeService.Add(blockType, CurrentPersonId);
                        blockTypeService.Save(blockType, CurrentPersonId);
                    }
                }
                catch
                {
                    //
                }
            }
        }
Пример #5
0
        public bool ImportPage(byte[] uploadedPackage, string fileName, int pageId, int siteId)
        {
            // Write .nupkg file to the PackageStaging folder...
            var path = Path.Combine(HttpContext.Current.Server.MapPath("~/App_Data/PackageStaging"), fileName);

            using (var file = new FileStream(path, FileMode.Create))
            {
                file.Write(uploadedPackage, 0, uploadedPackage.Length);
            }

            var  package      = new ZipPackage(path);
            var  packageFiles = package.GetFiles().ToList();
            var  exportFile   = packageFiles.FirstOrDefault(f => f.Path.Contains("export.json"));
            Page page         = null;

            // If export.json is present, deserialize data
            // * Are there any new BlockTypes to register? If so, save them first.
            // * Scrub out any `Id` and `Guid` fields that came over from export
            // * Save page data via PageService

            if (exportFile != null)
            {
                string json;

                using (var stream = exportFile.GetStream())
                {
                    json = stream.ReadToEnd();
                }

                page = Page.FromJson(json);
            }

            // Validate package...
            // + Does it have any executable .dll files? Should those go to the bin folder, or into a plugins directory to be loaded via MEF?
            // - Does it have code or asset files that need to go on the file system? (Done)
            // - Does it have an export.json file? Should that be a requirement? (Done)
            // + Does it have any corresponding SQL, migrations, seed methods to run, etc.

            if (page != null)
            {
                var rockContext = new RockContext();

                // Find new block types and save them prior to scrubbing data...
                var newBlockTypes = FindNewBlockTypes(page, new BlockTypeService(rockContext).Queryable()).ToList();
                rockContext.WrapTransaction(() =>
                {
                    try
                    {
                        var blockTypeService = new BlockTypeService(rockContext);

                        foreach (var blockType in newBlockTypes)
                        {
                            blockTypeService.Add(blockType);
                        }
                        rockContext.SaveChanges();

                        ValidateImportData(page, newBlockTypes);
                        SavePages(rockContext, page, newBlockTypes, pageId, siteId);
                        ExpandFiles(packageFiles);
                    }
                    catch (Exception e)
                    {
                        ErrorMessages.Add(e.Message);
                    }
                });

                // Clean up PackageStaging folder on successful import.
                var file = new FileInfo(path);
                file.Delete();
                return(ErrorMessages.Count <= 0);
            }

            ErrorMessages.Add("The export package uploaded does not appear to have any data associated with it.");
            return(false);
        }