小编Joe*_*oel的帖子

使用StructureMap注入工厂方法

我正在使用ASP.NET成员资格提供程序包装器,以便我可以使用更多松散耦合的库.我想使用StructureMap来提供真正的IoC,但是我在使用User-to-Profile工厂对象进行配置时遇到了麻烦,我正在使用它来在用户的上下文中实例化配置文件.这是相关的细节,首先是库中的接口和包装器:

// From ASP.Net MVC Membership Starter Kit
public interface IProfileService
{
    object this[string propertyName] { get; set; }
    void SetPropertyValue(string propertyName, object propertyValue);
    object GetPropertyValue(string propertyName);
    void Save();
}

public class AspNetProfileBaseWrapper : IProfileService
{
    public AspNetProfileBaseWrapper(string email) {}

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

接下来,用于与配置文件数据中的特定属性进行交互的存储库:

class UserDataRepository : IUserDataRepository
{
    Func<MembershipUser, IProfileService> _profileServiceFactory;

    // takes the factory as a ctor param 
            // to configure it to the context of the given user
    public UserDataRepository(
              Func<MembershipUser, IProfileService> profileServiceFactory) …
Run Code Online (Sandbox Code Playgroud)

.net c# structuremap

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

非静态方法需要PropertyInfo.SetValue中的目标

好的,所以我正在学习泛型,我正试图让这个东西运行,但它一直在说我同样的错误.这是代码:

public static T Test<T>(MyClass myClass) where T : MyClass2
{
    var result = default(T);
    var resultType = typeof(T);
    var fromClass = myClass.GetType();
    var toProperties = resultType.GetProperties();

    foreach (var propertyInfo in toProperties)
    {
        var fromProperty = fromClass.GetProperty(propertyInfo.Name);
        if (fromProperty != null)
            propertyInfo.SetValue(result, fromProperty, null );
    }

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

c# generics propertyinfo setvalue visual-studio

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

属性注入动作过滤器

我正在尝试使用Property Injection处理自定义操作过滤器属性.它本来应该工作,但是,我想在Property本身上使用DI.我的过滤器看起来像这样

[AttributeUsage(AttributeTargets.Class)]
public sealed class HeaderFilterAttribute : ActionFilterAttribute
{
    public IMarketService MarketService
    { get; set; }

    public override void OnActionExecuted(ActionExecutedContext filterContext)
    {
        var view = (ViewResultBase)filterContext.Result;

        if (view != null)
        {
            BaseViewModel viewModel = view.ViewData.Model as BaseViewModel;
            if (viewModel != null)
                viewModel.Header = GetHeaderScript();
        }
        base.OnActionExecuted(filterContext);
    }

   private string GetHeaderScript()
   {
     //Use MarketService here and return header script
     return "script";
   }
}
Run Code Online (Sandbox Code Playgroud)

这就是我在BootStrapper类中使用StructureMap配置属性的方法.

            //HeaderFilterAttribute
        IMarketRepository marketRepository = new SqlMarketRepository();
        IMarketService marketService = new MarketService(marketRepository);
        ObjectFactory.Container.Configure(r => r.ForConcreteType<HeaderFilterAttribute>().
                                          Configure.WithProperty("MarketService").
                                          EqualTo(marketService)); …
Run Code Online (Sandbox Code Playgroud)

c# structuremap dependency-injection asp.net-mvc-2

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

jqgrid在编辑模式下排

有没有办法知道jqgrid中的行是否处于编辑模式?

提前致谢.

javascript jqgrid

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

Structuremap PerRequest生命周期

我想在运行中(即在注册表/配置之外)将一个实例注入到结构映射中,该实例在请求的生命周期中存在.

目前我在做这个HandleBeginRequest的事件IHttpModule:

container.Configure(x => x.For<IMyClass>()
  .LifecycleIs(Lifecycles.GetLifecycle(InstanceScope.PerRequest))
  .Use(new MyClass()));
Run Code Online (Sandbox Code Playgroud)

但是,如果在应用程序的生命中的某个时刻我做了:

ObjectFactory.WhatDoIHave();
Run Code Online (Sandbox Code Playgroud)

我看到尽可能多的已配置实例IMyClass(或至少有大量数据).

考虑到它,考虑到我的代码,这种方式是有意义的.

有没有更好的方法将实例注入容器中,只是为了当前请求的生命周期,不会污染整个容器?

谢谢

.net c# structuremap

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

DataGridView设置行高不起作用

试着像这样设置RowHeight(在代码中):

dgvTruckAvail.RowTemplate.Height = 48;
Run Code Online (Sandbox Code Playgroud)

不行吗?我还尝试设置我添加的每个列的高度 - 不起作用.

这是网格属性:

this.dgvTruckAvail.AllowUserToAddRows = false;
this.dgvTruckAvail.AllowUserToDeleteRows = false;
this.dgvTruckAvail.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
    | System.Windows.Forms.AnchorStyles.Left) 
    | System.Windows.Forms.AnchorStyles.Right)));
