我正在编写一个.NET Web应用程序,管理员可以在其中自定义呈现给用户的各种数据输入表单.管理员可以创建和自定义大约六种不同的字段类型(即文本,数字,下拉列表,文件上载).所有字段共享一组基本属性/行为(是否需要该字段?它是否具有默认字段值?).还有一系列字段特定的属性/行为(即下拉列表具有数据源属性,但文本字段不具有).为简单起见,我将遗漏问题域的许多其他特征.
类层次结构很简单:一个抽象的超类,它封装了常见的行为/属性,以及大约六个处理字段特定内容的具体子类.
每个字段类型都呈现(即映射到)作为特定类型的.NET服务器控件,所有这些都派生自System.Web.UI.Control.
我创建了以下代码来映射字段域对象及其相应的UI控件之间的值:
public static void Bind(Control control, IList<DocumentFieldBase> fieldBaseList)
foreach (DocumentFieldBase fieldBase in fields){
if (typeof (DocumentFieldText).IsInstanceOfType(fieldBase)){
TextBox textbox = (TextBox) control;
textbox.Text = (fieldBase as DocumentFieldText).GetValue();
}
if (typeof (DocumentFieldDropDown).IsInstanceOfType(fieldBase)){
DropDown dropDown= (DropDown) control;
dropDown.Text = (fieldBase as DocumentFieldSelectOne).GetValue().Text;
dropDown.DataSource= (fieldBase as DocumentFieldSelectOne).DataSource;
dropDown.Id= (fieldBase as DocumentFieldSelectOne).GetValue().Id;
}
//more if statements left out for brevity
}
}
Run Code Online (Sandbox Code Playgroud)
如果执行类型检查的语句,我想抛弃那些不敬虔的人.我正在拍摄的方法是使用子类输入为每个字段/控件组合创建一个方法重载.例如:
public static void Bind(TextBox control, DocumentFieldText fieldText){
//some implementation code
}
public static void Bind(DropDown control, DocumentFieldDropDown fieldDropDown){ …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种方法来添加一个EventListener,它会在第一次触发后自动删除它,但我无法想办法按照我想要的方式执行此操作.
我找到了这个功能(这里):
public class EventUtil
{
public static function addOnceEventListener(dispatcher:IEventDispatcher,eventType:String,listener:Function):void
{
var f:Function = function(e:Event):void
{
dispatcher.removeEventListener(eventType,f);
listener(e);
}
dispatcher.addEventListener(eventType,f);
}
}
Run Code Online (Sandbox Code Playgroud)
但不必写:
EventUtil.addOnceEventListener( dispatcher, eventType, listener );
Run Code Online (Sandbox Code Playgroud)
我想以通常的方式使用它:
dispatcher.addOnceEventListener( eventType, listener );
Run Code Online (Sandbox Code Playgroud)
有没有人知道如何做到这一点?
任何帮助都会非常感激.
我有一个对象o,其保证在运行时是三种类型之一A,B或者C,所有这些实现公共接口的I.我可以控制I,但不能A,B或C.(因此我可以使用空标记接口,或者通过使用接口以某种方式利用类型中的相似性,但我无法添加新方法或更改类型中的现有方法.)
我也有一系列的方法MethodA,MethodB和MethodC.o查找运行时类型,然后将其用作这些方法的参数.
public void MethodA(A a) { ... }
public void MethodB(B b) { ... }
public void MethodC(C c) { ... }
Run Code Online (Sandbox Code Playgroud)
使用此策略,现在必须对类型执行检查o以确定应调用哪个方法.相反,我想简单地有三个重载方法:
public void Method(A a) { ... } // these are all overloads of each other
public void Method(B b) { ... }
public void Method(C c) { ... …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 chrome 中发送轮子事件,但仍然无法成功。我正在使用 WheelEvent 对象,但似乎无法正确“初始化”它。无论我做什么,delta 总是 0。我查看了规范,但没有帮助。更有趣的是,当我实际用鼠标滚轮滚动并尝试调度该事件时,我捕获了该事件,但增量再次为 0。有人遇到过这样的问题吗?这可能是一个错误吗?任何帮助都会很棒!
//dispatching the wheel event
var evt = document.createEvent("WheelEvent");
evt.initEvent("mousewheel", true, true, null, 0, 0, 0, 0, 0, false, false, false, false, 0, null, -120);
window.dispatchEvent(evt)
// catching the wheel event
window.addEventListener('mousewheel', callback, true);
callback = function(evt){
console.log(evt)
}
Run Code Online (Sandbox Code Playgroud) 正如Apple的文档所说,dispatch_get_global_queue()是并发队列,dispatch_sync是串行的意思.那么任务是处理异步还是同步?
我对前台调度行为有一个恼人的问题。有时onNewIntent()它会完全重新创建 Activity而不是调用,这会破坏应用程序的工作流程。
我的具体情况:Activity A是MainActivity,使用前台调度。一切正常。但是,在我从浏览器启动的活动 B(VIEW 操作)中,前台调度在某些情况下不再起作用。
工作流程:
我启动 MainActivity,切换到浏览器(不关闭 MainActivity),启动 Activity B 并连接我的 NFC 设备 --> 它创建了一个新的 Activity B。
我启动 MainActivity 并再次关闭它。之后我切换
到浏览器,启动活动 B 并连接我的 NFC 设备 --> 一切正常onNewIntent()
代码是正确的,例如,如果我在第一个场景中两次连接 NFC 设备,它会在第二次正常工作,但在第一次不正常。在 MainActivity 和活动 BI 中明确调用活动的 onPause() 方法中的 disableForegroundDispatch() 方法。
我的具体问题有解决方案吗?对我来说,这听起来像是一个错误。
编辑:
public void resume(Activity targetActivity) {
if (nfc != null && nfc.isEnabled()) {
// nfc is the default NFC adapter and never null on my devices
Intent intent = new Intent(targetActivity, targetActivity.getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = …Run Code Online (Sandbox Code Playgroud) 我在我的iOS应用中集成了Google Analytics iOS SDK,我想设置一个较长的调度间隔,以避免频繁的网络呼叫.我想设置6小时或更长的间隔.
// set Google Analytics dispatch interval, eg: 20 seconds
[GAI sharedInstance].dispatchInterval = 6*60*60; // dispatch after every 6 hours
Run Code Online (Sandbox Code Playgroud)
我几乎没有疑问:
Q1.如果App在调度数据之前被杀死会发生什么,下次启动应用程序时会立即发送数据吗?(例如:app在发送间隔前几分钟被杀死).
Q2.我们假设应用程序尝试在6小时后发送数据,但当时网络不可用.数据将在接下来的6个小时后再次发送,作为12小时数据的汇总数据?
有关优化方法的任何建议吗?我不希望每隔几秒钟或几分钟就消耗网络带宽,仅用于次要数据.
是否有一种优雅的方法来获取具有(单个)动态调度的OO语言中具有2个参数(或更多参数)的方法的多个调度?
可能的问题示例:
这是一个受Java启发的示例。(问题与语言无关!)
// Visitable elements
abstract class Operand {
}
class Integer extends Operand {
int value;
public int getValue() {
return value;
}
}
class Matrix extends Operand {
int[][] value;
public int[][] getValue() {
return value;
}
}
// Visitors
abstract class Operator {
// Binary operator
public Operand eval(Operand a, Operand b) {
return null; // unknown operation
}
}
class Addition extends Operator {
public Operand eval(Integer a, Integer b) {
return new Integer(a.getValue() …Run Code Online (Sandbox Code Playgroud) 我想在不同的场合分派 CustomEvent。网络上的大多数示例只创建和分派 CustomEvents 一次。我想知道如何正确地做到这一点。
在这个例子中,“A-Button”一遍又一遍地分派相同的事件。“B-Button”new CustomEvent每次创建一个,应该调度事件。
var targetA = document.getElementById('targetA');
var targetB = document.getElementById('targetB');
var evtA = new CustomEvent("myEvent");
function a(){
targetA.dispatchEvent(evtA);
}
function b(){
targetB.dispatchEvent(new CustomEvent("myOtherEvent"));
}
targetA.addEventListener("myEvent", function(e){
console.log(e);
console.log(e.timeStamp);
});
targetB.addEventListener("myOtherEvent", function(e){
console.log(e);
console.log(e.timeStamp);
});Run Code Online (Sandbox Code Playgroud)
<button onclick="a()">A</button>
<button onclick="b()">B</button>
<div id="targetA"></div>
<div id="targetB"></div>Run Code Online (Sandbox Code Playgroud)
A 方法的副作用可能是时间戳未更新。这可能会导致依赖时间戳的处理程序出现意外行为。
B 方法的性能可能较低,因为 CustomEvent 对象被一遍又一遍地实例化。(内存应该不是问题。)
有没有“正确”的方法,或者有什么最佳实践?
也许我不了解 Laravel 队列的工作原理,或者它本身不起作用,我对 Laravel 队列/调度的预期行为是,如果从控制器启动调度,则调度到队列的代码应静默执行,并在背景。最终用户浏览器不应等待代码执行。
然而,这就是我的代码发生的情况,调度到队列的代码在执行时让浏览器“旋转...”。
这是预期的行为吗?编码:
**Controller:**
public function make_eps_certs($tbl_eps)
{
//dd(Carbon::now()->addMinutes(10))
Log::info('Dispatching maeEPSCert to Queue');
$var_result=makeEPSCerts::dispatch($tbl_eps)->onQueue('eventadmin')
->delay(10);
return redirect()->back();
}
**Job:**
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use App\partSubs;
use Log;
use Image;
class makeEPSCerts implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
protected $passdata;
public $timeout = 120;
public function __construct($passdata)
{
Log::info('Constructing makeEPSCert');
$this->passdata = $passdata;
}
/** …Run Code Online (Sandbox Code Playgroud) dispatch ×10
c# ×2
events ×2
ios ×2
queue ×2
.net ×1
android ×1
concurrency ×1
dynamic ×1
foreground ×1
intervals ×1
iphone ×1
java ×1
javascript ×1
laravel ×1
laravel-5.5 ×1
methods ×1
mousewheel ×1
nfc ×1
oop ×1
overloading ×1
polymorphism ×1