private void HandleRequest(ITracer tracer, string request, NamedPipeServer.Connection connection) { try { NamedPipeMessages.Message message = NamedPipeMessages.Message.FromString(request); switch (message.Header) { case NamedPipeMessages.Notification.Request.Header: NamedPipeMessages.Notification.Request toastRequest = NamedPipeMessages.Notification.Request.FromMessage(message); if (toastRequest != null) { using (ITracer activity = this.tracer.StartActivity("SendToast", EventLevel.Informational)) { this.ShowToast(activity, toastRequest); } } break; } } catch (Exception e) { this.tracer.RelatedError("Unhandled exception: {0}", e.ToString()); } }
public void SendNotification(NamedPipeMessages.Notification.Request request) { string pipeName = Path.Combine(Path.GetTempPath(), NotificationServerPipeName); using (NamedPipeClient client = new NamedPipeClient(pipeName)) { if (client.Connect()) { try { client.SendRequest(request.ToMessage()); } catch (Exception ex) { EventMetadata metadata = new EventMetadata(); metadata.Add("Area", nameof(NotificationHandler)); metadata.Add("Exception", ex.ToString()); metadata.Add(TracingConstants.MessageKey.ErrorMessage, "MacOS notification display error"); this.tracer.RelatedError(metadata, $"MacOS notification: {request.Title} - {request.Message}."); } } else { this.tracer.RelatedError($"ERROR: Communication failure with native notification display tool. Notification info: {request.Title} - {request.Message}."); } } }
public void SendNotification(NamedPipeMessages.Notification.Request request) { using (NamedPipeClient client = new NamedPipeClient(GVFSConstants.Service.UIName)) { if (client.Connect()) { try { if (!client.TrySendRequest(request.ToMessage())) { this.tracer.RelatedInfo("Failed to send notification request to " + GVFSConstants.Service.UIName); } } catch (Exception ex) { EventMetadata metadata = new EventMetadata(); metadata.Add("Exception", ex.ToString()); metadata.Add("Identifier", request.Id); this.tracer.RelatedError(metadata, $"{nameof(this.SendNotification)}- Could not send notification request({request.Id}. {ex.ToString()}"); } } else { this.tracer.RelatedError($"{nameof(this.SendNotification)}- Could not connect with GVFS.Service.UI, failed to send notification request({request.Id}."); } } }
private void SendNotification(string title, string format, params object[] args) { NamedPipeMessages.Notification.Request request = new NamedPipeMessages.Notification.Request(); request.Title = title; request.Message = string.Format(format, args); NotificationHandler.Instance.SendNotification(this.tracer, request); }
private void DisplayUpgradeAvailableToast(string version) { NamedPipeMessages.Notification.Request request = new NamedPipeMessages.Notification.Request(); request.Id = NamedPipeMessages.Notification.Request.Identifier.UpgradeAvailable; request.NewVersion = version; this.notificationHandler.SendNotification(request); }
public void Setup() { this.tracer = new MockTracer(); this.mockToastNotifier = new Mock <IToastNotifier>(MockBehavior.Strict); this.mockToastNotifier.SetupSet(toastNotifier => toastNotifier.UserResponseCallback = It.IsAny <Action <string> >()).Verifiable(); this.toastHandler = new GVFSToastRequestHandler(this.mockToastNotifier.Object, this.tracer); this.request = new NamedPipeMessages.Notification.Request(); }
private void SendNotification( int sessionId, NamedPipeMessages.Notification.Request.Identifier requestId, string enlistment = null, int enlistmentCount = 0) { NamedPipeMessages.Notification.Request request = new NamedPipeMessages.Notification.Request(); request.Id = requestId; request.Enlistment = enlistment; request.EnlistmentCount = enlistmentCount; this.notificationHandler.SendNotification(sessionId, request); }
public void HandleToastRequest(ITracer tracer, NamedPipeMessages.Notification.Request request) { string title = null; string message = null; string buttonTitle = null; string args = null; string path = null; switch (request.Id) { case NamedPipeMessages.Notification.Request.Identifier.AutomountStart: string reposSuffix = request.EnlistmentCount <= 1 ? VFSForGitSingleRepo : VFSForGitMultipleRepos; title = VFSForGitAutomountStartTitle; message = string.Format(VFSForGitAutomountStartMessageFormat, request.EnlistmentCount, reposSuffix); break; case NamedPipeMessages.Notification.Request.Identifier.MountSuccess: if (this.TryValidatePath(request.Enlistment, out path, this.tracer)) { title = VFSForGitAutomountSuccessTitle; message = string.Format(VFSForGitAutomountSuccessMessageFormat, Environment.NewLine, path); } break; case NamedPipeMessages.Notification.Request.Identifier.MountFailure: if (this.TryValidatePath(request.Enlistment, out path, this.tracer)) { title = VFSForGitAutomountErrorTitle; message = string.Format(VFSForGitAutomountErrorMessageFormat, Environment.NewLine, path); buttonTitle = VFSForGitAutomountButtonTitle; args = $"{VFSForGitRemountActionPrefix} {path}"; } break; case NamedPipeMessages.Notification.Request.Identifier.UpgradeAvailable: title = string.Format(VFSForGitUpgradeTitleFormat, request.NewVersion); message = string.Format(VFSForGitUpgradeMessage); buttonTitle = VFSForGitUpgradeButtonTitle; args = $"{VFSForGitUpgradeActionPrefix}"; break; } if (title != null && message != null) { this.toastNotifier.Notify(title, message, buttonTitle, args); } }
public void SendNotification(ITracer tracer, NamedPipeMessages.Notification.Request request) { NamedPipeClient client; if (!this.TryOpenConnectionToUIProcess(tracer, out client)) { this.TerminateExistingProcess(tracer, GVFSConstants.Service.UIName); if (!ProcessAsCurrentUser.Run( tracer, Configuration.Instance.GVFSServiceUILocation, string.Empty, showWindow: false)) { tracer.RelatedError("Could not start " + GVFSConstants.Service.UIName); return; } this.TryOpenConnectionToUIProcess(tracer, out client); } if (client == null) { tracer.RelatedError("Failed to connect to " + GVFSConstants.Service.UIName); return; } try { if (!client.TrySendRequest(request.ToMessage())) { tracer.RelatedInfo("Failed to send notification request to " + GVFSConstants.Service.UIName); } } finally { client.Dispose(); } }
public void HandleToastRequest(ITracer tracer, NamedPipeMessages.Notification.Request request) { string title = null; string message = null; string buttonTitle = null; string args = null; switch (request.Id) { case NamedPipeMessages.Notification.Request.Identifier.UpgradeAvailable: title = string.Format(ScalarUpgradeTitleFormat, request.NewVersion); message = string.Format(ScalarUpgradeMessage); buttonTitle = ScalarUpgradeButtonTitle; args = $"{ScalarUpgradeActionPrefix}"; break; } if (title != null && message != null) { this.toastNotifier.Notify(title, message, buttonTitle, args); } }
public void SendNotification(int sessionId, NamedPipeMessages.Notification.Request request) { NamedPipeClient client; if (!this.TryOpenConnectionToUIProcess(out client)) { this.TerminateExistingProcess(GSDConstants.Service.UIName); CurrentUser currentUser = new CurrentUser(this.tracer, sessionId); if (!currentUser.RunAs( Configuration.Instance.GSDServiceUILocation, string.Empty)) { this.tracer.RelatedError("Could not start " + GSDConstants.Service.UIName); return; } this.TryOpenConnectionToUIProcess(out client); } if (client == null) { this.tracer.RelatedError("Failed to connect to " + GSDConstants.Service.UIName); return; } try { if (!client.TrySendRequest(request.ToMessage())) { this.tracer.RelatedInfo("Failed to send notification request to " + GSDConstants.Service.UIName); } } finally { client.Dispose(); } }
private void ShowToast(ITracer tracer, NamedPipeMessages.Notification.Request request) { ToastData toastData = new ToastData(); toastData.Visual = new VisualData(); BindingData binding = new BindingData(); toastData.Visual.Binding = binding; binding.Template = "ToastGeneric"; binding.Items = new XmlList <BindingItem>(); binding.Items.Add(new BindingItem.TextData(request.Title)); binding.Items.AddRange(request.Message.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).Select(t => new BindingItem.TextData(t))); XmlDocument toastXml = new XmlDocument(); using (StringWriter stringWriter = new StringWriter()) using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings { OmitXmlDeclaration = true })) { XmlSerializer serializer = new XmlSerializer(toastData.GetType()); XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces(); namespaces.Add(string.Empty, string.Empty); serializer.Serialize(xmlWriter, toastData, namespaces); toastXml.LoadXml(stringWriter.ToString()); } ToastNotification toastNotification = new ToastNotification(toastXml); ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier(ServiceAppId); toastNotifier.Show(toastNotification); }
public void SendNotification(ITracer tracer, int sessionId, NamedPipeMessages.Notification.Request request) { throw new NotImplementedException(); }
public void SendNotification(ITracer tracer, int sessionId, NamedPipeMessages.Notification.Request request) { // Log the notification till platform specific notifications become available. tracer.RelatedInfo($"MacOS notification: {request.Title} - {request.Message}."); }
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.MountRepoRequest.Header: try { NamedPipeMessages.MountRepoRequest mountRequest = NamedPipeMessages.MountRepoRequest.FromMessage(message); MountHandler mountHandler = new MountHandler(activity, this.repoRegistry, connection, mountRequest); mountHandler.Run(); } catch (SerializationException ex) { activity.RelatedError("Could not deserialize mount request: {0}", ex.Message); } break; case NamedPipeMessages.UnmountRepoRequest.Header: try { NamedPipeMessages.UnmountRepoRequest unmountRequest = NamedPipeMessages.UnmountRepoRequest.FromMessage(message); UnmountHandler unmountHandler = new UnmountHandler(activity, this.repoRegistry, connection, unmountRequest); unmountHandler.Run(); } catch (SerializationException ex) { activity.RelatedError("Could not deserialize unmount request: {0}", ex.Message); } break; case NamedPipeMessages.Notification.Request.Header: try { NamedPipeMessages.Notification.Request notificationRequest = NamedPipeMessages.Notification.Request.FromMessage(message); NotificationHandler.Instance.SendNotification(activity, notificationRequest); } catch (SerializationException ex) { activity.RelatedError("Could not deserialize notification request: {0}", ex.Message); } break; default: EventMetadata metadata = new EventMetadata(); metadata.Add("Area", EtwArea); metadata.Add("Header", message.Header); metadata.Add("ErrorMessage", "HandleNewConnection: Unknown request"); this.tracer.RelatedError(metadata); connection.TrySendResponse(NamedPipeMessages.UnknownRequest); break; } } }