Beispiel #1
0
        private void btnTestConnection_Click(object sender, EventArgs e)
        {
            var p4Service = new P4Service(_server.Text, _user.Text, _password.Text, _workspace.Text, _useP4Config.Checked, null, new Map());

            bool isSuccessful = true;

            try
            {
                p4Service.Connect();
            }
            catch (Exception ex)
            {
                isSuccessful = false;
                MessageBox.Show(ex.Message, Resources.CONNECTION_FAILED, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                p4Service.Disconnect();
                p4Service.Dispose();
                if (isSuccessful)
                {
                    MessageBox.Show(Resources.CONNECTION_SUCCEEDED);
                }
            }
        }
Beispiel #2
0
        private void SetFileStates(IList <string> fileNames)
        {
            if (fileNames.Count == 0)
            {
                return;
            }
            Trace.WriteLineIf(_traceSwitch.TraceVerbose,
                              String.Format("P4Cache.SetFileStates(IList) started: _server={0}, _user={1}, _workspace={2}, _solutionPath={3}",
                                            _server, _user, _workspace, _solutionPath));
            var p4Service = new P4Service(_server, _user, _password, _workspace, _useP4Config, _solutionPath, _map);

            try
            {
                p4Service.Connect();
            }
            catch (ArgumentException)
            {
                Trace.WriteLineIf(_traceSwitch.TraceVerbose, "P4Cache.SetFileStates(IList) got ArgumentException");
                p4Service.Dispose();
                // We can't handle this exception because we are on a background thread.
                // But the File States will show we are not connected.
                string msg = String.Format("ArgumentException in VS2P4.P4Cache.SetFileStates() -- Unable to connect to P4 at server={0} and user={1}", _server, _user);
                Log.Error(msg);
                return;
            }
            catch (P4API.Exceptions.PerforceInitializationError)
            {
                Trace.WriteLineIf(_traceSwitch.TraceVerbose, "P4Cache.SetFileStates(IList) got PerforceInitializationError");
                p4Service.Dispose();
                // We can't handle this exception because we are on a background thread.
                // But the File States will show we are not connected.
                string msg = String.Format("PerforceInitializationError in VS2P4.P4Cache.SetFileStates() -- Unable to connect to P4 at server={0} and user={1}", _server, _user);
                Log.Error(msg);
                return;
            }
            finally
            {
                Trace.WriteLineIf(_traceSwitch.TraceVerbose, "P4Cache.SetFileStates(IList) finished attempt to create P4Service");
            }
            Trace.WriteLineIf(_traceSwitch.TraceVerbose, "P4Cache.SetFileStates(IList) created P4Service");

            lock (_fileStatesLock)
            {
                Trace.WriteLineIf(_traceSwitch.TraceVerbose, "P4Cache.SetFileStates(IList) locked _fileStatesLock");
                Dictionary <string, FileState> states = p4Service.GetFileStates(fileNames);
                foreach (var fileName in states.Keys)
                {
                    Trace.WriteLineIf(_traceSwitch.TraceVerbose, String.Format("P4Cache.SetFileStates(IList) setting state for file {0}", fileName));
                    FileState state = states[fileName];
                    _fileStates[fileName] = state;
                    Trace.WriteLineIf(_traceSwitch.TraceVerbose, String.Format("P4Cache.SetFileStates(IList) state set for file {0} to {1}", fileName, state.ToString()));
                }
                Trace.WriteLineIf(_traceSwitch.TraceVerbose, "P4Cache.SetFileStates(IList) unlocking _fileStatesLock");
            }

            p4Service.Disconnect();
            p4Service.Dispose();
            Trace.WriteLineIf(_traceSwitch.TraceVerbose, "P4Cache.SetFileStates(IList) completed");
        }
        private void btnTestConnection_Click(object sender, EventArgs e)
        {
            if (_sccProviderService == null)
            {
                Log.Error("Missing SccProviderService");
                return;
            }
            P4Service p4Service;

            if (_useP4Config.Checked)
            {
                string solutionName = _sccProviderService.SccProvider.GetSolutionFileName();
                var    solutionPath = "";
                if (!String.IsNullOrEmpty(solutionName))
                {
                    solutionPath = Path.GetDirectoryName(solutionName);
                }
                p4Service = new P4Service("", "", "", "", true, solutionPath, _sccProviderService.Map);
            }
            else
            {
                p4Service = new P4Service(_server.Text, _user.Text, _password.Text, _workspace.Text, _useP4Config.Checked, null, _sccProviderService.Map);
            }

            bool isSuccessful = true;

            try
            {
                p4Service.Connect();
            }
            catch (Exception ex)
            {
                isSuccessful = false;
                MessageBox.Show(ex.Message, Resources.CONNECTION_FAILED, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                p4Service.Disconnect();
                p4Service.Dispose();
                if (isSuccessful)
                {
                    var msg = Resources.CONNECTION_SUCCEEDED;
                    if (_sccProviderService != null && _sccProviderService.Map != null)
                    {
                        var root = _sccProviderService.Map.Root;
                        msg += "\nPerforce root is " + root;
                    }
                    MessageBox.Show(msg);
                }
            }
        }
Beispiel #4
0
        private void SetFileStates(IList <string> fileNames)
        {
            var p4Service = new P4Service(_server, _user, _password, _workspace, _useP4Config, _solutionPath, _map);

            try
            {
                p4Service.Connect();
            }
            catch (ArgumentException)
            {
                p4Service.Dispose();
                // We can't handle this exception because we are on a background thread.
                // But the File States will show we are not connected.
                string msg = String.Format("ArgumentException in VS2P4.P4Cache.SetFileStates() -- Unable to connect to P4 at server={0} and user={1}", _server, _user);
                Log.Error(msg);
                return;
            }
            catch (P4API.Exceptions.PerforceInitializationError)
            {
                p4Service.Dispose();
                // We can't handle this exception because we are on a background thread.
                // But the File States will show we are not connected.
                string msg = String.Format("PerforceInitializationError in VS2P4.P4Cache.SetFileStates() -- Unable to connect to P4 at server={0} and user={1}", _server, _user);
                Log.Error(msg);
                return;
            }

            lock (_fileStatesLock)
            {
                Dictionary <string, FileState> states = p4Service.GetFileStates(fileNames);
                foreach (var fileName in states.Keys)
                {
                    FileState state = states[fileName];
                    _fileStates[fileName] = state;
                }
            }


            p4Service.Disconnect();
            p4Service.Dispose();
        }