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 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 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 Store(EditModel model) { try{ DateTime storeDate = DateTime.Now; string reg = model.Aircraft.RegistrationNumber; var origin = _context.Aircraft.AsNoTracking().Where(a => a.RegistrationNumber == reg).FirstOrDefault(); if (!model.NotUpdateDate || model.IsNew) { model.Aircraft.UpdateTime = storeDate; } model.Aircraft.ActualUpdateTime = storeDate; if (model.IsNew) { model.Aircraft.CreationTime = storeDate; _context.Aircraft.Add(model.Aircraft); } else { if (!model.NotUpdateDate) { //Historyにコピー var ah = new AircraftHistory(); Mapper.Map(origin, ah); ah.HistoryRegisterAt = storeDate; //HistoryのSEQのMAXを取得 var maxseq = _context.AircraftHistory.AsNoTracking().Where(ahh => ahh.RegistrationNumber == ah.RegistrationNumber).GroupBy(ahh => ahh.RegistrationNumber) .Select(ahh => new { maxseq = ahh.Max(x => x.Seq) }).FirstOrDefault(); ah.Seq = (maxseq?.maxseq ?? 0) + 1; _context.AircraftHistory.Add(ah); } _context.Entry(model.Aircraft).State = Microsoft.EntityFrameworkCore.EntityState.Modified; } //デリバリーされたらテストレジはクリア if (!OperationCode.PRE_DELIVERY.Contains(model.Aircraft.OperationCode)) { model.Aircraft.TestRegistration = null; } _context.SaveChanges(); }catch (Exception ex) { model.ex = ex; } model.AirlineList = MasterManager.AllAirline; model.TypeList = MasterManager.Type; model.OperationList = MasterManager.Operation; model.WiFiList = MasterManager.Wifi; string noheadString = string.Empty; if (model.NoHead) { noheadString = "?nohead=" + model.NoHead.ToString(); } //写真を更新 _ = HttpClientManager.GetInstance().GetStringAsync($"http://localhost:5000/Aircraft/Photo/{model.Aircraft.RegistrationNumber}?force=true"); return(Redirect("/E/" + model.Aircraft.RegistrationNumber + noheadString)); }
public async Task ExecuteCheckAsync() { int intervalSum = 0; var sw = new Stopwatch(); sw.Start(); Processing = true; var parser = new HtmlParser(); using var context = new jafleetContext(Options.Options); var toWorkingTest = new SortedDictionary <string, string>(); //テストレジが飛行した(テスト飛行した) var toWorking0 = new SortedDictionary <string, string>(); //予約登録かつ非稼働が稼働した(テスト飛行した) var toWorking1 = new SortedDictionary <string, string>(); //製造中かつ非稼働が稼働した(テスト飛行継続) var toWorking2 = new SortedDictionary <string, string>(); //デリバリーかつ非稼働が稼働した(営業運航投入) var toWorking3 = new SortedDictionary <string, string>(); //運用中で非稼働が稼働した var toWorking7 = new SortedDictionary <string, string>(); //退役で非稼働が稼働した(退役フェリーされた) var toNotWorking = new SortedDictionary <string, string>(); //非稼働になった var mainteStart = new SortedDictionary <string, string>(); //整備開始の疑い var mainteEnd = new SortedDictionary <string, string>(); //整備終了の疑い var mainteing = new SortedDictionary <string, string>(); //整備中の疑い var allLog = new StringBuilder(); foreach (AircraftView a in _targetRegistrationNumber) { bool success = false; int failCount = 0; Exception exBack = null; while (!success && failCount <= 5) { try { var htmlDocument = parser.ParseDocument(await HttpClientManager.GetInstance().GetStringAsync(FR24_DATA_URL + a.RegistrationNumber)); var row = htmlDocument.GetElementsByClassName("data-row"); var status = context.WorkingStatus.Where(s => s.RegistrationNumber == a.RegistrationNumber).FirstOrDefault(); var r = new Random(); if (row !.Length != 0) { //rowがもつ日付 string timestamp = row[0].GetAttribute("data-timestamp"); DateTime latestDate = DateTimeOffset.FromUnixTimeSeconds(long.Parse(timestamp)).LocalDateTime; var currentInfo = new StringBuilder(); string notifyMark = string.Empty; if (!string.IsNullOrEmpty(a.SpecialLivery)) { notifyMark = "◎"; } else if (a.MaintenanceNotify.HasValue && a.MaintenanceNotify.Value) { notifyMark = "☆"; } currentInfo.Append($"{a.RegistrationNumber}{notifyMark}({a.TypeDetailName}):{latestDate:yyyy/MM/dd HH:mm} "); //tdの各値 var td = row[0].GetElementsByTagName("td"); if (td !.Length != 0) { currentInfo.Append($"{td[3].TextContent!.Trim()} {td[4].TextContent!.Trim()} {td[5].TextContent!.Trim()} {td[11].TextContent!.Trim()}"); } bool? previousWorking; DateTime?previousDate; if (status == null) { status = new WorkingStatus() { RegistrationNumber = a.RegistrationNumber }; context.WorkingStatus.Add(status); } previousWorking = status.Working; previousDate = status.FlightDate; status.FlightDate = latestDate; status.FromAp = td[3].TextContent !.Trim(); status.ToAp = td[4].TextContent !.Trim(); status.FlightNumber = td[5].TextContent !.Trim(); status.Status = td[11].TextContent !.Trim(); status.Working = (DateTime.Now.Date < latestDate.Date) || ((DateTime.Now.Date - latestDate.Date) <= CompareTargetTimeSpan); if ((!previousWorking.HasValue || !previousWorking.Value) && status.Working !.Value) { string infoString = $"{currentInfo} ← {previousDate:yyyy/MM/dd HH:mm}"; //非稼働から稼働になった switch (a.OperationCode) { case OperationCode.RESERVED: toWorking0.Add(a.RegistrationNumber, infoString); break; case OperationCode.MAKING: toWorking1.Add(a.RegistrationNumber, infoString); break; case OperationCode.DELIVERY: toWorking2.Add(a.RegistrationNumber, infoString); break; case OperationCode.INTERNATIONAL: case OperationCode.DOMESTIC: case OperationCode.BOTH: case OperationCode.CARGO: toWorking3.Add(a.RegistrationNumber, infoString); break; case OperationCode.RETIRE_REGISTERED: toWorking7.Add(a.RegistrationNumber, infoString); break; } //整備終了の疑い if (status.Maintenancing.HasValue && status.Maintenancing.Value) { status.Maintenancing = false; mainteEnd.Add(a.RegistrationNumber, currentInfo.ToString()); } } else if (previousWorking.HasValue && previousWorking.Value && !status.Working.Value) { //稼働から非稼働になった toNotWorking.Add(a.RegistrationNumber, currentInfo.ToString()); //整備開始の疑い if (MAINTE_PLACE.Any(m => status.ToAp.Contains(m))) { status.Maintenancing = true; mainteStart.Add(a.RegistrationNumber, currentInfo.ToString()); } } else if (status.Maintenancing.HasValue && status.Maintenancing.Value && a.OperationCode != OperationCode.RETIRE_REGISTERED) { mainteing.Add(a.RegistrationNumber, currentInfo.ToString()); } Console.WriteLine(currentInfo); }
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}")); } }
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)); }