示例#1
0
        public static IObservable <Unit> PushTheToken <TObject>(this ApplicationModulesManager manager, string serviceName, Func <TObject, string> tokenFactory) where TObject : CloudOfficeBaseObject
        => manager.RegisterViewSimpleAction($"Push{serviceName}Token", typeof(User), ViewType.DetailView)
        .ActivateInUserDetails().FirstAsync()
        .WhenExecute(e => {
#if !NETCOREAPP3_1
            using (var objectSpace = e.Action.Application.CreateObjectSpace()) {
                var authentication = objectSpace.GetObjectByKey <TObject>(SecuritySystem.CurrentUserId);
                var token          = tokenFactory(authentication);

                var fullPath = Path.GetFullPath($"{AppDomain.CurrentDomain.ApplicationPath()}\\..\\PushToken.ps1");
                File.WriteAllText($"{Path.GetDirectoryName(fullPath)}\\{serviceName}Token.txt", token);
                var processStartInfo = new ProcessStartInfo("powershell.exe", $@"""{fullPath}"" '{serviceName}' -SkipPushToken")
                {
                    WorkingDirectory = Directory.GetCurrentDirectory()
                };
                var process = new Process()
                {
                    StartInfo = processStartInfo
                };
                process.StartWithEvents(createNoWindow: false);
                var output = process.WhenOutputDataReceived().Buffer(process.WhenExited).WhenNotEmpty().Do(t => {
                    Tracing.Tracer.LogSeparator("PushToken");
                    Tracing.Tracer.LogText(t.Join(Environment.NewLine));
                }).Publish();
                output.Connect();
                process.WaitForExit();
                return(output.ToUnit());
            }
#else
            return(Observable.Empty <Unit>());
#endif
        });
        public async Task RegisterAction_In_Parallel(int i)
        {
            var applicationModulesManager = new ApplicationModulesManager(new ControllersManager(), "");
            var id           = $"test{i}";
            var simpleAction = await applicationModulesManager.RegisterViewSimpleAction(id).FirstAsync();

            simpleAction.Id.ShouldBe(id);
        }