示例#1
0
        /// <summary>
        /// Generates paths of travel for near-corner points in one room to a single selected door.
        /// </summary>
        private void CreatePathsOfTravelInOneRoomMultiplePointsToOneDoor(UIDocument uiDoc)
        {
            Document  doc      = uiDoc.Document;
            ViewPlan  viewPlan = uiDoc.ActiveView as ViewPlan;
            ElementId levelId  = viewPlan.GenLevel.Id;

            // select room
            Reference reference = uiDoc.Selection.PickObject(ObjectType.Element, new RoomSelectionFilter(), "Select a room");
            Room      room      = doc.GetElement(reference) as Room;

            // select exit door
            Reference roomReference = uiDoc.Selection.PickObject(ObjectType.Element, new DoorSelectionFilter(), "Select a target door");
            Instance  doorElement   = doc.GetElement(roomReference) as Instance;
            Transform trf           = doorElement.GetTransform();
            XYZ       endPoint      = trf.Origin;

            ResultsSummary resultsSummary = new ResultsSummary();

            resultsSummary.numDoors = 1;

            Stopwatch stopwatch = Stopwatch.StartNew();

            GeneratePathsOfTravelForOneRoomOneDoor(doc, viewPlan, room, endPoint, resultsSummary);

            stopwatch.Stop();
            resultsSummary.elapsedMilliseconds = stopwatch.ElapsedMilliseconds;

            ShowResults(resultsSummary);
        }
示例#2
0
        static ResultsSummary ParseMSTestOutput(string output)
        {
            ResultsSummary summary = new ResultsSummary();

            bool foundSummary = false;
            string line = null;
            var reader = new StringReader(output);
            while((line = reader.ReadLine()) != null)
            {
                if (line.StartsWith("Summary") || line.StartsWith("Final Test Results"))
                {
                    foundSummary = true;
                    break;
                }

                if (line.StartsWith("Passed"))
                    summary.Passed++;
                if(line.StartsWith("Failed"))
                {
                    summary.Failed++;

                    var testName = line.Substring(line.IndexOf(' ')).Trim();
                    summary.FailedTestNames.Add(testName);
                }
            }

            if(!foundSummary)
            {
                throw new Exception("Failed to parse mstest output");
            }

            return summary;
        }
示例#3
0
        /// <summary>
        /// Shared implementation for use of Path of Travel bulk creation routine from all near-corner room points to all doors.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="viewPlan"></param>
        /// <param name="mapAllStartsToAllEnds"></param>
        private static void CreatePathsOfTravelInAllRoomsAllDoorsMultiplePointsManyToMany(Document doc, ViewPlan viewPlan, bool mapAllStartsToAllEnds)
        {
            ElementId levelId = viewPlan.GenLevel.Id;

            // find rooms on level
            FilteredElementCollector fec = new FilteredElementCollector(doc, viewPlan.Id);

            fec.WherePasses(new Autodesk.Revit.DB.Architecture.RoomFilter());


            // find doors on level
            FilteredElementCollector fec2 = new FilteredElementCollector(doc, viewPlan.Id);

            fec2.OfCategory(BuiltInCategory.OST_Doors);


            // setup results
            ResultsSummary resultsSummary = new ResultsSummary();

            List <XYZ> endPoints = new List <XYZ>();

            // Collect rooms
            List <Room> rooms = fec.Cast <Room>().ToList <Room>();

            // Loop on doors and collect target points (the door's origin)
            foreach (Element element in fec2)
            {
                Instance  doorElement = (Instance)element;
                Transform trf         = doorElement.GetTransform();
                endPoints.Add(trf.Origin);
            }

            resultsSummary.numDoors = endPoints.Count;



            using (TransactionGroup group = new TransactionGroup(doc, "Generate all paths of travel"))
            {
                group.Start();

                GeneratePathsOfTravelForRoomsToEndpointsManyToMany(doc, viewPlan, rooms, endPoints, resultsSummary, mapAllStartsToAllEnds);

                group.Assimilate();
            }

            ShowResults(resultsSummary);
        }
