Пример #1
0
        protected void OnPlantEnding(object sender, EventArgs e)
        {
            if (MathUtilities.IsPositive(Wt))
            {
                Detached.Add(Live);
                Detached.Add(Dead);
                surfaceOrganicMatter.Add(Wt * 10, N * 10, 0, plant.CropType, Name);
            }

            Clear();
        }
Пример #2
0
 /// <summary>
 /// Detaches this instance.
 /// </summary>
 public void Detach()
 {
     if (IsAttached)
     {
         IsAttached = false;
         RenderCore.Detach();
         Disposer.RemoveAndDispose(ref bitmapCache);
         OnDetach();
         Detached?.Invoke(this, EventArgs.Empty);
     }
 }
Пример #3
0
        private void OnPlantEnding(object sender, EventArgs e)
        {
            if (Wt > 0.0)
            {
                Detached.Add(Live);
                Detached.Add(Dead);
                SurfaceOrganicMatter.Add(Wt * 10, N * 10, 0, Plant.CropType, Name);
            }

            Clear();
        }
Пример #4
0
        protected void OnPlantEnding(object sender, EventArgs e)
        {
            if (Wt > 0.0)
            {
                Detached.Add(Live);
                Detached.Add(Dead);
                surfaceOrganicMatter.Add(Wt * 10, N * 10, 0, parentPlant.PlantType, Name);
            }

            Clear();
        }
Пример #5
0
        private void OnPlantEnding(object sender, EventArgs e)
        {
            Biomass total = Live + Dead;

            if (total.Wt > 0.0)
            {
                Detached.Add(Live);
                Detached.Add(Dead);
                SurfaceOrganicMatter.Add(total.Wt * 10, total.N * 10, 0, Plant.CropType, Name);
            }
            Clear();
        }
Пример #6
0
 /// <summary>Clears this instance.</summary>
 protected void Clear()
 {
     Height = 0;
     StartNRetranslocationSupply = 0;
     StartNReallocationSupply    = 0;
     LiveFWt = 0;
     DMDemand.Clear();
     DMSupply.Clear();
     NDemand.Clear();
     NSupply.Clear();
     Detached.Clear();
 }
Пример #7
0
        /// <summary>
        /// Requests that Duktape end the debug session.
        /// </summary>
        /// <returns></returns>
        public async Task Detach()
        {
            if (messenger == null)
            {
                return;
            }
            await DoRequest(DValueTag.REQ, Request.Detach);

            await Task.Run(() => messenger.Join());

            tcp.Client.Disconnect(true);
            Detached?.Invoke(this, EventArgs.Empty);
        }
Пример #8
0
 /// <summary>
 /// Detaches the element from the host. Override <see cref="OnDetach"/>
 /// </summary>
 public void Detach()
 {
     if (IsAttached)
     {
         IsAttached = false;
         InvalidateSceneGraph();
         RenderCore.Detach();
         OnDetach();
         DisposeAndClear();
         renderTechnique = null;
         Detached?.Invoke(this, EventArgs.Empty);
     }
 }
        public async Task WaitNextFrameAsync()
        {
            nextFrame = false;
            DateTime timeout = DateTime.Now;

            while (!nextFrame)
            {
                if ((DateTime.Now - timeout).Seconds > 3)
                {
                    Detached?.Invoke(this, null);
                    break;
                }
            }
        }
Пример #10
0
 /// <summary>Clears this instance.</summary>
 protected virtual void Clear()
 {
     Live = new Biomass();
     Dead = new Biomass();
     DMSupply.Clear();
     NSupply.Clear();
     DMDemand.Clear();
     NDemand.Clear();
     potentialDMAllocation.Clear();
     Allocated.Clear();
     Senesced.Clear();
     Detached.Clear();
     Removed.Clear();
 }
