Skip to content

Instantly share code, notes, and snippets.

@fnbk
Created September 2, 2022 21:20
Show Gist options
  • Save fnbk/c4c6ca17536933109caa64a858e6e95d to your computer and use it in GitHub Desktop.
Save fnbk/c4c6ca17536933109caa64a858e6e95d to your computer and use it in GitHub Desktop.
branching: try-catch
private async Task<Job> CreateJob(order order)
{
Job job = new Job()
{
ActivationTime = order.ClientLocalStartTime,
ComputerName = order.ComputerName,
orderId = order.Id,
};
try // happy path
{
EnsureComputerIsValid(order.ComputerName);
var computer = GetComputer(order.ComputerName, order.CustomerId);
computer.CustomerId = GetCustomerId(order.CustomerId, computer.CustomerId);
var siteServerAddress = GetServerAddress(order.ComputerName, computer.CustomerId);
var deploymentType = GetDeploymentType(order.MaterialNumber, computer.CustomerId);
job.JobActions = CreateJobActions(deploymentType, order, siteServerAddress, computer);
job.Status = "created";
}
catch (ComputerNotValid ex) // bad path
{
job.Status = "Failed, computer invalid";
}
catch (ComputerNotFound ex) // bad path
{
job.Status = "Failed, computer not found";
}
catch (NoSiteServerAddress ex) // bad path
{
job.Status = "Failed, computer has no site server address";
}
return job;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment