4Jun/103

Zocor Alternative Viagra

Zocor alternative viagra This week I ran into wanting to use C# 4.0 optional parameters, zocor alternative viagra but wanted StructureMap (my IoC tool of choice) to respect the default value specified for those optional parameters.

The Problem

Zocor alternative viagra In this example, zocor alternative viagra we’ll be pulling a command out of the container.  The important part is the optional constructor parameter (level), zocor alternative viagra and it’s default value (Level.Info).

public class LogCommand

{

    IDestination _destination;

    Level _level;

 

    public LogCommand(

        IDestination destination, zocor alternative viagra Level level = Level.Info)

    {

        _destination = destination;

        _level = level;

    }

 

    /* logging code here */

}

 

Zocor alternative viagra Here is your basic usage, zocor alternative viagra but doesn’t work since StructureMap doesn’t know how to take advantage of the optional parameters with default values.

var container = new Container(config =>

{

    config.Scan(scanner =>

    {

        scanner.TheCallingAssembly();

        scanner.AddAllTypesOf<IDestination>();

        scanner.WithDefaultConventions();

    });

});

 

var logCommand = container.GetInstance<LogCommand>();

 

Zocor alternative viagra The last line results in an exception because StructureMap doesn’t know how to fill in the level parameter.

The Solution

Zocor alternative viagra We can solve this by adding a new convention.  One that adds information about default constructor arguments.  Here is the implementation of the convention:

public class DefaultCtorParameterConvention : IRegistrationConvention

{

    public void Process(Type type, zocor alternative viagra Registry registry)

    {

        if(type.IsAbstract || type.IsEnum)

            return;

 

        var ctor = type.GetGreediestCtor();

 

        if(!ctor.HasOptionalParameters())

            return;

 

        var inst = registry.For(type).Use(type);

 

        foreach(var param in ctor.GetOptionalParameters())

            inst.Child(param.Name).Is(param.DefaultValue);

    }

}

Zocor alternative viagra Note: GetGreediestCtor, zocor alternative viagra HasOptionalParameters, zocor alternative viagra and GetOptionalParameters are extension methods.  We’ll see their implementation shortly.

Zocor alternative viagra The convention inherits from the IRegistrationConvention, zocor alternative viagra which is how you implement new conventions in StructureMap.  It has only one method: Process.  We filter out types that are abstract, zocor alternative viagra are enums, zocor alternative viagra or have constructors that don’t have optional parameters.  Once we realize we have a constructor we want to deal with, zocor alternative viagra we use the Child method, zocor alternative viagra that sets either a property or a constructor argument (for our case, zocor alternative viagra it’ll always be a constructor argument), zocor alternative viagra and then we set it’s value to the parameter’s default value, zocor alternative viagra as provided by the ParameterInfo object, zocor alternative viagra for each optional parameter.

Minor Details

Zocor alternative viagra Curious about the implementation of GetGreediestCtor or the *OptionalParameters methods?  If not, zocor alternative viagra skip this section.

public static bool HasOptionalParameters(

    this ConstructorInfo ctor)

{

    return ctor.GetOptionalParameters().Any();

}

 

public static IEnumerable<ParameterInfo> GetOptionalParameters(this ConstructorInfo ctor)

{

    return ctor.GetParameters().Where(

        param => param.Attributes

            .HasFlag(ParameterAttributes.Optional));

}

 

public static ConstructorInfo GetGreediestCtor(

    this Type target)

{

    return target.GetConstructors()

        .WithMax(ctor => ctor.GetParameters().Length);

}

 

public static T WithMax<T>(

    this IEnumerable<T> target, zocor alternative viagra Func<T, zocor alternative viagra int> selector)

{

    int max = -1;

    T currentMax = default(T);

 

    foreach(var item in target)

    {

        var current = selector(item);

        if(current <= max)

            continue;

 

        max = current;

        currentMax = item;

    }

 

    return currentMax;

}

 

Zocor alternative viagra  

The Usage

Zocor alternative viagra Here’s how to use your new convention.

