Example #1
0
        public static webModels.GetPagesResult ToWebModel(this IEnumerable <coreModels.Page> pages)
        {
            var retVal = new webModels.GetPagesResult();

            pages = pages.ToArray();

            var folders = pages.Where(i => i.Id.Split('/').Length > 1).Select(i => i.Id.Split('/')[0]).Distinct().ToList();

            if (!folders.Any(f => f.Equals("pages")))
            {
                folders.Add("pages");
            }
            if (!folders.Any(f => f.Equals("includes")))
            {
                folders.Add("includes");
            }

            foreach (var folder in folders)
            {
                var pageFolder = new webModels.PageFolder
                {
                    FolderName = folder
                };

                var addedPages = pages.Select(i => i.ToWebModel()).Where(i => i.Id.StartsWith(string.Format("{0}/", folder)));

                foreach (var page in addedPages)
                {
                    var steps = page.Name.Split('/');
                    if (steps.Length > 1)
                    {
                        steps = steps.Skip(1).ToArray();
                    }
                    page.Name = string.Join("/", steps);

                    pageFolder.Pages.Add(page);
                }

                retVal.Folders.Add(pageFolder);
            }

            var files = pages.Where(i => i.Id.Split('/').Length == 1);

            foreach (var file in files)
            {
                var addedFile = file.ToWebModel();

                var steps = addedFile.Name.Split('/');
                if (steps.Length > 1)
                {
                    steps = steps.Skip(1).ToArray();
                }
                addedFile.Name = string.Join("/", steps);

                retVal.Pages.Add(addedFile);
            }

            return(retVal);
        }
		public static webModels.GetPagesResult ToWebModel(this IEnumerable<coreModels.Page> pages)
		{
			var retVal = new webModels.GetPagesResult();

			pages = pages.ToArray();

			var folders = pages.Where(i => i.Id.Split('/').Length > 1).Select(i => i.Id.Split('/')[0]).Distinct().ToList();
			if (!folders.Any(f=> f.Equals("pages")))
			{
				folders.Add("pages");
			}
			if (!folders.Any(f => f.Equals("includes")))
			{
				folders.Add("includes");
			}

			foreach (var folder in folders)
			{
				var pageFolder = new webModels.PageFolder
				{
					FolderName = folder
				};

				var addedPages = pages.Select(i => i.ToWebModel()).Where(i => i.Id.StartsWith(string.Format("{0}/", folder)));

				foreach (var page in addedPages)
				{
					var steps = page.Name.Split('/');
					if (steps.Length > 1)
					{
						steps = steps.Skip(1).ToArray();
					}
					page.Name = string.Join("/", steps);

					pageFolder.Pages.Add(page);
				}

				retVal.Folders.Add(pageFolder);
			}

			var files = pages.Where(i => i.Id.Split('/').Length == 1);

			foreach (var file in files)
			{
				var addedFile = file.ToWebModel();

				var steps = addedFile.Name.Split('/');
				if (steps.Length > 1)
				{
					steps = steps.Skip(1).ToArray();
				}
				addedFile.Name = string.Join("/", steps);

				retVal.Pages.Add(addedFile);
			}

			return retVal;
		}
        private PageFolder LoadFolderRecursive(BlobFolder blobFolder, string path)
        {
            var retVal = new PageFolder
            {
                FolderName = blobFolder.Name
            };
            var result = _contentStorageProvider.Search(blobFolder.Url, null);

            foreach (var childFolder in result.Folders)
            {
                retVal.Folders.Add(LoadFolderRecursive(childFolder, path + "/" + childFolder.Name));
            }

            foreach (var item in result.Items)
            {
                var page = item.ToPageWebModel();
                page.Id = path + "/" + item.FileName;
                retVal.Pages.Add(page);
            }
            return retVal;
        }