private static async Task CheckQuality() { using (var ctx = new CheckContext()) { if (EnableAdvLogging) { Logger.Info("checking for quality"); } for (int i = 0; i < ctx.CheckList.Count(); i++) { var item = ctx.CheckList.ToList()[i]; if (EnableAdvLogging) { Logger.Info($"checking for {item} quality"); } if (CheckForVideoQuality(item.Name, item.SetName, await AutoRetry(Cloud.GetFileStat(BucketName, $"/{item.Name}/{item.SetName}.mp4")))) { ctx.CheckList.Remove(item); ctx.SaveChanges(); if (EnableAdvLogging) { Logger.Info($"{item} quality is done, remove"); } } } if (EnableAdvLogging) { Logger.Info("checking for quality is done"); } } }
private static async Task CheckForVideoFile(string item, string title, string setName, dynamic obj) { var file = new FileInfo(item); if (obj != null && obj.data?.filelen != file.Length) { Logger.Warn($"file {title} {setName} reuploading"); await Cloud.DeleteFile(BucketName, $"/{title}/{setName}.mp4"); await Cloud.SliceUploadFile(BucketName, $"/{title}/{setName}.mp4", item); using (var context = new AnimateDatabaseContext()) using (var ctx = new CheckContext()) { var id = context.AnimateList.FirstOrDefault(anime => anime.EnUs == title).Id; if (id != -1) { if (ctx.CheckList.Count(check => check.ID == id && check.SetName == setName) == 0) { ctx.CheckList.Add(new CheckModel { ItemID = id, Name = title, SetName = setName }); } if (ShareToWeibo && ctx.WeiboList.Count(check => check.ID == id && check.SetName == setName) == 0) { ctx.WeiboList.Add(new WeiboModel { ItemID = id, Name = title, SetName = setName, ZhTW = "" }); } ctx.SaveChanges(); } } Logger.Info($"reupload {title} {setName} complete"); } }
public CheckNotification AddCheckNotification(bool isHealthy) { using (var checkContext = new CheckContext(Options)) { var check = new Check { Name = CheckName }; var checkNotification = new CheckNotification { Check = check, CheckResult = new CheckResult { Check = check, CheckBatch = new CheckBatch(), Type = isHealthy ? CheckResultType.Success : CheckResultType.Failure }, IsHealthy = isHealthy, Version = 1 }; checkContext.CheckNotifications.Add(checkNotification); checkContext.SaveChanges(); return(checkNotification); } }
public IActionResult Create([FromBody] List <InfoItem> items) { List <InfoItem> resluts = new List <InfoItem>(); List <IActionResult> actionResults = new List <IActionResult>(); if (items == null) { return(BadRequest()); } foreach (InfoItem item in items) { _context.INFO_ITEMS.Add(item); _context.SaveChanges(); resluts.Add((InfoItem)CreatedAtRoute("GetInfo_Item", new { id = item.ID }, item).Value); } return(Ok(resluts)); }
public CheckResult AddCheckResult(CheckResult checkResult) { using (var checkContext = new CheckContext(Options)) { checkContext.CheckResults.Add(checkResult); checkContext.SaveChanges(); return(checkResult); } }
private static async Task CheckWeiboShare() { using (var ctx = new CheckContext()) { if (EnableAdvLogging) { Logger.Info("checking for weibo share"); } for (int i = 0; i < ctx.WeiboList.Count(); i++) { var item = ctx.WeiboList.ToList()[i]; if (EnableAdvLogging) { Logger.Info($"checking for {item} weibo"); } dynamic obj = await AutoRetry(Cloud.GetFileStat(BucketName, $"/{item.Name}/{item.SetName}.mp4")); if (!string.IsNullOrEmpty((string)obj.data?.video_cover)) { if (EnableAdvLogging) { Logger.Info($"sending weibo {item}"); } try { var url = $"http://OneEchan.moe/Watch?id={item.ItemID}&set={double.Parse(item.SetName)}"; //var shorturl = await OpenWeen.Core.Api.ShortUrl.Shorten(url); using (var client = new HttpClient()) using (Stream stream = await client.GetStreamAsync((string)obj.data?.video_cover)) using (var memStream = new MemoryStream()) { await stream.CopyToAsync(memStream); await OpenWeen.Core.Api.Statuses.PostWeibo.PostWithPic($"{item.ZhTW} - {item.SetName} {url}", memStream.ToArray()); } ctx.WeiboList.Remove(item); ctx.SaveChanges(); if (EnableAdvLogging) { Logger.Info($"weibo {item} sended"); } } catch (Exception e) { Logger.Error($"can not share to weibo {e.Message}"); } } } if (EnableAdvLogging) { Logger.Info("checking for weibo is done"); } } }
private static async Task AddSet(string item, string title, string setName) { if (EnableAdvLogging) { Logger.Info($"adding {title} {setName} into database"); } using (var context = new AnimateDatabaseContext()) { if (!context.AnimateList.Any(anime => anime.EnUs == title)) { if (EnableAdvLogging) { Logger.Info("cannot find id, create new"); } context.AnimateList.Add(new AnimateList { EnUs = title, Updated_At = DateTime.Now }); context.SaveChanges(); } var id = context.AnimateList.FirstOrDefault(anime => anime.EnUs == title).Id; if (id != -1) { if (EnableAdvLogging) { Logger.Info($"checking for file data..."); } dynamic obj = await AutoRetry(Cloud.GetFileStat(BucketName, $"/{title}/{setName}.mp4")); if (obj != null && obj.code == 0) { if (obj.data.access_url != null) { if (context.SetDetail.Any(anime => anime.Id == id && anime.SetName == double.Parse(setName))) { if (EnableAdvLogging) { Logger.Info("existed,add check"); } var animeItem = context.AnimateList.FirstOrDefault(anime => anime.Id == id); using (var ctx = new CheckContext()) { if (!ctx.CheckList.Any(check => check.ID == id && check.SetName == setName)) { ctx.CheckList.Add(new CheckModel { ItemID = id, Name = title, SetName = setName }); } if (ShareToWeibo && !ctx.WeiboList.Any(check => check.ID == id && check.SetName == setName)) { ctx.WeiboList.Add(new WeiboModel { ItemID = id, Name = title, SetName = setName, ZhTW = animeItem.ZhTw }); } ctx.SaveChanges(); } } else { if (EnableAdvLogging) { Logger.Info("adding set..."); } context.SetDetail.Add(new SetDetail { Id = id, SetName = double.Parse(setName), FilePath = obj.data.access_url, ClickCount = 0, Created_At = DateTime.Now }); var animeItem = context.AnimateList.FirstOrDefault(anime => anime.Id == id); animeItem.Updated_At = DateTime.Now; animeItem = await GetAnimeTitle(title, animeItem); context.Entry(animeItem).State = EntityState.Modified; context.SaveChanges(); using (var ctx = new CheckContext()) { if (ctx.CheckList.Count(check => check.ID == id && check.SetName == setName) == 0) { ctx.CheckList.Add(new CheckModel { ItemID = id, Name = title, SetName = setName }); } if (ShareToWeibo && ctx.WeiboList.Count(check => check.ID == id && check.SetName == setName) == 0) { ctx.WeiboList.Add(new WeiboModel { ItemID = id, Name = title, SetName = setName, ZhTW = animeItem.ZhTw }); } ctx.SaveChanges(); } if (EnableAdvLogging) { Logger.Info("add set complete"); } } } } } } }