var container = new Container(config =>

{

   config.Scan(scanner =>

   {

       scanner.TheCallingAssembly();

       scanner.AddAllTypesOf<IDestination>();

       scanner.WithDefaultConventions();

       scanner.Convention<DefaultCtorParameterConvention>();

   });

});

 

var logCommand = container.GetInstance<LogCommand>();

 

Zocor alternative viagra Now, zocor alternative viagra when we pull the LogCommand out of the container, zocor alternative viagra the level parameter gets defaulted to Level.Info, zocor alternative viagra just like we specified in the constructor.  Sweet!

Conclusion

Zocor alternative viagra This implementation is somewhat limiting, zocor alternative viagra but the version I have in my github repo is a little more open and configurable.  It allows you to customize the instance key/name you use when registering your type, zocor alternative viagra and also allows you to do additional, zocor alternative viagra non-standard registrations if you need to.

Zocor alternative viagra Also, zocor alternative viagra this doesn’t work if you’ve selected a constructor using the SelectConstructor config API from StructureMap, zocor alternative viagra I’m not sure how to tap into that facility to look for that constructor rather than the greediest.

Zocor alternative viagra Am I missing something?  Did something not make sense?  Leave me a note!

Average Rating: 4.8 out of 5 based on 241 user reviews.

11Dec/091

Viagra Next Day

Viagra next day Man, viagra next day I’d searched for this feature time and time again.  And finally found it here: http://www.kevinwilliampang.com/post/Visual-Studio-Split-Views.aspx

Viagra next day If you don’t want to follow the link…

Viagra next day Just double click that guy, viagra next day or drag it downward, viagra next day and you’ve split your file into two buffers.  Awesomeness.

Viagra next day split

Average Rating: 4.4 out of 5 based on 298 user reviews.

18Nov/090

Cialis Price 100 Mg

Cialis price 100 mg In my few days of being a developer, cialis price 100 mg I’ve heard and seen lots of talk about Singletons.  Things like

Cialis price 100 mg Singletons are teh suck.  Don’t use them.  EVAR.

Cialis price 100 mg to

Cialis price 100 mg Singleton’s saved my life and marriage!

Cialis price 100 mg In fact, cialis price 100 mg I might’ve been the person that said both of these… gasp!

Cialis price 100 mg I never like to speak in absolutes, cialis price 100 mg so I’ll say it this way (see what I did there?)… if you’re striving to implement a singleton, cialis price 100 mg you’re probably wrong.  For all you guys that are right, cialis price 100 mg I guess you’re right, cialis price 100 mg and you can leave now, cialis price 100 mg I guess.  This might help you out.

Cialis price 100 mg I was reading a blog from Mr. Cialis price 100 mg Dependency where he was talking about statics and basically what amounts to global state, cialis price 100 mg and how thatultimate-geeks-multi-tool-hammer binds you into globally available, cialis price 100 mg global data, cialis price 100 mg which usually (always?) turns into anarchy.

Cialis price 100 mg How do we always get ourselves into this mess if we know it’s bad in the first place?  Well, cialis price 100 mg some of us (those who are now zombocomming, cialis price 100 mg from above) don’t know it’s bad in the first place, cialis price 100 mg and the rest of us probably do it because it’s easy to implement, cialis price 100 mg and we understand it.  Long story short, cialis price 100 mg we can do the singleton implementation in our sleep, cialis price 100 mg so we pull out the singleton hammer, cialis price 100 mg and smack the nail.  It always goes in a little sideways, cialis price 100 mg but at least it goes in.

Cialis price 100 mg Maybe we should be using a different hammer?

Cialis price 100 mg What I’d like to do now, cialis price 100 mg is propose to split singleton in two.  I think there are two distinct responsibilities that the current thought of ‘singleton’ introduces. Cialis price 100 mg It:

  • Manages Session Scoping/Lifecycle/Lifestyle (albeit, cialis price 100 mg poorly, cialis price 100 mg only one strategy is available)
  • Disables the ability to create more