this.dgvTruckAvail.BackgroundColor = System.Drawing.Color.White;
this.dgvTruckAvail.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.dgvTruckAvail.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None;
this.dgvTruckAvail.Columns.AddRange(
    new System.Windows.Forms.DataGridViewColumn[] 
    {
        this.colMon,
        this.colTue,
        this.colWED,
        this.colThu,
        this.colFri,
        this.colSat,
        this.colSun});
this.dgvTruckAvail.Cursor = System.Windows.Forms.Cursors.Default;
dataGridViewCellStyle8.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle8.BackColor = System.Drawing.SystemColors.Window;
dataGridViewCellStyle8.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
dataGridViewCellStyle8.ForeColor = System.Drawing.SystemColors.ControlText;
dataGridViewCellStyle8.SelectionBackColor = System.Drawing.SystemColors.Window;
dataGridViewCellStyle8.SelectionForeColor = System.Drawing.SystemColors.ControlText;
dataGridViewCellStyle8.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
this.dgvTruckAvail.DefaultCellStyle = dataGridViewCellStyle8;
this.dgvTruckAvail.EnableHeadersVisualStyles = false; …
Run Code Online (Sandbox Code Playgroud)

c# datagridview winforms

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

datagridview中的复杂布局

我正在努力完成这样的事情: 样本清单

这可以用datagridview吗?或ListView,或Windows窗体中的任何其他组件?注意填充和(最重要的)标签在彼此之上.

我怎样才能在C#.NET中实现这一目标?

.net c# datagridview winforms

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

无法使用 Spring Data Redis 持久化数据

我正在试验 Spring Data Redis。我编写了一个 Java 类,它允许我连接到 Redis 服务器,但不会在服务器中保留数据。有人会知道可能有什么问题吗?以下是一些细节——

我的弹簧配置看起来像-

<bean id="jedisConnFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:use-pool="true"  p:host-name="127.0.0.1" p:port="6379"/>

<!-- redis template definition -->
<bean id="redisTemplate"
    class="org.springframework.data.redis.core.RedisTemplate"
    p:connection-factory-ref="jedisConnFactory"/>
Run Code Online (Sandbox Code Playgroud)

我的 Java 代码看起来像这样 -

public class CacheClient {

   @Autowired
    private RedisTemplate<String, String> template;
    public void setValue(String key, String value){
      template.boundValueOps(key).set(value);
    }
}
Run Code Online (Sandbox Code Playgroud)

一旦我调用了 template.setValue(key,value),我就会在 redis-cli 上执行“获取密钥”,但我没有看到为该密钥设置的任何值。

有人可以帮忙吗?

谢谢

java spring redis

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

jqGrid如何将额外的类应用于标题列

我想在特定列上应用一个额外的类,我知道这可以通过在colModel中指定它来实现行.但是这些类仅应用于"结果行"中的列而不应用于标题.

我想要达到的目的是通过一个简单的类名隐藏较小视口的特定列(用于Twitter Bootstrap).

javascript header class jqgrid

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

openlayers矢量功能z-indexing

我很难尝试理解矢量特征的z索引.

当我在网上搜索信息时,我发现了这些链接:http : //openlayers.org/dev/examples/ordering.html http://osgeo-org.1803224.n2.nabble.com/Bug-in-using- graphicZIndex-td2648665.htmlhttp://osgeo-org.1803224.n2.nabble.com/graphicZIndex-of-vector-features-td3919627.html

