コード例 #1
0
        public override void ComputeData()
        {
            if (Locked)
            {
                Phase = GH_SolutionPhase.Computed;
                Params.DoEach(p => p.Phase = GH_SolutionPhase.Computed);
                return;
            }

            switch (Phase)
            {
            case GH_SolutionPhase.Blank:
            case GH_SolutionPhase.Computed:
            case GH_SolutionPhase.Failed:
                return;

            case GH_SolutionPhase.Collecting:
                base.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Recursive Data Stream!");
                return;
            }

            // This gives the standard before/after control.
            // We can look into NOT doing this, actually.
            Phase = GH_SolutionPhase.Computing;
            var timer = new Stopwatch();

            timer.Start();
            Params.Output.DoEach(p => p.Phase = GH_SolutionPhase.Computed);

            // Do before.
            if (!TryWith(BeforeSolveInstance, "Before Solution Exception"))
            {
                goto done;
            }

            // Check that everything has its shit together.
            var hasData = Params.All(p => p.Optional || !p.VolatileData.IsEmpty);

            if (!hasData) // Didn't find anything. So, done
            {
                Phase = GH_SolutionPhase.Computed;
                TryWith(AfterSolveInstance, "After Solution Exception");
                goto done;
            }

            // Do the actual solve instance.
            var it = new ImpalaAccess(this);

            try
            {
                SolveInstance(it);
                Phase = GH_SolutionPhase.Computed;
            }
            catch (Exception ex)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Solution Exception: " + ex.Message);
                goto done;
            }

            _bbox = BoundingBox.Empty;
            if (Phase == GH_SolutionPhase.Computed)
            {
                Params.DoEach(p => (p as IGH_ParamWithPostProcess)?.PostProcessData());
            }
            TryWith(AfterSolveInstance, "After Solution Exception");

            // Quick exit, whenever it is that we get here.
done:
            timer.Stop();
            _time = timer.Elapsed;
        }