Cialis price 100 mg When I talk about this out loud, cialis price 100 mg I call the two approaches the singleton implementation pattern, cialis price 100 mg and singleton lifecycle.

Cialis price 100 mg What I am a fan of, cialis price 100 mg is the singleton lifecycle.  You create one of those objects, cialis price 100 mg and use it throughout the application.  You don’t get messy and allow global access to it all over the place (which necessarily happens when you have global state).  You intentionally inject it to collaborators, cialis price 100 mg and  intentionally don’t inject it to non-collaborators (don’t just hand this guy out willy-nilly, cialis price 100 mg he’s important).

Cialis price 100 mg So naturally, cialis price 100 mg the naysayers ask/demand:

Cialis price 100 mg How do you manage that there is a public constructor on this class!?  Dev’s are going to be new’ing this thing up all over the place!

Cialis price 100 mg I say:

Cialis price 100 mg False.  Use a DI tool and let it manage it for you.  Or establish a convention with your team, cialis price 100 mg and enforce it through social contracts. Cialis price 100 mg

Cialis price 100 mg Both of these approaches allow your scope lifecycle turn into whatever you want at any time, cialis price 100 mg in case you decide global isn’t what you really want.  It can be application session scoped, cialis price 100 mg or some other scope, cialis price 100 mg test scoped, cialis price 100 mg or whatever you want… incredibly flexible.

Cialis price 100 mg If you go with the DI tool approach, cialis price 100 mg instead of tying yourself to a particular scope, cialis price 100 mg you can now have any scope you want, cialis price 100 mg by changing a configuration parameter.  Delaying decisions until the latest responsible moment… seems like I’ve heard that one before.

Average Rating: 4.6 out of 5 based on 193 user reviews.

23Sep/091

Viagra Generic

Viagra generic The first time I saw autotest (presented by Anthony), viagra generic the idea of Continuous Testing captured me.

Viagra generic I live in a .NET world most of the time, viagra generic and I know of no similar solution for .NET.  It’s been awhile since that first time, viagra generic and I’ve tinkered here and there trying to get something comparable, viagra generic but usually come up short.  That is until I found watchr.

Viagra generic Watchr gave me the file change detection capabilities I needed, viagra generic and the extensibility to do whatever I want when a file has been detected as changed.  This made it incredibly easy to hook up some autotest goodness in my .NET world.

Viagra generic You'll have to have ruby installed, viagra generic and gems.  Then, viagra generic the very first thing you'll have to do is

Viagra generic gem install watchr --source=http://gemcutter.org

Viagra generic Here is my watchr script:

require 'autotest.rb'

watch( '^.*UnitTest.*.cs$' ) do |match|
  run_test(match.to_s)
end

Viagra generic This is basically just a regex that says to watch any *.cs files that also contain the string “UnitTest”, viagra generic and when it finds a change in a file matching that description, viagra generic call run_test with the matched file name.

Viagra generic So all the magic is in autotest.rb… lets check it out:

require 'rexml/document'

def build(test_project)
  `msbuild /nologo #{test_project}`
end

def mstest(test_container, viagra generic test_results_file, viagra generic tests_to_run)
  tests_to_run = ([""] << tests_to_run).flatten

  File.delete(test_results_file) if File.exists?(test_results_file)
  `mstest /nologo /resultsfile:#{test_results_file} /testcontainer:#{test_container} #{tests_to_run.join(" /test:")}`
  test_results = process_mstest_results(test_results_file)
  File.delete(test_results_file) if File.exists?(test_results_file)

  return test_results
end

def process_mstest_results(results_file)
  results = {}
  File.open(results_file) do |file|
    xml = REXML::Document.new(file)

    results[:num_tests] = xml.get_elements("//UnitTestResult").length
    failures = []
    xml.elements.each("//UnitTestResult[@outcome='Failed']") do |e|
      failure = {}
      failure[:message] = e.elements["Output/ErrorInfo/Message"].get_text

      stack = e.elements["Output/ErrorInfo/StackTrace"].get_text.value
      stack_match = /^.*at (.*) in(.*):line (\d+)$/.match(stack)

      failure[:stack] = stack_match[1] if stack_match
      failure[:location] = stack_match[2] if stack_match
      failure[:line] = stack_match[3] if stack_match

      failure[:stack] = stack if !stack_match

      failures << failure
    end
    results[:failures] = failures
  end

  return results