Пример #11
0
        protected virtual async ValueTask OnDetachedAsync(Channel <T> channel)
        {
            var taskCollector = Collector <ValueTask> .New();

            try {
                Detached?.Invoke(channel, ref taskCollector);

                // The traversal direction doesn't matter, so let's traverse
                // it in reverse order to help the compiler to get rid of extra
                // bound checks.
                var tasks = taskCollector.Buffer;
                for (var i = taskCollector.Count - 1; i >= 0; i--)
                {
                    var task = tasks[i];
                    try {
                        await task.ConfigureAwait(false);
                    }
                    catch {
                        // Ignore: we want to invoke all handlers
                    }
                }
            }
            finally {
                taskCollector.Dispose();
            }

            switch (channel)
            {
            case IAsyncDisposable ad:
                await ad.DisposeAsync().ConfigureAwait(false);

                break;

            case IDisposable d:
                d.Dispose();
                break;

            default:
                for (var i = 0; i < 3; i++)
                {
                    if (channel.Writer.TryComplete())
                    {
                        break;
                    }
                    await Task.Delay(TimeSpan.FromSeconds(10)).ConfigureAwait(false);
                }
                break;
            }
        }
Пример #12
0
 public void Detach()
 {
     if (Target != null)
     {
         Target.DrawingSurface.PreviewMouseDown -= OnMouseDown;
         Target.DrawingSurface.PreviewMouseMove -= OnMouseMove;
         Target.DrawingSurface.PreviewMouseUp   -= OnMouseUp;
         Target.ZoomChanged          -= OnZoomChanged;
         Target.SelectedLayerChanged -= OnSelectedLayerChanged;
         Target.FrameChanged         -= OnFrameChanged;
         Target.ToolOptions.Children.Clear();
         Target.ExtensionPanel.Children.Clear();
         Detached.Invoke(this);
         Target = null;
     }
 }
Пример #13
0
        public void Unset(INotifiable node, bool leaveDummy = false)
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            if (!successors.Remove(node))
            {
                throw new InvalidOperationException("The specified node is not registered as the successor.");
            }
            if (!(isDummySet = leaveDummy))
            {
                Detached?.Invoke(this, EventArgs.Empty);
            }
        }
Пример #14
0
 /// <summary>Clears this instance.</summary>
 protected void Clear()
 {
     Height = 0;
     StartNRetranslocationSupply = 0;
     StartNReallocationSupply    = 0;
     LiveFWt = 0;
     DMDemand.Clear();
     DMSupply.Clear();
     NDemand.Clear();
     NSupply.Clear();
     Detached.Clear();
     Leaves.Clear();
     if (Structure != null)
     {
         Structure.LeafTipsAppeared = 0;
     }
 }
Пример #15
0
 /// <summary>Clears this instance.</summary>
 private void Clear()
 {
     Live = new Biomass();
     Dead = new Biomass();
     DMSupply.Clear();
     NSupply.Clear();
     DMDemand.Clear();
     NDemand.Clear();
     potentialDMAllocation.Clear();
     Allocated.Clear();
     Senesced.Clear();
     Detached.Clear();
     Removed.Clear();
     Height          = 0;
     LAI             = 0;
     LeafInitialised = false;
 }
Пример #16
0
 /// <summary>Clears this instance.</summary>
 protected virtual void Clear()
 {
     Live = new Biomass();
     Dead = new Biomass();
     dryMatterSupply.Clear();
     nitrogenSupply.Clear();
     dryMatterDemand.Clear();
     nitrogenDemand.Clear();
     potentialDMAllocation.Clear();
     potentialDMAllocating           = 0.0;
     potentialStructuralDMAllocation = 0.0;
     potentialMetabolicDMAllocation  = 0.0;
     Allocated.Clear();
     Senesced.Clear();
     Detached.Clear();
     Removed.Clear();
 }
Пример #17
0
 /// <summary>Clears this instance.</summary>
 protected void Clear()
 {
     Height = 0;
     StartNRetranslocationSupply     = 0;
     StartNReallocationSupply        = 0;
     PotentialDMAllocation           = 0;
     PotentialStructuralDMAllocation = 0;
     PotentialMetabolicDMAllocation  = 0;
     StructuralDMDemand = 0;
     StorageDMDemand    = 0;
     LiveFWt            = 0;
     dryMatterDemand.Clear();
     dryMatterSupply.Clear();
     nitrogenDemand.Clear();
     nitrogenSupply.Clear();
     Detached.Clear();
 }
