The tale of how I simplified my workflow. Or writing your spy in C #

    In this article I want to tell you about an experiment that I set up for myself.

    I have been working remotely (outsourcing) for a long time and as a result I have to submit a monthly report on the work done, in the form of a table with the name of the tasks, time spent and other information. Even with the huge availability of ticket systems, use them daily to record work done - hard labor. In the company where I work there are no strict requirements for logging or other daily reports, which probably makes my problem of the lack of daily data unique, or at least not so popular (or not, maybe I'm not the only such outsourcer?). A month flies by unnoticed and completely immersed in work, instead of immersing in the bureaucracy, since everything is built on trust. And until recently, I dealt with the task of compiling monthly reports, because almost every day I at least greeted my skype colleagues, chatted about this, including the workflow, updated tickets, received letters. But here is the trouble, there is not always available the saved data for the right day, on which at least you can’t kill, you can’t remember what you did. And at one such moment, while compiling such a report, it suddenly dawned on me how I, as a programmer, can solve this problem myself.

    Programmers, after all, like any other specialists, possess a wealth of knowledge in their field and should use it not only for work. For example, doctors have at home a whole bunch of pills, syringes and other devices. The mechanic always has a whole bunch of spare parts and tools, to unscrew, nail, drill ... But I apparently came under the classic phrase "shoemaker without boots." My PC is assembled on a table in pieces from boards and wires, the operating system has not been rearranged for a million years, but oh well. I may be a shoemaker without boots, but the problem still needs to be solved, and I decided to patch up my boots.

    Having formed an idea in my head to solve the problem, I first decided to discuss it with my friends, what they think about it. As it turned out, they even threw me a couple of links to ready-made solutions. At first I was upset that my idea was already implemented, on the other hand, I did not even try the solutions proposed to me, because I was convinced of the ease of implementation and the security of my decision. Actually what is the idea itself?

    My solution to the logging problem was to write a spy program that would do all this work for me and hang constantly in the tray. In a couple of minutes, I came up with several functions for such a program. Here are some of the features invented:

    • Screenshot
    • Shooting short video clips of the screen
    • Clipboard Saving
    • Scheduled spying start (only on customizable hours and only on business days)

    We are talking about periodicity with a frequency of N seconds / minutes / hours (customizable in the program), i.e. when N is 1 minute, we get 8 * 60 = 480 shots in an eight-hour work day. One snapshot takes ~ 700 KB, rounded up to a megabyte, so 480 megabytes of images will accumulate in 1 working day. In a month it will be 14 gigabytes. I agree, the figure is scary. But I personally still have a place, and there is no need to save for more than a month, plus or minus. Alternatively, you can use clouds with unlimited space (it seems that there are some, no?), I personally do not use such services, I do not know. But theoretically and in a vacuum, this way you can accumulate work data for as many months / years as you want, while having access to your own data from anywhere. Another optimization option is to reduce the size of the image before saving or lengthen the period N.

    So this is the minimal set of espionage tasks that occurred to me. If you wrap everything in a beautiful interface, then perhaps the process of reading logs will become even pleasant. At my fingertips was C #, in which not so long ago I was doing some small task for work. Accordingly, the choice fell on C #.

    Using my free time in the evening, I began to implement the first function, since it is the easiest, and frankly, the only potentially useful in my task. If someone else has not fully understood the essence, then here it is: from the screenshots you can understand what you did during the day. Shooting a video is most likely a rudimentary idea, and will be deleted, since it does not bring much benefit. But I think with the clipboard. At the moment, the function is not implemented, but it is supposed to regularly save the clipboard (text) to the database on the hard disk. This is nothing more than a record of the form

    id | datetime | buffer

    Actually, the shorter the frequency N, the more data the spy will collect. By the contents of the clipboard it will be possible to understand what you programmed and copy-pasted at a specific date and time.

    Of course, I decided to make the first implementation as simple and quick as possible. So that the title of the program was not Form1, I introduced the first thing that occurred to Work Spy , and so it began to be called my brainchild. By the way, its original appearance, containing only one box with rich text (RichTextBox), which in turn was nothing more than a log window where, when and what it saved:



    Writing took about 10 minutes. A couple of requests to google and here we have examples the code for “how to take a screenshot in c #”. My spy creates a folder, calling it today's date, and accordingly during the program, using the Timer class, puts pictures of two of my monitors inside (image size 3840x1080), whose name also consists of the date and time (I decided that I would use such a template 12_03_2012__12_30_36.gif ). Image format - gif, in order to save space. Despite the graininess of the image, everything is clearly visible on it.

    The first version is written, it makes a minimum of gestures, all the settings are so far sewn into the code, instead of convenient elements on the form for setting up the program. Test debugging passed, it's time to try to run the program autonomously, and not by pressing F5. With the first launch, avast !, congratulated me, "drawing" attention to my program. Congratulations from the antivirus looked like this:



    This remains a mystery to me as he identified the potential harm in these ~ 100 lines of code, but on the other hand, it’s nice that even the simplest self-styled spy was able to suspect something was amiss. Not finding enough evidence of harm, avast! apologized



    I politely asked the esteemed avast! open my program as usual, and not in the sandbox, because I trust it 100%.

    At the moment, everything is still working in manual test mode. Daily start / close and view saved images. The program has worked so far for a week. The result is already impressive. If I open the pictures from the first day of launch, I clearly see my browser, a text editor in which I see the tabs and code of the project I'm working on. Sometimes funny pictures come across where I watch a movie (apparently a breaker, ay ay ay, during a working day), or write a message on a social network. It is the program’s self-descriptiveness that removes any worries and fears for what is captured on the screen, and yet the most unexpected and unpredictable may be captured :) a joke.

    Perhaps all that I wanted to narrate. The experiment is ongoing, and I'm sure I will be satisfied by the end of the month. It remains to agree with willpower and finish the arms and legs to the body, so that everything works as wah as convenient. The moral of the story is that 10 minutes and knowledge can solve big problems.

    In order to give the article usefulness, I will leave links to those solutions that I was advised to solve problems like mine. I do not answer for the adequacy of the programs, because I did not even download them to watch.

    www.debugmode.com/wink
    taskwarrior.org/projects/show/taskwarrior

    Also popular now: