Exemple #1
0
        public static P4.Repository get(String Port, String User, String Workspace)
        {
            // Verify Paramiters
            if (string.IsNullOrEmpty(Port))
            {
                throw new P4.P4Exception(P4.ErrorSeverity.E_FATAL, "P4PORT is invalid or not set");
            }

            // Set connection options
            P4.Options options = new P4.Options();
            options["ProgramName"]    = "P4VS";
            options["ProgramVersion"] = Versions.product();

            // Get Server connection
            P4.Server server = new P4.Server(new P4.ServerAddress(Port));

            // Create new Repository
            Repository = new P4.Repository(server);

            // set User
            if (!string.IsNullOrEmpty(User))
            {
                Repository.Connection.UserName = User;
            }

            // set Client
            if (!string.IsNullOrEmpty(Workspace))
            {
                P4.Client client = new P4.Client();
                client.Name = Workspace;
                Repository.Connection.Client = client;
            }

            // Connect...
            try
            {
                logger.Debug("AsyncConnectToRepository - Connect");
                bool connectResults = Repository.Connection.Connect(options);
                logger.Debug("AsyncConnectToRepository, result {0}", connectResults);
            }
            catch (P4.P4Exception ex)
            {
                // Look for trust errors
                checkTrust(ex);
            }

            // Set Command Timeout limits
            TimeSpan defCmdTimeout = TimeSpan.FromSeconds(30);
            TimeSpan cmdTimeout    = Preferences.LocalSettings.GetTimeSpan("CommandTimeOut", defCmdTimeout);

            Repository.Connection.CommandTimeout = cmdTimeout;

            return(Repository);
        }
Exemple #2
0
        public void Init(P4.Repository rep)
        {
            if (rep == null)
            {
                mDepotTreeView.Enabled = false;
                return;
            }
            // Initialize the depot tree view
            P4.P4Directory root     = new P4.P4Directory(rep, null, "depot", "//depot", null, null);
            TreeNode       rootNode = new TreeNode("Depot");

            rootNode.Tag                = root;
            rootNode.ImageIndex         = 0;
            rootNode.SelectedImageIndex = 0;
            rootNode.Nodes.Add(new TreeNode("empty"));
            mDepotTreeView.Nodes.Clear();
            mDepotTreeView.Nodes.Add(rootNode);
        }