示例#4
0
        /// <summary>
        /// Displays the results from a run of path of travel creation using a TaskDialog.
        /// </summary>
        /// <param name="resultsSummary"></param>
        private static void ShowResults(ResultsSummary resultsSummary)
        {
            TaskDialog td = new TaskDialog("Results of 2D export");

            td.MainInstruction = String.Format("2D exporter exported {0} elements", resultsSummary.numElements);
            String details = String.Format("There were {0} text nodes exported.\n\n",
                                           resultsSummary.numTexts);

            if (resultsSummary.numTexts > 0 && resultsSummary.texts.Length > 0)
            {
                details += "Exported text nodes:\n" + resultsSummary.texts;
            }

            td.MainContent = details;

            td.Show();
        }
示例#5
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public virtual Result Execute(ExternalCommandData commandData
                                      , ref string message, ElementSet elements)
        {
            try
            {
                UIDocument             uiDoc      = commandData.Application.ActiveUIDocument;
                Autodesk.Revit.DB.View activeView = uiDoc.ActiveView;
                if (!isExportableView(activeView))
                {
                    TaskDialog td = new TaskDialog("Cannot export view.");
                    td.MainInstruction = String.Format("Only plans, elevations and sections can be exported.");

                    td.Show();

                    return(Result.Succeeded);
                }

                using (Export2DView exportForm = new Export2DView())
                {
                    if (DialogResult.OK == exportForm.ShowDialog())
                    {
                        IList <XYZ>    points     = null;
                        ResultsSummary resSummary = null;
                        ExportView(activeView,
                                   activeView.DisplayStyle /*display with current display style*/,
                                   true /* always export some geometry */,
                                   exportForm.ViewExportOptions.ExportAnnotationObjects,
                                   exportForm.ViewExportOptions.ExportPatternLines,
                                   out points,
                                   out resSummary);

                        Utilities.displayExport(activeView, points);

                        ShowResults(resSummary);
                    }
                }

                return(Result.Succeeded);
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(Result.Failed);
            }
        }
