小编Ian*_*kes的帖子

如何在南希提供静态内容

我在Nancy中提供JavaScript等静态内容时遇到了麻烦.

例如,使用自托管示例我已将一个test.js添加到Views文件夹并添加了一个

<script type="text/javascript" src="test.js"></script>
Run Code Online (Sandbox Code Playgroud)

标记到staticview.html页面.如果我在浏览器中查看此页面,则JavaScript正确执行.

但是,当我运行示例时,JavaScript不会被执行.如果我在FireBug中查看该页面,我发现我收到了test.js的404错误.

我试过添加

Get["{file}"] = p =>
{
    string path = string.Format("Views/{0}", p.file);
    return Response.AsJs(path);
};
Run Code Online (Sandbox Code Playgroud)

当我设置一个断点并在即时窗口中执行Response.AsJs(path)时,我得到一个NotFound的StatusCode

我也尝试过添加一个StaticContentConvention,比如

protected override void ConfigureConventions(NancyConventions conventions)
{
    base.ConfigureConventions(conventions);
    conventions.StaticContentsConventions.Add(
        StaticContentConventionBuilder.AddDirectory("/", "Views"));
    conventions.StaticContentsConventions.Add(
        StaticContentConventionBuilder.AddDirectory("Views", "Views"));
}
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

nancy

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

什么是避免WPF PRISM/MVVM应用程序中的内存泄漏的最佳方法

我有一个基于PRISM的WPF应用程序,它使用MVVM模式.

我注意到偶尔我的视图模型,视图以及与它们相关的所有内容将在其预期寿命之后很久就会出现问题.

一个泄漏涉及在属于注入服务的集合上订阅CollectionChanged,另一个涉及不在DispatcherTimer上调用Stop方法,而另一个泄漏需要清除它的项目.

我觉得使用CompositePresentationEvent可能比订阅CollectionChanged更可取,但在其他场景中,我倾向于实现IDisposable并让视图在视图模型上调用Dispose方法.

但是后来需要告诉视图什么时候在视图模型上调用Dispose,当视图的复杂性增加时,它会变得更具吸引力,并且它们开始包含子视图.

您认为处理视图模型的最佳方法是什么,以确保它们不会泄漏内存?

提前致谢

伊恩

wpf memory-leaks prism mvvm

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

如何使用Silverlight 4 ScrollViewer使鼠标滚轮正常工作

当我在Silverlight 4中使用以下xaml时,ScrollViewer将无法识别鼠标滚轮,除非我在滚动条拇指上单击一次,并将鼠标悬停在滚动条上,同时转动鼠标滚轮.

<Grid x:Name="LayoutRoot" Background="White">
    <ScrollViewer>
        <StackPanel Name="stackPanel1">
            <Button Content="Button 1" Width="150" />
            <Button Content="Button 2" Width="150" Margin="0,20,0,0" />
            <Button Content="Button 3" Width="150" Margin="0,20,0,0" />
            <Button Content="Button 4" Width="150" Margin="0,20,0,0" />
            <Button Content="Button 5" Width="150" Margin="0,20,0,0" />
            <Button Content="Button 6" Width="150" Margin="0,20,0,0" />
            <Button Content="Button 7" Width="150" Margin="0,20,0,0" />
        </StackPanel>
    </ScrollViewer>
</Grid>
Run Code Online (Sandbox Code Playgroud)

有没有其他人经历过这个,有什么工作吗?

silverlight

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

如何在任何方向上搜索二维数组

我正在用C#编写一个单词搜索拼图,我希望能够以优雅的方式搜索二维字符数组.

从左到右,从上到下等基本搜索并不难写,但是当在对角线上搜索时,事情开始变得有点冗长.我已经开始工作,但我确信那里有更好的解决方案.

这是我想要解决的一个难题的例子,任何想法将不胜感激.

BXXD
AXEX
TRXX
FXXX

BAT FRED

编辑:感谢史蒂夫给我一个搜索罗盘点的想法

编辑:搜索结果需要返回数组中单词的x1,y1和x2,y2坐标.

编辑:感谢Antti为搜索数组提供了一个很好的算法.

这是我想出的最终结果.我基于Antti的答案中的算法,修改它以返回任何单词的开头和结尾的数组偏移量.这个算法将用于我在WPF中为我的孩子写的Word Search游戏.感谢大家帮助我.当它受到尊重时,我会在这里发布一个链接到应用程序.

public class Range
{
    public Range(Coordinate start, Coordinate end)
    {
        Start = start;
        End = end;
    }

    public Coordinate Start { get; set; }
    public Coordinate End { get; set; }
}

public class Coordinate
{
    public Coordinate(int x, int y)
    {
        X = x;
        Y = y;
    }

