示例#1
0
        public static async Task <IActionResult> GetHero(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "index1")] HttpRequest req,
            [Table(siteDisplayName, heroPk, heroRk, Connection = "AzureWebJobsStorage")] DisplayContent heroDisplay,
            [Table(siteDisplayName, skillPk, skillRk, Connection = "AzureWebJobsStorage")] DisplayContent skillsDisplay
            )
        {
            var hvm = new BasicContentViewModel();

            hvm.RequestPath = req?.Path.Value;

            var client    = GetBlobClient();
            var heroText  = string.Empty;
            var skillText = string.Empty;

            if (heroDisplay != null && heroDisplay.Published)
            {
                heroText = await GetTextFromBlob(client, siteCopyName, heroDisplay.BlobName, heroDisplay.HtmlContent).ConfigureAwait(false);
            }
            if (skillsDisplay != null && skillsDisplay.Published)
            {
                skillText = await GetTextFromBlob(client, siteCopyName, skillsDisplay.BlobName, skillsDisplay.HtmlContent).ConfigureAwait(false);
            }

            hvm.Content.Add(heroPk, heroText);
            hvm.Content.Add(skillPk, skillText);
            return((heroDisplay != null || skillsDisplay != null)
               ? (ActionResult) new OkObjectResult(hvm)
               : new NotFoundResult());
        }
示例#2
0
        private async Task <BasicContentViewModel> GetJsonData(string endpoint)
        {
            BasicContentViewModel data = null;
            var client = _clientFactory.CreateClient("ServerlessApi");

            try
            {
                data = await client.GetFromJsonAsync <BasicContentViewModel>(endpoint, jso).ConfigureAwait(false);
            }
            catch (HttpRequestException ex)
            {
                if (data is not null)
                {
                    data.RequestPath = ex.StatusCode.ToString() + " ERROR";
                }
            }
            catch (NotSupportedException ex)
            {
                if (data is not null)
                {
                    data.RequestPath = ex.Message + " ERROR";
                }
            }

            catch (JsonException ex)
            {
                if (data is not null)
                {
                    data.RequestPath = ex.Message + " ERROR";
                }
            }
            return(data);
        }
示例#3
0
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "documents/{key}")] HttpRequest req, string key,
            IBinder binder,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            var hvm = new BasicContentViewModel
            {
                RequestPath = req?.Path.Value
            };

            try
            {
                string documentText = await RhzStorageTools.ReadTextFromBlob(binder, RhzStorageTools.techDocs, key, "AzureWebJobsStorage").ConfigureAwait(false);
                if (documentText == null)
                {
                    throw new System.Exception($"Possible Document name missmatch request id {key} cannot be resolved.");
                }
                hvm.Content.Add("document", documentText);
                return new OkObjectResult(hvm);
            }
            catch (System.Exception ex)
            {
                log.LogInformation($"Data Error: {ex.Message}");
                throw;
            }
        }
示例#4
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "documents")] HttpRequest req,
            [Table(RhzStorageTools.postsName, Connection = "AzureWebJobsStorage")] CloudTable postsTable,
            [Table(RhzStorageTools.siteDisplayName, Connection = "AzureWebJobsStorage")] CloudTable siteDisplayTable,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            var getPostsQuery = RhzStorageTools.GenerateContentQuery <PostContent>(RhzStorageTools.techPostPk);


            var interestingLinksQuery = RhzStorageTools.GenerateContentQuery <LinkContent>(RhzStorageTools.interestingLinksPk);
            var dotnetLinksQuery      = RhzStorageTools.GenerateContentQuery <LinkContent>(RhzStorageTools.dotNetLinksPk);

            var postListSegment = await postsTable.ExecuteQuerySegmentedAsync(getPostsQuery, null).ConfigureAwait(false);

            var iLinkSegment = await siteDisplayTable.ExecuteQuerySegmentedAsync(interestingLinksQuery, null).ConfigureAwait(false);

            var dLinkSegment = await siteDisplayTable.ExecuteQuerySegmentedAsync(dotnetLinksQuery, null).ConfigureAwait(false);


            var lists = postListSegment.Where(pl => pl.Published).Select(pc =>
                                                                         new PostContentDto
            {
                Caption     = pc.Caption,
                Preview     = pc.Preview,
                BlobName    = pc.BlobName,
                Published   = pc.Published,
                PublishedOn = pc.PublishedOn,
                UpdatedOn   = pc.UpdatedOn
            });

            var hvm = new BasicContentViewModel
            {
                RequestPath = req?.Path.Value
            };

            hvm.Lists.Add(RhzStorageTools.interestingLinksPk, iLinkSegment.Where(lc => lc.Published).Select(lc =>
                                                                                                            new LinkContentDto
            {
                Caption = lc.Caption,
                Target  = lc.Target,
                Url     = lc.Url
            }));
            hvm.Lists.Add(RhzStorageTools.dotNetLinksPk, dLinkSegment.Where(lc => lc.Published).Select(lc =>
                                                                                                       new LinkContentDto
            {
                Caption = lc.Caption,
                Target  = lc.Target,
                Url     = lc.Url
            }));
            hvm.Documents = lists;


            return(new OkObjectResult(hvm));
        }
