Skip to content

Commit

Permalink
Refactor: Add soi many enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
MbarkT3STO committed Apr 8, 2024
1 parent ad31621 commit 584e1e6
Show file tree
Hide file tree
Showing 107 changed files with 586 additions and 271 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified .vs/OfficeDRPC/v17/.suo
Binary file not shown.
57 changes: 13 additions & 44 deletions .vs/OfficeDRPC/v17/DocumentLayout.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,8 @@
"WorkspaceRootPath": "C:\\Users\\MBARK.AzureAD\\source\\repos\\MbarkT3STO\\OfficeDRPC\\",
"Documents": [
{
"AbsoluteMoniker": "D:0:0:{835B7DBC-FB0D-4EE9-B948-0C0554221801}|ExcelDRPC\\ExcelDRPC.csproj|c:\\users\\mbark.azuread\\source\\repos\\mbarkt3sto\\officedrpc\\exceldrpc\\program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{835B7DBC-FB0D-4EE9-B948-0C0554221801}|ExcelDRPC\\ExcelDRPC.csproj|solutionrelative:exceldrpc\\program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
},
{
"AbsoluteMoniker": "D:0:0:{56AD1A2F-F1B9-4B14-993E-7BDE13E5FDBA}|OfficeDRPCCommander\\OfficeDRPCCommander.csproj|C:\\Users\\MBARK.AzureAD\\source\\repos\\MbarkT3STO\\OfficeDRPC\\officedrpccommander\\worker.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"AbsoluteMoniker": "D:0:0:{56AD1A2F-F1B9-4B14-993E-7BDE13E5FDBA}|OfficeDRPCCommander\\OfficeDRPCCommander.csproj|c:\\users\\mbark.azuread\\source\\repos\\mbarkt3sto\\officedrpc\\officedrpccommander\\worker.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{56AD1A2F-F1B9-4B14-993E-7BDE13E5FDBA}|OfficeDRPCCommander\\OfficeDRPCCommander.csproj|solutionrelative:officedrpccommander\\worker.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
},
{
"AbsoluteMoniker": "D:0:0:{56AD1A2F-F1B9-4B14-993E-7BDE13E5FDBA}|OfficeDRPCCommander\\OfficeDRPCCommander.csproj|C:\\Users\\MBARK.AzureAD\\source\\repos\\MbarkT3STO\\OfficeDRPC\\officedrpccommander\\program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{56AD1A2F-F1B9-4B14-993E-7BDE13E5FDBA}|OfficeDRPCCommander\\OfficeDRPCCommander.csproj|solutionrelative:officedrpccommander\\program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
}
],
"DocumentGroupContainers": [
Expand All @@ -22,52 +14,29 @@
"DocumentGroups": [
{
"DockedWidth": 200,
"SelectedChildIndex": 4,
"SelectedChildIndex": 0,
"Children": [
{
"$type": "Bookmark",
"Name": "ST:128:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
},
{
"$type": "Bookmark",
"Name": "ST:130:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}"
},
{
"$type": "Document",
"DocumentIndex": 2,
"Title": "Program.cs",
"DocumentMoniker": "C:\\Users\\MBARK.AzureAD\\source\\repos\\MbarkT3STO\\OfficeDRPC\\OfficeDRPCCommander\\Program.cs",
"RelativeDocumentMoniker": "OfficeDRPCCommander\\Program.cs",
"ToolTip": "C:\\Users\\MBARK.AzureAD\\source\\repos\\MbarkT3STO\\OfficeDRPC\\OfficeDRPCCommander\\Program.cs",
"RelativeToolTip": "OfficeDRPCCommander\\Program.cs",
"ViewState": "AQIAABAAAAAAAAAAAAAqwCMAAAAcAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2024-04-05T14:34:46.605Z"
},
{
"$type": "Document",
"DocumentIndex": 1,
"DocumentIndex": 0,
"Title": "Worker.cs",
"DocumentMoniker": "C:\\Users\\MBARK.AzureAD\\source\\repos\\MbarkT3STO\\OfficeDRPC\\OfficeDRPCCommander\\Worker.cs",
"RelativeDocumentMoniker": "OfficeDRPCCommander\\Worker.cs",
"ToolTip": "C:\\Users\\MBARK.AzureAD\\source\\repos\\MbarkT3STO\\OfficeDRPC\\OfficeDRPCCommander\\Worker.cs",
"RelativeToolTip": "OfficeDRPCCommander\\Worker.cs",
"ViewState": "AQIAABkAAAAAAAAAAAA1wB4AAAAlAAAA",
"ViewState": "AQIAAA8AAAAAAAAAAAAAABsAAAAAAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2024-04-05T07:28:35.81Z"
"WhenOpened": "2024-04-07T22:48:42.615Z",
"IsPinned": true,
"EditorCaption": ""
},
{
"$type": "Document",
"DocumentIndex": 0,
"Title": "Program.cs",
"DocumentMoniker": "C:\\Users\\MBARK.AzureAD\\source\\repos\\MbarkT3STO\\OfficeDRPC\\ExcelDRPC\\Program.cs",
"RelativeDocumentMoniker": "ExcelDRPC\\Program.cs",
"ToolTip": "C:\\Users\\MBARK.AzureAD\\source\\repos\\MbarkT3STO\\OfficeDRPC\\ExcelDRPC\\Program.cs",
"RelativeToolTip": "ExcelDRPC\\Program.cs",
"ViewState": "AQIAAAAAAAAAAAAAAAAAAAoAAAAFAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2024-04-07T09:51:36.631Z",
"EditorCaption": ""
"$type": "Bookmark",
"Name": "ST:128:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
},
{
"$type": "Bookmark",
"Name": "ST:130:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}"
}
]
}
Expand Down
112 changes: 81 additions & 31 deletions AccessDRPC/PresenceWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,48 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;

using AccessDRPC.Core;

using MBDRPC.Helpers;

namespace AccessDRPC
{
public class PresenceWorker
{
private Presence presence = new Presence();
private string officeAppSubscriptionType = "Mirosoft Office";
private bool isFirstRun = true;
private Presence presence = new Presence();
private string officeAppSubscriptionType = "Mirosoft Office";
private bool isFirstRun = true;
private DateTime startTime;
private string processName;
private string processName = "MSACCESS";

public Timer Timer;



[DllImport( "user32.dll", SetLastError = true)]
static extern IntPtr GetForegroundWindow();

[DllImport( "user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport( "user32.dll", SetLastError = true)]
static extern bool SetForegroundWindow(IntPtr hWnd);

[DllImport( "user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern int GetWindowText(IntPtr hWnd, string lpString, int nMaxCount);

[DllImport( "user32.dll", SetLastError = true)]
static extern int GetClassName(IntPtr hWnd, [Out] StringBuilder lpClassName, int nMaxCount);

[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);



/// <summary>
/// Starts the presence
/// </summary>
Expand All @@ -28,12 +53,19 @@ public void Start()
Timer = new Timer(_ => CheckMicrosoftAccess(), null, TimeSpan.Zero, TimeSpan.FromSeconds(1));
}

/// <summary>
/// Stops the presence
/// </summary>
public void Stop()
{
presence.ShutDown();
Timer.Dispose();
}


private void CheckMicrosoftAccess()
{
processName = "MSACCESS";
var isPowerPointAppRunning = RunningAppChecker.IsAppRunning(processName);
if (isPowerPointAppRunning)
if (RunningAppChecker.IsMicrosoftAccessRunning())
{
if (isFirstRun)
{
Expand Down Expand Up @@ -70,10 +102,8 @@ private void CheckMicrosoftAccess()
private static bool IsAnyOpenWindow()
{
// Check if Microsoft Access is running
var processes = Process.GetProcessesByName( "MSACCESS" )
.Where( p => ! string.IsNullOrEmpty( p.MainWindowTitle ) );

return processes.Any();
return Process
.GetProcessesByName("MSACCESS").Any(p => !string.IsNullOrEmpty(p.MainWindowTitle));
}


Expand Down Expand Up @@ -112,12 +142,8 @@ private static string[] GetAccessOpenWindowNames()
/// </summary>
private static bool IsHomeScreenActive()
{
var openWindowNames = GetAccessOpenWindowNames();

if (openWindowNames.Length <= 0) return false;

var windowName = openWindowNames[0];
return ! ( windowName.StartsWith( "Access - " ) );
var handle = FindWindow(null, "Access");
return handle != IntPtr.Zero;
}


Expand All @@ -129,10 +155,38 @@ private static bool IsHomeScreenActive(IReadOnlyList<string> openWindowNames)
if (openWindowNames.Count <= 0) return false;

var windowName = openWindowNames[0];
return windowName.Equals( "Access" );
return windowName.Equals("Access");
}


/// <summary>
/// Gets the name of the active window/file
/// </summary>
private static string GetActiveWindowName()
{
// App is running, check for the active window
var foregroundWindow = GetForegroundWindow();

if (foregroundWindow == IntPtr.Zero) return string.Empty;

// Get the window title
const int nChars = 256;
var windowTitle = new string(' ', nChars);
GetWindowText(foregroundWindow, windowTitle, nChars);

if ( windowTitle.Contains( "-" ) && windowTitle.Contains( ":" ) )
{
// Remove between 'Access - ' and ':' to the end from the window title
var fileName = windowTitle.Substring( windowTitle.IndexOf( " - " , StringComparison.Ordinal ) + 3 ,
windowTitle.IndexOf( ":" , StringComparison.Ordinal ) -
windowTitle.IndexOf( " - " , StringComparison.Ordinal ) - 3 );

return fileName;
}

return string.Empty;
}



/// <summary>
Expand All @@ -143,23 +197,19 @@ private void UpdatePresence()
//Check if any database is open
if (IsAnyOpenWindow())
{
var openWindowNames = GetAccessOpenWindowNames();

if(IsHomeScreenActive(openWindowNames))
if (IsHomeScreenActive())
{
presence.UpdateDetails("Home screen");
}
else
{
if ( openWindowNames.Length > 0 )
{
var windowName = openWindowNames[0];
var activeWindowName = GetActiveWindowName();

presence.UpdateDetails($"Managing database: {windowName}");
if (activeWindowName != string.Empty)
{
presence.UpdateDetails($"Managing database: {activeWindowName}");
}
}


}
else
{
Expand All @@ -182,11 +232,11 @@ private void UpdatePresenceTime()

public static string GetOfficeVersion()
{
string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
string office365Path = Path.Combine(appDataPath, "Microsoft", "Office");
var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
var office365Path = Path.Combine(appDataPath, "Microsoft", "Office");

string programFilesPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
string perpetualOfficePath = Path.Combine(programFilesPath, "Microsoft Office", "root", "Office16");
var programFilesPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
var perpetualOfficePath = Path.Combine(programFilesPath, "Microsoft Office", "root", "Office16");

if (Directory.Exists(office365Path))
{
Expand Down
Binary file modified AccessDRPC/bin/Debug/AccessDRPC.exe
Binary file not shown.
Binary file modified AccessDRPC/bin/Debug/AccessDRPC.pdb
Binary file not shown.
Binary file modified AccessDRPC/bin/Debug/MBDRPC.dll
Binary file not shown.
Binary file modified AccessDRPC/bin/Debug/MBDRPC.pdb
Binary file not shown.
Binary file modified AccessDRPC/obj/Debug/AccessDRPC.csproj.AssemblyReference.cache
Binary file not shown.
Binary file modified AccessDRPC/obj/Debug/AccessDRPC.exe
Binary file not shown.
Binary file modified AccessDRPC/obj/Debug/AccessDRPC.pdb
Binary file not shown.
Loading

0 comments on commit 584e1e6

Please sign in to comment.