示例#1
0
        private (TextBlock tb, IDisposable timer) GetDateLb(string optionalToTimeZone = null)
        {
            var dateLb = App.TextBlock;

            dateLb.TextAlignment = TextAlignment.Center;
            dateLb.FontSize      = 30;
            if (optionalToTimeZone == null)
            {
                dateLb.Text = lib.GetCurrDate();
            }
            else
            {
                dateLb.Text = lib.GetCurrDate(optionalToTimeZone);
            }

            var timer = DispatcherTimer.Run(() => {
                if (optionalToTimeZone == null)
                {
                    dateLb.Text = lib.GetCurrDate();
                }
                else
                {
                    dateLb.Text = lib.GetCurrDate(optionalToTimeZone);
                }
                return(true);
            }, new TimeSpan(0, 0, 0, 1, 0));

            return(dateLb, timer);
        }
示例#2
0
        static void CheckTimerTicking() => EnterLoop(cts =>
        {
            int ticks = 0;
            var st    = Stopwatch.StartNew();
            DispatcherTimer.Run(() =>
            {
                ticks++;
                Console.WriteLine($"Tick {ticks} at {st.Elapsed}");
                if (ticks == 5)
                {
                    if (st.Elapsed.TotalSeconds < 4.5)
                    {
                        Die("Timer is too fast");
                    }
                    if (st.Elapsed.TotalSeconds > 6)
                    {
                        Die("Timer is too slow");
                    }
                    cts.Cancel();
                    return(false);
                }

                return(true);
            }, TimeSpan.FromSeconds(1));
        });
示例#3
0
 static void CheckTimerOrdering() => EnterLoop(cts =>
 {
     bool firstFired = false, secondFired = false;
     DispatcherTimer.Run(() =>
     {
         Console.WriteLine("Second tick");
         VerifyAccess();
         if (!firstFired)
         {
             throw Die("Invalid timer ordering");
         }
         if (secondFired)
         {
             throw Die("Invocation of finished timer");
         }
         secondFired = true;
         cts.Cancel();
         return(false);
     }, TimeSpan.FromSeconds(2));
     DispatcherTimer.Run(() =>
     {
         Console.WriteLine("First tick");
         VerifyAccess();
         if (secondFired)
         {
             throw Die("Invalid timer ordering");
         }
         if (firstFired)
         {
             throw Die("Invocation of finished timer");
         }
         firstFired = true;
         return(false);
     }, TimeSpan.FromSeconds(1));
 });
示例#4
0
        /// <summary>
        /// Called when the pointer enters the <see cref="MenuItem"/>.
        /// </summary>
        /// <param name="e">The event args.</param>
        protected override void OnPointerEnter(PointerEventArgs e)
        {
            base.OnPointerEnter(e);

            var menu = Parent as Menu;

            if (menu != null)
            {
                if (menu.IsOpen)
                {
                    IsSubMenuOpen = true;
                }
            }
            else if (HasSubMenu && !IsSubMenuOpen)
            {
                _submenuTimer           = DispatcherTimer.Run(
                    () => IsSubMenuOpen = true,
                    TimeSpan.FromMilliseconds(400));
            }
            else
            {
                var parentItem = Parent as MenuItem;
                if (parentItem != null)
                {
                    foreach (var sibling in parentItem.Items
                             .OfType <MenuItem>()
                             .Where(x => x != this && x.IsSubMenuOpen))
                    {
                        sibling.CloseSubmenus();
                        sibling.IsSubMenuOpen = false;
                        sibling.IsSelected    = false;
                    }
                }
            }
        }
示例#5
0
        private (TextBlock tb, IDisposable timer) GetTimeLb(string optionalToTimeZone = null)
        {
            var timeLb = App.TextBlock;

            timeLb.TextAlignment = TextAlignment.Center;
            timeLb.FontSize      = 120;
            if (optionalToTimeZone == null)
            {
                timeLb.Text = lib.GetCurrTime12HrWithSeconds();
            }
            else
            {
                timeLb.Text = lib.GetCurrTime12HrWithSeconds(optionalToTimeZone);
            }

            var timer = DispatcherTimer.Run(() => {
                if (optionalToTimeZone == null)
                {
                    timeLb.Text = lib.GetCurrTime12HrWithSeconds();
                }
                else
                {
                    timeLb.Text = lib.GetCurrTime12HrWithSeconds(optionalToTimeZone);
                }
                return(true);
            }, new TimeSpan(0, 0, 0, 1, 0));

            return(timeLb, timer);
        }
