我有一个自定义相机在某些设备上工作正常.它适用于三星Galaxy Gran Duos(三星-gt i9082,Android 4.2.2)但是当我尝试捕捉图像时,我之前放大了,它冻结了,没有崩溃,唯一的出路就是按下返回键.这只发生在三星Galaxy Gran Duos上.
我用来拍照的代码:
Camera.PictureCallback photoCallback = new Camera.PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
try {
} catch (Exception e) {
if (flePicture== null){
Log.d("camera", "Error creating media file, check storage permissions: " +
e.getMessage());
return;
}
}
try {
FileOutputStream fos = new FileOutputStream(flePicture);
fos.write(data);
fos.close();
} catch (FileNotFoundException e) {
Log.d("camera", "File not found: " + e.getMessage());
} catch (IOException e) {
Log.d("camera", "Error accessing file: " + e.getMessage());
}
} …
Run Code Online (Sandbox Code Playgroud) 我正在尝试根据状态渲染多个子组件但是我只能返回一个子组件(SyntaxError:相邻的JSX元素必须包装在一个封闭的标记中)
每个子组件都传递相同的道具,这些代码怎么能保持干燥?
作品
export default ({changeState, myState, handleClick}) => (
<Navigation>
<span>Navigation</span>
<button onClick={() => changeState()}>Navigation</button>
{ myState ?
<NavigationItem handleClick={handleClick} title={'#Link-1'} />
: null
}
</Navigation>
)
Run Code Online (Sandbox Code Playgroud)
别
export default ({changeState, myState, handleClick}) => (
<Navigation>
<h1>Navigation</h1>
<button onClick={() => changeState()}>Navigation</button>
{ myState ?
<NavigationItem handleClick={handleClick} title={'#Link-1'} />
<NavigationItem handleClick={handleClick} title={'#Link-2'} />
<NavigationItem handleClick={handleClick} title={'#Link-3'} />
: null
}
</Navigation>
)
Run Code Online (Sandbox Code Playgroud) 考虑:
enum Foo
{
Bar,
Quux,
}
void Main()
{
var enumValues = new[] { Foo.Bar, Foo.Quux, };
Console.WriteLine(enumValues.GetType()); // output: Foo[]
Console.WriteLine(enumValues.First().GetType()); // output: Foo
var intValues = enumValues.Cast<int>();
Console.WriteLine(intValues.GetType()); // output: Foo[] ???
Console.WriteLine(intValues.First().GetType()); // output: Int32
Console.WriteLine(ReferenceEquals(enumValues, intValues)); // true
var intValuesArray = intValues.ToArray();
Console.WriteLine(intValuesArray.GetType()); // output: Int32[]
Console.WriteLine(intValuesArray.First().GetType()); // output: Int32
Console.WriteLine(ReferenceEquals(intValues, intValuesArray)); // false
}
Run Code Online (Sandbox Code Playgroud)
注意第三个Console.WriteLine
-我期望它打印出将要转换为数组的类型(Int32[]
),但是它将打印原始类型(Foo[]
)!并ReferenceEquals
确认确实,第一个Cast<int>
电话实际上是无人接听。
因此,我查看了以下内容的来源,Enumerable.Cast
并发现了以下内容:
public static IEnumerable<TResult> Cast<TResult>(this IEnumerable …
Run Code Online (Sandbox Code Playgroud) 我已将我的应用程序迁移到 .Net 8,并使用 ubuntu 22.04.3 LTS VPS 来托管我的 Web 应用程序。
我正在尝试在 VPS 上安装 .net 8,但无法安装
我已经尝试过微软的脚本安装,但没有成功
我已经尝试过microsoft 的Debian 安装,但没有成功
当我运行 ubuntu 的基本命令时
sudo apt-get update && \
sudo apt-get install -y dotnet-sdk-8.0
Run Code Online (Sandbox Code Playgroud)
即使更新和升级 ubuntu 后,我也会遇到以下错误
public IEnumerable<ModuleData> ListModules()
{
foreach (XElement m in Source.Descendants("Module"))
{
yield return new ModuleData(m.Element("ModuleID").Value);
}
}
Run Code Online (Sandbox Code Playgroud)
最初上面的代码很棒,因为如果不需要,就不需要评估整个集合.
但是,一旦枚举了所有模块,在没有更改时重复查询XDocument会变得更加昂贵.
因此,作为绩效改进:
public IEnumerable<ModuleData> ListModules()
{
if (Modules == null)
{
Modules = new List<ModuleData>();
foreach (XElement m in Source.Descendants("Module"))
{
Modules.Add(new ModuleData(m.Element("ModuleID").Value, 1, 1));
}
}
return Modules;
}
Run Code Online (Sandbox Code Playgroud)
如果我反复使用整个列表,那就太好了,但不是那么好.
是否存在中间点,我可以在整个列表被迭代之前返回,然后缓存它并将缓存提供给后续请求?
我的主机中有以下app.config:
<services>
<service name="DCC_Service.DCCService" behaviorConfiguration="serviceBehavior">
<endpoint binding="netNamedPipeBinding" contract="DCC_Service.IDCCService" address="DCCService" />
<endpoint binding="mexNamedPipeBinding" contract="IMetadataExchange" address="mex" />
<host>
<baseAddresses>
<add baseAddress="net.pipe://localhost/"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata httpGetEnabled="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
Run Code Online (Sandbox Code Playgroud)
如何将netNamedPipeBinding超时设置为无限又名Timespan.MaxValue
?
泛型类中的静态字段将为每个泛型参数组合具有单独的值.因此它可以用作Dictionary <Type,无论 >
这是不是一个静态的字典更好或更坏<类型,无论 >?
换句话说,哪些实现更有效?
public static class MethodGen<TParam> {
public static readonly Action<TParam> Method = CreateMethod();
static Action<TParam> CreateMethod() { /*...*/ }
}
Run Code Online (Sandbox Code Playgroud)
要么,
public static class MethodGen {
static readonly Dictionary<Type, Delegate> methods
= new Dictionary<Type, Delegate>();
public static Action<T> GetMethod<T>() {
//In production code, this would ReaderWriterLock
Delegate method;
if(!methods.TryGetValue(typeof(T), out method)
methods.Add(typeof(t), method = CreateMethod<T>());
return method;
}
static Action<T> CreateMethod<T>() { /*...*/ }
}
Run Code Online (Sandbox Code Playgroud)
特别是,CLR如何通过泛型类型参数查找静态字段?
我有一个如下所示的WCF DataContract
:
namespace MyCompanyName.Services.Wcf
{
[DataContract(Namespace = "http://mycompanyname/services/wcf")]
[Serializable]
public class DataContractBase
{
[DataMember]
public DateTime EditDate { get; set; }
// code omitted for brevity...
}
}
Run Code Online (Sandbox Code Playgroud)
当我在Visual Studio中添加对此服务的引用时,将生成此代理代码:
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.3082")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://mycompanyname/services/wcf")]
public partial class DataContractBase : object, System.ComponentModel.INotifyPropertyChanged {
private System.DateTime editDateField;
private bool editDateFieldSpecified;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order=0)]
public System.DateTime EditDate {
get {
return this.editDateField;
}
set {
this.editDateField = value;
this.RaisePropertyChanged("EditDate");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool EditDateSpecified { …
Run Code Online (Sandbox Code Playgroud) 我目前配置了静态和动态压缩.静态压缩正在工作,但是当通过YSlow和Fiddler检查时,动态压缩不起作用.
在我的applicationHost.config中,我有以下设置:
<urlCompression doStaticCompression="true" doDynamicCompression="true"
dynamicCompressionBeforeCache="true" />
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files"
maxDiskSpaceUsage="100" minFileSizeForComp="256">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll"
dynamicCompressionLevel="1" />
<dynamicTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="*/*" enabled="true" />
</dynamicTypes>
<staticTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="application/atom+xml" enabled="true" />
<add mimeType="application/xaml+xml" enabled="true" />
<add mimeType="*/*" enabled="true" />
</staticTypes>
</httpCompression>
<serverRuntime frequentHitThreshold="1" frequentHitTimePeriod="01:00:00" />
Run Code Online (Sandbox Code Playgroud)
我的web.config有:
<urlCompression doStaticCompression="true"
doDynamicCompression="true" dynamicCompressionBeforeCache="true" />
Run Code Online (Sandbox Code Playgroud)
这些模块已经安装,当我使用Failed Request Trace时,我得到了几个动态压缩命中,但没有成功或失败.只是这些类型的结果:
ModuleName DynamicCompressionModule
Notification …
Run Code Online (Sandbox Code Playgroud) 在我们基于ASP.NET Core的Web应用程序中,我们需要以下内容:某些请求的文件类型应该获得自定义ContentType的响应.例如.map
应该映射到application/json
.在"完整"的ASP.NET 4.x中,与IIS结合使用,可以使用web.config <staticContent>/<mimeMap>
,我希望用自定义的ASP.NET Core中间件替换此行为.
所以我尝试了以下(简化为简洁):
public async Task Invoke(HttpContext context)
{
await nextMiddleware.Invoke(context);
if (context.Response.StatusCode == (int)HttpStatusCode.OK)
{
if (context.Request.Path.Value.EndsWith(".map"))
{
context.Response.ContentType = "application/json";
}
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,尝试context.Response.ContentType
在调用其余的中间件链后设置会产生以下异常:
System.InvalidOperationException: "Headers are read-only, response has already started."
Run Code Online (Sandbox Code Playgroud)
如何创建解决此要求的中间件?
c# ×5
.net ×3
wcf ×2
.net-8.0 ×1
android ×1
asp.net ×1
asp.net-core ×1
blazor ×1
camera ×1
clr ×1
compression ×1
dictionary ×1
dynamic ×1
freeze ×1
generics ×1
http ×1
ienumerable ×1
iis-7 ×1
javascript ×1
linq ×1
reactjs ×1
return ×1
ubuntu ×1
wcf-binding ×1
yield ×1