Example #1
0
        /// <summary>
        /// Initializes a new instance of the CompareStreamData class and sets all properties based on the StreamData provided
        /// </summary>
        /// <param name="leftStream">First StreamData object to use for comparison</param>
        /// <param name="rightStream">Second StreamData object to use for comparison</param>
        public CompareStreamData(StreamData leftStream, StreamData rightStream)
        {
            if (leftStream == null && rightStream == null)
            {
                throw new InvalidOperationException(Strings.ErrorNoStreams);
            }

            this.StreamName = Strings.Unknown;
            this.LeftPublicMetadataCount    = 0;
            this.RightPublicMetadataCount   = 0;
            this.LeftPersonalMetadataCount  = 0;
            this.RightPersonalMetadataCount = 0;
            string          dataTypeIdKey         = Strings.DataTypeIdHeader;
            string          semanticIdKey         = Strings.SemanticIdHeader;
            string          eventCountKey         = Strings.EventCountHeader;
            string          startTimeKey          = Strings.StreamStartTimeHeader;
            string          endTimeKey            = Strings.StreamEndTimeHeader;
            string          leftSemanticId        = string.Empty;
            string          rightSemanticId       = string.Empty;
            string          leftEventCount        = string.Empty;
            string          rightEventCount       = string.Empty;
            string          leftStartTime         = string.Empty;
            string          rightStartTime        = string.Empty;
            string          leftEndTime           = string.Empty;
            string          rightEndTime          = string.Empty;
            string          leftDataTypeId        = string.Empty;
            string          rightDataTypeId       = string.Empty;
            KStudioMetadata leftPublicMetadata    = null;
            KStudioMetadata rightPublicMetadata   = null;
            KStudioMetadata leftPersonalMetadata  = null;
            KStudioMetadata rightPersonalMetadata = null;

            if (leftStream != null)
            {
                this.StreamName                = leftStream.EventStream.DataTypeName;
                leftSemanticId                 = leftStream.EventStream.SemanticId.ToString();
                leftEventCount                 = leftStream.EventHeaders.Count.ToString();
                leftStartTime                  = leftStream.StartTime.ToString();
                leftEndTime                    = leftStream.EndTime.ToString();
                leftDataTypeId                 = leftStream.EventStream.DataTypeId.ToString();
                leftPublicMetadata             = leftStream.PublicMetadata;
                leftPersonalMetadata           = leftStream.PersonalMetadata;
                this.LeftPublicMetadataCount   = leftStream.PublicMetadata.Count;
                this.LeftPersonalMetadataCount = leftStream.PersonalMetadata.Count;
            }

            if (rightStream != null)
            {
                if (leftStream == null)
                {
                    this.StreamName = rightStream.EventStream.DataTypeName;
                }

                rightSemanticId                 = rightStream.EventStream.SemanticId.ToString();
                rightEventCount                 = rightStream.EventHeaders.Count.ToString();
                rightStartTime                  = rightStream.StartTime.ToString();
                rightEndTime                    = rightStream.EndTime.ToString();
                rightDataTypeId                 = rightStream.EventStream.DataTypeId.ToString();
                rightPublicMetadata             = rightStream.PublicMetadata;
                rightPersonalMetadata           = rightStream.PersonalMetadata;
                this.RightPublicMetadataCount   = rightStream.PublicMetadata.Count;
                this.RightPersonalMetadataCount = rightStream.PersonalMetadata.Count;
            }

            // compare stream metadata
            bool samePublicMetadata   = true;
            bool samePersonalMetadata = true;

            this.PublicMetadata   = CompareFileData.CompareMetadata(leftPublicMetadata, rightPublicMetadata, out samePublicMetadata);
            this.PersonalMetadata = CompareFileData.CompareMetadata(leftPersonalMetadata, rightPersonalMetadata, out samePersonalMetadata);

            if (this.LeftPublicMetadataCount == 0 && this.RightPublicMetadataCount == 0)
            {
                this.StreamPublicMetadataCompareText = string.Format(Strings.PublicMetadataHeader, Strings.None);
            }
            else
            {
                this.StreamPublicMetadataCompareText = string.Format(Strings.PublicMetadataHeader, samePublicMetadata ? Strings.Same : Strings.Different);
            }

            if (this.LeftPersonalMetadataCount == 0 && this.RightPersonalMetadataCount == 0)
            {
                this.StreamPersonalMetadataCompareText = string.Format(Strings.PersonalMetadataHeader, Strings.None);
            }
            else
            {
                this.StreamPersonalMetadataCompareText = string.Format(Strings.PersonalMetadataHeader, samePersonalMetadata ? Strings.Same : Strings.Different);
            }

            // compare stream details
            this.StreamDetails = new ObservableCollection <CompareData>();
            this.StreamDetails.Add(new CompareData(dataTypeIdKey, leftDataTypeId, rightDataTypeId));
            this.StreamDetails.Add(new CompareData(semanticIdKey, leftSemanticId, rightSemanticId));
            this.StreamDetails.Add(new CompareData(eventCountKey, leftEventCount, rightEventCount));
            this.StreamDetails.Add(new CompareData(startTimeKey, leftStartTime, rightStartTime));
            this.StreamDetails.Add(new CompareData(endTimeKey, leftEndTime, rightEndTime));

            bool sameDetails = this.StreamDetails.All(data => data.Same);

            this.StreamDetailsCompareText = string.Format(Strings.StreamDetailsHeader, sameDetails ? Strings.Same : Strings.Different);

            this.Same = (samePublicMetadata && samePersonalMetadata && sameDetails) ? true : false;
        }
Example #2
0
        /// <summary>
        /// Compares similar streams from two different files together
        /// </summary>
        /// <param name="leftStreams">Stream list from first file to use in comparison</param>
        /// <param name="rightStreams">Stream list from second file to use in comparison</param>
        /// <returns>Collection of CompareStreamData, which contains comparison results of all streams</returns>
        internal static ObservableCollection <CompareStreamData> CompareStreams(IEnumerable <StreamData> leftStreams, IEnumerable <StreamData> rightStreams)
        {
            ObservableCollection <CompareStreamData> compareStreams = new ObservableCollection <CompareStreamData>();
            List <string> streamNames = new List <string>();

            // find unique and shared streams across both files
            if (leftStreams != null)
            {
                foreach (StreamData stream in leftStreams)
                {
                    streamNames.Add(stream.EventStream.DataTypeName);
                }
            }

            if (rightStreams != null)
            {
                foreach (StreamData stream in rightStreams)
                {
                    if (!streamNames.Contains(stream.EventStream.DataTypeName))
                    {
                        streamNames.Add(stream.EventStream.DataTypeName);
                    }
                }
            }

            // loop through each stream to compare between files
            foreach (string streamName in streamNames)
            {
                StreamData leftStream  = null;
                StreamData rightStream = null;

                // find stream in left file
                if (leftStreams != null)
                {
                    foreach (StreamData stream in leftStreams)
                    {
                        if (stream.EventStream.DataTypeName.Equals(streamName))
                        {
                            leftStream = stream;
                            break;
                        }
                    }
                }

                // find stream in right file
                if (rightStreams != null)
                {
                    foreach (StreamData stream in rightStreams)
                    {
                        if (stream.EventStream.DataTypeName.Equals(streamName))
                        {
                            rightStream = stream;
                            break;
                        }
                    }
                }

                compareStreams.Add(new CompareStreamData(leftStream, rightStream));
            }

            return(compareStreams);
        }