问题列表 - 第7505页

动态构建的正则表达式运行速度极慢!

我通过运行一些xml结构动态生成正则表达式,并在我查看其节点类型时构建语句.我正在使用此正则表达式作为我定义的布局类型的一部分.然后我解析一个文本文件,在每行的开头有一个Id.这个id指向我一个特定的布局.然后我尝试将该行中的数据与其正则表达式进行匹配.

听起来不错,花花公子吧?唯一的问题是匹配字符串非常慢.我把它们设置为编译,以尝试加快速度,但无济于事.令人困惑的是,这些表达方式并不复杂.我绝不是一个正则表达式的大师,但我知道一个体面的关于他们的量把事情顺利.

这是生成表达式的代码......

StringBuilder sb = new StringBuilder();
//get layout id and memberkey in there...
sb.Append(@"^([0-9]+)[ \t]{1,2}([0-9]+)"); 
foreach (ColumnDef c in columns)
{
    sb.Append(@"[ \t]{1,2}");
    switch (c.Variable.PrimType)
    {
        case PrimitiveType.BIT:
            sb.Append("(0|1)");
            break;
        case PrimitiveType.DATE:
            sb.Append(@"([0-9]{2}/[0-9]{2}/[0-9]{4})");
            break;
        case PrimitiveType.FLOAT:
            sb.Append(@"([-+]?[0-9]*\.?[0-9]+)");
            break;
        case PrimitiveType.INTEGER:
            sb.Append(@"([0-9]+)");
            break;
        case PrimitiveType.STRING:
            sb.Append(@"([a-zA-Z0-9]*)");
            break;
    }
}
sb.Append("$");
_pattern = new Regex(sb.ToString(), RegexOptions.Compiled);
Run Code Online (Sandbox Code Playgroud)

实际的慢节......

public System.Text.RegularExpressions.Match Match(string input)
{
    if (input == null)
       throw new ArgumentNullException("input");

    return _pattern.Match(input);
}
Run Code Online (Sandbox Code Playgroud)

典型的"_pattern"可能有大约40-50列.我将不会粘贴整个模式.我尝试对每个案例进行分组,以便稍后我可以在Match对象中枚举每个案例.

任何可以提供极大帮助的提示或修改?或者这种情况会慢慢发挥作用?

编辑清晰度:对不起,我认为我第一次不够清楚.

我使用xml文件为特定布局生成正则表达式.然后我运行一个文件进行数据导入.我需要确保文件中的每一行都匹配它应该是的模式.因此,可以多次检查模式,可能是数千次.

.net c# regex xml performance

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

LAN /交通拥堵意味着什么?

在谈论UDP时,我看到/听到拥塞几次.那是什么意思?

networking udp congestion-control ip-protocol

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

在Visual Studio WiX项目中使用WXI文件

我遇到了几个来源,说明使用包含文件(.wxi)将WiX安装文件拆分为单独的部分(变量,组件等).对我来说很有意义,所以我从.wxs文件中取出<components>节点并将它们放在一个单独的文件中,但是当我尝试在Visual Studio 2008中编译项目时,每个<ComponentRef>声明都会出错这是"产品:{...}"一节中的"未解决的符号参考...".

我已经使用<?包括"文件名"?>标记在我Product.wxs文件试过,但似乎打破了模式验证.如果是这样的,包括它的方式,在那里它需要去?

我有的文件如下.

Product.wxs

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product ...>
    <Package .../>
    <Media .../>
    <Directory Id="TARGETDIR" Name="SourceDir">
    </Directory>
    <Feature Id="MainProgram" Level="1">
      <ComponentRef Id="ProductComponent" />
      <Feature Id="ContextMenu" Level="2">
        <ComponentRef Id="ContextMenuComponent" />
      </Feature>
    </Feature>
  </Product>
</Wix>
Run Code Online (Sandbox Code Playgroud)

Components.wxi

<?xml version="1.0" encoding="utf-8"?>
<Include>
  <Fragment>
    <Component Id="ProductComponent" ...>
      <File .../>
    </Component>
    <Component Id="ContextMenuComponent" ...>
      <RegistryKey .../>
    </Component>
  </Fragment>
</Include>
Run Code Online (Sandbox Code Playgroud)

如何在Visual Studio中构建它?编写脚本似乎更简单,但还不是我的问题.

wix visual-studio-2008

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

用泛型克隆

曾几何时有一堂课:

public class Scope<C extends Cloneable & Comparable<C>> implements Comparable<Scope<C>>, Cloneable, Serializable {

   private C starts;
   private C ends;
   ...

   @SuppressWarnings("unchecked")
   @Override
   public Object clone() {
       Scope<C> scope;
       try {
           scope = (Scope<C>) super.clone();
           scope.setStarts((C) starts.clone()); // The method clone() from the type Object is not visible
           scope.setEnds((C) ends.clone()); // The method clone() from the type Object is not visible
       } catch (CloneNotSupportedException e) {
           throw new RuntimeException("Clone not supported");
       }
       return scope;
   }
}
Run Code Online (Sandbox Code Playgroud)

在对象中我们有:

protected native Object clone() …
Run Code Online (Sandbox Code Playgroud)

java clone

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

实体框架,WCF和更新

我创建了一个n层解决方案,我从WCF服务检索相关数据,在Windows窗体应用程序中更新它,然后通过WCF返回更新的数据以保存到数据库.应用程序,WCF服务和数据库都在不同的机器上.

检索的数据包含一个对象和子对象......

