我使用这种格式使用WCF进行JSON服务:
[OperationContract]
[ServiceKnownType(typeof(ComplexResult))]
[WebInvoke(
Method = "GET",
BodyStyle = WebMessageBodyStyle.Bare,
ResponseFormat = WebMessageFormat.Json)]
MyClass MyFunction(string myParams);
Run Code Online (Sandbox Code Playgroud)
这很有效,但它有一个限制.我不能忽略我正在序列化为JSON的类的属性.如果我使用JavaScriptSerializer类,那么我可以将[ScriptIgnore]属性放在我想忽略的属性上,并且它们不会在JSON中序列化,但是这不适用于上面的方法.
有没有办法使用ResponseFormat Json方法排除被序列化为JSON的类的属性?
我正在使用ZBar SDK在iPhone上读取QR码,但是我想在相机/扫描仪视图的底部添加一些文本,这些文本是用户的指导文本.这是我到目前为止:
UIView *cameraOverlayView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
cameraOverlayView.backgroundColor = [UIColor redColor];
UILabel *instructionLabel = [[UILabel alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
[instructionLabel setTextColor:[UIColor grayColor]];
[instructionLabel setBackgroundColor:[UIColor clearColor]];
[instructionLabel setFont:[UIFont fontWithName: @"Trebuchet MS" size: 24.0f]];
[instructionLabel setCenter:cameraOverlayView.center];
[cameraOverlayView addSubview:instructionLabel];
reader.cameraOverlayView = cameraOverlayView;
reader.wantsFullScreenLayout = YES;
[instructionLabel release];
[cameraOverlayView release];
Run Code Online (Sandbox Code Playgroud)
这是全班:
https://gist.github.com/4163761
不幸的是,标签没有显示.ZBar的文档说为了这个目的使用cameraOverlayView,但它似乎没有工作.
另外一点,我正在使用Titanium框架,因此这是额外的Titanium类所在的地方,但我的问题应该是针对ZBar的.
我正在尝试将Localytics SDK(通过他们的Xamarin组件)集成到我的Xamarin Android应用程序中.它在Debug模式下编译,但是如果我切换到Release版本,那么它在编译时出错:
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets:错误:执行任务LinkAssemblies时出错:错误XA2006:无法解析对'Android.Gms.Gcm.Iid.InstanceIDListenerService的引用'(在程序集中定义'LocalyticsXamarin.Android,Version = 4.2.0.29760,Culture = neutral,PublicKeyToken = null'),范围为'Xamarin.GooglePlayServices.Gcm,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null'.当范围与定义程序集不同时,通常意味着转发类型.(com.rpr.mobile.droid)
如果我只将Linker Behavior从Link SDK程序集切换到Do not link,那么它编译得很好,但这不是一个选项,因为那时apk太大了.如果我只切换回Link SDK程序集并将"LocalyticsXamarin.Android"添加到Ignore程序集列表中,它仍然会产生相同的编译错误.
此错误似乎意味着我的应用与Localytics Xamarin包装器之间的Google Play服务版本不匹配,但是他们向我发送了使用最新版本(42.1001.0)的包装器的更新版本,并且我已确认它与之匹配我们的应用.此外,他们自己的示例Android项目编译得很好.我已经梳理了他们的示例Android项目中的每个设置,并将其更改为与我的匹配,但仍然是他们编译而我的编译没有.
这是我的Android项目中的packages.config:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="modernhttpclient" version="2.4.2" targetFramework="MonoAndroid60" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="MonoAndroid60" />
<package id="Rx-Core" version="2.2.5" targetFramework="monoandroid70" />
<package id="Rx-Interfaces" version="2.2.5" targetFramework="monoandroid70" />
<package id="Rx-Linq" version="2.2.5" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="25.1.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Compat" version="25.1.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Core.UI" version="25.1.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Core.Utils" version="25.1.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Fragment" version="25.1.1" …Run Code Online (Sandbox Code Playgroud) 我试图在EditText控件中呈现一个html字符串.粗体,斜体和下划线html正确呈现,但是直接通过被忽略.
这是EditText控件,没什么特别的:
<EditText
android:id="@+id/rich_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Widget.EditText"
android:gravity="top"
android:inputType="textFilter|textMultiLine|textNoSuggestions"
android:minLines="8"
android:textStyle="normal" />
Run Code Online (Sandbox Code Playgroud)
以下是在EditText控件中设置html的代码:
var textView = view.FindViewById<EditText> (Resource.Id.rich_text);
var html = "<b>bold test</b> <u>underline test</u> <i>italic test</i> <strike>strike test 1</strike> <del>strike test 2</del> <s>strike test 3</s>";
textView.TextFormatted = Html.FromHtml (html);
Run Code Online (Sandbox Code Playgroud)
下面是它如何显示的屏幕截图,注意通过测试的罢工是如何工作的.
我有什么想法我做错了吗?
我们刚刚在Play商店中发布了新版本的Android应用,现在用户正在报告崩溃情况。我们能够复制,但是它在整个应用程序中随机发生,并且是SIGSEGV崩溃。
https://gist.github.com/justintoth/78abbd4b647de3ee04037631e921198f
根据回溯,最后两次崩溃似乎都与图像视图有关。
崩溃#1:
A / DEBUG(6953):#00 pc 000c1178 /system/lib/libandroid_runtime.so 04-13 17:26:53.640:A / DEBUG(6953):#01 pc 020813ce / system / framework / x86 / boot-framework。燕麦(偏移量0x1588000)(android.view.RenderNode.nGetTransformMatrix + 138)04-13 17:26:53.640:A / DEBUG(6953):#02 pc 020845cd /system/framework/x86/boot-framework.oat(偏移量0x1588000)(android.view.RenderNode.getMatrix + 89)04-13 17:26:53.640:A / DEBUG(6953):#03 pc 020082dd /system/framework/x86/boot-framework.oat(偏移量0x1588000)( android.view.View.getMatrix + 89)04-13 17:26:53.640:A / DEBUG(6953):
04 pc 02061f2b /system/framework/x86/boot-framework.oat(offset 0x1588000)(android.view.ViewGroup.invalidateChild + 119)04-13
17:26:53.640:A / DEBUG(6953):#05 pc 0200bda1 /system/framework/x86/boot-framework.oat(offset 0x1588000)(android.view.View.invalidateInternal + 541)04-13 17:26 :53.640:A / DEBUG(6953):#06 pc 0200ba3b /system/framework/x86/boot-framework.oat(offset 0x1588000)(android.view.View.invalidate + 103)04-13 17:26:53.640: A /调试(6953):
07 pc 0200b822 /system/framework/x86/boot-framework.oat(offset 0x1588000)(android.view.View.invalidate …
我正在抓一个网站,在html中它有一个日期格式如下:
"date":"\/Date(1184050800000-0700)\/"
Run Code Online (Sandbox Code Playgroud)
如果这是在javascript中,它将是一个日期对象,我可以使用它的方法以我喜欢的任何格式检索数据.但是,我正在使用C#应用程序进行抓取.有谁知道这种格式是什么?它是特定日期之后的总秒数吗?我需要一种方法将其转换为C#datetime对象.
我正在使用MongoDB的C#驱动程序,并且我试图让Query.Near工作以在中心点的5,10,25或50英里内返回待售房屋.这是查询:
var near = Query.Near("Coordinates", coordinates.Latitude, coordinates.Longitude, find.GetRadiansAway(), false);
//var near = Query.WithinCircle("Coordinates", coordinates.Latitude, coordinates.Longitude, find.GetRadiansAway(), false);
var query = Collection().Find(near);
query.Limit = 1000;
var listings = query.ToList();
Run Code Online (Sandbox Code Playgroud)
我将里程半径除以62.1868289以获得弧度并将其输入到查询中,但无论我传递的是什么弧度值,它都会返回相同数量的待售房屋.我也尝试将球形参数设置为true和使用Query.WithinCircle,但是它们都不会更好.
我正在使用最新的C#驱动程序(1.0.0.4098),这是C#驱动程序中的一个错误,MongoDB中的错误,还是我在这里遗漏了什么?
以下是查询的外观:
5英里(近):
db.Listing.find({ "Coordinates" : { "$near" : [39.4812172, -76.6438598], "$maxDistance" : 0.072463768115942032 } });
Run Code Online (Sandbox Code Playgroud)
10英里(近):
db.Listing.find({ "Coordinates" : { "$near" : [39.4812172, -76.6438598], "$maxDistance" : 0.14492753623188406 } });
Run Code Online (Sandbox Code Playgroud)
5英里远(近球形):
db.Listing.find({ "Coordinates" : { "$nearSphere" : [39.4812172, -76.6438598], "$maxDistance" : 0.0012629451881788331 } });
Run Code Online (Sandbox Code Playgroud)
10英里远(近球形):
db.Listing.find({ "Coordinates" : { "$nearSphere" : …Run Code Online (Sandbox Code Playgroud) 我有一个 MongoDB 聚合管道,其中包含许多步骤(匹配索引字段、添加字段、排序、折叠、再次排序、页面、项目结果。)如果我注释掉除第一个匹配步骤之外的所有步骤,查询执行速度超快(0.075 秒),因为它利用了正确的索引。但是,如果我随后尝试执行任何后续步骤,即使是获取结果计数这样简单的操作,查询也会开始花费 27 秒!!!
这是查询:(不要太在意它的复杂性,因为索引正在快速执行它的工作......)
db.runCommand({
aggregate: 'ResidentialProperty',
allowDiskUse: false,
explain: false,
cursor: {},
pipeline:
[
{
"$match" : {
"$and" : [
{
"CountyPlaceId" : 20006073
},
{
"$or" : [
{
"$and" : [
{
"ForSaleGroupId" : {
"$in" : [
2,
3
]
}
},
{
"$or" : [
{
"ForSaleGroupId" : {
"$nin" : [
2,
3
]
}
},
{
"ListDate" : {
"$gte" : ISODate("2019-02-21T00:00:00.000Z")
}
}
]
},
{
"$or" : …Run Code Online (Sandbox Code Playgroud) 在启动我的 ASP.NET Core Web 应用程序(使用 IdentityServer 4)时,在 ConfigureServices 方法中,我注册了想要通过 OAuth2 和 OIDC 启用 SSO 的外部身份提供程序。
services
.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = authenticationScheme;
options.DefaultScheme = authenticationScheme;
})
.AddOAuthSsoIdentityProviders(ssoIdentityProviders);
internal static AuthenticationBuilder AddOAuthSsoIdentityProviders(this AuthenticationBuilder authenticationBuilder, List<IdentityProvider> ssoIdentityProviders)
{
var oAuthSsoIdentityProviders = ssoIdentityProviders
.Where(idp => idp.SsoFlowType == SsoFlowType.Oidc || idp.SsoFlowType == SsoFlowType.OAuth2)
.ToList();
foreach (var ssoIdentityProvider in oAuthSsoIdentityProviders)
{
switch (ssoIdentityProvider.SsoFlowType)
{
case SsoFlowType.Oidc:
authenticationBuilder.AddOpenIdConnect(ssoIdentityProvider.SsoCode, options => SetOidcOptions(ssoIdentityProvider, options));
break;
case SsoFlowType.OAuth2:
authenticationBuilder.AddOAuth(ssoIdentityProvider.SsoCode, options => SetOAuth2Options(ssoIdentityProvider, options));
break;
}
}
return authenticationBuilder;
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试设置一个wcf服务,以便在IIS 7上使用net.tcp.
这是我得到的错误:
在net.tcp://127.0.0.1:8000/ListingService中没有可以接受该消息的端点监听.这通常是由错误的地址或SOAP操作引起的.有关更多详细信息,请参阅InnerException(如果存在).
这是我从客户端调用的代码:
using (var client = new ListingServiceClient("NetTcpBinding"))
{
client.Test();
client.Close();
}
Run Code Online (Sandbox Code Playgroud)
这是我的服务web.config - http://pastebin.com/3S8BZbup
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding portSharingEnabled="true">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="default">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<!--throttle service-->
<serviceThrottling
maxConcurrentCalls="10000"
maxConcurrentSessions="10000"
maxConcurrentInstances="10000" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="default" name="Housters.Services.ListingService">
<endpoint name="TcpEndpoint"
address="net.tcp://127.0.0.1:8000/ListingService"
binding="netTcpBinding"
contract="Housters.Services.IListingService" />
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
这是我的客户端app.config - http://pastebin.com/YpiAhh46
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding">
<security mode="None"/>
</binding>
</netTcpBinding>
</bindings> …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用C#抓取网页,但是在页面加载后,它会执行一些JavaScript,从而将更多元素加载到需要抓取的DOM中。标准的抓取工具只是在加载时抓取页面的html,而不会提取通过javascript进行的DOM更改。我该如何放置某种功能以等待一两秒钟,然后获取源代码?
这是我当前的代码:
private string ScrapeWebpage(string url, DateTime? updateDate)
{
HttpWebRequest request = null;
HttpWebResponse response = null;
Stream responseStream = null;
StreamReader reader = null;
string html = null;
try
{
//create request (which supports http compression)
request = (HttpWebRequest)WebRequest.Create(url);
request.Pipelined = true;
request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
if (updateDate != null)
request.IfModifiedSince = updateDate.Value;
//get response.
response = (HttpWebResponse)request.GetResponse();
responseStream = response.GetResponseStream();
if (response.ContentEncoding.ToLower().Contains("gzip"))
responseStream = new GZipStream(responseStream, CompressionMode.Decompress);
else if (response.ContentEncoding.ToLower().Contains("deflate"))
responseStream = new DeflateStream(responseStream, CompressionMode.Decompress);
//read html.
reader = new …Run Code Online (Sandbox Code Playgroud) 我有一个网站表,其中有一个客户表的外键.网站并不总是会有一个关联的客户端,但是当我在没有指定客户端的情况下保存网站时,它会出错,因为Website.ClientID是一个int32(不可为空)并且设置为0.
我尝试将我的EF图中的关系更改*为网站的旁边和客户端旁边的0..1然后它给出一个错误,说它不能为ClientID做0..1,因为它不可为空.然后我将Website.ClientID更改为可为空,但现在它给出了此错误:
TothSolutions.msl(69,10) : error 3031: Problem in mapping fragments starting
at line 69:Non-nullable column Website.ClientID in table Website is mapped to
a nullable entity property.
Run Code Online (Sandbox Code Playgroud)
如何设置依赖对象可以为空的外键关系?
我试图动态地使用反射做一个OrderBy是否给定的sortColumn(串)为空或不是,一ThenBy对sortColumn价值和ThenBy对硬编码列。像这样:
if (!String.IsNullOrEmpty(sortColumn)) {
var descending = sortDirection == "desc";
views = views.AsQueryable()
.OrderByNull<ToDoView>(sortColumn, true) // extension method
.OrderBy<ToDoView>(sortColumn, descending, true) // extension method
.ThenBy(v => v.summary ?? v.description).ToList();
}
Run Code Online (Sandbox Code Playgroud)
使用其他 SO 答案,我能够使OrderBy扩展方法起作用:
public static IOrderedQueryable<TEntity> OrderBy<TEntity>(this IQueryable<TEntity> source,
string orderByProperty, bool desc, bool thenBy = false) {
string command = desc ? "OrderByDescending" : "OrderBy";
if (thenBy)
command = desc ? "ThenByDescending" : "ThenBy";
var type = …Run Code Online (Sandbox Code Playgroud) c# ×5
xamarin ×3
android ×2
mongodb ×2
wcf ×2
asp.net-core ×1
c#-4.0 ×1
date ×1
datetime ×1
ios ×1
javascript ×1
json ×1
linq ×1
nullable ×1
reflection ×1
titanium ×1
web-scraping ×1
zbar ×1
zbar-sdk ×1