Example #1
0
 protected override void ProgressBarDataDataAction(ProgressBarData barData)
 {
     if (barData.Id == id)
     {
         fillerController.SetFill(barData.CurrentAmount / barData.TotalAmount);
     }
 }
        #pragma warning restore 649

        protected override void ProgressBarDataDataAction(ProgressBarData barData)
        {
            if (showTime == null)
            {
                return;
            }
            showTime.SetTime(barData.CurrentAmount);
        }
Example #3
0
 private void ProgressBarDataHandler(ProgressBarData barData)
 {
     if (barData.BarType != barType)
     {
         return;
     }
     ProgressBarDataDataAction(barData);
 }
Example #4
0
 private void ProgressBarDataHandler(ProgressBarData barData)
 {
     if (barData.BarType != barType)
     {
         return;
     }
     fillerController.SetFill(barData.CurrentAmount / barData.TotalAmount);
     ProgressBarDataDataAction(barData);
 }
Example #5
0
        #pragma warning restore 649

        protected override void ProgressBarDataDataAction(ProgressBarData barData)
        {
            fillerController.SetFill(barData.CurrentAmount / barData.TotalAmount);

            if (showTime == null)
            {
                return;
            }
            showTime.SetTime(barData.CurrentAmount);
        }
Example #6
0
        public void AddProgressBar(ReduceCounter reduceCounter)
        {
            var prgoressbarData = new ProgressBarData(reduceCounter,
                                                      new Point(0, 15),
                                                      Color.FromArgb(200, 0, 127, 255),
                                                      Color.FromArgb(128, 0, 0, 0),
                                                      DrawType.RightToLeft, 100, 10, 2);

            RegisterProgressBar(prgoressbarData);
            RegisterCounter(reduceCounter);
        }
Example #7
0
 private static void invoke(ProgressBarData pbd)
 {// Invoke the progress bar's dispatcher to update the progress bar:
     try
     {
         pbd.ProgressBar.Dispatcher.Invoke(pbd.UpdateProgressBar,
                                           System.Windows.Threading.DispatcherPriority.Background,
                                           new object[] { ProgressBar.ValueProperty, pbd.CurValue }
                                           );
     }
     catch (Exception ex) { MessageBox.Show("invoke: " + ex.Message); } // Unexpcted error.
 }
Example #8
0
        public ProgressBarData GetProgressBar(string jobType, int idFrom, int idTo, int loopCounterProgressBar)
        {
            ProgressBarData progressBar = new ProgressBarData()
            {
                JobType    = jobType,
                FromId     = idFrom,
                ToId       = idTo,
                LoopCouner = loopCounterProgressBar
            };

            return(progressBar);
        }
        /// <summary>
        /// Initialze the configuration for design system
        /// And load initial values to use
        /// </summary>
        private void Init()
        {
            if (JMRThemeConfigurator == null)
            {
                JMRThemeConfigurator = new ThemeConfigurator();
            }

            currentColorsList = JMRThemeConfigurator.GetColorPreferences();
            currentIconsList  = JMRThemeConfigurator.GetIconPreferences();

            m_ProgressBarData = new ProgressBarData("Searching ...", "0%", m_CompletionPercentage);

            // TO DO: Do this only once in a life time
            AddTagsToTagManager();
        }
Example #10
0
        private void InitializeLevelProgressBar()
        {
            var playerPosition = TryPlayerPosition();

            var finishPosition = TryFinishPosition();

            totalLevelDistance   = Mathf.Abs(playerPosition - finishPosition);
            currentLevelDistance = 0f;

            levelProgressBarData = new ProgressBarData
            {
                BarType     = ProgressBarType.LevelProgression,
                TotalAmount = totalLevelDistance
            };
        }
        public void ProgressBarEvent_Published_UpdatesProgressBarPropertiess()
        {
            ProgressBarData bar = new ProgressBarData()
            {
                JobType    = "unit test",
                LoopCouner = 100,
                FromId     = 10,
                ToId       = 1010
            };

            _progressBarEvent.Publish(bar);

            Assert.Equal(10, _viewModel.UpdateStatusBar);
            Assert.Equal("unit test", _viewModel.WorkStatus);
            Assert.Equal("100 / 1000", _viewModel.ProgressDisplay);
        }
