Пример #1
0
        public static async Task <int> getNextWordNumber(CloudTable tabCats)
        {
            mainWordData MWD = new mainWordData();

            TableOperation query  = TableOperation.Retrieve <mainWordData>("mainWordData", "count");
            TableResult    tabRes = await tabCats.ExecuteAsync(query);

            if (tabRes.Result != null)
            {
                MWD = (mainWordData)tabRes.Result;
            }

            MWD.wordCount++;

            TableOperation writeBack = TableOperation.InsertOrReplace(MWD);
            await tabCats.ExecuteAsync(writeBack);

            return(MWD.wordCount);
        }
        public static async Task <IActionResult> createWordBulk(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            //Offenbar bekommt die Funktion automatisch ein korrekt eingerichtetes Objekt für die Tabelle mitgegeben
            [Table("categorization")] CloudTable tabCats,
            ILogger log)
        {
            List <bulkWordData> allBW;

            //Bulk data - array of objects with name, langu, desc as attributes
            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();

            if (requestBody == null || requestBody == "")
            {
                return(null);
            }

            log.LogInformation("dummy");

            allBW = JsonConvert.DeserializeObject <List <bulkWordData> >(requestBody);

            mainWordData   MWD    = new mainWordData();
            TableOperation query  = TableOperation.Retrieve <mainWordData>("mainWordData", "count");
            TableResult    tabRes = await tabCats.ExecuteAsync(query);

            if (tabRes.Result != null)
            {
                MWD = (mainWordData)tabRes.Result;
            }

            MWD.wordCount++;
            lastBulkWord = MWD.wordCount;

            bulkTO  = new TableBatchOperation();
            bulkTO2 = new TableBatchOperation();

            tmpAllW2NI = await intGetAllWordNames(tabCats);

            int bCount = 0;
            int xcount = 0;
            List <Task <IList <TableResult> > > batchTasks = new List <Task <IList <TableResult> > >();

            foreach (bulkWordData oneWord in allBW)
            {
                xcount++;
                if (oneWord.n == null || oneWord.n == "" || bCount == 54)
                {
                    var x = 0;
                }
                bCount++;
                await intCreateWord(tabCats, oneWord.n, true);

                if (bCount == 99)
                {
                    if (bulkTO.Count > 0)
                    {
                        batchTasks.Add(tabCats.ExecuteBatchAsync(bulkTO));
                    }
                    if (bulkTO2.Count > 0)
                    {
                        batchTasks.Add(tabCats.ExecuteBatchAsync(bulkTO2));
                    }
                    bCount = 0;
                    bulkTO.Clear();
                    bulkTO2.Clear();
                }
            }

            MWD.wordCount = lastBulkWord;
            TableOperation writeBack = TableOperation.InsertOrReplace(MWD);
            var            dummy     = tabCats.ExecuteAsync(writeBack);

            if (bulkTO.Count > 0)
            {
                batchTasks.Add(tabCats.ExecuteBatchAsync(bulkTO));
            }
            if (bulkTO2.Count > 0)
            {
                batchTasks.Add(tabCats.ExecuteBatchAsync(bulkTO2));
            }

            try
            {
                //Task.WaitAll(batchTasks.ToArray());
            }
            catch (System.Exception ex)
            {
                log.LogInformation(ex.Message);
                throw;
            }


            return(new OkObjectResult(""));
        }