Exemple #1
0
        public void GoToTime(int time)
        {
            //Zeitpunkt bestimmt CurrentPhase und verbleibende Phasen
            var sum   = 0;
            var found = false;

            foreach (var phase in PhaseQueue)
            {
                sum += phase.Duration;
                if (sum >= time)
                {
                    if (found)
                    {
                        WorkingQueue.Enqueue(phase);
                    }
                    else
                    {
                        found        = true;
                        CurrentPhase = phase;
                        CurrentPhase.RemainingTime = (sum - time);
                        WorkingQueue.Clear();
                    }
                }
            }

            //PhaseEventArgs als Informationspaket instanzieren
            PhaseChanged?.Invoke(this, new PhaseEventArgs(CurrentPhase, MessageType.Move, time));
            //SubController benachrichtigen
        }
Exemple #2
0
        /// <summary>
        /// Inner conversion
        /// </summary>
        /// <param name="outputFile">Output file</param>
        private void PerformConvert(string outputFile)
        {
            ConversionWarnings = null;
            string errorMessage = null;
            var    result       = 0;

            PdfGlobalSettings.OutputFile      = outputFile;
            wkHtmlToPdfWrapper.ProgressEvent += percentage => ProgressChanged?.Invoke(this, percentage);
            wkHtmlToPdfWrapper.PhaseEvent    += phaseDescription => PhaseChanged?.Invoke(this, phaseDescription);
            wkHtmlToPdfWrapper.ErrorEvent    += errorText => errorMessage = errorText;
            wkHtmlToPdfWrapper.FinishedEvent += resultCode =>
            {
                result = resultCode;
                Finished?.Invoke(this, resultCode);
            };
            wkHtmlToPdfWrapper.WarningEvent += warningsMessage => ConversionWarnings = warningsMessage;

            SetObjectSettings(PdfGlobalSettings, true);
            SetObjectSettings(PdfObjectSettings, false);
            SetObjectSettings(WebSettings, false);
            SetObjectSettings(LoadSettings, false);
            SetObjectSettings(HeaderSettings, false);
            SetObjectSettings(FooterSettings, false);
            wkHtmlToPdfWrapper.convert();

            if (result == 0)
            {
                throw new HtmlConversionException(errorMessage);
            }
        }
Exemple #3
0
        private void OnDoPhenology(object sender, EventArgs e)
        {
            if (PlantIsAlive)
            {
                if (thermalTime.Value() < 0)
                {
                    throw new Exception("Negative Thermal Time, check the set up of the ThermalTime Function in" + this);
                }

                // Calculate progression through current phase
                double propOfDayToUse = 1;
                bool   incrementPhase = CurrentPhase.DoTimeStep(ref propOfDayToUse);

                //sorghum resets the stage variable to 0 on the day the phase changes
                //it will resume again normally the day after
                double resetSorghumStage = SorghumFlag != null && incrementPhase ? 0.0 : 1.0;

                while (incrementPhase)
                {
                    if ((CurrentPhase is EmergingPhase) || (CurrentPhase.End == structure?.LeafInitialisationStage))
                    {
                        Emerged = true;
                    }

                    stagesPassedToday.Add(CurrentPhase.End);
                    if (currentPhaseIndex + 1 >= phases.Count)
                    {
                        throw new Exception("Cannot transition to the next phase. No more phases exist");
                    }

                    currentPhaseIndex = currentPhaseIndex + 1;

                    PhaseChangedType PhaseChangedData = new PhaseChangedType();
                    PhaseChangedData.StageName = CurrentPhase.Start;
                    PhaseChanged?.Invoke(plant, PhaseChangedData);

                    if (SorghumFlag != null && CurrentPhase is EmergingPhase)
                    {
                        propOfDayToUse = 0.0;
                    }
                    incrementPhase = CurrentPhase.DoTimeStep(ref propOfDayToUse);
                }

                AccumulatedTT += thermalTime.Value();
                if (Emerged)
                {
                    AccumulatedEmergedTT += thermalTime.Value();
                }

                Stage = (currentPhaseIndex + 1) + resetSorghumStage * CurrentPhase.FractionComplete;

                if (plant != null)
                {
                    if (plant.IsAlive && PostPhenology != null)
                    {
                        PostPhenology.Invoke(this, new EventArgs());
                    }
                }
            }
        }
