2008-11-13 57 views
3

我需要以編程方式從sourcesafe數據庫獲取文件。任何想法如何做到這一點?如何以編程方式從sourcesafe獲取文件?

ps:我會通過使用C#來做到這一點。

+3

這個評論是一種強制性的,但得到從SourceSafe走爲上就可以了,如果可能的話。 – MusiGenesis 2008-11-13 14:38:18

+0

幾周後,我會的! :) – 2008-11-13 14:45:33

回答

10
using System; 
using System.Collections.Generic; 
using SourceSafeTypeLib; 

namespace YourNamespace 
{ 

public class SourceSafeDatabase 
{ 
    private readonly string dbPath; 
    private readonly string password; 
    private readonly string rootProject; 
    private readonly string username; 
    private readonly VSSDatabaseClass vssDatabase; 

    public SourceSafeDatabase(string dbPath, string username, string password, string rootProject) 
    { 
     this.dbPath = dbPath; 
     this.username = username; 
     this.password = password; 
     this.rootProject = rootProject; 

     vssDatabase = new VSSDatabaseClass(); 
    } 

    public List<string> GetAllLabels() 
    { 
     List<string> allLabels = new List<string>(); 

     VSSItem item = vssDatabase.get_VSSItem(rootProject, false); 
     IVSSVersions versions = item.get_Versions(0); 

     foreach (IVSSVersion version in versions) 
     { 
      if (version.Label.Length > 0) 
      { 
       allLabels.Add(version.Label); 
      } 
     } 

     return allLabels; 
    } 

    public void GetLabelledVersion(string label, string project, string directory) 
    { 
     string outDir = directory; 
     vssDatabase.get_VSSItem(rootProject, false).get_Version(label).Get(ref outDir, (int)VSSFlags.VSSFLAG_RECURSYES + (int)VSSFlags.VSSFLAG_USERRONO); 
    } 

    public void Open() 
    { 
     vssDatabase.Open(dbPath, username, password); 
    } 

    public void Close() 
    { 
     vssDatabase.Close(); 
    } 

} 


// some other code that uses it 

SourceSafeDatabase sourceControlDatabase = new sourceControlDatabase(...); 
sourceControlDatabase.Open(); 
sourceControlDatabase.GetLabelledVersion(label, rootProject, projectDirectory); 
sourceControlDatabase.Close(); 
2

有一個命令行SS.EXE程序,您可以調用來執行源代碼管理操作。然而,它依賴於全局的SourceSafe配置,所以有時很難做到你想做的。

相關問題