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 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(); }