public Product Select(string catalogueNumber) {

  return (from p in this.ProductEntities.Products.Include(@"Tracks")
            where p.vcCatalogueNumber == catalogueNumber
            select p).FirstOrDefault() ?? new Product();
}
Run Code Online (Sandbox Code Playgroud)

客户端应用程序应用的更新可以以及更新现有内容,还可以插入其他"跟踪"对象.

当我从客户端应用程序收到Product对象时,我可以正确地看到所有更新,但为了正确保存所有更改,我必须跳过几个箍......

public void Save(Product product) {

    Product original = this.Select(product.vcCatalogueNumber);
    if (original.EntityKey != null) {

        this.ProductEntities.ApplyPropertyChanges(product.EntityKey.EntitySetName, product);

        // There must be a better way to sort out the child objects...
        foreach (Track track in product.Tracks.ToList()) {

            if (track.EntityKey == null) {
                original.Tracks.Add(track);
            }
            else {
                this.ProductEntities.ApplyPropertyChanges(track.EntityKey.EntitySetName, track);
            }

        }

    }
    else {

        this.ProductEntities.AddToProducts(product);

    }

    this.ProductEntities.SaveChanges();

}
Run Code Online (Sandbox Code Playgroud)

当然,必须有一个更简单的方法来做到这一点? …

wcf entity-framework n-tier-architecture

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

图像大小调整 - 有时质量很差?

我正在调整一些图像到用户的屏幕分辨率; 如果宽高比错误,应该剪切图像.我的代码看起来像这样:

protected void ConvertToBitmap(string filename)
    {
        var origImg = System.Drawing.Image.FromFile(filename);
        var widthDivisor = (double)origImg.Width / (double)System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
        var heightDivisor = (double)origImg.Height / (double)System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
        int newWidth, newHeight;

        if (widthDivisor < heightDivisor)
        {
            newWidth = (int)((double)origImg.Width / widthDivisor);
            newHeight = (int)((double)origImg.Height / widthDivisor);
        }
        else
        {
            newWidth = (int)((double)origImg.Width / heightDivisor);
            newHeight = (int)((double)origImg.Height / heightDivisor);
        }

         var newImg = origImg.GetThumbnailImage(newWidth, newHeight, null, IntPtr.Zero);
        newImg.Save(this.GetBitmapPath(filename), System.Drawing.Imaging.ImageFormat.Bmp);
    }
Run Code Online (Sandbox Code Playgroud)

在大多数情况下,这很好.但是对于一些图像,结果有一个非常质量较差.它似乎已被调整为非常小(缩略图大小)的东西并再次放大..但图像的分辨率是正确的.我能做什么?

例如原稿图像: 替代文字http://img523.imageshack.us/img523/1430/naturaerowoods.jpg

调整大小的图片示例: alt text http://img523.imageshack.us/img523/2531/naturaerowoods.png

注意:我有一个WPF应用程序,但我使用WinForms函数进行大小调整,因为它更容易,因为我已经需要一个托盘图标的System.Windows.Forms引用.

c# resize image image-scaling

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

我怎样才能将wpf应用程序转换为exe

如何将wpf应用程序转换为将在所有Microsoft Windows操作系统上运行的.exe. 

wpf

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

为什么这种解体不起作用?

我几分钟前尝试回答这个问题并为自己准备了这个例子:

<script>
  function trialMethod()
  {
    alert('On Submit Run!'); return true;
  }
  function trialMethod2()
  {
    alert('On Submit Run trialMethod2!'); return true;
  }
</script>

<form id="aspnetForm" onsubmit="trialMethod();">
    <input type="submit">
</form>
Run Code Online (Sandbox Code Playgroud)

为什么第一个解除绑定不起作用:

<input type="button" id="btnTrial1" value="UNBIND 1" 
   onclick="$('#aspnetForm').unbind('submit', trialMethod);">
Run Code Online (Sandbox Code Playgroud)

但是这个适用于trialMethod2方法:

<input type="button" id="btnTrial2" value="UNBIND 2" 
   onclick="$('#aspnetForm').bind('submit', trialMethod2).unbind('submit', trialMethod2);">
Run Code Online (Sandbox Code Playgroud)

javascript jquery jquery-events

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

用于.NET的BLOB分布式存储?

我正在寻找一个经过合理测试的库+服务器来存储一个持久的分布式哈希表.

我非常喜欢使用基于SQL的解决方案,因为数据是高度面向文档的,由数百万~64KB的blob组成,只有一个索引(通过所述BLOB的哈希计算) - 并且需要能够分发以进行长期扩展前景.

由于费用和带宽的考虑,S3等外部解决方案不是一种选择.

像CouchDB或Project Voldemort这样的东西是理想的 - 但是两者都有明显缺乏.NET绑定(PV可以是来自Java的IKVMC-但是有"问题".).键和值都是字节数组(键为16字节,值最大为2048KB,平均为64KB)

到目前为止,我已经搜索了Dynamo,Chord和类似的某种.NET端口 - 但是大多数结果似乎都是纯粹的内存缓存,缺乏任何形式的持久性或复制.

有人有任何想法或建议吗?

.net database storage distributed dht

15
推荐指数
1
解决办法
1059
查看次数

通用类文件名约定

我希望能够区分类的泛型和非常规(非泛型)版本.就像.NET框架使用它的几个接口和集合类的通用和非泛型版本一样.(队列,队列(T))

我通常喜欢遵循每个文件一个类的约定(如在Java中).是否存在命名包含单个泛型类的文件的通用约定?我最感兴趣的是Windows(特别是NTFS),但它似乎是一个很好的约定(至少有点)可移植.

c# generics

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