Exemple #4
0
        private void OnPhaseChanged(IntPtr converter)
        {
            var currentPhase = _wkHtmlToPdf.GetCurrentPhase(converter);
            var eventArgs    = new PhaseChangedArgs
            {
                Document     = _processingDocument,
                PhaseCount   = _wkHtmlToPdf.GetPhaseCount(converter),
                CurrentPhase = currentPhase,
                Description  = _wkHtmlToPdf.GetPhaseDescription(converter, currentPhase)
            };

            PhaseChanged?.Invoke(this, eventArgs);
        }
        private void OnPhaseChanged(IntPtr converter)
        {
            int currentPhase = wkHtmlToXService.GetCurrentPhase(converter);
            var eventArgs    = new PhaseChangedArgs()
            {
                Document     = ProcessingDocument,
                PhaseCount   = wkHtmlToXService.GetPhaseCount(converter),
                CurrentPhase = currentPhase,
                Description  = wkHtmlToXService.GetPhaseDescription(converter, currentPhase)
            };

            PhaseChanged?.Invoke(this, eventArgs);
        }
Exemple #6
0
        private void OnHarvesting(object sender, EventArgs e)
        {
            if (sender == Plant)
            {
                //Jump phenology to the end

                string           OldPhaseName     = CurrentPhase.Name;
                int              EndPhase         = Phases.Count;
                PhaseChangedType PhaseChangedData = new PhaseChangedType();
                PhaseChangedData.OldPhaseName = OldPhaseName;
                PhaseChangedData.NewPhaseName = Phases[EndPhase - 1].Name;
                PhaseChanged.Invoke(PhaseChangedData);
                CurrentPhaseName = Phases[EndPhase - 1].Name;
            }
        }
Exemple #7
0
        private void OnDoPhenology(object sender, EventArgs e)
        {
            if (PlantIsAlive)
            {
                if (thermalTime.Value() < 0)
                {
                    throw new Exception("Negative Thermal Time, check the set up of the ThermalTime Function in" + this);
                }

                // Calculate progression through current phase
                double propOfDayToUse = 1;
                bool   incrementPhase = CurrentPhase.DoTimeStep(ref propOfDayToUse);
                AccumulateTT(CurrentPhase.TTForTimeStep);

                while (incrementPhase)
                {
                    if ((CurrentPhase is EmergingPhase) || (CurrentPhase is BuddingPhase))
                    {
                        Emerged = true;
                    }

                    stagesPassedToday.Add(CurrentPhase.End);
                    if (currentPhaseIndex + 1 >= phases.Count)
                    {
                        throw new Exception("Cannot transition to the next phase. No more phases exist");
                    }

                    currentPhaseIndex = currentPhaseIndex + 1;

                    PhaseChangedType PhaseChangedData = new PhaseChangedType();
                    PhaseChangedData.StageName = CurrentPhase.Start;
                    PhaseChanged?.Invoke(plant, PhaseChangedData);

                    incrementPhase = CurrentPhase.DoTimeStep(ref propOfDayToUse);
                    AccumulateTT(CurrentPhase.TTForTimeStep);
                }

                Stage = (currentPhaseIndex + 1) + CurrentPhase.FractionComplete;

                if (plant != null)
                {
                    if (plant.IsAlive && PostPhenology != null)
                    {
                        PostPhenology.Invoke(this, new EventArgs());
                    }
                }
            }
        }
        public void Start()
        {
            IsMoniting = true;

            if (MonitingThread != null)
            {
                return;
            }

            MonitingThread = new Thread(async() =>
            {
                while (IsMoniting)
                {
                    try
                    {
                        string phase = await Wrapper.GetGameflowPhaseAsync();
                        if (phase != LastPhase)
                        {
                            PhaseChanged?.Invoke(this, new PhaseChangedArgs(LastPhase, phase));
                        }
                        LastPhase = phase;
                    }
                    catch (RequestWrapper.NoClientException ex)
                    {
                    }
                    catch (System.Net.WebException ex)
                    {
                    }
                    Thread.Sleep(500);
                }
                MonitingThread = null;
            })
            {
                IsBackground = true,
                Name         = "GameflowPhaseMonitor.MonitingThread"
            };
            MonitingThread.Start();
        }
 protected virtual void OnPhaseChanged()
 {
     PhaseChanged?.Invoke(this, new PhaseEventArgs(CurrentPhase, remainingTime));
 }
