Esempio n. 1
0
        /// <summary>
        /// Process method checks for presence of a session id and sequence
        /// number. If they do not exist then they are initialized in evidence.
        /// If they do exist in evidence then the sequence number is incremented
        /// and added back to the evidence.
        /// </summary>
        /// <param name="data">
        /// The <see cref="IFlowData"/> instance to process.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Thrown if the supplied data instance is null
        /// </exception>
        protected override void ProcessInternal(IFlowData data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            var evidence = data.GetEvidence().AsDictionary();

            // If the evidence does not contain a session id then create a new one.
            if (evidence.ContainsKey(Constants.EVIDENCE_SESSIONID) == false)
            {
                data.AddEvidence(Constants.EVIDENCE_SESSIONID, GetNewSessionId());
            }

            // If the evidence does not have a sequence then add one. Otherwise
            // increment it.
            if (evidence.ContainsKey(Constants.EVIDENCE_SEQUENCE) == false)
            {
                data.AddEvidence(Constants.EVIDENCE_SEQUENCE, 1);
            }
            else if (evidence.TryGetValue(Constants.EVIDENCE_SEQUENCE, out object sequence))
            {
                if (sequence is int result || (sequence is string seq && int.TryParse(seq, out result)))
                {
                    data.AddEvidence(Constants.EVIDENCE_SEQUENCE, result + 1);
                }
                else
                {
                    data.AddError(new Exception(Messages.MessageFailSequenceNumberParse), this);
                    Logger.LogError(Messages.MessageFailSequenceNumberIncrement);
                }
            }
Esempio n. 2
0
 /// <summary>
 /// Check if the given key is needed by the given flowdata.
 /// If it is then add it as evidence.
 /// </summary>
 /// <param name="flowData">
 /// The <see cref="IFlowData"/> to add the evidence to.
 /// </param>
 /// <param name="key">
 /// The evidence key
 /// </param>
 /// <param name="value">
 /// The evidence value
 /// </param>
 private static void CheckAndAdd(IFlowData flowData, string key, object value)
 {
     if (flowData.EvidenceKeyFilter.Include(key))
     {
         flowData.AddEvidence(key, value);
     }
 }