Example #1
0
        public static async Task <List <string> > RunOrchestrator(
            [OrchestrationTrigger] IDurableOrchestrationContext context)
        {
            PartitionKeyGenerator data = context.GetInput <PartitionKeyGenerator>();
            var outputs = new List <string>();

            foreach (var item in data.PartitionKey)
            {
                outputs.Add(await context.CallActivityAsync <string>("Activity_ScheduleExam", item));
            }

            return(outputs);
        }
Example #2
0
        public static void Run([BlobTrigger("inputcsv/{name}.csv", Connection = "AzureWebJobsStorage")] Stream myBlob, string name, ILogger log)
        {
            try
            {
                //var parser = new TextFieldParser(myBlob, Encoding.UTF8);
                //parser.TextFieldType = FieldType.Delimited;
                //parser.SetDelimiters(",");
                //parser.HasFieldsEnclosedInQuotes = true;
                //parser.TrimWhiteSpace = true;

                //int candidateid = 0;
                //List<CandidatesModel> candidatesList = new List<CandidatesModel>();
                //while (!parser.EndOfData)
                //{
                //    string[] row = parser.ReadFields();
                //    bool isHeader = (row[0] == "CandidateReference");
                //    if (isHeader)
                //        continue;

                //    var candidates = new CandidatesModel(row);
                //    candidates.Id = ++candidateid;
                //    candidatesList.Add(candidates);
                //}

                //InsertIntoCandidateEntity(candidatesList, name);

                try
                {
                    using (var reader = new StreamReader(myBlob, Encoding.Default))
                        using (var csv = new CsvReader(reader))
                        {
                            csv.Configuration.RegisterClassMap <CandidateMapper>();
                            var records = csv.GetRecords <CandidatesModel>().ToList();
                            InsertIntoCandidateEntity(records, name);
                        }
                }
                catch (UnauthorizedAccessException e)
                {
                    throw new Exception(e.Message);
                }
                catch (FieldValidationException e)
                {
                    throw new Exception(e.Message);
                }
                catch (CsvHelperException e)
                {
                    throw new Exception(e.Message);
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }

                log.LogInformation($"Calling https://zixerapp.azurewebsites.net/api/ScheduleExam_HttpStart with {name}");

                BaseClient            client = new BaseClient("https://zixerapp.azurewebsites.net/api/ScheduleExam_HttpStart");
                PartitionKeyGenerator keyGen = new PartitionKeyGenerator();
                keyGen.PartitionKey = new List <string> {
                    name
                };
                string jsonSerialize = JsonConvert.SerializeObject(keyGen);
                var    response      = client.PostCallAsync("", jsonSerialize).GetAwaiter().GetResult();

                log.LogInformation(response.ResponseMessage);
            }
            catch (Exception ex)
            {
                log.LogError(ex.Message == null ? ex.InnerException.ToString() : ex.Message);
            }
        }