public IEnumerable<RecordDescription> GetRecordDescriptions(SearchCondition param) { lock (_recordDescriptions) { var temp = _recordDescriptions.AsEnumerable(); if (param.ComponentType != null) { temp = temp.Where(x => x.ComponentType == param.ComponentType); } if (param.DataType != null) { temp = temp.Where(x => x.DataType == param.DataType); } if (param.PortName != null) { temp = temp.Where(x => x.PortName == param.PortName); } if (param.StartDateTime != null) { temp = temp.Where(x => x.CreatedDateTime >= param.StartDateTime); } if (param.EndDateTime != null) { temp = temp.Where(x => x.CreatedDateTime <= param.EndDateTime); } return temp; } }
/// <summary> /// 非同期でデータベースの検索を行う /// </summary> private IObservable<IEnumerable<RecordDescription>> SearchAsync(SignalNotifier isSearching) { isSearching.Increment(); // 検索中 var condition = new SearchCondition() { DataType = DataType, ComponentType = ComponentType, PortName = PortName, StartDateTime = StartDate, EndDateTime = EndDate }; return Observable.Start(() => { //SearchResults.Clear(); var ret = _recordDescriptionRepository.GetRecordDescriptions(condition); //isSearching.Decrement(); //検索完了 return ret; }) .Finally(() => isSearching.Decrement()) .Catch((Exception ex) => Messenger.Raise(new InformationMessage("データベースアクセスに失敗しました。", "エラー", "ShowError"))); }
public IEnumerable<RecordDescription> GetRecordDescriptions(SearchCondition param) { // 引数に応じて検索条件を組み立てる。*はなんでもあり。 var conditions = new List<string>(); if (!string.IsNullOrEmpty(param.DataType) && param.DataType!="*") { conditions.Add("DataType = @DataType"); } if (!string.IsNullOrEmpty(param.ComponentType) && param.ComponentType != "*") { conditions.Add("ComponentType = @ComponentType"); } if (!string.IsNullOrEmpty(param.PortName) && param.PortName != "*") { conditions.Add("PortName = @PortName"); } if (param.StartDateTime.HasValue) { conditions.Add("CreatedDateTime >= @StartDateTime"); } if (param.EndDateTime.HasValue) { conditions.Add("CreatedDateTime <= @EndDateTime"); } string condition = ""; if (conditions.Count != 0) { condition = "where " + string.Join(" and ", conditions); } var descs = DbExecutor.Select<RecordDescription>( new SQLiteConnection(_connectionString), @"select * from RecordDescriptions " + condition, param); return descs; }