コード例 #1
0
ファイル: ConflictResolver.cs プロジェクト: nuxleus/flexwiki
    private string DefaultResolve(LocalTopic topic, string remoteContents)
    {
      string tempPath = Path.Combine(tempDir, topic.Name + ".wiki"); 

      StreamWriter sw = new StreamWriter(tempPath, false, Encoding.UTF8); 
      try
      {
        sw.WriteLine("Both versions of the topic {0}.{1} appear below", topic.Namespace.Name, topic.Name); 
        sw.WriteLine("The remote version appears first, then the local version.");
        sw.WriteLine();
        sw.WriteLine("Edit the file to merge the changes together. Be sure to remove these remarks, ");
        sw.WriteLine("the ===='s separating the sections, and any anything you don't want to appear ");
        sw.WriteLine("in the final copy. Then save the file and confirm the changes"); 
        sw.WriteLine();
        sw.WriteLine("==REMOTE VERSION============================");
        sw.WriteLine(FixupLineTerminators(remoteContents)); 
        sw.WriteLine();
        sw.WriteLine("==LOCAL VERSION============================");
        sw.WriteLine(FixupLineTerminators(topic.ReadContents())); 
        sw.WriteLine(); 
      }
      finally
      {
        sw.Close(); 
      }

      Process process = Process.Start("notepad.exe", tempPath); 
      process.WaitForExit(); 

      bool accept = false; 

      string result = null;   
      if (confirmAll)
      {
        accept = true; 
      }
      else
      {
        Console.Write("Accept changes (y/n)? ");
        char c = (char) Console.Read(); 

        if (c == 'y' || c == 'Y')
        {
          accept = true; 
        }
      }

      if (accept)
      {
        StreamReader sr = new StreamReader(tempPath, Encoding.Default, true); 
        try
        {
          result = sr.ReadToEnd(); 
        }
        finally
        {
          sr.Close(); 
        }
      }

      File.Delete(tempPath); 

      return result; 

    }
コード例 #2
0
ファイル: ConflictResolver.cs プロジェクト: nuxleus/flexwiki
    private string NormalMerge(LocalTopic topic, string remoteContents, string mergeWith)
    {
      string localContentPath  = Path.Combine(tempDir, string.Format("{0}.local.wiki", topic.Name)); 
      string remoteContentPath = Path.Combine(tempDir, string.Format("{0}.remote.wiki", topic.Name)); 
      string mergedContentPath = Path.Combine(tempDir, string.Format("{0}.merged.wiki", topic.Name)); 

      StreamWriter sw = new StreamWriter(localContentPath, false, Encoding.UTF8); 
      try
      {
        sw.Write(topic.ReadContents());
      }
      finally
      {
        sw.Close(); 
      }

      sw = new StreamWriter(remoteContentPath, false, Encoding.UTF8); 
      try
      {
        sw.Write(remoteContents); 
      }
      finally
      {
        sw.Close(); 
      }

      Process process = Process.Start(mergeWith, string.Format("\"{0}\" \"{1}\" \"{2}\"", remoteContentPath, localContentPath, 
        mergedContentPath)); 
      process.WaitForExit(); 

      string result = null; 
      if (File.Exists(mergedContentPath))
      {
        StreamReader sr = new StreamReader(mergedContentPath, Encoding.Default, true); 
        try
        {
          result = sr.ReadToEnd(); 
        }
        finally
        {
          sr.Close(); 
        }
      }

      File.Delete(localContentPath);
      File.Delete(remoteContentPath); 
      File.Delete(mergedContentPath); 

      return result; 

    }