示例#5
0
        public static async Task <IActionResult> GetAbout(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "about1")] HttpRequest req,
            [Table(siteDisplayName, Connection = "AzureWebJobsStorage")] CloudTable siteDisplayTable
            )
        {
            var interestingLinksQuery = GenerateContentQuery <LinkContent>(interestingLinksPk);
            var dotnetLinksQuery      = GenerateContentQuery <LinkContent>(dotNetLinksPk);

            var getAboutOp = TableOperation.Retrieve <DisplayContent>(aboutPk, aboutRk);

            var iLinkSegment = await siteDisplayTable.ExecuteQuerySegmentedAsync(interestingLinksQuery, null).ConfigureAwait(false);

            var dLinkSegment = await siteDisplayTable.ExecuteQuerySegmentedAsync(dotnetLinksQuery, null).ConfigureAwait(false);

            var aboutData = await siteDisplayTable.ExecuteAsync(getAboutOp).ConfigureAwait(false);

            if (aboutData.Result == null)
            {
                return(new NotFoundResult());
            }
            var aboutDisplay = (DisplayContent)aboutData.Result;


            var hvm = new BasicContentViewModel();

            hvm.RequestPath = req?.Path.Value;

            var client = GetBlobClient();

            var aboutText = string.Empty;

            if (aboutDisplay != null && aboutDisplay.Published)
            {
                aboutText = await GetTextFromBlob(client, siteCopyName, aboutDisplay.BlobName, aboutDisplay.HtmlContent).ConfigureAwait(false);
            }

            hvm.Lists.Add(interestingLinksPk, iLinkSegment.Where(lc => lc.Published).Select(lc =>
                                                                                            new LinkContentDto
            {
                Caption = lc.Caption,
                Target  = lc.Target,
                Url     = lc.Url
            }));
            hvm.Lists.Add(dotNetLinksPk, dLinkSegment.Where(lc => lc.Published).Select(lc =>
                                                                                       new LinkContentDto
            {
                Caption = lc.Caption,
                Target  = lc.Target,
                Url     = lc.Url
            }));
            hvm.Content.Add(aboutPk, aboutText);

            return((aboutDisplay != null)
               ? (ActionResult) new OkObjectResult(hvm)
               : new NotFoundResult());
        }
