Beispiel #1
0
        /// <summary>
        /// vss check out命令
        /// </summary>
        /// <param name="vssFilePath">vss上的文件路径</param>
        /// <param name="localPath">本地文件路径</param>
        /// <param name="comment">checkout注释</param>
        public void CheckOut(string vssFilePath, string localPath, string comment)
        {
            vssFilePath = this.FormatToVssDir(vssFilePath);
            localPath   = this.FormatToLocalDir(localPath);
            //string testFile = "$/TestFolder/test.txt";

            // Create a VSSDatabase object.
            IVSSDatabase vssDatabase = new VSSDatabase();

            // Open a VSS database using network name
            // for automatic user login.
            vssDatabase.Open(this.srcSafeIni, this.username, this.password);

            IVSSItem vssFile = vssDatabase.get_VSSItem(vssFilePath, false);

            vssFile.Checkout(comment, localPath, 0);

            if ((VSSFileStatus)vssFile.IsCheckedOut ==
                VSSFileStatus.VSSFILE_NOTCHECKEDOUT)
            {
                Console.WriteLine(vssFile.Spec + " is checked in.");
            }
            else
            {
                Console.WriteLine(vssFile.Spec + " is checked out.");
            }

            Console.WriteLine("Now alter the file and hit any key.");
            Console.ReadLine();
        }
Beispiel #2
0
 public void Connect()
 {
     if (VSSDB == null)
     {
         try
         {
             VSSDB = new VSSDatabase();
             VSSDB.Open(Location, Login, "");
         }
         catch (System.Runtime.InteropServices.COMException exc)
         {
             if (exc.ErrorCode == -2147167977)
             {
                 throw new ArgumentException("Wrong location or login");
             }
             else
             {
                 throw new ArgumentException(VSSErrors.GetMessageByCode(exc.ErrorCode));
             }
         }
         catch
         {
             throw new Exception("Неопознанная ошибка");
         }
     }
 }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        public void NewProject(string foldName, string vssParentPath, string comment)
        {
            // Create a VSSDatabase object.
            IVSSDatabase vssDatabase = new VSSDatabase();

            // Open a VSS database using network name
            // for automatic user login.
            vssDatabase.Open(this.srcSafeIni, this.username, this.password);

            IVSSItem vssParentFolder = vssDatabase.get_VSSItem(vssParentPath, false);

            DisplayFolder(vssParentFolder);

            // Create folder C in folder A.
            Console.WriteLine("- Creating folder C in folder A");
            IVSSItem vssChildFolder =
                vssParentFolder.NewSubproject(foldName, comment);

            DisplayFolder(vssParentFolder);

            //// Remove folder C from folder A.
            //Console.WriteLine("- Remove folder C from folder A");
            //vssChildFolder.Destroy();
            //DisplayFolder(vssParentFolder);
        }
Beispiel #4
0
        private static bool BuildFileList()
        {
            searchLog.Info("##### Building file list");

            vssDb = new VSSDatabase();
            vssDb.Open(vssSRCSAFEINI, vssUSER, vssPASSWORD);
            VSSItem vssRootItem = vssDb.get_VSSItem(vssPROJ, false);

            if (vssRootItem.Type == (int)VSSItemType.VSSITEM_PROJECT)
            {
                searchLog.Debug(vssRootItem.Spec);
                searchLog.Debug(vssRootItem.Parent.Spec);
                //Directory.CreateDirectory(Path.Combine(repoDIR, vssRootItem.Parent.Spec.Substring(2).Replace("/", "\\")));
                fileList.Add(vssRootItem);
                BuildFileList(vssRootItem);
            }
            else
            {
                fileList.Add(vssRootItem);
            }

            if (fileList.Count == 0)
            {
                searchLog.Error("No results from building file list");
                return(false);
            }

            return(true);
        }
