Example #1
0
 /// <summary>
 /// Constructer
 /// </summary>
 /// <param name="server">Target P4Server</param>
 /// <param name="command">Command String i.e 'submit'</param>
 /// <param name="taggedOutput">Run in tagged protocol</param>
 /// <param name="arguments">Arguments for the command</param>
 public P4Command(P4Server server,
                  String command,
                  bool taggedOutput,
                  params String[] arguments)
     : this(server, command, null, taggedOutput, arguments)
 {
 }
Example #2
0
 /// <summary>
 /// Create a new P4MapApi
 /// </summary>
 /// <param name="pserver">The P4Server on which the map will be used</param>
 /// <remarks>
 /// The server is needed to know whether or not it is necessary to translate
 /// strings to/from Unicode </remarks>
 public P4MapApi(P4Server pserver)
 {
     if (pserver != null)
     {
         UseUnicode = pserver.UseUnicode;
     }
     pMapApi = CreateMapApi();
 }
Example #3
0
 /// <summary>
 /// Constructer
 /// </summary>
 /// <param name="server">Target P4Server</param>
 /// <param name="command">Command String i.e 'submit'</param>
 /// <param name="promptHandler">Handler function</param>
 /// <param name="taggedOutput">Run in tagged protocol</param>
 /// <param name="arguments">Arguments for the command</param>
 public P4Command(P4Server server,
                  String command,
                  P4Server.PromptHandlerDelegate promptHandler,
                  bool taggedOutput,
                  params String[] arguments)
     : this(server, promptHandler)
 {
     cmd    = command;
     tagged = taggedOutput;
     args   = arguments;
 }
Example #4
0
        /// <summary>
        /// Thread entry point for running more P4Servers
        /// </summary>
        private static void ParallelTransferThread(object args)
        {
            ParallelTransferArgs transferArgs = (ParallelTransferArgs)args;

            // make a new connection to the server and run the command
            // we should not need trust or fingerprint as this should initiate from a successful (trusted) session
            using (P4Server target = new P4Server(transferArgs.original))
            {
                // add the server for the original P4Server
                lock (transferArgs.original.parallelServers)
                {
                    transferArgs.original.parallelServers.Add(target);
                }

                // set the dictionary as protocol settings
                foreach (KeyValuePair p in transferArgs.dict)
                {
                    P4Bridge.SetProtocol(target.pServer, p.Key, p.Value);
                }

                try
                {
                    // Note: due to legacy (unused) cmdId code in p4bridge, cmdId < 0 will explicitly not call
                    //       the assigned callbacks.  set the cmdId from the other's cmdId generator
                    if (target.RunCommand(transferArgs.cmd, transferArgs.original.getCmdId(), true, transferArgs.args, transferArgs.args.Length))
                    {
                        target.Disconnect();
                        return;
                    }
                }
                catch (P4Exception e)
                {
                    Debug.Trace(e.Message);
                }
                // grab the errors and inject them into the original P4Server
                P4ClientErrorList list = target.GetErrorResults(0);
                // sometimes we get here without client errors (e.g. disconnect?)
                if (transferArgs.original.parallelErrors != null && list != null)
                {
                    // make sure the threads don't step on each other
                    lock (transferArgs.original.parallelErrors)
                    {
                        foreach (P4ClientError e in list)
                        {
                            transferArgs.original.parallelErrors.Add(e);
                        }
                    }
                }
            }
        }
Example #5
0
        // for parallel operations, a special constructor to hook up all of the delegates from the command initiator
        private P4Server(P4Server source) : this(source._server, source.User, source.Password, source.Client, source._cwd)
        {
            // add the original's callback delegates to this connection so the messages seem like they are flowing from the original server
            // do all 5: tagged output, errors, info, text, and binary
            // it's unlikely to get info/text/binary for parallel operations at this point, but whatever

            // TODO: remove these later?  I don't think it matters as we are not modifying
            //       the server's list, just adding its event handlers to our event processing
            if (source.TaggedOutputReceived != null)
            {
                Delegate[] tor = source.TaggedOutputReceived.GetInvocationList();
                foreach (TaggedOutputDelegate d in tor)
                {
                    TaggedOutputReceived += d;
                }
            }
            if (source.ErrorReceived != null)
            {
                Delegate[] err = source.ErrorReceived.GetInvocationList();
                foreach (ErrorDelegate d in err)
                {
                    ErrorReceived += d;
                }
            }
            if (source.InfoResultsReceived != null)
            {
                Delegate[] info = source.InfoResultsReceived.GetInvocationList();
                foreach (InfoResultsDelegate d in info)
                {
                    InfoResultsReceived += d;
                }
            }
            if (source.TextResultsReceived != null)
            {
                Delegate[] textResults = source.TextResultsReceived.GetInvocationList();
                foreach (TextResultsDelegate d in textResults)
                {
                    TextResultsReceived += d;
                }
            }
            if (source.BinaryResultsReceived != null)
            {
                Delegate[] binaryResults = source.BinaryResultsReceived.GetInvocationList();
                foreach (BinaryResultsDelegate d in binaryResults)
                {
                    source.BinaryResultsReceived += d;
                }
            }
        }
Example #6
0
        /// <summary>
        /// Translate a returned string based on the UseUnicode setting
        /// </summary>
        /// <param name="pStr"> Native pointer to the string</param>
        /// <returns>UTF-16 String</returns>
        internal String MarshalPtrToString(IntPtr pStr)
        {
            try
            {
                if (UseUnicode)
                {
                    return(P4Server.MarshalPtrToStringUtf8_Int(pStr));
                }

                return(Marshal.PtrToStringAnsi(pStr));
            }
            catch (Exception ex)
            {
                LogFile.LogException("MarshalPtrToString", ex);
                return(null);
            }
        }
Example #7
0
 /// <summary>
 /// Create/retreive a P4Server for a different thread
 /// </summary>
 /// <param name="threadId">Managed thread ID of the other thread</param>
 /// <returns>P4Server connection</returns>
 public P4Server getServerForThread(int threadId)
 {
     lock (dictLock)
     {
         if (mapTIDtoServer.ContainsKey(threadId))
         {
             return(mapTIDtoServer[threadId]);
         }
         // only call the fingerprint constructor if we got configured with a fingerprint
         // otherwise it will not throw the correct "you need to trust this" exception
         // (which seems wrong, both methods should operate similarly))
         P4Server p4server = (fingerprint != null && fingerprint.Length != 0) ||
                             (trustFlag != null && trustFlag.Length != 0) ?
                             new P4Server(server, user, pass, ws_client, cwd, trustFlag, fingerprint) :
                             new P4Server(server, user, pass, ws_client, cwd);
         p4server.SetThreadOwner(threadId);
         mapTIDtoServer[threadId] = p4server;
         return(p4server);
     }
 }
Example #8
0
        /// <summary>
        /// Create a new command
        /// </summary>
        public P4Command(P4Server server, P4Server.PromptHandlerDelegate promptHandler)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server",
                                                "P4Command requires a P4Server");
            }
            pServer = server;

            CommandId = server.getCmdId();

            onInfoResultsDelegate =
                new P4Server.InfoResultsDelegate(OnInfoOut);

            if (promptHandler != null)
            {
                CmdPromptHandler = promptHandler;
            }
            else
            {
                CmdPromptHandler =
                    new P4Server.PromptHandlerDelegate(HandlePrompt);
            }
        }
Example #9
0
 /// <summary>
 /// Create a new command
 /// </summary>
 public P4Command(P4Server server)
     : this(server, null)
 {
 }