当前位置: 首页>>代码示例>>C#>>正文


C# Differences类代码示例

本文整理汇总了C#中Differences的典型用法代码示例。如果您正苦于以下问题:C# Differences类的具体用法?C# Differences怎么用?C# Differences使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Differences类属于命名空间,在下文中一共展示了Differences类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Fragment

 public Fragment(Differences.FragmentType ThisType, string Part, int Location)
 {
     sb = new StringBuilder();
     Type = ThisType;
     Position = Location;
     sb.Append(Part);
 }
开发者ID:i-e-b,项目名称:DiffTools,代码行数:7,代码来源:Fragment.cs

示例2: ScriptDifferences

 private ExecutionBlock ScriptDifferences(Differences differences)
 {
     var work = new Work();
     work.BuildFromDifferences(differences, Options.Default, true);
     ExecutionBlock block = work.ExecutionBlock;
     return block;
 }
开发者ID:tcabanski,项目名称:SouthSideDevToys,代码行数:7,代码来源:SchemaSyncEngine.cs

示例3: BuildDiffCode

        /// <summary>
        /// Build a code that can be used to transform one version of a file into another.
        /// </summary>
        public static string BuildDiffCode(Differences differences)
        {
            var sb = new StringBuilder();
            int pos = 0;
            int del = 0;
            string ins = "";

            foreach (Fragment frag in differences) {

                if (frag.Type == Differences.FragmentType.Unchanged) {
                    pos += del;
                    pos -= ins.Length;
                    if (del > 0 || ins.Length > 0) {
                        WriteDiffCode(sb, pos-del, del, ins);
                    }
                    pos += frag.Length;
                    del = 0;
                    ins = "";
                } else if (frag.Type == Differences.FragmentType.Deleted) {
                    del += frag.Length;
                } else if (frag.Type == Differences.FragmentType.Inserted) {
                    pos += frag.Length;
                    ins += frag.SplitPart;
                } else {
                    throw new Exception("broken frag type");
                }
            }

            // Don't forget the last one!
            if (del > 0 || ins.Length > 0) {
                WriteDiffCode(sb, pos - del, del, ins);
            }

            return sb.ToString();
        }
开发者ID:i-e-b,项目名称:DiffTools,代码行数:38,代码来源:DiffCode.cs

示例4: GetClosestMatch

 public virtual AttributeNode GetClosestMatch(AttributeNode/*!*/ nd1, AttributeList/*!*/ list1, AttributeList list2, int list1pos, ref int list2start,
   TrivialHashtable/*!*/ matchedNodes, out Differences closestDifferences, out int list2pos) {
   closestDifferences = null; list2pos = -1;
   if (list2 == null) return null;
   if (nd1 == null || list1 == null || matchedNodes == null ||  list1pos < 0 || list1pos >= list1.Count || list2start < 0 || list2start >= list2.Count) {
     Debug.Assert(false); return null;
   }
   AttributeNode closest = null;
   Differences winnerSoFar = null;
   for (int j = list2start, m = list2.Count; j < m; j++){
     AttributeNode nd2 = list2[j];
     if (list2start == j) list2start++;
     if (nd2 == null) continue;
     if (matchedNodes[nd2.UniqueKey] != null) continue;
     Differences diff = this.GetDifferences(nd1, nd2);
     if (diff == null){Debug.Assert(false); continue;}
     if (diff.Similarity <= 0.5){
       //Not a good enough match
       if (list2start == j+1) list2start--; //The next call to GetClosestMatch will start looking at list2start, so this node will be considered then
       continue; //ignore it for the rest of this call
     }
     if (winnerSoFar != null && winnerSoFar.Similarity >= diff.Similarity) continue;
     winnerSoFar = closestDifferences = diff;
     closest = nd2;
     list2pos = j;
     if (diff.NumberOfDifferences == 0) return closest; //Perfect match, no need to look for other matches
   }
   if (closest != null){
     //^ assert winnerSoFar != null;
     //closest is closer to nd1 than any other node in list2, but this is no good if some other node in list1 has a better claim on closest
     for (int i = list1pos+1, n = list1.Count; i < n; i++){
       AttributeNode nd1alt = list1[i];
       if (nd1alt == null) continue;
       if (matchedNodes[nd1alt.UniqueKey] != null) continue;
       Differences diff = this.GetDifferences(nd1alt, closest);
       if (diff == null){Debug.Assert(false); continue;}
       if (diff.Similarity <= winnerSoFar.Similarity) continue;
       //nd1alt has a better claim on closest. See if it wants closest.
       Differences diff2;
       int j, k = list2start;
       AttributeNode nd2alt = this.GetClosestMatch(nd1alt, list1, list2, i, ref k,  matchedNodes, out diff2, out j);
       if (nd2alt != closest){
         Debug.Assert(nd2alt != null && diff2 != null && diff2.Similarity >= diff.Similarity);
         continue; //nd1alt prefers nd2alt to closest, so closest is still available
       }
       //nd1alt wants closest, take it out of the running
       matchedNodes[closest.UniqueKey] = nd1alt;
       //Now that closest is out of the running, try again
       k = list2start;
       AttributeNode newClosest = this.GetClosestMatch(nd1, list1, list2, i, ref k, matchedNodes, out winnerSoFar, out list2pos);
       //put closest back in the running so that the next call to this routine will pick it up
       matchedNodes[closest.UniqueKey] = closest;
       closest = newClosest;
       break;
     }
   }
   closestDifferences = winnerSoFar;
   return closest;
 }
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:59,代码来源:Comparer.cs

