Example #1
0
        public override int Fill(DataSet dataSet)
        {
            int filled = 0;

            foreach (DataTable table in dataSet.Tables)
            {
                DateTime lastModified;
                if (lastModifiedDict.ContainsKey(table.TableName))
                {
                    lastModified = lastModifiedDict[table.TableName];
                }
                else
                {
                    lastModified = DateTime.Now - TimeSpan.FromDays(90); // TODO: 90 days is arbitrary
                }
                int    modifiedTime = dateTimeConverter.ToUnixTime(lastModified);
                JToken token        = webServiceClient.DoSync(modifiedTime.ToString(), table.TableName);
                if (token != null)
                {
                    DataTable dataTable  = ToDataTable(token["updated"]);
                    DataTable mergeTable = dataSet.Tables[table.TableName].Clone();
                    foreach (DataRow row in dataTable.Rows)
                    {
                        if (null != BeforeImport)
                        {
                            BeforeImport(mergeTable, row);
                        }
                        mergeTable.ImportRow(row);
                    }
                    dataSet.Merge(mergeTable);
                }
            }
            return(filled);
        }