end

def show_results(results)
  puts "#{results[:num_tests]} tests run (#{results[:failures].length} failures)"
  results[:failures].each do |failure|
      puts "---------------------------------------"
      puts "Message: #{failure[:message]}"
      puts "Location: #{failure[:location]}"
      puts "Line: #{failure[:line]}"
      puts "Stack Trace: #{failure[:stack]}"
  end
end

def run_test(file_name)
  test_container = ""
  test_results_file = "result.trx"
  test_project = ""

  system("cls")
  system("echo Detected change in:")
  system("echo   #{file_name}")
  system("echo Building and Testing")

  test_namespace = ''
  test_class = ''
  test_names = []

  File.open(file_name, viagra generic "r") do |f|
    f.each do |line|
      ns_match = /^namespace (.*)$/.match(line)
      test_namespace = ns_match[1] if ns_match

      class_match = /^\s*public class (.\w*).*$/.match(line)
      test_class = class_match[1] if class_match

      test_name_match = /^\s*public void (\w*).*$/.match(line)
      test_names << test_name_match[1] if test_name_match
    end
  end

  test_names = test_names.map { |n| "#{test_namespace}.#{test_class}.#{n}" }

  build(test_project)
  results = mstest(test_container, viagra generic test_results_file, viagra generic test_names)
  show_results(results)
end

Viagra generic The key parts (I think) are the fact that I’m using MSTest to run my tests (this can easily be modified to run your framework of choice… note MSTest is not my choice ;) ).  The result parsing is also specific to the MSTest output format, viagra generic but should be simple enough for any framework that can output XML. Viagra generic Also, viagra generic I'm making some assumptions based on my project... Viagra generic we've got one unit test project, viagra generic so I know I can run tests in a single DLL, viagra generic and rebuilding only that project, viagra generic I don't have to worry about choosing the correct project and output dll to build and run tests in.

Viagra generic To get the thing up and running, viagra generic just run

Viagra generic watchr <path to watchr script>

Viagra generic Please, viagra generic use/adapt/give feedback/whatever at will.

Viagra generic Go forth and autotest, viagra generic .NET comrades!

Average Rating: 4.7 out of 5 based on 255 user reviews.

30Mar/090

Free Viagra Sample

Free viagra sample I'm in the middle of writing a bunch of XML API documentation for a prototype I just built.  I'm not really a fan of xml doc-comments, free viagra sample which is why I didn't do it in the first place, free viagra sample but the client wants API documentation, free viagra sample so this is definitely the best way to get it.  The two aforementioned tools?

GhostDoc

Free viagra sample GhostDoc basically infers the documentation from the name of the method and its parameter signature.  Absolutely brilliant.  Hook this baby up with a keyboard shortcut, free viagra sample and blam!, free viagra sample it just spits out documentation with a keystroke (which of course is easy to tweak once it's there).  One of the  awesome features is that for implemented methods of an interface, free viagra sample it'll use the exact documentation from the doc-comments from the interface file.  Sweet.

Docu

Free viagra sample Docu is sort of like the NDoc of old.  I know that SandCastle exists, free viagra sample but this is so much simpler.  It uses the Spark view engine/templating system, free viagra sample so that means the output is completely customizable.  Right now it comes with a single template, free viagra sample that is heavily inspired by rdoc rather than something like MSDN style (though I'm certain an MSDN style template will be contributed to the project soon).  The project is really young, free viagra sample but it is used already by FluentNHibernate (and was the reason for its inception, free viagra sample really).  Here is the output for the FluentNH project: FluentNH API Docs.

Free viagra sample Amazazing.

Average Rating: 4.9 out of 5 based on 292 user reviews.