Example #1
0
 private void WriteToClient(NamedPipeMessages.RegisterRepoRequest.Response response)
 {
     NamedPipeMessages.Message message = response.ToMessage();
     if (!this.connection.TrySendResponse(message))
     {
         this.tracer.RelatedError("Failed to send line to client: {0}", message);
     }
 }
Example #2
0
        private bool RegisterMount(GVFSEnlistment enlistment, out string errorMessage)
        {
            errorMessage = string.Empty;

            NamedPipeMessages.RegisterRepoRequest request = new NamedPipeMessages.RegisterRepoRequest();
            request.EnlistmentRoot = enlistment.EnlistmentRoot;

            WindowsIdentity  identity  = WindowsIdentity.GetCurrent();
            WindowsPrincipal principal = new WindowsPrincipal(identity);

            request.OwnerSID = identity.User.Value;

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

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

                        if (!string.IsNullOrEmpty(message.ErrorMessage))
                        {
                            errorMessage = message.ErrorMessage;
                            return(false);
                        }

                        if (message.State != NamedPipeMessages.CompletionState.Success)
                        {
                            errorMessage = "Unable to register repo. " + errorMessage;
                            return(false);
                        }
                        else
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        errorMessage = string.Format("GVFS.Service responded with unexpected message: {0}", response);
                        return(false);
                    }
                }
                catch (BrokenPipeException e)
                {
                    errorMessage = "Unable to communicate with GVFS.Service: " + e.ToString();
                    return(false);
                }
            }
        }
Example #3
0
        public void Run()
        {
            string errorMessage = string.Empty;

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

            if (this.registry.TryRegisterRepo(this.request.EnlistmentRoot, this.request.OwnerSID, out errorMessage))
            {
                response.State = NamedPipeMessages.CompletionState.Success;
            }
            else
            {
                response.ErrorMessage = errorMessage;
                response.State        = NamedPipeMessages.CompletionState.Failure;
            }

            this.WriteToClient(response);
        }
Example #4
0
        public void Run()
        {
            string errorMessage = string.Empty;

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

            if (this.registry.TryRegisterRepo(this.request.EnlistmentRoot, this.request.OwnerSID, out errorMessage))
            {
                response.State = NamedPipeMessages.CompletionState.Success;
                this.tracer.RelatedInfo("Registered repo {0}", this.request.EnlistmentRoot);
            }
            else
            {
                response.ErrorMessage = errorMessage;
                response.State        = NamedPipeMessages.CompletionState.Failure;
                this.tracer.RelatedError("Failed to register repo {0} with error: {1}", this.request.EnlistmentRoot, errorMessage);
            }

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