public UnregisterRepoHandler(ITracer tracer, RepoRegistry registry, NamedPipeServer.Connection connection, NamedPipeMessages.UnregisterRepoRequest request) { this.tracer = tracer; this.registry = registry; this.connection = connection; this.request = request; }
protected virtual void HandleMessage( ITracer tracer, NamedPipeMessages.Message message, NamedPipeServer.Connection connection) { switch (message.Header) { case NamedPipeMessages.RegisterRepoRequest.Header: this.requestDescription = MountRequestDescription; NamedPipeMessages.RegisterRepoRequest mountRequest = NamedPipeMessages.RegisterRepoRequest.FromMessage(message); RegisterRepoHandler mountHandler = new RegisterRepoHandler(tracer, this.repoRegistry, connection, mountRequest); mountHandler.Run(); break; case NamedPipeMessages.UnregisterRepoRequest.Header: this.requestDescription = UnmountRequestDescription; NamedPipeMessages.UnregisterRepoRequest unmountRequest = NamedPipeMessages.UnregisterRepoRequest.FromMessage(message); UnregisterRepoHandler unmountHandler = new UnregisterRepoHandler(tracer, this.repoRegistry, connection, unmountRequest); unmountHandler.Run(); break; case NamedPipeMessages.GetActiveRepoListRequest.Header: this.requestDescription = RepoListRequestDescription; NamedPipeMessages.GetActiveRepoListRequest repoListRequest = NamedPipeMessages.GetActiveRepoListRequest.FromMessage(message); GetActiveRepoListHandler excludeHandler = new GetActiveRepoListHandler(tracer, this.repoRegistry, connection, repoListRequest); excludeHandler.Run(); break; case NamedPipeMessages.EnableAndAttachProjFSRequest.Header: // This request is ignored on non Windows platforms. NamedPipeMessages.EnableAndAttachProjFSRequest.Response response = new NamedPipeMessages.EnableAndAttachProjFSRequest.Response(); response.State = NamedPipeMessages.CompletionState.Success; this.TrySendResponse(tracer, response.ToMessage().ToString(), connection); break; default: this.requestDescription = UnknownRequestDescription; EventMetadata metadata = new EventMetadata(); metadata.Add("Area", this.etwArea); metadata.Add("Header", message.Header); tracer.RelatedWarning(metadata, "HandleNewConnection: Unknown request", Keywords.Telemetry); this.TrySendResponse(tracer, NamedPipeMessages.UnknownRequest, connection); break; } }
private bool UnregisterRepo(string rootPath, out string errorMessage) { errorMessage = string.Empty; NamedPipeMessages.UnregisterRepoRequest request = new NamedPipeMessages.UnregisterRepoRequest(); request.EnlistmentRoot = rootPath; using (NamedPipeClient client = new NamedPipeClient(this.ServicePipeName)) { if (!client.Connect()) { errorMessage = "Unable to unregister repo because GVFS.Service is not responding. " + GVFSVerb.StartServiceInstructions; return(false); } try { client.SendRequest(request.ToMessage()); NamedPipeMessages.Message response = client.ReadResponse(); if (response.Header == NamedPipeMessages.UnregisterRepoRequest.Response.Header) { NamedPipeMessages.UnregisterRepoRequest.Response message = NamedPipeMessages.UnregisterRepoRequest.Response.FromMessage(response); if (message.State != NamedPipeMessages.CompletionState.Success) { errorMessage = message.ErrorMessage; return(false); } else { errorMessage = string.Empty; 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); } } }
private void HandleRequest(ITracer tracer, string request, NamedPipeServer.Connection connection) { NamedPipeMessages.Message message = NamedPipeMessages.Message.FromString(request); if (string.IsNullOrWhiteSpace(message.Header)) { return; } using (ITracer activity = this.tracer.StartActivity(message.Header, EventLevel.Informational, new EventMetadata { { "request", request } })) { switch (message.Header) { case NamedPipeMessages.RegisterRepoRequest.Header: try { NamedPipeMessages.RegisterRepoRequest mountRequest = NamedPipeMessages.RegisterRepoRequest.FromMessage(message); RegisterRepoHandler mountHandler = new RegisterRepoHandler(activity, this.repoRegistry, connection, mountRequest); mountHandler.Run(); } catch (SerializationException ex) { activity.RelatedError("Could not deserialize mount request: {0}", ex.Message); } break; case NamedPipeMessages.UnregisterRepoRequest.Header: try { NamedPipeMessages.UnregisterRepoRequest unmountRequest = NamedPipeMessages.UnregisterRepoRequest.FromMessage(message); UnregisterRepoHandler unmountHandler = new UnregisterRepoHandler(activity, this.repoRegistry, connection, unmountRequest); unmountHandler.Run(); } catch (SerializationException ex) { activity.RelatedError("Could not deserialize unmount request: {0}", ex.Message); } break; case NamedPipeMessages.EnableAndAttachProjFSRequest.Header: try { NamedPipeMessages.EnableAndAttachProjFSRequest attachRequest = NamedPipeMessages.EnableAndAttachProjFSRequest.FromMessage(message); EnableAndAttachProjFSHandler attachHandler = new EnableAndAttachProjFSHandler(activity, connection, attachRequest); attachHandler.Run(); } catch (SerializationException ex) { activity.RelatedError("Could not deserialize attach volume request: {0}", ex.Message); } break; case NamedPipeMessages.GetActiveRepoListRequest.Header: try { NamedPipeMessages.GetActiveRepoListRequest repoListRequest = NamedPipeMessages.GetActiveRepoListRequest.FromMessage(message); GetActiveRepoListHandler excludeHandler = new GetActiveRepoListHandler(activity, this.repoRegistry, connection, repoListRequest); excludeHandler.Run(); } catch (SerializationException ex) { activity.RelatedError("Could not deserialize repo list request: {0}", ex.Message); } break; default: EventMetadata metadata = new EventMetadata(); metadata.Add("Area", EtwArea); metadata.Add("Header", message.Header); this.tracer.RelatedWarning(metadata, "HandleNewConnection: Unknown request", Keywords.Telemetry); connection.TrySendResponse(NamedPipeMessages.UnknownRequest); break; } } }