A 25-year-old man has been jailed for nine years for a series of offences committed in Midlothian.