Exemple #3
0
        private void initConnection(bool noUI, string path, bool clientNotRequired)
        {
            ID = _id++;

            if (P4.LogFile.ExternalLogFn == null)
            {
                P4.LogFile.LogMessageDelgate logfn = new LogFile.LogMessageDelgate(FileLogger.LogMessage);
                P4.LogFile.SetLoggingFunction(logfn);
            }

            // reset bool on init
            ssoSuccess = true;

            _disconnected = true;

            if (Repository != null)
            {
                Repository.Dispose();
                Repository = null;
            }

            while (Repository == null)
            {
                // Get connection settings from dialog, if UI required
                if (!noUI)
                {
                    // reset the SSO bool, so login will be attempted again
                    ssoSuccess = true;
                    // Open Connection dialog
                    DialogResult result = connectionDialog();
                    if (result == DialogResult.Cancel)
                    {
                        return;
                    }
                }

                // Get the credentials for the Perforce Server
                try
                {
                    // Get configuration
                    getConfiguration(path);

                    // Create repository from server connection
                    Repository = RepositoryFactory.get(Port, User, Workspace);

                    // set Swarm here since Login will check Swarm availability
                    Swarm = new Swarm(Repository, User);
                    if (string.IsNullOrEmpty(Workspace) && !clientNotRequired)
                    {
                        DialogResult res = P4ErrorDlg.Show(Resources.P4ScmProvider_WorkspaceEnvUnset,
                                                           false, false);
                        P4VsProvider.BroadcastNewConnection(null);
                        return;
                    }

                    if (Repository == null ||
                        Repository.Connection.Status == P4.ConnectionStatus.Disconnected)
                    {
                        Repository = null;
                        continue;
                    }

                    // Set configuration
                    setConfiguration();

                    // Check API level of server is greater than 28 (2009.2)
                    checkApiLevel(28);

                    // set Swarm here since Login will check Swarm availability
                    Swarm = new Swarm(Repository, User);

                    // Login if required
                    if (!string.IsNullOrEmpty(User) && !isLoggedIn())
                    {
                        if (!ssoSuccess)
                        {
                            break;
                        }
                        LoginResult loginResult = Login();
                        if (loginResult == LoginResult.HASTimeout)
                        {
                            P4VS.UI.P4VSMessage p4VSMessage = new P4VS.UI.P4VSMessage(Resources.P4VS,
                                                                                      string.Format(Resources.HAS_Auth_Fail,
                                                                                                    Repository.Connection.UserName, Repository.Connection.Server.Address.Uri));
                            p4VSMessage.ShowDialog();
                            return;
                        }
                        if (loginResult == LoginResult.Fail)
                        {
                            Repository = null;
                            continue;
                        }
                    }

                    // Exit if no client defined
                    if (!string.IsNullOrEmpty(User) && !string.IsNullOrEmpty(Workspace))
                    {
                        setWorkspace();

                        // Save Connection as User and Workspace are good
                        saveRecentConnection();
                    }
                    else
                    {
                        logger.Warn("Workspace not initialised.");
                    }

                    if (Repository.Connection.Server.Metadata.UnicodeEnabled)
                    {
                        string cs = Repository.Connection.CharacterSetName;
                        string m  = string.Format(Resources.P4ScmProvider_ConnectingToUnicodeServer, cs);
                        P4VsOutputWindow.AppendMessage(m);
                        FileLogger.LogMessage(3, "P4ScmProvider", m);
                    }

                    // Subscribe to the output events to display results in the command window
                    Repository.Connection.InfoResultsReceived  += CommandLine.InfoResultsCallbackFn;
                    Repository.Connection.ErrorReceived        += CommandLine.ErrorCallbackFn;
                    Repository.Connection.TextResultsReceived  += CommandLine.TextResultsCallbackFn;
                    Repository.Connection.TaggedOutputReceived += CommandLine.TaggedOutputCallbackFn;
                    Repository.Connection.CommandEcho          += CommandLine.CommandEchoCallbackFn;

                    _disconnected = false;

                    // Connection OK, break out of loop
                    break;
                }
                catch (P4Exception ex)
                {
                    if (ex.ErrorCode == P4.P4ClientError.MsgServer_Login2Required)
                    {
                        P4VsProvider.CurrentScm = new P4ScmProvider(null);
                        if (P4VsProvider.CurrentScm.LaunchHelixMFA(User, Port) == 0)
                        {
                            noUI = true;
                            initConnection(noUI, path, clientNotRequired);
                        }
                    }
                    else
                    {
                        logger.Trace("caught an Exception: {0}\r\n{1}", ex.Message, ex.StackTrace);
                        if (Repository != null)
                        {
                            Repository.Dispose();
                            Repository = null;
                        }
                        MessageBox.Show(ex.Message, Resources.P4VS, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        P4VsOutputWindow.AppendMessage(ex.Message);
                    }
                    // If we're not showing the connection dialog return a null
                    if (noUI)
                    {
                        return;
                    }
                }
                catch (Exception ex)
                {
                    logger.Trace("caught an Exception: {0}\r\n{1}", ex.Message, ex.StackTrace);
                    if (Repository != null)
                    {
                        Repository.Dispose();
                        Repository = null;
                    }
                    MessageBox.Show(ex.Message, Resources.P4VS, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    P4VsOutputWindow.AppendMessage(ex.Message);

                    // If we're not showing the login dialog return a null as the credentials are bad
                    if (noUI)
                    {
                        return;
                    }
                }
            }

            Repository.Connection.KeepAlive    = new KeepAliveMonitor();
            JobsToolWindowControl.GotJobFields = false;
        }
Exemple #4
0
        public DepotPathDlg(P4.Repository rep)
        {
            InitializeComponent();

            Init(rep);
        }
Exemple #5
0
 public Swarm(P4.Repository repository, string user)
 {
     this.repository = repository;
     this.user       = user;
 }