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

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

                if (!result.Success)
                {
                    Label_Results.Text  = "Error uploading:\r\n";
                    Label_Results.Text += $"{result.AirtableApiError.ErrorMessage}\r\n{result.AirtableApiError}";
                    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
                    }
                    await App.Database.SaveEventTeamMatchAsync(match);

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