diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2022-04-28 01:46:21 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2022-04-28 01:46:21 +0300 |
| commit | 59aa6065ebb3481e50c13ec6b4850448fe66186a (patch) | |
| tree | a0fc681cebd3535bc611c270075d74784daaf324 /Software | |
| parent | b9b8126eacf4a4391f9725c91328586dd5446d4b (diff) | |
| download | Tango-59aa6065ebb3481e50c13ec6b4850448fe66186a.tar.gz Tango-59aa6065ebb3481e50c13ec6b4850448fe66186a.zip | |
FSE Procedures Remote Notifications.
Diffstat (limited to 'Software')
11 files changed, 218 insertions, 2 deletions
diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures/IProcedureContext.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures/IProcedureContext.cs index 0d00522ce..f421a88f5 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures/IProcedureContext.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures/IProcedureContext.cs @@ -442,6 +442,35 @@ namespace Tango.FSE.Procedures bool ShowWarningQuestion(String message); /// <summary> + /// Displays an information message to the remote user. + /// </summary> + /// <param name="message">The message.</param> + /// <param name="timeout">Timeout in seconds.</param> + void ShowInfoRemote(String message, int timeout); + + /// <summary> + /// Displays a warning message to the remote user. + /// </summary> + /// <param name="message">The message.</param> + /// <param name="timeout">Timeout in seconds.</param> + void ShowWarningRemote(String message, int timeout); + + /// <summary> + /// Displays an error message to the remote user. + /// </summary> + /// <param name="message">The message.</param> + /// <param name="timeout">Timeout in seconds.</param> + void ShowErrorRemote(String message, int timeout); + + /// <summary> + /// Present the remote user with a question an returns a value indicating the confirmation. + /// </summary> + /// <param name="message">The message.</param> + /// <param name="timeout">Timeout in seconds.</param> + /// <returns></returns> + bool ShowQuestionRemote(String message, int timeout); + + /// <summary> /// Request user input for the specified primitive or complex type (model). /// </summary> /// <typeparam name="T">Type of input (primitive or complex)</typeparam> diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures/ProcedureContext.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures/ProcedureContext.cs index 949863f52..5597c834d 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures/ProcedureContext.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures/ProcedureContext.cs @@ -30,6 +30,7 @@ using Tango.FSE.Procedures.Dialogs; using Tango.FSE.Procedures.Helpers; using Tango.Integration.Operation; using Tango.PMR; +using Tango.PPC.Shared.Notifications; using Tango.Scripting.Basic; using Tango.Scripting.Core; @@ -439,6 +440,46 @@ namespace Tango.FSE.Procedures return AutoInvoke(NotificationProvider.ShowWarningQuestion(message)); } + public void ShowInfoRemote(string message, int timeout) + { + ShowRemoteMessageBox(RemoteMessageBoxType.Info, message, timeout); + } + + public void ShowWarningRemote(string message, int timeout) + { + ShowRemoteMessageBox(RemoteMessageBoxType.Warning, message, timeout); + } + + public void ShowErrorRemote(string message, int timeout) + { + ShowRemoteMessageBox(RemoteMessageBoxType.Error, message, timeout); + } + + public bool ShowQuestionRemote(string message, int timeout) + { + return ShowRemoteMessageBox(RemoteMessageBoxType.Question, message, timeout); + } + + private bool ShowRemoteMessageBox(RemoteMessageBoxType type, String message, int timeout) + { + TimeSpan timespan = TimeSpan.FromSeconds(timeout); + + var response = MachineProvider.MachineOperator.SendGenericRequest< + RemoteMessageBoxRequest, + RemoteMessageBoxResponse>( + new RemoteMessageBoxRequest() + { + Type = type, + Timeout = timespan, + Message = message, + }, new Transport.TransportRequestConfig() + { + Timeout = timespan.Add(TimeSpan.FromSeconds(2)) + }).Result; + + return response.Result; + } + public T RequestUserInputFor<T>(string title, string message) { return RequestUserInputFor<T>(typeof(T).IsValueTypeOrString() ? default(T) : Activator.CreateInstance<T>(), title, message); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteNotifications/DefaultRemoteNotificationsService.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteNotifications/DefaultRemoteNotificationsService.cs new file mode 100644 index 000000000..5931f56ab --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteNotifications/DefaultRemoteNotificationsService.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Tango.Core.DI; +using Tango.Core.Threading; +using Tango.Integration.ExternalBridge; +using Tango.PPC.Common.ExternalBridge; +using Tango.PPC.Common.Notifications; +using Tango.PPC.Shared.Notifications; + +namespace Tango.PPC.Common.RemoteNotifications +{ + [TangoCreateWhenRegistered] + public class DefaultRemoteNotificationsService : IRemoteNotificationsService + { + private INotificationProvider _notification; + + public bool Enabled { get; set; } = true; + + public DefaultRemoteNotificationsService(IPPCExternalBridgeService externalBridge, INotificationProvider notificationProvider) + { + _notification = notificationProvider; + externalBridge.RegisterRequestHandler(this); + } + + [ExternalBridgeRequestHandlerMethod(typeof(RemoteMessageBoxRequest), RequestHandlerLoggingMode.LogRequestName)] + public async Task OnRemoteMessageBoxRequest(RemoteMessageBoxRequest request, String token, ExternalBridgeReceiver receiver) + { + bool result = false; + bool completed = false; + + if (request.Timeout != null) + { + ThreadFactory.StartNew(() => + { + Thread.Sleep(request.Timeout.Value); + + if (!completed) + { + completed = true; + _notification.CurrentMessageBox.Close(false); + receiver.SendErrorResponse(new TimeoutException("The user did not respond within the given timeout."), token); + } + }); + } + + switch (request.Type) + { + case RemoteMessageBoxType.Info: + await _notification.ShowInfo(request.Message); + break; + case RemoteMessageBoxType.Warning: + await _notification.ShowWarning(request.Message); + break; + case RemoteMessageBoxType.Question: + result = await _notification.ShowQuestion(request.Message); + break; + case RemoteMessageBoxType.Error: + await _notification.ShowError(request.Message); + break; + default: + break; + } + + if (completed) return; + + completed = true; + + await receiver.SendGenericResponse(new RemoteMessageBoxResponse() { Result = result }, token); + } + + public void OnReceiverDisconnected(ExternalBridgeReceiver receiver) + { + + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteNotifications/IRemoteNotificationsService.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteNotifications/IRemoteNotificationsService.cs new file mode 100644 index 000000000..a3c1d106b --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteNotifications/IRemoteNotificationsService.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Integration.ExternalBridge; + +namespace Tango.PPC.Common.RemoteNotifications +{ + public interface IRemoteNotificationsService : IPPCService, IExternalBridgeRequestHandler + { + + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj index 48cb50dff..af3531817 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj @@ -188,6 +188,8 @@ <Compile Include="RemoteJob\DefaultRemoteJobService.cs" /> <Compile Include="RemoteJob\IRemoteJobService.cs" /> <Compile Include="RemoteActions\IRemoteActionsService.cs" /> + <Compile Include="RemoteNotifications\DefaultRemoteNotificationsService.cs" /> + <Compile Include="RemoteNotifications\IRemoteNotificationsService.cs" /> <Compile Include="SQL\DefaultRemoteSqlService.cs" /> <Compile Include="SQL\IRemoteSqlService.cs" /> <Compile Include="Synchronization\DefaultMachineDataSynchronizer.cs" /> @@ -525,7 +527,7 @@ </Target> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> + <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> </VisualStudio> </ProjectExtensions> </Project>
\ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Shared/Notifications/RemoteMessageBoxRequest.cs b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Notifications/RemoteMessageBoxRequest.cs new file mode 100644 index 000000000..6ea6c9024 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Notifications/RemoteMessageBoxRequest.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.PPC.Shared.Notifications +{ + public class RemoteMessageBoxRequest + { + public RemoteMessageBoxType Type { get; set; } + public String Message { get; set; } + public TimeSpan? Timeout { get; set; } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Shared/Notifications/RemoteMessageBoxResponse.cs b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Notifications/RemoteMessageBoxResponse.cs new file mode 100644 index 000000000..0b3a31e92 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Notifications/RemoteMessageBoxResponse.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.PPC.Shared.Notifications +{ + public class RemoteMessageBoxResponse + { + public bool Result { get; set; } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Shared/Notifications/RemoteMessageBoxType.cs b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Notifications/RemoteMessageBoxType.cs new file mode 100644 index 000000000..025dd6c75 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Notifications/RemoteMessageBoxType.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.PPC.Shared.Notifications +{ + public enum RemoteMessageBoxType + { + Info, + Warning, + Question, + Error + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Shared/Tango.PPC.Shared.csproj b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Tango.PPC.Shared.csproj index a6eb2de89..3664a1835 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Shared/Tango.PPC.Shared.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Tango.PPC.Shared.csproj @@ -81,6 +81,9 @@ <Compile Include="Logs\GetLogFilesResponse.cs" /> <Compile Include="Logs\RemoteLogFile.cs" /> <Compile Include="Logs\RemoteLogFileType.cs" /> + <Compile Include="Notifications\RemoteMessageBoxResponse.cs" /> + <Compile Include="Notifications\RemoteMessageBoxRequest.cs" /> + <Compile Include="Notifications\RemoteMessageBoxType.cs" /> <Compile Include="Performance\PerformancePackage.cs" /> <Compile Include="Performance\StartPerformanceUpdatesRequest.cs" /> <Compile Include="Performance\StartPerformanceUpdatesResponse.cs" /> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs index 6ce738c24..8513d18ac 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs @@ -30,6 +30,7 @@ using Tango.PPC.Common.RemoteActions; using Tango.PPC.Common.RemoteAssistance; using Tango.PPC.Common.RemoteDesktop; using Tango.PPC.Common.RemoteJob; +using Tango.PPC.Common.RemoteNotifications; using Tango.PPC.Common.SQL; using Tango.PPC.Common.Storage; using Tango.PPC.Common.Synchronization; @@ -105,6 +106,7 @@ namespace Tango.PPC.UI TangoIOC.Default.Unregister<IThreadLoadingService>(); TangoIOC.Default.Unregister<IDataStoreService>(); TangoIOC.Default.Unregister<IBitManager>(); + TangoIOC.Default.Unregister<IRemoteNotificationsService>(); if (App.StartupArgs != null && App.StartupArgs.Contains("-webDebug")) { @@ -150,6 +152,7 @@ namespace Tango.PPC.UI TangoIOC.Default.Register<IThreadLoadingService, DefaultThreadLoadingService>(); TangoIOC.Default.Register<IDataStoreService, DefaultDataStoreService>(); TangoIOC.Default.Register<IBitManager, DefaultBitManager>(); + TangoIOC.Default.Register<IRemoteNotificationsService, DefaultRemoteNotificationsService>(); TangoIOC.Default.Register<LoadingViewVM>(); TangoIOC.Default.Register<MainViewVM>(); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/app.manifest b/Software/Visual_Studio/PPC/Tango.PPC.UI/app.manifest index d72e75011..efc5f8179 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/app.manifest +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/app.manifest @@ -16,7 +16,7 @@ Remove this element if your application requires this virtualization for backwards compatibility. --> - <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> + <!--<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />--> </requestedPrivileges> </security> </trustInfo> |