示例#6
0
        public static async Task <IActionResult> GetPostList(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "documentList1")] HttpRequest req,
            [Table(postsName, Connection = "AzureWebJobsStorage")] CloudTable postsTable,
            [Table(siteDisplayName, Connection = "AzureWebJobsStorage")] CloudTable siteDisplayTable
            )
        {
            var getPostsQuery = GenerateContentQuery <PostContent>(testPostPk);


            var interestingLinksQuery = GenerateContentQuery <LinkContent>(interestingLinksPk);
            var dotnetLinksQuery      = GenerateContentQuery <LinkContent>(dotNetLinksPk);

            var postListSegment = await postsTable.ExecuteQuerySegmentedAsync(getPostsQuery, null).ConfigureAwait(false);

            var iLinkSegment = await siteDisplayTable.ExecuteQuerySegmentedAsync(interestingLinksQuery, null).ConfigureAwait(false);

            var dLinkSegment = await siteDisplayTable.ExecuteQuerySegmentedAsync(dotnetLinksQuery, null).ConfigureAwait(false);


            var lists = postListSegment.Where(pl => pl.Published).Select(pc =>
                                                                         new PostContentDto
            {
                Key         = pc.RowKey,
                Caption     = pc.Caption,
                Preview     = pc.Preview,
                BlobName    = pc.BlobName,
                Published   = pc.Published,
                PublishedOn = pc.PublishedOn,
                UpdatedOn   = pc.UpdatedOn
            });

            var hvm = new BasicContentViewModel();

            hvm.RequestPath = req?.Path.Value;

            hvm.Lists.Add(interestingLinksPk, iLinkSegment.Where(lc => lc.Published).Select(lc =>
                                                                                            new LinkContentDto
            {
                Caption = lc.Caption,
                Target  = lc.Target,
                Url     = lc.Url
            }));
            hvm.Lists.Add(dotNetLinksPk, dLinkSegment.Where(lc => lc.Published).Select(lc =>
                                                                                       new LinkContentDto
            {
                Caption = lc.Caption,
                Target  = lc.Target,
                Url     = lc.Url
            }));
            hvm.Documents = lists;


            return(new OkObjectResult(hvm));
        }
示例#7
0
        public static async Task <IActionResult> GetPost(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "document1/{key}")] HttpRequest req, string key,
            //[Table(postsName, testPostPk, "010286c659974974bf064fed7d7a055c", Connection = "AzureWebJobsStorage")] PostContent documentDisplay
            [Table(postsName, Connection = "AzureWebJobsStorage")] CloudTable postsTable
            )
        {
            var hvm = new BasicContentViewModel();

            hvm.RequestPath = req?.Path.Value;

            var getDocOp = TableOperation.Retrieve <PostContent>(testPostPk, key);

            var postData = await postsTable.ExecuteAsync(getDocOp).ConfigureAwait(false);

            //if (postData.Result == null)
            //{
            //    return new NotFoundResult();
            //}
            //var documentDisplay = (PostContent)postData.Result;

            //-- Alternative start
            if (postData.HttpStatusCode == 200)
            {
                var documentDisplay = (PostContent)postData.Result;
                var client          = GetBlobClient();
                var documentText    = string.Empty;
                if (documentDisplay != null && documentDisplay.Published)
                {
                    documentText = await GetTextFromBlob(client, techDocs, documentDisplay.BlobName).ConfigureAwait(false);

                    hvm.Content.Add("document", documentText);
                    return(new OkObjectResult(hvm));
                }
            }
            return(new NotFoundResult());
            //-- Alternative end

            //var client = GetBlobClient();
            //var documentText = string.Empty;
            //if(documentDisplay != null && documentDisplay.Published)
            //{
            //    documentText = await GetTextFromBlob(client, techDocs, documentDisplay.BlobName).ConfigureAwait(false);
            //}


            //hvm.Content.Add("document", documentText);
            //return (documentDisplay != null)
            //   ? (ActionResult)new OkObjectResult(hvm)
            //   : new NotFoundResult();
        }
