using System;
using System.Collections.Generic;
using System.Text;
using SourceSafeTypeLib;
///更新日期:2012/04/12
namespace QuickVSS
{
public class VSSMgr
{
public const string USER_RIGHT_READONLY = "0";
public const string USER_RIGHT_WRITABLE = "1";
private VSSDatabaseClass _vssDB;
private string _iniFilePath;
private string _userName;
private string _password;
#region Enum
public enum UserRight
{
ReadOnly,
Writable
}
public enum FileProperty
{
ReadOnly,
Writable
}
public enum CheckOutFlag
{
Default,
GetNewVersion
}
#endregion
#region Property
public string INIFilePath
{
get
{
return _iniFilePath;
}
set
{
_iniFilePath = value;
}
}
public string UserName
{
get
{
return _userName;
}
set
{
_userName = value;
}
}
public string Password
{
get
{
return _password;
}
set
{
_password = value;
}
}
#endregion
#region Method
public VSSMgr()
{
_vssDB = new VSSDatabaseClass();
}
public VSSMgr(string INIFilePath, string UserName, string Password)
{
_vssDB = new VSSDatabaseClass();
_iniFilePath = INIFilePath;
_userName = UserName;
_password = Password;
//_vssDB.Open(INIFilePath, UserName, Password);
}
public void Open()
{
_vssDB.Open(_iniFilePath, _userName, _password);
}
public void Open(string INIFilePath, string UserName, string Password)
{
_vssDB.Open(INIFilePath, UserName, Password);
}
public void Close()
{
if (_vssDB == null)
{
//TODO :
}
_vssDB.Close();
}
public void AddUser(string UserName, string Password, bool IsReadOnly)
{
if (_vssDB == null)
{
//TODO :
}
_vssDB.AddUser(UserName, Password, IsReadOnly);
}
public bool UserIsExists(string UserName)
{
VSSUser userInfo;
if (_vssDB == null)
{
//TODO :
}
try
{
userInfo = _vssDB.get_User(UserName);
}
catch (System.Runtime.InteropServices.COMException ex)
{
switch (ex.ErrorCode)
{
//ユーザーが存在しない場合
case -2147166526:
return false;
//VSSが閉じる場合
case -2147221504:
throw ex;
default:
throw ex;
}
}
return true;
}
public string[] GetUserList()
{
IVSSUsers users;
List<string> userList;
userList = new List<string>();
if (_vssDB == null)
{
//TODO :
}
users = _vssDB.Users;
foreach (VSSUserClass user in users)
{
userList.Add(user.Name);
}
return userList.ToArray();
}
public void GetFile(string SourceFilePath, string DestFilePath, FileProperty fileProperty)
{
VSSItem item;
int flag;
flag = 0;
if (fileProperty == FileProperty.Writable)
{
flag = 1;
}
if (System.IO.File.Exists(DestFilePath) == true)
{
System.IO.File.SetAttributes(DestFilePath, System.IO.FileAttributes.Normal);
System.IO.File.Delete(DestFilePath);
}
item = _vssDB.get_VSSItem(SourceFilePath, false);
item.Get(ref DestFilePath, flag);
}
public string Checkout(string ProjectFile, string Comment, CheckOutFlag checkOutFlag)
{
VSSItem project;
IVSSCheckouts checkoutInfo;
string localFile;
project = _vssDB.get_VSSItem(ProjectFile, false);
checkoutInfo = project.Checkouts;
if (checkoutInfo.Count > 0)
{
return "";
}
localFile = project.LocalSpec;
if (string.Equals(localFile, "") == true)
{
throw new Exception("Set working folder please.");
}
if (checkOutFlag == CheckOutFlag.GetNewVersion)
{
GetFile(ProjectFile, localFile, FileProperty.Writable);
}
project.Checkout(Comment, localFile, 0);
return localFile;
}
public bool Checkin(string ProjectPath, string Comment, int iFlag)
{
VSSItem project;
IVSSCheckouts checkoutInfo;
project = _vssDB.get_VSSItem(ProjectPath, false);
checkoutInfo = project.Checkouts;
if (checkoutInfo.Count == 0)
{
return false;
}
project.Checkin(Comment, "", iFlag);
return true;
}
public List<string> GetSubFolder(string folderName)
{
VSSItem folder;
IVSSItems subFolders;
List<string> subFolderNames;
folder = _vssDB.get_VSSItem(folderName, false);
subFolders = folder.get_Items(true);
subFolderNames = new List<string>();
foreach (IVSSItem subFolder in subFolders)
{
if (subFolder.Deleted == false)
subFolderNames.Add(subFolder.Name);
}
return subFolderNames;
}
public bool ProjectIsCheckout(string ProjectPath)
{
VSSItem project;
IVSSCheckouts checkoutInfo;
project = _vssDB.get_VSSItem(ProjectPath, false);
checkoutInfo = project.Checkouts;
if (checkoutInfo.Count > 0)
{
return true;
}
return false;
}
#endregion
}
}
VSS的操作
最新推荐文章于 2015-12-02 19:37:02 发布