Geometries and Properties of Excited states in the Gas Phase and in Solution. Theory and Application of a Time-Dependent DFT Polarizable Continuum Model