小编Myk*_*ola的帖子

使用存储过程从Dapper.net查询返回值

我试图调用存储过程using Dapper.Net并获取返回值.

p.Add("@INCIDENT_ID", dbType: DbType.Int32, direction: ParameterDirection.ReturnValue);

var retResults = con.Execute("usp_GetIncidentID", p, commandType:CommandType.StoredProcedure);

int IncidentID = p.Get<int>("INCIDENT_ID"); 
Run Code Online (Sandbox Code Playgroud)

我已经尝试了几个与参数方向不同的东西并使用了"@INCIDENT_ID".如果您单步执行结果,您可以看到值中存在正确的返回值retResults,但我无法按照下面的文档中描述的方式访问这些值.

存储过程Dapper支持完全存储的过程:

var user = cnn.Query<User>("spGetUser", new {Id = 1}, 
    commandType: CommandType.StoredProcedure).First();}}}
If you want something more fancy, you can do:

var p = new DynamicParameters();
p.Add("@a", 11);
p.Add("@b", dbType: DbType.Int32, direction: ParameterDirection.Output);
p.Add("@c", dbType: DbType.Int32, direction: ParameterDirection.ReturnValue);

cnn.Execute("spMagicProc", p, commandType: commandType.StoredProcedure); 

int b = p.Get<int>("@b");
int c = p.Get<int>("@c");   
Run Code Online (Sandbox Code Playgroud)

c# sql-server dapper

12
推荐指数
2
解决办法
3万
查看次数

Node.js/Express/Mocha/Supertest Rest API - 空请求正文

我到处寻找可以找到解决方案.我发现的唯一一件事是没有回复的帖子.如果我忽略了某些事情,我会道歉.

问题是,当我尝试获取API中的POST值时/createQuestion,正文是空的/未定义的.我Cannot read proprety 'question' of undefined从API 那里得到这样的错误.

Express API:

app.post("/createQuestion", function(req, res) {
    var questionType = req.body.question.type;
    var questionText = req.body.question.text;
    var questionDuringClass = req.body.question.duringClass;

    // Do a bunch of stuff

    res.send(response);
});
Run Code Online (Sandbox Code Playgroud)

