Jump to content


P4API.Net "p4 populate" equivalent

P4API.Net

  • Please log in to reply
10 replies to this topic

#1 Elliott Lock

Elliott Lock

    Member

  • Members
  • PipPip
  • 27 posts

Posted 08 October 2017 - 12:07 PM

Hi,

Just started to use the P4API.Netimplementing a GUI to manage naming conventions when creating a new stream.

However, I've come across a problem and I can't figure out how to make a call similar to that of "p4 populate" via the P4API.Net. Can anyone help?


Right now my streams are being created, but they're empty of that initial default change list e.g. "Initial branch of files from main (//streams/main) to release (//streams/release)"

Many Thanks

#2 Sambwise

Sambwise

    Advanced Member

  • Members
  • PipPipPip
  • 325 posts

Posted 08 October 2017 - 04:57 PM

Use the P4Server.RunCommand() method to run the "populate" command.

Alternatively, use "p4 switch -c" to create your new stream -- that command will automatically make a new child stream of the current stream and populate it.  https://www.perforce.../p4_switch.html

#3 Elliott Lock

Elliott Lock

    Member

  • Members
  • PipPip
  • 27 posts

Posted 09 October 2017 - 12:49 PM

Thanks for the info regarding P4Server.RunCommand() to call the populate command. I've tried calling it and I'm having some issues. I'm not too sure what some of the parameters are meant to be, so maybe I'm going wrong there. Right now I'm doing the following:

				string[] stringP4populateArgs = new string[] { "-o", "-r", "-S", stringText };
				p4server.RunCommand("p4 populate", 0, false, stringP4populateArgs, 4);

However, that gives me the following issue:
- $exception {"Unknown command.  Try 'p4 help' for info.\n"} Perforce.P4.P4Exception

Any help would be greatly appreciated

#4 Elliott Lock

Elliott Lock

    Member

  • Members
  • PipPip
  • 27 posts

Posted 09 October 2017 - 01:03 PM

Ok, I fixed one issue, apparently, I didn't need the "p4" just "populate". However, I'd still like it if you could shed some list of the parameter "cmdId" and "tagged" as right now I don't really know if I'm passing the correct values.

Many thanks again

#5 Sambwise

Sambwise

    Advanced Member

  • Members
  • PipPipPip
  • 325 posts

Posted 09 October 2017 - 05:45 PM

The "tagged" parameter indicates whether you want the output in user-readable format (default, same as you get running "p4 populate" at a command prompt) or in a dictionary (tagged, same as you get running "p4 -Ztag populate").

Browsing around through some of the other methods, it looks like cmdID is an arbitrary int that you can use later to refer to that command.   If in the course of your coding you don't find yourself using any other methods that take a cmdID I'd guess you can just pass 0 in there and ignore it.

#6 Elliott Lock

Elliott Lock

    Member

  • Members
  • PipPip
  • 27 posts

Posted 10 October 2017 - 10:11 PM

Thanks

Annoyingly this worked on my test server but since putting the application on the main server with many more files I'm getting the following issue:

Message "Command time out[0]: populate  -o -r -S //streams/test_main_dev" string

Any ideas how to handle this?

Also thanks again, you've been very helpful :)

#7 Sambwise

Sambwise

    Advanced Member

  • Members
  • PipPipPip
  • 325 posts

Posted 11 October 2017 - 12:55 AM

That one's not a Perforce error, so I'm guessing it's a configuration problem with your server -- maybe it times out if something takes too long to run?

#8 Elliott Lock

Elliott Lock

    Member

  • Members
  • PipPip
  • 27 posts

Posted 11 October 2017 - 09:23 PM

Humm, well I thought I was getting there but no. I'm trying to simply do this,,,

			string[] stringArgs = new string[] { };
			p4server.RunCommand("set", 0, false, stringArgs, 0);

But I get exception:

- $exception {"Unknown command.  Try 'p4 help' for info.\n"} Perforce.P4.P4Exception

