コード例 #1
0
        private async Task UpdateTable(DataTable dt)
        {
            if (!_resourcesMapping.ContainsKey(dt.TableName) || UpdatesPerformed.Contains(dt) || dt.Rows.Count == 0)
            {
                return;
            }

            var methodName = $"Update{dt.TableName}Async";

            // TODO handle the case of a write error on a batch of rows. Right now
            // the table is reported as not saved while in fact some rows might be saved
            // which would lead to inconsistency on the local Amica DB.

            foreach (DataRow row in dt.Rows)
            {
                await((Task)GetType().GetMethod(methodName).Invoke(this, new object[] { row, true }));
                if (ActionPerformed == ActionPerformed.Aborted)
                {
                    goto End;
                }
            }

            UpdatesPerformed.Add(dt);
            End :;
        }
コード例 #2
0
        /// <summary>
        /// Casts a DataRow to the mathcing object supported by the server, then sends the object upstream for update.
        /// </summary>
        /// <typeparam name="T">Type to which the DataRow should be casted.</typeparam>
        /// <param name="row">DataRow to be sent to the server.</param>
        /// <param name="batch">Wether this update is part of a batch operation or not.</param>
        /// <returns></returns>
        private async Task UpdateRowAsync <T>(DataRow row, bool batch) where T : BaseModel
        {
            if (!batch)
            {
                UpdatesPerformed.Clear();
            }
            await UpdateAsync <T>(row, batch);

            if (!batch)
            {
                UpdatesPerformed.Add(row.Table);
            }
        }