예제 #1
0
        public RAMUsageBar(dynamic settings)
        {
            if (settings["color"] != null)
            {
                this.MainColor = (string)settings["color"];
            }
            if (settings["background-color"] != null)
            {
                this.BackgroudColor = (string)settings["background-color"];
            }
            if (settings["width"] != null)
            {
                this.Width = (int)settings["width"];
            }
            if (settings["height"] != null)
            {
                this.Height = (int)settings["height"];
            }
            if (settings["radius"] != null)
            {
                this.Radius = (int)settings["radius"];
            }
            this.grid = new Grid();
            Rectangle rect = new Rectangle();

            rect.Fill    = new SolidColorBrush((Color)ColorConverter.ConvertFromString(this.BackgroudColor.ToUpper()));
            rect.RadiusX = Radius;
            rect.RadiusY = Radius;
            this.grid.Children.Add(rect);
            this.grid.Width  = this.Width;
            this.grid.Margin = new Thickness(0, (18 - this.Height) / 2, 0, (18 - this.Height) / 2);
            this.innerRect   = new Rectangle();
            this.innerRect.HorizontalAlignment = HorizontalAlignment.Left;
            if (!this.MainColor.Equals("from-percentage"))
            {
                innerRect.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString(this.MainColor.ToUpper()));
            }
            this.innerRect.RadiusX = Radius;
            this.innerRect.RadiusY = Radius;
            this.innerRect.Width   = 0;
            this.grid.Children.Add(this.innerRect);

            this.timer          = new Timer();
            this.timer.Interval = 1000;
            this.timer.Elapsed += delegate {
                PerfomanceInfoData data = PsApiWrapper.GetPerformanceInfo();
                Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate
                {
                    double percentage = ((double)1 - ((double)data.PhysicalAvailableBytes / (double)data.PhysicalTotalBytes));
                    if (this.MainColor.Equals("from-percentage"))
                    {
                        this.innerRect.Fill = new SolidColorBrush(this.PercentColor(100 - percentage * 100));
                    }
                    this.innerRect.Width = percentage * (double)this.Width;
                }));
            };
            this.timer.Start();
        }
예제 #2
0
        /// <summary>
        /// Get physical memory information
        /// </summary>
        private void GetMemoryInformaton()
        {
            this.performanceInfoData = PsApiWrapper.GetPerformanceInfo();

            var AvailableGb = this.performanceInfoData.PhysicalAvailableBytes.ToPrettySize(1);
            var UsedGb      = (this.performanceInfoData.PhysicalTotalBytes - this.performanceInfoData.PhysicalAvailableBytes).ToPrettySize(1);

            this.UsedPhysicalMemoryInPercent = (double)(this.performanceInfoData.PhysicalTotalBytes - this.performanceInfoData.PhysicalAvailableBytes) / this.performanceInfoData.PhysicalTotalBytes * 100;
            this.FreePhysicalMemoryInPercent = (double)100 - this.UsedPhysicalMemoryInPercent;

            this.OnPropertyChanged(() => this.UsedPhysicalMemory);
            this.OnPropertyChanged(() => this.FreePhysicalMemory);
        }
예제 #3
0
        public RAMUsageText(dynamic settings)
        {
            if (settings["color"] != null)
            {
                this.MainColor = (string)settings["color"];
            }
            this.textBlock            = new TextBlock();
            this.textBlock.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(this.MainColor));

            this.timer          = new Timer();
            this.timer.Interval = 1000;
            this.timer.Elapsed += delegate {
                PerfomanceInfoData data = PsApiWrapper.GetPerformanceInfo();
                Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate
                {
                    this.textBlock.Text = $"{Math.Round(((double)1 - ((double)data.PhysicalAvailableBytes / (double)data.PhysicalTotalBytes)) * 100)} %";
                }));
            };
            this.timer.Start();
        }
예제 #4
0
        /// <summary>
        /// Get physical memory information
        /// </summary>
        private void GetPhysicalMemoryInformation()
        {
            this.performanceInfoData = PsApiWrapper.GetPerformanceInfo();

            var AvailableGb = this.performanceInfoData.PhysicalAvailableBytes.ToPrettySize(1);
            var UsedGb      = (this.performanceInfoData.PhysicalTotalBytes - this.performanceInfoData.PhysicalAvailableBytes).ToPrettySize(1);

            this.UsedPhysicalMemoryInPercent = (double)(this.performanceInfoData.PhysicalTotalBytes - this.performanceInfoData.PhysicalAvailableBytes) / this.performanceInfoData.PhysicalTotalBytes * 100;
            this.UsedPhysicalMemory          = (this.performanceInfoData.PhysicalTotalBytes - this.performanceInfoData.PhysicalAvailableBytes).ToPrettySize(1);
            this.FreePhysicalMemoryInPercent = (double)100 - this.UsedPhysicalMemoryInPercent;
            this.FreePhysicalMemory          = this.performanceInfoData.PhysicalAvailableBytes.ToPrettySize(1);

            if (this.CurrentRAMWorkloadSeries != null && this.CurrentRAMWorkloadSeries.Count == 0)
            {
                this.CurrentRAMWorkloadSeries.Add(new ChartDataPoint()
                {
                    Name = "Used Physical Memory", Value = this.UsedPhysicalMemoryInPercent
                });
            }
            else
            {
                this.CurrentRAMWorkloadSeries.FirstOrDefault().Value = this.UsedPhysicalMemoryInPercent;
            }
        }