示例#6
0
        private void InitializeComponent()
        {
            AvaloniaXamlLoader.Load(this);

            _drawingPresenter = this.FindControl <DrawingPresenter>("drawingPresenter");

            DispatcherTimer.Run(() =>
            {
                UpdateGlyphRun();

                return(true);
            }, TimeSpan.FromSeconds(1));
        }
        private void InitializeComponent()
        {
            AvaloniaXamlLoader.Load(this);

            _imageControl        = this.FindControl <Image>("imageControl");
            _imageControl.Source = new DrawingImage();

            DispatcherTimer.Run(() =>
            {
                UpdateGlyphRun();

                return(true);
            }, TimeSpan.FromSeconds(1));
        }
        protected override IDisposable StartCore(Action <TimeSpan> tick)
        {
            bool cancelled = false;
            var  st        = Stopwatch.StartNew();

            DispatcherTimer.Run(() =>
            {
                if (cancelled)
                {
                    return(false);
                }
                tick(st.Elapsed);
                return(!cancelled);
            }, TimeSpan.FromSeconds(1.0 / FramesPerSecond), DispatcherPriority.Render);
            return(Disposable.Create(() => cancelled = true));
        }
        public DownloadTaskListViewModel()
        {
            result = new ObservableCollectionExtended <DownloadTaskItemViewModel>(Aria2Helper.Aria2.DownloadTasks
                                                                                  .Select(p => p.ConvertToViewModel()).ToList());
            result.ToObservableChangeSet().Bind(out _tasks).Subscribe();
            DispatcherTimer.Run(() =>
            {
                if (Aria2Helper.Aria2 == null)
                {
                    return(false);
                }

                lock (refreshLock)
                {
                    var tasks  = Aria2Helper.Aria2.DownloadTasks;
                    var allGid = tasks.Select(p => p.GID).Union(result.Select(p => p.GID)).ToList();

                    allGid.ForEach(gid =>
                    {
                        var oriTask = result.FirstOrDefault(p => p.GID == gid);
                        var ar2Task = tasks.Find(p => p.GID == gid);

                        if (oriTask == null)
                        {
                            result.Add(ar2Task.ConvertToViewModel());
                            return;
                        }

                        if (ar2Task == null)
                        {
                            result.Remove(oriTask);
                            return;
                        }

                        oriTask.TaskName      = ar2Task.TaskName;
                        oriTask.DownloadSpeed = ar2Task.DownloadSpeed;
                        oriTask.Status        = ar2Task.Status;
                        oriTask.TotalSize     = ar2Task.TotalLength;
                        oriTask.CompleteSize  = ar2Task.CompletedLength;
                    });

                    //ViewModelListMerge(_tasks, tasks);
                }

                return(true);
            }, new TimeSpan(0, 0, 0, 0, 500));
        }
