小编Eso*_*ame的帖子

导入2具有相同名称的类

在PHP中,我希望导入2个具有相同名称的第三方类.例如:

// in file libs/3rdparty/AppleTree/Apple.php
class Apple extends SomeOtherModel {
  // class details
}

// in file libs/3rdparty/AppleSeed/Apple.php
class Apple extends SomeModel {
  // class details
}
Run Code Online (Sandbox Code Playgroud)

鉴于他们的构造函数是相同的,例如:

$appletree = new Apple();
$appleseed = new Apple();
Run Code Online (Sandbox Code Playgroud)

PHP如何区分这两个类?在Java中,我们可以在构造函数之前附加类路径.

注意:我使用的是PHP 5,我无法修改类,因为它们被其他类文件使用.

php

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

在Read Uncommitted查询之后,我是否必须将其设置回Committed?

想象一下,使用类似于此处的代码执行查询:

using (SqlConnection TheConnection = GetSqlConnectionNoCatch(SQLConnectionStr))
using (SqlDataAdapter TheDataAdapter = new SqlDataAdapter(SQLStatement, TheConnection) { MissingSchemaAction = SchemaAction })
{
    DataSet TheDataSet = new DataSet();
    TheDataAdapter.SelectCommand.CommandTimeout = SQLTimeout;
    TheDataAdapter.Fill(TheDataSet, TableName);

    return TheDataSet;
}
Run Code Online (Sandbox Code Playgroud)

并且想象一下,必须读取数据库表,这些数据表绝对会受到攻击,不间断,写入会导致大量死锁和失败,因此您必须使用Read Uncommitted Isolation级别执行读取操作.

如果我的正常查询是:

SELECT Field1, Field2 FROM Table WHERE some_type_of_clause
Run Code Online (Sandbox Code Playgroud)

我经常看到你会把它改成:

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
SELECT Field1, Field2 FROM Table WHERE some_type_of_clause
Run Code Online (Sandbox Code Playgroud)

好的,所以这就是让我问这个问题的原因,这个特殊的链接:http://blog.sqlauthority.com/2011/04/17/sql-server-applying-nolock-hint-at-query-level-nolock-换整个事务/

他的例子如下:

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
SELECT *
FROM AdventureWorks.Sales.SalesOrderDetail sod
INNER JOIN AdventureWorks.Sales.SalesOrderHeader soh ON
sod.SalesOrderID = …
Run Code Online (Sandbox Code Playgroud)

sql-server transaction-isolation sql-server-2008

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

将网站从http重定向到https

我有一个存储在azure上的网站,我获得了SSL证书.我正在尝试将www.mywebsite.com重定向到https://www.mywebsite.com,但没有成功.

我使用以下代码来更改部署项目的IIS的配置:

<system.webServer>
<rewrite>
  <rules>
    <rule name="Redirect to HTTPS">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
        <add input="{URL}" pattern="/$" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
      </conditions>
      <action type="Redirect" url="https://{SERVER_NAME}/{R:1}" redirectType="SeeOther" />
    </rule>
  </rules>
</rewrite>
Run Code Online (Sandbox Code Playgroud)

但是当我输入我的URL时,它不会重定向到https.

顺便说一下,重写似乎没有被Intellisense重新识别.

c# iis azure

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

如何从故障偏移中确定调用的kernel32.dll函数

我有一个作为Windows服务运行的应用程序.今天,我被告知该服务已经死亡.我找到了一个事件查看器条目,其基本信息是:故障模块kernel32.dll,版本6.0.6002.18740,时间戳0x50b58c3d,异常代码0xc0000005,故障偏移0x0003fc2e

我确信我的代码中存在错误.我可以从偏移量确定kernel32.dll函数(异常来自哪里)吗?我打算在我的代码中回溯到调用.

c windows

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

在表中添加和删除时使用序列

我正在创建一个表格,我将添加文件名和许多其他字段.我使用fileid列按顺序表示文件; 即要上传的第一个文件应该有fieldid 1,然后下一个文件将有fileid 2,依此类推.我用了一个序列和触发器:

create sequence create_file_id start with 1 increment by 1 nocache;
Run Code Online (Sandbox Code Playgroud)

触发器是:

before insert on add_files_details
for each row
begin
select create_file_id.nextval into :new.file_id from dual;
end;
Run Code Online (Sandbox Code Playgroud)

但是,如果从表中删除任何记录/记录,则序列会混乱.所以,我正在考虑使用另一个带触发器的序列来减少前一个序列的值,删除的行数.但是我坚持实现这个序列的触发器.

序列:

create sequence del_file_id increment by -1 nocache;
Run Code Online (Sandbox Code Playgroud)

有没有实现这个目标?

oracle triggers plsql sequence

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

为什么这段代码没有编译?

我正在编写一个生成DataTable的方法,将数据源作为通用的IEnumerable.如果没有值,我试图在字段上设置默认值,代码如下:

