Ejemplo n.º 1
0
        public async Task <PageData> GeneratePageData(string itemid, PayloadType itemLoadType, List <ScopeType> itemScopeTypes, string datasourceFieldName, string itemLanguage = "en")
        {
            ScItemsResponse response = await GetItemById(itemid, itemLoadType, itemScopeTypes, itemLanguage);

            if (response == null)
            {
                return(null);
            }

            ISitecoreItem item = response.First();

            if (item == null)
            {
                return(null);
            }

            PageData pageData = new PageData {
                PageName               = item.DisplayName,
                ItemContext            = response,
                NavigationTitle        = item.GetValueFromField(Constants.Sitecore.Fields.Navigation.NavigationTitle),
                PageType               = item.GetTemplateName(),
                DataSourceFromChildren = await GetDatasourceFromChildren(item),
                DataSourceFromField    = await GetDataSourceFromFieldName(item, datasourceFieldName)
            };

            return(pageData);
        }
Ejemplo n.º 2
0
        public Task <Page> LoadPageByPageData(PageData pageData)
        {
            TaskCompletionSource <Page> taskCompletions = new TaskCompletionSource <Page> ();

            Task.Run(() => {
                if (pageData == null || pageData.ItemContext == null)
                {
                    taskCompletions.SetException(new PageFailedException("PageData or ItemContext is empty"));
                }

                ISitecoreItem item = pageData.ItemContext.First();

                if (item == null)
                {
                    string message = $"Sitecore Item is null for page {pageData.PageName}";
                    taskCompletions.SetException(new PageFailedException(pageData.PageName, message));
                }


                Type pageType = Type.GetType($"HabitatApp.Views.Pages.{item.GetTemplateName()}");

                if (pageType == null)
                {
                    string message = $"Could not identify pagetype for page name {pageData.PageName}";
                    taskCompletions.SetException(new PageFailedException(pageData.PageName, message));
                }


                try {
                    //Load page by page type
                    Page currentPage = App.AppInstance.Container.Resolve(pageType) as Page;

                    IViewModel viewModel = (IViewModel)currentPage.BindingContext;

                    viewModel.PageContext = pageData;

                    taskCompletions.SetResult(currentPage);
                } catch (Exception ex) {
                    string message = $"Could not resolve page for page name {pageData.PageName}";
                    taskCompletions.SetException(new PageFailedException(pageData.PageName, message, ex));
                }
            });

            return(taskCompletions.Task);
        }