Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactorings and various changes #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed Bin/CheckForJavaW.exe
Binary file not shown.
19 changes: 0 additions & 19 deletions Bin/Icons/readme.txt

This file was deleted.

Binary file removed CheckForJavaW.zip
Binary file not shown.
70 changes: 56 additions & 14 deletions VS/CheckForJavaW.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

109 changes: 71 additions & 38 deletions VS/CheckForJavaW.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,103 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Consultingwerk.Tools.Properties;

namespace WindowsFormsApplication2
namespace Consultingwerk.Tools
{
public partial class CheckForJavaW : Component
{
string currentIcon = "";
#region Fields

private string runningInstancesMessage = "";

#endregion

#region Constructors

public CheckForJavaW()
{
InitializeComponent();
tsmiQuit.Click += tsmiQuit_OnClick;
tsmiRunningInstances.Click += tsmiRunningInstances_OnClick;
}

public CheckForJavaW(IContainer container)
{
container.Add(this);
#endregion

InitializeComponent();
}
#region Methods

private void timer1_Tick(object sender, EventArgs e)
private Icon GetIcon(int count)
{
string icon = "";
var resourceManager = Resources.ResourceManager;

int sessionId = Process.GetCurrentProcess().SessionId;
int numberofinstances = 0;
if (count < 10)
return (Icon) resourceManager.GetObject($"icon_{count}");

Process[] processes = Process.GetProcessesByName("javaw");
return Resources.icon_plus;
}

foreach (Process javaw in processes)
{
if (javaw.SessionId == sessionId)
{ numberofinstances = numberofinstances + 1; }
}
public void Exit()
{
notifyIcon.Visible = false;
components.Dispose();
}

if (numberofinstances > 9)
{
numberofinstances = 9;
}
#endregion

icon = Path.Combine (new FileInfo (Application.ExecutablePath).Directory.FullName,
"Icons",
String.Format(@"Iconarchive-Red-Orb-Alphabet-Number-{0}.ico", numberofinstances));
#region Event Handlers

if (icon != currentIcon)
{
notifyIcon1.Icon = new System.Drawing.Icon(icon);
notifyIcon1.Visible = true;

currentIcon = icon;
}
private void tsmiRunningInstances_OnClick(object sender, EventArgs eventArgs)
{
MessageBox.Show(runningInstancesMessage,
"Running JavaW Instances",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}

private void notifyIcon1_MouseDoubleClick(object sender, System.Windows.Forms.MouseEventArgs e)
private void tsmiQuit_OnClick(object sender, EventArgs eventArgs)
{
Process.Start("taskmgr");
Application.Exit();
}

public void Exit()
private void timer_Tick(object sender, EventArgs e)
{
notifyIcon1.Visible = false;
this.components.Dispose();
List<Process> processes =
Process.GetProcessesByName("javaw")
.Where(x => x.SessionId == Process.GetCurrentProcess().SessionId)
.ToList();

int numberOfInstances = processes.Count();
var pathsStringBuilder = new StringBuilder();

foreach (Process process in processes)
{
try
{
pathsStringBuilder.AppendLine(process.MainModule.FileName);
}
catch (Exception ex)
{
pathsStringBuilder.AppendLine(
"Javaw running in 64bit mode, this programm is running in 32bit Mode, could not get Executable Paths!");
pathsStringBuilder.AppendLine("");
pathsStringBuilder.AppendLine("Exception:");
pathsStringBuilder.AppendLine(ex.ToString());
break;
}
}

notifyIcon.Icon = GetIcon(numberOfInstances);
notifyIcon.Text = $"Number of currently executed javaw.exe processes: {numberOfInstances}";

runningInstancesMessage = pathsStringBuilder.ToString();
}

private void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e) => Process.Start("taskmgr");

#endregion
}
}
}
78 changes: 48 additions & 30 deletions VS/CheckForJavaW.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,42 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -65,6 +101,7 @@
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
Expand All @@ -78,36 +115,17 @@
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Content Include="Icons\Iconarchive-Red-Orb-Alphabet-Number-0.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Icons\Iconarchive-Red-Orb-Alphabet-Number-1.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Icons\Iconarchive-Red-Orb-Alphabet-Number-2.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Icons\Iconarchive-Red-Orb-Alphabet-Number-3.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Icons\Iconarchive-Red-Orb-Alphabet-Number-4.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Icons\Iconarchive-Red-Orb-Alphabet-Number-5.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Icons\Iconarchive-Red-Orb-Alphabet-Number-6.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Icons\Iconarchive-Red-Orb-Alphabet-Number-7.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Icons\Iconarchive-Red-Orb-Alphabet-Number-8.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Icons\Iconarchive-Red-Orb-Alphabet-Number-9.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="Icons\icon-0.ico" />
<None Include="Icons\icon-1.ico" />
<None Include="Icons\icon-2.ico" />
<None Include="Icons\icon-3.ico" />
<None Include="Icons\icon-4.ico" />
<None Include="Icons\icon-5.ico" />
<None Include="Icons\icon-6.ico" />
<None Include="Icons\icon-7.ico" />
<None Include="Icons\icon-8.ico" />
<None Include="Icons\icon-9.ico" />
<None Include="Icons\icon-plus.ico" />
<Content Include="Icons\readme.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down
Loading