private void createTable<T>(IEnumerable<T> MyCollection, DataTable tabela) 
        {
            Type tipo = typeof(T);

            foreach (var item in tipo.GetFields() )
            {
                tabela.Columns.Add(new DataColumn(item.Name, item.FieldType));
            }

            foreach (Pessoa recordOnEnumerable in ListaPessoa.listaPessoas)
            {
                DataRow linha = tabela.NewRow();

                foreach (FieldInfo itemField in tipo.GetFields())
                {
                    Type typeAux = itemField.GetType();

                    linha[itemField.Name] =
                        itemField.GetValue(recordOnEnumerable) ?? default(typeAux); 

                }
            }
        }
Run Code Online (Sandbox Code Playgroud)

它抛出了这个错误:

找不到类型或命名空间名称'typeAux'(您是否缺少using指令或程序集引用?)

为什么?"Default(Type)"函数不应该返回该类型的默认值吗?

.net c# generics types

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

.restart smali 关键字有什么作用?

smali 中的这一行有什么作用?我一直在 google 上搜索 .restart 的东西,但没有找到任何关于它的信息。

.restart local v3       #i:I
Run Code Online (Sandbox Code Playgroud)

java android smali

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

CSV类型提供程序无法在F#interactive中找到列

所以,假设我有一个CSV文件,其中包含包含Population和Profit列的标题,我想在F#interactive中使用它.我有以下代码:

#r "../packages/FSharp.Data.1.1.10/lib/net40/FSharp.Data.dll"

open FSharp.Data

// load csv header
let cities = new CsvProvider<"cities.csv">()

// how to reach data
let firstRow = cities.Data |> Seq.head
let firstPopulation = firstRow.Population
let firstProfit = firstRow.Profit
Run Code Online (Sandbox Code Playgroud)

我收到F#interactive的错误:

错误FS0039:未定义字段,构造函数或成员"Population"

这对我来说似乎很困惑,因为VS中的intellisense通过CSV类型提供程序从我的数据中获取此列没有任何问题.

此外,我尝试使用相同类型的提供程序创建一个程序,它一切正常.像这样:

open FSharp.Data

[<EntryPoint>]
let main argv = 
    use file = System.IO.File.CreateText("result.txt")
    let csv = new CsvProvider<"cities.csv">()
    for record in csv.Data do
        fprintfn file "%A" record.Population
    0
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?谢谢你的回答.

f# f#-interactive type-providers f#-data

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

避免一次又一次地创建PictureBoxes

我有以下问题.我的目的是在Windows窗体中从右向左移动多个图像.下面的代码非常好用.令我困扰的是,每次创建PictureBox对象时,此过程都会占用大量内存.每个图像从右到左不间断地跟随前一图像.图像显示从一侧移动到另一侧的天空.它应该看起来像一架飞机在空中飞舞.

如何避免使用太多内存?我可以用PaintEvent和GDI做些什么吗?我对图形编程不太熟悉.

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;

public class Background : Form
    {

        private PictureBox sky, skyMove;
        private Timer moveSky;
        private int positionX = 0, positionY = 0, width, height;
        private List<PictureBox> consecutivePictures;


        public Background(int width, int height)
        {

            this.width = width;
            this.height = height;

            // Creating Windows Form
            this.Text = "THE FLIGHTER";
            this.Size = new Size(width, height);
            this.StartPosition = FormStartPosition.CenterScreen;
            this.FormBorderStyle = FormBorderStyle.FixedSingle;
            this.MaximizeBox = false;


            // The movement of the sky becomes possible by the …
Run Code Online (Sandbox Code Playgroud)

c# memory picturebox winforms

5
推荐指数
0
解决办法
652
查看次数

TDD:.NET遵循TDD原则,模拟/不模拟?

我正在尝试跟踪TDD,我遇到了一个小问题.我编写了一个Test来将新用户插入数据库.在MyService类上调用Insert new user,因此我继续创建mytest.它失败了,我开始在我的MyService类上实现我的CreateUser方法.

我遇到的问题是MyService将调用存储库(另一个类)来进行数据库插入.

所以我想我会使用一个模拟框架来模拟这个Repository类,但这是正确的方法吗?

这意味着我必须更改我的测试以实际为我的用户存储库创建一个模拟.但这是推荐的吗?我最初写了我的测试并使它失败了,现在我意识到我需要一个存储库并需要模拟它,所以我不得不改变我的测试以满足模拟对象.闻起来有点?

我想在这里得到一些反馈.

如果这是要走的路,那么什么时候才能创建实际的用户存储库?这需要自己的测试吗?

或者我应该忘记嘲笑任何东西?但是,这将被归类为集成测试而不是单元测试,因为我将MyService和User Repository一起作为一个单元进行测试.

我有点失落; 我想以正确的方式开始.

.net c# tdd mocking

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