    public int X { get; set; }
    public int Y { get; set; } …
Run Code Online (Sandbox Code Playgroud)

c# algorithm

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

FakeItEasy说MustHaveHappened并没有发生......但确实如此

我正在尝试对"服务层"/"应用程序外观层"方法进行单元测试.这是我试图进行单元测试的方法:

// Create a new order in the database for a customer.  Given a customer id,
// will create a new order and return an OrderDto for use in the presentation
// layer.
public OrderDto CreateOrderForCustomer(int customerId)
{
  // Find the customer
  var customer = _customerRepository.GetCustomerById(customerId);

  // Create an order and apply special logic to get it ready for use.
  var orderFactory = new OrderFactory();
  var order = orderFactory.CreateOrder(customer);

  // IMPORTANT: This is what I'm trying to unit test ... …
Run Code Online (Sandbox Code Playgroud)

c# unit-testing mocking fakeiteasy

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

在NetworkCredentials中提供用户名和密码时,.net中的HttpClient会发出2个请求

当使用.net 4.5中的HttpClient进行基本身份验证时,我发现它发出了2个请求.

第一个失败,HTTP/1.1 401 Unauthorized,然后重新发送我们获得HTTP/1.1 200 OK的请求.

关于如何阻止它这样做的任何想法?

var credential = new NetworkCredential 
{ 
    UserName = username, 
    Password = password 
}
var httpClientHandler = new System.Net.Http.HttpClientHandler
{
    Credentials = credential
};
httpClient = new HttpClient(httpClientHandler, true)
{
    BaseAddress = address
};
Run Code Online (Sandbox Code Playgroud)

.net c#

7
推荐指数
2
解决办法
3851
查看次数

如何在Silverlight应用程序中修复2104错误

我有一个现有的Silverlight应用程序已经运行了几个月,有很多用户.本周我们有一个新用户尝试使用该应用程序,但他不断收到此错误消息.

用户代理:Mozilla/4.0(兼容; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727)时间戳:Wed,24 Nov 2010 03:49:04 UTC

消息:Silverlight应用程序代码中的未处理错误:2104
类别:InitializeError
消息:2104发生错误.

我们在Windows 2008 R2上运行IIS 7.5,用户安装了Silverlight 4(4.0.50826.0).

知道什么可能是错的吗?

silverlight-4.0

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

Mahapps弹出窗口没有出现和caliburn.micro

我正在尝试使用mahapps和caliburn.micro在wpf中显示一个弹出窗口,遗憾的是,弹出窗口的视图没有得到解决,我得到的只是弹出窗口中显示的视图模型的类型名称.

我需要在shell中显示基于ActiveItem的弹出窗口,例如公司搜索弹出窗口与联系人搜索弹出窗口不同.

任何想法我如何使这项工作.

public void ShowSearchFlyout()
{
    var supportsSearch = ActiveItem as ISupportSearch;
    if (supportsSearch != null)
    {
        if (!Flyouts.Contains(supportsSearch.SearchFlyout))
        {
            Flyouts.Add(supportsSearch.SearchFlyout);
        }
        supportsSearch.SearchFlyout.IsOpen = true;
    }
}
Run Code Online (Sandbox Code Playgroud)
<controls:MetroWindow.Flyouts>
    <controls:FlyoutsControl ItemsSource="{Binding Flyouts}">
        <controls:FlyoutsControl.ItemContainerStyle>
            <Style BasedOn="{StaticResource {x:Type controls:Flyout}}" TargetType="{x:Type controls:Flyout}">
                <Setter Property="Header" Value="{Binding Header}"  />
                <Setter Property="IsOpen" Value="{Binding IsOpen}" />
                <Setter Property="Position" Value="{Binding Position}" />
            </Style>
        </controls:FlyoutsControl.ItemContainerStyle>
    </controls:FlyoutsControl>
</controls:MetroWindow.Flyouts>
Run Code Online (Sandbox Code Playgroud)

wpf caliburn.micro mahapps.metro

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

TeamCity中功能分支的自动合并无法正常工作

我们使用TeamCity Professional 9.1.1和Git/Stash进行版本控制,我试图让自动分支合并工作.

我们的场景是开发人员从名为feature/feature-feature的master创建功能分支.一旦该功能准备好进行测试,它们就会将分支合并到一个集成分支中.我们希望在团队城市中实现自动化.

我已经设法通过将其添加到我们的分支规范中来自动构建功能和bugfix分支:在主分支的VCS根目录中

+:refs/heads/feature/*
+:refs/heads/bugfix/*
Run Code Online (Sandbox Code Playgroud)

但我很难让功能分支自动合并到集成分支中.我添加了一个自动合并构建功能,我尝试了各种组合的"分支中的监视构建"和"合并到分支中:"对于"分支中的监视构建"我目前有

+:feature*
+:bugfix*
Run Code Online (Sandbox Code Playgroud)

并为'合并到分支:'

integration
Run Code Online (Sandbox Code Playgroud)

而我也试过了

+:feature/*
+:bugfix/*
Run Code Online (Sandbox Code Playgroud)

+:refs/heads/feature/*
+:refs/heads/bugfix/*
Run Code Online (Sandbox Code Playgroud)

构建成功但分支不会合并到集成中,并且日志中没有消息.

我有什么想法我做错了吗?

git teamcity

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