Пример #1
0
 /// <summary>
 /// One time timer to execute timed events.
 /// </summary>
 private void StartTimer(treeParts part, int interval, CustomizedButton cb)
 {
     _timer           = new Timer();
     _timer.Interval  = interval += 100;
     _timer.AutoReset = false;
     if (part.Equals(treeParts.leaf))
     {
         _timer.Elapsed += (sender, e) => timer_Reassign_Leaf_Tick(sender, e, cb);
     }
     else
     {
         _timer.Elapsed += timer_Create_Trunk_Tick;
     }
     _timer.Start();
 }
Пример #2
0
        /// <summary>
        /// Creates a specified part of the tree.
        /// </summary>
        void CreateTreePart(treeParts part)
        {
            // Store data of avaliable tree index.
            Tuple <int, int, int> treeIndex = TreeIndex(part);

            // When treeIndex returns nothing or sorting hasn't finished, terminate here.
            if (treeIndex == null || _finishedSorting == false)
            {
                return;
            }

            // Create Button.
            Button button = new Button();

            button.Width  = 50;
            button.Height = 25;

            // Add button to the grid.
            grid.Children.Add(button);

            switch (part)
            {
            case treeParts.leaf:
                // Customize Button
                CustomizedButton cb = new CustomizedButton(button, _client.Sentiment(null, TextBox.Text));
                cb.MainWindow = this;
                cb.UpdateProperties(treeIndex.Item1, treeIndex.Item2, treeIndex.Item3);

                // Register button for reference.
                RegisterName(button.Name, button);

                // Add Button to SortedTupleCollection bag for later manipulation.
                _bag.Add(cb.SentimentValue, cb);

                // Update sentiment percentages.
                UpdateStatistics(cb.SentimentValue, cb.Sentiment.Polarity, false);
                break;

            case treeParts.trunk:
                button.SetValue(Grid.RowProperty, treeIndex.Item2);
                button.SetValue(Grid.ColumnProperty, treeIndex.Item3);
                button.Background = Brushes.SandyBrown;
                break;
            }
        }
Пример #3
0
        /// <summary>
        /// Deletes a specified CustomizedButton.
        /// </summary>
        public void DeleteLeaf(CustomizedButton cb)
        {
            // When parameter cb is empty or sorting hasn't finished, terminate here.
            if (cb == null || _finishedSorting == false)
            {
                return;
            }

            // Set leaf index to default value.
            _treeIndices[(int)cb.Button.GetValue(Grid.RowProperty), (int)cb.Button.GetValue(Grid.ColumnProperty)] = (int)treeParts.leaf;

            // Convert SortedTupleCollection bag to a list and store it.
            List <Tuple <double, CustomizedButton> > list = _bag.ToList();

            // Remove specified tuple from the list.
            list.Remove(Tuple.Create(cb.SentimentValue, cb));

            // Re-initialize the SortedTupleCollection bag.
            _bag = new SortedTupleCollection <double, CustomizedButton>();

            // Iterate through every element in the list.
            foreach (var element in list)
            {
                // Re-add element into the SortedTupleCollection bag.
                _bag.Add(element);
            }

            // Update sentiment percentages.
            UpdateStatistics(cb.SentimentValue, cb.Sentiment.Polarity, true);

            // Unregister Button's name.
            UnregisterName(cb.Button.Name);

            cb.UnloadEvents();

            // Remove Button from the grid.
            grid.Children.Remove(cb.Button);
        }
Пример #4
0
        /// <summary>
        /// After every elapse of _sortTimer re-assign leaf properties.
        /// </summary>
        private void timer_Reassign_Leaf_Tick(object sender, EventArgs e, CustomizedButton cb)
        {
            // Store data of avaliable tree index.
            Tuple <int, int, int> leafIndex = TreeIndex(treeParts.leaf);

            // Make sure we are on the main thread.
            Application.Current.Dispatcher.Invoke(delegate
            {
                // Update CustomizedButton properties.
                cb.UpdateProperties(leafIndex.Item1, leafIndex.Item2, leafIndex.Item3);

                // Register name for later use.
                RegisterName(cb.Button.Name, cb.Button);

                // Add button to the grid.
                grid.Children.Add(cb.Button);
            });

            // When the maximum capacity is reached, sorting has finished.
            if (leafIndex.Item1.Equals(_bag.Count))
            {
                _finishedSorting = true;
            }
        }