< Summary - pva.SuperV

Information
Class: pva.SuperV.Engine.Processing.ScriptBase
Assembly: pva.SuperV.Engine
File(s): /home/runner/work/pva.SuperV/pva.SuperV/pva.SuperV.Engine/Processing/ScriptBase.cs
Tag: dotnet-ubuntu_22190969454
Line coverage
87%
Covered lines: 28
Uncovered lines: 4
Coverable lines: 32
Total lines: 97
Line coverage: 87.5%
Branch coverage
87%
Covered branches: 7
Total branches: 8
Branch coverage: 87.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Project()100%11100%
get_ScriptDefinition()100%11100%
get_Instances()100%11100%
RegisterForTopicNotification()87.5%9878.94%
HandleFieldValueChangeInternal(...)100%11100%

File(s)

/home/runner/work/pva.SuperV/pva.SuperV/pva.SuperV.Engine/Processing/ScriptBase.cs

#LineLine coverage
 1using pva.Helpers.Extensions;
 2using pva.SuperV.Engine.Exceptions;
 3using System.Threading.Channels;
 4
 5namespace pva.SuperV.Engine.Processing
 6{
 7    /// <summary>
 8    /// Base class for the generated scripts.
 9    /// </summary>
 10    /// <param name="project">Project where the script is running.</param>
 11    /// <param name="scriptDefinition">Script definition for the script.</param>
 11512    public abstract class ScriptBase(RunnableProject project, ScriptDefinition scriptDefinition)
 13    {
 14        /// <summary>
 15        /// The changed instance constant for instance.
 16        /// </summary>
 17        public const string ChangedInstance = "ChangedInstance";
 18
 19        /// <summary>
 20        /// Gets the project.
 21        /// </summary>
 22        /// <value>
 23        /// The project.
 24        /// </value>
 23425        protected RunnableProject Project { get; } = project;
 26        /// <summary>
 27        /// Gets the script definition.
 28        /// </summary>
 29        /// <value>
 30        /// The script definition.
 31        /// </value>
 23232        protected ScriptDefinition ScriptDefinition { get; } = scriptDefinition;
 33        /// <summary>
 34        /// Gets the instances.
 35        /// </summary>
 36        /// <value>
 37        /// The instances.
 38        /// </value>
 12339        protected Dictionary<string, IInstance> Instances { get; } = [];
 40
 41        /// <summary>
 42        /// Registers the script for topic notification.
 43        /// </summary>
 44        /// <returns>The value task.</returns>
 45        /// <exception cref="SuperVException">Error while processing topic notification.</exception>
 46        /// <exception cref="UnknownEntityException">Unknown topic</exception>
 47        public async ValueTask RegisterForTopicNotification()
 11548        {
 11549            if (Project.TopicsChannels.TryGetValue(ScriptDefinition.TopicName, out Channel<FieldValueChangedEvent>? noti
 11550            {
 51                try
 11552                {
 11753                    while (await notificationChannel.Reader.WaitToReadAsync())
 254                    {
 455                        while (notificationChannel.Reader.TryRead(out FieldValueChangedEvent? fieldValueChangedEvent))
 256                        {
 257                            Instances.Clear();
 658                            HashSet<string> instanceReferences = [.. ScriptDefinition.fieldReferences.Select(f => f.Inst
 659                            instanceReferences.Where(instanceName => instanceName != ChangedInstance).ForEach(instanceNa
 260                            {
 261                                IInstance instance = Project.GetInstance(instanceName);
 262                                Instances.Add(instanceName, instance);
 463                            });
 264                            Instances[ChangedInstance] = fieldValueChangedEvent.Field.Instance!;
 265                            HandleFieldValueChangeInternal(Project, Instances, fieldValueChangedEvent);
 266                        }
 267                    }
 11568                    return;
 69                }
 070                catch (Exception e)
 071                {
 072                    throw new SuperVException("Error while processing topic notification.", e);
 73                }
 74            }
 075            throw new UnknownEntityException("topic", ScriptDefinition.TopicName);
 11576        }
 77
 78        /// <summary>
 79        /// Handles the field value change internally. Calls the abstract method HandleFieldValueChange.
 80        /// </summary>
 81        /// <param name="project">The project.</param>
 82        /// <param name="instances">The instances.</param>
 83        /// <param name="fieldValueChangedEvent">The field value changed event.</param>
 84        private void HandleFieldValueChangeInternal(RunnableProject project, Dictionary<string, IInstance> instances, Fi
 285        {
 286            HandleFieldValueChange(project, instances, fieldValueChangedEvent);
 287        }
 88
 89        /// <summary>
 90        /// Handles the field value change. This method must be implemented in the generated class.
 91        /// </summary>
 92        /// <param name="project">The project.</param>
 93        /// <param name="instances">The instances.</param>
 94        /// <param name="fieldValueChangedEvent">The field value changed event.</param>
 95        public abstract void HandleFieldValueChange(RunnableProject project, Dictionary<string, IInstance> instances, Fi
 96    }
 97}