Beispiel #1
0
        public static string GetCorrectedXaml(string xml, LabelReplacer replacer)
        {
            try
            {
                xml = xml ?? string.Empty;

                xml = ContentComparerHelper.RemoveDiacritics(xml);

                if (!TryParseXml(xml, out XElement doc))
                {
                    return(xml);
                }

                replacer.FullfillLabelsForWorkflow(doc);

                RemoveEmptyXMLText(doc);

                RenameClasses(doc);

                WorkflowUsedEntitiesHandler.ReplaceGuids(doc);

                return(doc.ToString());
            }
            catch (Exception ex)
            {
                DTEHelper.WriteExceptionToOutput(null, ex);

#if DEBUG
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    System.Diagnostics.Debugger.Break();
                }
#endif

                throw;
            }
        }
Beispiel #2
0
        public static ContentCompareResult CompareWorkflowXAML(string xml1, string xml2, LabelReplacer rep1, LabelReplacer rep2, bool withDetails = false)
        {
            try
            {
                xml1 = xml1 ?? string.Empty;
                xml2 = xml2 ?? string.Empty;

                xml1 = ContentComparerHelper.RemoveDiacritics(xml1);
                xml2 = ContentComparerHelper.RemoveDiacritics(xml2);

                diff_match_patch match = new diff_match_patch
                {
                    Diff_Timeout = ContentComparerHelper.Diff_Timeout
                };

                if (string.IsNullOrEmpty(xml1) && string.IsNullOrEmpty(xml2))
                {
                    return(new ContentCompareResult(true, null));
                }

                if (string.IsNullOrEmpty(xml1) && !string.IsNullOrEmpty(xml2))
                {
                    return(new ContentCompareResult(false, match.diff_main(xml1, xml2, false)));
                }

                if (!string.IsNullOrEmpty(xml1) && string.IsNullOrEmpty(xml2))
                {
                    return(new ContentCompareResult(false, match.diff_main(xml1, xml2, false)));
                }

                if (!TryParseXml(xml1, out XElement doc1) || !TryParseXml(xml2, out XElement doc2))
                {
                    bool isEqual = string.Equals(xml1, xml2);

                    if (isEqual)
                    {
                        return(new ContentCompareResult(true, null));
                    }
                    else
                    {
                        if (withDetails)
                        {
                            return(new ContentCompareResult(false, match.diff_main(xml1, xml2, false)));
                        }
                        else
                        {
                            return(new ContentCompareResult(false, null));
                        }
                    }
                }

                RemoveEmptyElements(doc1);
                RemoveEmptyElements(doc2);

                RenameClasses(doc1);
                RenameClasses(doc2);

                WorkflowUsedEntitiesHandler.ReplaceGuids(doc1);
                WorkflowUsedEntitiesHandler.ReplaceGuids(doc2);

                if (rep1 != null)
                {
                    rep1.FullfillLabelsForWorkflow(doc1);
                }

                if (rep2 != null)
                {
                    rep2.FullfillLabelsForWorkflow(doc2);
                }

                {
                    bool isEqual = XNode.DeepEquals(doc1, doc2);

                    if (isEqual)
                    {
                        return(new ContentCompareResult(true, null));
                    }
                    else
                    {
                        if (withDetails)
                        {
                            return(new ContentCompareResult(false, match.diff_main(doc1.ToString(), doc2.ToString(), false)));
                        }
                        else
                        {
                            return(new ContentCompareResult(false, null));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                DTEHelper.WriteExceptionToOutput(null, ex);

#if DEBUG
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    System.Diagnostics.Debugger.Break();
                }
#endif

                throw;
            }
        }