void HandleOnSwipe(object sender, DraggableEventArgs args) { var headlineView = sender as HeadlineView; Headlines.Remove(headlineView.Headline); if (args.Dragged.Equals(DraggableDirection.None)) { return; } if (args.Dragged.Equals(DraggableDirection.Left) && DidSwipeLeft != null) { DidSwipeLeft(headlineView); } else if (args.Dragged.Equals(DraggableDirection.Right) && DidSwipeRight != null) { DidSwipeRight(headlineView); } headlineView.RemoveFromSuperview(); InsertSubviewBelow(headlineView, visibleCards.Last()); visibleCards.Remove(headlineView); visibleCards.Add(headlineView); LoadNextCard(); }
public void Clear() { foreach (var card in visibleCards) { card.RemoveFromSuperview(); } Headlines.Clear(); }
public async Task <IActionResult> Edit( int id, [Bind("ID", "BoardGameID", "IsActive", "ImageFilePath", "FormFileUpload")] Headlines headlines) { var headlineToUpdate = await _db.Headlines.FindAsync(id); if (headlineToUpdate == null) { return(NotFound()); } var filepath = headlines.ImageFilePath; var oldFilePath = headlines.ImageFilePath; if (ModelState.IsValid) { if (headlines.FormFileUpload != null) { var rand = new Random(); var randNum = rand.Next(100000, 1000000); var fileName = randNum.ToString() + "_" + headlines.FormFileUpload.FileName; filepath = $"/images/headline/{fileName}"; var file = Path.Combine(_environment.ContentRootPath, "wwwroot/images/headline/", fileName); using (var fileStream = new FileStream(file, FileMode.Create)) { await headlines.FormFileUpload.CopyToAsync(fileStream); } var deleteFile = Path.Combine(_environment.ContentRootPath, $"wwwroot{headlineToUpdate.ImageFilePath}"); if (System.IO.File.Exists(deleteFile) && (oldFilePath != "/images/headline/defaultHeadline/gray.jpg")) { System.IO.File.Delete(deleteFile); } } if (await TryUpdateModelAsync <Headlines>( headlineToUpdate, "", i => i.IsActive, i => i.ImageFilePath)) { if (headlines.FormFileUpload != null) { headlineToUpdate.ImageFilePath = filepath; } await _db.SaveChangesAsync(); return(RedirectToAction("Index")); } } return(View(headlines)); }
public async Task <IActionResult> Create( [Bind("ID", "BoardGameID", "IsActive", "ImageFilePath", "FormFileUpload")] Headlines headline) { var errors = ModelState .Where(x => x.Value.Errors.Count > 0) .Select(x => new { x.Key, x.Value.Errors }) .ToArray(); if (ModelState.IsValid) { var filepath = "/images/headline/defaultHeadline/gray.jpg"; if (headline.FormFileUpload != null) { var rand = new Random(); var randNum = rand.Next(100000, 1000000); var fileName = randNum.ToString() + "_" + headline.FormFileUpload.FileName; filepath = $"/images/headline/{fileName}"; var file = Path.Combine(_environment.ContentRootPath, "wwwroot/images/headline/", fileName); using (var fileStream = new FileStream(file, FileMode.Create)) { await headline.FormFileUpload.CopyToAsync(fileStream); } } var emptyHeadlines = new Headlines(); if (await TryUpdateModelAsync <Headlines>( emptyHeadlines, "headline", i => i.BoardGameID, i => i.IsActive, i => i.ImageFilePath)) { emptyHeadlines.ImageFilePath = filepath; _db.Add(emptyHeadlines); await _db.SaveChangesAsync(); return(RedirectToAction("Index")); } } IEnumerable <BoardGame> boardGames = await _db.BoardGames .OrderBy(i => i.Title) .ToListAsync(); HeadlinesViewModel headlinesViewModel = new HeadlinesViewModel() { Headline = headline, BoardGames = boardGames }; return(View(headlinesViewModel)); }
// GET: Current Top Headlines public async Task <ActionResult> Index() { if (top == null) { top = new Headlines(); } var top20 = await top.GetHeadlinesAsync(); return(View(top20)); }
public async Task <IActionResult> Delete(int?id) { Headlines headlines = await _db.Headlines .Include(i => i.BoardGame) .FirstOrDefaultAsync(i => i.ID == id); if (headlines == null) { return(NotFound()); } return(View(headlines)); }
static async Task Main(string[] args) { //Upload earn headlines await Headlines.UploadEarnAsync(); //Activate actual news updating NewsUpdateTimer = new TimerCallback(Headlines.UploadAndUpdateNewsAsync); Timer newsTimer = new Timer(NewsUpdateTimer, null, 0, 600000); //Activate a bot CryptoBot = new Bot(); await CryptoBot.ActivateBotAsync(); }
public async Task <IActionResult> Create() { Headlines headline = new Headlines(); IEnumerable <BoardGame> boardGames = await _db.BoardGames .OrderBy(i => i.Title) .ToListAsync(); HeadlinesViewModel headlinesViewModel = new HeadlinesViewModel() { Headline = headline, BoardGames = boardGames }; return(View(headlinesViewModel)); }
static void Main(string[] _) { try { // Create a session into the platform... using (ISession session = Sessions.GetSession()) { // Open the session if (session.Open() == Session.State.Opened) { // *************************************************************************************************************** // Note: Each request below specifies a count of zero (0) which implies all available headlines within the query. // *************************************************************************************************************** // Use date specified within query 1 year ago var last_year = DateTime.UtcNow.AddYears(-1); var dateRange = $"{last_year:yyyy-MM-dd},{last_year.AddDays(6):yyyy-MM-dd}"; Console.WriteLine($"\nRetrieve all headlines for query: '{dateRange}'..."); DisplayHeadlines(Headlines.Definition().Query($"Apple daterange:{dateRange}") .Count(0) .Sort(Headlines.SortOrder.oldToNew) .GetData()); // Use date specifier within query - last 5 days Console.WriteLine("Retrieve all headlines for query: 'Apple last 5 days'..."); DisplayHeadlines(Headlines.Definition().Query("Apple last 5 days") .Count(0) .Sort(Headlines.SortOrder.oldToNew) .GetData()); // Same as previous except show each page response from the platform Console.WriteLine("Same as previous except show each page response..."); DisplayHeadlines(Headlines.Definition().Query("Apple last 5 days") .Count(0) .Sort(Headlines.SortOrder.oldToNew) .GetData((response, def, s) => Console.Write($"{response.Data.Headlines.Count}, "))); } } } catch (Exception e) { Console.WriteLine($"\n**************\nFailed to execute: {e.Message}\n{e.InnerException}\n***************"); } }
static void Main(string[] _) { try { // Create a session into the platform... using (ISession session = Sessions.GetSession()) { // Open the session if (session.Open() == Session.State.Opened) { // Retrieve the most recent headline about Apple var headline = Headlines.Definition().Query("L:EN and Apple") .Count(1) .GetData(); if (headline.IsSuccess) { // Retrieve the story based on the story ID var story = Story.Definition(headline.Data.Headlines[0].StoryId).GetData(); Console.WriteLine($"\nHeadline: {headline.Data.Headlines[0].HeadlineTitle}"); if (story.IsSuccess) { Console.WriteLine($"\nStory: {story.Data.NewsStory}"); } else { Console.WriteLine($"Problem retrieving the story: {story.HttpStatus}"); } } else { Console.WriteLine($"Problem retrieving the headline: {headline.HttpStatus}"); } } } } catch (Exception e) { Console.WriteLine($"\n**************\nFailed to execute: {e.Message}\n{e.InnerException}\n***************"); } }
static void Main(string[] _) { try { // Create a session into the platform... using (ISession session = Configuration.Sessions.GetSession()) { // Open the session if (session.Open() == Session.State.Opened) { // *************************************************************************************************************** // Note: Each request below specifies a count of zero (0) which implies all available headlines within the query. // *************************************************************************************************************** // Use date specified within query: "Apple daterange:'2020-06-01,2020-06-07'" Console.WriteLine("\nRetrieve all headlines for query: 'Apple daterange'..."); DisplayHeadlines(Headlines.Definition().Query(@"Apple daterange:""2020-06-01,2020-06-07""") .Count(0) .Sort(Headlines.SortOrder.oldToNew) .GetData()); // Use date specifier within query - last 5 days Console.WriteLine("Retrieve all headlines for query: 'Apple last 5 days'..."); DisplayHeadlines(Headlines.Definition().Query("Apple last 5 days") .Count(0) .Sort(Headlines.SortOrder.oldToNew) .GetData()); // Same as previous except show each page response from the platform Console.WriteLine("Same as previous except show each page response..."); DisplayHeadlines(Headlines.Definition().Query("Apple last 5 days") .Count(0) .Sort(Headlines.SortOrder.oldToNew) .OnPageResponse((p, headlines) => Console.Write($"{headlines.Data.Headlines.Count}, ")) .GetData()); } } } catch (Exception e) { Console.WriteLine($"\n**************\nFailed to execute: {e.Message}\n{e.InnerException}\n***************"); } }
public void ReloadNews() { Task.Run(async() => { this.newsLoaded = false; this.headlines = await Headlines.Get(this.app.Launcher, this.app.Settings.ClientLanguage ?? ClientLanguage.English).ConfigureAwait(false); this.banners = new TextureWrap[this.headlines.Banner.Length]; var client = new HttpClient(); for (var i = 0; i < this.headlines.Banner.Length; i++) { var textureBytes = await client.GetByteArrayAsync(this.headlines.Banner[i].LsbBanner).ConfigureAwait(false); this.banners[i] = TextureWrap.Load(textureBytes); } this.newsLoaded = true; }); }
static void Main(string[] _) { try { // Create a session into the platform... using (ISession session = Configuration.Sessions.GetSession()) { // Open the session if (session.Open() == Session.State.Opened) { // Default Count: Retrieve the most recent 100 headlines DisplayHeadlines(Headlines.Definition().GetData()); // Default Count: Retrieve most recent 100 headlines for Apple DisplayHeadlines(Headlines.Definition().Query("R:AAPL.O").GetData()); // Specify Count: Retrieve most recent N headlines for Apple DisplayHeadlines(Headlines.Definition().Query("R:AAPL.O") .Count(15) .GetData()); // Specify Count: Retrieve large batch for the most recent N headlines for Apple DisplayHeadlines(Headlines.Definition().Query("R:AAPL.O") .Count(350) .GetData()); // Same as last one except provide a callback to retrieve each page DisplayHeadlines(Headlines.Definition().Query("R:AAPL.O") .Count(350) .OnPageResponse((p, response) => DisplayHeadlines(response)) .GetData()); } } } catch (Exception e) { Console.WriteLine($"\n**************\nFailed to execute: {e.Message}\n{e.InnerException}\n***************"); } }
public async Task <Headlines> GetHeadlinesAsync() { var uri = new Uri("http://newsapi.org/v2/top-headlines?country=us&apiKey=" + _apiKey); Items = new List <Fuel>(); try { var response = await _client.GetAsync(uri); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); Headlines = JsonConvert.DeserializeObject <Headlines>(content); } } catch (Exception ex) { Debug.WriteLine(@"\tERROR {0}", ex.Message); } return(Headlines); }
private void SetupHeadlines() { try { _bannerChangeTimer?.Stop(); _headlines = Headlines.Get(_launcher, App.Settings.Language.GetValueOrDefault(ClientLanguage.English)); _bannerBitmaps = new BitmapImage[_headlines.Banner.Length]; for (var i = 0; i < _headlines.Banner.Length; i++) { var imageBytes = _launcher.DownloadAsLauncher(_headlines.Banner[i].LsbBanner.ToString(), App.Settings.Language.GetValueOrDefault(ClientLanguage.English)); using var stream = new MemoryStream(imageBytes); var bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = stream; bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.EndInit(); bitmapImage.Freeze(); _bannerBitmaps[i] = bitmapImage; } Dispatcher.BeginInvoke(new Action(() => { BannerImage.Source = _bannerBitmaps[0]; })); _bannerChangeTimer = new Timer { Interval = 5000 }; _bannerChangeTimer.Elapsed += (o, args) => { if (_currentBannerIndex + 1 > _headlines.Banner.Length - 1) { _currentBannerIndex = 0; } else { _currentBannerIndex++; } Dispatcher.BeginInvoke(new Action(() => { BannerImage.Source = _bannerBitmaps[_currentBannerIndex]; })); }; _bannerChangeTimer.AutoReset = true; _bannerChangeTimer.Start(); Dispatcher.BeginInvoke(new Action(() => { NewsListView.ItemsSource = _headlines.News; })); } catch (Exception) { Dispatcher.BeginInvoke(new Action(() => { NewsListView.ItemsSource = new List <News> { new News { Title = Loc.Localize("NewsDlFailed", "Could not download news data."), Tag = "DlError" } }; })); } }
private void SetupHeadlines() { try { _bannerChangeTimer?.Stop(); _headlines = Headlines.Get(_game); _bannerBitmaps = new BitmapImage[_headlines.Banner.Length]; for (var i = 0; i < _headlines.Banner.Length; i++) { var imageBytes = _game.DownloadAsLauncher(_headlines.Banner[i].LsbBanner.ToString()); using (var stream = new MemoryStream(imageBytes)) { var bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = stream; bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.EndInit(); bitmapImage.Freeze(); _bannerBitmaps[i] = bitmapImage; } } Dispatcher.BeginInvoke(new Action(() => { BannerImage.Source = _bannerBitmaps[0]; })); _bannerChangeTimer = new Timer { Interval = 5000 }; _bannerChangeTimer.Elapsed += (o, args) => { if (_currentBannerIndex + 1 > _headlines.Banner.Length - 1) { _currentBannerIndex = 0; } else { _currentBannerIndex++; } Dispatcher.BeginInvoke(new Action(() => { BannerImage.Source = _bannerBitmaps[_currentBannerIndex]; })); }; _bannerChangeTimer.AutoReset = true; _bannerChangeTimer.Start(); Dispatcher.BeginInvoke(new Action(() => { NewsListView.ItemsSource = _headlines.News; })); } catch (Exception) { Dispatcher.BeginInvoke(new Action(() => { NewsListView.Items.Add(new News { Title = "Could not download news data.", Tag = "DlError" }); })); } }
public async Task LoadHeadlines() { await Headlines.Refresh(); Headlines.Shuffle(); }