/// <summary>
        /// Estimates memory consumption
        /// </summary>
        /// <exception cref="InvalidOperationException">Process has exited</exception>
        /// <returns></returns>
        public ProcessMemoryInfo GetMemoryInfo(int pid)
        {
            var handle = IntPtr.Zero;

            try
            {
                handle = ProcessUtility.OpenLimitedQueryInformationProcessHandle(pid);
                EnsureProcessIsRunning(handle, pid);

                if (!PsApi.GetProcessMemoryInfo(handle, out var counters))
                {
                    Win32ExceptionUtility.Throw();
                }

                return(new ProcessMemoryInfo
                {
                    // use PrivateUsage instead of PagefileUsage because PagefileUsage is always zero on Windows 7, Windows Server 2008 R2 and earlier systems
                    PrivateBytes = (long)counters.PrivateUsage,
                    WorkingSetBytes = (long)counters.WorkingSetSize
                });
            }
            finally
            {
                Kernel32.CloseHandle(handle);
            }
        }
Пример #2
0
        public Home()
        {
            this.InitializeComponent();

            this.learningUnits = PsApi.getInstance().learningUnits;
            this.fetchLearningUnits();
        }
        private void handleClickDeleteModule(object sender, RoutedEventArgs e)
        {
            Module module = (Module)((Button)sender).DataContext;

            PsApi.getInstance().deleteModule(module.id, this.learningUnit.id);
            this.modules.Remove(module);
        }
Пример #4
0
 /// <summary>
 ///     Do work in the background
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void BackgroundWorkerTimerTick(object sender, EventArgs e)
 {
     if (_coreConfiguration.MinimizeWorkingSetSize)
     {
         PsApi.EmptyWorkingSet();
     }
 }
 private async void handleClickSave(ContentDialog sender, ContentDialogButtonClickEventArgs args)
 {
     if (this.mode == ModuleDialogMode.CREATE)   // Create
     {
         this.result = await PsApi.getInstance().createModule(this.result, this.unitId);
     }
     else if (this.mode == ModuleDialogMode.EDIT)   // Update
     {
         this.result = await PsApi.getInstance().updateModule(this.result, this.unitId);
     }
 }
        private async void handleClickDeleteGrade(object sender, RoutedEventArgs e)
        {
            Grade  grade  = (Grade)((Button)sender).DataContext;
            Module module = modules.FirstOrDefault(m => m.grades.Select(g => grade.id).Contains(grade.id));

            PsApi.getInstance().deleteGrade(grade.id, module.id);
            module.grades.Remove(grade);
            int index = this.modules.IndexOf(module);

            modules.RemoveAt(index);
            modules.Insert(index, module);
        }
Пример #7
0
 private async void ContentDialog_PrimaryButtonClick(ContentDialog sender,
                                                     ContentDialogButtonClickEventArgs args)
 {
     if (this.mode == GradeDialogMode.CREATE)   // Create
     {
         this.result = await PsApi.getInstance().createGrade(this.result, this.moduleId);
     }
     else if (this.mode == GradeDialogMode.EDIT)   // Update
     {
         this.result = await PsApi.getInstance().updateGrade(this.result, this.moduleId);
     }
 }
Пример #8
0
        /// <summary>
        /// Estimates memory consumption
        /// </summary>
        /// <exception cref="InvalidOperationException">Process has exited</exception>
        /// <returns></returns>
        public ProcessMemoryInfo GetMemoryInfo()
        {
            ProcessUtility.EnsureProcessIsRunning(handle, pid);

            if (!PsApi.GetProcessMemoryInfo(handle, out var counters))
            {
                Win32ExceptionUtility.Throw();
            }

            return(new ProcessMemoryInfo
            {
                // use PrivateUsage instead of PagefileUsage because PagefileUsage is always zero on Windows 7, Windows Server 2008 R2 and earlier systems
                PrivateBytes = (long)counters.PrivateUsage,
                WorkingSetBytes = (long)counters.WorkingSetSize,
            });
        }
        private async void handleClickAddGrade(object sender, RoutedEventArgs e)
        {
            Module module        = (Module)((Button)sender).DataContext;
            var    gradeDialog   = new GradeDialog(new Grade(), module.id, GradeDialog.GradeDialogMode.CREATE);
            var    buttonClicked = await gradeDialog.ShowAsync();

            module.grades.Add(gradeDialog.result);

            if (buttonClicked == ContentDialogResult.Primary)
            {
                this.learningUnit = await PsApi.getInstance().getLearningUnitAsync(this.learningUnit.id);

                this.modules.Clear();
                this.learningUnit.modules.ForEach(modules.Add);
            }
        }