Example #12
0
        private static Timer timer = new Timer();                                                                // The timer.

        // Create and add a new progress bar data element to the progressbars dictionary, and to timerList if TimerTicks is > 0.
        public static int New(ProgressBar pb, double min, double max, double value, int timerTicks = 0)
        {                             // Adds a new progress bar to be updated:
            var handle = newHandle(); // Get a new handle.

            if (handle != InvalidHandle)
            {// Handle is valid, create a new data element:
                try
                {
                    var pbd = new ProgressBarData()
                    {
                        ProgressBar = pb
                    };                                                    // New progress bar data element.
                    pbd.MinValue            = min;
                    pbd.ProgressBar.Minimum = min;
                    pbd.MaxValue            = max;
                    pbd.ProgressBar.Maximum = max;
                    pbd.CurValue            = value;
                    pbd.InitialValue        = value;
                    pbd.TimerTicks          = timerTicks;
                    pbd.LastUpdate          = DateTime.Now;
                    pbd.UpdateProgressBar   = new UpdateProgressBarDelegate(pbd.ProgressBar.SetValue);
                    progressBars.Add(handle, pbd);
                    if (pbd.TimerTicks > 0)
                    {                          // Updates are based on the timer.
                        pbd.TimerPause = true; // Updating does not automatically start, you must call TimerReset();
                        timerList.Add(handle);
                    }
                    timerSet(); // Make sure timer is started if there are any items in the timerList and if not, stop the timer.
                }
                catch (Exception ex)
                {// Some unforeseen error has occurred:
                    if (progressBars.ContainsKey(handle))
                    {
                        progressBars.Remove(handle);                                    // Reverse all that
                    }
                    if (timerList.Contains(handle))
                    {
                        timerList.Remove(handle);                                       // may have been done.
                    }
                    handle = InvalidHandle;                                             // Return invalid handle.
                    MessageBox.Show("New: " + ex.Message);
                }
            }
            return(handle);
        }
Example #13
0
    public void LoadProgressBar(ProgressBarData data)
    {
        if (data == null)
        {
            return;
        }

        _currentVal = data.value;

        Debug.Log("Load progress bar");

        if (_nextLevelLoadController.descentWasSpawned)
        {
            DisableProgressBar();
        }
        else
        {
            EnableProgressBar();
        }
    }
Example #14
0
        /// <summary>
        /// updates data on progress bar for any task
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnProgressBarTick(ProgressBarData bar)
        {
            int divider = bar.ToId - bar.FromId;

            WorkStatus = bar.JobType;

            if (divider > 0)
            {
                UpdateStatusBar = bar.LoopCouner * 100 / (bar.ToId - bar.FromId);
                ProgressDisplay = bar.LoopCouner + " / " + (bar.ToId - bar.FromId);
            }
            else if (divider == 0)
            {
                UpdateStatusBar = 1 / 1;
                ProgressDisplay = "1 / 1";
            }
            else if (divider < 0)
            {
                UpdateStatusBar = 1 / 1;
                ProgressDisplay = "ERROR";
            }
        }
