问题列表 - 第43993页

停止Magento事件观察员结账的正确方法是什么?

我在事件checkout_controller_onepage_save_shipping_method期间验证运费报价,如果验证失败,我想将用户发送回运送方式选择,但我还想显示一条消息,说明它失败的原因.Magento有办法内置吗?

我已经在验证数据,我只是缺少重定向到发货方式和显示消息的方式.

php magento

2
推荐指数
2
解决办法
5732
查看次数

验证asp.net mvc中的下拉列表

//in controller
ViewBag.Categories = categoryRepository.GetAllCategories().ToList();

//in view
 @Html.DropDownList("Cat", new SelectList(ViewBag.Categories,"ID", "CategoryName"))
Run Code Online (Sandbox Code Playgroud)

如何制作它以便默认情况下显示"-Select Category-"

并验证检查选择的内容(客户端和模型)

谢谢

c# asp.net-mvc razor

37
推荐指数
2
解决办法
10万
查看次数

Facebook开放图表帖子的网址是什么?

给定图搜索返回的帖子ID,例如:186173001411937

是否有一个网址链接到Facebook的帖子?以下网址无效:http: //www.facebook.com/post.php?id = 186173001411937

facebook facebook-graph-api

17
推荐指数
3
解决办法
1万
查看次数

CorrelationManager.LogicalOperationStack是否与Parallel.For,Tasks,Threads等兼容

有关背景信息,请参阅此问题:

任务并行库中的任务如何影响ActivityID?

该问题询问Tasks如何影响Trace.CorrelationManager.ActivityId.@Greg Samson用测试程序回答了他自己的问题,显示ActivityId在Tasks的上下文中是可靠的.测试程序在Task委托的开头设置一个ActivityId,休眠以模拟工作,然后检查最后的ActivityId以确保它是相同的值(即它没有被另一个线程修改).该程序成功运行.

在研究线程,任务和并行操作的其他"上下文"选项(最终为日志提供更好的上下文)时,我遇到了Trace.CorrelationManager.LogicalOperationStack的一个奇怪问题(无论如何我都很奇怪).我在下面的问题中复制了我的"答案".

我认为它充分描述了我遇到的问题(Trace.CorrelationManager.LogicalOperationStack显然已经损坏 - 或者什么 - 当在Parallel.For的上下文中使用时,但只有当Parallel.For本身包含在逻辑操作中时) .

这是我的问题:

  1. Trace.CorrelationManager.LogicalOperationStack应该可以与Parallel.For一起使用吗?如果是这样,如果一个逻辑操作已经与Parallel.For启动有效,它是否会有所不同?

  2. 是否有一种"正确"的方式使用LogicalOperationStack与Parallel.For?我能不同地对这个示例程序进行编码以使其"有效"吗?通过"工作",我的意思是LogicalOperationStack总是具有预期的条目数,并且条目本身是预期的条目.

我已经使用Threads和ThreadPool线程做了一些额外的测试,但是我必须返回并重试这些测试,看看我是否遇到了类似的问题.

我会说,看起来任务/并行线程和ThreadPool线程确实从父线程"继承"了Trace.CorrelationManager.ActivityId和Trace.CorrelationManager.LogicalOperationStack值.这是预期的,因为CorrelationManager使用CallContext的LogicalSetData方法(而不是SetData)存储这些值.

请再次参考此问题,以获取我在下面发布的"答案"的原始背景:

任务并行库中的任务如何影响ActivityID?

另请参阅Microsoft的Parallel Extensions论坛上的类似问题(目前尚未得到解答):

http://social.msdn.microsoft.com/Forums/en-US/parallelextensions/thread/7c5c3051-133b-4814-9db0-fc0039b4f9d9

[开始粘贴]

请原谅我发布这个作为答案,因为它不是你的问题的真正答案,但是,它与你的问题有关,因为它处理CorrelationManager行为和线程/任务/等.我一直在寻找使用CorrelationManager LogicalOperationStack(和StartLogicalOperation/StopLogicalOperation方法)在多线程场景中提供额外的上下文.

我拿了你的例子并稍微修改它以增加使用Parallel.For并行执行工作的能力.另外,我用StartLogicalOperation/StopLogicalOperation括号(内部)DoLongRunningWork.从概念上讲,DoLongRunningWork每次执行时都会执行以下操作:

DoLongRunningWork
  StartLogicalOperation
  Thread.Sleep(3000)
  StopLogicalOperation
Run Code Online (Sandbox Code Playgroud)

我发现如果我将这些逻辑操作添加到您的代码中(或多或少),所有逻辑操作都保持同步(始终是堆栈上预期的操作数,并且堆栈上的操作值始终为预期).

在我自己的一些测试中,我发现并非总是这样.逻辑操作堆栈正在"损坏".我能想到的最好的解释是,当"子"线程退出时,将CallContext信息"合并"回"父"线程上下文导致"旧"子线程上下文信息(逻辑操作)为"继承"由另一个兄弟姐妹线程.

问题也可能与Parallel.For显然使用主线程(至少在示例代码中,如编写)作为"工作线程"之一(或者在并行域中应该调用它们)之间的事实有关.每当执行DoLongRunningWork时,就会启动一个新的逻辑操作(在开始时)并停止(在结束时)(也就是说,将其推送到LogicalOperationStack并从中弹出).如果主线程已经有效的逻辑操作,并且DoLongRunningWork在主线程上执行,则启动新的逻辑操作,因此主线程的LogicalOperationStack现在具有两个操作.DoLongRunningWork的任何后续执行(只要DoLongRunningWork的这个"迭代"在主线程上执行)将(显然)继承主线程的LogicalOperationStack(现在它有两个操作,而不仅仅是一个预期的操作).

我花了很长时间才弄清楚为什么LogicalOperationStack的行为在我的示例中与我的示例的修改版本不同.最后我看到在我的代码中我将整个程序放在逻辑操作中,而在我的测试程序的修改版本中,我没有.这意味着在我的测试程序中,每次执行"工作"(类似于DoLongRunningWork)时,已经存在逻辑操作.在我的测试程序的修改版本中,我没有在逻辑操作中将整个程序括起来.

所以,当我修改你的测试程序以在逻辑操作中包含整个程序时如果我使用Parallel.For,我遇到了完全相同的问题.

使用上面的概念模型,这将成功运行:

Parallel.For
  DoLongRunningWork
    StartLogicalOperation
    Sleep(3000)
    StopLogicalOperation
Run Code Online (Sandbox Code Playgroud)

虽然这最终会因为LogicalOperationStack显然不同步而断言:

StartLogicalOperation
Parallel.For
  DoLongRunningWork
    StartLogicalOperation
    Sleep(3000)
    StopLogicalOperation
StopLogicalOperation
Run Code Online (Sandbox Code Playgroud)

这是我的示例程序.它类似于你的,因为它有一个DoLongRunningWork方法来操作ActivityId以及LogicalOperationStack.我也有两种踢DoLongRunningWork的方式.一种风味使用任务一使用Parallel.For.还可以执行每种风格,使得整个并行操作被包含在逻辑操作中或不包含在逻辑操作中.因此,总共有4种方法来执行并行操作.要尝试每个,只需取消注释所需的"使用..."方法,重新编译并运行. UseTasks,UseTasks(true)并且UseParallelFor应该全部运行完成. UseParallelFor(true)因为LogicalOperationStack没有预期的条目数,所以会在某些时候断言.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; …
Run Code Online (Sandbox Code Playgroud)

.net c# system.diagnostics parallel-extensions task-parallel-library

10
推荐指数
1
解决办法
4110
查看次数

在JSDoc中记录开放式参数函数的正确方法

假设您有以下内容:

var someFunc = function() {
    // do something here with arguments
}
Run Code Online (Sandbox Code Playgroud)

您如何正确地记录此函数可以在JSDoc中获取任意数量的参数?这是我最好的猜测,但我不确定它是否正确.

/**
 * @param {Mixed} [...] Unlimited amount of optional parameters
 */
var someFunc = function() {
    // do something here with arguments
}
Run Code Online (Sandbox Code Playgroud)

相关:php - 如何doc一个可变数量的参数

javascript jsdoc

74
推荐指数
4
解决办法
2万
查看次数

如何在PHP中获取浮点数的二进制表示?

有没有办法在PHP中获取浮点数的二进制表示?像Java的Double.doubleToRawLongBits()之类的东西.

给定一个正浮点数,我想获得最大可表示的浮点数,该数字小于该数.在Java中,我可以这样做:

double x = Double.longBitsToDouble(Double.doubleToRawLongBits(d) - 1);
Run Code Online (Sandbox Code Playgroud)

但我在PHP中没有看到类似的东西.

php floating-point numerical-methods

8
推荐指数
3
解决办法
4414
查看次数

从类到接口转换问题

Assembly assembly = Assembly.LoadFrom("Logic\\bin\\Debug\\Logic.dll");
            Type queryManagerType = assembly.GetType("Logic." + HttpContext.Current.Session["lang_name"] + "SearchQueryManager");
            var queryManager = (ISearchQueryManager)Activator.CreateInstance(queryManagerType);


public interface ISearchQueryManager
    {
        IList<Advertisements> ApplyQueries(string searchQuery, int page, int pageSize, string orderBy, out int count);
    }

public class SlovenianSearchQueryManager : ISearchQueryManager
    {
...
}
Run Code Online (Sandbox Code Playgroud)

但我明白了

无法将"Logic.SlovenianSearchQueryManager"类型的对象强制转换为"Logic.ISearchQueryManager".

编辑:整个堆栈跟踪

用户代码未处理System.InvalidCastException
消息="无法将类型为'Logic.SlovenianSearchQueryManager'的对象强制转换为'Logic.ISearchQueryManager'."
Source ="ViaMura.Web.Module"
StackTrace:位于D:\ PROJEKTI\crawler\WebCrawlerSuite\ViaMura.Web中的ViaMura.Web.Module.WebController.GetAdvertismentsByRawQuery(String rawQuery,Int32 page,Int32 pageSize,String orderBy,Int32&count) .Module\WebController.cs:D:\ PROJEKTI\crawler\WebCrawlerSuite\ViaMura.Web.Module\Views\SearchResultsPresenter中的ViaMura.Web.Module.Views.SearchResultsPresenter.OnResultsLoad(Int32页面,Int32 pageSize,String orderBy)第32行.cs:第43行在ViaMura.Web.SearchResults.SearchAdvertisments()中的D:\ PROJEKTI\crawler\WebCrawlerSuite\ViaMura.Web\SearchResults.aspx.cs:第155行,位于ViaMura.Web.SearchResults.Page_Load(Object sender,EventArgs) e)在系统中的System:Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp,Object o,Object t,EventArgs e)的D:\ PROJEKTI\crawler\WebCrawlerSuite\ViaMura.Web\SearchResults.aspx.cs:第149行.位于ViaMura.Web.App_C的System.Web.UI.Control.OnLoad(EventArgs e)上的Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,EventArgs e)系统中System.Web.UI.Control.LoadRecursive()的D:\ PROJEKTI\crawler\WebCrawlerSuite\ViaMura.Web\App_Code\PageControllers\BasePage.cs:第89行中的ode.PageControllers.BasePage.OnLoad(EventArgs e). Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)
InnerException:

EDIT2:

string a1 = typeof …
Run Code Online (Sandbox Code Playgroud)

c#

6
推荐指数
1
解决办法
3075
查看次数

Youtube - iPhone - 显示视频的UIWebView

我的应用程序中有一个脚本,在UIView的一部分中加载Youtube链接,链接由我的服务器(mySQL /使用php)提供,并且从中加载...下面这个脚本工作正常....但是......

这就是我现在所拥有的,我正在寻找以编程方式删除部分(它给出维度并可能用UIWebView替换它),因此我可以即兴使用IB,这将有助于我的应用程序启动时,快速动画发生,然后我想在viewDidLoad完成后加载和显示此youtube链接.

.h文件:

- (void)embedYouTube:(NSString *)urlString frame:(CGRect)frame;
Run Code Online (Sandbox Code Playgroud)

.m文件

//view did load function...

[self embedYouTube:youtubestring frame:CGRectMake(69,72,184,138)];

//after the view did load is closed I have..

- (void)embedYouTube:(NSString *)urlString frame:(CGRect)frame {
NSString *embedHTML = @"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: white;\
}\
</style>\
</head><body style=\"margin:0\">\
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
NSString *html = [NSString stringWithFormat:embedHTML, urlString, frame.size.width, frame.size.height];
UIWebView *videoView = [[UIWebView alloc] initWithFrame:frame];
[videoView loadHTMLString:html baseURL:nil];
[self.view addSubview:videoView];
[videoView release];
}
Run Code Online (Sandbox Code Playgroud)

任何帮助将非常感谢!! 谢谢

youtube iphone sdk uiwebview

2
推荐指数
1
解决办法
5907
查看次数

如何在python-ldap中基于其dn在LDAP中搜索对象?

我试图使用例如search_s函数来搜索基于其完整的可分辨名称的对象,但我发现这不方便.例如,

search_s('DC=example, DC=com', ldap.SCOPE_SUBTREE,
    '(CN=Somebody, OU=Department, DC=example, DC=com)')
Run Code Online (Sandbox Code Playgroud)

如何根据其完整的LDAP专有名称检索一个对象?

ldap python-ldap

4
推荐指数
1
解决办法
7761
查看次数

ContactsContract查找联系ID的电话号码

我试图通过他们的contactId查找联系人的电话号码,bll结果返回 - 电话号码:1

我尝试过围绕SO使用其他示例,但我一直在光标上得到0计数

Uri uri = ContentUris.withAppendedId(Data.CONTENT_URI, contactId);

Log.i(TAG, "Locate Contact by Id: " + contactId + " at Uri: " + uri.toString());

Cursor cursor = this.getContentResolver().query(uri, null, null, null, null);

try {
    if (cursor.moveToFirst()) {
        Log.i(TAG, "Phone Number: " + cursor.getString(cursor.getColumnIndex(Phone.NUMBER)));
    }
} finally {
    cursor.close();
}
Run Code Online (Sandbox Code Playgroud)

android uri contactscontract

2
推荐指数
1
解决办法
8710
查看次数