Exemple #10
0
        /// <summary>A function that resets phenology to a specified stage</summary>
        public void SetToStage(double newStage)
        {
            int oldPhaseIndex = IndexFromPhaseName(CurrentPhase.Name);

            stagesPassedToday.Clear();

            if (newStage <= 0)
            {
                throw new Exception(this + "Must pass positive stage to set to");
            }
            if (newStage > phases.Count() + 1)
            {
                throw new Exception(this + " Trying to set to non-existant stage");
            }

            currentPhaseIndex = Convert.ToInt32(Math.Floor(newStage), CultureInfo.InvariantCulture) - 1;

            if (newStage < Stage)
            {
                //Make a list of phases to rewind
                List <IPhase> phasesToRewind = new List <IPhase>();
                foreach (IPhase phase in phases)
                {
                    if ((IndexFromPhaseName(phase.Name) >= currentPhaseIndex) && (IndexFromPhaseName(phase.Name) <= oldPhaseIndex))
                    {
                        phasesToRewind.Add(phase);
                    }
                }

                foreach (IPhase phase in phasesToRewind)
                {
                    if (!(phase is IPhaseWithTarget) && !(phase is GotoPhase) && !(phase is EndPhase) && !(phase is PhotoperiodPhase) && !(phase is LeafDeathPhase) && !(phase is DAWSPhase))
                    {
                        throw new Exception("Can not rewind over phase of type " + phase.GetType());
                    }
                    if (phase is IPhaseWithTarget)
                    {
                        IPhaseWithTarget rewindingPhase = phase as IPhaseWithTarget;
                        AccumulatedTT        -= rewindingPhase.ProgressThroughPhase;
                        AccumulatedEmergedTT -= rewindingPhase.ProgressThroughPhase;
                        phase.ResetPhase();
                    }
                    else
                    {
                        phase.ResetPhase();
                    }
                }
                AccumulatedEmergedTT = Math.Max(0, AccumulatedEmergedTT);
            }
            else
            {
                //Make a list of phases to fast forward
                List <IPhase> phasesToFastForward = new List <IPhase>();
                foreach (IPhase phase in phases)
                {
                    if (IndexFromPhaseName(phase.Name) >= oldPhaseIndex)
                    {
                        phasesToFastForward.Add(phase);
                    }
                }
                foreach (IPhase phase in phasesToFastForward)
                {
                    if (phase is EndPhase)
                    {
                        stagesPassedToday.Add(phase.Start); //Fixme.  This is a pretty ordinary bit of programming to get around the fact we use a phenological stage to match observed values. We should change this so plant has a harvest tag to match on.
                    }
                    stagesPassedToday.Add(phase.End);
                    PhaseChangedType PhaseChangedData = new PhaseChangedType();
                    PhaseChangedData.StageName = phase.End;
                    PhaseChanged?.Invoke(plant, PhaseChangedData);
                }
            }

            if (phases[currentPhaseIndex] is IPhaseWithTarget)
            {
                IPhaseWithTarget currentPhase = (phases[currentPhaseIndex] as IPhaseWithTarget);
                currentPhase.ProgressThroughPhase = currentPhase.Target * (newStage - currentPhaseIndex - 1);

                if (currentPhase.ProgressThroughPhase == 0)
                {
                    stagesPassedToday.Add(currentPhase.Start);
                }
            }
            if ((phases[currentPhaseIndex] is PhotoperiodPhase) || (phases[currentPhaseIndex] is LeafDeathPhase))
            {
                stagesPassedToday.Add(phases[currentPhaseIndex].Start);
            }

            StageWasReset?.Invoke(this, new EventArgs());
        }