Пример #10
0
 /// <summary>
 ///     Do work in the background
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void BackgroundWorkerTimerTick(object sender, EventArgs e)
 {
     if (_coreConfiguration.MinimizeWorkingSetSize)
     {
         PsApi.EmptyWorkingSet();
     }
     if (UpdateHelper.IsUpdateCheckNeeded())
     {
         Log.Debug().WriteLine("BackgroundWorkerTimerTick checking for update");
         // Start update check in the background
         var backgroundTask = new Thread(UpdateHelper.CheckAndAskForUpdate)
         {
             Name         = "Update check",
             IsBackground = true
         };
         backgroundTask.Start();
     }
 }
Пример #11
0
        public void RaiseChanges()
        {
            try
            {
                var pi = new PerformanceInformation();
                if (PsApi.GetPerformanceInfo(out pi, Marshal.SizeOf(pi)))
                {
                    this.Free  = Convert.ToInt64(pi.PhysicalAvailable.ToInt64() * pi.PageSize.ToInt64());
                    this.Total = Convert.ToInt64(pi.PhysicalTotal.ToInt64() * pi.PageSize.ToInt64());
                }
            }
            catch (Exception ex)
            {
                this.logger.LogWarning(ex, "Error on resolving ram info.");
            }

            this.Info = this.format.GetFormatedString(this.Total, this.Free);

            this.RaisePropertyChanged(nameof(this.Total));
            this.RaisePropertyChanged(nameof(this.Free));
            this.RaisePropertyChanged(nameof(this.Info));
            this.RaisePropertyChanged(nameof(this.Value));
        }
Пример #12
0
 private async void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
 {
     this.result = await PsApi.getInstance().updateUnit(this.result);
 }
Пример #13
0
        public void Initialize()
        {
            Log.Debug().WriteLine("Initializing MainForm.");
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            try
            {
                InitializeComponent();
                SetupBitmapScaleHandler();
            }
            catch (ArgumentException ex)
            {
                // Added for Bug #1420, this doesn't solve the issue but maybe the user can do something with it.
                ex.Data.Add("more information here", "http://support.microsoft.com/kb/943140");
                throw;
            }
            notifyIcon.Icon = GreenshotResources.GetGreenshotIcon();

            // Disable access to the settings, for feature #3521446
            contextmenu_settings.Visible = !_coreConfiguration.DisableSettings;

            UpdateUi();

            if (_coreConfiguration.DisableQuickSettings)
            {
                contextmenu_quicksettings.Visible = false;
            }
            else
            {
                // Do after all plugins & finding the destination, otherwise they are missing!
                InitializeQuickSettingsMenu();
            }

            // Set the Greenshot icon visibility depending on the configuration. (Added for feature #3521446)
            // Setting it to true this late prevents Problems with the context menu
            notifyIcon.Visible = !_coreConfiguration.HideTrayicon;

            // Check if it's the first time launch?
            if (_coreConfiguration.IsFirstLaunch)
            {
                _coreConfiguration.IsFirstLaunch = false;
                Log.Info().WriteLine("FirstLaunch: Created new configuration, showing balloon.");
                try
                {
                    notifyIcon.BalloonTipClicked += BalloonTipClicked;
                    notifyIcon.BalloonTipClosed  += BalloonTipClosed;
                    notifyIcon.ShowBalloonTip(2000, "Greenshot", string.Format(_greenshotLanguage.TooltipFirststart, HotkeyControl.GetLocalizedHotkeyStringFromString(_coreConfiguration.RegionHotkey)), ToolTipIcon.Info);
                }
                catch (Exception ex)
                {
                    Log.Warn().WriteLine(ex, "Exception while showing first launch: ");
                }
            }

            // Make Greenshot use less memory after startup
            if (_coreConfiguration.MinimizeWorkingSetSize)
            {
                PsApi.EmptyWorkingSet();
            }
        }
Пример #14
0
 private void handleClickValider(object sender, RoutedEventArgs e)
 {
     PsApi.getInstance().addLearningUnitAsync(new LearningUnit(this.name));
 }
        public MainPage()
        {
            this.InitializeComponent();

            this.service = PsApi.getInstance();
        }
Пример #16
0
 public void fetchLearningUnits()
 {
     PsApi.getInstance().getLearningUnitsAsync();
     Debug.WriteLine(this.learningUnits.Count);
 }
#pragma warning disable 618
        public void PerformanceInformation() => PsApi.GetPerformanceInfo(out _);
 private void handleClickDeleteUnit(object sender, RoutedEventArgs e)
 {
     PsApi.getInstance().deleteUnit(this.learningUnit.id);
     this.Frame.Navigate(typeof(Empty));
 }