GetBestWorkingFolder and Get latest file

Post your questions regarding using the Vault and Fortress API in your programs.

Moderator: SourceGear

random
Posts: 16
Joined: Tue Apr 29, 2008 11:53 am
Location: Longueuil, Québec
Contact:

GetBestWorkingFolder and Get latest file

Post by random » Tue Apr 29, 2008 12:01 pm

I am having issues with getting the latest version of a checked-out file. I am able to connect and checkout the file; however, Get fails with a GetLatestVersionFailedException because I do not have a working folder.

I have attempted to use both GetBestWorkingFolder and GetWorkingFolder to no avail. They both always return null. From what I understand, GetBest* works with inherited working folders while GetWorkingFolder works with explicit working folders. I have setup both scenarios and am still unable to get a working folder.

Is there something that I am missing?

shannon

Post by shannon » Tue Apr 29, 2008 12:45 pm

can you post a code snippet?

random
Posts: 16
Joined: Tue Apr 29, 2008 11:53 am
Location: Longueuil, Québec
Contact:

Post by random » Wed Apr 30, 2008 8:23 am

Absolutely! Thanks for your help :)

VaultClientFolder folder = m_client.Repository.Root.FindFolderRecursive( workingFolder );

if( folder == null )
return null;

// Get the working folder otherwise Get will fail.
if( m_client.TreeCache.GetBestWorkingFolder( folder.FullPath ) == null )
return null;

m_client.Refresh();

// TODO should check responses to see if there were errors
VaultClientFile[] files = VaultConnection.GetFiles( folder, fileNames );
VaultLib.VaultResponseItem[] responses = m_client.CheckOut( files, VaultLib.VaultCheckOutType.CheckOut, "" );

// We must do a get after the checkout otherwise the client will not be aware that the file
// exists locally and will not be able to check in later.
if( VaultConnection.GetLatestFiles( files ) )
return new List<VaultClientFile>( files );

return null;

Probably self-evident, but m_client is an instance of the ClientInstance class that has previously been created and is connected to our Vault server.

Also, I made sure that the version of the assemblies and the vault server are the same.

shannon

Post by shannon » Wed Apr 30, 2008 9:07 am

I forgot to ask, what version of the api are you using?

random
Posts: 16
Joined: Tue Apr 29, 2008 11:53 am
Location: Longueuil, Québec
Contact:

Post by random » Wed Apr 30, 2008 9:08 am

4.1.1.18060

shannon

Post by shannon » Wed Apr 30, 2008 9:18 am

our VaultConnection class doesn't have a GetFiles or GetLatestFiles method, is this a class you wrote?

random
Posts: 16
Joined: Tue Apr 29, 2008 11:53 am
Location: Longueuil, Québec
Contact:

Post by random » Wed Apr 30, 2008 9:38 am

It is. Here is the code for those methods:

private static VaultClientFile[] GetFiles( VaultClientFolder workingFolder, List<string> fileNames )
{
if( !m_isConnected )
return null;

try
{
List<VaultClientFile> list = new List<VaultClientFile>();

foreach( string fileName in fileNames )
{
if( workingFolder.HasFile( fileName ) )
{
foreach( VaultClientFile file in workingFolder.Files )
{
if( file.Name == fileName )
list.Add( file );
}
}
}

return list.ToArray<VaultClientFile>();
}
catch
{
}

return null;
}


public static bool GetLatestFiles( VaultClientFile[] files )
{
try
{
m_client.Get( files, true, MakeWritableType.MakeAllFilesWritable, SetFileTimeType.Current, MergeType.OverwriteWorkingCopy, null );
m_client.Refresh();
return true;
}
catch
{
}

return false;
}

It is the call to the Get method in GetLatestFiles that is throwing the GetLatestFailedException because of the lack of a working folder.

shannon

Post by shannon » Wed Apr 30, 2008 9:46 am

How are you setting the working folders? Can you log into the gui client and see that they've actually been set?

random
Posts: 16
Joined: Tue Apr 29, 2008 11:53 am
Location: Longueuil, Québec
Contact:

Post by random » Wed Apr 30, 2008 9:47 am

I can. The root ($) folder is set to "d:\localdev.net" and I force the inheritance of all subfolders. I also tried explicitly setting a working folder but the result was the same.

shannon

Post by shannon » Wed Apr 30, 2008 10:15 am

I'm working to figure out your problem, but it's taking some time. Can you give me the exact exception information, maybe a stack trace?

random
Posts: 16
Joined: Tue Apr 29, 2008 11:53 am
Location: Longueuil, Québec
Contact:

Post by random » Wed Apr 30, 2008 10:22 am

at VaultClientOperationsLib.ClientInstance.ProcessGetFileRequests(GetFileInfo[] infos, MakeWritableType makeWritable, SetFileTimeType setFileTime, MergeType merge, Boolean updateHiddenFilesOnly, String ancestorFullPath, Boolean flat, String ancestorDiskPath, OverwritePrompt PromptData, Boolean isLabelGet, String currentPathToLabelItem, Int64 labelID, Boolean isRetry, Boolean isGetByDisplayVersion)
at VaultClientOperationsLib.ClientInstance.Get(VaultClientFile[] files, Boolean forceLatest, MakeWritableType makeWritable, SetFileTimeType setFileTime, MergeType merge, OverwritePrompt PromptData)
at FtsIndexParser.VaultConnection.GetLatestFiles(VaultClientFile[] files) in D:\localdev_vault\Documentation\FtsIndexParser\VaultConnection.cs:line 165
at FtsIndexParser.VaultConnection.CheckOut(String workingFolder, List`1 fileNames) in D:\localdev_vault\Documentation\FtsIndexParser\VaultConnection.cs:line 149
at FtsIndexParser.MainWindow.CloseWindow(Object sender, RoutedEventArgs e) in D:\localdev_vault\Documentation\FtsIndexParser\MainWindow.xaml.cs:line 822
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.ReRaiseEventAs(RoutedEventArgs args, RoutedEvent newEvent)
at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.Run()
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at System.Windows.Application.Run()
at FtsIndexParser.App.Main() in D:\localdev_vault\Documentation\FtsIndexParser\obj\Debug\App.g.cs:line 0
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

random
Posts: 16
Joined: Tue Apr 29, 2008 11:53 am
Location: Longueuil, Québec
Contact:

Post by random » Wed Apr 30, 2008 10:23 am

Just a note: the file is successfully CheckedOut using the API before the Get method is called.

shannon

Post by shannon » Wed Apr 30, 2008 10:59 am

Are you setting your working folders using the gui client or in code with the api?

Can you successfully do a get on one of the files from the gui client? (make sure the file needs a get when you test this, i.e. old)

random
Posts: 16
Joined: Tue Apr 29, 2008 11:53 am
Location: Longueuil, Québec
Contact:

Post by random » Wed Apr 30, 2008 10:59 am

Working folders are set in the GUI client. I can do a getlatest without issues through the GUI client.

shannon

Post by shannon » Wed Apr 30, 2008 11:48 am

Please insert a call to m_client.TreeCache.GetWorkingFolderAssignments before your call to GetBestWorkingFolder and see what it returns.

Post Reply