예제 #1
0
파일: ServiceVerb.cs 프로젝트: smodin/GVFS
        private bool TryGetRepoList(out List <string> repoList, out string errorMessage)
        {
            repoList     = null;
            errorMessage = string.Empty;

            NamedPipeMessages.GetActiveRepoListRequest request = new NamedPipeMessages.GetActiveRepoListRequest();

            using (NamedPipeClient client = new NamedPipeClient(this.ServicePipeName))
            {
                if (!client.Connect())
                {
                    errorMessage = "GVFS.Service is not responding.";
                    return(false);
                }

                try
                {
                    client.SendRequest(request.ToMessage());
                    NamedPipeMessages.Message response = client.ReadResponse();
                    if (response.Header == NamedPipeMessages.GetActiveRepoListRequest.Response.Header)
                    {
                        NamedPipeMessages.GetActiveRepoListRequest.Response message = NamedPipeMessages.GetActiveRepoListRequest.Response.FromMessage(response);

                        if (!string.IsNullOrEmpty(message.ErrorMessage))
                        {
                            errorMessage = message.ErrorMessage;
                        }
                        else
                        {
                            if (message.State != NamedPipeMessages.CompletionState.Success)
                            {
                                errorMessage = "Unable to retrieve repo list.";
                            }
                            else
                            {
                                repoList = message.RepoList;
                                return(true);
                            }
                        }
                    }
                    else
                    {
                        errorMessage = string.Format("GVFS.Service responded with unexpected message: {0}", response);
                    }
                }
                catch (BrokenPipeException e)
                {
                    errorMessage = "Unable to communicate with GVFS.Service: " + e.ToString();
                }

                return(false);
            }
        }
예제 #2
0
        public void Run()
        {
            string errorMessage;

            NamedPipeMessages.GetActiveRepoListRequest.Response response = new NamedPipeMessages.GetActiveRepoListRequest.Response();
            response.State    = NamedPipeMessages.CompletionState.Success;
            response.RepoList = new List <string>();

            List <RepoRegistration> repos;

            if (this.registry.TryGetActiveRepos(out repos, out errorMessage))
            {
                List <string> tempRepoList = repos.Select(repo => repo.EnlistmentRoot).ToList();

                foreach (string repoRoot in tempRepoList)
                {
                    if (!this.IsValidRepo(repoRoot))
                    {
                        if (!this.registry.TryRemoveRepo(repoRoot, out errorMessage))
                        {
                            this.tracer.RelatedInfo("Removing an invalid repo failed with error: " + response.ErrorMessage);
                        }
                        else
                        {
                            this.tracer.RelatedInfo("Removed invalid repo entry from registry: " + repoRoot);
                        }
                    }
                    else
                    {
                        response.RepoList.Add(repoRoot);
                    }
                }
            }
            else
            {
                response.ErrorMessage = errorMessage;
                response.State        = NamedPipeMessages.CompletionState.Failure;
                this.tracer.RelatedError("Get active repo list failed with error: " + response.ErrorMessage);
            }

            this.WriteToClient(response.ToMessage(), this.connection, this.tracer);
        }
예제 #3
0
        public void Run()
        {
            string errorMessage;

            NamedPipeMessages.GetActiveRepoListRequest.Response response = new NamedPipeMessages.GetActiveRepoListRequest.Response();

            List <RepoRegistration> repos;

            if (this.registry.TryGetActiveRepos(out repos, out errorMessage))
            {
                response.RepoList = repos.Select(repo => repo.EnlistmentRoot).ToList();
                response.State    = NamedPipeMessages.CompletionState.Success;
            }
            else
            {
                response.ErrorMessage = errorMessage;
                response.State        = NamedPipeMessages.CompletionState.Failure;
                this.tracer.RelatedError("Get active repo list failed with error: " + response.ErrorMessage);
            }

            this.WriteToClient(response.ToMessage(), this.connection, this.tracer);
        }