/// <summary> /// Handle a Repository State request /// /// Gets a path from the stream, then writes a return code, the size of the state data, /// and then invokes RepositoryState.Write (which writes the same way it does to a file). /// </summary> private void HandleStateRequest() { var repoName = _reader.ReadString(); var repo = _config.Repositories[repoName]; if (repo == null || !Directory.Exists(repo.Path)) { _writer.Write(RetCode.BadPath); return; } if (repo.Users.Count(u => u.Name == _userName || u.Name == AnonymousUsername) == 0) { _writer.Write(RetCode.BadAuth); return; } var stateFile = Path.Combine( repo.Path, FooSyncEngine.RepoStateFileName ); if (!File.Exists(stateFile)) { RepositoryStateCollection state = new RepositoryStateCollection(); state.AddRepository(new FooTree(_foo, repo.Path), state.RepositoryID); state.Write(stateFile); } _writer.Write(RetCode.Success); using (var statestream = new FileStream(stateFile, FileMode.Open)) { _writer.Write(statestream.Length); statestream.CopyTo(_stream); } }