小编Ben*_*jin的帖子

"没有加载模块MyLibrary.dll的符号"?

我正在尝试通过制作一个提供有关口袋妖怪信息的基本应用来学习Windows Phone开发.为此,我创建了一个可移植的类库(PokeLib.dll),因此它与通用应用程序兼容.我通过同一解决方案("测试")中的项目对此进行了测试,并且工作正常.您可以在我的Github上查看这些代码,但据我所知,这一切都很好.这两个项目都在一个解决方案中.对于Windows Phone应用程序的解决方案,我将PokeLib添加为"现有项目",添加了引用,并编写了几行代码以确保我可以调用它:

MainPage.xaml中:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <Button Name="GetDataButton" Content="GetData" Click="GetDataButton_Click" Grid.Row="0" HorizontalAlignment="Center"/>
    <TextBlock Name="DataText" Text="Click to get data" Grid.Row="1" Padding="10"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)

MainPage.xaml.cs中:

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        p = new Pokemon(1); // gets data for Pokemon #1 (Bulbasaur)
    }

    Pokemon p;
    int counter = 0;

    private async void GetDataButton_Click(object sender, RoutedEventArgs e)
    {
        DataText.Text = "Fetching... Count: " + ++counter;
        if (counter == 1) // first time button's clicked
        {
            await p.Create(); …
Run Code Online (Sandbox Code Playgroud)

.net c# windows-phone-8 win-universal-app

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

使用具有可扩展工厂的泛型?

我把我的问题简化为一个涉及动物的例子.我想定义一组接口(/抽象类),允许任何人为给定的动物创建工厂并将其注册到中央注册器:AnimalRegistry跟踪所有已注册的AnimalFactory对象,然后生成并提供一致的集合Animal对象的功能.

通过我写这个(下面的代码)的方式,我有一个非常简单的界面来处理泛型动物:

        AnimalRegistry registry = new AnimalRegistry();
        registry.Register<ElephantFactory>();
        registry.Register<GiraffeFactory>();

        Animal a1 = registry.GetInstance<ElephantFactory>().Create(new ElephantParams(weight: 1500));
        Animal a2 = registry.GetInstance<GiraffeFactory>().Create(new GiraffeParams(height: 180));

        registry.Serialize(a1);
        registry.Serialize(a2);
Run Code Online (Sandbox Code Playgroud)

但是,我真的不喜欢这个:

在编译时没有什么可以阻止ElephantParams意外传递给registry.GetInstance<GiraffeFactory>().Create(AnimalParams).

如何AnimalFactory以这样的方式编写基类,以确保在编译时只能AnimalParams传递正确的类型,同时仍然允许其他人为其他动物编写自己的具体实现?

我可以...

  • 添加明确的方法Create(ElephantParams)Create(GiraffeParams)各自的班级,但这需要抛弃所有的基类有一个Create()方法的合同.
  • AnimalRegistry在它们AnimalParams和相应的工厂之间添加一个额外的映射,并Create()在注册表中定义一个新方法,但这不是一个优雅的解决方案,因为问题只是移动而不是解决.

我怀疑答案在于更多类型的泛型,但它现在逃脱了我.

AnimalRegistry:

public class AnimalRegistry
{
    Dictionary<Type, AnimalFactory> registry = new Dictionary<Type, AnimalFactory>();

    public void Register<T>() where T : AnimalFactory, new()
    {
        AnimalFactory factory = new T();

        registry[typeof(T)] …
Run Code Online (Sandbox Code Playgroud)

c# generics

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

通过Java访问Windows证书存储证书?

我期待写一些东西,可以枚举和CurrentUser /我和LOCALMACHINE /我使用(签)证书,但我一直没能找到Windows的证书存储,只有Java的自己的秘密商店什么. 这个链接看起来很有希望,但我只能使用Java附带的东西.

我之前发现过这个问题,但它是从五年前开始的,这是计算机时代的很长一段时间.谢谢!

java windows certificate-store x509certificate

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

登录后重定向到原始目标

Rails 2.3.11

如果用户在未登录时尝试转到/照片,则会将其定向到[site]/admin/login?route=[site]/photos.登录后,我希望将它们发送到"route"中定义的任何内容,而不是默认主页.

在/app/controllers/admin_controller.rb中:

def login
    if session[:user_id] #already logged in
      redirect_to ''
    @destination = request.url
    end
    if request.post?
      if [authentication code]
        if user.activated? #check to see whether the user has activated their account
          session[:user_id] = user.id
          if params[:route] # ********
            redirect_to "#{params[:route]}"
          else
            redirect_to :controller => 'home'
          end
        else
          flash.now[:notice] = "Your account hasn't been activated yet.  Check your emails!"
        end
      else
        flash.now[:notice] = "Invalid email/password combination"
      end
    end
  end
Run Code Online (Sandbox Code Playgroud)

" * "ed行是无法正常工作的行.当我检查以查看参数时,:route不在其中,因此参数不会与登录帖一起传入.任何人都可以向我解释为什么它不是,我怎么能解决它?

谢谢!

ruby-on-rails

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

通过PInvoke"Hello World"

我正在尝试在C#中创建一些需要调用一些非托管DLL的东西,这个过程对我一无所知!我发现了一个"Hello World"教程,应该像从底部复制和粘贴几行代码一样简单:

using System;
using System.Runtime.InteropServices;

namespace PInvokeTest
{
    class Program
    {
        [DllImport("msvcrt40.dll")]
        public static extern int printf(string format, __arglist);

        public static void Main()
        {
            printf("Hello %s!\n", __arglist("World"));
            Console.ReadKey();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这个编译并运行完成没有任何错误,但是到达时没有任何打印ReadKey().

我错过了一些重要的设置步骤吗?该项目是为.NET 4.6.1构建的(如果对DLL版本控制很重要).

.net c# pinvoke

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

除了"荣誉代码"之外,还有一个区别是使用专用的"锁定对象"并直接锁定数据吗?

我有两个线程:一个提供更新,另一个将它们写入磁盘.只有最新的更新很重要,所以我不需要PC队列.

简而言之:

  • 馈线线程将最新更新丢弃到缓冲区中,然后设置标志以指示新的更新.
  • writer线程检查该标志,如果它指示新内容,则将缓冲的更新写入磁盘并再次禁用该标志.

我目前正在使用专用锁对象来确保没有不一致,我想知道直接锁定标志和缓冲区有什么区别.我唯一知道的是,一个专用的锁对象需要信任,每个想要操纵标志和缓冲区的人都使用锁.

相关代码:

private object cacheStateLock = new object();
string textboxContents;
bool hasNewContents;

private void MainTextbox_TextChanged(object sender, TextChangedEventArgs e)
{
    lock (cacheStateLock)
    {
        textboxContents = MainTextbox.Text;
        hasNewContents = true;
    }
}

private void WriteCache() // running continually in a thread
{
    string toWrite;

    while (true)
    {
        lock (cacheStateLock)
        {
            if (!hasNewContents)
                continue;

            toWrite = textboxContents;
            hasNewContents = false;
        }

        File.WriteAllText(cacheFilePath, toWrite);
    }
}
Run Code Online (Sandbox Code Playgroud)

.net c# multithreading synchronization

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

如何在XAML中绘制细分数据绑定矩形?

我正在创建一个根据映射配置文件显示表行的应用程序.现在,我有XAML在正确的位置显示矩形的外边界,但我找不到任何有关绘制细分线的信息,这些细分线在数据源中保存为numTablesWidenumTablesTall.

这是在正确的位置绘制框的XAML

<ListBox.ItemContainerStyle>
    <Style TargetType="ListBoxItem">
        <Setter Property="Template">
            <!-- Selection stuff -->
        </Setter>

        <Setter Property="Canvas.Top" Value="{Binding y}"/>
        <Setter Property="Canvas.Left" Value="{Binding x}"/>

        <Setter Property="VerticalContentAlignment" Value="Stretch"/>
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        <Setter Property="Padding" Value="5"/>
        <Setter Property="Panel.ZIndex" Value="{Binding z}" />

        <Setter Property="ContentTemplate">
            <Setter.Value>
                <DataTemplate>
                    <Grid>
                        <Path Data="{Binding data}" Stroke="{Binding brush}" StrokeThickness="2" Stretch="Fill"/>
                        <TextBlock Text="{Binding i}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                    </Grid>
                </DataTemplate>
            </Setter.Value>
        </Setter>

        <Style.Triggers>
            <DataTrigger Binding="{Binding type}" Value="tableBlock">
                <Setter Property="ContentTemplate">
                    <Setter.Value>
                        <DataTemplate>
                            <Grid>
                                <Rectangle Fill="{Binding fill}" Stroke="Black" StrokeThickness="5"
                                           Width="{Binding width}" Height="{Binding height}" Panel.ZIndex="50"/>
                                <TextBlock …
Run Code Online (Sandbox Code Playgroud)

c# wpf

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

滑块移动时获取滑块的价值?

我正在搞乱学习一些基本的前端Web技术 - Bootstrap,jQuery,HTML5 canvas - 我希望能够在滑块移动时更新我正在绘制的正弦曲线的尺寸,而不是在它被释放时(如何发布)目前有效).

<input type="range" id="ampSlider" min="-200" max="200" step="5" onchange="refreshGraph()">
<input type="range" id="freqSlider" min="1" max="400" step="5" onchange="refreshGraph()">
<canvas id="graphCanvas" width="1000" height="600"></canvas>

<script>
    drawShape();
    drawGraph(200, 150);
    $("#ampSlider").val(200);
    $("#freqSlider").val(150);

    function refreshGraph()
    {
        console.log($("#ampSlider").val());
        drawGraph($("#ampSlider").val(), $("#freqSlider").val());
    }

    function drawGraph(amp, freq)
    {
        console.log("Drawing: " + amp + " | " + freq);
        var canvas = document.getElementById('graphCanvas');
        var context = canvas.getContext('2d');
        context.clearRect(0, 0, canvas.width, canvas.height);
        var y = canvas.height/2;
        context.lineWidth = 10;
        context.beginPath();
        context.moveTo(0, y);

        for(n = 0; n < canvas.width; n …
Run Code Online (Sandbox Code Playgroud)

javascript jquery html5

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

SQL Server:UDT与UDDT?

用户定义的类型(UDT)和用户定义的数据类型(UDDT)有什么区别?

t-sql sql-server sqlclr user-defined-types user-defined-data-types

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

以编程方式添加一个上下文菜单,其单击处理程序知道右键单击了哪个项目

我正在动态生成一棵树TreeViewItem,并希望向树中的每个项目添加相同的上下文菜单。因为所有上下文菜单都是相同的,所以我想我可以制作一个,并将其应用到每个TreeViewItem. (也许这是一个坏主意?)似乎只要Click处理程序可以确定TreeViewItem打开了哪个上下文菜单,就应该可以工作。

我尝试将此处(获取右键单击的对象)和此处(以编程方式添加绑定)的答案结合起来,并得出以下结论:

ContextMenu carContextMenu;

public MainWindow()
{
    InitializeComponent();
    Initialize();
    ConstructTree();
}

void ConstructTree()
{
    string[] carNames = {"Mustang", "Viper", "Jetta"};

    foreach (string car in carNames)
    {
        TreeViewItem carNode = new TreeViewItem();
        carNode.Header = car;
        carNode.ContextMenu = carContextMenu;

        CarTree.Items.Add(carNode);
    }
}

void Initialize()
{
    carContextMenu= new ContextMenu();
    MenuItem newQuery = new MenuItem();
    newQuery.Header = "Drive car...";

    Binding b = new Binding("Parent");
    b.RelativeSource = RelativeSource.Self;

    newQuery.SetBinding(MenuItem.CommandParameterProperty, b);
    newQuery.Click += NewQuery_Click; …
Run Code Online (Sandbox Code Playgroud)

.net c# wpf

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