Seamless Transition of a Microgrid Between Grid-Connected and Islanded Mode