如何知道我的 Silverlight 应用程序是否在本地运行?

发布于 2024-12-24 20:17:09 字数 333 浏览 2 评论 0原文

我正在开发 Silverlight 4 应用程序,我想在本地部署应用程序以进行测试时启用/禁用某些功能。

例如,当我在本地测试应用程序时,将禁用指标收集,以避免向我的“实时”指标数据库发送垃圾邮件。

我目前执行此操作的方法是检查主机名。例如,在我的 App.xaml.cs 文件中:

if (HtmlPage.Document.DocumentUri.Host == "localhost")
{
    // Do stuff only when deployed locally
}

是否有更好的方法来执行此操作?

I am developing a Silverlight 4 application and I want to enable/disable some features when deploying the app locally for testing purposes.

For example, metrics collecting will be disabled when I test the application locally to avoid spamming my database of "live" metrics.

The way that I am currently doing this is by checking the host name. For example, in my App.xaml.cs file:

if (HtmlPage.Document.DocumentUri.Host == "localhost")
{
    // Do stuff only when deployed locally
}

Is there a better way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

木緿 2024-12-31 20:17:09

我创建了两个 html 页面来测试我的代码,例如 mysilverlightpage.htmlmyslpage.notracking.html。然后在 myslpage.notracking.html 的对象嵌入标记中添加一个 initparam:

<param name="InitParams" value="noTracking=true" />

然后在我的代码中,我检查我的 InitParams 参数:

if (!App.Current.Host.InitParams.ContainsKey("noTracking") || bool.Parse(App.Current.Host.InitParams["noTracking"]) == false)
{
    // perform tracking here
}

现在可以检查发布版本的功能而不会使跟踪指标无效。

I create two html pages to test my code, for example mysilverlightpage.html and myslpage.notracking.html. Then in the object embed tag for myslpage.notracking.html I add an initparam:

<param name="InitParams" value="noTracking=true" />

Then in my code, I do a check on my InitParams params:

if (!App.Current.Host.InitParams.ContainsKey("noTracking") || bool.Parse(App.Current.Host.InitParams["noTracking"]) == false)
{
    // perform tracking here
}

Now it's possible to check the release version for functionality without invalidating your tracking metrics.

[浮城] 2024-12-31 20:17:09

另一种解决方案是在 Silverlight 项目的“生成”选项卡中定义您自己的条件编译符号(例如:LOCAL),然后使用 #if 语句。当您准备好移动应用程序时,请取出该符号。 (或者以相反的方式进行,因为您实际上正在禁用代码)

Another solution would be to define your own Conditional Compilation symbol in the Build tab of your Silverlight project (eg: LOCAL) and then using the #if statement. Take out the symbol when you're ready to move your app. (Or do it the opposite way since you're actually disabling code)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文