Beispiel #1
0
        /// <summary>
        /// Cretaes a CompareRules instance using an xml file as input.
        /// </summary>
        /// <param name="fullFileName">Full file name of the .xml file.</param>
        /// <returns>The created CompareRules instance.</returns>
        public static CompareRules Deserialize(String fullFileName)
        {
            FileStream   myFileStream = null;
            CompareRules compareRules = null;

            try
            {
                XmlSerializer mySerializer = new XmlSerializer(typeof(CompareRules));

                // To read the file, creates a FileStream.
                myFileStream = new FileStream(fullFileName, FileMode.Open);

                // Calls the Deserialize method and casts to the object type.
                compareRules = (CompareRules)mySerializer.Deserialize(myFileStream);
            }
            catch (System.Exception exception)
            {
                // Rethrow exception.
                throw(exception);
            }
            finally
            {
                if (myFileStream != null)
                {
                    myFileStream.Close();
                }
            }

            myFileStream.Close();

            return(compareRules);
        }
Beispiel #2
0
        internal CompareRules Clone()
        {
#pragma warning disable 0618
            CompareRules clonedCompareRules = new CompareRules();
#pragma warning restore 0618

            clonedCompareRules.generalAttributeCollectionDescriptions = this.generalAttributeCollectionDescriptions;
            clonedCompareRules.compareRules = this.compareRules.Clone() as ArrayList;

            return(clonedCompareRules);
        }
Beispiel #3
0
        internal void AddAttributeCollectionsInformationUsingDynamicCompare(AttributeCollections attributeCollections, CompareRules compareRules)
        {
            //
            // Iterate through all attributes of all AttributeSets.
            //

            GeneratorDynamicCompare generatorDynamicCompare = new GeneratorDynamicCompare(attributeCollections, compareRules);

            AttributeList attributeList = null;

            while ((attributeList = generatorDynamicCompare.GetNextAttributes()) != null)
            {
                AddAttributesInformation(attributeList);

                if (this.addEmptyRowAfterEachDynamicComparedList)
                {
                    NewRow();

                    for (int columnIndex = 0; columnIndex < this.numberOfColumns; columnIndex++)
                    {
                        SetCellOK(columnIndex + 1, ".");
                    }
                }
            }
        }
Beispiel #4
0
        //
        // - Constructors -
        //

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="compareRules">All the CcompareRules that will be applied to the attributeCollections.</param>
        /// <param name="attributeCollections">All the AttributeCollections on which the CcompareRules will be applied.</param>
        ///


        public GeneratorDynamicCompare(AttributeCollections attributeCollections, CompareRules compareRules)
        {
            this.compareRules         = compareRules;
            this.attributeCollections = attributeCollections;
        }
