Example #1
0
        public Calculation([NotNull] CalculationConstraint constraint, IEnumerable <GridIndex> calculationMask)
        {
            constraint.AssertNotNull(nameof(constraint));

            m_Constraint      = constraint;
            m_CalculationMask = calculationMask;

            m_Worker = new BackgroundWorker
            {
                WorkerSupportsCancellation = true,
                WorkerReportsProgress      = true
            };
            m_Worker.DoWork += (sender, args) =>
            {
                GridData result = Simulate(m_CalculationMask);
                if (result == null)
                {
                    args.Cancel = true;
                }
                args.Result = result;
            };
            m_Worker.ProgressChanged += (sender, args) =>
            {
                m_Progress.OnNext(args.ProgressPercentage);
            };
            m_Worker.RunWorkerCompleted += (sender, args) =>
            {
                if (!args.Cancelled)
                {
                    m_Result.OnNext((GridData)args.Result);
                    m_Result.OnCompleted();
                    m_Progress.OnCompleted();
                }
            };
        }
        public PrCalculation([NotNull] CalculationConstraint constraint, [NotNull] EdgeData edgeData, IEnumerable <GridIndex> calculationMask)
            : base(constraint, calculationMask)
        {
            constraint.AssertNotNull(nameof(constraint));
            edgeData.AssertNotNull(nameof(edgeData));

            m_EdgeData = edgeData;
        }