CmdLine "set" string
+ Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
+ Details null Perforce.P4.P4ClientInfoMessageList
ErrorCode 805379098 int
ErrorLevel E_FAILED Perforce.P4.ErrorSeverity
HResult -2146233088 int
HelpLink null string
+ InnerException null System.Exception
Message "Unknown command.  Try 'p4 help' for info.\n" string
+ NextError null Perforce.P4.P4Exception
Source "p4api.net" string
StackTrace "   at Perforce.P4.P4Exception.Throw(String cmd, String[] args, P4ClientErrorList errors, P4ClientInfoMessageList details)\r\n   at Perforce.P4.P4Server.RunCommand(String cmd, UInt32 cmdId, Boolean tagged, String[] args, Int32 argc)\r\n   at perforceCommander.Form1.testRunCommandToConsole() in C:\\Users\\ellio\\Documents\\Visual Studio 2015\\Projects\\perforceCommander\\perforceCommander\\Form1.cs:line 576\r\n   at perforceCommander.Form1.buttonAdmin_Click(Object sender, EventArgs e) in C:\\Users\\ellio\\Documents\\Visual Studio 2015\\Projects\\perforceCommander\\perforceCommander\\Form1.cs:line 570\r\n   at System.Windows.Forms.Control.onclick(EventArgs e)\r\n   at System.Windows.Forms.Button.onclick(EventArgs e)\r\n   at System.Windows.Forms.Button.onmouseup(MouseEventArgs mevent)\r\n   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)\r\n   at System.Windows.Forms.Control.WndProc(Message& m)\r\n   at System.Windows.Forms.ButtonBase.WndProc(Message& m)\r\n   at System.Windows.Forms.Button.WndProc(Message& m)\r\n   at System.Windows.Forms.Control.ControlNativewindow.OnMessage(Message& m)\r\n   at System.Windows.Forms.Control.ControlNativewindow.WndProc(Message& m)\r\n   at System.Windows.Forms.Nativewindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)\r\n   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)\r\n   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)\r\n   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)\r\n   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)\r\n   at System.Windows.Forms.Application.Run(Form mainForm)\r\n   at perforceCommander.Program.Main() in C:\\Users\\ellio\\Documents\\Visual Studio 2015\\Projects\\perforceCommander\\perforceCommander\\Program.cs:line 19\r\n   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)\r\n   at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args)\r\n   at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)\r\n   at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()\r\n   at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)\r\n   at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)\r\n   at System.Activator.CreateInstance(ActivationContext activationContext)\r\n   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()\r\n   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)\r\n   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)\r\n   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)\r\n   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n   at System.Threading.ThreadHelper.ThreadStart()" string
+ TargetSite {Void Throw(System.String, System.String[], Perforce.P4.P4ClientErrorList, Perforce.P4.P4ClientInfoMessageList)} System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}
+ Static members
+ Non-Public members

#9 Sambwise

Sambwise

    Advanced Member

  • Members
  • PipPipPip
  • 325 posts

Posted 11 October 2017 - 09:29 PM

"set" isn't a Perforce server command, it's a sort of pseudo-command implemented in the p4 CLI as a user interface to the DefineClient()/etc C++ API functions.  In .NET land I think you want P4Server.Get() and P4Server.Set().

C++ implementation of "p4 set" for reference: https://swarm.worksh...entmain.cc#1015

#10 Elliott Lock

Elliott Lock

    Member

  • Members
  • PipPip
  • 27 posts

Posted 17 October 2017 - 08:01 AM

Thanks @Sambwise. This I did not realise. Is there a list of what commands are server based Vs which are not?

#11 Sambwise

Sambwise

    Advanced Member

  • Members
  • PipPipPip
  • 325 posts

Posted 17 October 2017 - 09:11 PM

Almost all commands are just passed directly to the server.  Here's the list that are implemented in the command line client (as of 2017.1):

https://swarm.worksh...ientmain.cc#420

i.e. "merge3", "set", "tickets", "init", "clone", "ignores", "replicate", and also "run" (which is down at line 578).

In general these commands are CLI wrappers around some functionality that's available in the client API where it doesn't make sense to have the server drive it -- "set" is a wrapper around the Define* methods, "merge3" is a wrapper around the DiffMerge class, "tickets" wraps the Ticket class, "run" invokes ClientApi::Run(), etc.

Every other command is passed directly to the server by the CLI, so an app that uses the client API can just do its equivalent of Run("command") and the execution of the command will be driven by the server.





Also tagged with one or more of these keywords: P4API.Net

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users