Exemple #11
0
        /// <summary>Respond to a remove biomass event.</summary>
        /// <param name="removeBiomPheno">The remove biom pheno.</param>
        internal void OnRemoveBiomass(double removeBiomPheno)
        {
            string existingStage = CurrentStageName;

            if (RewindDueToBiomassRemoved != null)
            {
                FractionBiomassRemoved = removeBiomPheno; // The RewindDueToBiomassRemoved function will use this.

                double ttCritical       = TTInAboveGroundPhase;
                double removeFractPheno = RewindDueToBiomassRemoved.Value();
                double removeTTPheno    = ttCritical * removeFractPheno;

                string msg;
                msg  = "Phenology change:-\r\n";
                msg += "    Fraction DM removed  = " + removeBiomPheno.ToString() + "\r\n";
                msg += "    Fraction TT removed  = " + removeFractPheno.ToString() + "\r\n";
                msg += "    Critical TT          = " + ttCritical.ToString() + "\r\n";
                msg += "    Remove TT            = " + removeTTPheno.ToString() + "\r\n";

                double ttRemaining = removeTTPheno;
                for (int i = Phases.Count - 1; i >= 0; i--)
                {
                    Phase Phase = Phases[i];
                    if (Phase.TTinPhase > 0)
                    {
                        double ttCurrentPhase = Phase.TTinPhase;
                        if (ttRemaining > ttCurrentPhase)
                        {
                            Phase.ResetPhase();
                            ttRemaining       -= ttCurrentPhase;
                            CurrentPhaseIndex -= 1;
                            if (CurrentPhaseIndex < 4)  //FIXME - hack to stop onEmergence being fired which initialises biomass parts
                            {
                                CurrentPhaseIndex = 4;
                                break;
                            }
                        }
                        else
                        {
                            Phase.Add(-ttRemaining);
                            // Return fraction of thermal time we are through the current
                            // phenological phase (0-1)
                            //double frac = Phase.FractionComplete;
                            //if (frac > 0.0 && frac < 1.0)  // Don't skip out of this stage - some have very low targets, eg 1.0 in "maturity"
                            //    currentStage = frac + floor(currentStage);

                            break;
                        }
                    }
                    else
                    { // phase is empty - not interested in it
                    }
                }
                Stage = (CurrentPhaseIndex + 1) + CurrentPhase.FractionComplete - PhaseIndexOffset;

                if (existingStage != CurrentStageName)
                {
                    PhaseChangedType PhaseChangedData = new PhaseChangedType();
                    PhaseChangedData.OldPhaseName = existingStage;
                    PhaseChangedData.NewPhaseName = CurrentPhase.Name;
                    PhaseChanged.Invoke(Plant, PhaseChangedData);
                    //Fixme MyPaddock.Publish(CurrentPhase.Start);
                }
            }
        }
Exemple #12
0
        /// <summary>A function that resets phenology to a specified stage</summary>
        public void SetToStage(double newStage)
        {
            string stageOnEvent  = CurrentPhase.End;
            double oldPhaseIndex = IndexFromPhaseName(CurrentPhase.Name);

            stagesPassedToday.Clear();

            if (newStage <= 0)
            {
                throw new Exception(this + "Must pass positive stage to set to");
            }
            if (newStage > phases.Count() + 1)
            {
                throw new Exception(this + " Trying to set to non-existant stage");
            }

            currentPhaseIndex = Convert.ToInt32(Math.Floor(newStage)) - 1;

            if (!(phases[currentPhaseIndex] is IPhaseWithTarget))
            {
                throw new Exception("Can not set phenology to phase of type " + phases[currentPhaseIndex].GetType());
            }

            if (currentPhaseIndex <= oldPhaseIndex)
            {
                //Make a list of phases to rewind
                List <IPhase> phasesToRewind = new List <IPhase>();
                foreach (IPhase phase in phases)
                {
                    if ((IndexFromPhaseName(phase.Name) >= currentPhaseIndex) && (IndexFromPhaseName(phase.Name) <= oldPhaseIndex))
                    {
                        phasesToRewind.Add(phase);
                    }
                }

                foreach (IPhase phase in phasesToRewind)
                {
                    AccumulatedTT        -= phase.TTinPhase;
                    AccumulatedEmergedTT -= phase.TTinPhase;
                    phase.ResetPhase();
                }
                AccumulatedEmergedTT = Math.Max(0, AccumulatedEmergedTT);
            }
            else
            {
                //Make a list of phases fast forward
                List <IPhase> phasesToFastForward = new List <IPhase>();
                foreach (IPhase phase in phases)
                {
                    if (IndexFromPhaseName(phase.Name) >= oldPhaseIndex)
                    {
                        phasesToFastForward.Add(phase);
                    }
                }
                foreach (IPhase phase in phasesToFastForward)
                {
                    stagesPassedToday.Add(phase.End);
                    if (PhaseChanged != null)
                    {
                        PhaseChangedType PhaseChangedData = new PhaseChangedType();
                        PhaseChangedData.StageName = phase.End;
                        PhaseChanged.Invoke(plant, PhaseChangedData);
                    }
                }
            }

            IPhaseWithTarget currentPhase = (phases[currentPhaseIndex] as IPhaseWithTarget);

            currentPhase.TTinPhase = currentPhase.Target * (newStage - currentPhaseIndex - 1);

            if (currentPhase.TTinPhase == 0)
            {
                stagesPassedToday.Add(currentPhase.Start);
            }

            if (StageWasReset != null)
            {
                StageWasReset.Invoke(this, new EventArgs());
            }
        }
