Created
September 2, 2022 21:20
-
-
Save fnbk/c4c6ca17536933109caa64a858e6e95d to your computer and use it in GitHub Desktop.
branching: try-catch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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