示例#10
0
        public MainViewModel(IAssetLoader assets, TemperatureService temperatureService)
        {
            _assets             = assets;
            _temperatureService = temperatureService;
            _frames             = new[]
            {
                new Bitmap(_assets.Open(new Uri("avares://pidashboard/Assets/nyan-0.png", UriKind.Absolute))),
                new Bitmap(_assets.Open(new Uri("avares://pidashboard/Assets/nyan-1.png", UriKind.Absolute))),
                new Bitmap(_assets.Open(new Uri("avares://pidashboard/Assets/nyan-2.png", UriKind.Absolute))),
                new Bitmap(_assets.Open(new Uri("avares://pidashboard/Assets/nyan-3.png", UriKind.Absolute)))
            };

            EnvironmentalDataUpdater();
            CurrentTimeUpdater();
            DispatcherTimer.Run(EnvironmentalDataUpdater, TimeSpan.FromSeconds(30));
            DispatcherTimer.Run(CurrentTimeUpdater, TimeSpan.FromSeconds(1));
            DispatcherTimer.Run(NyanCatenator, TimeSpan.FromMilliseconds(150));
        }
        /// <summary>
        /// Called when the pointer enters the <see cref="MenuItem"/>.
        /// </summary>
        /// <param name="e">The event args.</param>
        protected override void OnPointerEnter(PointerEventArgs e)
        {
            base.OnPointerEnter(e);

            var menu = Parent as Menu;

            if (menu != null)
            {
                if (menu.IsOpen)
                {
                    IsSubMenuOpen = true;
                }
            }
            else if (HasSubMenu && !IsSubMenuOpen)
            {
                _submenuTimer           = DispatcherTimer.Run(
                    () => IsSubMenuOpen = true,
                    TimeSpan.FromMilliseconds(400));
            }
        }
示例#12
0
        private void StartGame()
        {
            _GenerationsOutputFileNameTimeStamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); //Used for output filename

            Cell[,] currentStateGrid = ReadCurrentStateFromGrid();

            _universe = new Universe(currentStateGrid);

            _RunTimer = true;

            if (!_TimerCreated) // This will avoid duplicate timers. If one was already created, reuse it.
            {
                DispatcherTimer.Run(() =>
                {
                    _universe.Tick();
                    RenderCurrentState();

                    return(_RunTimer);
                }, TimeSpan.FromSeconds(_TimerIntervalInSeconds));
            }
        }
 public override void Activated()
 {
     TimeoutSecondsLeft = TimeoutSeconds;
     DispatcherTimer.Run(TimerTick, TimeSpan.FromSeconds(1));
 }
示例#14
0
        public GridSite(DataGrid owningGrid, string urlString)
        {
            Uri uriOut;

            if (!(Uri.TryCreate(urlString, UriKind.Absolute, out uriOut) &&
                  (uriOut.Scheme == Uri.UriSchemeHttp || uriOut.Scheme == Uri.UriSchemeHttps)))
            {
                throw new InvalidUrlException();
            }
            Site = uriOut.ToString();

            Library lib = new Library();

            void ForceGridUpdate()
            {
                owningGrid.Items = owningGrid.Items.Cast <GridSite>().ToList();
            }

            async void UpdateTimedEntry()
            {
                Last = DateTime.Now;
                Next = DateTime.Now.AddMinutes(((App)Application.Current).AppUI.RefreshMinutes);
                bool siteReached = true;

                if (Status.Equals(Status.Initializing))
                {
                    try {
                        currentContent = lib.GetParsedPageContent(await lib.GetPageAsync(uriOut));
                    } catch {
                        Status      = Status.Unreachable;
                        siteReached = false;
                        ForceGridUpdate();
                    }
                    if (siteReached)
                    {
                        Status = Status.Unchanged;
                        ForceGridUpdate();
                    }
                }
                else
                {
                    try {
                        newContent = lib.GetParsedPageContent(await lib.GetPageAsync(uriOut));
                    } catch {
                        Status      = Status.Unreachable;
                        siteReached = false;
                        ForceGridUpdate();
                    }
                    if (siteReached && currentContent.Equals(newContent))
                    {
                        Status = Status.Unchanged;
                        ForceGridUpdate();
                    }
                    else if (siteReached && !currentContent.Equals(newContent))
                    {
                        Status = Status.Changed;
                        var oldNewtextDiffs = lib.GetTextDifferences(currentContent, newContent);
                        if (((App)Application.Current).AppUI.IsShowNotificationEnabled)
                        {
                            await InitDiffsWindow(oldNewtextDiffs).ShowDialog <Window>(Application.Current.MainWindow);
                        }
                        ForceGridUpdate();
                    }
                }
            }

            UpdateTimedEntry();

            timerDisposable = DispatcherTimer.Run(() => {
                UpdateTimedEntry();
                return(true);
            }, new TimeSpan(0, 0, ((App)Application.Current).AppUI.RefreshMinutes, 0, 0));
        }
示例#15
0
        static void Main(string[] args)
        {
            //LogManager.Enable(new TestLogger());
            //LogManager.Instance.LogLayoutMessages = true;

            App application = new App
            {
                DataTemplates = new DataTemplates
                {
                    new TreeDataTemplate <Node>(
                        x => new TextBlock {
                        Text = x.Name
                    },
                        x => x.Children,
                        x => true),
                },
            };

            TextBlock fps;

            Window window = new Window
            {
                Title   = "Perspex Test Application",
                Content = new Grid
                {
                    ColumnDefinitions = new ColumnDefinitions
                    {
                        new ColumnDefinition(1, GridUnitType.Star),
                        new ColumnDefinition(1, GridUnitType.Star),
                    },
                    RowDefinitions = new RowDefinitions
                    {
                        new RowDefinition(1, GridUnitType.Star),
                        new RowDefinition(GridLength.Auto),
                    },
                    Children = new Controls
                    {
                        new TabControl
                        {
                            Items = new[]
                            {
                                ButtonsTab(),
                                TextTab(),
                                ImagesTab(),
                                ListsTab(),
                                SlidersTab(),
                                LayoutTab(),
                                AnimationsTab(),
                            },
                            [Grid.ColumnSpanProperty] = 2,
                        },
                        (fps = new TextBlock
                        {
                            HorizontalAlignment = HorizontalAlignment.Left,
                            Margin = new Thickness(2),
                            [Grid.RowProperty] = 1,
                        }),
                        new TextBlock
                        {
                            Text = "Press F12 for Dev Tools",
                            HorizontalAlignment = HorizontalAlignment.Right,
                            Margin = new Thickness(2),
                            [Grid.ColumnProperty] = 1,
                            [Grid.RowProperty]    = 1,
                        },
                    }
                },
            };

            DevTools.Attach(window);

            var renderer = ((IRenderRoot)window).Renderer;
            var last     = renderer.RenderCount;

            DispatcherTimer.Run(() =>
            {
                fps.Text = "FPS: " + (renderer.RenderCount - last);
                last     = renderer.RenderCount;
                return(true);
            }, TimeSpan.FromSeconds(1));

            window.Show();
            Application.Current.Run(window);
        }
        public void InitializeDialog(string saveTitle, string saveProdCode, string saveIdentifier, ushort saveRegion, int saveSize, int iconFrames, int interpolationMode, int iconPropertiesSize, Bitmap[] saveIcons, int[] slotNumbers, int backColor)
        {
            string ocupiedSlots = null;

            iconInterpolationMode = interpolationMode;
            iconSize        = iconPropertiesSize;
            SaveTitleText   = saveTitle;
            ProductCodeText = saveProdCode;
            IdentifierText  = saveIdentifier;
            SizeText        = saveSize.ToString() + " KB";
            IconFramesText  = iconFrames.ToString();
            maxCount        = iconFrames;
            iconData        = saveIcons;
            iconBackColor   = backColor;

            //Show region string
            switch (saveRegion)
            {
            default:            //Region custom, show hex
                RegionText = "0x" + saveRegion.ToString("X4");
                break;

            case 0x4142:        //America
                RegionText = "America";
                break;

            case 0x4542:        //Europe
                RegionText = "Europe";
                break;

            case 0x4942:        //Japan
                RegionText = "Japan";
                break;
            }

            //Get ocupied slots
            for (int i = 0; i < slotNumbers.Length; i++)
            {
                ocupiedSlots += (slotNumbers[i] + 1).ToString() + ", ";
            }

            //Show ocupied slots
            SlotText = ocupiedSlots.Remove(ocupiedSlots.Length - 2);

            //Draw first icon so there is no delay
            drawIcons(iconIndex);

            //Enable Paint timer in case of multiple frames
            if (iconFrames > 1)
            {
                TimerObject = DispatcherTimer.Run(() =>
                {
                    if (iconIndex < (maxCount - 1))
                    {
                        iconIndex++;
                    }
                    else
                    {
                        iconIndex = 0;
                    }
                    drawIcons(iconIndex);
                    return(true);
                }, TimeSpan.FromMilliseconds(180));
            }
        }