Beispiel #5
0
        /// <summary>
        /// 根据vss的绝对路径创建一个Folder
        /// </summary>
        /// <param name="absoluteVssPath"></param>
        /// <param name="comment"></param>
        public void NewProject(string absoluteVssPath, string comment)
        {
            //string vssFolder = @"$/LIS-CM-AB/05-项目任务/B-契约模块/ABLREQUEST-1396-团险添加投保率不足0.75的控制提示/test";
            string vssFolder = @"$";//根目录

            string[] dir = absoluteVssPath.Split('/');

            IVSSDatabase vssDatabase = new VSSDatabase();

            vssDatabase.Open(this.srcSafeIni, this.username, this.password);
            IVSSItem vssParentFolder = null;// = vssDatabase.get_VSSItem(vssFolder, false);
            bool     existProject    = false;

            for (int i = 1; i < dir.Length; i++)
            {
                vssFolder += @"/" + dir[i];
                //暂时使用异常来判断是否存在,之后优化
                try
                {
                    vssParentFolder = vssDatabase.get_VSSItem(vssFolder, false);
                    existProject    = true;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    existProject = false;
                }
                if (!existProject) //不存在
                {
                    IVSSItem vssChildFolder = vssParentFolder.NewSubproject(dir[i], comment);
                    vssParentFolder = vssChildFolder;
                }
            }
        }
Beispiel #6
0
    static void Main(string[] args)
    {
        //Environment.CurrentDirectory = @"c:\Program Files (x86)\Microsoft Visual SourceSafe Upgrade";
        IVSSDatabase db = new VSSDatabase();

        db.Open(@"ThePath\srcsafe.ini", "Admin", "ThePassword");
        IVSSItem rootFolder = db.get_VSSItem("$/", false);
        var      versions   = new List <VersionInfo>();

        foreach (IVSSVersion item in rootFolder.get_Versions((int)Microsoft.VisualStudio.SourceSafe.Interop.VSSFlags.VSSFLAG_RECURSYES))
        {
            versions.Add(new VersionInfo()
            {
                ItemName          = item.VSSItem.Name,
                ItemFullPath      = item.VSSItem.Spec,
                ItemVersionDate   = item.Date,
                ItemVersionNumber = item.VersionNumber
            });
        }
        // echo all
        var versionInfo = versions.OrderByDescending(i => i.ItemVersionDate).First();

        Console.WriteLine("{0} {1}", versionInfo.ItemFullPath, versionInfo.ItemVersionDate);
        Console.ReadLine();
    }
Beispiel #7
0
        /// <summary>
        /// Attempts to connect to the SourceSafe Database and
        /// load the specified item, or version of the item, if specified.
        /// </summary>
        protected void ConnectToDatabase()
        {
            _database = new VSSDatabase();
            _database.Open(new FileInfo(DatabasePath).FullName, UserName, Password);

            _item = _database.get_VSSItem(Path, false);
            if (Version != null)
            {
                _item = _item.get_Version(Version);
            }
        }
Beispiel #8
0
        public SelectVssProjectsDialog(VssMigration migrationSettings)
            : this()
        {
            if (migrationSettings == null)
            {
                throw new ArgumentNullException("migrationSettings");
            }

            this.MigrationSettings = migrationSettings;

            _database = VssUtilities.OpenDatabase(migrationSettings.VssConnectionSettings);
            this.AddProjectNode(null, _database.get_VSSItem("$/"));
        }
Beispiel #9
0
        public static VSSDatabase OpenDatabase(string database, string username, string password)
        {
            VSSDatabase ssDatabase;

            if (!string.IsNullOrEmpty(database) && !database.ToLower().EndsWith("srcsafe.ini"))
            {
                database = Path.Combine(database, "srcsafe.ini");
            }

            ssDatabase = new VSSDatabase();
            ssDatabase.Open(string.IsNullOrEmpty(database) ? null : database, string.IsNullOrEmpty(username) ? null : username, string.IsNullOrEmpty(password) ? null : password);

            return(ssDatabase);
        }
Beispiel #10
0
        /// <summary>
        /// vss Destroy 命令
        /// 删除销毁文件
        /// </summary>
        /// <param name="destroyFolder">vss目录中的路径</param>
        /// <param name="comment">destroy注释说明</param>
        public void Destroy(string destroyFolder, string comment)
        {
            // Create a VSSDatabase object.
            IVSSDatabase vssDatabase = new VSSDatabase();

            // Open a VSS database using network name
            // for automatic user login.
            vssDatabase.Open(this.srcSafeIni, this.username, this.password);

            IVSSItem vssDestroyFolder = vssDatabase.get_VSSItem(destroyFolder, false);

            // Remove folder C from folder A.
            Console.WriteLine("- Remove folder C from folder A");
            vssDestroyFolder.Destroy();
            DisplayFolder(vssDestroyFolder.Parent);
        }
