Exemple #1
0
        internal void AssertEquivalentTo(SymbolTreeInfo other)
        {
            Debug.Assert(Checksum.Equals(other.Checksum));
            Debug.Assert(_concatenatedNames == other._concatenatedNames);
            Debug.Assert(_nodes.Length == other._nodes.Length);

            for (int i = 0, n = _nodes.Length; i < n; i++)
            {
                _nodes[i].AssertEquivalentTo(other._nodes[i]);
            }

            Debug.Assert(_inheritanceMap.Keys.Count == other._inheritanceMap.Keys.Count);
            var orderedKeys1 = this._inheritanceMap.Keys.Order().ToList();
            var orderedKeys2 = other._inheritanceMap.Keys.Order().ToList();

            for (int i = 0; i < orderedKeys1.Count; i++)
            {
                var values1 = this._inheritanceMap[i];
                var values2 = other._inheritanceMap[i];

                Debug.Assert(values1.Length == values2.Length);
                for (int j = 0; j < values1.Length; j++)
                {
                    Debug.Assert(values1[j] == values2[j]);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Verify a checksum.
        /// </summary>
        /// <param name="fullPath">The path to the file.</param>
        public void VerifyChecksum(string fullPath)
        {
            MD5 md5 = new MD5CryptoServiceProvider();

            if (md5.GetType().ToString().Equals(ChecksumType))
            {
                using (FileStream file = new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    byte[] retVal = md5.ComputeHash(file);
                    file.Close();

                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < retVal.Length; i++)
                    {
                        sb.Append(retVal[i].ToString("x2"));
                    }

                    if (!Checksum.Equals(sb.ToString()))
                    {
                        throw new ApplicationException("Checksum does not match for file " + fullPath);
                    }
                }
            }
            else
            {
                throw new ApplicationException("Unknown checksum type: " + ChecksumType);
            }
        }
Exemple #3
0
 /// <summary>
 /// True iff the two objects are equal Layers.
 /// </summary>
 public bool Equals(GreLayer other)
 {
     return(other != null &&
            Version.Equals(other.Version) &&
            ProtocolType.Equals(other.ProtocolType) &&
            RecursionControl.Equals(other.RecursionControl) &&
            FutureUseBits.Equals(other.FutureUseBits) &&
            ChecksumPresent.Equals(other.ChecksumPresent) &&
            (Checksum == null ? other.Checksum == null : Checksum.Equals(other.Checksum)) &&
            (Key == null ? other.Key == null : Key.Equals(other.Key)) &&
            (SequenceNumber == null ? other.SequenceNumber == null : SequenceNumber.Equals(other.SequenceNumber)) &&
            (AcknowledgmentSequenceNumber == null ? other.AcknowledgmentSequenceNumber == null : AcknowledgmentSequenceNumber.Equals(other.AcknowledgmentSequenceNumber)) &&
            (RoutingOffset == null ? other.RoutingOffset == null : RoutingOffset.Equals(other.RoutingOffset)) &&
            (Routing == null ? other.Routing == null : Routing.SequenceEqual(other.Routing)) &&
            StrictSourceRoute.Equals(other.StrictSourceRoute));
 }
Exemple #4
0
 /// <exception cref="System.IO.IOException"/>
 /// <exception cref="System.Exception"/>
 protected override void Reduce(Text key, IEnumerable <Text> values, Reducer.Context
                                context)
 {
     if (Error.Equals(key))
     {
         foreach (Text val in values)
         {
             context.Write(key, val);
         }
     }
     else
     {
         if (Checksum.Equals(key))
         {
             Unsigned16 tmp = new Unsigned16();
             Unsigned16 sum = new Unsigned16();
             foreach (Text val in values)
             {
                 tmp.Set(val.ToString());
                 sum.Add(tmp);
             }
             context.Write(Checksum, new Text(sum.ToString()));
         }
         else
         {
             Text value = values.GetEnumerator().Next();
             if (firstKey)
             {
                 firstKey = false;
             }
             else
             {
                 if (value.CompareTo(lastValue) < 0)
                 {
                     context.Write(Error, new Text("bad key partitioning:\n  file " + lastKey + " key "
                                                   + TextifyBytes(lastValue) + "\n  file " + key + " key " + TextifyBytes(value)));
                 }
             }
             lastKey.Set(key);
             lastValue.Set(value);
         }
     }
 }
Exemple #5
0
        static void Main(string[] args)
        {
            byte[] test = new byte[10];

            test[0] = 0b11111111;
            test[1] = 0b11111111;
            test[2] = 0b00000001;
            test[3] = 0b00000001;
            test[4] = 0b00000001;
            test[5] = 0b00000001;
            test[6] = 0b00000001;
            test[7] = 0b00000001;
            test[8] = 0b00000001;
            test[9] = 0b00000001;

            var chksum1 = new Checksum(test);
            var chksum2 = new Checksum(test);

            // Should be the same
            Console.WriteLine(chksum1.Equals(chksum2));
            Console.WriteLine(chksum1 == chksum2);

            //Console.WriteLine(Convert.ToString(chksum1.Value, 2));
        }