public static ReshapeResult TryReshape( [NotNull] ReshapeGrpc.ReshapeGrpcClient rpcClient, [NotNull] IList <Feature> selectedFeatures, [NotNull] Polyline reshapeLine, [CanBeNull] IList <Feature> adjacentFeatures, bool allowOpenJawReshape, bool multiReshapeAsUnion, bool tryReshapeNonDefault, CancellationToken cancellationToken) { var allInputFeatures = new Dictionary <GdbObjectReference, Feature>(); AddInputFeatures(selectedFeatures, allInputFeatures); var request = CreateReshapeRequest( selectedFeatures, reshapeLine, adjacentFeatures, allowOpenJawReshape, multiReshapeAsUnion, tryReshapeNonDefault); request.AllowOpenJawReshape = true; // TODO: If the server is overwhelmed by requests, the calls block (and cannot even be cancelled) // Add a task scheduler mode that throws if no free thread is available immediately const int deadline = 2000; AdvancedReshapeResponse reshapeResultMsg = RpcCallUtils.Try( o => rpcClient.AdvancedReshape(request, o), cancellationToken, deadline, true); if (reshapeResultMsg == null) { return(null); } var result = new ReshapeResult { OpenJawReshapeHappened = reshapeResultMsg.OpenJawReshapeHappened, OpenJawIntersectionCount = reshapeResultMsg.OpenJawIntersectionCount, FailureMessage = reshapeResultMsg.WarningMessage }; if (reshapeResultMsg.ResultFeatures.Count == 0) { return(result); } foreach (ResultObjectMsg resultFeatureMsg in reshapeResultMsg.ResultFeatures) { GdbObjectReference objRef = new GdbObjectReference( resultFeatureMsg.Update.ClassHandle, resultFeatureMsg.Update.ObjectId); Feature inputFeature = allInputFeatures[objRef]; var reshapeResultFeature = new ResultFeature(inputFeature, resultFeatureMsg); result.ResultFeatures.Add(reshapeResultFeature); } return(result); }
public void RunGherkinBasedTests(IMessageSerializer messageSerializer) { WriteOutput($"Starting Gherkin-based tests with serializer: {messageSerializer.GetType().Name}"); Gremlin.InstantiateTranslationsForTestRun(); var stepDefinitionTypes = GetStepDefinitionTypes(); var results = new List <ResultFeature>(); using var scenarioData = new ScenarioData(messageSerializer); CommonSteps.ScenarioData = scenarioData; foreach (var feature in GetFeatures()) { var resultFeature = new ResultFeature(feature); results.Add(resultFeature); foreach (var child in feature.Children) { var scenario = (Scenario)child; var failedSteps = new Dictionary <Step, Exception>(); resultFeature.Scenarios[scenario] = failedSteps; if (IgnoredScenarios.TryGetValue(scenario.Name, out var reason)) { failedSteps.Add(scenario.Steps.First(), new IgnoreException(reason)); continue; } StepBlock? currentStep = null; StepDefinition stepDefinition = null; foreach (var step in scenario.Steps) { var previousStep = currentStep; currentStep = GetStepBlock(currentStep, step.Keyword); if (currentStep == StepBlock.Given && previousStep != StepBlock.Given) { stepDefinition = GetStepDefinitionInstance(stepDefinitionTypes, step.Text); } if (stepDefinition == null) { throw new NotSupportedException( $"Step '{step.Text} not supported without a 'Given' step first"); } scenarioData.CurrentScenario = scenario; var result = ExecuteStep(stepDefinition, currentStep.Value, step); if (result != null) { failedSteps.Add(step, result); // Stop processing scenario break; } } } } OutputResults(results); WriteOutput($"Finished Gherkin-based tests with serializer: {messageSerializer.GetType().Name}."); }
public void RunGherkinBasedTests() { WriteOutput("Starting Gherkin-based tests"); var stepDefinitionTypes = GetStepDefinitionTypes(); var results = new List <ResultFeature>(); foreach (var feature in GetFeatures()) { var resultFeature = new ResultFeature(feature); results.Add(resultFeature); foreach (var scenario in feature.Children) { var failedSteps = new Dictionary <Step, Exception>(); resultFeature.Scenarios[scenario] = failedSteps; if (IgnoredScenarios.TryGetValue(scenario.Name, out var reason)) { failedSteps.Add(scenario.Steps.First(), new IgnoreException(reason)); continue; } StepBlock? currentStep = null; StepDefinition stepDefinition = null; foreach (var step in scenario.Steps) { var previousStep = currentStep; currentStep = GetStepBlock(currentStep, step.Keyword); if (currentStep == StepBlock.Given && previousStep != StepBlock.Given) { stepDefinition?.Dispose(); stepDefinition = GetStepDefinitionInstance(stepDefinitionTypes, step.Text); } if (stepDefinition == null) { throw new NotSupportedException( $"Step '{step.Text} not supported without a 'Given' step first"); } ScenarioData.CurrentScenario = scenario; var result = ExecuteStep(stepDefinition, currentStep.Value, step); if (result != null) { failedSteps.Add(step, result); // Stop processing scenario break; } } } } OutputResults(results); WriteOutput("Finished Gherkin-based tests"); ScenarioData.Shutdown(); }
private static ReshapeResult Reshape( [NotNull] ReshapeGrpc.ReshapeGrpcClient rpcClient, [NotNull] AdvancedReshapeRequest request, [NotNull] IReadOnlyDictionary <GdbObjectReference, Feature> allInputFeatures, CancellationToken cancellationToken) { request.AllowOpenJawReshape = true; const int deadlinePerFeature = 5000; AdvancedReshapeResponse reshapeResultMsg = RpcCallUtils.Try( o => rpcClient.AdvancedReshape(request, o), cancellationToken, deadlinePerFeature * request.Features.Count); if (reshapeResultMsg == null) { return(null); } var result = new ReshapeResult { OpenJawReshapeHappened = reshapeResultMsg.OpenJawReshapeHappened, OpenJawIntersectionCount = reshapeResultMsg.OpenJawIntersectionCount, FailureMessage = reshapeResultMsg.WarningMessage }; if (reshapeResultMsg.ResultFeatures.Count == 0) { return(result); } foreach (ResultObjectMsg resultFeatureMsg in reshapeResultMsg.ResultFeatures) { GdbObjectReference objRef = new GdbObjectReference( resultFeatureMsg.Update.ClassHandle, resultFeatureMsg.Update.ObjectId); Feature inputFeature = allInputFeatures[objRef]; var reshapeResultFeature = new ResultFeature(inputFeature, resultFeatureMsg); result.ResultFeatures.Add(reshapeResultFeature); } return(result); }
public static bool CanChange([NotNull] ResultFeature resultFeature, [NotNull] HashSet <long> editableClassHandles, params RowChangeType[] allowedChangeType) { if (allowedChangeType.All(t => t != resultFeature.ChangeType)) { return(false); } Feature feature = resultFeature.Feature; bool result = CanChange(feature, editableClassHandles, out string warning); if (!string.IsNullOrEmpty(warning)) { resultFeature.Messages.Add(warning); resultFeature.HasWarningMessage = true; } return(result); }
public static List <ResultFeature> ApplyCutCurves( [NotNull] ChangeAlongGrpc.ChangeAlongGrpcClient rpcClient, [NotNull] IList <Feature> sourceFeatures, [NotNull] IList <Feature> targetFeatures, [NotNull] IList <CutSubcurve> selectedSubcurves, CancellationToken cancellationToken, out ChangeAlongCurves newChangeAlongCurves) { Dictionary <GdbObjectReference, Feature> featuresByObjRef = CreateFeatureDictionary(sourceFeatures, targetFeatures); ApplyCutLinesRequest request = CreateApplyCutCurvesRequest(sourceFeatures, targetFeatures, selectedSubcurves); ApplyCutLinesResponse response = rpcClient.ApplyCutLines(request, null, null, cancellationToken); List <ResultObjectMsg> responseResultFeatures = response.ResultFeatures.ToList(); var resultFeatures = new List <ResultFeature>(); foreach (ResultObjectMsg resultObjectMsg in responseResultFeatures) { GdbObjectReference originalFeatureRef = GetOriginalGdbObjectReference(resultObjectMsg); Feature originalFeature = featuresByObjRef[originalFeatureRef]; ResultFeature resultFeature = new ResultFeature( originalFeature, resultObjectMsg); resultFeatures.Add(resultFeature); } newChangeAlongCurves = PopulateReshapeAlongCurves( sourceFeatures, targetFeatures, response.NewCutLines, (ReshapeAlongCurveUsability)response.CutLinesUsability); return(resultFeatures); }