Example #1
0
        /// <summary>
        /// Compare 2 models
        /// </summary>
        /// <param name="modelManager"></param>
        /// <returns></returns>
        public bool CompareModels(ModelManager2 modelManager)
        {
            bool success = true;

            //
            Analyze();
            modelManager.Analyze();
            StreamWriter streamWriter = null;

            try
            {
                string found    = "<Found>";
                string notFound = "<NotFound>";
                streamWriter = new StreamWriter(new MemoryStream(), System.Text.ASCIIEncoding.ASCII);
#if DEBUG
                int debugCount = 0;
#endif // DEBUG
                foreach (DescriptorInfo descriptorToFind in modelManager._descriptorManager.SelectedDescriptors)
                {
                    bool match = _descriptorManager.IsDescriptorMatch(descriptorToFind, streamWriter);
                    success &= match;
                    streamWriter.Flush();
                    if (match)
                    {
                        // add to "found" section
                        found += System.Text.ASCIIEncoding.ASCII.GetString(((MemoryStream)(streamWriter.BaseStream)).GetBuffer()).Trim('\0');
                    }
                    else
                    {
                        // add to "NotFound" section
                        notFound += System.Text.ASCIIEncoding.ASCII.GetString(((MemoryStream)(streamWriter.BaseStream)).GetBuffer()).Trim('\0');
                    }
#if DEBUG
                    debugCount++;
#endif // DEBUG
                }
                found    += "</Found>";
                notFound += "</NotFound>";

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml("<DescriptorsDifferences result='" + success.ToString() + "'>" + found + notFound + "</DescriptorsDifferences>");

                _modelDifferences = xmlDoc.DocumentElement;
            }
            finally
            {
                if (streamWriter != null)
                {
                    streamWriter.Close(); streamWriter = null;
                }
            }
            if (success == false)
            {
                _failurePackage = Package.Create(true);
                _failurePackage.PackageCompare = PackageCompareTypes.ModelAnalytical;
                _failurePackage.MasterBitmap   = ImageUtility.ToBitmap(modelManager.Image); // if MasterBitmap clonethe bmp, we need to dispose the original here
                _failurePackage.MasterModel    = modelManager.Descriptors.Serialize();      // if MasterModel clone the stream, we need to close it here
                _failurePackage.CapturedBitmap = ImageUtility.ToBitmap(this.Image);         // if MasterBitmap clonethe bmp, we need to dispose the original here
                _failurePackage.XmlDiff        = this.ModelDifferences;
            }
            return(success);
        }