Ejemplo n.º 1
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            BlockTypeService blockTypeService = new BlockTypeService();
            SortProperty     sortProperty     = gBlockTypes.SortProperty;

            if (sortProperty != null)
            {
                gBlockTypes.DataSource = blockTypeService.Queryable().Sort(sortProperty).ToList();
            }
            else
            {
                gBlockTypes.DataSource = blockTypeService.Queryable().OrderBy(b => b.Name).ToList();
            }

            gBlockTypes.DataBind();
        }
Ejemplo n.º 2
0
        private static int LoadByGuid2(Guid guid, RockContext rockContext)
        {
            var blockTypeService = new BlockTypeService(rockContext);

            return(blockTypeService
                   .Queryable().AsNoTracking()
                   .Where(b => b.Guid.Equals(guid))
                   .Select(b => b.Id)
                   .FirstOrDefault());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Expands the files.
        /// </summary>
        /// <param name="packageFiles">The package files.</param>
        private void ExpandFiles(IEnumerable <IPackageFile> packageFiles)
        {
            // Remove export.json file from the list of files to be unzipped
            var filesToUnzip        = packageFiles.Where(f => !f.Path.Contains("export.json")).ToList();
            var blockTypeService    = new BlockTypeService(new RockContext());
            var installedBlockTypes = blockTypeService.Queryable().Where(b => !string.IsNullOrEmpty(b.Path));
            var webRoot             = HttpContext.Current.Server.MapPath("~");

            // Compare the packages files with currently installed block types, removing anything that already exists
            foreach (var blockType in installedBlockTypes)
            {
                var blockFileName = blockType.Path.Substring(blockType.Path.LastIndexOf("/", StringComparison.InvariantCultureIgnoreCase));
                blockFileName = blockFileName.Replace('/', Path.DirectorySeparatorChar);
                filesToUnzip.RemoveAll(f => f.Path.Contains(blockFileName));
            }

            foreach (var packageFile in filesToUnzip)
            {
                var path = Path.Combine(webRoot, packageFile.EffectivePath);
                var file = new FileInfo(path);

                // Err on the side of not being destructive for now. Consider refactoring to give user a choice
                // on whether or not to overwrite these files.
                if (file.Exists)
                {
                    WarningMessages.Add(string.Format("Skipping '{0}', found duplicate file at '{1}'.", file.Name, path));
                    continue;
                }

                // Write each file out to disk
                using (var fileStream = new FileStream(path, FileMode.Create))
                {
                    var stream = packageFile.GetStream();
                    var bytes  = stream.ReadAllBytes();
                    fileStream.Write(bytes, 0, bytes.Length);
                    stream.Close();
                }
            }
        }
        /// <summary>
        /// Gets the query.
        /// </summary>
        /// <returns></returns>
        private IQueryable <BlockType> GetQuery()
        {
            BlockTypeService blockTypeService = new BlockTypeService(new RockContext());

            var blockTypes = blockTypeService.Queryable().AsNoTracking();

            // Filter by Name
            string nameFilter = gfSettings.GetUserPreference("Name");

            if (!string.IsNullOrEmpty(nameFilter.Trim()))
            {
                blockTypes = blockTypes.Where(b => b.Name.Contains(nameFilter.Trim()));
            }

            // Filter by Path
            string path = gfSettings.GetUserPreference("Path");

            if (!string.IsNullOrEmpty(path.Trim()))
            {
                blockTypes = blockTypes.Where(b => b.Path.Contains(path.Trim()));
            }

            return(blockTypes);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            BlockTypeService blockTypeService = new BlockTypeService(new RockContext());
            SortProperty     sortProperty     = gBlockTypes.SortProperty;

            var blockTypes = blockTypeService.Queryable();

            // Exclude system blocks if checked.
            if (!string.IsNullOrWhiteSpace(gfSettings.GetUserPreference("Exclude System")))
            {
                blockTypes = blockTypes.Where(b => b.IsSystem == false);
            }

            // Filter by Name
            string nameFilter = gfSettings.GetUserPreference("Name");

            if (!string.IsNullOrEmpty(nameFilter.Trim()))
            {
                blockTypes = blockTypes.Where(b => b.Name.Contains(nameFilter.Trim()));
            }

            // Filter by Path
            string path = gfSettings.GetUserPreference("Path");

            if (!string.IsNullOrEmpty(path.Trim()))
            {
                blockTypes = blockTypes.Where(b => b.Path.Contains(path.Trim()));
            }

            string category = gfSettings.GetUserPreference("Category");

            if (!string.IsNullOrWhiteSpace(category))
            {
                blockTypes = blockTypes.Where(b => b.Category == category);
            }

            var selectQry = blockTypes.Select(a =>
                                              new
            {
                a.Id,
                a.Name,
                a.Category,
                a.Description,
                a.Path,
                BlocksCount = a.Blocks.Count(),
                a.IsSystem
            });

            if (sortProperty != null)
            {
                if (sortProperty.Property == "Status")
                {
                    // special case:  See if the file exists and sort by that
                    if (sortProperty.Direction == System.Web.UI.WebControls.SortDirection.Ascending)
                    {
                        gBlockTypes.DataSource = selectQry.ToList().OrderBy(a => System.IO.File.Exists(Request.MapPath(a.Path))).ToList();
                    }
                    else
                    {
                        gBlockTypes.DataSource = selectQry.ToList().OrderBy(a => !System.IO.File.Exists(Request.MapPath(a.Path))).ToList();
                    }
                }
                else
                {
                    gBlockTypes.DataSource = selectQry.Sort(sortProperty).ToList();
                }
            }
            else
            {
                gBlockTypes.DataSource = selectQry.OrderBy(b => b.Name).ToList();
            }

            gBlockTypes.EntityTypeId = EntityTypeCache.Read <Rock.Model.BlockType>().Id;
            gBlockTypes.DataBind();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            BlockTypeService blockTypeService = new BlockTypeService();
            SortProperty     sortProperty     = gBlockTypes.SortProperty;

            var blockTypes = blockTypeService.Queryable();

            // Exclude system blocks if checked.
            if (cbExcludeSystem.Checked)
            {
                blockTypes = blockTypes.Where(b => b.IsSystem == false);
            }

            // Filter by Name
            if (!string.IsNullOrEmpty(tbNameFilter.Text.Trim()))
            {
                blockTypes = blockTypes.Where(b => b.Name.Contains(tbNameFilter.Text.Trim()));
            }

            // Filter by Path
            if (!string.IsNullOrEmpty(tbPathFilter.Text.Trim()))
            {
                blockTypes = blockTypes.Where(b => b.Path.Contains(tbPathFilter.Text.Trim()));
            }

            var selectQry = blockTypes.Select(a =>
                                              new
            {
                a.Id,
                a.Name,
                a.Description,
                a.Path,
                BlocksCount = a.Blocks.Count(),
                a.IsSystem
            });

            if (sortProperty != null)
            {
                if (sortProperty.Property == "Status")
                {
                    // special case:  See if the file exists and sort by that
                    if (sortProperty.Direction == System.Web.UI.WebControls.SortDirection.Ascending)
                    {
                        gBlockTypes.DataSource = selectQry.ToList().OrderBy(a => System.IO.File.Exists(Request.MapPath(a.Path))).ToList();
                    }
                    else
                    {
                        gBlockTypes.DataSource = selectQry.ToList().OrderBy(a => !System.IO.File.Exists(Request.MapPath(a.Path))).ToList();
                    }
                }
                else
                {
                    gBlockTypes.DataSource = selectQry.Sort(sortProperty).ToList();
                }
            }
            else
            {
                gBlockTypes.DataSource = selectQry.OrderBy(b => b.Name).ToList();
            }

            gBlockTypes.DataBind();
        }