我正在尝试以下列方式序列化Type对象:
Type myType = typeof (StringBuilder);
var serializer = new XmlSerializer(typeof(Type));
TextWriter writer = new StringWriter();
serializer.Serialize(writer, myType);
Run Code Online (Sandbox Code Playgroud)
当我这样做时,对Serialize的调用会引发以下异常:
"不期望使用System.Text.StringBuilder类型.使用XmlInclude或SoapInclude属性指定静态未知的类型."
有没有办法让我序列化Type对象?请注意,我不是要尝试序列化StringBuilder自身,而是Type包含有关StringBuilder类的元数据的对象.
我试图IOBluetooth framework在OS X 10.8.2上使用连接蓝牙手机模拟计算机作为免提设备.我可以成功与手机建立连接,手机可以将连接识别为连接到手机的HandsFree.但是当我尝试使用手机拨打电话并想要将音频发送到mac(通过选择来源作为免提)时,音频永远不会到达计算机.
此时蓝牙框架尝试打开SCO Audio connection设备,但连接建立从未成功,我得到0x0DscoConnectionOpened状态的错误代码状态代码.
我正在使用IOBluetoothAddSCOAudioDevice功能将SCO音频设备连接到蓝牙设备,它总是成功的.
//btDevice is paired
res=IOBluetoothAddSCOAudioDevice((IOBluetoothDeviceRef) btDevice,NULL);
if(res != kIOReturnSuccess)
{
self.error.title = [NSString stringWithFormat:
@"Could not attach the Audio device. Try paring device again"];
}
Run Code Online (Sandbox Code Playgroud)
控制台日志说
24/11/2012 4:02:13.000 PM kernel [0]:[SendHCIRequestFormatted] ### ERROR:[0x0428](设置同步连接) - 发送请求失败(错误= 0x000D(kBluetoothHCIErrorHostRejectedLimitedResources))
24/11/2012 4:02:13.000 PM内核[0]:REQUIRE_NO_ERR失败:0xd - 文件:/SourceCache/IOBluetoothFamily_kexts/IOBluetoothFamily-4090.4.33/Core/Family/Drivers/IOBluetoothSCOAudioDriver/IOBluetoothSCOAudioDevice.cpp:872
虽然控制台日志说有限的资源,但我尝试了多个电池充满电池.
我对此感到难过,只是想我是否需要做任何特殊或不同的事情?
在此先感谢您的帮助.
OAuth 2规范让我相信"资源服务器"和"授权服务器"不一定必须是同一个应用程序,但我正在努力弄清楚这在实践中是如何实际实现的.
例如,假设存在以下应用程序:
场景#1:登录Web前端
场景#2:授权第三方应用
我理解的部分是如何在方案#2中显示允许/拒绝表单之前验证用户.用户可能登录到主Web应用程序,但是auth服务不知道这一点,并且会以某种方式再次需要对用户进行身份验证.auth服务是否也需要支持登录/会话?
我想知道web应用程序是否更有意义负责显示允许/拒绝表单有两个原因:
这是方案#2的一种可能的替代方案:
处理这个问题的最佳方法是什么?任何一般性意见,建议等都会很棒!
谢谢
我已经在SO上查看了使用键值观察的示例NSArray(或者NSMutableArray),显然你需要使用NSArrayController(不像KVO我不熟悉的),但我没有找到如何执行此操作的具体示例.有人可以解释一些示例代码吗?
例如,如果我有一个GameModel代表其播放器名称NSArray (playerNameArray)的a NSStrings.我想观察那些字符串(视图控制器观察模型的数据)来更新视图中的各种内容.
如何获得播放器名称数组已更改的通知?
编辑:iOS SDK甚至支持NSArrayController吗?如果没有,还有另一种方式吗?
iphone objective-c key-value-observing nsarray nsarraycontroller
我刚开始研究Dapper.我正在测试它并能够做基本的CRUD,我的基本意思是在这个结构的类上工作:
public class Product {
public int Id {get;set;}
public string Name {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
现在我正在寻找能够更容易地进行插入和更新的东西,并找到了Dapper.Rainbow.我检查了它,并能够使用它来获取和插入对象,如上所述.我的问题是,当Product有导航属性时,我不能在该字段上插入.所以,如果我有这个:
public class Product {
public int Id {get;set;}
public string Name {get;set;}
public ProductCategory Category {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
我将无法做到这一点:
// connection is a valid and opened connection
var db = TestDatabase.Init(connection , 300);
var newId = db.Products.Insert(newProduct);
Run Code Online (Sandbox Code Playgroud)
因为这个原因:
The member Category of type ProductCategory cannot be used as a parameter value
Run Code Online (Sandbox Code Playgroud)
如果我Category用type 替换int(数据库中的相同数据类型),则可以解决该问题.但是,如果我这样做,我将无法使用其类别信息查询产品,而不仅仅是(类别)ID.
因此,如果不使用原始Dapper,如何使用具有导航属性的类进行插入和更新?我希望我可以执行以下操作并告诉Dapper.Rainbow Category在插入或更新时忽略.
public class Product { …Run Code Online (Sandbox Code Playgroud) 我遇到了与此处描述的问题相同的问题,我的设置几乎完全相同,实际上是基于本指南.当我在我的控制器中访问一个方法时,我得到了这个
尝试创建"TestController"类型的控制器时发生错误.确保控制器具有无参数的公共构造函数.
这是堆栈跟踪
at System.Web.Http.Dispatcher.DefaultHttpControllerActivator
.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor,
Type controllerType)\r\n
at System.Web.Http.Controllers.HttpControllerDescriptor
.CreateController(HttpRequestMessage request)\r\n
at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()
Run Code Online (Sandbox Code Playgroud)
这是内部异常的堆栈跟踪
at System.Linq.Expressions.Expression.New(Type type)\r\n
at System.Web.Http.Internal.TypeActivator.Create[TBase](Type instanceType)\r\n
at System.Web.Http.Dispatcher.DefaultHttpControllerActivator
.GetInstanceOrActivator(HttpRequestMessage request, Type controllerType, Func`1& activator)\r\n
at System.Web.Http.Dispatcher.DefaultHttpControllerActivator
.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
Run Code Online (Sandbox Code Playgroud)
这是我的控制器的样子
public class TestController : ApiController
{
private readonly ITestRepo _repo;
public TestController(ITestRepo repo)
{
_repo = repo;
}
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
public string Get(int …Run Code Online (Sandbox Code Playgroud) 我正在镜像一些内部网站以备份.截至目前我基本上使用这个c#代码:
System.Net.WebClient client = new System.Net.WebClient();
byte[] dl = client.DownloadData(url);
Run Code Online (Sandbox Code Playgroud)
这基本上只是将html下载到一个字节数组中.这就是我要的.然而问题是html中的链接大多数时间是相对的,而不是绝对的.
我基本上想要在相对链接之前附加任何完整的http://domain.is,以将其转换为将重定向到原始内容的绝对链接.我基本上只关心href =和src =.是否有正则表达式将涵盖一些基本情况?
编辑[我的尝试]:
public static string RelativeToAbsoluteURLS(string text, string absoluteUrl)
{
if (String.IsNullOrEmpty(text))
{
return text;
}
String value = Regex.Replace(
text,
"<(.*?)(src|href)=\"(?!http)(.*?)\"(.*?)>",
"<$1$2=\"" + absoluteUrl + "$3\"$4>",
RegexOptions.IgnoreCase | RegexOptions.Multiline);
return value.Replace(absoluteUrl + "/", absoluteUrl);
}
Run Code Online (Sandbox Code Playgroud) 鉴于以下两个实体
public class Customer
{
public Customer()
{
Orders = new List<Orders>();
}
public int CustomerId { get; set; }
public string CustomerName { get; set; }
public List<Orders> Orders { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
和
public class Orders
{
public int OrderId { get; set; }
public int CustomerId { get; set; }
public int Quantity { get; set; }
public string OrderDescription { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
以下代码
string sql = @"
select c.CustomerId, c.CustomerName, o.OrderId as OrderId, …Run Code Online (Sandbox Code Playgroud) 我有以下重写规则,在IIS7上运行的常规asp.net项目上完全正常.
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
</rule>
Run Code Online (Sandbox Code Playgroud)
因此,在http访问时,我们的一个页面://{domain}/aboutus将重定向到https://{domain}/aboutus.现在在Umbraco站点中放置相同的重写规则会导致无限循环.我们的Umbraco网站没有任何其他重写规则.这让我觉得Umbraco有点劫持从http到https的路由并导致无限循环.我们缺少什么?
我在mvc 4.0中创建一个Web应用程序,我需要使用Asp.netWeb站点管理工具启用成员资格和授权,但是当我点击安全选项卡时它会给我一个错误
您选择的数据存储存在问题.这可能是由无效的服务器名称或凭据或权限不足引起的.它也可能是由未启用角色管理器功能引起的.单击下面的按钮可重定向到可以选择新数据存储的页面.以下消息可能有助于诊断问题:无法连接到SQL Server数据库.
我的连接字符串如下
<connectionStrings>
<add name="MusicStoreEntities"
connectionString="Data Source=|DataDirectory|MvcMusicStore.sdf"
providerName="System.Data.SqlClient"/>
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
我无法在代码中发现任何错误,所以请帮助我