public bool Run(out string ErrorMessage)
        {
            // Get the server settings
            string ServerAndPort = SelectedProject.ServerAndPort;
            string UserName      = SelectedProject.UserName;

            string ProjectFileName = null;

            if (SelectedProject.Type == UserSelectedProjectType.Local)
            {
                ProjectFileName = SelectedProject.LocalPath;
            }

            if (!PerforceModalTask.TryGetServerSettings(ProjectFileName, ref ServerAndPort, ref UserName, Log))
            {
                ErrorMessage = "Unable to get Perforce server settings.";
                return(false);
            }

            // Create the connection and make sure we're logged in
            PerforceConnection Perforce = new PerforceConnection(UserName, null, ServerAndPort);

            if (!Perforce.IsLoggedIn(Log))
            {
                ErrorMessage = "User is not logged in to Perforce.";
                return(false);
            }

            // Execute like a regular task
            return(Run(Perforce, Log, out ErrorMessage));
        }
        public bool Run(out string ErrorMessage)
        {
            // Set the default login state to failed
            LoginResult = LoginResult.Failed;

            // Get the server settings
            if (!TryGetServerSettings(ProjectFileName, ref ServerAndPort, ref UserName, Log))
            {
                ErrorMessage = "Unable to get Perforce server settings.";
                return(false);
            }

            // Create the connection
            PerforceConnection Perforce = new PerforceConnection(UserName, null, ServerAndPort);

            // If we've got a password, execute the login command
            if (Password != null)
            {
                string PasswordErrorMessage;
                LoginResult = Perforce.Login(Password, out PasswordErrorMessage, Log);
                if (LoginResult != LoginResult.Succeded)
                {
                    ErrorMessage = String.Format("Unable to login: {0}", PasswordErrorMessage);
                    return(false);
                }
            }

            // Check that we're logged in
            if (!Perforce.IsLoggedIn(Log))
            {
                LoginResult  = LoginResult.MissingPassword;
                ErrorMessage = "User is not logged in to Perforce.";
                return(false);
            }

            // Execute the inner task
            LoginResult = LoginResult.Succeded;
            return(InnerTask.Run(Perforce, Log, out ErrorMessage));
        }
        void PollForUpdates()
        {
            string StreamName;

            if (!Perforce.GetActiveStream(out StreamName, LogWriter))
            {
                StreamName = null;
            }

            // Try to update the zipped binaries list before anything else, because it causes a state change in the UI
            UpdateZippedBinaries();

            while (!bDisposing)
            {
                Stopwatch Timer = Stopwatch.StartNew();

                // Check we still have a valid login ticket
                if (!Perforce.IsLoggedIn(LogWriter))
                {
                    LastStatusMessage = "User is not logged in";
                    OnLoginExpired();
                }
                else
                {
                    // Check we haven't switched streams
                    string NewStreamName;
                    if (Perforce.GetActiveStream(out NewStreamName, LogWriter) && NewStreamName != StreamName)
                    {
                        OnStreamChange();
                    }

                    // Update the stream list
                    if (StreamName != null)
                    {
                        List <string> NewOtherStreamNames;
                        if (!Perforce.FindStreams(PerforceUtils.GetClientOrDepotDirectoryName(StreamName) + "/*", out NewOtherStreamNames, LogWriter))
                        {
                            NewOtherStreamNames = new List <string>();
                        }
                        OtherStreamNames = NewOtherStreamNames;
                    }

                    // Check for any p4 changes
                    if (!UpdateChanges())
                    {
                        LastStatusMessage = "Failed to update changes";
                    }
                    else if (!UpdateChangeTypes())
                    {
                        LastStatusMessage = "Failed to update change types";
                    }
                    else if (!UpdateZippedBinaries())
                    {
                        LastStatusMessage = "Failed to update zipped binaries list";
                    }
                    else
                    {
                        LastStatusMessage = String.Format("Last update took {0}ms", Timer.ElapsedMilliseconds);
                    }
                }

                // Wait for another request, or scan for new builds after a timeout
                RefreshEvent.WaitOne((IsActive? 1 : 10) * 60 * 1000);
            }
        }