Пример #18
0
 /// <summary>Clears this instance.</summary>
 protected virtual void Clear()
 {
     Live.Clear();
     Dead.Clear();
     DMRetranslocationSupply         = 0.0;
     DMReallocationSupply            = 0.0;
     NRetranslocationSupply          = 0.0;
     NReallocationSupply             = 0.0;
     PotentialDMAllocation           = 0.0;
     PotentialStructuralDMAllocation = 0.0;
     PotentialMetabolicDMAllocation  = 0.0;
     StructuralDMDemand = 0.0;
     StorageDMDemand    = 0.0;
     Allocated.Clear();
     Senesced.Clear();
     Detached.Clear();
     Removed.Clear();
 }
Пример #19
0
        protected void OnDoPotentialPlantGrowth(object sender, EventArgs e)
        {
            if (Plant.IsEmerged)
            {
                Detached.Clear();
                FRGR   = FRGRFunction.Value();
                Height = HeightFunction.Value();
                //Initialise biomass and nitrogen

                cohort.AddLeaf(InitialWtFunction.Value(), MinimumNConc.Value(), MaximumNConc.Value(), SpecificLeafAreaFunction.Value());

                double developmentRate = LeafDevelopmentRate.Value();
                cohort.IncreaseAge(developmentRate);

                StartLive = ReflectionUtilities.Clone(Live) as Biomass;
                StartNReallocationSupply    = NSupply.Reallocation;
                StartNRetranslocationSupply = NSupply.Retranslocation;
            }
        }
Пример #20
0
 /// <summary>Clears this instance.</summary>
 protected void Clear()
 {
     Height       = 0;
     PotentialEP  = 0;
     WaterDemand  = 0;
     LightProfile = null;
     StartNRetranslocationSupply = 0;
     StartNReallocationSupply    = 0;
     LiveFWt = 0;
     DMDemand.Clear();
     DMSupply.Clear();
     NDemand.Clear();
     NSupply.Clear();
     Detached.Clear();
     cohort.Clear();
     GrowthRespiration = 0;
     FRGR = 0;
     if (Structure != null)
     {
         Structure.LeafTipsAppeared = 0;
     }
 }
Пример #21
0
        protected void OnDoActualPlantGrowth(object sender, EventArgs e)
        {
            if (parentPlant.IsAlive)
            {
                // Do senescence
                double senescedFrac = senescenceRate.Value();
                if (Live.Wt * (1.0 - senescedFrac) < BiomassToleranceValue)
                {
                    senescedFrac = 1.0;  // remaining amount too small, senesce all
                }
                Biomass Loss = Live * senescedFrac;
                Live.Subtract(Loss);
                Dead.Add(Loss);
                Senesced.Add(Loss);

                // Do detachment
                double detachedFrac = detachmentRateFunction.Value();
                if (Dead.Wt * (1.0 - detachedFrac) < BiomassToleranceValue)
                {
                    detachedFrac = 1.0;  // remaining amount too small, detach all
                }
                Biomass detaching = Dead * detachedFrac;
                Dead.Multiply(1.0 - detachedFrac);
                if (detaching.Wt > 0.0)
                {
                    Detached.Add(detaching);
                    surfaceOrganicMatter.Add(detaching.Wt * 10, detaching.N * 10, 0, parentPlant.PlantType, Name);
                }

                // Do maintenance respiration
                MaintenanceRespiration = 0;
                if (maintenanceRespirationFunction.Value() > 0)
                {
                    MaintenanceRespiration = (Live.MetabolicWt + Live.StorageWt) * maintenanceRespirationFunction.Value();
                    Live.MetabolicWt      *= (1 - maintenanceRespirationFunction.Value());
                    Live.StorageWt        *= (1 - maintenanceRespirationFunction.Value());
                }
            }
        }