示例#17
0
        public AppUI()
        {
            var tTbs = App.TabControl;

            tTbs.Height = 500;

            TextBlock dateLb = GetDateLb().tb;

            dateLb.Foreground = Brushes.White;
            TextBlock timeLb = GetTimeLb().tb;

            timeLb.Foreground = Brushes.White;

            Stopwatch s = new Stopwatch();

            var stwLb = App.TextBlock;

            stwLb.TextAlignment = TextAlignment.Center;
            stwLb.FontSize      = 120;
            stwLb.Text          = lib.GetStopwatchElapsedTime(s);

            var stwBtHolder = App.HorizontalStackPanel;

            stwBtHolder.HorizontalAlignment = HorizontalAlignment.Center;
            var ssBt = App.Button;

            ssBt.Content = "Start";

            IDisposable displayTimer = null;

            ssBt.Click += (z, zz) => {
                if (!s.IsRunning)
                {
                    ssBt.Content = "Stop";
                    displayTimer = DispatcherTimer.Run(() => {
                        s.Start();
                        stwLb.Text = lib.GetStopwatchElapsedTime(s);
                        return(true);
                    }, new TimeSpan(0, 0, 0, 0, 1));
                }
                else
                {
                    ssBt.Content = "Start";
                    s.Stop();
                    displayTimer.Dispose();
                }
            };

            var rstBt = App.Button;

            rstBt.Content = "Reset";

            rstBt.Click += (z, zz) => {
                if (displayTimer != null)
                {
                    displayTimer.Dispose();
                }

                if (s.IsRunning)
                {
                    ssBt.Content = "Start";
                }
                s.Reset();
                stwLb.Text = lib.GetStopwatchElapsedTime(s);
            };

            stwBtHolder.Children.Add(ssBt);
            stwBtHolder.Children.Add(rstBt);

            TextBlock fromZoneDateLb = GetDateLb().tb;
            TextBlock fromZoneTimeLb = GetTimeLb().tb;

            var tzSelec = App.ComboBoxWithLabel;

            tzSelec.holder.HorizontalAlignment = HorizontalAlignment.Center;
            tzSelec.label.Text             = "To time zone:";
            tzSelec.comboBox.Items         = lib.TimeZones.Select(z => "UTC" + z.BaseUtcOffset.TotalHours + " " + z.Id);
            tzSelec.comboBox.SelectedIndex = 0;

            var ctCv = new StackPanel();

            ctCv.HorizontalAlignment = HorizontalAlignment.Stretch;
            ctCv.VerticalAlignment   = VerticalAlignment.Stretch;
            ctCv.Background          = Brushes.Black;

            ctCv.Children.AddRange(new List <IControl> {
                new Control()
                {
                    Height = 130
                }, dateLb, timeLb
            });

            var sCv = new StackPanel();

            sCv.Children.AddRange(new List <IControl> {
                stwLb, stwBtHolder
            });

            var ttzCv = new StackPanel();

            var tzdl = GetDateLb(((string)tzSelec.comboBox.SelectedItem).Substring(((string)tzSelec.comboBox.SelectedItem).IndexOf(" ") + " ".Length));
            var tztl = GetTimeLb(((string)tzSelec.comboBox.SelectedItem).Substring(((string)tzSelec.comboBox.SelectedItem).IndexOf(" ") + " ".Length));

            tzSelec.comboBox.SelectionChanged += (z, zz) => {
                tzdl.timer.Dispose();
                tztl.timer.Dispose();

                ttzCv.Children.Remove(tzdl.tb);
                ttzCv.Children.Remove(tztl.tb);

                tzdl = GetDateLb(((string)tzSelec.comboBox.SelectedItem).Substring(((string)tzSelec.comboBox.SelectedItem).IndexOf(" ") + " ".Length));
                tztl = GetTimeLb(((string)tzSelec.comboBox.SelectedItem).Substring(((string)tzSelec.comboBox.SelectedItem).IndexOf(" ") + " ".Length));

                ttzCv.Children.Add(tzdl.tb);
                ttzCv.Children.Add(tztl.tb);
            };

            ttzCv.Children.AddRange(new List <IControl> {
                fromZoneDateLb, fromZoneTimeLb, tzSelec.holder, tzdl.tb, tztl.tb
            });

            sCv.HorizontalAlignment = ttzCv.HorizontalAlignment = HorizontalAlignment.Center;
            sCv.VerticalAlignment   = ttzCv.VerticalAlignment = VerticalAlignment.Center;

            tTbs.Items = new List <TabItem> {
                new TabItem()
                {
                    Header = "Current time", Content = ctCv
                },
                new TabItem()
                {
                    Header = "Stopwatch", Content = sCv
                },
                new TabItem()
                {
                    Header = "To Time Zone", Content = ttzCv
                },
            };
            tTbs.SelectedIndex = 0;

            rootPan.Children.AddRange(new List <IControl> {
                tTbs
            });
        }