Beispiel #11
0
        /// <summary>
        /// Add file 命令的接口核心实现
        /// </summary>
        /// <param name="vssWorkFolder"></param>
        /// <param name="localFile"></param>
        /// <param name="comment"></param>
        public void AddFile(string vssWorkFolder, string localFile, string comment)
        {
            //TODO:添加判断文件是否存在

            IVSSDatabase vssDatabase = new VSSDatabase();

            vssDatabase.Open(this.srcSafeIni, this.username, this.password);
            VSSItem vssFolder = vssDatabase.get_VSSItem(vssWorkFolder, false);

            DisplayFolderContent(vssFolder);
            VSSItem vssTestFile = vssFolder.Add(localFile, comment, 0);

            DisplayFolderContent(vssFolder);
            vssTestFile.Destroy();
            DisplayFolderContent(vssFolder);
        }
Beispiel #12
0
        public bool IsCheckOut(string vssFilePath)
        {
            IVSSDatabase vssDatabase = new VSSDatabase();

            vssDatabase.Open(this.srcSafeIni, this.username, this.password);
            IVSSItem vssFile = vssDatabase.get_VSSItem(vssFilePath, false);

            if ((VSSFileStatus)vssFile.IsCheckedOut ==
                VSSFileStatus.VSSFILE_CHECKEDOUT)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #13
0
        /// <summary>
        /// 判断指定的文件路径是否存在vss中
        /// </summary>
        /// <param name="vssFolderPath"></param>
        /// <returns></returns>
        public bool ExistFolder(string vssFolderPath)
        {
            IVSSDatabase vssDatabase = new VSSDatabase();

            vssDatabase.Open(this.srcSafeIni, this.username, this.password);
            //暂时使用异常来判断是否存在,之后优化
            try
            {
                IVSSItem vssParentFolder = vssDatabase.get_VSSItem(vssFolderPath, false);
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(false);
            }
        }
Beispiel #14
0
        private void btnFind_Click(object sender, EventArgs e)
        {
            VSSDatabase vssDB = new VSSDatabase();

            try
            {
                vssDB.Open(serverUrl, userName, password);
            }
            catch (Exception ex)
            {
                MessageBox.Show(MESSAGE_ERROR_OCCURED + ex.Message);
                return;
            }

            if (vssDB.IsNull())
            {
                MessageBox.Show("Unable to open VSSDB: " + serverUrl);
                return;
            }

            VSSItem rootSourceFolderItem = null;

            try
            {
                rootSourceFolderItem = vssDB.get_VSSItem(rootSourceFolder, false);
            }
            catch (Exception ex)
            {
                MessageBox.Show(MESSAGE_ERROR_OCCURED + ex.Message);
                return;
            }

            if (rootSourceFolderItem.IsNull())
            {
                MessageBox.Show(string.Format("The VSS Source Folder doesnt Exists: {0}", rootSourceFolder));
                return;
            }

            filesCheckedOutByCurrentUser.Clear();
            filesCheckedOutByOthers.Clear();
            FindCheckedOutFiles(rootSourceFolderItem);
            BindFilesCheckedOutByCurrentUser();
        }
Beispiel #15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="vssFilePath"></param>
        /// <param name="localPath"></param>
        /// <param name="comment"></param>
        public void UndoCheckOut(string vssFilePath, string comment)
        {
            vssFilePath = this.FormatToVssDir(vssFilePath);

            IVSSDatabase vssDatabase = new VSSDatabase();

            vssDatabase.Open(this.srcSafeIni, this.username, this.password);

            IVSSItem vssFile = vssDatabase.get_VSSItem(vssFilePath, false);

            //只有取消自己检出的
            if ((VSSFileStatus)vssFile.IsCheckedOut == VSSFileStatus.VSSFILE_CHECKEDOUT_ME)
            {
                vssFile.UndoCheckout();

                Console.WriteLine("undo check out ." + vssFilePath);
            }
            Console.ReadLine();
        }
Beispiel #16
0
        /// <summary>
        /// 从vss目录获取文件
        /// </summary>
        /// <param name="vssPath">vss文件目录</param>
        /// <param name="localPath">本地保存目录</param>
        public void Get(string vssPath, string localPath)
        {
            // Create a VSSDatabase object.
            IVSSDatabase vssDatabase = new VSSDatabase();

            // Open a VSS database using network name
            // for automatic user login.
            vssDatabase.Open(this.srcSafeIni, this.username, this.password);

            IVSSItem vssFile =
                vssDatabase.get_VSSItem(vssPath, false);

            // Get a file into a specified folder.
            //string testFile = @"C:\1\test.txt";
            vssFile.Get(ref localPath, 0);

            //// Get a file into a working folder.
            //localPath = null;
            //vssFile.Get(ref localPath, 0);
            Console.WriteLine("The Get operation is completed");
        }
Beispiel #17
0
        /// <summary>
        /// Opens the Source Safe database and sets the reference to the specified
        /// item and version.
        /// </summary>
        protected void Open()
        {
            try {
                _database = new VSSDatabase();
                _database.Open(DBPath.FullName, UserName, Password);
            } catch (Exception ex) {
                throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                       "Failed to open database \"{0}\".", DBPath.FullName),
                                         Location, ex);
            }

            try {
                // get the reference to the specified project item
                // and version
                _item = _database.get_VSSItem(Path, false);
                if (Version != null)
                {
                    _item = _item.get_Version(Version);
                }
            } catch (Exception ex) {
                throw new BuildException("The \"path\" and/or \"version\" is not valid.",
                                         Location, ex);
            }
        }
