Skip to content

Instantly share code, notes, and snippets.

@fnbk
Created September 2, 2022 21:22
Show Gist options
  • Save fnbk/2ea9b6253c11005fb88be10985c25719 to your computer and use it in GitHub Desktop.
Save fnbk/2ea9b6253c11005fb88be10985c25719 to your computer and use it in GitHub Desktop.
branching: local-functions
private Job CreateJob(order order)
{
var job = ValidateComputer(order.ComputerName, onSuccess, onFailure);
return job;
Job onSuccess(Order order)
{
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);
return new Job()
{
ActivationTime = order.ClientLocalStartTime,
ComputerName = order.ComputerName,
orderId = order.Id,
JobActions = CreateJobActions(deploymentType, order, siteServerAddress, computer),
Status = "created",
}
}
Job onFailure(Order order)
{
return new Job()
{
ActivationTime = order.ClientLocalStartTime,
ComputerName = order.ComputerName,
orderId = order.Id,
Status = invalidComputerErrorMessage,
};
}
}
private Job ValidateComputer(Order order, Func<Order, Job> onSuccess, Func<Order, Job> onFailure);
{
bool valid = !String.IsNullOrEmpty(order.ComputerName);
if (valid)
{
return onSuccess(order);
}
return onFailure(order);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment