gpt4 book ai didi

sitecore - 无法让 Sitecore JobMonitor/JobContext 显示对话框

转载 作者:行者123 更新时间:2023-12-01 12:43:20 24 4
gpt4 key购买 nike

根据 this blog post by Adam Najmanowicz ,使用 Sitecore.Jobs.AsyncUI 中的 JobMonitor 和 JobContext 类从后台作业打开警报或确认对话框应该相对容易。我无法让它工作。谁能告诉我我错过了什么?我的控件的 CodeBeside 类如下。我试过将它作为模式对话框和应用程序打开,但它没有显示任何警报。

public class JobMonitorTestForm : BaseForm
{
protected JobMonitor Monitor;

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);

if (this.Monitor == null)
{
if (!Context.ClientPage.IsEvent)
{
this.Monitor = new JobMonitor { ID = "Monitor" };
Context.ClientPage.Controls.Add(this.Monitor);
}
else
{
this.Monitor = Context.ClientPage.FindControl("Monitor") as JobMonitor;
}
}

this.Monitor.JobFinished += this.JobFinished;
this.Monitor.JobDisappeared += this.JobFinished;

this.Monitor.Start("JobMonitorTest", "Test", this.Run);
}

private void JobFinished(object sender, EventArgs eventArgs)
{
SheerResponse.Alert("Job finished!");
}

private void Run()
{
Thread.Sleep(2000);
JobContext.Alert("Hello!");
Thread.Sleep(2000);
}
}

更新

我找到了另一条线索,但我仍然一头雾水。我的日志文件显示以下异常。这是 Sitecore.Web.UI.Sheer.ClientPage 的构造函数中的空引用异常,因为 HttpContext.Current 为空。这是有道理的,因为调用是从后台线程启动的,但我认为 AsyncUI 命名空间中的类的全部意义在于解决这个问题。

ManagedPoolThread #3 23:18:28 ERROR Exception
Exception: System.Reflection.TargetInvocationException
Message: Exception has been thrown by the target of an invocation.
Source: mscorlib
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at (Object , Object[] )
at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
at Sitecore.Jobs.Job.ThreadEntry(Object state)

Nested Exception

Exception: System.NullReferenceException
Message: Object reference not set to an instance of an object.
Source: Sitecore.Kernel
at Sitecore.Web.UI.Sheer.ClientPage..ctor()
at Sitecore.Web.UI.Sheer.SheerResponse.Alert(String text, String[] arguments)
at TestApp.sitecore.shell.Applications.Dialogs.JobMonitorTest.JobMonitorTestForm.Run() in c:\Projects\sc66Test\TestApp\TestApp\sitecore\shell\Applications\Dialogs\JobMonitorTest\JobMonitorTestForm.cs:line 45
at Sitecore.Jobs.AsyncUI.JobMonitor.TaskRunner.Run()

最佳答案

您发布的代码有一个小问题,就像异步 UI 中的任何内容一样引起了大量调查:)

问题在于时机。您不能在 OnLoad 中执行作业创建,因为这会在请求有时间往返于用户并由浏览器中的监视器控件处理之前使用监视器。基本上,工作还没有什么可坚持的。

有两种解决方法。您可以显示您的对话框,并作为用户按下按钮/功能区/菜单,这将触发一个事件来启 Action 业。另一种方法是我在 PowerShell Extensions 中所做的当我想让运行者在没有用户干预的情况下开始工作时。在 Sheer 控件中包含一个 JavaScript,它会在页面加载后向您的对话框发送一个事件:

window.onload=function(){
scForm.postRequest("", "", "", "psr:execute");
};

然后在您控件的代码旁边:

[HandleMessage("psr:execute", true)]
protected virtual void Execute(ClientPipelineArgs args)
{
// Do the Job starting through the monitor.
}

希望对您有所帮助。如果您有任何问题,我将非常乐意分享更多详细信息或提供示例

关于sitecore - 无法让 Sitecore JobMonitor/JobContext 显示对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22241653/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com