Exemplo n.º 1
0
        async private Task <int> AirtableSendNewRecords(AirtableBase airtableBase,
                                                        List <Fields> newRecordList)
        {
            AirtableCreateUpdateReplaceMultipleRecordsResponse result;
            List <Fields> sendList   = new List <Fields>();
            int           finalCount = 0;

            while (newRecordList.Count > 0)
            {
                sendList.Clear();
                do
                {
                    sendList.Add(newRecordList[0]);
                    newRecordList.RemoveAt(0);
                } while (newRecordList.Count > 0 && sendList.Count < 10);
                result = await airtableBase.CreateMultipleRecords("Match", sendList.ToArray());

                if (!result.Success)
                {
                    Label_Results.Text  = "Error uploading:\r\n";
                    Label_Results.Text += $"{result.AirtableApiError.ErrorMessage}\r\n";
                    return(-1);
                }
                foreach (AirtableRecord rec in result.Records)
                {
                    EventTeamMatch match = App.Database.GetEventTeamMatchAsyncUuid(rec.GetField("Uuid").ToString());
                    match.Changed++; // mark as uploaded
                    if (match.Changed % 2 == 1)
                    {
                        match.Changed++; // make even so it doesn't send again
                    }
                    match.AirtableId = rec.Id;
                    await App.Database.SaveEventTeamMatchAsync(match);

                    finalCount++;
                }
                if (newRecordList.Count > 0)
                {
                    // can only send 5 batches per second, make sure that doesn't happen
                    System.Threading.Thread.Sleep(500);
                }
            }
            return(finalCount);
        }