示例5: Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            string left = File.ReadAllText(Server.MapPath("~/Examples/DeOfficiis.txt"));
            //string left = File.ReadAllText(Server.MapPath("~/Examples/DeOfficiis_Recombined.txt"));

            string right = File.ReadAllText(Server.MapPath("~/Examples/DeOfficiis_Altered.txt"));
            //string right = File.ReadAllText(Server.MapPath("~/Examples/DeOfficiis_Minor_Altered.txt"));
            //string right = File.ReadAllText(Server.MapPath("~/Examples/TotallyDifferent.txt"));

            GC.Collect(3, GCCollectionMode.Forced); // give the algorithm a fair shot...
            var sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            var differences = new Differences(left, right, Differences.PerWord);

            sw.Stop();

            Repeater1.DataSource = from d in differences
                                   select new Fragment(d.Type,
                                       HttpContext.Current.Server.HtmlEncode(d.SplitPart).Replace("\n", "<br/>"), d.Position);
            Repeater1.DataBind();

            Response.Write("DocDiff took " + sw.Elapsed.TotalSeconds + " seconds<br/>");

            // This gives a code to convert LEFT into RIGHT
            // Is a revision repository, the older file would be RIGHT, and the newer be LEFT.
            sw.Reset();
            sw.Start();
            byte[] final_out = DiffCode.StorageDiffCode(differences);
            sw.Stop();
            Response.Write("DocDiff-code took " + sw.Elapsed.TotalSeconds + " seconds<br/>");

            double sizePc = ((double)final_out.Length / right.Length) * 100.0;
            Response.Write("<br/>DocDiff code size: " + (final_out.Length / 1024) + "KiB which is " + sizePc.ToString("0.0") + "% of the resulting file");
            Response.Write("<br/>diff code contains " + differences.Count() + " alterations.");

            sw.Reset();
            sw.Start();
            File.WriteAllText(Server.MapPath("~/Examples/DeOfficiis_Recombined.txt"),
                DiffCode.BuildRevision(left, DiffCode.BuildDiffCode(differences)));
            sw.Stop();
            Response.Write("<br/>Rebuild and write took " + sw.Elapsed.TotalSeconds + " seconds<br/>");
        }
开发者ID:i-e-b,项目名称:DiffTools,代码行数:43,代码来源:DocDiff.aspx.cs

示例6: LogChanges

        private void LogChanges(string zipFilePath, Differences differences)
        {
            Console.WriteLine("In {0}...", zipFilePath);
            Logger.Info("In {0}...", zipFilePath);

            var added = differences.Added;
            var changed = differences.Changed;
            var removed = differences.Removed;

            int numberOfDifferences = added.Count + changed.Count + removed.Count;

            if (numberOfDifferences > 0)
            {
                Console.WriteLine("Number of differences = {0}.", numberOfDifferences);
                Logger.Info("Number of differences = {0}.", numberOfDifferences);
            }

            if (added.Any())
            {
                Console.WriteLine("Added...");
                Logger.Info("Added...");
                added.Keys.ToList().ForEach(k => { Console.WriteLine(k); Logger.Info(k); });
            }

            if (changed.Any())
            {
                Console.WriteLine("Changed...");
                Logger.Info("Changed...");
                changed.Keys.ToList().ForEach(k => { Console.WriteLine(k); Logger.Info(k); });
            }

            if (removed.Any())
            {
                Console.WriteLine("Removed...");
                Logger.Info("Removed...");
                removed.Keys.ToList().ForEach(k => { Console.WriteLine(k); Logger.Info(k); });
            }
        }
