Category Archives: Software

Posts about software engineering, both approaches and specific packages to solve common problems.

Naos.Packaging.NuGet – Wrapper to easily download packages from NuGet

Summary

NuGet is just plain hard to work with.  I know you shouldn’t throw stones in glass houses and all that.  I’m sure many people think my contributions to Naos are terribly written code.  All that said, I personally think the entire NuGet stack is terribly written code.  Its got far too many layers, zero to terrible documentation, hard to read, hard to follow, counter-intuitive, etc.  Since I needed to be able to simply download packages for use in the Naos.Deployment work I created this library to hide and document all the scariness necessary to download packages from either a private repository or the public one using .NET.

Project

Naos is an opensource project dedicated to providing infrastructure tools for free to aid in small companies having solid platforms to launch on, learn more at http://naosproject.com.

Source

The entire project is open sourced under the MIT license and available at: https://github.com/NaosFramework/Naos.Packaging

Referencing

It’s best to reference the NuGet package: http://www.nuget.org/packages/Naos.Packaging.NuGet which will provide a more feature rich interaction with packages…

The specific NuGet operations using the prototcol are included in a single file which can be copied into your project without a Naos depedency in your project (will still REQUIRE package NuGet.PackageManagement):https://raw.githubusercontent.com/NaosProject/Naos.Packaging/master/Naos.Packaging.NuGet/NuGetPackageManager.cs.

Use

Below is an example of usage in C#.

// this is how you would use the full retriever
[Fact(Skip = "Meant for local debugging and to show usage.")]
public void DownloadPrivate()
{
        var repoConfig = new PackageRepositoryConfiguration
                            {
                                Source = "https://ci.appveyor.com/nuget/XXX",
                                ClearTextPassword = "ThisIsPassword",
                                Username = "ThisIsUser",
                                SourceName = "ThisIsGalleryName",
                                ProtocolVersion = 2,
                            };

    var defaultWorkingDirectory = @"D:\Temp\NewNuGet";
    var pm = new PackageRetriever(repoConfig, defaultWorkingDirectory);
    var bundleAllDependencies = false;
    var package = pm.GetPackage(new PackageDescription { Id = "ThisIsPackage" }, bundleAllDependencies);
    Assert.NotNull(package.PackageFileBytes);
}

[Fact(Skip = "Meant for local debugging and to show usage.")]
public void DownloadPublic()
{
    var defaultWorkingDirectory = @"D:\Temp\NewNuGet";
    var pm = new PackageRetriever(defaultWorkingDirectory);
    var bundleAllDependencies = false;
    var package = pm.GetPackage(new PackageDescription { Id = "Newtonsoft.Json" }, bundleAllDependencies);
    Assert.NotNull(package.PackageFileBytes);
}

// this is how you would use the NuGet only file
[Fact(Skip = "Meant for local debugging and to show usage.")]
public void DownloadPrivate()
{
    var defaultWorkingDirectory = @"D:\Temp\NewNuGet";
    var downloadDirectory = Path.Combine(defaultWorkingDirectory, Guid.NewGuid() + ".tmp");

    var pm = new NuGetPackageManager(2, "ThisIsGalleryName", "https://ci.appveyor.com/nuget/XXX", "ThisIsUser", "ThisIsPassword");

    var includeUnlisted = true;
    var includePreRelease = true;
    var latestVersionTask = pm.GetLatestVersionAsync("ThisIsPackageId", includeUnlisted, includePreRelease);
    latestVersionTask.Wait();
    var version = latestVersionTask.Result;

    var includeDependencies = true;

    pm.DownloadPackageToPathAsync(
        "ThisIsPackageid",
        version,
        downloadDirectory,
        includeDependencies,
        includeUnlisted,
        includePreRelease).Wait();
}

[Fact]
public void DownloadPublic()
{
    var defaultWorkingDirectory = @"D:\Temp\NewNuGet";
    var downloadDirectory = Path.Combine(defaultWorkingDirectory, Guid.NewGuid() + ".tmp");

    var pm = new NuGetPackageManager();

    var includeUnlisted = true;
    var includePreRelease = true;
    var latestVersionTask = pm.GetLatestVersionAsync("Newtonsoft.Json", includeUnlisted, includePreRelease);
    latestVersionTask.Wait();
    var version = latestVersionTask.Result;

    var includeDependencies = true;

    pm.DownloadPackageToPathAsync(
        "Newtonsoft.Json",
        version,
        downloadDirectory,
        includeDependencies,
        includeUnlisted,
        includePreRelease).Wait();
}

