private SyncedItemProgress GetSyncedItemProgress(IDataReader reader) { var item = new SyncedItemProgress(); item.ItemId = reader.GetString(0); if (!reader.IsDBNull(1)) { item.Status = (SyncJobItemStatus)Enum.Parse(typeof(SyncJobItemStatus), reader.GetString(1), true); } return(item); }
private void AddStatusResult(IDataReader reader, Dictionary <string, SyncedItemProgress> result, bool multipleIds) { if (reader.IsDBNull(0)) { return; } var itemIds = new List <string>(); var ids = reader.GetString(0); if (multipleIds) { itemIds = ids.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); } else { itemIds.Add(ids); } if (!reader.IsDBNull(1)) { SyncJobItemStatus status; var statusString = reader.GetString(1); if (string.Equals(statusString, "Completed", StringComparison.OrdinalIgnoreCase) || string.Equals(statusString, "CompletedWithError", StringComparison.OrdinalIgnoreCase)) { status = SyncJobItemStatus.Synced; } else { status = (SyncJobItemStatus)Enum.Parse(typeof(SyncJobItemStatus), statusString, true); } if (status == SyncJobItemStatus.Synced) { foreach (var itemId in itemIds) { result[itemId] = new SyncedItemProgress { Status = SyncJobItemStatus.Synced }; } } else { double progress = reader.IsDBNull(2) ? 0.0 : reader.GetDouble(2); foreach (var itemId in itemIds) { SyncedItemProgress currentStatus; if (!result.TryGetValue(itemId, out currentStatus) || (currentStatus.Status != SyncJobItemStatus.Synced && progress >= currentStatus.Progress)) { result[itemId] = new SyncedItemProgress { Status = status, Progress = progress }; } } } } }
public Dictionary <string, SyncedItemProgress> GetSyncedItemProgresses(SyncJobItemQuery query) { var result = new Dictionary <string, SyncedItemProgress>(); using (var connection = CreateConnection(true).Result) { using (var cmd = connection.CreateCommand()) { cmd.CommandText = "select ItemId,Status,Progress from SyncJobItems"; var whereClauses = new List <string>(); if (!string.IsNullOrWhiteSpace(query.TargetId)) { whereClauses.Add("TargetId=@TargetId"); cmd.Parameters.Add(cmd, "@TargetId", DbType.String).Value = query.TargetId; } if (query.Statuses.Length > 0) { var statuses = string.Join(",", query.Statuses.Select(i => "'" + i.ToString() + "'").ToArray()); whereClauses.Add(string.Format("Status in ({0})", statuses)); } if (whereClauses.Count > 0) { cmd.CommandText += " where " + string.Join(" AND ", whereClauses.ToArray()); } using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult)) { while (reader.Read()) { var itemId = reader.GetString(0); if (!reader.IsDBNull(1)) { var status = (SyncJobItemStatus)Enum.Parse(typeof(SyncJobItemStatus), reader.GetString(1), true); if (status == SyncJobItemStatus.Synced) { result[itemId] = new SyncedItemProgress { Status = SyncJobItemStatus.Synced }; } else { SyncedItemProgress currentStatus; double progress = reader.IsDBNull(2) ? 0.0 : reader.GetDouble(2); if (!result.TryGetValue(itemId, out currentStatus) || (currentStatus.Status != SyncJobItemStatus.Synced && progress >= currentStatus.Progress)) { result[itemId] = new SyncedItemProgress { Status = status, Progress = progress }; } } } } } } } return(result); }