Thursday, September 13, 2012

ConcatWith Extension Method for IEnumerable

So, I recently contributed some code to the dnpextensions project to allow easily concatenation of the contents of an IEnumerable<T> into a string using a specified separator (which defaults to a comma).  Thought I'd post it here in case anyone might find it useful:

/// <summary>
/// Concatenate a list of items using the provided separator.
/// </summary>
/// <param name="items">An enumerable collection of items to concatenate.</param>
/// <param name="separator">The separator to use for the concatenation (defaults to ",").</param>
/// <param name="formatString">An optional string formatter for the items in the output list.</param>
/// <returns>The enumerable collection of items concatenated into a single string.</returns>
/// <example>
///    <code>
///        List&lt;double&gt; doubles = new List&lt;double&gt;() { 123.4567, 123.4, 123.0, 4, 5 };
///        string concatenated = doubles.ConcatWith(":", "0.00");  // concatenated = 123.46:123.40:123.00:4.00:5.00
///     </code>
/// </example>
public static string ConcatWith<T>(this IEnumerable<T> items, string separator = ",", string formatString = "")
    if (items == null) throw new ArgumentNullException("items");
    if (separator == null) throw new ArgumentNullException("separator");

    // shortcut for string enumerable
    if (typeof(T) == typeof(string))
        return string.Join(separator, ((IEnumerable<string>)items).ToArray());

    if (string.IsNullOrEmpty(formatString))
        formatString = "{0}";
        formatString = string.Format("{{0:{0}}}", formatString);

    return string.Join(separator, items.Select(x => string.Format(formatString, x)).ToArray());

Friday, September 07, 2012

MSFT Fail?

So I decided to install Visual Studio 2012 and SQL Server 2012 today...the SQL Server install went alright, but the VS install hangs at applying Microsoft Web Deploy 3.0 and when I try to post a question about it on the MSDN/Live forums, I get into an infinite redirect loop.  Nice.
Got VS2012 and SQL Server 2012 successfully installed on my home machine and got it all hooked up to CodePlex...might do some more work on the dnpextensions library soon.

Tuesday, September 04, 2012

ARB (A Request Broker)

So, I'm working on an idea for a new project that I will likely host on CodePlex...I'm not sure how useful it will be general, but mostly it's an excuse to mess around with various .NET technologies and figure out how to do a bunch of potentially useful things, using C# 5.0 and the .NET Framework 4.5.

The idea is something like a Request Broker, but with some additional functionality, such as:

  • Hosting 3rd-party add-ins, which will most likely run as their own applications (a discussion of the reasoning behind this to come eventually)
  • Serving up a unified method of communication for external processes to call methods in the add-ins, and otherwise communication with them (as well as for the add-ins to communicate with each other)
  • Running/monitoring arbitrary external processes, with the ability to monitor (and notify about)...
    • Database connectivity
    • File system availability
    • Network availability
    • Memory usage
    • etc.
  • Running in tandem on multiple servers, and successfully negotiating operations
  • Load balancing tasks between multiple servers
  • Gracefully handling clustered environments, such as NLB/ACE, and a methodology to easily extend to other methods of clustering
  • Provide a tiered caching mechanism for 3rd-party add-ins
  • Task scheduling
  • etc.?
I'm thinking it would be great to implement this in such a way that it can be run as a Windows service, or as a "normal" executable.

Things to hash out before proceeding:

  • Where will we store persistent information (database, file, configurable?)
  • How will our processes communicate with each other (.NET Remoting, WCF, other?)
  • How will we handle database access, and what databases can/will we support?
  • How will we handle logging?
  • What will the 3rd party add-ins look like?


So, I've now posted my dozen-th Errata on C# 5.0 in a Nutshell...feels like they should be paying me as an editor...