示例#8
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "index")] HttpRequest req,
            [Table(RhzStorageTools.siteDisplayName, RhzStorageTools.heroPk, RhzStorageTools.heroRk, Connection = "AzureWebJobsStorage")] DisplayContent heroDisplay,
            [Table(RhzStorageTools.siteDisplayName, RhzStorageTools.skillPk, RhzStorageTools.skillRk, Connection = "AzureWebJobsStorage")] DisplayContent skillsDisplay,
            IBinder binder,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            var hvm = new BasicContentViewModel
            {
                RequestPath = req?.Path.Value
            };
            string heroText;

            if (heroDisplay != null && heroDisplay.Published)
            {
                heroText = await RhzStorageTools.ReadTextFromBlob(binder, RhzStorageTools.siteCopyName, heroDisplay.BlobName, "AzureWebJobsStorage").ConfigureAwait(false);
            }
            else
            {
                heroText = heroDisplay.HtmlContent ?? string.Empty;
            }

            string skillText;

            if (skillsDisplay != null && skillsDisplay.Published)
            {
                skillText = await RhzStorageTools.ReadTextFromBlob(binder, RhzStorageTools.siteCopyName, skillsDisplay.BlobName, "AzureWebJobsStorage").ConfigureAwait(false);
            }
            else
            {
                skillText = skillsDisplay.HtmlContent ?? string.Empty;
            }

            hvm.Content.Add(RhzStorageTools.heroPk, heroText);
            hvm.Content.Add(RhzStorageTools.skillPk, skillText);
            return((heroDisplay != null || skillsDisplay != null)
               ? (ActionResult) new OkObjectResult(hvm)
               : new NotFoundResult());
        }
示例#9
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "about")] HttpRequest req,
            [Table(RhzStorageTools.siteDisplayName, Connection = "AzureWebJobsStorage")] CloudTable siteDisplayTable,
            IBinder binder,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            var interestingLinksQuery = RhzStorageTools.GenerateContentQuery <LinkContent>(RhzStorageTools.interestingLinksPk);
            var dotnetLinksQuery      = RhzStorageTools.GenerateContentQuery <LinkContent>(RhzStorageTools.dotNetLinksPk);
            var mailStatusQuery       = RhzStorageTools.GenerateContentQuery <LinkContent>(RhzStorageTools.mailStatusPk);
            var getAboutOp            = TableOperation.Retrieve <DisplayContent>(RhzStorageTools.aboutPk, RhzStorageTools.aboutRk);

            var iLinkSegment = await siteDisplayTable.ExecuteQuerySegmentedAsync(interestingLinksQuery, null).ConfigureAwait(false);

            var dLinkSegment = await siteDisplayTable.ExecuteQuerySegmentedAsync(dotnetLinksQuery, null).ConfigureAwait(false);

            var mailstatusSegment = await siteDisplayTable.ExecuteQuerySegmentedAsync(mailStatusQuery, null).ConfigureAwait(false);

            var aboutData = await siteDisplayTable.ExecuteAsync(getAboutOp).ConfigureAwait(false);

            if (aboutData.Result == null)
            {
                return(new NotFoundResult());
            }
            var aboutDisplay = (DisplayContent)aboutData.Result;

            var hvm = new BasicContentViewModel
            {
                RequestPath = req?.Path.Value
            };

            var aboutText = string.Empty;

            if (aboutDisplay != null && aboutDisplay.Published)
            {
                aboutText = await RhzStorageTools.ReadTextFromBlob(binder, RhzStorageTools.siteCopyName, aboutDisplay.BlobName, "AzureWebJobsStorage").ConfigureAwait(false);
            }
            else
            {
                aboutText = aboutDisplay.HtmlContent ?? string.Empty;
            }

            hvm.Lists.Add(RhzStorageTools.interestingLinksPk, iLinkSegment.Where(lc => lc.Published).Select(lc =>
                                                                                                            new LinkContentDto
            {
                Caption = lc.Caption,
                Target  = lc.Target,
                Url     = lc.Url
            }));
            hvm.Lists.Add(RhzStorageTools.dotNetLinksPk, dLinkSegment.Where(lc => lc.Published).Select(lc =>
                                                                                                       new LinkContentDto
            {
                Caption = lc.Caption,
                Target  = lc.Target,
                Url     = lc.Url
            }));
            hvm.Lists.Add(RhzStorageTools.mailStatusPk, mailstatusSegment.Where(lc => lc.Published).Select(lc =>
                                                                                                           new LinkContentDto
            {
                Caption = lc.Caption,
                Target  = lc.Target,
                Url     = lc.Url
            }));
            hvm.Content.Add(RhzStorageTools.aboutPk, aboutText);

            return((aboutDisplay != null)
               ? (ActionResult) new OkObjectResult(hvm)
               : new NotFoundResult());
        }