Ejemplo n.º 1
0
        private void addStockToolStripMenuItem_Click(object sender, EventArgs e)
        {
            HoldingForm form = new HoldingForm(refreshTime);

            form.ShowDialog();
            if (form.save)
            {
                stocks.Add(form.stock);
            }
            UpdateGrids();
        }
Ejemplo n.º 2
0
        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();
        }
Ejemplo n.º 3
0
        void ProcessCommand(TileBaseCmd command)
        {
            switch (command)
            {
            case TileCMD_GetServername cmd:
                cmd.Servername = Settings.Servername;
                client.SendMessage(cmd.SID, serializer.Serialize(cmd));
                break;

            case TileCMD_GetMapInfo cmd:
                cmd.MapInfo = Settings.MapInfo;
                client.SendMessage(cmd.SID, serializer.Serialize(cmd));
                break;

            case TileCMD_UpdatePlayerInfo cmd:
                lock (tileClients)
                {
                    PlayerInfo pi = tileClients.FirstOrDefault(p => p.ID == cmd.SID);
                    if (pi == null)
                    {
                        tileClients.Add(pi = new PlayerInfo()
                        {
                            ID = cmd.SID
                        });
                    }
                    pi.Populate(cmd.Playerinfo);
                }
                break;
            }
        }
 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);
         }
 }
Ejemplo n.º 5
0
    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);
            }
        }
    }
Ejemplo n.º 6
0
        /// <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();
        }
Ejemplo n.º 7
0
        void marketplace_XmlDocChanged(object sender, EventArgs a)
        {
            contentview.SuppressSelectionChanged();
            _content.RaiseListChangedEvents = false;
            _batchhandler.Abort();
            //while (!batchhandler.WorkDone) Task.Delay(10);
            _content.Clear();
            var xdoc = _helper.XmlDoc;

            if (xdoc != null)
            {
                var entries = xdoc.Descendants(Constants.NetworkConnectivity.Namespaces.Atom + "entry");
                foreach (var entry in entries)
                {
                    MarketPlaceContent tempContent = new MarketPlaceContent(entry, (Language)querylanguage_sel.SelectedItem);
                    tempContent.Load();
                    _content.Add(tempContent);
                }
                numitems_sync_label.Text = xdoc.Descendants(Constants.NetworkConnectivity.Namespaces.Live + "totalItems").First().Value;
                cat_sync_label.Text      = _helper.MediaTypes.Name;
                int numItems;
                if (Int32.TryParse(numitems_sync_label.Text, out numItems))
                {
                    int max = (int)Math.Ceiling(numItems / entrys_num.Value);
                    if (max < page_num.Value)
                    {
                        page_num.Value = max;
                    }
                    page_num.Maximum = max;
                    Constants.BindingLists.Categorys[Constants.BindingLists.Categorys.IndexOf((MediaId)cat_select.SelectedItem)].TotalCount = numItems;
                }
            }
            _content.RaiseListChangedEvents = true;
            _content.ResetBindings();
            _batchhandler.StartUrlCheck(false);
            contentview.ResumeSelectionChanged();
        }
Ejemplo n.º 8
0
        /// <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);
            }
        }