Ejemplo n.º 1
0
        /// <summary>
        /// Handles the signaling of this <see cref="DataWatcher"/>.
        /// </summary>
        protected override void HandleSignaling()
        {
            lock (_locker)
            {
                DateTime        utcLastModified = DateTime.UtcNow;
                List <object[]> values          = new List <object[]>();
                DataManager     manager         = Manager.Clone();
                using (DbDataReader reader = manager.ExecuteReader(Command, Parameters))
                {
                    while (reader.Read())
                    {
                        object[] readerValues = new object[reader.FieldCount];
                        reader.GetValues(readerValues);
                        values.Add(readerValues);
                    }
                }
                long currentSignature = StructUtility.GetHashCode64(EnumerableConverter.Parse(values, o => o.GetHashCode()));
                values.Clear();

                if (Signature == 0)
                {
                    Signature = currentSignature;
                }
                if (!Signature.Equals(currentSignature))
                {
                    SetUtcLastModified(utcLastModified);
                    OnChangedRaised();
                }
                Signature = currentSignature;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Combines a sequence of objects into one object, and computes a hash value of the specified <paramref name="values"/>.
        /// </summary>
        /// <param name="values">The objects to compute a hash code for.</param>
        /// <param name="setup">The <see cref="HashOptions"/> which need to be configured.</param>
        /// <returns>A <see cref="HashResult"/> containing the computed hash value of the specified object sequence <paramref name="values"/>.</returns>
        public static HashResult ComputeHash(object[] values, Action <HashOptions> setup = null)
        {
            Validator.ThrowIfNull(values, nameof(values));
            var  options   = setup.ConfigureOptions();
            long signature = StructUtility.GetHashCode64(EnumerableConverter.Parse(values, o => o.GetHashCode()));

            return(ComputeHash(BitConverter.GetBytes(signature), o => o.AlgorithmType = options.AlgorithmType));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Combines the <paramref name="additionalChecksum"/> to the representation of this instance.
        /// </summary>
        /// <param name="additionalChecksum">A <see cref="String"/> array that contains zero or more checksums of the additional data this instance must represent.</param>
        public ChecksumBuilder CombineWith(params string[] additionalChecksum)
        {
            List <long> result = new List <long>();

            if (additionalChecksum == null)
            {
                result.Add(StructUtility.HashCodeForNullValue);
            }
            else
            {
                for (int i = 0; i < additionalChecksum.Length; i++)
                {
                    result.Add(StructUtility.GetHashCode64(additionalChecksum[i]));
                }
            }
            return(CombineWith(result.ToArray()));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Computes and returns a MD5 signature of the following properties: <see cref="P:Cuemon.IO.JsonInstance.Name"/>, <see cref="P:Cuemon.IO.JsonInstance.Value"/>, <see cref="P:Cuemon.IO.JsonInstance.NodeNumber"/> and <see cref="NodeType"/>.
 /// </summary>
 /// <returns>
 /// A MD5 signature of the following properties: <see cref="P:Cuemon.IO.JsonInstance.Name"/>, <see cref="P:Cuemon.IO.JsonInstance.Value"/>, <see cref="P:Cuemon.IO.JsonInstance.NodeNumber"/> and <see cref="NodeType"/>.
 /// </returns>
 public override string GetSignature()
 {
     return(StructUtility.GetHashCode64(string.Concat(Name, Value, NodeNumber, Enum.GetName(typeof(XPathNodeType), NodeType))).ToString());
 }
Ejemplo n.º 5
0
 private static long GenerateGroupKey(string key, string group)
 {
     return(StructUtility.GetHashCode64(group == NoGroup ? key : string.Concat(key, group)));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CacheValidator"/> class.
 /// </summary>
 /// <param name="created">A <see cref="DateTime"/> value for when data this instance represents was first created.</param>
 /// <param name="modified">A <see cref="DateTime"/> value for when data this instance represents was last modified.</param>
 /// <param name="checksum">A <see cref="String"/> value containing a byte-for-byte checksum of the data this instance represents.</param>
 /// <param name="setup">The <see cref="CacheValidatorOptions"/> which need to be configured.</param>
 public CacheValidator(DateTime created, DateTime?modified, string checksum, Action <CacheValidatorOptions> setup = null)
     : this(created, modified, checksum == null ? StructUtility.HashCodeForNullValue : StructUtility.GetHashCode64(checksum), setup)
 {
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Computes and returns a MD5 signature of the following properties: <see cref="Name"/>, <see cref="Value"/> and <see cref="NodeNumber"/>.
 /// </summary>
 /// <returns>A MD5 signature of the following properties: <see cref="Name"/>, <see cref="Value"/> and <see cref="NodeNumber"/>.</returns>
 public virtual string GetSignature()
 {
     return(StructUtility.GetHashCode64(string.Concat(Name, Value, NodeNumber)).ToString(CultureInfo.InvariantCulture));
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ChecksumBuilder"/> class.
 /// </summary>
 /// <param name="checksum">A <see cref="String"/> value containing a byte-for-byte checksum of the data this instance represents.</param>
 /// <param name="setup">The <see cref="ChecksumBuilderOptions"/> which need to be configured.</param>
 public ChecksumBuilder(string checksum, Action <ChecksumBuilderOptions> setup = null) : this(checksum == null ? StructUtility.HashCodeForNullValue : StructUtility.GetHashCode64(checksum), setup)
 {
 }