Exemple #13
0
 private void OnPhaseChanged(CcjRoundPhase phase) => PhaseChanged?.Invoke(this, phase);
Exemple #14
0
        private void OnDoPhenology(object sender, EventArgs e)
        {
            if (PlantIsAlive)
            {
                if (thermalTime.Value() < 0)
                {
                    throw new Exception("Negative Thermal Time, check the set up of the ThermalTime Function in" + this);
                }

                // Calculate progression through current phase
                double propOfDayToUse = 1;
                bool   incrementPhase = CurrentPhase.DoTimeStep(ref propOfDayToUse);

                //sorghum resets the stage variable to 0 on the day the phase changes
                //it will resume again normally the day after
                double resetSorghumStage = SorghumFlag != null && incrementPhase ? 0.0 : 1.0;

                while (incrementPhase)
                {
                    if ((CurrentPhase is EmergingPhase) || (CurrentPhase.End == structure?.LeafInitialisationStage) || (CurrentPhase is DAWSPhase))
                    {
                        Emerged = true;
                    }

                    stagesPassedToday.Add(CurrentPhase.End);
                    if (currentPhaseIndex + 1 >= phases.Count)
                    {
                        throw new Exception("Cannot transition to the next phase. No more phases exist");
                    }

                    currentPhaseIndex = currentPhaseIndex + 1;

                    PhaseChangedType PhaseChangedData = new PhaseChangedType();
                    PhaseChangedData.StageName = CurrentPhase.Start;
                    PhaseChanged?.Invoke(plant, PhaseChangedData);

                    if (SorghumFlag != null && CurrentPhase is EmergingPhase)
                    {
                        // void accumulate(...)
                        double dltPhase     = 1.0 + Stage % 1.0;
                        double newStage     = Math.Floor(Stage) + dltPhase;
                        double dltStage     = newStage - Stage;
                        double pIndex       = Stage;
                        double dltIndex     = dltStage;
                        double indexDevel   = pIndex - Math.Floor(pIndex) + dltIndex;
                        double portionInOld = 1 - APSIM.Shared.Utilities.MathUtilities.Divide(indexDevel - 1, dltIndex, 0);
                        propOfDayToUse = 1 - portionInOld;
                    }
                    incrementPhase = CurrentPhase.DoTimeStep(ref propOfDayToUse);
                    if (SorghumFlag != null && CurrentStageName == "Emergence")
                    {
                        AccumulatedEmergedTT -= (1 - propOfDayToUse) * thermalTime.Value();
                    }
                }

                AccumulatedTT += thermalTime.Value();
                if (Emerged)
                {
                    AccumulatedEmergedTT += thermalTime.Value();
                }

                Stage = (currentPhaseIndex + 1) + resetSorghumStage * CurrentPhase.FractionComplete;

                if (plant != null && plant.IsAlive && PostPhenology != null)
                {
                    PostPhenology.Invoke(this, new EventArgs());
                }
            }
        }