DirecTV is buying Dish and Sling, a deal it has sought to complete for years, as the company seeks to better compete against streaming services that have become dominant.