Exemplo n.º 1
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;
            }
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
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());
        }
Exemplo n.º 4
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());
        }
Exemplo n.º 5
0
        public static async Task Run(
            [QueueTrigger("newdocs", Connection = "AzureWebJobsStorage")] DocumentNotify myQueueItem,
            [Table(RhzStorageTools.postsName, Connection = "AzureWebJobsStorage")] CloudTable postsTable,
            //[Table(RhzStorageTools.postsName)] IAsyncCollector<PostContent> postsTable,  // this and the commented line below are alternatives .
            IBinder binder,
            ILogger log)
        {
            log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");

            string text = await RhzStorageTools.ReadTextFromBlob(binder, RhzStorageTools.techDocs, myQueueItem.BlobName, "AzureWebJobsStorage").ConfigureAwait(false);

            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(text);

            log.LogInformation($"Document Loaded length: {doc.ToString().Length}");

            // Check the first 2 lines of the document
            // This still needs a lot of work, not thought of all the possibilites yet, just get it functioning
            var linePosition = 1;

            try
            {
                var cap = doc.DocumentNode.SelectSingleNode($"/html[1]/body[1]/div[1]/p[{linePosition}]/span[1]");
                if (cap == null)
                {
                    linePosition++;
                    cap = doc.DocumentNode.SelectSingleNode($"/html[1]/body[1]/div[1]/p[{linePosition}]/span[1]");
                }

                log.LogInformation($"Preview Position: {linePosition}");

                var captionString = Path.GetFileNameWithoutExtension(myQueueItem.BlobName.Replace("-", " "));


                TableOperation insertUpdateOp = null;
                TableOperation insertIdxOp    = null;

                var post = new PostContent
                {
                    PartitionKey = RhzStorageTools.techPostPk,
                    BlobName     = myQueueItem.BlobName,
                    Published    = true,
                    PublishedOn  = myQueueItem.PublishedOn,
                    UpdatedOn    = myQueueItem.PublishedOn,
                    Caption      = captionString,
                    Preview      = cap?.InnerText ?? "Preview not provided",
                    RowKey       = Guid.NewGuid().ToString("N"),
                    ETag         = "*"
                };

                // check if this document index exists

                var fetchIdxOp   = TableOperation.Retrieve <PostContentIdx>(RhzStorageTools.techPostIndexPk, myQueueItem.BlobName);
                var newIdxRecord = await postsTable.ExecuteAsync(fetchIdxOp);

                if (newIdxRecord.Result != null)
                {
                    PostContentIdx documentIdx = null;
                    documentIdx      = ((PostContentIdx)newIdxRecord.Result);
                    post.RowKey      = documentIdx.DocumentId;
                    post.PublishedOn = documentIdx.PublishedOn;
                    insertUpdateOp   = TableOperation.Replace(post);
                }
                else
                {
                    insertUpdateOp = TableOperation.Insert(post);
                    insertIdxOp    = TableOperation.Insert(new PostContentIdx
                    {
                        PartitionKey = RhzStorageTools.techPostIndexPk,
                        RowKey       = myQueueItem.BlobName,
                        DocumentId   = post.RowKey,
                        PublishedOn  = myQueueItem.PublishedOn,
                    });
                }

                var newRecord = await postsTable.ExecuteAsync(insertUpdateOp);

                if ((insertIdxOp != null) && newRecord.HttpStatusCode == (int)HttpStatusCode.NoContent)
                {
                    _ = await postsTable.ExecuteAsync(insertIdxOp);
                }

                //await postsTable.AddAsync(post);
                log.LogInformation($"New Post status: {newRecord.HttpStatusCode}");
            }
            catch (Exception ex)
            {
                log.LogInformation($"Error {ex.Message}: {myQueueItem}");
            }
        }