public async Task <IActionResult> GetDataFiles([FromRoute] long?id, [FromQuery] bool withUrl) { if (id == null) { return(JsonBadRequest("DataSet ID is required.")); } var dataSet = await dataSetRepository.GetDataSetIncludeDataSetEntryAndDataAsync(id.Value); if (dataSet == null) { return(JsonNotFound($"DataSet Id {id.Value} is not found.")); } var model = new DataFileOutputModel(dataSet); if (dataSet.DataSetEntries != null) { //エントリの作成開始 var entities = new Dictionary <string, List <ApiModels.DataApiModels.DataFileOutputModel> >(); var flatEntries = new ConcurrentQueue <ApiModels.DataApiModels.DataFileOutputModel>(); //空のデータ種別も表示したい&順番を統一したいので、先に初期化しておく foreach (var dataType in dataTypeRepository.GetAllWithOrderby(d => d.SortOrder, true)) { entities.Add(dataType.Name, new List <ApiModels.DataApiModels.DataFileOutputModel>()); } //エントリを並列で取得する if (dataSet.IsFlat) { dataSet.DataSetEntries.AsParallel().ForAll(entry => { var dataFiles = dataLogic.GetDataFiles(entry.Data, withUrl); foreach (var x in dataFiles) { flatEntries.Enqueue(x); } }); } else { dataSet.DataSetEntries.AsParallel().ForAll(entry => { var key = entry.DataType.Name; var dataFiles = dataLogic.GetDataFiles(entry.Data, withUrl); lock (entities) { entities[key].AddRange(dataFiles); } }); } model.SetEntries(entities); model.FlatEntries = flatEntries; } return(JsonOK(model)); }
public async Task <IActionResult> GetFiles([FromRoute] long id, [FromQuery] bool withUrl) { //データの存在チェック var exist = await dataRepository.ExistsAsync(d => d.Id == id); if (exist == false) { return(JsonNotFound($"Data ID {id} is not found.")); } dataLogic.GetDataFiles(id, withUrl); return(JsonOK(dataLogic.GetDataFiles(id, withUrl))); }
public async Task <IActionResult> GetDataFiles([FromRoute] long?id, [FromQuery] bool withUrl) { if (id == null) { return(JsonBadRequest("DataSet ID is required.")); } var dataSet = await dataSetRepository.GetDataSetIncludeDataSetEntryAsync(id.Value); if (dataSet == null) { return(JsonNotFound($"DataSet Id {id.Value} is not found.")); } var model = new DataFileOutputModel(dataSet); if (dataSet.DataSetEntries != null) { //エントリの作成開始。最初はDictionary形式で var entities = new Dictionary <string, List <ApiModels.DataApiModels.DataFileOutputModel> >(); //空のデータ種別も表示したい&順番を統一したいので、先に初期化しておく foreach (var dataType in dataTypeRepository.GetAllWithOrderby(d => d.SortOrder, true)) { entities.Add(dataType.Name, new List <ApiModels.DataApiModels.DataFileOutputModel>()); } //エントリを一つずつ突っ込んでいく。件数次第では遅いかも。 foreach (var entry in dataSet.DataSetEntries) { string key = entry.DataType.Name; var dataFiles = dataLogic.GetDataFiles(entry.DataId, withUrl); entities[key].AddRange(dataFiles); } model.SetEntries(entities); } return(JsonOK(model)); }