示例#18
0
        public AppUI()
        {
            var itfs = lib.GetNetworkInterfaces().Select(z => new PrunedNetInterface(z));

            foreach (var itf in itfs)
            {
                var dg = App.DataGrid;
                dg.Height = 430;
                dg.Margin = new Thickness(5);
                dg.SetValue(DataGrid.WidthProperty, AvaloniaProperty.UnsetValue);

                dg.Items = BuildNinfo(itf).Select(z => new { z.Variable, z.Value });

                ((List <DataGrid>)niControls).Add(dg);
            }

            var blb1 = App.TextBlock;

            blb1.TextAlignment = TextAlignment.Center;
            blb1.Text          = "Current Network Interfaces";

            gridScroll.Height     = App.Current.MainWindow.Height - 100;
            gridScroll.Background = Brushes.Transparent;

            App.Current.MainWindow.PropertyChanged += (z, zz) => {
                if (zz.Property.Equals(Window.HeightProperty))
                {
                    gridScroll.Height = App.Current.MainWindow.Height - 100;
                }
            };

            gridScroll.Content           = this.rootGrid;
            rootGrid.Margin              = new Thickness(10, 0);
            rootGrid.Background          = Brushes.Transparent;
            rootGrid.HorizontalAlignment = HorizontalAlignment.Stretch;
            rootGrid.ColumnDefinitions   = new ColumnDefinitions("*,*,*");

            int R = (int)Math.Ceiling((decimal)itfs.Count() / 3);

            for (int i = 0; i < R; i++)
            {
                rootGrid.RowDefinitions.Add(new RowDefinition());
            }
            int emtCountr = 0;

            for (int r = 0; r < R; r++)
            {
                for (int c = 0; c < 3; c++)
                {
                    if (emtCountr < niControls.Count())
                    {
                        niControls.ElementAt(emtCountr)[Grid.RowProperty]      = r;
                        niControls.ElementAt(emtCountr++)[Grid.ColumnProperty] = c;
                    }
                }
            }
            rootGrid.Children.AddRange(niControls);
            rootPan.Children.AddRange(new List <IControl> {
                blb1, gridScroll
            });

            DispatcherTimer.Run(() => {
                foreach (var nis in lib.GetNetworkInterfaces().Select(z => new PrunedNetInterface(z)))
                {
                    if (niControls.Any(z => {
                        return(z.Items.Cast <dynamic>().Any(zz => { return zz.Variable.Equals("Id") && nis.Id.Equals(zz.Value); }));
                    }))
                    {
                        var tempNic   = niControls.First(z => z.Items.Cast <dynamic>().Any(zz => { return(zz.Variable.Equals("Id") && nis.Id.Equals(zz.Value)); }));
                        tempNic.Items = BuildNinfo(nis).Select(z => new { z.Variable, z.Value });
                    }
                }
                return(true);
            }, TimeSpan.FromSeconds(3));
        }