main
cs 68 lines 1.82 KB
Raw
1 // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3 using System;
4 using System.IO;
5 using System.Collections;
6
7 namespace WixToolset.Dtf.Tools.DDiff
8 {
9 public interface IDiffEngine
10 {
11 float GetDiffQuality(string diffInput1, string diffInput2, string[] options, IDiffEngineFactory diffFactory);
12
13 bool GetDiff(string diffInput1, string diffInput2, string[] options, TextWriter diffOutput, string linePrefix, IDiffEngineFactory diffFactory);
14
15 IDiffEngine Clone();
16 }
17
18 public interface IDiffEngineFactory
19 {
20 IDiffEngine GetDiffEngine(string diffInput1, string diffInput2, string[] options);
21 }
22
23 public class BestQualityDiffEngineFactory : IDiffEngineFactory
24 {
25 public virtual IDiffEngine GetDiffEngine(string diffInput1, string diffInput2, string[] options)
26 {
27 float bestDiffQuality = 0;
28 IDiffEngine bestDiffEngine = null;
29
30 foreach(IDiffEngine diffEngine in diffEngines)
31 {
32 float diffQuality = diffEngine.GetDiffQuality(diffInput1, diffInput2, options, this);
33 if(diffQuality > bestDiffQuality)
34 {
35 bestDiffQuality = diffQuality;
36 bestDiffEngine = diffEngine;
37 }
38 }
39 return (bestDiffEngine != null ? bestDiffEngine.Clone() : null);
40 }
41
42 public BestQualityDiffEngineFactory() : this(null) { }
43 public BestQualityDiffEngineFactory(IDiffEngine[] diffEngines)
44 {
45 this.diffEngines = (diffEngines != null ? new ArrayList(diffEngines) : new ArrayList());
46 }
47
48 protected IList diffEngines;
49
50 public virtual void Add(IDiffEngine diffEngine)
51 {
52 diffEngines.Add(diffEngine);
53 }
54
55 public virtual void Remove(IDiffEngine diffEngine)
56 {
57 diffEngines.Remove(diffEngine);
58 }
59
60 public IList DiffEngines
61 {
62 get
63 {
64 return ArrayList.ReadOnly(diffEngines);
65 }
66 }
67 }
68 }