How to start a business – easy steps to get off the ground quickly!

TrendLineUpBarGraph

Introduction

Many people have books/posts/etc. on this topic.  This is my $0.02 on things people often overlook or do incorrectly when trying to start a business.  That said, lets get going…

The Idea

First, you need to figure out the idea.  Are you creating a service or a product?  The idea can simply be great content with advertising.

Focus on the Business

Jump in to the business NOT what you do for a living – as a developer I want to jump into coding but really developers are problem solvers first and wizards that can talk to computers second…  Make sure you’re focus is on growing your business and not doing a hobby where no one tells you what to do.

Branding

Get a name

Don’t shirk this step as it’s an important step because branding matters whether we like it or not.  Think about the tone you’re conveying about your business.  This is your first impression with a prospective customer so make it count.

Get a logo

This is almost as important as the name.  This communicates tons of information about your company and the investment in it.  Mainly you want to look professional, anyone can spot a lame “I did this in MsPaint” logo.  There are many cheap ways to get a very professional logo online.  I recommend Suki at Adaptive Logo Design as he is very inexpensive ($60/logo at time of writing), easy to work with, and very creative.  He has a YouTube video here introducing himself.

Web Presence

Get a website

Don’t spend $3K on a site name for an unproven business, get a cheap enough one and remember that if you’re wildly successful you’ll just pay someone to go get the nice one and move everything over.

Get common, easy to use hosting

Don’t run it from your basement to save money.  Also don’t use some experimental or niche thing.  This is written on WordPress, and no I don’t like PHP either.  I chose it because it’s ubiquitous so solutions are easily found and user interface is pretty nice as it’s been refined several times.

Get Google Analytics

This is free and will let you see how your doing but also can be a great bargaining tool to show your traffic for businesses that might try to attract donations of products in exchange for reviews, etc.  Sometimes investors use this to assess value, it’s easy up front so you should just do it…

Get real email

If you email clients directly (which who doesn’t nowadays), don’t use your personal email and have it saved by everyone to bother you later.  Setup a real email address against your domain early because it will save you time later.  I use Google Apps for Business and pay for users.  Remember though that really only need to pay for your “real users”!  Things like “support@”, “sales@”, etc. can be done using Groups which are free for as many as you like and just put yourself as the single member of all of them.  This makes it easy to scale in the future if you hire people and need to delegate sections of the business, keeps you organized, and looks far more professional to the outside world.

Get a LinkedIn page

Create a LinkedIn Company page and fill out some information (and use your newly created logo so you can get that branding on your personal LinkedIn page).  Then list yourself as a founder/CEO/whatever on your LinkedIn page, this is easy and free advertising for your business and will possibly attract investors…

Get some social media

If you’re young and/or in a high touch market you should probably create a Facebook/G+/Twitter account(s) because people should find it really easy to trip over your business on the internet.  If you’re in a super high touch line of business then you should probably have a YouTube video introducing yourself because it will make people feel very uncomfortable outsourcing.  These things are free and can only help funnel business to you so there is really no excuse.

Get some advertising

Sure you “never” click on those ads at the side but many years in internet advertising taught me that millions of people do.  It can’t hurt to run a standard AdWords campaign and see if it helps, if it doesn’t then throw it away.  This is easy to figure out because you’re already using Google Analytics…  There are exceptions if you run some niche thing that the presence of any advertising out on the internet would actually alienate your potential customers but this rare, most of the time people are afraid it won’t help or just simply too cheap to invest in it.  People have to know about you and hitting all the angles is good, for example social media is just advertising that you’re out doing yourself.

Paper Presence

Get business cards

This is often overlooked in the world of the ubiquitous smart phone.  Smart phones are great and allow for quickly adding someone to LinkedIn and verifying that you’re getting the correct person with the sub-par search they offer.  Aside from being one more place to use your logo; business cards work when your battery is dead and when you’re without signal.  You don’t have to worry about bringing them in your pocket when you head to the beach and left your phone in the car.  It also helps avoid that awkward moment when you meet someone who hands you their card and you’re without one to hand back.  I use moo.com and love their product and the easy to use site but there are several out there and they are all probably fine…

