Ejemplo n.º 1
0
 public AttachGvFltHandler(
     ITracer tracer,
     NamedPipeServer.Connection connection,
     NamedPipeMessages.AttachGvFltRequest request)
 {
     this.tracer     = tracer;
     this.connection = connection;
     this.request    = request;
 }
Ejemplo n.º 2
0
        private bool AttachGvFltThroughService(GVFSEnlistment enlistment, out string errorMessage)
        {
            errorMessage = string.Empty;

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

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

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

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

                        if (message.State != NamedPipeMessages.CompletionState.Success)
                        {
                            errorMessage = "Failed to attach GvFlt to volume.";
                            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);
                }
            }
        }
Ejemplo n.º 3
0
        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.AttachGvFltRequest.Header:
                    try
                    {
                        NamedPipeMessages.AttachGvFltRequest attachRequest = NamedPipeMessages.AttachGvFltRequest.FromMessage(message);
                        AttachGvFltHandler attachHandler = new AttachGvFltHandler(activity, connection, attachRequest);
                        attachHandler.Run();
                    }
                    catch (SerializationException ex)
                    {
                        activity.RelatedError("Could not deserialize attach volume request: {0}", ex.Message);
                    }

                    break;

                case NamedPipeMessages.ExcludeFromAntiVirusRequest.Header:
                    try
                    {
                        NamedPipeMessages.ExcludeFromAntiVirusRequest excludeFromAntiVirusRequest = NamedPipeMessages.ExcludeFromAntiVirusRequest.FromMessage(message);
                        ExcludeFromAntiVirusHandler excludeHandler = new ExcludeFromAntiVirusHandler(activity, connection, excludeFromAntiVirusRequest);
                        excludeHandler.Run();
                    }
                    catch (SerializationException ex)
                    {
                        activity.RelatedError("Could not deserialize exclude from antivirus 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;
                }
            }
        }