private void Load() { nicknameBox.Text = client.User.Login; chatroomsBindingList = new ThreadedBindingList <Chatroom>(); client.ChatroomsBindingList = chatroomsBindingList; defaultChatroom = new Chatroom("Select a chatroom"); chatroomsBindingList.Add(defaultChatroom); chatrooms.ItemsSource = chatroomsBindingList; usersBindingList = new ThreadedBindingList <User>(); client.UsersBindingList = usersBindingList; userlist.ItemsSource = usersBindingList; messagesBindingList = new ThreadedBindingList <string>(); client.MessagesBindingList = messagesBindingList; messages.ItemsSource = messagesBindingList; // Start the thread to check the chatrooms available checkChatrooms = new Thread(new ThreadStart(this.getChatrooms)); checkChatrooms.Start(); // Start the thread to check the users connected to the current chatroom checkUsers = new Thread(new ThreadStart(this.getUsers)); checkUsers.Start(); // Start the thread to check server checkServer = new Thread(new ThreadStart(this.getServer)); checkServer.Start(); }
private void MainForm_Shown(object sender, EventArgs e) { LoginForm loginForm = new LoginForm(); loginForm.ShowDialog(); if (loginForm.cancelFlag) { Application.Exit(); } dataGridViewPositions_Resize(null, null); pictureBoxBGImage.BringToFront(); market = new Stock("SPY"); TVIX = new Stock("TVIX"); nugt = new Stock("NUGT"); if (File.Exists(Robinhood.__stocksFile)) { stocks = ReadFromXmlFile <ThreadedBindingList <Stock> >(Robinhood.__stocksFile); } else { stocks = new ThreadedBindingList <Stock>(); } AllPendingOrders = new ThreadedBindingList <OrderSnapshot>(); RecentOrders = new ThreadedBindingList <OrderSnapshot>(); stocks.sortProperty = "Ticker"; ThreadPool.QueueUserWorkItem(PendingOrdersUpdater, null); ThreadPool.QueueUserWorkItem(MarketPerfomanceUpdater, this); ready = true; }
static void Main() { Application.EnableVisualStyles(); using (var form = new Form()) using (var lst = new ListBox()) { form.Controls.Add(lst); lst.Dock = DockStyle.Fill; form.Shown += delegate { BindingList <Foo> data = new ThreadedBindingList <Foo>(); lst.DataSource = data; ThreadPool.QueueUserWorkItem(delegate { int i = 0; while (true) { data.Add(new Foo(i++)); Thread.Sleep(1000); } }); }; Application.Run(form); } }
static void Main() { using (Form form = new Form()) { FlightUav currentlyControlledFlightUav = new FlightUav(); BindingSource bindSrc = new BindingSource(); var list = new ThreadedBindingList <FlightUav>(); list.Add(currentlyControlledFlightUav); bindSrc.DataSource = list; form.DataBindings.Clear(); form.DataBindings.Add("Text", list, "Latitude"); using (Button btn = new Button()) { btn.Text = "Fly"; btn.Click += delegate { Thread tFly = new Thread(currentlyControlledFlightUav.Fly); tFly.IsBackground = true; tFly.Start(); }; form.Controls.Add(btn); Application.Run(form); } } }
/// <summary> /// Action performed after the constructor: create the ThreadedBindingLists and start the 2 threads /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Chat_Load(object sender, EventArgs e) { // When we close this form, we want to close it all! this.FormClosing += new FormClosingEventHandler(Chat_Closing); welcomeLabel.Text = "Welcome " + client.User.Login; chatroomsBindingList = new ThreadedBindingList <Chatroom>(); client.ChatroomsBindingList = chatroomsBindingList; defaultChatroom = new Chatroom("Select a chatroom"); chatroomsBindingList.Add(defaultChatroom); chatrooms.DataSource = chatroomsBindingList; usersBindingList = new ThreadedBindingList <User>(); client.UsersBindingList = usersBindingList; userlist.DataSource = usersBindingList; messagesBindingList = new ThreadedBindingList <string>(); client.MessagesBindingList = messagesBindingList; messages.DataSource = messagesBindingList; // Start the thread to check the chatrooms available checkChatrooms = new Thread(new ThreadStart(this.getChatrooms)); checkChatrooms.Start(); // Start the thread to check the users connected to the current chatroom checkUsers = new Thread(new ThreadStart(this.getUsers)); checkUsers.Start(); // Start the thread to check server checkServer = new Thread(new ThreadStart(this.getServer)); checkServer.Start(); }
public BatchUrlChecker(ThreadedBindingList <MarketPlaceContent> content, SynchronizationContext uiThread) { _content = content; _uithread = uiThread ?? SynchronizationContext.Current; bgw.DoWork += new DoWorkEventHandler(bgw_DoWork); bgw.ProgressChanged += new ProgressChangedEventHandler(bgw_ProgressChanged); bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgw_RunWorkerCompleted); }
private void converter_init() { _xcpList = new ThreadedBindingList <XcpInstance>(); _godList = new ThreadedBindingList <GameOnDemand>(); _isoList = new ThreadedBindingList <IsoInstance>(); xcptogod_blvex.DataSource = _xcpList; godtoiso_blvex.DataSource = _godList; }
private void UpdateMarketQuotes(MainForm mainForm) { //List<Stock> quotes = new List<Stock>(); if (mainForm.stocks.Count() == 0) { return; //quotes = mainForm.stocks.Union(quotes).ToList(); } List <Stock> marketStocks = Robinhood.GetQuote(mainForm.stocks.ToList()); foreach (Stock stock in marketStocks) { //relying on update recent order to add pending orders ThreadedBindingList <OrderSnapshot> pendingOrders = null; if (stock.PendingOrders != null) { lock (stock.PendingOrders) { pendingOrders = new ThreadedBindingList <OrderSnapshot>(AllPendingOrders.Where(o => o.InstrumentId == stock.InstrumentURL).ToList()); } } else { pendingOrders = new ThreadedBindingList <OrderSnapshot>(AllPendingOrders.Where(o => o.InstrumentId == stock.InstrumentURL).ToList()); } if (pendingOrders.Count > 0) { stock.PendingOrders = pendingOrders; } else { stock.PendingOrders = null; } mainForm.PositionsGrid.BeginInvoke((Action) delegate { lock (mainForm.stocks) { int index = mainForm.stocks.ToList() .FindIndex(s => s.Ticker == stock.Ticker); if (index >= 0) { mainForm.stocks[index] = stock; } } }); if (stock.NoOfShares > 0) { UpdateOwnedStock(mainForm, stock); } else { //don't own this stock stock.CostBasis = 0.00m; } } }
private void download_init() { _downloads = new ThreadedBindingList <DownloadInstance>(); downloadmanager_blv.DataSource = _downloads; foreach (BetterListViewColumnHeader header in downloadmanager_blv.Columns) { header.AutoResize(BetterListViewColumnHeaderAutoResizeStyle.HeaderSize); } }
private void marketplace_init() { _batchhandler = new BatchUrlChecker(new ThreadedBindingList <MarketPlaceContent>(), SynchronizationContext.Current); _content = _batchhandler._content; _helper.XmlDocLoaded += marketplace_XmlDocChanged; _batchhandler.ProgressChangedEnd += marketplace_urlChecking_ProgressBar_Progress; try { entrys_num.Value = Settings.Default.entry_per_page; page_num.Maximum = Settings.Default.last_page_viewed; page_num.Value = Settings.Default.last_page_viewed; batchdelay_updown.Value = Settings.Default.batchdelay; #region CategoryInit cat_select.DataSource = Constants.BindingLists.Categorys; cat_select.DisplayMember = "name"; cat_select.SelectedIndex = Settings.Default.mediaindex; _helper.MediaTypes = (MediaId)cat_select.SelectedItem; cat_select.SelectedIndexChanged += setting_marketplace_cat_select_SelectedIndexChanged; #endregion #region RegionInit reg_select.DataSource = Constants.BindingLists.Regions; reg_select.DisplayMember = "name"; reg_select.SelectedIndex = Settings.Default.regionindex; _helper.Locales = (RegionId)reg_select.SelectedItem; reg_select.SelectedIndexChanged += setting_marketplace_reg_select_SelectedIndexChanged; #endregion #region QueryLanguageInit querylanguage_sel.DataSource = Constants.BindingLists.Languages; querylanguage_sel.DisplayMember = "id"; querylanguage_sel.SelectedIndex = Settings.Default.languageindex; _helper.Language = (Language)querylanguage_sel.SelectedItem; querylanguage_sel.SelectedValueChanged += setting_marketplace_querylanguage_sel_SelectedIndexChanged; #endregion #region OtherInit versionval_label.Text = Constants.Debug + Constants.Iteration + '.' + Constants.Majorversion + '.' + Constants.Minorversion; _batchhandler.NetworkDelay = Convert.ToInt32(batchdelay_updown.Value); #endregion _helper.PageSize = entrys_num.Value.ToString(); _helper.PageNum = page_num.Value.ToString(); _helper.SubmitQuery(); contentview.DataSource = _content; marketplace_ContentViewResize(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
/* public Globals(Form myForm, TextBox mytextBox) { ProxyServers = new BindingList<ProxyServer>(); ProxySources = new BindingList<ProxySource>(); _textBox1 = mytextBox; _Form = myForm; } */ public Globals(Form myForm, TextBox mytextBox) { ProxyServers = new ThreadedBindingList<ProxyServer>(); ProxySources = new ThreadedBindingList<ProxySource>(); ProxyServers.SynchronizationContext = SynchronizationContext.Current; ProxySources.SynchronizationContext = SynchronizationContext.Current; _textBox1 = mytextBox; _Form = myForm; }
/// <summary> /// Refreshes Order history/Queued orders /// </summary> /// <param name="param"></param> void PendingOrdersUpdater(object param) { while (true) { try { IList <OrderSnapshot> queuedOrders = new List <OrderSnapshot>(); IList <OrderSnapshot> completedOrders = new List <OrderSnapshot>(); IList <OrderSnapshot> cancelledOrders = new List <OrderSnapshot>(); //get the most recent 1k orders var result = Robinhood.rh.DownloadOrders().Result; int i = 1; do { ThreadedBindingList <OrderSnapshot> oList = new ThreadedBindingList <OrderSnapshot>(result.Items.ToList()); if (oList != null && oList.Any(o => o.State == "queued") || oList.Any(o => o.State == "confirmed")) { //adding confirmed orders to pending order ((List <OrderSnapshot>)queuedOrders).AddRange(oList.Where(o => o.State == "confirmed")); //adding queueed order to pending orders ((List <OrderSnapshot>)queuedOrders).AddRange(oList.Where(o => o.State == "queued" && !queuedOrders.Any(or => or.OrderId == o.OrderId)).ToList()); } //TODO: add support for "partially_filled" orders if (oList != null && oList.Any(o => o.State == "filled")) { //adding filled orders ((List <OrderSnapshot>)completedOrders).AddRange(oList.Where(o => o.State == "filled").ToList()); } if (oList != null && oList.Any(o => o.State == "cancelled")) { //adding canceled orders ((List <OrderSnapshot>)cancelledOrders).AddRange(oList.Where(o => o.State == "cancelled").ToList()); } //removing filled and cancelled orders from pending orders lock (AllPendingOrders) { for (int j = 0; j < AllPendingOrders.Count(); j++) { if (cancelledOrders.Any(or => or.OrderId == AllPendingOrders[j].OrderId) || completedOrders.Any(or => or.OrderId == AllPendingOrders[j].OrderId)) { AllPendingOrders.RemoveAt(j); } } } //From the most recent 1k orders adding opened & filled order to recent orders ui grid if (i == 1) { RecentOrders = new ThreadedBindingList <OrderSnapshot>(oList.Where(o => o.State != "cancelled").ToList()); this.dataGridViewRecentOrders.BeginInvoke((Action) delegate { this.UpdateRecentOrders(); }); } //after downloading recent 3 order break loop and start from most recent order again if (i >= 3) { break; } i++; // going back 1k orders result = Robinhood.rh.DownloadOrders(result.Next).Result; } while (result.Items != null); //from the most recent 3k order adding open order to a list foreach (OrderSnapshot order in queuedOrders) { if (!AllPendingOrders.Any(o => o.OrderId == order.OrderId)) { lock (AllPendingOrders) { AllPendingOrders.Add(order); } } } foreach (Stock s in stocks) { s.PendingOrders = new ThreadedBindingList <OrderSnapshot>(AllPendingOrders.Where(o => o.InstrumentId == s.InstrumentURL).ToList()); } } catch (Exception e) { } //sleep for 1 second before fetching recent 3k orders again Thread.Sleep(1000); } }
/// <summary> /// this thread updates all the quotes on the grids also downloads /// also download latest portfolio from RH /// </summary> /// <param name="form"></param> void MarketPerfomanceUpdater(object form) { MainForm mainForm = (MainForm)form; int i = 0; decimal lastprice = 0; while (true) { if (mainForm.formClosing) { break; } try { Stock[] quotes = new Stock[] { new Stock() { Ticker = mainForm.market.Ticker }, new Stock() { Ticker = mainForm.TVIX.Ticker }, new Stock() { Ticker = mainForm.nugt.Ticker } }; Account account = Robinhood.rh.DownloadAllAccounts().Result.First(); IList <Position> positions = Robinhood.rh.DownloadPositions(account.PositionsUrl.Uri.ToString()); foreach (Position position in positions) { Stock stock = mainForm.stocks.FirstOrDefault(s => s.InstrumentURL == position.InstrumentUrl.Uri.ToString()); if (stock == null) { if ((int)position.Quantity == 0) { continue; //skip stocks in RH watchlist } var q = Robinhood.rh.DownloadInstrument(position.InstrumentUrl.Uri.ToString()); stock = new Stock() { Ticker = q.Result.Symbol, NoOfShares = (int)position.Quantity, CostBasis = position.AverageBuyPrice }; mainForm.stocks.Add(stock); } else { stock.NoOfShares = (int)position.Quantity; if (stock.NoOfShares > 0) { stock.CostBasis = position.AverageBuyPrice; } else { stock.CostBasis = 0.00m; } } } if (mainForm.stocks.Count() > 0) { quotes = mainForm.stocks.Union(quotes).ToArray(); } List <Stock> marketStocks = Robinhood.GetQuote(quotes.ToList()); foreach (Stock stock in marketStocks) { if (stock.Ticker == market.Ticker) { mainForm.market = stock; } else if (stock.Ticker == TVIX.Ticker) { mainForm.TVIX = stock; } else if (stock.Ticker == nugt.Ticker) { mainForm.nugt = stock; } //relying on update recent order to add pending orders ThreadedBindingList <OrderSnapshot> pendingOrders = null; if (stock.PendingOrders != null) { lock (stock.PendingOrders) { pendingOrders = new ThreadedBindingList <OrderSnapshot>(AllPendingOrders.Where(o => o.InstrumentId == stock.InstrumentURL).ToList()); } } else { pendingOrders = new ThreadedBindingList <OrderSnapshot>(AllPendingOrders.Where(o => o.InstrumentId == stock.InstrumentURL).ToList()); } if (pendingOrders.Count > 0) { stock.PendingOrders = pendingOrders; } else { stock.PendingOrders = null; } mainForm.PositionsGrid.BeginInvoke((Action) delegate { lock (mainForm.stocks) { int index = mainForm.stocks.ToList() .FindIndex(s => s.Ticker == stock.Ticker); if (index >= 0) { mainForm.stocks[index] = stock; } } }); if (stock.NoOfShares > 0) { if (!mainForm.tabControlMain.TabPages[1].Text.Contains("Loading") && !trailStopping.Contains(stock.Ticker)) { //implementing trailing loss if (stock.StopLoss != null && stock.StopLoss.Execution == PricePointControl.Execution.Trailing && stock.StopLoss.TrailPrcntg > 0 && stock.NoOfShares > 0) { //PT reached sell if (stock.StopLoss.Price >= stock.LastTradePrice) { stock.StopLoss.Price = 0; //reset stop loss } decimal newVal = (stock.StopLoss.Price + (stock.StopLoss.Price * stock.StopLoss.TrailPrcntg / 100)); if (stock.LastTradePrice > newVal ) // within 2% of price target place limit sell { newVal = Math.Round(stock.LastTradePrice - (stock.LastTradePrice * stock.StopLoss.TrailPrcntg / 100), 2); if (stock.PendingOrders == null || (stock.PendingOrders != null && !stock.PendingOrders.Any(o => o.StopPrice <= newVal + 0.2m && o.StopPrice >= newVal - 0.2m))) { if (stock.NoOfShares < stock.StopLoss.NoOfShares) { stock.NoOfShares = stock.StopLoss.NoOfShares; } stock.StopLoss.Trigger = TriggerType.Stop; KeyValuePair <Stock, decimal> input = new KeyValuePair <Stock, decimal>(stock, newVal); lock (trailStopping) { trailStopping.Add(stock.Ticker); } ThreadPool.QueueUserWorkItem(TrailStopper, input); } } } //no stop loss place it if manage trade selected if (stock.ManageTrade && stock.NoOfShares > 0 && stock.StopLoss.Execution != PricePointControl.Execution.Trailing) { decimal newVal; decimal?currentStop = null; if (stock.PendingOrders != null && stock.PendingOrders.Count() > 0) { currentStop = (decimal)stock.PendingOrders.First().Price; } //if price has moved > 2% from cost newVal = Math.Round(stock.CostBasis + (stock.CostBasis * 2.10m / 100), 2); if (stock.LastTradePrice > newVal) { //price has moved 2% from cost move stop to break even newVal = Math.Round(stock.CostBasis + (stock.CostBasis * 2.00m / 100), 2); } else { //place stop loss at max newVal = Math.Round(stock.CostBasis - (stock.CostBasis * stock.MaxPrctgLoss / 100), 2); stock.StopLoss.StopOffset = 0.02m; stock.StopLoss.Trigger = TriggerType.Stop; //price has already moved at or below stop loss liquidate immiediately if (stock.LastTradePrice <= newVal) { newVal = stock.LastTradePrice; stock.StopLoss.Trigger = TriggerType.Immediate; } } if (currentStop == null || currentStop <= newVal - 0.03m || currentStop >= newVal + 0.03m) { stock.StopLoss.NoOfShares = stock.NoOfShares; stock.StopLoss.Price = newVal; //place adjusted stop loss KeyValuePair <Stock, decimal> input = new KeyValuePair <Stock, decimal>(stock, newVal); lock (trailStopping) { trailStopping.Add(stock.Ticker); } ThreadPool.QueueUserWorkItem(TrailStopper, input); } } } //Checking if Price target reached if (stock.PriceTarget != null && stock.NoOfShares > 0 && stock.PriceTarget.Price > 0 && stock.PriceTarget.NoOfShares > 0 && !priceTargeting.Contains(stock.Ticker)) { //PT reached sell if (stock.LastTradePrice + 0.02m >= stock.PriceTarget.Price) // within 2cent of price target place limit sell { KeyValuePair <Stock, decimal> input = new KeyValuePair <Stock, decimal>(stock, stock.PriceTarget.Price); lock (priceTargeting) { priceTargeting.Add(stock.Ticker); } ThreadPool.QueueUserWorkItem(PriceTargeter, input); } } } else { //don't own this stock stock.CostBasis = 0.00m; } } //Updating market tickers mainForm.BeginInvoke((MethodInvoker)(() => { mainForm.marketLabel.Text = market.Quote; mainForm.marketLabel.ForeColor = market.Color; })); mainForm.labelTVIX.BeginInvoke((Action) delegate { mainForm.labelTVIX.Text = TVIX.Quote; mainForm.labelTVIX.ForeColor = TVIX.Color; }); mainForm.nugtLabel.BeginInvoke((Action) delegate { mainForm.nugtLabel.Text = nugt.Quote; mainForm.nugtLabel.ForeColor = nugt.Color; }); //Updating account information mainForm.buyPowerLabel.Invoke((Action) delegate { mainForm.buyPowerLabel.Text = "Buying Power: $" + Math.Round(account.CashBalance.BuyingPower, 2).ToString(); }); mainForm.labelUnsettled.Invoke((Action) delegate { mainForm.labelUnsettled.Text = "Unsettled: $" + Math.Round(account.CashBalance.UnsettledFunds, 2).ToString(); }); mainForm.labelCash.Invoke((Action) delegate { mainForm.labelCash.Text = "Cash: $" + Math.Round(account.CashBalance.BuyingPower + account.CashBalance.UnsettledFunds + account.CashBalance.CashHeldForOrders, 2).ToString(); }); mainForm.buttonAddStock.Invoke((Action) delegate { mainForm.buttonAddStock.Enabled = true; }); if (mainForm.PositionsGrid.Enabled == false) { mainForm.PositionsGrid.Invoke((Action) delegate { mainForm.buttonAddStock.Enabled = true; }); } mainForm.PositionsGrid.Invoke((Action) delegate { UpdateGrids(); }); Thread.Sleep(refreshTime); } catch (AggregateException) { mainForm.BeginInvoke((MethodInvoker)(() => { mainForm.marketLabel.Text = "Could not reach Robinhood, Check network connection"; mainForm.marketLabel.ForeColor = Color.IndianRed; mainForm.marketLabel.BringToFront(); })); } catch (WebException e) { MessageBox.Show(e.ToString()); } catch (HttpException e) { MessageBox.Show(e.ToString()); } catch (Exception e) { MessageBox.Show(e.ToString()); logger.Error(e); } } }
private void StartBatchUrlCheck(ThreadedBindingList <MarketPlaceContent> boundList, SynchronizationContext threadToInvoke, DoWorkEventArgs e, BackgroundWorker worker) { int progressbarMax = 100; bgw.ReportProgress(0); if (NetworkDelay == 0) { bgw.ReportProgress(progressbarMax); return; } try { List <MarketPlaceContent> workingContent = boundList.ToList(); foreach (MarketPlaceContent oneContent in workingContent) { //e.argument is ForceRecheck true/false int DelayModifier = 40; //todo Math Over here, Fill progress bar with correct value int Delay = 1000 / DelayModifier; decimal InnerCount; decimal OuterCount = workingContent.IndexOf(oneContent) + 1; int InnerTotal = DelayModifier * Delay * NetworkDelay; int OuterTotal = workingContent.Count; int ProgressPercent = (int)Math.Ceiling(OuterCount / OuterTotal * progressbarMax); if (worker.CancellationPending && !(bool)e.Argument) { break; } if (!oneContent.DownloadChecked || (bool)e.Argument) { oneContent.CheckDownloadUrl(worker.CancellationPending, (bool)e.Argument); } else { bgw.ReportProgress(ProgressPercent); continue; } var elementAtOrDefault = boundList.ElementAtOrDefault(workingContent.IndexOf(oneContent)); if (elementAtOrDefault != null && elementAtOrDefault.TitleId == oneContent.TitleId) { //boundList.RaiseListChangedEvents = false; boundList[workingContent.IndexOf(oneContent)] = oneContent; //boundList.RaiseListChangedEvents = true; //threadToInvoke.Post(delegate { boundList.ResetItem(boundList.IndexOf(oneContent)); }, null); } bgw.ReportProgress(ProgressPercent); //networkdelay * 10 * sleep = TotalDelay if (oneContent.DownloadChecked || (bool)e.Argument) { if (!(workingContent.IndexOf(oneContent) >= workingContent.Count)) //Skip the Delay { //NetworkDelay is Delay as Int Value in Seconds for (int i = 0; i < NetworkDelay * DelayModifier; i++) { InnerCount = Delay * i; ProgressPercent = (int)Math.Ceiling((InnerCount + OuterCount * InnerTotal) / (InnerTotal * (OuterTotal + 1)) * progressbarMax); bgw.ReportProgress(ProgressPercent); if (worker.CancellationPending) { break; } Thread.Sleep(Delay); } if (worker.CancellationPending) { break; } } else { ProgressPercent = (int)Math.Ceiling((OuterCount + 1 / OuterTotal) * progressbarMax); } } } } catch (InvalidOperationException ex) { boundList.ResetBindings(); //Do Nothing Here, This Exception Is Intentional //And is Caused by allcontent being changed from user switching the page they are viewing Console.WriteLine(e.ToString()); throw; } }
private void RefreshInternalTimerList() { var validDates = gallifrey.JiraTimerCollection.GetValidTimerDates().OrderByDescending(x => x.Date); //Build Correct Set Of Data Internally foreach (var validDate in validDates) { //Add missing dates if (!internalTimerList.ContainsKey(validDate)) { var list = new ThreadedBindingList<JiraTimer> { RaiseListChangedEvents = true }; list.ListChanged += OnListChanged; internalTimerList.Add(validDate, list); } //Add missing timers var addedTimer = false; var listStartedEmpty = !internalTimerList[validDate].Any(); foreach (var jiraTimer in gallifrey.JiraTimerCollection.GetTimersForADate(validDate)) { if (internalTimerList[validDate].All(x => x.UniqueId != jiraTimer.UniqueId)) { if (!listStartedEmpty) addedTimer = true; internalTimerList[validDate].Add(jiraTimer); } } //re-order list if (addedTimer) { var orderedList = internalTimerList[validDate].OrderBy(x => x.JiraReference, new JiraReferenceComparer()).ToList(); var list = new ThreadedBindingList<JiraTimer>(orderedList) { RaiseListChangedEvents = true }; list.ListChanged += OnListChanged; internalTimerList[validDate] = list; var timerList = (ListBox)tabTimerDays.TabPages[validDate.ToString("yyyyMMdd")].Controls[string.Format("lst_{0}", validDate.ToString("yyyyMMdd"))]; timerList.DataSource = internalTimerList[validDate]; } //remove timers that have been deleted var removeList = internalTimerList[validDate].Where(timer => gallifrey.JiraTimerCollection.GetTimer(timer.UniqueId) == null).ToList(); foreach (var jiraTimer in removeList) { internalTimerList[validDate].Remove(jiraTimer); } } //remove dates that don't have any timers or date is not present var removeDates = internalTimerList.Where(x => !x.Value.Any()).Select(x => x.Key).ToList(); removeDates.AddRange(internalTimerList.Where(x => validDates.All(date => date != x.Key)).Select(x => x.Key)); foreach (var removeDate in removeDates) { internalTimerList.Remove(removeDate); } UpdateTabPages(); }
public static void Clear() { list = null; }