Beispiel #18
0
		public void ReadConfig(string conf)
		{
			Config = File.ReadAllLines(conf)
				.Where(l => !string.IsNullOrEmpty(l))
				.Select(l => l.Trim())
				.Where(l => !l.StartsWith("#"))
				.Select(l => {
					var pos = l.IndexOf('=');
					if(pos == -1)
					{
						Console.WriteLine("Wrong line in config: {0}", l);
						Environment.Exit(-1);
					}

					return new { Key = l.Substring(0, pos).Trim(), Value = l.Substring(pos + 1).Trim()};
				})
				.ToLookup(p => p.Key, p => p.Value)
			;

			SSPath = Config["ss.exe"].FirstOrDefault();

			// cache
			CacheDir = Config["cache-dir"].DefaultIfEmpty(".cache").First();

			LatestOnly.Clear();
			foreach (var v in Config["latest-only"])
			{
				LatestOnly.Add(v);
			}

			LatestOnlyRx = Config["latest-only-rx"].Select(rx => new Regex(rx, RegexOptions.IgnoreCase)).ToArray();

			// commit setup

			// silent period
			SilentSpan = Config["commit-silent-period"]
				.DefaultIfEmpty("120")
				.Select(Double.Parse)
				.Select(TimeSpan.FromMinutes)
				.First()
			;

			// overlapping
			OverlapCommits = Config["overlapped-commits"]
				.DefaultIfEmpty("false")
				.Select(bool.Parse)
				.First()
			;

			// merge changes
			MergeChanges = Config["merge-changes"]
				.DefaultIfEmpty("false")
				.Select(bool.Parse)
				.First()
			;

			UnimportantCheckinCommentRx = Config["unimportant-checkin-comment-rx"]
				.Select(s => new Regex(s, RegexOptions.IgnoreCase))
				.ToArray()
			;

			UserMappingStrict = Config["user-mapping-strict"]
				.DefaultIfEmpty("false")
				.Select(bool.Parse)
				.First()
			;

			CommentAddVssFilesInfo = Config["comment-add-vss-files-info"]
				.DefaultIfEmpty("false")
				.Select(bool.Parse)
				.First()
			;

			CommentAddUserTime = Config["comment-add-user-time"]
				.DefaultIfEmpty("false")
				.Select(bool.Parse)
				.First()
			;

			CommentAddCommitNumber = Config["comment-add-commit-number"]
				.DefaultIfEmpty("false")
				.Select(bool.Parse)
				.First()
			;

			ImportDriver = Config["import-driver"]
				.DefaultIfEmpty("svn")
				.First()
				.ToLowerInvariant()
			;

			if (ImportDriver == "git")
			{
				GitExe = Config["git-exe"]
					.DefaultIfEmpty("git.exe")
					.First()
				;

				GitRepoDir = Config["git-repo-dir"]
					.Select(p => Path.Combine(Environment.CurrentDirectory, p))
					.FirstOrDefault()
				;

				if (string.IsNullOrWhiteSpace(GitRepoDir))
				{
					GitRepoDir = Path.Combine(Environment.CurrentDirectory, "_git_repo");
				}
				else
				{
					IsGitRepoDirExternal = true;
				}

				GitDefaultAuthorDomain = Config["git-default-author-domain"]
					.DefaultIfEmpty("@dummy-email.org")
					.First()
				;

				GitStartAfterImport = Config["git-start-after-import"]
					.FirstOrDefault()
				;

				GitStartAfterImportArgs = Config["git-start-after-import-args"]
					.FirstOrDefault() ?? ""
				;
			}

			if (ImportDriver == "tfs")
			{
				TfExe = Config["tf-exe"]
					.DefaultIfEmpty("tf.exe")
					.First()
				;

				TfsWorkTreeDir = Config["tfs-worktree-dir"]
					.Select(p => Path.Combine(Environment.CurrentDirectory, p))
					.FirstOrDefault()
				;

				TfNoCheckStatusBeforeStartRevision = Config["tfs-no-check-status-every-revision"]
					.Select(p => p.ToLowerInvariant())
					.Select(p => p == "1" || p == "yes" || p == "true")
					.FirstOrDefault()
				;
			}

			if (ImportDriver == "svn")
			{
				SvnRepoUrl = Config["svn-repo-url"]
					.FirstOrDefault()
				;

				if (string.IsNullOrWhiteSpace(SvnRepoUrl))
				{
					SvnRepoUrl = Path.Combine(Environment.CurrentDirectory, "_svn_repo");
				}
				else
				{
					IsSvnRepoDirExternal = true;
				}

				SvnWorkTreeDir = Config["svn-worktree-dir"]
					.Select(p => Path.Combine(Environment.CurrentDirectory, p))
					.FirstOrDefault()
				;

				if (string.IsNullOrWhiteSpace(SvnWorkTreeDir))
				{
					SvnWorkTreeDir = Path.Combine(Environment.CurrentDirectory, "_svn_wc");
				}
			}

			MangleImportPath = Config["mangle-import-path"]
				.Select(p => Tuple.Create(new Regex(p.Split(':')[0], RegexOptions.IgnoreCase), p.Split(':')[1]))
				.ToList()
			;

			// open VSS DB
			if (DB != null && DB.IsValueCreated)
			{
				DB.Value.Close();
				DB = null;
			}

			SourceSafeIni = Config["source-safe-ini"].DefaultIfEmpty("srcsafe.ini").First();
			SourceSafeUser = Config["source-safe-user"].DefaultIfEmpty("").First();
			SourceSafePassword = Config["source-safe-password"].DefaultIfEmpty("").First();
			DB = new Lazy<VSSDatabase>(() => {
				Console.WriteLine("Initialize VSS driver....");
				var db = new VSSDatabase();
				db.Open(SourceSafeIni, SourceSafeUser, SourceSafePassword);
				Console.WriteLine("VSS driver initialized");
				return db;
			});

			SSExeHelper.SetupSS(SourceSafeIni, SourceSafeUser, SourceSafePassword);

			// include/exclude checks
			var checks = Config["import-pattern"]
				.Select(pat => new { Rx = new Regex(pat.Substring(1), RegexOptions.IgnoreCase), Exclude = pat.StartsWith("-") })
				.ToArray()
			;

			IncludePredicate = path => {
				var m = checks.FirstOrDefault(c => c.Rx.IsMatch(path));
				if (m == null)
					return true;

				return !m.Exclude;
			};
		}
