public ResultList <EstudioDto> GetEstudios(string searchText, int pageIndex, int?pageCount) { var result = new ResultList <EstudioDto>(); UNIR.Comun.Servicios.RespuestaServicioOfArrayOfEstudioDtoWP8jzdkm resEstudios; var cache = _dataCache.Get <UNIR.Comun.Servicios.RespuestaServicioOfArrayOfEstudioDtoWP8jzdkm>(GlobalValues.CACHE_ESTUDIO, GlobalValues.GROUP_CACHE_GESTOR); if (cache != null) { resEstudios = cache; } else { var configMinutes = ConfigurationManager.AppSettings["TimeMinutesWsGestor"]; var minutes = 0; if (!int.TryParse(configMinutes, out minutes)) { minutes = GlobalValues.DEFAULT_MINUTE_CACHE; } resEstudios = _estudiosService.ObtenerEstudiosUNIR(0); _dataCache.Put(GlobalValues.CACHE_ESTUDIO, resEstudios, GlobalValues.GROUP_CACHE_GESTOR, TimeSpan.FromMinutes(minutes)); } pageCount = pageCount ?? 10; var query = resEstudios.Respuesta.AsQueryable(); if (!string.IsNullOrEmpty(searchText)) { query = query.Where( e => e.sNombreEstudio.ToLower().Trim().Contains(searchText.ToLower().Trim())); } var listado = query.Skip((pageIndex - 1) * pageCount.Value) .Take(pageCount.Value).ToList(); result.Elements = listado; result.TotalElements = query.Count(); result.PageCount = listado.Count; return(result); }
public void EnqueueProcess(Expression <Action> action, int?progressId = null) { var call = action.Body as MethodCallExpression; if (call == null) { throw new Exception("La expresión no corresponde a una llamada a un método"); } if (call.Object == null) { throw new Exception("La expresión no corresponde a un método de instancia"); } var methodInfo = call.Method; var argsValues = call.Arguments.Select(a => { var argAsObj = Expression.Convert(a, typeof(object)); return(Expression.Lambda <Func <object> >(argAsObj, null) .Compile()()); }); var targetOnly = Expression.Lambda(call.Object, null); var compiled = targetOnly.Compile(); var result = compiled.DynamicInvoke(null); var type = result.GetType(); Task.Run(() => { using (var container = AutofacConfig.Container.BeginLifetimeScope()) { var service = container.Resolve(type); try { var invokeData = methodInfo.Invoke(service, argsValues.ToArray()); var state = ProgressInfoState.Completed; if (invokeData != null && progressId.HasValue) { var baseResult = invokeData as BaseResult; if (baseResult != null) { state = baseResult.HasErrors ? ProgressInfoState.HasErrors : state; } _cache.Put(string.Format(GlobalValues.CACHE_PROGRESS_INFO, progressId), invokeData, TimeSpan.FromMinutes(30)); } var progress = _contenxt.ProgressInfo.Find(progressId); if (progress != null) { progress.State = state.ToString(); progress.Completion = 100; _contenxt.SaveChanges(); } } catch (Exception exception) { var log = LogManager.GetLogger(typeof(JobService)); log.Error("Migracion", exception); var logEntity = new Log { Date = DateTime.Now, Loger = typeof(JobService).FullName, Message = exception.Message, Exception = exception.ToString(), Level = GlobalValues.ERROR }; _contenxt.Log.Add(logEntity); _contenxt.SaveChanges(); if (progressId.HasValue) { var progress = _contenxt.ProgressInfo.Find(progressId); if (progress != null) { progress.State = ProgressInfoState.Failed.ToString(); progress.Message = string.Format(CanvasApiStrings.ErrorJobServices, logEntity.Id); progress.Exception = exception.ToString(); progress.Completion = 100; _contenxt.SaveChanges(); } } } } }); }