public void Watchlist_Constructor() { var testWatchlist = new Watchlist( FakeObjects.TestUserWithId(), FakeValues.Name, FakeValues.QuerystringJson); Assert.AreEqual(testWatchlist.Name, FakeValues.Name); Assert.AreEqual(testWatchlist.QuerystringJson, FakeValues.QuerystringJson); }
public void Watchlist_UpdateDetails() { var testWatchlist = new Watchlist(FakeObjects.TestUser(), FakeValues.Name, FakeValues.QuerystringJson); testWatchlist.UpdateDetails( FakeObjects.TestUser(), FakeValues.Name.AppendWith(additionalString), FakeValues.QuerystringJson.AppendWith(additionalString)); Assert.AreEqual(testWatchlist.Name, FakeValues.Name.AppendWith(additionalString)); Assert.AreEqual(testWatchlist.QuerystringJson, FakeValues.QuerystringJson.AppendWith(additionalString)); }
/// <summary> /// Returns a string representation of the given Watchlist. /// </summary> /// <param name="watchList"></param> /// <returns>String representation of the given Watchlist.</returns> public static string PrintWatchlist(Watchlist watchList) { var result = new StringBuilder(); if (watchList != null) { foreach (var item in watchList.List) { result.AppendFormat("{0}As At: {1}", Environment.NewLine, item.AsAt); result.AppendFormat("{0}Bid Count {1}", Environment.NewLine, item.BidCount); result.AppendFormat("{0}Buy Now price {1}", Environment.NewLine, item.BuyNowPrice); result.AppendFormat("{0}Category name: {1}", Environment.NewLine, item.CategoryName); result.AppendFormat("{0}Has Pay Now: {1}", Environment.NewLine, item.HasPayNow); result.AppendFormat("{0}Is New: {1}", Environment.NewLine, item.IsNew); result.AppendFormat("{0}Title: {1}", Environment.NewLine, item.Title); } } return result.ToString(); }
/// <summary> /// Deletes the specified watchlist. /// </summary> /// <param name="watchlist">The watchlist to delete.</param> public void Delete(Watchlist watchlist) { _context.Watchlists.Remove(watchlist); _context.SaveChanges(); }
public IActionResult Profile() { var SessionId = HttpContext.Session.GetInt32("LoggedUserId"); ViewBag.Id = SessionId; // Check to ensure there is a properly logged in user by checking session. if (HttpContext.Session.GetInt32("LoggedUserId") >= 0) { User User = _context.Users.SingleOrDefault(u => u.Id == SessionId); // Put User in ViewBag to display in view. ViewBag.User = User; // Get Stock data for Portfolio and Watch List Portfolio Portfolio = _context.Portfolios .Include(p => p.Stocks) .SingleOrDefault(p => p.User == User); // For each Stock in Portfolio, call API based on values in database // Also, populate Stocks list for later use in ViewBag ViewBag.Total = 0; foreach (Stock Stock in Portfolio.Stocks) { // Create a Dictionary object to store JSON values from API call Dictionary <string, object> Data = new Dictionary <string, object>(); // Make API call WebRequest.GetQuote(Stock.Symbol, JsonResponse => { Data = JsonResponse; } ).Wait(); // Define values for each stock to be stored in ViewBag double CurrentPrice = Convert.ToDouble(Data["latestPrice"]); Stock.Name = (string)Data["companyName"]; Stock.PurchaseValue = Stock.PurchasePrice * Stock.Shares; Stock.CurrentPrice = CurrentPrice; Stock.CurrentValue = CurrentPrice * Stock.Shares; Stock.GainLossPrice = CurrentPrice - Stock.PurchasePrice; Stock.GainLossValue = (CurrentPrice - Stock.PurchasePrice) * Stock.Shares; Stock.GainLossPercent = 100 * (CurrentPrice - Stock.PurchasePrice) / (Stock.PurchasePrice); Stock.Week52Low = Convert.ToDouble(Data["week52Low"]); Stock.Week52High = Convert.ToDouble(Data["week52High"]); Stock.UpdatedAt = DateTime.Now; _context.SaveChanges(); ViewBag.Total += Stock.CurrentValue; // This is for the Watchlist } // Store values in ViewBag for Portfolio page rendering ViewBag.Portfolio = Portfolio; // Watchlist START Watchlist Watchlist = _context.Watchlists .Include(w => w.Stocks) .SingleOrDefault(p => p.User == User); ViewBag.Total = 0; foreach (Stock Stock in Watchlist.Stocks) { // Create a Dictionary object to store JSON values from API call Dictionary <string, object> Data = new Dictionary <string, object>(); // Make API call WebRequest.GetQuote(Stock.Symbol, JsonResponse => { Data = JsonResponse; } ).Wait(); // Define values for each stock to be stored in ViewBag double CurrentPrice = Convert.ToDouble(Data["latestPrice"]); Stock.Name = (string)Data["companyName"]; Stock.PurchaseValue = Stock.PurchasePrice * Stock.Shares; Stock.CurrentPrice = CurrentPrice; Stock.CurrentValue = CurrentPrice * Stock.Shares; Stock.GainLossPrice = CurrentPrice - Stock.PurchasePrice; Stock.GainLossValue = (CurrentPrice - Stock.PurchasePrice) * Stock.Shares; Stock.GainLossPercent = 100 * (CurrentPrice - Stock.PurchasePrice) / (Stock.PurchasePrice); Stock.Week52Low = Convert.ToDouble(Data["week52Low"]); Stock.Week52High = Convert.ToDouble(Data["week52High"]); Stock.UpdatedAt = DateTime.Now; _context.SaveChanges(); ViewBag.Total += Stock.CurrentValue; } // Store values in ViewBag for Portfolio page rendering ViewBag.Watchlist = Watchlist; return(View("Profile")); } else { return(View("landing")); } // If no id is in session that means that the user is not properly logged on. Redirect to logout (to clear session, just in case) which will end up at landing page. }
/// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='id'> /// </param> /// <param name='watchlist'> /// </param> public static Watchlist UpdateWatchlist(this IWatchlistsAPI operations, Guid id, Watchlist watchlist = default(Watchlist)) { return(Task.Factory.StartNew(s => ((IWatchlistsAPI)s).UpdateWatchlistAsync(id, watchlist), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
/// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='id'> /// </param> /// <param name='watchlist'> /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <Watchlist> UpdateWatchlistAsync(this IWatchlistsAPI operations, Guid id, Watchlist watchlist = default(Watchlist), CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.UpdateWatchlistWithHttpMessagesAsync(id, watchlist, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Create or update a Watchlist and its Watchlist Items (bulk creation, e.g. /// through text/csv content type). To create a Watchlist and its Items, we /// should call this endpoint with either rawContent or a valid SAR URI and /// contentType properties. The rawContent is mainly used for small watchlist /// (content size below 3.8 MB). The SAS URI enables the creation of large /// watchlist, where the content size can go up to 500 MB. The status of /// processing such large file can be polled through the URL returned in /// Azure-AsyncOperation header. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. The name is case insensitive. /// </param> /// <param name='workspaceName'> /// The name of the workspace. /// </param> /// <param name='watchlistAlias'> /// Watchlist Alias /// </param> /// <param name='watchlist'> /// The watchlist /// </param> public static Watchlist CreateOrUpdate(this IWatchlistsOperations operations, string resourceGroupName, string workspaceName, string watchlistAlias, Watchlist watchlist) { return(operations.CreateOrUpdateAsync(resourceGroupName, workspaceName, watchlistAlias, watchlist).GetAwaiter().GetResult()); }
/// <summary> /// Create or update a Watchlist and its Watchlist Items (bulk creation, e.g. /// through text/csv content type). To create a Watchlist and its Items, we /// should call this endpoint with either rawContent or a valid SAR URI and /// contentType properties. The rawContent is mainly used for small watchlist /// (content size below 3.8 MB). The SAS URI enables the creation of large /// watchlist, where the content size can go up to 500 MB. The status of /// processing such large file can be polled through the URL returned in /// Azure-AsyncOperation header. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. The name is case insensitive. /// </param> /// <param name='workspaceName'> /// The name of the workspace. /// </param> /// <param name='watchlistAlias'> /// Watchlist Alias /// </param> /// <param name='watchlist'> /// The watchlist /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <Watchlist> CreateOrUpdateAsync(this IWatchlistsOperations operations, string resourceGroupName, string workspaceName, string watchlistAlias, Watchlist watchlist, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, workspaceName, watchlistAlias, watchlist, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
public void Update(Watchlist obj) { //DbContext.Watchlists.Attach(obj); DbContext.SaveChanges(); }
public void AddMovieToWatchlist(Watchlist watchlist) { applicationDbContext.Watchlists.Add(watchlist); applicationDbContext.SaveChanges(); }
public void DeleteMovieFromWatchlist(Watchlist watchlist) { applicationDbContext.Watchlists.Remove(watchlist); applicationDbContext.SaveChanges(); }
public static void Load() { if (AutoSaveWorld.IsRunning && !AutoSaveWorld.IsEnabled) { AutoSaveWorld.Stop(); } if (!AutoSaveWorld.IsRunning && AutoSaveWorld.IsEnabled) { AutoSaveWorld.Start(); } if (Badwords.IsRunning && !Badwords.IsEnabled) { Badwords.Unload(); } if (!Badwords.IsRunning && Badwords.IsEnabled) { Badwords.Load(); } if (ClanManager.IsEnabled) { PersistentContainer.Instance.Players.GetClans(); } if (!ClanManager.IsEnabled) { PersistentContainer.Instance.Players.clans.Clear(); } if (CustomCommands.IsRunning && !CustomCommands.IsEnabled) { CustomCommands.Unload(); } if (!CustomCommands.IsRunning && CustomCommands.IsEnabled) { CustomCommands.Load(); } if (Gimme.IsRunning && !Gimme.IsEnabled) { Gimme.Unload(); } if (!Gimme.IsRunning && Gimme.IsEnabled) { Gimme.Load(); } if (HighPingKicker.IsRunning && !HighPingKicker.IsEnabled) { HighPingKicker.Unload(); } if (!HighPingKicker.IsRunning && HighPingKicker.IsEnabled) { HighPingKicker.Load(); } if (InfoTicker.IsRunning && !InfoTicker.IsEnabled) { InfoTicker.Unload(); } if (!InfoTicker.IsRunning && InfoTicker.IsEnabled) { InfoTicker.Load(); } if (InventoryCheck.IsRunning && !InventoryCheck.IsEnabled) { InventoryCheck.Unload(); } if (!InventoryCheck.IsRunning && InventoryCheck.IsEnabled) { InventoryCheck.Load(); } if (!Watchlist.IsRunning && Watchlist.IsEnabled) { Watchlist.Load(); } if (Watchlist.IsRunning && !Watchlist.IsEnabled) { Watchlist.Unload(); } if (!ReservedSlots.IsRunning && ReservedSlots.IsEnabled) { ReservedSlots.Load(); } if (ReservedSlots.IsRunning && !ReservedSlots.IsEnabled) { ReservedSlots.Unload(); } }
public void AddWatchlist(Watchlist watchlistToAdd) { _context.AddAsync(watchlistToAdd); }
public void Create(Watchlist watchlist) { _context.Watchlists.Add(watchlist); _context.SaveChanges(); }
private void ValidateWatchlist(Watchlist Watchlist) { Assert.NotNull(Watchlist); }
public static bool SaveWatchlist(StocksDB stocksDB, string login, Watchlist watchlist) { User user = null; string collectionName = "watchlists"; if (stocksDB is null) { stocksDB = new StocksDB(); } user = GetOrCreateUser(stocksDB, login); if (user == null) { throw new UserException("Unable to access user:"******"Id", watchlist.Id); try { user.LastAccessDate = lastAccessDate; ReplaceOneResult replaceResult = collection.ReplaceOne(filter, watchlist, new UpdateOptions { IsUpsert = true }); if (replaceResult.ModifiedCount != 1 && !(replaceResult.IsAcknowledged && replaceResult.UpsertedId != null)) { return(false); } } catch (Exception e) { Console.Write(e); throw new WatchlistException("Failed to save watchlist:" + watchlist.Name + ":" + e.Message); } return(true); }
public static void Load() { Timers.TimerStart(); if (TeleportCheck.IsEnabled) { TeleportCheck.DetectionLogsDir(); } if (FlightCheck.IsEnabled) { FlightCheck.DetectionLogsDir(); } if (HatchElevator.IsEnabled) { HatchElevator.DetectionLogsDir(); } if (PlayerLogs.IsEnabled) { PlayerLogs.PlayerLogsDir(); } if (Report.IsEnabled) { Report.ReportLogsDir(); } if (PlayerStatCheck.IsEnabled) { PlayerStatCheck.DetectionLogsDir(); } if (UndergroundCheck.IsEnabled) { UndergroundCheck.DetectionLogsDir(); } if (Bank.IsEnabled) { Bank.CreateFolder(); } if (AuctionBox.IsEnabled) { AuctionBox.CreateFolder(); } if (Bounties.IsEnabled) { Players.CreateFolder(); } if (CredentialCheck.IsEnabled) { CredentialCheck.CreateFolder(); } if (DupeLog.IsEnabled) { DupeLog.CreateFolder(); } Poll.CreateFolder(); if (PersistentContainer.Instance.PollOpen) { Poll.Check(); } if (ChatHook.Special_Player_Name_Coloring) { ChatHook.SpecialIdCheck(); } if (ClanManager.IsEnabled) { PersistentContainer.Instance.Players.GetClans(); ClanManager.BuildList(); } if (!ClanManager.IsEnabled) { PersistentContainer.Instance.Players.clans.Clear(); ClanManager.ClanMember.Clear(); } if (!InfoTicker.IsEnabled && InfoTicker.IsRunning) { InfoTicker.Unload(); } if (InfoTicker.IsEnabled && !InfoTicker.IsRunning) { InfoTicker.Load(); } if (Gimme.IsRunning && !Gimme.IsEnabled) { Gimme.Unload(); } if (!Gimme.IsRunning && Gimme.IsEnabled) { Gimme.Load(); } if (UndergroundCheck.IsRunning && !UndergroundCheck.IsEnabled) { UndergroundCheck.Unload(); } if (!UndergroundCheck.IsRunning && UndergroundCheck.IsEnabled) { UndergroundCheck.Load(); } if (Badwords.IsRunning && !Badwords.IsEnabled) { Badwords.Unload(); } if (!Badwords.IsRunning && Badwords.IsEnabled) { Badwords.Load(); } if (!LoginNotice.IsRunning && LoginNotice.IsEnabled) { LoginNotice.Load(); } if (LoginNotice.IsRunning && !LoginNotice.IsEnabled) { LoginNotice.Unload(); } if (!Zones.IsRunning && Zones.IsEnabled) { Zones.Load(); } if (Zones.IsRunning && !Zones.IsEnabled) { Zones.Unload(); } if (!VoteReward.IsRunning && VoteReward.IsEnabled) { VoteReward.Load(); } if (VoteReward.IsRunning && !VoteReward.IsEnabled) { VoteReward.Unload(); } if (!Watchlist.IsRunning && Watchlist.IsEnabled) { Watchlist.Load(); } if (Watchlist.IsRunning && !Watchlist.IsEnabled) { Watchlist.Unload(); } if (!ReservedSlots.IsRunning && ReservedSlots.IsEnabled) { ReservedSlots.Load(); } if (ReservedSlots.IsRunning && !ReservedSlots.IsEnabled) { ReservedSlots.Unload(); } if (!StartingItems.IsRunning && StartingItems.IsEnabled) { StartingItems.Load(); } if (StartingItems.IsRunning && !StartingItems.IsEnabled) { StartingItems.Unload(); } if (!Travel.IsRunning && Travel.IsEnabled) { Travel.Load(); } if (Travel.IsRunning && !Travel.IsEnabled) { Travel.Unload(); } if (!Shop.IsRunning && Shop.IsEnabled) { Shop.Load(); } if (Shop.IsRunning && !Shop.IsEnabled) { Shop.Unload(); } if (!Motd.IsRunning && Motd.IsEnabled) { Motd.Load(); } if (Motd.IsRunning && !Motd.IsEnabled) { Motd.Unload(); } if (InventoryCheck.IsRunning && !InventoryCheck.IsEnabled) { InventoryCheck.Unload(); } if (!InventoryCheck.IsRunning && InventoryCheck.IsEnabled) { InventoryCheck.Load(); } if (HighPingKicker.IsRunning && !HighPingKicker.IsEnabled) { HighPingKicker.Unload(); } if (!HighPingKicker.IsRunning && HighPingKicker.IsEnabled) { HighPingKicker.Load(); } if (CredentialCheck.IsRunning && !CredentialCheck.IsEnabled) { CredentialCheck.Unload(); } if (!CredentialCheck.IsRunning && CredentialCheck.IsEnabled) { CredentialCheck.Load(); } if (CustomCommands.IsRunning && !CustomCommands.IsEnabled) { CustomCommands.Unload(); } if (!CustomCommands.IsRunning && CustomCommands.IsEnabled) { CustomCommands.Load(); } if (DupeLog.IsRunning && !DupeLog.IsEnabled) { DupeLog.Unload(); } if (!DupeLog.IsRunning && DupeLog.IsEnabled) { DupeLog.Load(); } if (AuctionBox.IsEnabled) { AuctionBox.AuctionList(); } if (MutePlayer.IsEnabled) { MutePlayer.MuteList(); } if (Jail.IsEnabled) { Jail.JailList(); } if (Animals.IsEnabled) { Animals.AnimalList(); } if (AutoShutdown.IsEnabled) { AutoShutdown.ShutdownList(); } }
public void Delete(Watchlist entity) { DbContext.Watchlists.Remove(entity); DbContext.SaveChanges(); }
public IActionResult NewUser(AllUserViewModels model) { // Check if models received any validation errors. if (ModelState.IsValid) { try { // Check if email already exists in DB. var EmailExists = _context.Users.Where(e => e.Email == model.Reg.Email).SingleOrDefault(); // If email is unique, perform registration. if (EmailExists == null) { // Hash and store password in DB. PasswordHasher <RegisterViewModel> Hasher = new PasswordHasher <RegisterViewModel>(); string HashedPassword = Hasher.HashPassword(model.Reg, model.Reg.Password); User NewUser = new User { FirstName = model.Reg.FirstName, LastName = model.Reg.LastName, Email = model.Reg.Email, Password = HashedPassword, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now, }; Portfolio Portfolio = new Portfolio { User = NewUser, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now, }; Watchlist Watchlist = new Watchlist { User = NewUser, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now, }; _context.Add(NewUser); _context.Add(Portfolio); _context.Add(Watchlist); _context.SaveChanges(); // Set user id in session for use in identification, future db calls, and for greeting the user. HttpContext.Session.SetInt32("LoggedUserId", NewUser.Id); // Redirect to Profile method. return(RedirectToAction("Profile")); } // Redirect w/ error if email already exists in db. else { ViewBag.email = "That email is already in use. Please try again using a different one."; MostActiveStocksAPICall(); return(View("landing")); } } // Catch should only run if there was an error with the password hashing or storing on the new user in the DB. catch { MostActiveStocksAPICall(); return(View("landing")); } } // Else statement will run if the ModelState is invalid. else { MostActiveStocksAPICall(); return(View("landing")); } }
private async Task ThrowIfUnauthorized(Claim userId, Watchlist watchlist) { var watcher = await _dataContext.GetWatcherFromClaim(userId); ThrowIfUnauthorized(watcher.Id, watchlist); }
public async Task SetRedisMaintenanceScheduleAsync() { LoadApplicationKey().ThrowIfFailure(); var logger = TestGlobal.Logger; var tracingContext = new Context(logger); var context = new OperationContext(tracingContext); var environmentResources = await App.Monitor.CreateEnvironmentResourcesAsync(context, Constants.DefaultEnvironments); var watchlist = await Watchlist.CreateAsync( logger, Constants.DefaultEnvironments, environmentResources.ToDictionary( kvp => kvp.Key, kvp => kvp.Value.KustoQueryClient)); var rings = (new string[] { "Ring_0", "Ring_1", "Ring_2", "Ring_3" }).Reverse().ToArray(); var primaryInstancesPerRing = rings.ToDictionary(r => r, r => new List <IRedisCache>()); var secondaryInstancesPerRing = rings.ToDictionary(r => r, r => new List <IRedisCache>()); var resources = environmentResources[MonitorEnvironment.CloudBuildProduction]; foreach (var stamp in watchlist.EnvStamps[MonitorEnvironment.CloudBuildProduction]) { var metadata = watchlist.TryGetProperties(stamp).GetValueOrThrow(); if (resources.RedisCaches.TryGetValue(stamp.PrimaryRedisName, out var primary)) { primaryInstancesPerRing[metadata.Ring].Add(primary); } if (resources.RedisCaches.TryGetValue(stamp.SecondaryRedisName, out var secondary)) { secondaryInstancesPerRing[metadata.Ring].Add(secondary); } } var primaryDayByRing = new[] { DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday }; var secondaryDayByRing = new[] { DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday }; var startHourUtc = 17; var maintenanceWindow = TimeSpan.FromHours(6); var exceptions = new List <Exception>(); foreach (var(ring, position) in rings.Select((x, i) => (x, i))) { foreach (var instance in primaryInstancesPerRing[ring]) { try { await SetMaintenanceScheduleAsync(instance, primaryDayByRing[position], startHourUtc, maintenanceWindow); } catch (Exception e) { tracingContext.Error(e, $"Failed to set maintenance schedule for instance {instance.Name}", nameof(RedisMaintenanceSchedule)); exceptions.Add(e); } } foreach (var instance in secondaryInstancesPerRing[ring]) { try { await SetMaintenanceScheduleAsync(instance, secondaryDayByRing[position], startHourUtc, maintenanceWindow); } catch (Exception e) { tracingContext.Error(e, $"Failed to set maintenance schedule for instance {instance.Name}", nameof(RedisMaintenanceSchedule)); exceptions.Add(e); } } } if (exceptions.Count > 0) { throw new AggregateException(innerExceptions: exceptions); } }