Automated Contingency Handling Framework for Factories of the Future