BuildingCoder.CmdPurgeTextNoteTypes.Execute C# (CSharp) 메소드

Execute() 공개 메소드

public Execute ( ExternalCommandData commandData, string &message, ElementSet elements ) : System.Result
commandData ExternalCommandData
message string
elements ElementSet
리턴 System.Result
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app = commandData.Application;
              Document doc = app.ActiveUIDocument.Document;

              ICollection<ElementId> unusedTextNoteTypes
            = GetUnusedTextNoteTypes( doc );

              int n = unusedTextNoteTypes.Count;

              int nLoop = 100;

              Stopwatch sw = new Stopwatch();

              sw.Reset();
              sw.Start();

              for( int i = 0; i < nLoop; ++ i )
              {
            unusedTextNoteTypes
              = GetUnusedTextNoteTypes( doc );

            Debug.Assert( unusedTextNoteTypes.Count == n,
              "expected same number of unused text note types" );
              }

              sw.Stop();
              double ms = (double) sw.ElapsedMilliseconds
            / (double) nLoop;

              sw.Reset();
              sw.Start();

              for( int i = 0; i < nLoop; ++ i )
              {
            unusedTextNoteTypes
              = GetUnusedTextNoteTypesExcluding( doc );

            Debug.Assert( unusedTextNoteTypes.Count == n,
              "expected same number of unused texct note types" );
              }

              sw.Stop();
              double msExcluding
            = (double) sw.ElapsedMilliseconds
              / (double) nLoop;

              Transaction t = new Transaction( doc,
            "Purging unused text note types" );

              t.Start();

              sw.Reset();
              sw.Start();

              doc.Delete( unusedTextNoteTypes );

              sw.Stop();
              double msDeleting
            = (double) sw.ElapsedMilliseconds
              / (double) nLoop;

              t.Commit();

              Util.InfoMsg( string.Format(
            "{0} text note type{1} purged. "
            + "{2} ms to collect, {3} ms to collect "
            + "excluding, {4} ms to delete.",
            n, Util.PluralSuffix( n ),
            ms, msExcluding, msDeleting ) );

              return Result.Succeeded;
        }