Vault Api - Check-out and Check-in issue

Vault Api - Check-out and Check-in issue

felix.bausemer
Contributor Contributor
1,962 Views
4 Replies
Message 1 of 5

Vault Api - Check-out and Check-in issue

felix.bausemer
Contributor
Contributor

Hey everyone,

 

I have a problem with checking out and checking in a file from and to Autodesk Vault. 

 

For the check-out I am using "FileManager.AcquireFiles(...)" and for the check-in, I am using "FileManager.CheckinFile()". The problem is that I can do the following workflow with the Vault Api only once for a new file: Checkout -> File modification -> Checkin. For some reason, my program leaves its thread the second time I am trying to check out the same file. I realized that although the first check-in worked and the file was properly displayed as checked-in via the Vault Client the property "Checked out" still shows a time stamp. I am not quite sure why it seems so hard to do a "simple" check-out and check-in with this API. 

I hope some of you understand my issue because I am not sure how to explain it in a more comprehensible way.

Maybe you have a well-documented sample where this process is shown.

Thanks in advance and best regards.

0 Likes
Accepted solutions (2)
1,963 Views
4 Replies
Replies (4)
Message 2 of 5

Markus.Koechl
Autodesk
Autodesk

This code snippet should help to compare your approach with a working one: 

// checkin new file version
                AcquireFilesSettings aqSettings = new AcquireFilesSettings(conn)
                {
                    DefaultAcquisitionOption = AcquireFilesSettings.AcquisitionOption.Checkout
                };
                vdfFile = new VDF.Vault.Currency.Entities.FileIteration(conn, wsFile);
                aqSettings.AddEntityToAcquire(vdfFile);
                var results = conn.FileManager.AcquireFiles(aqSettings);
                try
                {
                    mUploadedFile = conn.FileManager.CheckinFile(results.FileResults.First().File, "Created by Job Processor", false, null, null, false, null, FileClassification.None, false, vdfPath);
                }
                catch
                {
                    throw new Exception("Job could not update existing report file " + vdfFile);
                }


Markus Koechl

Solutions Engineer PDM, Autodesk Central Europe
0 Likes
Message 3 of 5

felix.bausemer
Contributor
Contributor

Thank you for your reply.

I tried your approach but it seems that the method "AcquireFiles(...)" returns an empty collection.

public static FileIteration CheckinFile(
Connection connection, 
long masterId, 
string localFilePath, 
string newFileName = null, 
FileClassification classification = FileClassification.None)
{
AcquireFilesSettings aqSettings = new AcquireFilesSettings(connection)
{
DefaultAcquisitionOption = AcquireFilesSettings.AcquisitionOption.Checkout
};

File file = connection.WebServiceManager.DocumentService.GetFilesByMasterId(masterId)[0];

FileIteration fileIteration = new FileIteration(connection, file);
aqSettings.AddEntityToAcquire(fileIteration);
var results = connection.FileManager.AcquireFiles(aqSettings);
FilePathAbsolute filePathAbsolute = new FilePathAbsolute(localFilePath);
try
{
return connection.FileManager.CheckinFile(results.FileResults.First().File, "Created by Job Processor", false, null, null, false, newFileName, classification, false, filePathAbsolute);
}
catch(Exception e)
{
throw new Exception($"Job could not update existing report file {fileIteration}\n{e.Message}");
}
}

 

felixbausemer_0-1707463269664.png
Thank you in advance.

0 Likes
Message 4 of 5

Markus.Koechl
Autodesk
Autodesk
Accepted solution

The collection is filled if you downloaded files. If you checked out without downloading it, it is empty. Use the FileAquisitionResult object for each file to investigate in detail. The sample I shared before does not need to edit an existing file; it checks in a newly created file as a new iteration. I am sorry that I did not consider this when providing the sample. 

Another sample code demonstrates the check-out/download, local edit, and check-in: Vault-Job-Processor---iLogic-Extension/Autodesk.VltInvSrv.iLogicSampleJob/iLogicJobExtension.cs at 2...



Markus Koechl

Solutions Engineer PDM, Autodesk Central Europe
0 Likes
Message 5 of 5

felix.bausemer
Contributor
Contributor
Accepted solution

Hello Markus,

 

thanks for the update. I found a solution in the meantime. 

public static FileIteration CheckinFile(Connection connection, long masterId, string localFilePath, string newFileName = null, FileClassification classification = FileClassification.None)
{
    File file = connection.WebServiceManager.DocumentService.GetFilesByMasterId(masterId)[0];

    FileIteration fileIteration = new FileIteration(connection, file);

    IntPtr parent = new IntPtr();

    InteractiveAcquireFileSettings settings = new InteractiveAcquireFileSettings(connection, parent, "Download file");

    settings.AddFileToAcquire(fileIteration, AcquireFilesSettings.AcquisitionOption.Download);
    var results = connection.FileManager.AcquireFiles(settings);

    FileAssocParam[] fileAssociations = FileService.GetFileAssocParams(connection, masterId).ToArray();

    Autodesk.Connectivity.WebServices.BOM bom = connection.WebServiceManager.DocumentService.GetBOMByFileId(file.Id);

    FilePathAbsolute filePathAbsolute = new FilePathAbsolute(localFilePath);
    try
    {
        return connection.FileManager.CheckinFile(results.FileResults.First().File, "Checked in by plugin", false, fileAssociations, bom, false, newFileName, classification, false, filePathAbsolute);
    }
    catch (Exception e)
    {
        throw new Exception($"Job could not update existing report file {fileIteration}\n{e.Message}");
    }
}

 

It works so far. 

0 Likes