public IActionResult Error() { var ex = HttpContext.Features.Get <IExceptionHandlerPathFeature>().Error; ErrorViewModel model = new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }; model.IsAdmin = CookieUtil.IsAdmin(HttpContext); model.Ex = ex; LineUtil.PushMe($"【エラー発生】\n" + $"{ex.ToString().Split(Environment.NewLine)[0]}\n" + $"{ex.ToString().Split(Environment.NewLine)[1]}", HttpClientManager.GetInstance()); Log log = new Log { LogDate = DateTime.Now , LogType = LogType.EXCEPTION , LogDetail = ex.ToString() , UserId = CookieUtil.IsAdmin(HttpContext).ToString() }; _context.Log.Add(log); _context.SaveChanges(); return(View(model)); }
public IActionResult Send(MessageModel model) { LineUtil.PushMe("【JA-Fleet from web】\n" + $"名前:{model.Name}\n" + $"返信先:{model.Replay}\n" + $"{model.Message}", HttpClientManager.GetInstance()); Task.Run(() => { using (var serviceScope = _services.CreateScope()) { using (var context = serviceScope.ServiceProvider.GetService <jafleetContext>()) { var m = new Message { Sender = model.Name, MessageDetail = model.Message, ReplayTo = model.Replay, MessageType = Commons.Constants.MessageType.WEB, RecieveDate = DateTime.Now }; context.Messages.Add(m); context.SaveChanges(); } } }); return(Content("OK")); }
public IActionResult WorkingCheck(int?interval) { if (!CookieUtil.IsAdmin(HttpContext)) { return(NotFound()); } if (jafleet.WorkingCheck.Processing) { LineUtil.PushMe("WorkingCheck 二重起動を検出", HttpClientManager.GetInstance()); return(Content("Now Processing!!")); } _ = Task.Run(() => { using (var serviceScope = _services.CreateScope()) { IEnumerable <AircraftView> targetReg; using (var context = serviceScope.ServiceProvider.GetService <jafleetContext>()) { #if DEBUG targetReg = context.AircraftView.Where(a => a.RegistrationNumber == "JA26LR").AsNoTracking().ToArray(); #else targetReg = context.AircraftView.Where(a => a.OperationCode != OperationCode.RETIRE_UNREGISTERED).AsNoTracking().ToArray().OrderBy(r => Guid.NewGuid()); #endif var check = new WorkingCheck(targetReg, interval ?? 15); _ = check.ExecuteCheckAsync(); } } }); return(Content("WorkingCheck Launch!")); }
public IActionResult RegisterNamedSearchCondition(SearchConditionInModel scm, string searchConditionName) { string scjson = scm.ToString(); string schash = HashUtil.CalcCRC32(scjson); var sc = _context.SearchCondition.Where(sc => sc.SearchConditionKey == schash).SingleOrDefault(); if (sc != null) { sc.SearchConditionName = searchConditionName; } else { sc = new SearchCondition { SearchConditionKey = schash, SearchConditionJson = scjson, SearchConditionName = searchConditionName, SearchCount = 0 }; _context.SearchCondition.Add(sc); } _context.SaveChanges(); MasterManager.ReloadNamedSearchCondition(_context); _ = Task.Run(() => { LineUtil.PushMe($"検索条件が登録されました。\n{searchConditionName}\n{scjson}", HttpClientManager.GetInstance()); }); return(Content(sc.SearchConditionKey)); }
public async System.Threading.Tasks.Task <IActionResult> Photo(string id, [FromQuery] bool force) { if (string.IsNullOrEmpty(id)) { return(BadRequest()); } var photo = _context.AircraftPhoto.Where(p => p.RegistrationNumber == id).SingleOrDefault(); Aircraft a = null; if (photo != null && DateTime.Now.Date == photo.LastAccess.Date && !force) { if (photo.PhotoUrl != null) { //1日以内のキャッシュがあれば、キャッシュから返す return(Redirect($"https://www.jetphotos.com{photo.PhotoUrl}")); } else { //キャッシュがNULLの場合は、リンクURLもNULLの場合のみnophotoを返す //そうしないとキャッシュがNULLで、あとからLinkUrlを登録した場合に最大1日待つ必要が出る。 a = _context.Aircraft.Where(p => p.RegistrationNumber == id.ToUpper()).FirstOrDefault(); if (string.IsNullOrEmpty(a.LinkUrl)) { return(Redirect("/nophoto.html")); } else { return(ReturnLinkUrl(a.LinkUrl)); } } } string jetphotoUrl = string.Format("https://www.jetphotos.com/showphotos.php?keywords-type=reg&keywords={0}&search-type=Advanced&keywords-contain=0&sort-order=2", id); if (a == null) { a = _context.Aircraft.Where(p => p.RegistrationNumber == id.ToUpper()).FirstOrDefault(); } var parser = new HtmlParser(); try { var htmlDocument = parser.ParseDocument(await HttpClientManager.GetInstance().GetStringAsync(jetphotoUrl)); var photos = htmlDocument.GetElementsByClassName("result__photoLink"); if (photos.Length != 0) { //Jetphotosに写真があった場合 string newestPhotoLink = photos[0].GetAttribute("href"); var photoTag = htmlDocument.GetElementsByClassName("result__photo"); string directUrl = null; if (photoTag.Length != 0) { directUrl = photoTag[0].GetAttribute("src").Replace("//cdn.jetphotos.com/400", string.Empty); } _ = Task.Run(() => { //写真をキャッシュに登録する using var serviceScope = _services.CreateScope(); using var context = serviceScope.ServiceProvider.GetService <jafleetContext>(); if (!string.IsNullOrEmpty(a.LinkUrl)) { //Jetphotosから取得できるのにDBにも登録されている場合は、DBから消す a.LinkUrl = null; a.ActualUpdateTime = DateTime.Now; context.Aircraft.Update(a); LineUtil.PushMe($"{id}のLinkUrlを削除しました", HttpClientManager.GetInstance()); } StoreAircraftPhoto(context, photo, newestPhotoLink, id, directUrl); }); return(Redirect($"https://www.jetphotos.com{newestPhotoLink}")); } else { if (string.IsNullOrEmpty(a?.LinkUrl)) { //Jetphotosに写真がなかった場合 _ = Task.Run(() => { //写真がないという情報を登録する using var serviceScope = _services.CreateScope(); using var context = serviceScope.ServiceProvider.GetService <jafleetContext>(); StoreAircraftPhoto(context, photo, null, id, null); }); return(Redirect("/nophoto.html")); } else { return(ReturnLinkUrl(a.LinkUrl)); } } } catch { return(Redirect($"/failphotoload.html?reg={id}")); } }