考试:

    var should = require('should'); 
    var assert = require('assert');
    var request = require('supertest');  
    var winston = require('winston');

    request = request('http://localhost:8080');

        describe('Questions', function() { // Test suite
            before(function(done) {
                done();
            });

        it('Should create a freeResponse question', function(done) { // Test case …
Run Code Online (Sandbox Code Playgroud)

rest mocha.js node.js express supertest

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

STM32 USB OTG HOST库挂起尝试使用FatF创建文件

我正在尝试在USB闪存上创建一个带有FatFs的文件,但是我的f_open调用尝试读取第一次文件系统挂载的启动扇区时挂起了这个函数.

DRESULT disk_read (
                   BYTE drv,            /* Physical drive number (0) */
                   BYTE *buff,          /* Pointer to the data buffer to store read data */
                   DWORD sector,        /* Start sector number (LBA) */
                   BYTE count           /* Sector count (1..255) */
                     )
{
  BYTE status = USBH_MSC_OK;

  if (drv || !count) return RES_PARERR;
  if (Stat & STA_NOINIT) return RES_NOTRDY;


  if(HCD_IsDeviceConnected(&USB_OTG_Core))
  {  

    do
    {
      status = USBH_MSC_Read10(&USB_OTG_Core, buff,sector,512 * count);
      USBH_MSC_HandleBOTXfer(&USB_OTG_Core ,&USB_Host);

      if(!HCD_IsDeviceConnected(&USB_OTG_Core))
      { 
        return RES_ERROR;
      }      
    }
    while(status == …
Run Code Online (Sandbox Code Playgroud)

c embedded stm32 usb-otg fatfs

11
推荐指数
1
解决办法
2407
查看次数

如何模拟ASP.NET 5中的UserManager

我正在编写一个用于在ASP.NET 5应用程序中管理用户的UI .我需要在UI中显示UserManager返回的任何错误.我IdentityResult在视图模型中传递了错误,但在测试我的代码时我是一个漂亮的触摸器.

什么是嘲笑的最佳方法UserManagerASP.NET 5

我应该继承UserManager并覆盖我正在使用的所有方法,然后将我的版本注入我的测试项目UserManager的实例中Controller吗?

c# unit-testing xunit.net asp.net-core-mvc asp.net-core

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

如何创建一个从基类派生的ATL COM类?

"ATL简单对象"向导未提供指定从现有coclass及其接口派生新类的方法.在Visual Studio 2008中,如何创建一个从现有的ATL COM类派生的新类(即Base实现IBase,我想创建一个Derived派生自Base该实现的新类IDerived,其中IDerived派生自IBase.)

更新:听起来很简单,但向导生成的ATL类最多有六个基类,一个COM映射和一个连接点映射.应该在派生类中重复哪些基类和映射?如果映射在派生类中重复,它们是否应包含基类映射的内容或仅包含其他项?基类的顺序是否重要?怎么样FinalConstruct()FinalRelease()?应该DECLARE_PROTECT_FINAL_CONSTRUCTDECLARE_REGISTRY_RESOURCEID在派生类中被重复?

这是一个示例基类,除了所有样板文件外都是空的.现在派生类应该是什么样的?

class ATL_NO_VTABLE CBase :
    public CComObjectRootEx<CComSingleThreadModel>,
    public CComCoClass<CBase, &CLSID_Base>,
    public ISupportErrorInfo,
    public IConnectionPointContainerImpl<CBase>,
    public CProxy_IBaseEvents<CBase>,
    public IDispatchImpl<IBase, &IID_IBase, &LIBID_ExampleLib, /*wMajor =*/ 1, /*wMinor =*/ 0>
{
public:
    CBase()
    {
    }

DECLARE_REGISTRY_RESOURCEID(IDR_Base)


BEGIN_COM_MAP(CBase)
    COM_INTERFACE_ENTRY(IBase)
    COM_INTERFACE_ENTRY(IDispatch)
    COM_INTERFACE_ENTRY(ISupportErrorInfo)
    COM_INTERFACE_ENTRY(IConnectionPointContainer)
END_COM_MAP()

BEGIN_CONNECTION_POINT_MAP(CBase)
    CONNECTION_POINT_ENTRY(__uuidof(_IBaseEvents))
END_CONNECTION_POINT_MAP()
// ISupportsErrorInfo
    STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);


    DECLARE_PROTECT_FINAL_CONSTRUCT()

    HRESULT FinalConstruct()
    {
        return S_OK;
    }

    void …
Run Code Online (Sandbox Code Playgroud)

c++ com atl classwizard visual-studio

9
推荐指数
1
解决办法
5684
查看次数

Qt QPlainTextEdit背景

我想改变一个背景颜色,QPlainTextEdit我该怎么做?

c++ qt

9
推荐指数
1
解决办法
7416
查看次数

为什么这会调用复制构造函数,而不是移动构造函数?

我有一节课,PlayerInputComponent:

.H:

class PlayerInputComponent
{
public:
    PlayerInputComponent(PlayerMoveComponent& parentMoveComponent_, std::unique_ptr<IRawInputConverter> inputConverter_);
    PlayerInputComponent(PlayerInputComponent&& moveFrom);
    void update();

private:
    std::unique_ptr<IRawInputConverter> inputConverter;
    PlayerMoveComponent& parentMoveComponent;
};
}
Run Code Online (Sandbox Code Playgroud)

的.cpp:

PlayerInputComponent::PlayerInputComponent(PlayerMoveComponent& parentMoveComponent_, std::unique_ptr<IRawInputConverter> inputConverter_) :
    parentMoveComponent(parentMoveComponent_),
    inputConverter(std::move(inputConverter_))
{
}

PlayerInputComponent::PlayerInputComponent(PlayerInputComponent&& moveFrom) :
    parentMoveComponent(moveFrom.parentMoveComponent),
    inputConverter(moveFrom.inputConverter.release())
{
}
Run Code Online (Sandbox Code Playgroud)

和一个PlayerMoveComponen包含PlayerInputComponent成员的类,并使用std::unique_ptr传递作为参数对其进行初始化.它的构造函数:

PlayerMoveComponent::PlayerMoveComponent(/* other parameters */ std::unique_ptr<IRawInputConverter> inputConverter) :
    //other initializations
    inputComponent(PlayerInputComponent(*this, std::move(inputConverter)))
{
}
Run Code Online (Sandbox Code Playgroud)

我为PlayerInputComponent类定义了自己的移动构造函数,因为我的理解是不会为包含引用成员的类构造默认移动构造函数.在这种情况下,虽然我知道引用将保留在PlayerInputComponent对象生命周期的持续时间内.

由于我初始化PlayerMoveComponentinputComponent从一个临时变量,笔者认为以下两件事情之一是应该发生的:

  1. PlayerInputComponent的移动构造函数用于初始化playerInputComponent成员变量.
  2. 编译器省略了此举.

但是,Visual Studio 2012吐出了这个:

error C2248: …
Run Code Online (Sandbox Code Playgroud)

c++ move-semantics c++11

9
推荐指数
1
解决办法
828
查看次数

std :: vector是否满足Boost.Interprocess分配器的容器要求?

boost::interprocess文档中,据说要将容器存储在共享内存中:

  1. STL容器可能不会假定分配器分配的内存可以与其他相同类型的分配器一起释放.只有当分配了一个对象的内存可以与另一个对象解除分配时,所有分配器对象必须比较相等,并且这只能operator==()在运行时进行测试.
  2. 容器的内部指针应该是类型allocator::pointer,容器可能不会假定allocator::pointer是原始指针.
  3. 必须通过allocator::constructallocator::destroy函数构造所有对象.

我正在使用gcc 4.7.1和-std = c ++ 11(和boost 1.53).使用下面定义的ShmVector类型是否安全?

typedef boost::interprocess::allocator<int,
    boost::interprocess::managed_shared_memory::segment_manager>  ShmemAllocator;
typedef std::vector<int, ShmemAllocator> ShmVector;
Run Code Online (Sandbox Code Playgroud)

我尝试了一个使用这种类型的虚拟进程,看起来它正在工作,但我仍然不确定gcc4.7.1中的向量是否满足所有要求.我对第一个要求特别不确定.

#include <iostream>
#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/interprocess/managed_shared_memory.hpp>
#include <vector>
#include <cstdlib> //std::system

typedef boost::interprocess::allocator<int,
        boost::interprocess::managed_shared_memory::segment_manager>  ShmemAllocator;
typedef std::vector<int, ShmemAllocator> ShmVector;

int main(int argc, char *argv[])
{
    if(argc == 1){ //Parent process

        struct shm_remove
        {
            shm_remove() { boost::interprocess::shared_memory_object::remove("MySharedMemory"); }
            ~shm_remove(){ boost::interprocess::shared_memory_object::remove("MySharedMemory"); }
        } remover;

        //Create a new …
Run Code Online (Sandbox Code Playgroud)

c++ vector boost-interprocess gcc4.7

8
推荐指数
1
解决办法
692
查看次数

TSaveDialog失败,客户端视觉样式被禁用

我想TSaveDialog在Delphi XE6中使用a :

if not SaveDialog1.Execute(0) then
   Exit;
Run Code Online (Sandbox Code Playgroud)

该调用立即返回false,而不显示任何对话框.我将其追溯到创建shell Save Dialog COM对象的行为:

function TCustomFileSaveDialog.CreateFileDialog: IFileDialog;
var
       LGuid: TGUID;
begin
  LGuid := CLSID_FileSaveDialog;

  CoCreateInstance(LGuid, nil, CLSCTX_INPROC_SERVER,
    StringToGUID(SID_IFileSaveDialog), Result);
end;
Run Code Online (Sandbox Code Playgroud)

呼叫CoCreateInstance失败了.我创建了最少的代码来重现问题:

procedure TForm1.Button1Click(Sender: TObject);
const
   CLSID_FileSaveDialog: TGUID = '{C0B4E2F3-BA21-4773-8DBA-335EC946EB8B}';
begin
   CreateComObject(CLSID_FileSaveDialog);
end;
Run Code Online (Sandbox Code Playgroud)

它抛出EOleSysError异常:

0x80040111:ClassFactory无法提供请求的类,ClassID:{C0B4E2F3-BA21-4773-8DBA-335EC946EB8B}

我的应用程序使用公共控件库(6.0.7601.18837)的第6版,但我意识到,如果用户已禁用我的应用程序的视觉样式时才会发生:

在此输入图像描述

我们仍在使用公共控件库的第6版,只IsAppThemed返回false.

注意:我知道很多人错误地认为:

  • Visual Styles API仅在我们加载了Comctrl32.dll版本6时才有效
  • 如果加载了Comctrl32.dll的版本6,则Visual Styles API将起作用
  • 如果我们不使用ComCtrl v6那么这意味着视觉样式被禁用
  • 如果我们使用旧的公共控件库,则禁用视觉样式

蛮力解决方案是将全局UseLatestCommonDialogs设置为false.

但这非常糟糕,因为它仅适用于在应用程序中禁用视觉样式的人:

  • 对话框继续在没有视觉样式的操作系统上工作(例如Windows Server 2008 R2)
  • 关闭视觉样式后对话框继续工作(例如关闭视觉样式的Windows 7)

这意味着我不能简单地使用IsAppThemed,因为如果 …

delphi themes visual-styles delphi-xe6

7
推荐指数
1
解决办法
305
查看次数

Vector vs SynchronizedList性能

在阅读关于集合实现的Oracle教程时,我发现了以下句子:

如果您需要同步,则a Vector将比ArrayList同步的稍快Collections.synchronizedList

来源:列表实现

但是当搜索它们之间的差异时,许多人不鼓励使用,Vector并且应该在SynchronizedList需要同步时替换.那么哪一方有权被追随?

java collections synchronization list

7
推荐指数
1
解决办法
832
查看次数