Beispiel #19
0
        /// <summary>
        /// Opens the Source Safe database and sets the reference to the specified
        /// item and version.
        /// </summary>
        protected void Open()
        {
            try {
                _database = new VSSDatabase();
                _database.Open(DBPath.FullName, UserName, Password);
            } catch (Exception ex) {
                throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                    "Failed to open database \"{0}\".", DBPath.FullName),
                    Location, ex);
            }

            try {
                // get the reference to the specified project item
                // and version
                _item = _database.get_VSSItem(Path, false);
                if (Version != null) {
                    _item = _item.get_Version(Version);
                }
            } catch (Exception ex) {
                throw new BuildException("The \"path\" and/or \"version\" is not valid.",
                    Location, ex);
            }
        }
Beispiel #20
0
 public FVSS()
 {
     vssdb = new VSSDatabase();
 }
Beispiel #21
0
        /// <summary>
        /// Attempts to connect to the SourceSafe Database and
        /// load the specified item, or version of the item, if specified.
        /// </summary>
        protected void ConnectToDatabase()
        {
            _database = new VSSDatabase();
            _database.Open(new FileInfo(DatabasePath).FullName, UserName, Password);

            _item = _database.get_VSSItem(Path, false);
            if (Version != null)
            {
                _item = _item.get_Version(Version);
            }
        }