我做的是设置样式,就像它们显示在第一个链接上:

 this.vectorsLayer = new OpenLayers.Layer.Vector("Vectors", {
                styleMap: new OpenLayers.StyleMap({
                    "default": {
                    'strokeColor': "#ff9933",
                    'strokeWidth': 5
                    },
                    "select": {
                        'strokeColor': "#3399ff"
                    }
                })
            }
        );
    this.carsLayer = new OpenLayers.Layer.Vector("Cars", {'rendererOptions': {yOrdering: false, zIndexing: true}});

     this.startIconStyle = {'externalGraphic':this.startIconUrl};

     this.parkIconStyle = {'externalGraphic':this.parkIconUrl};

     this.endIconStyle = {'externalGraphic':this.endIconUrl};

     this.defaultStyles = {
             //'label':getLabel(),
             'graphicZIndex':745,
            'graphicXOffset':-13,
            'graphicYOffset':-41,
            'graphicWidth':26,
            'graphicHeight':41,
            'strokeLinecap':'round',
            'strokeColor':"#000000",
            'strokeWidth':2,
            'strokeOpacity':1,
            'fillOpacity':1}
        //style of path that car has used 
    this.drivedStyle = {
            'strokeWidth': 3,
            'strokeOpacity': 1,
            'strokeColor': …
Run Code Online (Sandbox Code Playgroud)

javascript openlayers

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

找到了与请求匹配的多个操作

我已经阅读了很多关于路由和控制器的问题,但我根本无法找到我正在寻找的东西.我有这个结构的控制器:

更新:包含完整的类源.

public class LocationsController : ApiController
{
    private readonly IUnitOfWork _unitOfWork;

    public LocationsController(IUnitOfWork unitOfWork)
    {
        _unitOfWork = unitOfWork;
    }

    // GET /api/locations/id
    public Location Get(Guid id)
    {
        return this.QueryById<Location>(id, _unitOfWork);
    }

    // GET /api/locations
    public IQueryable<Location> Get()
    {
        return this.Query<Location>(_unitOfWork);
    }

    // POST /api/locations
    public HttpResponseMessage Post(Location location)
    {
        var id = _unitOfWork.CurrentSession.Save(location);
        _unitOfWork.Commit();

        var response = Request.CreateResponse<Location>(HttpStatusCode.Created, location);
        response.Headers.Location = new Uri(Request.RequestUri, Url.Route(null, new { id }));

        return response;
    }

    // PUT /api/locations
    public Location Put(Location location) …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc-routing asp.net-web-api

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

使用Java正则表达式自定义HTML img标记

我是正则表达式的新手,但我相信这是我解决方案的方法.我正在尝试使用任意HTML代码段并自定义图像标记.例如,

如果我有这个HTML代码: <><><><><img src="blah.jpg"><><><><><><><><img src="blah2.jpg"><><><>

我想把它变成: <><><><><img src="images/blah.jpg"><><><><><><><><img src="images/blah2.jpg"><><><>

我现在的守则是这样的:

Pattern p = Pattern.compile("<img.*src=\".*\\..*\"");
Matcher m = p.matcher(htmlString);
boolean b = m.find();

String imgPath = "src=\"images/";

while(b)
{
    //Get file name.
    String name="test.jpg\"";

    //Assign new path.
    m.group().replaceAll("src=\".*\"",imgPath+name);
}
Run Code Online (Sandbox Code Playgroud)

html java regex

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

每秒都从cron运行一个脚本

我有一个脚本,我从浏览器运行元刷新,它在浏览器中没有任何问题,但它不会在cron中工作所以我可以做什么从cron运行每一秒?我知道睡眠我可以,但我必须在cron作业中创建几个cron选项卡,每次我必须运行脚本

有睡眠我怎么能每5秒运行一次这个脚本.

<meta http-equiv="refresh" content="5;url=test.php">
<?php
    $res = mysql_query("SELECT * FROM tableA where st='0' order by id asc LIMIT 1");
    $row = mysql_fetch_array($res);

    $link= $row['wl'];

    function getTitle($Url){
        $str = file_get_contents($Url);
        if(strlen($str)>0){
        preg_match("/\<\/td\><\/tr\><tr\><td colspan\=2\>(.*)\<\/td\>/",$str,$title);

            return $title[1];
        }
    }
    getTitle($link);
?>
Run Code Online (Sandbox Code Playgroud)

php cron crontab

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