Paperwork

Get the corporate side in order

Don’t start with some friends and assume that when there is a ton of money you’ll just figure out how to split it up correctly (this sadly ends many relationships in general…).  Go get a proper LLC (or S-corp) and become really good at setting them up and keeping organized.  I use a registered agent service (specifically BizFilings) but you can use yourself or someone you trust.  This will cost a little bit of money but if you don’t have a few hundred dollars to try to start a business then you’re not in a position to start a business and need to save up capital or seek an investor.  Make sure there is a contract with the founders that explicitly maps out how earnings from the company are to be shared and how decisions are made (especially tie breakers).  This is easily done, can be gotten online for free and will save a ton head and heart ache in the future.  If you know a lawyer locally they can usually draft this up for not a lot of money also.

Get you books in order

This is something that took me a long time to figure out…  I now keep everything separate and it’s much nicer.  If you’re spending money then get a business checking account and credit card.  This is easily done at your local bank and they will usually waive any fees if you’re already a personal account holder.  This will allow you to keep easy track of your expenses.  You can also plug this stuff into Wave, FreshBooks, Mint, etc. to get things ready for tax time.  I personally don’t care for Intuit so I use Wave because they are free and have been happy with them so far.

Get an accountant

Unless you really like to do taxes for some strange reason (in which case you should probably be an accountant) or have a close relative that is doing this for you then this is a no-brainer.  They will pay for themselves in savings of doing things incorrectly and will make it easy to start and end companies frequently which will promote failing fast and not waiting too long on the good ideas.

Get time tracking, expensing, and invoicing software

If you’re invoicing clients, don’t just keep invoices in Excel or hand write emails.  This will just create headaches for you later because; it’s difficult to keep track of, impossible to run analytics on, and just looks amateur.  Use some software that easily tracks hours against projects and makes nice invoices.  If you’re having to log expenses then find a good program for that too, this is best done by just having a business credit card but for some lines of business it’s unavoidable.  Whatever you use should be easy to interact with on your cell phone AND be backed up somewhere besides your cell phone.  You will inevitably need to update stuff on the go but also want to be safe if you fall in the fountain on the way home from a meeting.  I use Harvest which costs some money but has a nice clean interface and provides any feature I care about.  If you expense a LOT you may want to go ahead and get an Expensify account also but that’s only for certain lines of business in my opinion.

Final Thoughts

I’m not going to sugar coat this at all, this stuff takes a lot of time to get going, it’s not hard work but it is work (nothing is totally free in life).  The maintenance is actually pretty easy but getting going is hard so start early while you have a day job to afford you the time to do it.  I’ve heard the great analogy that it’s like there are dollar bills stuck to the ground everywhere BUT you gotta spend the time to go scrape them up…  It’s not that it’s easy, it’s just worth it in my opinion.

Don’t be afraid and be a pro at this stuff because the lower the viscosity for getting going correctly the more likely you’ll get out there and be successful!

Naos.FluentUri – Fluent interface for calling RESTful web services

Summary

Microsoft sort of recommends the HttpClient but I really just don’t like the interface on it.  I wanted something that sat on top of the .NET Uri object without having to new up anything else.  I also really like the fluent interface for work like this because its easy to see where the components came from rather than using format strings.  Naos.FluentUri was created to simply clean up the way I called RESTful services from .NET.

Project

Naos is an opensource project dedicated to providing infrastructure tools for free to aid in small companies having solid platforms to launch on, learn more at http://naosproject.com.

Source

The entire project is open sourced under the MIT license and available at: https://github.com/NaosFramework/Naos.FluentUri

Referencing

The entire implemenation is in a single file so it can be included without taking a dependency on the NuGet package if necessary preferred.

Use – Building up the URL

 

  • Adding segments to the URL
    • To get http://baseUrlOfService/subPath use new Uri("http://baseUrlOfService").AppendPathSegment("subPath");
    • Trailing slashes are handled… http://baseUrlOfService/subPath can also be done using new Uri("http://baseUrlOfService/").AppendPathSegment("subPath");
  • Adding query string parameters
    • To get http://url?myParam=aValue use new Uri(http://url).AppendQueryStringParam("myParam", "aValue");
    • Can also be done in batches by using .AppendQueryStringParams(/* IDictionary<string, string> */); or .AppendQueryStringParams(/* ICollection<KeyValuePair<string, string>> */);
    • Will work correctly out of order too… http://url/path?q=hello can be done using new Uri("http://url").AppendQueryStringParam("q", "hello").AppendPathSegment("path"); although this is not really recommended as it doesn’t read great…