Beispiel #5
0
        //
        // - Methods -
        //

        /// <summary>
        /// Do a dynamic compare for the attribute sets supplied.
        ///
        /// Note that the parameters attributeSets, attributeSetDescriptions and each compareRule instance in
        /// the parameter compareRules must have the same size and have a size at least 2.
        /// </summary>
        /// <param name="tableDescription">Description of the table.</param>
        /// <param name="attributeCollections">The attribute sets to compare with each other.</param>
        /// <param name="attributeCollectionDescriptions">The descriptions of the attribute sets.</param>
        /// <param name="compareRules">
        /// Specifies which attributes with what tags should be compared with each other.
        /// Also specifies how the attributes should be compared with each other.
        /// </param>
        /// <returns>The results of the dynamic compare presented as a table (that may be converted to HTML).</returns>
        public CompareResults CompareAttributeCollections(String tableDescription, AttributeCollections attributeCollections, StringCollection attributeCollectionDescriptions, CompareRules compareRules)
        {
            //
            // Sanity check.
            //

            if (attributeCollections.Count < 2)
            {
                throw new System.Exception("Parameter attributeSets supplied to the method StaticCompare.CompareAttributeSets has size smaller than 2.");
            }

            if (attributeCollections.Count != attributeCollectionDescriptions.Count)
            {
                throw new System.Exception("Parameters attributeSets and attributeSetDescriptions supplied to the method StaticCompare.CompareAttributeSets have different size.");
            }

            for (int index = 0; index < compareRules.Count; index++)
            {
                CompareRule compareRule = compareRules[index];

                if (attributeCollections.Count != compareRule.Count)
                {
                    throw new System.Exception("Method StaticCompare.CompareAttributeSets: each CompareRule instance present in the parameter compareRules must have the same size as the parameter attributeCollections.");
                }
            }



            // Todo change taking the possibility of null into account for the attribute collections.

            //
            // Remove the attribute collections that are null and adjust the compare rules.
            //

            for (int index = attributeCollections.Count - 1; index >= 0; index--)
            {
                AttributeCollectionBase attributeCollection = attributeCollections[index];

                if (attributeCollection == null)
                {
                    // Clone the collections because we don't want to change the supplied collections.
                    attributeCollections = attributeCollections.Clone();
                    attributeCollections.RemoveAt(index);

                    StringCollection newAttributeCollectionDescriptions = new StringCollection();
                    foreach (String description in attributeCollectionDescriptions)
                    {
                        newAttributeCollectionDescriptions.Add(description);
                    }
                    attributeCollectionDescriptions = newAttributeCollectionDescriptions;
                    attributeCollectionDescriptions.RemoveAt(index);

#pragma warning disable 0618
                    CompareRules newCompareRules = new CompareRules();
#pragma warning restore 0618

                    for (int compareRuleIndex = 0; compareRuleIndex < compareRules.Count; compareRuleIndex++)
                    {
                        CompareRule compareRule = compareRules[compareRuleIndex].Clone();
                        compareRule.RemoveAt(index);
                        newCompareRules.Add(compareRule);
                    }

                    compareRules = newCompareRules;
                }
            }



            //
            // Do the actual compare.
            //

            this.compareResults = null;

            // Determine the index of the different columns in the table.
            int numberOfColumns = DetermineColumnIndices(attributeCollections);

            // To be able to compare correctly, we first make sure the attributes in all DicomAttributeCollections are ascending.
            attributeCollections.DicomMakeAscending();

            // Determine the table headers and comlumn widths.
            this.compareResults = CreateCompareResults(numberOfColumns, attributeCollections, tableDescription, attributeCollectionDescriptions);

            // Do the actual comparison.
            AddAttributeCollectionsInformationUsingDynamicCompare(attributeCollections, compareRules);

            if (this.differenceFound)
            {
                this.compareResults.DifferencesCount++;
                this.differenceFound = false;
            }

            return(this.compareResults);
        }
Beispiel #6
0
        internal void AddAttributeCollectionsInformationUsingDynamicCompare(AttributeCollections attributeCollections, CompareRules compareRules)
        {
            //
            // Iterate through all attributes of all AttributeSets.
            //


            GeneratorDynamicCompare generatorDynamicCompare = new GeneratorDynamicCompare(attributeCollections, compareRules);

            AttributeList attributeList = null;

            while ((attributeList = generatorDynamicCompare.GetNextAttributes()) != null)
            {
                AddAttributesInformation(attributeList);

                if (this.addEmptyRowAfterEachDynamicComparedList)
                {
                    NewRow();

                    for (int columnIndex = 0; columnIndex < this.numberOfColumns; columnIndex++)
                    {
                        SetCellOK(columnIndex + 1, ".");
                    }
                }
            }
        }
Beispiel #7
0
        internal CompareRules Clone()
        {
            #pragma warning disable 0618
            CompareRules clonedCompareRules = new CompareRules();
            #pragma warning restore 0618

            clonedCompareRules.generalAttributeCollectionDescriptions = this.generalAttributeCollectionDescriptions;
            clonedCompareRules.compareRules = this.compareRules.Clone() as ArrayList;

            return(clonedCompareRules);
        }