开发者ID:kevinmcfarlane,项目名称:CloudBackupActors,代码行数:38,代码来源:BackupStatisticsActor.cs

示例7: GetMemberDifferences

 public virtual Differences GetMemberDifferences(Member member1, Member member2) {
   if (member1 == null || member2 == null) return new Differences(member1, member2);
   if (this.memberDifferencesMapFor == null) this.memberDifferencesMapFor = new TrivialHashtable();
   TrivialHashtable map = this.memberDifferencesMapFor[member1.UniqueKey] as TrivialHashtable;
   if (map == null) this.memberDifferencesMapFor[member1.UniqueKey] = map = new TrivialHashtable();
   Differences differences = map[member2.UniqueKey] as Differences;
   if (differences == null){
     map[member2.UniqueKey] = differences = new Differences(member1, member2);
     if (member1 == member2) differences.NumberOfSimilarities++;
   }
   return differences;
 }
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:12,代码来源:Comparer.cs

示例8: VisitQueryUpdate

    public virtual Differences VisitQueryUpdate(QueryUpdate update1, QueryUpdate update2){
      Differences differences = new Differences(update1, update2);
      if (update1 == null || update2 == null){
        if (update1 != update2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++;
        return differences;
      }
      QueryUpdate changes = (QueryUpdate)update2.Clone();
      QueryUpdate deletions = (QueryUpdate)update2.Clone();
      QueryUpdate insertions = (QueryUpdate)update2.Clone();

      //      update1.Context;
      //      update1.Source;
      //      update1.UpdateList;

      if (differences.NumberOfDifferences == 0){
        differences.Changes = null;
        differences.Deletions = null;
        differences.Insertions = null;
      }else{
        differences.Changes = changes;
        differences.Deletions = deletions;
        differences.Insertions = insertions;
      }
      return differences;
    }    
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:25,代码来源:Comparer.cs

示例9: VisitQueryTypeFilter

    public virtual Differences VisitQueryTypeFilter(QueryTypeFilter filter1, QueryTypeFilter filter2){
      Differences differences = new Differences(filter1, filter2);
      if (filter1 == null || filter2 == null){
        if (filter1 != filter2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++;
        return differences;
      }
      QueryTypeFilter changes = (QueryTypeFilter)filter2.Clone();
      QueryTypeFilter deletions = (QueryTypeFilter)filter2.Clone();
      QueryTypeFilter insertions = (QueryTypeFilter)filter2.Clone();

      //      filter1.Constraint;
      //      filter1.Source;

      if (differences.NumberOfDifferences == 0){
        differences.Changes = null;
        differences.Deletions = null;
        differences.Insertions = null;
      }else{
        differences.Changes = changes;
        differences.Deletions = deletions;
        differences.Insertions = insertions;
      }
      return differences;
    }
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:24,代码来源:Comparer.cs

示例10: VisitQuerySingleton

    public virtual Differences VisitQuerySingleton(QuerySingleton singleton1, QuerySingleton singleton2){
      Differences differences = new Differences(singleton1, singleton2);
      if (singleton1 == null || singleton2 == null){
        if (singleton1 != singleton2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++;
        return differences;
      }
      QuerySingleton changes = (QuerySingleton)singleton2.Clone();
      QuerySingleton deletions = (QuerySingleton)singleton2.Clone();
      QuerySingleton insertions = (QuerySingleton)singleton2.Clone();

      //singleton1.Source;

      if (differences.NumberOfDifferences == 0){
        differences.Changes = null;
        differences.Deletions = null;
        differences.Insertions = null;
      }else{
        differences.Changes = changes;
        differences.Deletions = deletions;
        differences.Insertions = insertions;
      }
      return differences;
    }
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:23,代码来源:Comparer.cs

示例11: VisitQueryQuantifiedExpression

    public virtual Differences VisitQueryQuantifiedExpression(QueryQuantifiedExpression qqe1, QueryQuantifiedExpression qqe2){
      Differences differences = new Differences(qqe1, qqe2);
      if (qqe1 == null || qqe2 == null){
        if (qqe1 != qqe2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++;
        return differences;
      }
      QueryQuantifiedExpression changes = (QueryQuantifiedExpression)qqe2.Clone();
      QueryQuantifiedExpression deletions = (QueryQuantifiedExpression)qqe2.Clone();
      QueryQuantifiedExpression insertions = (QueryQuantifiedExpression)qqe2.Clone();

      //      qqe1.Expression;
      //      qqe1.Left;
      //      qqe1.Right;

      if (differences.NumberOfDifferences == 0){
        differences.Changes = null;
        differences.Deletions = null;
        differences.Insertions = null;
      }else{
        differences.Changes = changes;
        differences.Deletions = deletions;
        differences.Insertions = insertions;
      }
      return differences;
    }
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:25,代码来源:Comparer.cs

示例12: VisitQueryRollback

 public virtual Differences VisitQueryRollback(QueryRollback qr1, QueryRollback qr2){
   Differences differences = new Differences(qr1, qr2);
   if (qr1 == null || qr2 == null){
     if (qr1 != qr2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++;
   }else
     differences.Changes = null;
   return differences;
 }
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:8,代码来源:Comparer.cs

示例13: VisitQueryGroupBy

    public virtual Differences VisitQueryGroupBy(QueryGroupBy groupby1, QueryGroupBy groupby2){
      Differences differences = new Differences(groupby1, groupby2);
      if (groupby1 == null || groupby2 == null){
        if (groupby1 != groupby2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++;
        return differences;
      }
      QueryGroupBy changes = (QueryGroupBy)groupby2.Clone();
      QueryGroupBy deletions = (QueryGroupBy)groupby2.Clone();
      QueryGroupBy insertions = (QueryGroupBy)groupby2.Clone();

      //      groupby1.AggregateList;
      //      groupby1.GroupContext;
      //      groupby1.GroupList;
      //      groupby1.Having;
      //      groupby1.HavingContext;
      //      groupby1.Source;

      if (differences.NumberOfDifferences == 0){
        differences.Changes = null;
        differences.Deletions = null;
        differences.Insertions = null;
      }else{
        differences.Changes = changes;
        differences.Deletions = deletions;
        differences.Insertions = insertions;
      }
      return differences;
    }
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:28,代码来源:Comparer.cs

示例14: VisitQueryExists

    public virtual Differences VisitQueryExists(QueryExists exists1, QueryExists exists2){
      Differences differences = new Differences(exists1, exists2);
      if (exists1 == null || exists2 == null){
        if (exists1 != exists2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++;
        return differences;
      }
      QueryExists changes = (QueryExists)exists2.Clone();
      QueryExists deletions = (QueryExists)exists2.Clone();
      QueryExists insertions = (QueryExists)exists2.Clone();

      //      exists1.Source;

      if (differences.NumberOfDifferences == 0){
        differences.Changes = null;
        differences.Deletions = null;
        differences.Insertions = null;
      }else{
        differences.Changes = changes;
        differences.Deletions = deletions;
        differences.Insertions = insertions;
      }
      return differences;
    }
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:23,代码来源:Comparer.cs

示例15: VisitQueryDistinct

    public virtual Differences VisitQueryDistinct(QueryDistinct distinct1, QueryDistinct distinct2){
      Differences differences = new Differences(distinct1, distinct2);
      if (distinct1 == null || distinct2 == null){
        if (distinct1 != distinct2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++;
        return differences;
      }
      QueryDistinct changes = (QueryDistinct)distinct2.Clone();
      QueryDistinct deletions = (QueryDistinct)distinct2.Clone();
      QueryDistinct insertions = (QueryDistinct)distinct2.Clone();

      //      distinct1.Context;
      //      distinct1.Group;
      //      distinct1.GroupTarget;
      //      distinct1.Source;

      if (differences.NumberOfDifferences == 0){
        differences.Changes = null;
        differences.Deletions = null;
        differences.Insertions = null;
      }else{
        differences.Changes = changes;
        differences.Deletions = deletions;
        differences.Insertions = insertions;
      }
      return differences;
    }
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:26,代码来源:Comparer.cs


注:本文中的Differences类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。