Example #15
0
        /// <summary>
        /// updates collections of generic type
        /// I/O operations
        /// creates loads of parallel tasks to improve performance speed
        /// use of SemaphoreSlim to control tasks
        /// SemaphoreSlim credits: https://blog.briandrupieski.com/throttling-asynchronous-methods-in-csharp
        /// SemaphoreSlim corrections: https://stackoverflow.com/a/56641448/11027921
        /// Task.Run corrections: https://stackoverflow.com/a/56631208/11027921
        /// credits for SemaphoreSlim cancellation: https://stackoverflow.com/a/24099764/11027921
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="genericCollection">collection parameter</param>
        /// <param name="idFrom">object id limitation</param>
        /// <param name="idTo">object id limitation</param>
        /// <param name="jobType">type of scrapping</param>
        /// <returns></returns>
        public async Task <List <T> > UpdateDataAsync <T>(List <T> genericCollection, int idFrom, int idTo, string jobType)
        {
            ProgressBarData progressBar;
            int             loopCounterProgressBar = 0;
            string          jobTypeProgressBar     = "";

            //parse collections, display job
            if (typeof(T) == typeof(LoadedHorse))
            {
                Horses             = new List <LoadedHorse>(genericCollection.Cast <LoadedHorse>());
                jobTypeProgressBar = "Updating horse data";
            }
            else if (typeof(T) == typeof(LoadedJockey))
            {
                Jockeys            = new List <LoadedJockey>(genericCollection.Cast <LoadedJockey>());
                jobTypeProgressBar = "Updating jockey data";
            }
            else if (typeof(T) == typeof(RaceDetails))
            {
                Races = new List <RaceDetails>(genericCollection.Cast <RaceDetails>());
                jobTypeProgressBar = "Updating historic data";
            }

            //initial
            SemaphoreSlim throttler = new SemaphoreSlim(_degreeOfParallelism);
            List <Task>   tasks     = new List <Task>();

            TokenSource       = new CancellationTokenSource();
            CancellationToken = TokenSource.Token;

            progressBar = GetProgressBar(jobType, idFrom, idTo, loopCounterProgressBar);

            progressBar = new ProgressBarData()
            {
                JobType    = jobType,
                FromId     = idFrom,
                ToId       = idTo,
                LoopCouner = loopCounterProgressBar
            };

            _eventAggregator.GetEvent <ProgressBarEvent>().Publish(progressBar);

            //run loop
            for (int i = idFrom; i < idTo + 1; i++)
            {
                int id = i;

                if (CancellationToken.IsCancellationRequested)
                {
                    break;
                }

                //create loads of parallel tasks
                tasks.Add(Task.Run(async() =>
                {
                    await throttler.WaitAsync();
                    try
                    {
                        if (CancellationToken.IsCancellationRequested)
                        {
                            return;
                        }

                        if (typeof(T) == typeof(LoadedHorse))
                        {
                            await UpdateHorsesAsync(jobType, id);
                        }
                        else if (typeof(T) == typeof(LoadedJockey))
                        {
                            await UpdateJockeysAsync(jobType, id);
                        }
                        else if (typeof(T) == typeof(RaceDetails))
                        {
                            await UpdateRacesAsync(jobType, id);
                        }
                    }
                    catch
                    {
                        MessageBox.Show(id.ToString());
                    }
                    finally
                    {
                        loopCounterProgressBar++;

                        progressBar = GetProgressBar(jobTypeProgressBar, idFrom, idTo, loopCounterProgressBar);

                        _eventAggregator.GetEvent <ProgressBarEvent>().Publish(progressBar);

                        throttler.Release();
                    }
                }));
            }

            try
            {
                await Task.WhenAll(tasks);
            }
            finally
            {
                //save when finish
                if (typeof(T) == typeof(LoadedJockey))
                {
                    await _dataServices.SaveAllJockeysAsync(Jockeys.ToList());
                }
                else if (typeof(T) == typeof(LoadedHorse))
                {
                    await _dataServices.SaveAllHorsesAsync(Horses.ToList());
                }
                else if (typeof(T) == typeof(RaceDetails))
                {
                    if (jobType.Contains("Historic"))
                    {
                        await _dataServices.SaveAllRaces(Races.ToList());
                    }
                    else if (jobType.Contains("testRaces"))
                    {
                        await _dataServices.SaveRaceSimulatedResultsAsync(Races.ToList());
                    }
                }
            }

            if (typeof(T) == typeof(LoadedHorse))
            {
                return((List <T>)Convert.ChangeType(Horses, typeof(List <T>)));
            }
            else if (typeof(T) == typeof(LoadedJockey))
            {
                return((List <T>)Convert.ChangeType(Jockeys, typeof(List <T>)));
            }
            else if (typeof(T) == typeof(RaceDetails))
            {
                return((List <T>)Convert.ChangeType(Races, typeof(List <T>)));
            }
            else
            {
                throw new ArgumentException();
            }
        }
Example #16
0
 protected abstract void ProgressBarDataDataAction(ProgressBarData barData);
 protected override void ProgressBarDataDataAction(ProgressBarData barData)
 {
     //empty;
 }