I have written a successful business application used by 100+ clients, which had the initial requirements:
- Copy some files in already defined xml file stored somewhere on the clients machine from a non-mapped windows share into a fixed installation path on the user clients machine
- The application must be able to do this without admin user privileges, so the operative code must be executed by a WCF service which has proper rights.
- The user can trigger this operation from a normal desktop application without needing any administrative privileges whatsoever.
- It must be rock solid and must be able to update itself
Thats the requriment, now to we get to the actual implementation:
I created a c# console application with one class and the main() entry point only - containing all code to satisfy the base requirements without any others methods or classes. When i run that application with admin rights it worked beutifully. Of course when i run it without admin rights it crashed at that point when it wanted to write/create something in "C:\Program files" which was the targets base directory.
Now i moved out all actual file and directory operation code into its own static methods and made sure that it still works and does not depend on anything. Then i created a interface "IAdminFileOperations" containing all that method signatures. After that i created a class which implements the interface and containing all the code i had already. Of course i changed all the code to use the new interface and the implementation class instead and tested it by a unit-test class.
Now i had to get it working without admin privileges, called by that console application - which was a pain in the ass.
So i created two additional projects: One WCF windows service, one class library. I moved the interface into the class library and moved the implementation class into the windows service. A few days later i got it working doing exactly what i wanted. Why tooked it so long? Well... WCF (Windows Communication Framework) just sucks and is one of the worst network framework thingy i ever have worked with. But well it was a required, so i got it working and was happy...
Got it more features than i had before? No i just abstracted the IO operations to the service and thats it - with a few more required classes and interfaces... just because WCF... *sigh*
I personally had used a simple TCP network server/client approach, but it was a requirement from the management so i had no choice :-(
Long story short:
Now the console application is a full blown WPF GUI Application powered by DevExpress requiring millions of dll´s... with UI, progress bar, labels, buttons, whatsoever. Just doing the same thing as before: Copying files from A to B...
Of course the initial features was expanded in great detail and now its about 50 k lines of code with tons of classes. Now it supports FTP, SFTP and Share´s as Source and Target as well - including impersonation if needed, but only abstracted with one interface and one class for each system. Just one layer more than i had before.
But the actual code which loops over the source files and triggers the actual operations is still the same as it was before: One gigantic method (>100 lines of code) - just because it worked beutifully and their was no need to change or abstract that. If there isn´t a need, dont abstract it.
And yes most of it is unit-tested, but the WCF part is not...
Could i have planned it? Partly yes, but the planning in this case would be useless just because the initial requirements was changed so much and often that it had never matched the planning at all... Also i had no idea about WCF and had to learn it. The documentation for that was pretty bad as well...
One major mistake i learned from that:
Dont put any code into a static constructor! When one single exception gets thrown you are screwed and the windows service wont startup.