示例#6
0
        static int Main(string[] args)
        {
            try
            {
                var mstestExe   = args[0];
                var mstTestArgs = new string[args.Length - 1];
                Array.Copy(args, 1, mstTestArgs, 0, mstTestArgs.Length);

                ResultsSummary msTestResults = null;
                do
                {
                    var arguments = new List <string>(mstTestArgs);
                    if (msTestResults != null)
                    {
                        Console.WriteLine("Attempting to retry tests for {0} failed tests.", msTestResults.Failed);
                        foreach (var test in msTestResults.FailedTestNames)
                        {
                            arguments.Add(string.Format("/test:{0}", test));
                        }
                    }
                    var output     = RunMsTest(mstestExe, arguments);
                    var newResults = ParseMSTestOutput(output);

                    msTestResults = newResults;
                }while ((msTestResults.Passed > 0 && msTestResults.Failed > 0));


                if (msTestResults.Failed > 0)
                {
                    Console.WriteLine("Still failing tests after retry");
                    return(1);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Unknown error running tests: {0}", e.Message);
                Console.WriteLine(e.StackTrace);
                return(1);
            }

            return(0);
        }
示例#7
0
        static void Main(string[] args)
        {
            PopulateDb();

            var results = new ResultsSummary();

            while (true)
            {
                try
                {
                    results.UserInterface();
                }
                catch (CustomException ex)
                {
                    ex.PrintError();
                    if (Console.ReadKey().KeyChar == 'y')
                    {
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
                catch (CancelApp ex)
                {
                    ex.Cancel();
                    if (Console.ReadKey().KeyChar == 'y')
                    {
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
示例#8
0
        private static void ExportView(Autodesk.Revit.DB.View exportableView,
                                       DisplayStyle displayStyle,
                                       bool includeGeometricObjects,
                                       bool export2DIncludingAnnotationObjects,
                                       bool export2DGeometricObjectsIncludingPatternLines,
                                       out IList <XYZ> points,
                                       out ResultsSummary resultsSummary)
        {
            TessellatedGeomAndText2DExportContext context = new TessellatedGeomAndText2DExportContext(out points);
            CustomExporter exporter = new CustomExporter(exportableView.Document, context);

            exporter.IncludeGeometricObjects                       = includeGeometricObjects;
            exporter.Export2DIncludingAnnotationObjects            = export2DIncludingAnnotationObjects;
            exporter.Export2DGeometricObjectsIncludingPatternLines = export2DGeometricObjectsIncludingPatternLines;
            exporter.ShouldStopOnError = true;
            exporter.Export(exportableView);
            exporter.Dispose();

            resultsSummary             = new ResultsSummary();
            resultsSummary.numElements = context.NumElements;
            resultsSummary.numTexts    = context.NumTexts;
            resultsSummary.texts       = context.Texts;
        }
示例#9
0
        /// <summary>
        /// Displays the results from a run of path of travel creation using a TaskDialog.
        /// </summary>
        /// <param name="resultsSummary"></param>
        private static void ShowResults(ResultsSummary resultsSummary)
        {
            CultureInfo ci = new CultureInfo("en-us");

            int numOfPathsToCreate = resultsSummary.numSourcePoints * resultsSummary.numDoors;

            double successRatePercent = (double)(resultsSummary.numSuccesses) / (double)(numOfPathsToCreate);

            TaskDialog td = new TaskDialog("Results of PathOfTravel creation");

            td.MainInstruction = String.Format("Path of Travel succeeded on {0} of known points", successRatePercent.ToString("P01", ci));
            String details = String.Format("There were {0} room source points found in room analysis (via offsetting boundaries). " +
                                           "They would be connected to {2} door target points. {1} failed to generate a Path of Travel out of {4}  " +
                                           "Processing took {3} milliseconds.",
                                           resultsSummary.numSourcePoints, resultsSummary.numFailures, resultsSummary.numDoors, resultsSummary.elapsedMilliseconds, numOfPathsToCreate);

            if (resultsSummary.numFailures > 0)
            {
                details += "  Most likely reason for failures is an obstacle on or nearby to the source point.";
            }
            td.MainContent = details;

            td.Show();
        }
示例#10
0
        static ResultsSummary ParseMSTestOutput(string output)
        {
            ResultsSummary summary = new ResultsSummary();

            bool   foundSummary = false;
            string line         = null;
            var    reader       = new StringReader(output);

            while ((line = reader.ReadLine()) != null)
            {
                if (line.StartsWith("Summary") || line.StartsWith("Final Test Results"))
                {
                    foundSummary = true;
                    break;
                }

                if (line.StartsWith("Passed"))
                {
                    summary.Passed++;
                }
                if (line.StartsWith("Failed"))
                {
                    summary.Failed++;

                    var testName = line.Substring(line.IndexOf(' ')).Trim();
                    summary.FailedTestNames.Add(testName);
                }
            }

            if (!foundSummary)
            {
                throw new Exception("Failed to parse mstest output");
            }

            return(summary);
        }
示例#11
0
 /// <summary>
 /// Generates paths of travel from points in one room to a single target location using the slower (one-at-a-time) method.
 /// </summary>
 /// <param name="doc"></param>
 /// <param name="viewPlan"></param>
 /// <param name="room"></param>
 /// <param name="endPoint"></param>
 /// <param name="resultsSummary"></param>
 private static void GeneratePathsOfTravelForOneRoomOneDoor(Document doc, ViewPlan viewPlan, Room room, XYZ endPoint, ResultsSummary resultsSummary)
 {
     GeneratePathsOfTravelForOneRoomManyDoors(doc, viewPlan, room, new List <XYZ> {
         endPoint
     }, resultsSummary);
 }
示例#12
0
        /// <summary>
        ///  Generates paths of travel from points in one room to many target locations using the slower (one-at-a-time) method.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="viewPlan"></param>
        /// <param name="room"></param>
        /// <param name="endPoints"></param>
        /// <param name="resultsSummary"></param>
        private static void GeneratePathsOfTravelForOneRoomManyDoors(Document doc, ViewPlan viewPlan, Room room, List <XYZ> endPoints, ResultsSummary resultsSummary)
        {
            List <XYZ> sourcePoints = GetRoomNearCornerPoints(room);

            resultsSummary.numSourcePoints += sourcePoints.Count;

            // generate paths

            using (Transaction t = new Transaction(doc, "Generate paths of travel"))
            {
                t.Start();
                IList <PathOfTravelCalculationStatus>           statuses;
                IList <Autodesk.Revit.DB.Analysis.PathOfTravel> pathsOfTravel = Autodesk.Revit.DB.Analysis.PathOfTravel.CreateMapped(viewPlan, sourcePoints, endPoints, out statuses);

                foreach (Autodesk.Revit.DB.Analysis.PathOfTravel pOT in pathsOfTravel)
                {
                    if (pOT == null)
                    {
                        resultsSummary.numFailures++;
                    }
                    else
                    {
                        resultsSummary.numSuccesses++;
                    }
                }
                t.Commit();
            }
        }
示例#13
0
        /// <summary>
        /// Wraps all calls to PathOfTravel.Create() with multiple start/ends.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="viewPlan"></param>
        /// <param name="startPoints"></param>
        /// <param name="endPoints"></param>
        /// <param name="resultsSummary"></param>
        /// <param name="mapAllStartsToAllEnds"></param>
        private static void GeneratePathsOfTravel(Document doc, ViewPlan viewPlan, List <XYZ> startPoints, List <XYZ> endPoints, ResultsSummary resultsSummary, bool mapAllStartsToAllEnds)
        {
            // Performance monitoring
            Stopwatch stopwatch = Stopwatch.StartNew();

            using (Transaction t = new Transaction(doc, "Generate paths of travel"))
            {
                t.Start();

                IList <PathOfTravelCalculationStatus>           statuses;
                IList <Autodesk.Revit.DB.Analysis.PathOfTravel> pathsOfTravel;
                if (mapAllStartsToAllEnds)
                {
                    pathsOfTravel = Autodesk.Revit.DB.Analysis.PathOfTravel.CreateMapped(viewPlan, startPoints, endPoints, out statuses);
                }
                else
                {
                    pathsOfTravel = Autodesk.Revit.DB.Analysis.PathOfTravel.CreateMultiple(viewPlan, startPoints, endPoints, out statuses);
                }

                int i = 0;

                foreach (Autodesk.Revit.DB.Analysis.PathOfTravel pathOfTravel in pathsOfTravel)
                {
                    if (pathOfTravel == null)
                    {
                        resultsSummary.numFailures++;
                        resultsSummary.failuresFound.Add(statuses[i]);
                    }
                    else
                    {
                        resultsSummary.numSuccesses++;
                    }
                    i++;
                }

                t.Commit();
            }
            stopwatch.Stop();
            resultsSummary.elapsedMilliseconds = stopwatch.ElapsedMilliseconds;
        }
示例#14
0
        /// <summary>
        ///  Generates path of travels from room corner points to the corresponding list of end points.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="viewPlan"></param>
        /// <param name="rooms"></param>
        /// <param name="endPoints"></param>
        /// <param name="resultsSummary"></param>
        /// <param name="mapAllStartsToAllEnds"></param>
        private static void GeneratePathsOfTravelForRoomsToEndpointsManyToMany(Document doc, ViewPlan viewPlan, List <Room> rooms, List <XYZ> endPoints, ResultsSummary resultsSummary,
                                                                               bool mapAllStartsToAllEnds)
        {
            List <XYZ> allSourcePoints = new List <XYZ>();

            foreach (Room room in rooms)
            {
                AppendRoomNearCornerPoints(room, allSourcePoints);
            }
            //            foreach (Room room in rooms)
            //            {
            //                LocationPoint location = room.Location as LocationPoint;
            //                if (location == null)
            //                    continue;
            //                XYZ roomPoint = location.Point;
            //                allSourcePoints.Add(roomPoint);
            //            }

            resultsSummary.numSourcePoints += allSourcePoints.Count;

            List <XYZ> inputStartPoints = null;
            List <XYZ> inputEndPoints   = null;

            // generate full lists of start and end points mapped to one another.
            // This is for testing purposes, the API option to do this mapping is likely more efficient for this case.
            if (mapAllStartsToAllEnds)
            {
                List <XYZ> allSourcePointsMappedToEnds = new List <XYZ>();
                List <XYZ> allEndPointsMappedToEnds    = new List <XYZ>();
                foreach (XYZ source in allSourcePoints)
                {
                    foreach (XYZ end in endPoints)
                    {
                        allSourcePointsMappedToEnds.Add(source);
                        allEndPointsMappedToEnds.Add(end);
                    }
                }

                inputStartPoints = allSourcePointsMappedToEnds;
                inputEndPoints   = allEndPointsMappedToEnds;
            }
            else
            {
                inputStartPoints = allSourcePoints;
                inputEndPoints   = endPoints;
            }

            GeneratePathsOfTravel(doc, viewPlan, inputStartPoints, inputEndPoints, resultsSummary, !mapAllStartsToAllEnds);
        }
示例#15
0
        static int Main(string[] args)
        {
            Globals.bProgramRunning = true;

            Stopwatch stopwatch = Stopwatch.StartNew();

            TestConfig testConfig = ConfigHandler.ConfigureTestParameters(args);

            Globals.LoggingHandler = new LoggingHandler(testConfig);
            Globals.LoggingHandler.StartLogQueueWatcher();

            Version currentVersion = Assembly.GetExecutingAssembly().GetName().Version;

            Globals.LoggingHandler.LogConsole($"\nCosmo {currentVersion.Major}.{currentVersion.Minor}.{currentVersion.Build}\n");

            UpdateChecker updateChecker = new UpdateChecker(currentVersion, Environment.CurrentDirectory);

            bool bUpdateApp = updateChecker.Execute();

            ResultsSummary resultsSummary = new ResultsSummary();

            if (!bUpdateApp)
            {
                Globals.LoggingHandler.LogConsole($"\nInitialising {testConfig.TestName}...");

                Test test = new Test(testConfig)
                            .SetUpTargetAPI()
                            .SetUpSwaggerDocuments()
                            .SetUpPayloadDictionaries()
                            .SetUpAuthDictionaries()
                            .SetUpSimulatedUsers()
                            .SetUpTestSchedule();

                Globals.LoggingHandler.LogConsole("finished!\n");
                Globals.LoggingHandler.LogConsole($"\nRunning {testConfig.TestName}...");

                test.Run();

                resultsSummary = test.HandleResultSet();
            }

            Globals.LoggingHandler.LogConsole("finished!\n\n");

            Globals.LoggingHandler.LogConsole
            (
                Defaults.TestSummaryMessage
                .Replace("[[Endpoints]]", resultsSummary.EndpointsTested.ToString())
                .Replace("[[Successes]]", resultsSummary.EndpointsPassed.ToString())
                .Replace("[[Failures]]", resultsSummary.EndpointsFailed.ToString())
            );

            stopwatch.Stop();
            Console.WriteLine(stopwatch.ElapsedMilliseconds);

            Globals.LoggingHandler.LogConsole("\nWriting logs...");

            Globals.LoggingHandler.WaitForLoggingCompletion();

            Globals.LoggingHandler.LogConsole("finished!\n");

            Globals.bProgramRunning = false;

            return(0);
        }