private async Task <PageDefinition> CreatePageDefinitionAsync(PageDefinition page)
        {
            using (ILockObject lockObject = await LockDesignedPagesAsync()) {
                PageDefinition.DesignedPage desPage = new PageDefinition.DesignedPage()
                {
                    PageGuid = page.PageGuid, Url = page.Url,
                };
                DesignedPagesDictionaryByUrl designedPagesByUrl = await GetDesignedPagesWithoutLockAsync();

                if (designedPagesByUrl.ContainsKey(desPage.Url.ToLower()))
                {
                    throw new Error(this.__ResStr("pageUrlErr", "A page with Url {0} already exists.", desPage.Url));
                }
                if (!await DataProvider.AddAsync(page))
                {
                    throw new Error(this.__ResStr("pageGuidErr", "A page with Guid {0} already exists.", desPage.PageGuid));
                }
                await SetCachedPageAsync(page);
                await AddDesignedPageAsync(designedPagesByUrl, page.Url.ToLower(), desPage);

                await lockObject.UnlockAsync();
            }
            await Auditing.AddAuditAsync($"{nameof(PageDefinitionDataProvider)}.{nameof(CreatePageDefinitionAsync)}", page.Url, page.PageGuid,
                                         "Create Page",
                                         DataBefore : null,
                                         DataAfter : page,
                                         ExpensiveMultiInstance : true
                                         );

            return(page);
        }
예제 #2
0
            public async Task <DesignedPagesDictionaryByUrl> GetDesignedPagesAsync()
            {
                DesignedPagesDictionaryByUrl byUrl = new DesignedPagesDictionaryByUrl();
                List <Guid> pageGuids = await GetListOfKeysAsync(BaseFolder);

                foreach (var pageGuid in pageGuids)
                {
                    PageDefinition page = await GetAsync(pageGuid);

                    if (page == null)
                    {
                        throw new InternalError("No PageDefinition for guid {0}", pageGuid);
                    }
                    PageDefinition.DesignedPage desPage = new PageDefinition.DesignedPage()
                    {
                        Url = page.Url, PageGuid = page.PageGuid
                    };
                    byUrl.Add(page.Url.ToLower(), desPage);
                }
                return(byUrl);
            }
 // Requires an active static lock
 private async Task AddDesignedPageAsync(DesignedPagesDictionaryByUrl designedPagesByUrl, string url, PageDefinition.DesignedPage designedPage)
 {
     designedPagesByUrl.Add(url, designedPage);
     using (ICacheDataProvider staticCacheDP = YetaWF.Core.IO.Caching.GetStaticCacheProvider()) {
         await staticCacheDP.AddAsync(DESIGNEDPAGESKEY, designedPagesByUrl);
     }
 }
        public async Task SavePageDefinitionAsync(PageDefinition page)
        {
            if (page.Temporary)
            {
                throw new InternalError("Page {0} is a temporary page and can't be saved", page.PageGuid);
            }

            PageDefinition oldPage = null;

            using (ILockObject lockObject = await LockDesignedPagesAsync()) {
                page.Updated = DateTime.UtcNow;
                CleanupUsersAndRoles(page);
                await SaveImagesAsync(page.PageGuid, page);

                oldPage = await LoadPageDefinitionAsync(page.PageGuid);

                if (oldPage == null)
                {
                    throw new Error(this.__ResStr("pageDeleted", "Page '{0}' has been deleted and can no longer be updated."), page.Url);
                }

                Guid newPage = await FindPageAsync(page.Url);

                if (newPage != Guid.Empty && newPage != page.PageGuid)
                {
                    throw new Error(this.__ResStr("pageRename", "A page with Url '{0}' already exists."), page.Url);
                }

                UpdateStatusEnum status = await DataProvider.UpdateAsync(page.PageGuid, page.PageGuid, page);

                switch (status)
                {
                case UpdateStatusEnum.OK:
                    break;

                case UpdateStatusEnum.NewKeyExists:
                    throw new InternalError("Unexpected UpdateStatusEnum.NewKeyExists in SavePageDefinition");

                case UpdateStatusEnum.RecordDeleted:
                    throw new InternalError("Unexpected UpdateStatusEnum.RecordDeleted in SavePageDefinition");
                }
                await SetCachedPageAsync(page);

                await Manager.StaticPageManager.RemovePageAsync(page.Url);

                if (newPage == Guid.Empty)
                {
                    DesignedPagesDictionaryByUrl designedPagesByUrl = await GetDesignedPagesWithoutLockAsync();

                    designedPagesByUrl.Remove(oldPage.Url.ToLower());

                    PageDefinition.DesignedPage desPage = new PageDefinition.DesignedPage()
                    {
                        PageGuid = page.PageGuid, Url = page.Url,
                    };
                    await AddDesignedPageAsync(designedPagesByUrl, page.Url.ToLower(), desPage);
                }
                await lockObject.UnlockAsync();
            }
            await Auditing.AddAuditAsync($"{nameof(PageDefinitionDataProvider)}.{nameof(SavePageDefinitionAsync)}", oldPage.Url, oldPage.PageGuid,
                                         "Save Page",
                                         DataBefore : oldPage,
                                         DataAfter : page,
                                         ExpensiveMultiInstance : true
                                         );
        }