gpt4 book ai didi

c# - KitchenPC 和 Ironpython

转载 作者:行者123 更新时间:2023-11-29 11:59:53 25 4
gpt4 key购买 nike

我正在尝试使用 IronPython 来处理 KitchenPC。

我在这里使用数据库配置示例:http://blog.kitchenpc.com/2014/02/11/kitchenpc-database-provisioning-101/

我成功引用并导入了所有 dll 及其命名空间:

import clr
clr.AddReference("System")

from System import *
from System.Reflection import *
from System.Reflection import Assembly

L4N = Assembly.LoadFrom('C://KitchenPC//DLL//log4net.dll')
clr.AddReference(L4N)

NU= Assembly.LoadFrom('C://KitchenPC//DLL//nunit.framework.dll')
clr.AddReference(NU)

LC= Assembly.LoadFrom('C://KitchenPC//DLL//Iesi.Collections.dll')
clr.AddReference(LC)

PGSQL = Assembly.LoadFrom('C://KitchenPC//DLL//Npgsql.dll')
clr.AddReference(PGSQL)

NH = Assembly.LoadFrom('C://KitchenPC//DLL//NHibernate.dll')
clr.AddReference(NH)

FNH = Assembly.LoadFrom('C://KitchenPC//DLL//FluentNHibernate.dll')
clr.AddReference(FNH)

KPC = Assembly.LoadFrom('C://KitchenPC//DLL//KitchenPC.dll')
clr.AddReference(KPC)

KPCDB = Assembly.LoadFrom('C://KitchenPC//DLL//KitchenPC.DB.dll')
clr.AddReference(KPCDB)

clr.AddReferenceToFileAndPath('C://KitchenPC//DLL//FluentNHibernate.dll')

from Npgsql import *
from log4net import *
from Iesi.Collections import *

from FluentNHibernate import *
from FluentNHibernate.Cfg import *
from FluentNHibernate.Cfg.Db import *

from NHibernate import *
from NHibernate.Cfg import Configuration

from KitchenPC import *
from KitchenPC.DB import *
from KitchenPC.Context import DBContext
from KitchenPC.DB import DatabaseAdapter

from NUnit.Framework import *

我可以像这样定义一个 PostgreSQLConfiguration:

connString = "Server=localhost;Port=5432;User Id=postgres;Password=password;Database=KPCSample"
# Context connected to local database
DBC = PostgreSQLConfiguration.PostgreSQL82.ConnectionString(connString).ShowSql()

但是当我尝试设置数据库适配器时:

DatabaseAdapter.Configure.DatabaseConfiguration( DBC )

我遇到了一个错误:

TypeError: expected IPersistenceConfigurer, got PostgreSQLConfiguration

奇怪的是instance(DBC, IPersistenceConfigurer)返回True,所以DBC确实是抽象类的一个实例IPersistenceConfigurerDatabaseAdapter 的子类。

这是我尝试从 C# 转置的原始代码示例:

// Context connected to local database
var dbConfig = Configuration.Build
.Context(DBContext.Configure
.Adapter(DatabaseAdapter.Configure
.DatabaseConfiguration(
PostgreSQLConfiguration.PostgreSQL82
.ConnectionString(@"Server=localhost;Port=5432;User Id=Website;Password=password;Database=KPCSample")
.ShowSql()
)
)
).Create();

// Context connected to local data store
var staticConfig = Configuration.Build
.Context(StaticContext.Configure
.DataDirectory(@"C:\KitchenPC\ConsoleTest\LocalStore\")
)
.Create();

这是来自 KitchenPC 的 DatabaseAdapter 类的示例:

/// <summary>A database adapter that uses NHibernate to connect to an underlying database.</summary>
public class DatabaseAdapter : IDBAdapter, IDisposable
{
ISessionFactory sessionFactory;
Configuration nhConfig;
readonly DatabaseAdapterBuilder builder;

public IPersistenceConfigurer DatabaseConfiguration { get; set; }
public List<IConvention> DatabaseConventions { get; set; }
public ISearchProvider SearchProvider { get; set; }

public static DatabaseAdapterBuilder Configure
{
get
{
return new DatabaseAdapter().builder;
}
}

DatabaseAdapter()
{
builder = new DatabaseAdapterBuilder(this);
}
}

在 Ironpython 中实例化 DatabaseAdapter 我做错了什么?

最佳答案

事实证明,我导入的方式不正确。

但基本上,导入应该是这样的:

import clr
import sys
sys.path.append(os.path.abspath('./DLL')) #where your dlls are
clr.AddReference('System')
clr.AddReference('FluentNHibernate')
from FluentNHibernate.Cfg.Db import PostgreSQLConfiguration

如果另一个 DLL 在 clr 中导入它,则不需要导入它。

关于c# - KitchenPC 和 Ironpython,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27804885/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com