小编Use*_*ser的帖子

如何从asmx Web服务返回纯XML?

我想要一个带有GetPeople()方法的asmx webservice,它返回以下XML(不是SOAP响应):

<People>

    <Person>
        <FirstName>Sara</FirstName>
        <LastName>Smith</LastName>
    </Person>

    <Person>
        <FirstName>Bill</FirstName>
        <LastName>Wilson</LastName>
    </Person>

</People>
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

xml asp.net web-services xml-serialization asmx

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

Django:设置数据库代码表(又名参考表,域表)?

应用程序通常需要一些数据库代码表(也就是引用表或域表或查找表).假设我有一个名为Status的模型类,其名称为name,可以包含以下值:

Canceled
Pending
InProgress
Complete
Run Code Online (Sandbox Code Playgroud)

我将在何处以及在什么时候在Django中设置这些值?它就像在数据库中设置这些值的一次性操作.不经常,可以添加这些值.

我想更普遍的是,你如何用数据初始化模型?例如,假设我有一个用于保持汽车品牌的模型,我想用一组已知值初始化此列表.我该怎么做?

django configuration lookup-tables django-models project-setup

5
推荐指数
1
解决办法
1300
查看次数

C#:返回在运行时确定具体类型的对象的方法?

我正在考虑设计一个方法,该方法将返回一个实现接口的对象,但在运行时才会知道其具体类型.比如假设:

ICar
Ford implements ICar
Bmw implements ICar
Toyota implements ICar

public ICar GetCarByPerson(int personId)
Run Code Online (Sandbox Code Playgroud)

我们不知道在运行之前我们会得到什么车.

a)我想知道这个人有什么类型的汽车.

b)根据我们得到的具体车型,我们会调用不同的方法(因为有些方法只对类有意义).所以客户端代码会做类似的事情.

ICar car = GetCarByPerson(personId);

if ( car is Bmw )
{
  ((Bmw)car).BmwSpecificMethod();
}
else if (car is Toyota)
{
  ((Toyota)car).ToyotaSpecificMethod();
}
Run Code Online (Sandbox Code Playgroud)

这是一个很好的设计吗?有代码味吗?有一个更好的方法吗?

我很好用返回接口的方法,如果客户端代码显然调用接口方法,那就没问题了.但我担心的是客户端代码转换为具体类型是否是好的设计.

c# interface concrete

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

C#:具有服务层,接口和模拟的文件夹结构?

我最近开始创建服务层并进行如下声明:

MyService myService = new MyService();
myService.DoSomething();
Run Code Online (Sandbox Code Playgroud)

这是受一些ASP.NET MVC视频的启发,我喜欢这种模式.

然后我开始创建接口和模拟,如:

IMyService myService = new MockMyService();
myService.DoSomething();
Run Code Online (Sandbox Code Playgroud)

所以我可以隔离部分代码进行测试.但现在我的服务层文件夹加载了类,接口和模拟类:

IServiceTypeA.cs
ServiceTypeA.cs
MockServiceTypeA.cs
IServiceTypeB.cs
ServiceTypeB.cs
MockServiceTypeB.cs
...
IServiceTypeZ.cs
ServiceTypeZ.cs
MockServiceTypeZ.cs
Run Code Online (Sandbox Code Playgroud)

你如何以合理的方式组织这些?

c# directory-structure code-organization project-structure

5
推荐指数
1
解决办法
2746
查看次数

Sqlite:如何从C++绑定和插入日期?

使用C++(Visual Studio)和sqlite.如何将日期绑定到参数?

sqlite3_stmt *statement;

const char *sql = 
    "INSERT INTO employees "
        "(full_name,"
        "date_started)" 
    " VALUES "
        "(@full_name,"
        "@date_started)";

sqlite3_prepare_v2(database_, sql, -1, &statement, NULL);

int parameterIndex = sqlite3_bind_parameter_index(statement, "@full_name");
sqlite3_bind_text(statement, parameterIndex, "John Smith", -1, SQLITE_TRANSIENT);

parameterIndex = sqlite3_bind_parameter_index(statement, "@date_started");

// <??? what goes here ???>
// I want to include the local current time, so I want to know:
// 1. what's the best way to get local time in C++
// 2. and what goes here for the date …
Run Code Online (Sandbox Code Playgroud)

c++ sql sqlite datetime insert

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

MFC:动态更改控件的字体大小吗?

我有一个CListCtrl类,我希望能够轻松更改其字体大小。我将CListCtrl子类化为MyListControl。我可以在PreSubclassWindow事件处理程序中使用以下代码成功设置字体:

void MyListControl::PreSubclassWindow()
{
    CListCtrl::PreSubclassWindow();

    // from http://support.microsoft.com/kb/85518
    LOGFONT lf;                        // Used to create the CFont.

    memset(&lf, 0, sizeof(LOGFONT));   // Clear out structure.
    lf.lfHeight = 20;                  // Request a 20-pixel-high font
    strcpy(lf.lfFaceName, "Arial");    //    with face name "Arial".
    font_.CreateFontIndirect(&lf);    // Create the font.
    // Use the font to paint a control.
    SetFont(&font_);
}
Run Code Online (Sandbox Code Playgroud)