Пример #22
0
        protected void OnDoActualPlantGrowth(object sender, EventArgs e)
        {
            if (Plant.IsAlive)
            {
                // Do senescence
                double senescedFrac = SenescenceRate.Value;
                if (Live.Wt * (1.0 - senescedFrac) < BiomassToleranceValue)
                {
                    senescedFrac = 1.0;  // remaining amount too small, senesce all
                }
                Biomass Loss = Live * senescedFrac;
                Live.Subtract(Loss);
                Dead.Add(Loss);
                Senesced.Add(Loss);

                // Do detachment
                double detachedFrac = DetachmentRateFunction.Value;
                if (Dead.Wt * (1.0 - detachedFrac) < BiomassToleranceValue)
                {
                    detachedFrac = 1.0;  // remaining amount too small, detach all
                }
                Biomass detaching = Dead * detachedFrac;
                Dead.Multiply(1.0 - detachedFrac);
                if (detaching.Wt > 0.0)
                {
                    Detached.Add(detaching);
                    SurfaceOrganicMatter.Add(detaching.Wt * 10, detaching.N * 10, 0, Plant.CropType, Name);
                }

                // Do maintenance respiration
                MaintenanceRespiration += Live.MetabolicWt * MaintenanceRespirationFunction.Value;
                Live.MetabolicWt       *= (1 - MaintenanceRespirationFunction.Value);
                MaintenanceRespiration += Live.NonStructuralWt * MaintenanceRespirationFunction.Value;
                Live.NonStructuralWt   *= (1 - MaintenanceRespirationFunction.Value);
            }
        }
Пример #23
0
 private void RaiseDetached()
 {
     Detached?.Invoke(this, EventArgs.Empty);
 }
Пример #24
0
 ///////////////////////////////////////////////////////////////////////
 /// <summary>
 /// Handles the notifications from the USB device manager of the
 /// removal of a USB device.
 /// </summary>
 /// <param name="usbDevice">Reference the the USB device that has been detached.</param>
 public void OnDetached(object sender, EventArgs e)
 {
     _isAttached = false;
     // Check if anyone has registered for the event.
     Detached?.Invoke(sender, e);
 }
Пример #25
0
 public void OnDetached(CompositeObject owner, CompositeObjectProperty prop)
 {
     Detached?.Invoke(owner, prop);
 }
Пример #26
0
        public virtual void Detach()
        {
            Target = null;

            Detached?.Invoke(this, EventArgs.Empty);
        }
Пример #27
0
 protected virtual void OnViewDetached()
 {
     Detached?.Invoke();
 }
Пример #28
0
        private void ProcessMessages()
        {
            while (true)
            {
                DMessage message = DMessage.Receive(tcp.Client);
                if (message == null)
                {
                    // if DMessage.Receive() returns null, detach.
                    tcp.Close();
                    Detached?.Invoke(this, EventArgs.Empty);
                    return;
                }
                else if (message[0].Tag == DValueTag.NFY)
                {
                    switch ((Notify)(int)message[1])
                    {
                    case Notify.Status:
                        FileName   = (string)message[3];
                        LineNumber = (int)message[5];
                        Running    = (int)message[2] == 0;
                        Status?.Invoke(this, EventArgs.Empty);
                        break;

                    case Notify.Throw:
                        Throw?.Invoke(this, new ThrowEventArgs(
                                          (string)message[3], (string)message[4], (int)message[5],
                                          (int)message[2] != 0));
                        break;

                    case Notify.Detaching:
                        tcp.Close();
                        Detached?.Invoke(this, EventArgs.Empty);
                        return;

                    case Notify.AppNotify:
                        switch ((AppNotify)(int)message[2])
                        {
                        case AppNotify.DebugPrint:
                            PrintType type      = (PrintType)(int)message[3];
                            string    debugText = (string)message[4];
                            string    prefix    = type == PrintType.Assert ? "ASSERT"
                                        : type == PrintType.Debug ? "debug"
                                        : type == PrintType.Error ? "ERROR"
                                        : type == PrintType.Info ? "info"
                                        : type == PrintType.Trace ? "trace"
                                        : type == PrintType.Warn ? "warn"
                                        : "log";
                            Print?.Invoke(this, new TraceEventArgs(string.Format("{0}: {1}", prefix, debugText)));
                            break;
                        }
                        break;
                    }
                }
                else if (message[0].Tag == DValueTag.REP || message[0].Tag == DValueTag.ERR)
                {
                    lock (replyLock) {
                        DMessage request = requests.Dequeue();
                        replies.Add(request, message);
                    }
                }
            }
        }
 private void OnDetached(object sender, EventArgs e)
 {
     Detached?.Invoke(sender, e);
 }
Пример #30
0
 private void _device_Removed()
 {
     EndPoint = null;
     Detached?.Invoke(this, null);
 }