我有一个powershell脚本,通过写输出提供一些状态输出.我故意不使用write-host,因为输出可能被捕获并写入日志文件,如下所示:
./myscript.ps1 | out-file log.txt
Run Code Online (Sandbox Code Playgroud)
但是如果输出没有被重定向,那么在控制台上输出彩色输出会很好,因为脚本会产生许多不同的状态消息.我知道使用write-host可以实现彩色输出,但状态消息应该是可管理的.
任何想法如何解决这个问题?
我是Android的新手,我试图从我自定义的DialogPreference加载/持久化值.目前,这会失败,因为findViewById返回null.我(尝试)这样做的方式是否正确?如何在代码中访问我的EditText小部件?
public class AddressDialogPreference extends DialogPreference {
public AddressDialogPreference(Context context, AttributeSet attrs) {
super(context, attrs);
setDialogLayoutResource(R.layout.address_dialog);
}
@Override
protected void onBindDialogView(View view) {
EditText idField = (EditText) view.findViewById(R.id.hostID);
EditText ipField = (EditText) view.findViewById(R.id.hostIP);
SharedPreferences pref = getSharedPreferences();
idField.setText(pref.getString(getKey() + "_id","ExampleHostname"));
ipField.setText(pref.getString(getKey() + "_ip","192.168.1.1"));
super.onBindDialogView(view);
}
@Override
protected void onDialogClosed(boolean positiveResult) {
if(!positiveResult)
return;
Dialog myDial = getDialog();
EditText idField = (EditText) myDial.findViewById(R.id.hostID);
EditText ipField = (EditText) myDial.findViewById(R.id.hostIP);
SharedPreferences.Editor editor = getEditor();
editor.putString(getKey() + "_id",idField.getText().toString());
editor.putString(getKey() + "_ip",ipField.getText().toString());
}
Run Code Online (Sandbox Code Playgroud)
address_dialog.xml:
<TextView …Run Code Online (Sandbox Code Playgroud) 我有一个JOURNAL表,其中INSERT_DATE列应由DB填充,插入记录时的当前日期和时间.我没有故意使用TIMESTAMP类型,因为它的范围有限.
class Journal(tag: Tag) extends Table[JournalEntry](tag, "JOURNAL") {
def id = column[Int]("ID", O.PrimaryKey, O.AutoInc)
def insertDate = column[OffsetDateTime]("INSERT_DATE", SqlType("DateTime default CURRENT_TIMESTAMP"))(localDateTimeColumnType)
def valueDate = column[OffsetDateTime]("VALUE_DATE", SqlType("DateTime"))(localDateTimeColumnType)
def amount = column[Int]("AMOUNT")
def note = column[String]("NOTE", O.Length(100))
def * : ProvenShape[JournalEntry] = (id.?, insertDate.?, valueDate, amount, note)
<> ((JournalEntry.apply _).tupled, JournalEntry.unapply)
}
Run Code Online (Sandbox Code Playgroud)
我还实现了一个case类:
case class JournalEntry(id: Option[Int], insertDate: Option[LocalDateTime],
valueDate: LocalDateTime, amount: Int, note: String)
Run Code Online (Sandbox Code Playgroud)
当我的应用程序启动时,我使用随机测试数据填充数据库:
TableQuery[Journal] ++= Seq.fill(1000)(JournalEntry(None, Some(LocalDateTime.now()),
LocalDateTime.of(2006 + Random.nextInt(10), 1 + Random.nextInt(11),
1 + Random.nextInt(27),Random.nextInt(24), Random.nextInt(60)), Random.nextInt(),
TestDatabase.randomString(100))) …Run Code Online (Sandbox Code Playgroud)