Beispiel #8
0
        //
        // - Methods -
        //
        /// <summary>
        /// Do a dynamic compare for the attribute sets supplied.
        /// 
        /// Note that the parameters attributeSets, attributeSetDescriptions and each compareRule instance in
        /// the parameter compareRules must have the same size and have a size at least 2.
        /// </summary>
        /// <param name="tableDescription">Description of the table.</param>
        /// <param name="attributeCollections">The attribute sets to compare with each other.</param>
        /// <param name="attributeCollectionDescriptions">The descriptions of the attribute sets.</param>
        /// <param name="compareRules">
        /// Specifies which attributes with what tags should be compared with each other.
        /// Also specifies how the attributes should be compared with each other.
        /// </param>
        /// <returns>The results of the dynamic compare presented as a table (that may be converted to HTML).</returns>
        public CompareResults CompareAttributeCollections(String tableDescription, AttributeCollections attributeCollections, StringCollection attributeCollectionDescriptions, CompareRules compareRules)
        {
            //
            // Sanity check.
            //

            if (attributeCollections.Count < 2)
            {
                throw new System.Exception("Parameter attributeSets supplied to the method StaticCompare.CompareAttributeSets has size smaller than 2.");
            }

            if (attributeCollections.Count != attributeCollectionDescriptions.Count)
            {
                throw new System.Exception("Parameters attributeSets and attributeSetDescriptions supplied to the method StaticCompare.CompareAttributeSets have different size.");
            }

            for (int index = 0; index < compareRules.Count; index++)
            {
                CompareRule compareRule = compareRules[index];

                if (attributeCollections.Count != compareRule.Count)
                {
                    throw new System.Exception("Method StaticCompare.CompareAttributeSets: each CompareRule instance present in the parameter compareRules must have the same size as the parameter attributeCollections.");
                }
            }

            // Todo change taking the possibility of null into account for the attribute collections.

            //
            // Remove the attribute collections that are null and adjust the compare rules.
            //

            for (int index = attributeCollections.Count - 1; index >= 0; index--)
            {
                AttributeCollectionBase attributeCollection = attributeCollections[index];

                if (attributeCollection == null)
                {
                    // Clone the collections because we don't want to change the supplied collections.
                    attributeCollections = attributeCollections.Clone();
                    attributeCollections.RemoveAt(index);

                    StringCollection newAttributeCollectionDescriptions = new StringCollection();
                    foreach(String description in attributeCollectionDescriptions)
                    {
                        newAttributeCollectionDescriptions.Add(description);
                    }
                    attributeCollectionDescriptions = newAttributeCollectionDescriptions;
                    attributeCollectionDescriptions.RemoveAt(index);

            #pragma warning disable 0618
                    CompareRules newCompareRules = new CompareRules();
            #pragma warning restore 0618

                    for (int compareRuleIndex = 0; compareRuleIndex < compareRules.Count; compareRuleIndex++)
                    {
                        CompareRule compareRule = compareRules[compareRuleIndex].Clone();
                        compareRule.RemoveAt(index);
                        newCompareRules.Add(compareRule);
                    }

                    compareRules = newCompareRules;
                }
            }

            //
            // Do the actual compare.
            //

            this.compareResults = null;

            // Determine the index of the different columns in the table.
            int numberOfColumns = DetermineColumnIndices(attributeCollections);

            // To be able to compare correctly, we first make sure the attributes in all DicomAttributeCollections are ascending.
            attributeCollections.DicomMakeAscending();

            // Determine the table headers and comlumn widths.
            this.compareResults = CreateCompareResults(numberOfColumns, attributeCollections, tableDescription, attributeCollectionDescriptions);

            // Do the actual comparison.
            AddAttributeCollectionsInformationUsingDynamicCompare(attributeCollections, compareRules);

            if (this.differenceFound)
            {
                this.compareResults.DifferencesCount++;
                this.differenceFound = false;
            }

            return(this.compareResults);
        }
 //
 // - Constructors -
 //
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="compareRules">All the CcompareRules that will be applied to the attributeCollections.</param>
 /// <param name="attributeCollections">All the AttributeCollections on which the CcompareRules will be applied.</param>
 /// 
 public GeneratorDynamicCompare(AttributeCollections attributeCollections, CompareRules compareRules)
 {
     this.compareRules = compareRules;
     this.attributeCollections = attributeCollections;
 }