这可行。但是,我想做的是创建一个名为SetFontSize(int size)的方法,该方法将简单地更改现有的字体大小(不改变外观和其他特征)。因此,我认为此方法将需要获取现有字体,然后更改字体大小,但是我这样做的尝试失败了(这杀死了我的程序):

void MyListControl::SetFontSize(int pixelHeight)
{
    LOGFONT lf;                        // Used to create the CFont.

    CFont *currentFont = GetFont();
    currentFont->GetLogFont(&lf);
    LOGFONT lfNew = lf;
    lfNew.lfHeight = pixelHeight;                  // …
Run Code Online (Sandbox Code Playgroud)

fonts mfc

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

用指针理解const_iterator?

我试图理解const_iterator的含义.我有以下示例代码:

void CustomerService::RefreshCustomers()
{
    for(std::vector<Customer*>::const_iterator it = customers_.begin();
        it != customers_.end() ; it ++)
    {
        (*it)->Refresh();
    }
}
Run Code Online (Sandbox Code Playgroud)

Refresh()Customer类中的方法,它没有定义为const.起初以为我认为const_iterator应该禁止修改容器的元素.但是,此代码无需投诉即可编译.这是因为有一个额外的间接水平吗?const_iterator到底是什么意思?

UPDATE

在这种情况下,使用const_iterator是最佳做法吗?

c++ const-iterator

5
推荐指数
1
解决办法
8974
查看次数

PyBrain:使用numpy.loadtxt加载数据?

我有一些工作代码可以正确地将csv文件中的数据加载到PyBrain数据集中:

def old_get_dataset():

    reader = csv.reader(open('test.csv', 'rb'))

    header = reader.next()
    fields = dict(zip(header, range(len(header))))
    print header

    # assume last field in csv is single target variable
    # and all other fields are input variables
    dataset = SupervisedDataSet(len(fields) - 1, 1)

    for row in reader:
        #print row[:-1]
        #print row[-1]
        dataset.addSample(row[:-1], row[-1])

    return dataset
Run Code Online (Sandbox Code Playgroud)

现在我正在尝试重写此代码以使用numpy的loadtxt函数.我相信addSample可以采用numpy数组,而不必一次添加一行数据.

假设我加载的numpy数组是mxn维,那么如何将第一个mx(n-1)数据集作为第一个参数传递,最后一列数据作为第二个参数?这就是我正在尝试的:

def get_dataset():

    array = numpy.loadtxt('test.csv', delimiter=',', skiprows=1)

    # assume last field in csv is single target variable
    # and all other fields are input variables
    number_of_columns …
Run Code Online (Sandbox Code Playgroud)

python numpy pybrain

5
推荐指数
1
解决办法
5586
查看次数

使用googlemock EXPECT_CALL和shared_ptr?

我有一个测试,使用原始指针工作正常,但我无法使用它std::shared_ptr.这个班是这样的:

class MyClass
{
    MyClass(SomeService *service);
    void DoIt();
}
Run Code Online (Sandbox Code Playgroud)

我的测试代码如下:

    class MyClassTests : public ::testing::Test
    {
    public:
        MyClassTests():
            myClass_(new MyClass(&service_))
        {}

    protected:
        SomeServiceFake service_;
        MyClassSharedPointer myClass_;
    };

TEST_F(MyClassTests, DoIt_DoesNotMeetCriteria_DoesNotPerformAction) {

    // Arrange
    EXPECT_CALL(service_, MeetsCriteria(_))
        .WillRepeatedly(Return(false));

    EXPECT_CALL(service_, PerformAction(_))
        .Times(0);

    // Act
    myClass_->DoIt();
}
Run Code Online (Sandbox Code Playgroud)

在这个测试中,service_是在测试中在堆栈上创建的mock/fake,我将地址传递给构造函数MyClass.更改MyClassserviceshared_ptr,我的新类的样子:

class MyClass
{
    MyClass(std::shared_ptr<SomeService> service);
    DoIt();
}
Run Code Online (Sandbox Code Playgroud)

我在测试中尝试的是:

    class MyClassTests : public ::testing::Test
    {
    public:
        MyClassTests():
            myClass_(new MyClass(std::shared_ptr<SomeService>(&service_)))
        {

        }
            ...
Run Code Online (Sandbox Code Playgroud)

但是,当我这样做时,测试失败了:

Debug Assertion Failed! …
Run Code Online (Sandbox Code Playgroud)

c++ shared-ptr googlemock

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

在SortedDictionary中找到具有最大值的键?

SortedDictionary如何找到与最大值关联的密钥?我是否必须遍历每个KeyValuePair?

c# max sorteddictionary

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