예제 #1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            try
            {
                string companyId = req.Query["companyId"];
                if (string.IsNullOrWhiteSpace(companyId))
                {
                    throw new ArgumentNullException($"{nameof(companyId)} is blank.");
                }

                string learningPath = req.Query["learningPath"];
                if (string.IsNullOrWhiteSpace(learningPath))
                {
                    throw new ArgumentNullException($"{nameof(learningPath)} is blank.");
                }

                BlobApi         blobApi      = await BlobApi.Instance;
                ContestResponse savedContest = await blobApi.GetContest(companyId, learningPath);

                string sponsorEmail = savedContest.MicrosoftAccountSponsor;

                return(new OkObjectResult(sponsorEmail));
            }
            catch (Exception ex)
            {
                log.LogWarning($"Unable to get sponsor email. {ex}");
                return(new BadRequestObjectResult($"{ex}"));
            }
        }
예제 #2
0
        public static async Task <IActionResult> RunQuery(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
            ILogger log)
        {
            try
            {
                string tpid = req.Query["customerId"];

                if (string.IsNullOrWhiteSpace(tpid))
                {
                    throw new ArgumentNullException("Expecting customerId in query param. Recieved empty string.");
                }

                BlobApi blobApi = await BlobApi.Instance;
                IList <ContestResponse> activeContests = await blobApi.GetContestResponseAsync(tpid);

                if (activeContests == null)
                {
                    throw new KeyNotFoundException($"Customer Code ({tpid}) not found.");
                }

                string response = activeContests.GetCollectionString();

                return(new OkObjectResult(response));
            }
            catch (Exception ex)
            {
                log.LogError(string.Format("Error in CreateChallenges: {0}", ex.Message));
                return(new BadRequestObjectResult(ex.Message));
            }
        }
예제 #3
0
        private static async Task <IList <ContestResponse> > CreateAndSaveChallengesAsync(string json, ILogger logger)
        {
            logger.LogInformation($"C# CreateChallenges function processing async: {json}");

            ChallengeRequest request = ContestFactory.CreateChallengeRequest(json);

            BlobApi       blobApi = await BlobApi.Instance;
            CloudSkillApi cscApi  = await CloudSkillApi.Instance;

            Tuple <IList <ContestResponse>, string> tuple = await blobApi.GetAllContestTupleAsync(request.BaseInputs.Mstpid);

            if (tuple?.Item1 != null)
            {
                request.LearningPaths = RemoveDuplicateLearningPaths(request, tuple.Item1);
                await blobApi.DeleteBlobAsync(tuple.Item2);
            }

            List <ContestResponse> response = await cscApi.CreateChallengesAsyc(request);

            logger.LogInformation($"Created the Challenges. Saving response to blob");

            if (tuple?.Item1 != null)
            {
                foreach (ContestResponse contest in tuple.Item1)
                {
                    response.Add(contest);
                }
            }

            await WriteToBlobAsync(request.BaseInputs, response);

            logger.LogInformation($"C# CreateChallenges function processed");

            return(response);
        }
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            try
            {
                string userName     = req.Query["userName"];
                string companyId    = req.Query["companyId"];
                string learningPath = req.Query["learningPath"];

                BlobApi         blobApi      = await BlobApi.Instance;
                ContestResponse savedContest = await blobApi.GetContest(companyId, learningPath);

                CloudSkillApi cloudSkillApi = await CloudSkillApi.Instance;
                int           progress      = await cloudSkillApi.GetUserProgressAsync(savedContest.ContestId, userName);

                return(new OkObjectResult(progress));
            }
            catch (Exception ex)
            {
                log.LogWarning($"GetLearnerProgress failed ({ex.Message})");
                return(new BadRequestObjectResult(ex.Message));
            }
        }
예제 #5
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger GetLearnerProgress function processed a request.");

            try
            {
                string userName = req.Query["userName"];
                if (string.IsNullOrWhiteSpace(userName))
                {
                    throw new ArgumentNullException($"{nameof(userName)} is blank.");
                }

                string contestId = req.Query["contestId"];
                if (string.IsNullOrWhiteSpace(contestId))
                {
                    string companyId = req.Query["companyId"];
                    if (string.IsNullOrWhiteSpace(companyId))
                    {
                        throw new ArgumentNullException($"{nameof(companyId)} is blank.");
                    }

                    string learningPath = req.Query["learningPath"];
                    if (string.IsNullOrWhiteSpace(learningPath))
                    {
                        throw new ArgumentNullException($"{nameof(learningPath)} is blank.");
                    }

                    BlobApi         blobApi      = await BlobApi.Instance;
                    ContestResponse savedContest = await blobApi.GetContest(companyId, learningPath);

                    contestId = savedContest.ContestId;
                }

                CloudSkillApi cloudSkillApi = await CloudSkillApi.Instance;
                Learner       learner       = await cloudSkillApi.GetLearner(contestId, userName);

                if (learner == null)
                {
                    return(new OkObjectResult(-1));
                }

                if (learner.PercentComplete == null)
                {
                    throw new NullReferenceException($"Unable to determine percent complete.");
                }

                return(new OkObjectResult(learner.PercentComplete));
            }
            catch (Exception ex)
            {
                log.LogWarning($"GetLearnerProgress failed ({ex.Message})");
                return(new BadRequestObjectResult(ex.Message));
            }
        }
예제 #6
0
        private static async Task WriteToBlobAsync(ContestRequest request, IList <ContestResponse> contests)
        {
            BlobApi blobApi = await BlobApi.Instance;

            // Writes the blob to storage
            BlobContents contents = new BlobContents
            {
                BaseInputs = request,
                Contests   = contests
            };
            string jsonString = JsonConvert.SerializeObject(contents);
            string fileName   = $"{request.Mstpid}-{DateTime.Now:yyyy-MM}-{Guid.NewGuid()}";
            await blobApi.UploadToBlobAsync(jsonString, fileName);
        }
예제 #7
0
        public static async Task <IActionResult> RunHttp(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            try
            {
                string         requestBody = await new StreamReader(req.Body).ReadToEndAsync();
                LearnerRequest request     = JsonConvert.DeserializeObject <LearnerRequest>(requestBody);

                BlobApi         blobApi = await BlobApi.Instance;
                ContestResponse contest = await blobApi.GetContest(request.CustomerId, request.CollectionName);

                CloudSkillApi cloudSkillApi  = await CloudSkillApi.Instance;
                Learner       learnerReponse = await cloudSkillApi.AddLearnerAsync(contest.ContestId, request.LearnerId);

                return(new OkObjectResult(contest.CollectionUrl));
            }
            catch (Exception ex)
            {
                log.LogError(string.Format("Error in AddLearnerToChallengeFromHttp: {0}", ex.Message));
                return(new BadRequestObjectResult(ex.Message));
            }
        }