c# How to determine if a file is in ClearCase

2019-08-31 02:44发布

问题:

I am writing a program that needs to know whether a file (excel workbook) is in clearcase or not. If so I need to check it out. Here is my code for checking out a file:

    private void buttonClicked(object sender, RibbonControlEventArgs e)
    {

        ClearCase.ClearTool checkingOut = new ClearCase.ClearTool();

        string fileLoc = Globals.ThisAddIn.Application.ActiveWorkbook.FullName;

        checkingOut.CmdExec(@"checkout """ + fileLoc + @"""");
    }

I do not want to perform the checkout unless I know if it is in Clearcase or not. This is part of an Excel add-in.

Thank You!

回答1:

The simplest way to know if a file is in ClearCase is to perform a cleartool ls aFile (ct.CmdExec("ls aFile"); with the CAL API)

See the cleartool ls man page:

List the VOB-resident objects and view-private objects in the current working directory.

cmd-context ls
Makefile@@/main/3                                   Rule: /main/LATEST
bug.report
cm_add.c@@/main/0                                    Rule: /main/LATEST

Here bug.report isn't in ClearCase yet: it has no selection rule associated to it.



回答2:

The easiest way to check whether a file in clearcase or not is to check whether file@@/main/0 exists



回答3:

I've never used ClearCase but looking at the docs for the CLI can you just execute the find command?



回答4:

It seems you are using the ClearCase Automation Library for C# ClearCase Automation Library

On that page, it mentions this information:

After getting all the checked out files, you can search if the current file is a member of that list or not.