C# Shortcuts: Startup and Automated Perforce

Background

My C# Shortcuts app is a personal project of mine being developed in my own time outside of work in 2021. The goal of this app is to automate a bunch of different repetitive tasks in my everyday life to save time and increase efficiency. Programmers are definitely one of the laziest people you’ll meet, in the way that if we can get out of manually doing the work, we’ll dedicate 12 hours to automating a 1 hour job, with the aim of not having to manually repeat that 1 hour job in future. That is the goal of this app.

But why C# if my main work is all in C++? The reason is quite simple: because if I wrote it in C++, I wouldn’t be learning anything. C# was the first programming language I used back when I started my tertiary education at AIE, and I’ve touched on it again and again in the years since but I’ve never held onto a C# project long enough to become properly proficient in the language. By building this project in C#, I learn new things with every new feature, and I continue to add to my personal knowledge base, which is always the main goal of all my work.


Theme: Automation
Engine: MonoGame (XNA)
Platform: PC
Time Worked: 30 January 2021 - 08 February 2021

Base Project

I decided to use the MonoGame (XNA) Plugin for Visual Studio in order to create this app for two reasons. One is that it holds a certain nostalgic value for me, as it was the first tool I used in AIE where I created my first ever project, which was a simple Pong game. The second is that MonoGame’s template has a window already set up, and it’s extremely easy to add and control UI elements and input, and since my main focus is on features and not setup, it was a quick and easy way to start. Since I don’t know exactly what all the future features of the app might be, I figured it would be good to be able to quickly add UI elements without the fuss of setting something up from scratch. Plus, I have a handful of UI classes like buttons already written in past projects if and when I need them.

Startup and Automated Perforce

The goal of this first feature was to automate my startup process every morning when I first turn on my computer at work. That way I can press the power button and walk away to get some food or a drink or something while my computer prepares itself for the work day ahead. I set it up so that my C# Shortcuts app opened automatically on startup and performs the following actions:

  1. Reads from an XML file to find the default Perforce connection information for work’s Perforce server, and then also for the apps that I want to open.
  2. Connects to Perforce (using the Perforce C# API), discovers all local workspaces, and pulls the latest for each of the workspaces.
  3. Opens the apps that I use every day. In my case it’s p4v, Gyazo Replay, Google Chrome for my work schedule, and Discord. I open p4v last so that it’s the foremost window open, allowing the app to automatically simulate a keyboard <enter> press, to let it establish its connection and load the default workspace.
  4. By the time I finish with whatever I’m doing and get back to my computer, it’s all set up and ready for the day ahead.