public async Task <TitleEntity> FindOrUpsertTitle(String title, int publishId) { TitleEntity retval = null; using (var dataContext = new AppDbContext()) { try { retval = dataContext.Titles.FirstOrDefault(x => x.Name == title && x.PublisherId == publishId); if (retval == null) { retval = dataContext.Titles.Add(new TitleEntity { Name = title, PublisherId = publishId, LastUpdate = DateTime.UtcNow }); //var success = await dataContext.SaveChangesAsync(); var success = dataContext.SaveChanges(); } } catch (Exception e) { var test = e.Message; } } return(retval); }
internal static Title ToServiceModel(this TitleEntity dataObject) { Title serviceModel = new Title(); serviceModel.Id = dataObject.Id; serviceModel.GameIds = dataObject.GameIds.ToServiceModels(); serviceModel.FallbackTitles = dataObject.FallbackTitles; serviceModel.Names = dataObject.Names.ToServiceModels(); return(serviceModel); }
internal static TitleEntity ToDataObject(this Title serviceModel) { TitleEntity dataObject = new TitleEntity(); dataObject.Id = serviceModel.Id; dataObject.GameIds = serviceModel.GameIds.ToDataObjects().ToList(); dataObject.FallbackTitles = serviceModel.FallbackTitles.ToList(); dataObject.Names = serviceModel.Names.ToDataObjects().ToList(); return(dataObject); }
public TitleEntity FindNextPosition() { if (NumberPoint > -1) { NumberPoint--; if (NumberPoint >= 0) { CurrentPoint = NavigationSystem.instance.Way[NumberPoint]; } } return(CurrentPoint); }
void FindClosePoint(TitleEntity title) { foreach (TitleEntity nextTitle in Titles) { if (Vector3.Distance(title.transform.position, nextTitle.transform.position) < 2f && nextTitle.Type != TypeTitle.NotMove && nextTitle.Distance == 99) { nextTitle.Distance = title.Distance + 1; AddClose(nextTitle); } } RemoveClose(title); }
void FindStartEndPoint() { foreach (TitleEntity title in Titles) { if (title.Type == TypeTitle.Start) { StartPoint = title; title.Distance = 0; AddClose(title); } if (title.Type == TypeTitle.End) { EndPoint = title; AddWay(title); } } }
public async Task <TitleEntity> FindTitleById(int titleId) { TitleEntity retval = null; using (var dataContext = new AppDbContext()) { try { retval = dataContext.Titles.FirstOrDefault(x => x.Id == titleId); } catch (Exception e) { var test = e.Message; } } return(retval); }
//float alpha; private void SetupTitleScreen() { AddGraphic <Image>(new Image(@"..\..\Backgrounds\bg.png")); titleEntity = new TitleEntity(Game.Instance.Width / 2, Game.Instance.Height / 2); exitEntity = new ExitEntity(10, 10); if (_controller.interf.Connected) { messageEntity = new TitleMessageEntity("Press green to start!", titleEntity.X, titleEntity.Y + 150); } else { messageEntity = new TitleMessageEntity("No Launchpad detected. Please restart the game with a Launchpad plugged in.", titleEntity.X, titleEntity.Y + 150); DetectingLaunchpad = true; } Add(messageEntity); Add(titleEntity); Add(exitEntity); }
public List <TitleEntity> GetUrlsForTitle(string title) { if (cache.Count > 100) { cache = new Dictionary <string, List <TitleEntity> >(); } else if (cache.ContainsKey(title)) { return(cache[title]); } List <WebCrawlerEntity> listOfTitles = new List <WebCrawlerEntity>(); string[] titles = title.Split(' '); foreach (string s in titles) { string temp = s.ToLower(); TableQuery <WebCrawlerEntity> titlesQuery = new TableQuery <WebCrawlerEntity>() .Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, temp)); foreach (WebCrawlerEntity entity in table.ExecuteQuery(titlesQuery)) { listOfTitles.Add(entity); } } //LINQ statement here var urlsToReturn = listOfTitles .GroupBy(x => x.RowKey) .Select(x => new Tuple <string, int, string, string>(x.Key, x.ToList().Count, x.ToList()[0].title, x.ToList()[0].date)) .OrderByDescending(x => x.Item2) .ThenByDescending(x => x.Item4).Take(18).ToList(); List <TitleEntity> tuples = new List <TitleEntity>(); foreach (Tuple <string, int, string, string> temp in urlsToReturn) { TitleEntity temp2 = new TitleEntity(temp); tuples.Add(temp2); } cache.Add(title, tuples); return(tuples); }
void RemoveClose(TitleEntity item) { CloseTitles.Remove(item); }
void FindNextTitle() { PointToMove = Move.FindNextPosition(); }
public async void OnCreatTileCommand(object obj) { if (!App.IsPro) { ToastHelper.ShowMessage("这是专业版功能,购买专业版即可使用"); return; } Book book = null; if (obj is LocalBookItemViewModel) { book = (obj as LocalBookItemViewModel)?.CurrentBook; } else if (obj is Book) { book = (obj as Book); } if (book == null) { return; } //磁贴ID var tileid = book.BookId; //磁贴展示名称 var displayName = book.BookName; //点击磁贴传回的参数 var str = JsonConvert.SerializeObject(book); var titleEntity = new TitleEntity(); titleEntity.TtitleId = book.BookId; titleEntity.BookJosn = str; if (book.IsLocal || book.IsOnline || book.IsTxt) { titleEntity.BookType = "1"; } else { titleEntity.BookType = "0"; } var args = JsonConvert.SerializeObject(titleEntity); var filepath = AppDataPath.GetBookCoverPath(book.BookId); //磁贴背景图片的路径 var logourl = filepath != null ? new Uri($"ms-appdata:///local/Images/{book.BookId}.jpg") : new Uri("ms-appx:///Assets/Square150x150Logo.scale-150.png"); //磁贴的大小 var size = TileSize.Square150x150; //创建磁贴对象 var tile = new SecondaryTile(tileid, displayName, args, logourl, size); //让磁贴显示展示名 tile.VisualElements.ShowNameOnSquare150x150Logo = true; //创建磁贴,返回bool值 bool b = await tile.RequestCreateAsync(); if (b) { ToastHelper.ShowMessage($"{book.BookName}磁贴创建成功"); } else { ToastHelper.ShowMessage($"{book.BookName}磁贴创建失败", false); } }
public static async Task ScrapeIssuePages(string url, string weekOf = "", bool newRelease = true) { PublisherCommandRepository publisherRepository = new PublisherCommandRepository(); TitleCommandRepository titleRepository = new TitleCommandRepository(); IssueCommandRepository issueRepository = new IssueCommandRepository(); var webGet = new HtmlWeb(); System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12; var document = webGet.Load(url); if (newRelease && string.IsNullOrEmpty(weekOf)) { var titleNode = document.DocumentNode.SelectSingleNode("//title"); if (titleNode != null && titleNode.InnerText != null) { weekOf = titleNode.InnerText.Replace("Comic Book New Releases ", ""); } } var nextNode = document.DocumentNode.SelectSingleNode("//li[@class='next']"); string nextLink; if (nextNode != null && nextNode.InnerHtml != null) { nextLink = _baseUrl + nextNode.FirstChild.Attributes["href"].Value.Replace("amp;", ""); ScrapeIssuePages(nextLink, weekOf, newRelease); } string lastTitle = null, lastPublisher = null; int lastTitleID = 0, lastPublisherID = 0; var issueList = document.DocumentNode.SelectNodes("//li[@class='issue']"); if (issueList != null) { foreach (HtmlNode issueNode in issueList) { string titleName = null; string issueNumber = null; string imageurl = null; string publishDate = null; string publisher = null; string description = null; decimal coverPrice = 0; var imageURLNode = issueNode.SelectSingleNode(".//a[@class='fancyboxthis']"); if (imageURLNode != null && imageURLNode.Attributes["href"] != null) { imageurl = imageURLNode.Attributes["href"].Value; } var titleInfoNode = issueNode.SelectSingleNode(".//div[@class='title']"); if (titleInfoNode != null) { //title = titleInfoNode.FirstChild.InnerText; //issue = titleInfoNode.FirstChild.NextSibling.NextSibling.InnerText.Replace("#", ""); var titleNode = titleInfoNode.SelectSingleNode(".//a"); if (titleNode != null) { titleName = titleNode.InnerText; } var numberNode = titleInfoNode.SelectSingleNode(".//strong"); if (numberNode != null) { issueNumber = numberNode.InnerText.Replace("#", ""); } } var publishInfoNode = issueNode.SelectSingleNode(".//div[@class='othercolright']"); if (publishInfoNode != null) { foreach (var publishNode in publishInfoNode.SelectNodes(".//a")) { if (string.IsNullOrEmpty(publishDate)) { publishDate = publishNode.InnerText; } publisher = publishNode.InnerText; } //no publish date info if (publishDate == publisher || newRelease) { publishDate = weekOf; } } try { DateTime publishDatetime = DateTime.Parse(publishDate); } catch (Exception e) { publishDate = DateTime.Now.ToString(); } var descriptionInfoNode = issueNode.SelectSingleNode(".//div[@class='issuegrades']"); if (descriptionInfoNode != null && descriptionInfoNode.NextSibling != null && descriptionInfoNode.NextSibling.NextSibling != null) { description = descriptionInfoNode.NextSibling.NextSibling.InnerText; if (description != null && description.Contains("Cover price")) { string coverPriceString = "0"; try { coverPriceString = description.Substring(description.LastIndexOf("Cover price")).Replace("Cover price", ""). Replace( "$", "").TrimEnd( '\n', '\r', '.', '\t', ' '); } catch (FormatException e) { coverPriceString = "0"; } if (!String.IsNullOrEmpty(coverPriceString)) { try { coverPrice = decimal.Parse(coverPriceString); } catch (FormatException) { coverPrice = 0m; } } } } int publisherID = 0; if (publisher != lastPublisher) { publisherID = await publisherRepository.FindOrUpsertPublisher(publisher); lastPublisher = publisher; lastPublisherID = publisherID; } else { publisherID = lastPublisherID; } if (publisherID > 0) { TitleEntity title = null; if (titleName != lastTitle) { title = await titleRepository.FindOrUpsertTitle(titleName, publisherID); lastTitle = titleName; lastTitleID = title.Id; } else { title = new TitleEntity { Name = lastTitle, Id = lastTitleID, PublisherId = publisherID }; } IssueEntity issue = new IssueEntity { TitleId = title.Id, SeoFriendlyName = issueNumber, ReleaseDate = DateTime.Parse(publishDate), CoverPrice = coverPrice, Description = description, ImageUrl = imageurl, CreatedDated = DateTime.UtcNow }; await issueRepository.FindAndUpsertIssue(issue); } } } }
public static async Task ScrapeTitlePages(int titleId, bool titlesOnly = true, bool fillTitle = false, int maxTitle = 0) { PublisherCommandRepository publisherRepository = new PublisherCommandRepository(); TitleCommandRepository titleRepository = new TitleCommandRepository(); IssueCommandRepository issueRepository = new IssueCommandRepository(); var title = await titleRepository.FindTitleById(titleId); var url = String.Format(_baseUrl + "search?q={0}", title.Name); var webGet = new HtmlWeb(); System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12; var document = webGet.Load(url); string lastPublisher = null; int lastPublisherID = 0; var resultsNode = document.DocumentNode.SelectSingleNode("//table[@class='results']"); if (resultsNode != null) { var titleNodes = resultsNode.SelectNodes(".//tr"); if (maxTitle == 0 || titleNodes.Count < maxTitle) { //foreach ( HtmlNode titleNode in resultsNode.SelectNodes( ".//tr" ) ) foreach (HtmlNode titleNode in titleNodes) { TitleEntity newTitle = new TitleEntity(); string issueRange = null; string publisher = null; string yearRange = null; var titleNameNode = titleNode.SelectSingleNode(".//td[@class='title']"); if (titleNameNode != null) { var titleNameLink = titleNameNode.SelectSingleNode(".//a[@href]"); if (titleNameLink != null) { newTitle.Name = titleNameLink.InnerText; // newTitle.SeoFriendlyName = CommonCode.GetSeoFriendlyName(titleNameLink.InnerText); } } var issueRangeNode = titleNode.SelectSingleNode(".//td[@class='issue']"); if (issueRangeNode != null) { issueRange = issueRangeNode.InnerText; issueRange = issueRange.Replace("#", ""); if (issueRange.Contains("-")) { newTitle.IssueBegin = issueRange.Substring(0, issueRange.IndexOf("-")); newTitle.IssueEnd = issueRange.Substring(issueRange.IndexOf("-") + 1); } else { newTitle.IssueBegin = issueRange; newTitle.IssueEnd = issueRange; } } var publisherNode = titleNode.SelectSingleNode(".//td[@class='publisher']"); if (publisherNode != null) { var publisherLinkNode = publisherNode.SelectSingleNode(".//a"); if (publisherLinkNode != null) { publisher = publisherLinkNode.InnerText.Trim(); int publisherID = 0; if (publisher != lastPublisher) { publisherID = await publisherRepository.FindOrUpsertPublisher(publisher); if (publisherID <= 0) { continue; } lastPublisher = publisher; lastPublisherID = publisherID; } else { publisherID = lastPublisherID; } newTitle.PublisherId = publisherID; } } var yearRangeNode = titleNode.SelectSingleNode(".//td[@class='year']"); if (yearRangeNode != null) { yearRange = yearRangeNode.InnerText; yearRange = yearRange.TrimStart('\n', '\r', '.', '\t', ' ').TrimEnd('\n', '\r', '.', '\t', ' '); if (yearRange.Contains("-")) { newTitle.YearStart = int.Parse(yearRange.Substring(0, yearRange.IndexOf("-")).TrimStart('\n', '\r', '.', '\t', ' ').TrimEnd('\n', '\r', '.', '\t', ' ')); newTitle.YearEnd = int.Parse(yearRange.Substring(yearRange.IndexOf("-") + 1).TrimStart('\n', '\r', '.', '\t', ' ').TrimEnd('\n', '\r', '.', '\t', ' ')); } else { newTitle.YearStart = int.Parse(yearRange); newTitle.YearEnd = int.Parse(yearRange); } //if (newTitle.YearStart.Length > 4) //{ // newTitle.YearStart = newTitle.YearStart.Substring(0, 4); //} //if (newTitle.YearEnd.Length > 4) //{ // newTitle.YearEnd = newTitle.YearEnd.Substring(0, 4); //} //try //{ // if (int.Parse(newTitle.YearEnd) < DateTime.Now.Year) // { // newTitle.Continuing = false; // } // else // { // newTitle.Continuing = true; // } //} //catch (FormatException) //{ // newTitle.Continuing = false; //} //newTitle.Filled = false; } await titleRepository.FindOrUpsertTitle(newTitle.Name, newTitle.PublisherId); if (!titlesOnly) { var linkNode = titleNode.SelectSingleNode(".//a[@href]"); var titleLink = _baseUrl + linkNode.Attributes["href"].Value; ScrapeIssuePages(titleLink, "", false); } } } } if (titlesOnly) { var nextNode = document.DocumentNode.SelectSingleNode("//li[@class='next']"); string nextLink; if (nextNode != null && nextNode.InnerHtml != null) { nextLink = _baseUrl + nextNode.FirstChild.Attributes["href"].Value.Replace("amp;", ""); //ScrapeTitlePages(nextLink); } } }
void StartPosition() { NumberPoint = NavigationSystem.instance.Way.Count - 1; CurrentPoint = NavigationSystem.instance.StartPoint; transform.position = CurrentPoint.transform.position; }
void AddWay(TitleEntity item) { Way.Add(item); }
void RemoveWay(TitleEntity item) { Way.Remove(item); }
void RemoveNextClose(TitleEntity item) { CloseNextTitles.Remove(item); }
void AddNextClose(TitleEntity item) { CloseNextTitles.Add(item); }
public TitleEventEntity(Title title) { OldValue = new TitleEntity(); NewValue = new TitleEntity(); Mapper.Map(title, OldValue); }
void AddClose(TitleEntity item) { CloseTitles.Add(item); }