如果我的URL是http://www.server.com/myapp/stuff/to/see和磁盘上的目录结构htdocs/myapp/*,我该如何提取/myapp部件?如果没有应用程序文件夹且应用程序root只是'/',该怎么办?是否有预定义的变量来获取该值?
我想要的是一个能够修剪/myapp请求URI 的函数,所以我只剩下了/stuff/to/see.并且,如果我要将应用程序移动到服务器文档根目录,请确定它(因此它/stuff/to/see只是作为返回/stuff/to/see)
我的目录结构是这样的:
application
|-config
|-config.inc.php
library
|-autoload.class.php
public
|-css
|-img
index.php
Run Code Online (Sandbox Code Playgroud)
所以,从index.php,我想知道如何得到我上面提到的.
我有一个在unix机器上创建的二进制文件.这只是一堆接一个写的记录.记录的定义如下:
struct RECORD {
UINT32 foo;
UINT32 bar;
CHAR fooword[11];
CHAR barword[11];
UNIT16 baz;
}
Run Code Online (Sandbox Code Playgroud)
我试图找出如何在Windows机器上阅读和解释这些数据.我有这样的事情:
fstream f;
f.open("file.bin", ios::in | ios::binary);
RECORD r;
f.read((char*)&detail, sizeof(RECORD));
cout << "fooword = " << r.fooword << endl;
Run Code Online (Sandbox Code Playgroud)
我得到了一堆数据,但这不是我期望的数据.我怀疑我的问题与机器的endian区别有关,所以我来问这个问题.
我知道多个字节将存储在windows中的little-endian和unix环境中的big-endian中,我明白了.对于两个字节,Windows上的0x1234在unix系统上将为0x3412.
endianness会影响整个结构的字节顺序,还会影响结构的每个成员的字节顺序?我将采用什么方法将在unix系统上创建的结构转换为在Windows系统上具有相同数据的结构?任何比几个字节的字节顺序更深入的链接也会很棒!
我得到的值正确显示使用:
[DefaultValue ( typeof ( Color ), "255, 0, 0" )]
public Color LineColor
{
get { return lineColor; }
set { lineColor = value; Invalidate ( ); }
}
Run Code Online (Sandbox Code Playgroud)
但是在我重新加载项目后使用了控件,这个值被设置为White,我可以调用Reset来再次回到Red,但是我不明白这个问题.
除非我从默认值手动更改值,否则您应该如何设置默认值并确保保留默认值?
实际上我也这样做,它将Back和ForeColor设置为这些值,VS属性编辑器将它们显示为从默认值更改它们.
这是错的吗?
public CoolGroupBox ( )
{
InitializeComponent ( );
base.BackColor = Color.FromArgb ( 5, 5, 5 );
base.ForeColor = Color.FromArgb ( 0, 0, 0 );
}
Run Code Online (Sandbox Code Playgroud) 我正在使用Castle Windsor来管理控制器实例(以及其他内容).我的控制器工厂看起来像这样:
public class WindsorControllerFactory : DefaultControllerFactory
{
private WindsorContainer _container;
public WindsorControllerFactory()
{
_container = new WindsorContainer(new XmlInterpreter());
var controllerTypes = from t in Assembly.GetExecutingAssembly().GetTypes()
where typeof(Controller).IsAssignableFrom(t)
select t;
foreach (Type t in controllerTypes)
{
_container.AddComponentLifeStyle(t.FullName, t, LifestyleType.Transient);
}
}
protected override IController GetControllerInstance(Type controllerType)
{
return (IController)_container.Resolve(controllerType); // ArgumentNullException is thrown here
}
Run Code Online (Sandbox Code Playgroud)
当我启动我的ASP.Net MVC应用程序并尝试转到"/"(或其他路径)时,我得到一个ArgumentNullException.我在GetControllerInstance的输入上设置了一个断点,发现它使用我的HomeController调用了一次,然后第二次调用null(这是抛出异常的时候).为什么再次被召唤?
我应该将方法更改为这样的方法:
protected override IController GetControllerInstance(Type controllerType)
{
if (controllerType == null)
return null;
return (IController)_container.Resolve(controllerType);
}
Run Code Online (Sandbox Code Playgroud) 有什么不同?如果我有这两个表:
CREATE TABLE Account (Id int NOT NULL)
CREATE TABLE Customer (AccountId int NOT NULL)
Run Code Online (Sandbox Code Playgroud)
我想要一个连接两者的外键,我应该做以下哪些?为什么?
选项1:
ALTER TABLE [dbo].[Customer] WITH CHECK
ADD CONSTRAINT [FK_Accounts_Customers] FOREIGN KEY([AccountId])
REFERENCES [dbo].[Account] ([Id])
Run Code Online (Sandbox Code Playgroud)
选项2:
ALTER TABLE [dbo].[Account] WITH CHECK
ADD CONSTRAINT [FK_Accounts_Customers] FOREIGN KEY([Id])
REFERENCES [dbo].[Customer] ([Id])
Run Code Online (Sandbox Code Playgroud) 有没有一种简单的方法可以用c ++(xml或二进制)序列化数据,然后在C#中反序列化数据?
我正在使用一些不能运行.Net的远程WINNT机器.我的服务器应用程序完全用C#编写,所以我想要一种简单的方法来共享简单的数据(主要是键值对,也许是SQL结果集的一些表示).我认为最好的方法是在客户端上以某种预定义格式将数据写入xml,将xml文件传输到我的服务器,并让C#包装器将xml读入可用的c#对象.
客户端和服务器通过tcp连接进行通信,我真正想要的是将客户端内存中的数据序列化,通过套接字将二进制数据传输到ac#内存流,我可以将其反序列化为ac#对象(消除文件)创造,转移等),但我不认为这样的事情存在.随意赐教.
我知道我可以在c ++应用程序中创建一个结构,并在c#中定义它并以这种方式传输数据,但在我看来,这就像我限制了可以发送的内容.我必须为对象等设置预定义的大小
我有一组呼叫详细记录,根据这些记录,我应该确定每个系统每小时的平均并发活动呼叫数(精度为一分钟).如果我查询下午7点到晚上8点,我应该看到该小时内(每个系统)的小时平均并发呼叫(平均每分钟的并发呼叫).
所以,我需要一种方法来检查7:00-7:01,7:01-7:02等活动呼叫的数量,然后平均这些数字.如果呼叫的时间和持续时间落在正在检查的当前分钟内,则认为呼叫处于活动状态.
更难的是它需要跨越SQL 7.0和SQL 2000(2000中的某些功能在7.0中不可用,例如GetUTCTime()),如果我能让2000工作,我会很高兴.
我考虑在被检查的小时内循环分钟(60)并添加落在该分钟之间的呼叫计数,然后以某种方式交叉引用持续时间以确保在晚上7:00开始并且持续时间为300秒在7:04显示活跃,但我无法想象如何解决问题.我试图找出一种方法来对每一次电话进行加权,特别是那一分钟会告诉我这段时间内呼叫是否有效,但无法提出有效的解决方案.
这里的数据类型与我要查询的数据类型相同.我没有对模式的任何控制(除了可能转换数据并插入具有更合适的数据类型的另一个表之外).我提供了一些我知道有并发活动调用的示例数据.
CREATE TABLE Records(
seconds char(10),
time char(4),
date char(8),
dur int,
system int,
port int,
)
--seconds is an stime value. It's the difference of seconds from UTC 1/1/1970 00:00:00 to the current UTC time, we use it as an identifier (like epoch).
--time is the time the call was made.
--date is the day the call was made.
--dur is the duration of the call in seconds.
--system is the system …Run Code Online (Sandbox Code Playgroud) 我试图做与链接问题相同的事情,但使用C#.我正在显示缩放图像,并允许用户选择要裁剪的区域.但是,我不能从缩放的图像选择中获取x1y1,x2y2坐标并从原始图像中裁剪出来.我试过像其他问题那样做一些基本的数学,但这显然也不是正确的方法(它肯定更接近).
编辑
原始图像尺寸: w = 1024 h = 768
缩放图像尺寸: w = 550 h = 412
我从图像开始,比如1024x768.我希望它在550x550的盒子中尽可能大.我正在使用以下方法来获得缩放的图像大小(同时保持纵横比).然后我对这些新维度进行基本调整.
对于选择区域,它可以是任何(0,0)到(100,100).
private static Rectangle MaintainAspectRatio(Image imgPhoto, Rectangle thumbRect)
{
int sourceWidth = imgPhoto.Width; int sourceHeight = imgPhoto.Height; int sourceX = 0; int sourceY = 0; int destX = 0; int destY = 0;
float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;
nPercentW = ((float)thumbRect.Width / (float)sourceWidth);
nPercentH = ((float)thumbRect.Height / (float)sourceHeight);
//if we have to pad the height …Run Code Online (Sandbox Code Playgroud) 我需要用户能够创建部分URL,而无需每次都输入完整的URL.
例如,假设我计划在网址上www.example.com/areas/{userinput}/home.我希望用户能够在文本框中输入一些文本,我想验证它是否是有效的URL.
URL验证器的功能如下:
url: function(value, element) {
return this.optional(element) || /giantregex/.test(value);
}
Run Code Online (Sandbox Code Playgroud)
我尝试通过以下方法向验证器添加验证方法:
$.validator.addMethod("exturl", function(value) {
return $.validator.methods.url.call($.validator, "http://www.example.com/areas/" + value + "/home");
});
Run Code Online (Sandbox Code Playgroud)
但是,当表单被验证并且我的扩展名被调用时,我不断收到此错误:
Uncaught TypeError: Object function (d,a){this.settings=b.extend(true,{},b.validator.defaults,d);this.currentForm=a;this.init()} has no method 'optional'
Run Code Online (Sandbox Code Playgroud)
optional看起来是$.validator对象的方法,但我无法弄清楚如何调用验证器url方法.
c# ×5
c++ ×2
sql ×2
.net ×1
algorithm ×1
asp.net-mvc ×1
colors ×1
endianness ×1
foreign-keys ×1
gdi+ ×1
php ×1
sql-server ×1
sql-server-7 ×1
struct ×1
winforms ×1