Use – Calling the URL

 

 

  • Void Return vs. Typed Return
    • Void Return Usage:
      • new Uri("http://api/Objects/42/Setting").Put();
    • Typed Return Usage:
      • MyObject returnedData = net Uri("http://api/Objects/42").Get<MyObject>();
  • The four main verbs are currently supported as first class methods as well as a method to pass any verb as a string.
    • GET – new Uri("http://api/Objects/42").Get();
    • POST – new Uri("http://api/Objects/").Post();
    • PUT – new Uri("http://api/Objects/42/Setting").Put();
    • DELETE – new Uri("http://api/Objects/42").Delete();
    • “Custom Verb” – new Uri("http://api/Objects/42").CallWithVerb("Custom Verb");
  • There are additional decorators for the call for standard operations.
    • Add a body to the request:
      • new Uri("http://api/Objects/").WithBody(new MyObject()).Post();
    • Add a cookie to the request:
      • // Cookie can also be of type HttpCookie...
      • var cookie = new Cookie(".ASPXAUTH", "[AuthCookieValue]") { Expires = DateTime.Now.AddDays(30) };
      • var obj = new Uri("http://api/Objects/42").WithCookie(cookie).Get<MyObject>();
    • Add headers to the request:
      • // Headers can also be of type WebHeaderCollection or NameValueCollection..
      • var headers = new[] { new KeyValuePair<string, string>("Auth-Token", "[AuthTokenValue]") };
      • var obj = new Uri("http://api/Objects/42").WithHeaders(headers).Get<MyObject>();
    • Update the timeout of the request:
      • var obj = new Uri("http://api/Objects/42").WithTimeout(TimeSpan.FromHours(1)).Get<MyObject>();
    • Save response headers using a lambda:
      • KeyValuePair<string, string>[] responseHeadersFromCall;
      • new Uri("http://api/Auth/Login").WithResponseHeaderSaveAction(responseHeaders => responseHeadersFromCall = responseHeaders).Post();

Use – Combined

C# Example of making and authentication call.

var loginResponse = new Uri("http://auth.services.com")
                                     .AppendPathSegment("login")
                                     .WithBody(loginRequest)
                                     .Post();

 

C# Example of updating a users’ zip code.

new Uri("http://user.services.com")
            .AppendPathSegment("user")
            .AppendPathSegment(user.Id)
            .AppendPathSegment("zipCode")
            .AppendPathSegment(user.ZipCode)
            .WithCookie(authCookieToAllowThis)
            .Put();

 

Naos.WinRM – Windows Remote Management and file sending via .NET

Summary

This is a standard problem space that Microsoft, for whatever reason, has chosen not to solve.  The two problems are 1) you can’t run remote commands on a windows computer from .NET code 2) you can’t send or receive a file via the WinRM Protocol.  I wrote Naos.WinRM to solve both of these.

Project

Naos is an opensource project dedicated to providing infrastructure tools for free to aid in small companies having solid platforms to launch on, learn more at http://naosproject.com.

Source

The entire project is open sourced under the MIT license and available at: https://github.com/NaosFramework/Naos.WinRM

Referencing

The entire implemenation is in a single file so it can be included without taking a dependency on the NuGet package if that is necessary or preferred.

Use

Below is an example of usage in C#.

// this is the entrypoint to interact with the system (interfaced for testing).
var machineManager = new MachineManager(
    "10.0.0.1",
    "Administrator",
    MachineManager.ConvertStringToSecureString("xxx"),
    true);

// will perform a user initiated reboot.
machineManager.Reboot();

// can run random script blocks WITH parameters.
var fileObjects = machineManager.RunScript("{ param($path) ls $path }", new[] { @"C:\PathToList" });

// can transfer files to AND from the remote server (over WinRM's protocol!).
var localFilePath = @"D:\Temp\BigFileLocal.nupkg";
var fileBytes = File.ReadAllBytes(localFilePath);
var remoteFilePath = @"D:\Temp\BigFileRemote.nupkg";

machineManager.SendFile(remoteFilePath, fileBytes);
var downloadedBytes = machineManager.RetrieveFile(remoteFilePath);