Beispiel #1
0
        public async Task RemovesOpenFile()
        {
            var source1 = @"using System; class Foo { }";
            var source2 = @"class Bar { private Foo foo; }";

            var workspace = await TestHelpers.CreateSimpleWorkspace(new Dictionary <string, string> {
                { "foo.cs", source1 }, { "bar.cs", source2 }
            });

            var document = workspace.GetDocumentId("foo.cs");

            var openController  = new FileOpenService(workspace);
            var closeController = new FileOpenService(workspace);
            var openResponse    = await openController.Handle(new FileOpenRequest
            {
                FileName = "foo.cs"
            });

            Assert.True(workspace.IsDocumentOpen(document));

            var closeResponse = await openController.Handle(new FileOpenRequest
            {
                FileName = "foo.cs"
            });

            Assert.False(workspace.IsDocumentOpen(document));
        }
    public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
    {
        UIApplication uiApp = commandData.Application;
        Document      doc   = uiApp.ActiveUIDocument.Document;
        Application   app   = commandData.Application.Application;

        // internal agreement: abuse KeyValuePair to pass plugin operation state and objects
        KeyValuePair <Result, SpaceSyntax> kvSpaceSyntax = FileOpenService.PromtUserForSpaceSyntaxXml();

        if (kvSpaceSyntax.Key != Result.Succeeded)
        {
            return(kvSpaceSyntax.Key);
        }
        SpaceSyntax spaceSyntax = kvSpaceSyntax.Value;

        KeyValuePair <Result, Level> kvSelectedLevel = new KeyValuePair <Result, Level>(Result.Failed, null);

        if (!string.IsNullOrEmpty(spaceSyntax.ScenarioName))
        {
            kvSelectedLevel = RevitUtils.AttemptToGetLevelByScenarioName(doc, spaceSyntax.ScenarioName);
        }

        if (kvSelectedLevel.Key != Result.Succeeded)
        {
            kvSelectedLevel = UserLevelSelectService.LetUserPickLevelFromDialog(doc);
        }

        if (kvSelectedLevel.Key != Result.Succeeded)
        {
            return(kvSelectedLevel.Key);
        }
        Level level = kvSelectedLevel.Value;

        KeyValuePair <Result, PlanarFace> kvTopFace = RevitUtils.GetTopFaceFromLevel(app, level);

        if (kvSelectedLevel.Key != Result.Succeeded)
        {
            return(kvSelectedLevel.Key);
        }
        PlanarFace topFace = kvTopFace.Value;

        Result result = RevitVisualizationService.CreateSpaceSyntaxAnalysisResult(doc, spaceSyntax, topFace);

        return(result);
    }