我有一个wcf服务.服务本身(继承ServiceContract的类)有一个构造函数,有时会抛出异常.如果服务失败,我想向用户显示一条消息.我应该像使用服务方法一样使用故障吗?
前言:我来自.NET和PHP背景.我很擅长用Java创建一个控制台应用程序.我从来没有在任何平台上使用过ORM.我正在尝试学习企业级Java最佳实践.因此,如果我听起来无知,那可能是因为我.
我下载了最新版本的SpringSource Tool Suite.我想用JPA mongo制作一个spring项目(适配器/驱动程序/驱动程序).我想和roo这样做.所以我认为我需要知道的是具有mongodb驱动程序的JPA库的名称.
拿简单的HashTable:
$data = @{
First = 'Justin';
Last = 'Dearing';
StartDate = Get-Date '2002-03-23';
}
Run Code Online (Sandbox Code Playgroud)
关键的StartDate似乎包含DateTime.
C:\Users\zippy\Documents> $data.StartDate.GetType().FullName
System.DateTime
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试对其执行二进制序列化,我会得到一个例外,抱怨PSObject不可序列化.
$ms = New-Object System.IO.MemoryStream
$bf = New-Object System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
$bf.Serialize($ms, $data)
$ms.Close()
Run Code Online (Sandbox Code Playgroud)
抛出:
DocumentsException calling "Serialize" with "2" argument(s): "Type 'System.Management.Automation.PSObject' in Assembly 'System.Management.Automation, Versio
n=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is not marked as serializable."
At C:\Users\jdearing\AppData\Local\Temp\b8967f99-0a24-41f7-9c97-dad2bc288bd9.ps1:12 char:14
+ $bf.Serialize <<<< ($ms, $data)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Run Code Online (Sandbox Code Playgroud)
如果我使用显式转换为[DateTime],这条消息消失了,一切正常:
$data = …Run Code Online (Sandbox Code Playgroud) 在PowerShell中,您可以指定带方括号的类型,如下所示:
PS C:\Users\zippy> [int]
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Int32 System.ValueType
Run Code Online (Sandbox Code Playgroud)
还有像[xml]这样的内置类型加速器,当您希望将某些内容转换为XmlDocument时,它会保存一些按键.
PS C:\Users\zippy> [xml]
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True False XmlDocument System.Xml.XmlNode
Run Code Online (Sandbox Code Playgroud)
您可以通过以下两个命令之一生成列表:
[type]::gettype("System.Management.Automation.TypeAccelerators")::Get[psobject].assembly.gettype("System.Management.Automation.TypeAccelerators")::GetPowerShell 3.0添加了一个名为[ordered]的运算符.它不是一个类型别名.
PS C:\Users\zippy> [ordered]
Unable to find type [ordered]: make sure that the assembly containing this type is loaded.
At line:1 char:1
+ [ordered]
+ ~~~~~~~~~
+ CategoryInfo : InvalidOperation: (ordered:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
Run Code Online (Sandbox Code Playgroud)
但是,它可以将 …
这与这个问题非常相似,除了它是关于在两个不同的 JSON 文件之间附加数组之外。
我有一个 ASP.NET Core 应用程序
我在 appsettings.Development.Json 中有以下内容
"Serilog": {
"WriteTo": [
{
"Name": "ApplicationInsightsTraces",
"Args": { "instrumentationKey": "XXXXXXXX" }
}
]
}
Run Code Online (Sandbox Code Playgroud)
并在appsettings.json:
"Serilog": {
// . . . Rest of Serilog configs
"WriteTo": [
{
"Name": "Console",
"Args": {
"theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Code, Serilog.Sinks.Console",
"outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {RequestId}-{SourceContext} {$Scope:lj}: {Message:lj}{NewLine}{Exception}"
},
"restrictedToMinimumLevel": "Information"
},
}
Run Code Online (Sandbox Code Playgroud)
因为键会覆盖 Appsettings.json 中的其他键,所以我最终会覆盖控制台接收器。是否有允许附加它的语法?
我可能会建议从VSS迁移,因为它无法在文件级别授予和拒绝权限.问题是源控制系统允许这样做.
更新 我将SVN答案标记为"正确"答案,因为它的反馈最多.但是,没有正确的答案.我会根据您的所有反馈向管理层提出建议.
如果$文件名存在,那么该cmdlet相当于[System.IO.Path]::GetFullPath($fileName);是(Get-Item $fileName).FullName.但是,如果路径不存在,则抛出异常.他们的另一个cmdlet我不见了?
Join-Path 是不可接受的,因为它在传递绝对路径时不起作用:
C:\Users\zippy\Documents\deleteme> join-path $pwd 'c:\config.sys'
C:\Users\zippy\Documents\deleteme\c:\config.sys
C:\Users\zippy\Documents\deleteme>
Run Code Online (Sandbox Code Playgroud) 假设我在一个powershell脚本中用C#定义了以下类:
Add-Type -TypeDefinition @"
public class InnerClass {
int a, b;
public int A { get { return a; } set { a = value; } }
public int B { get { return b; } set { b = value; } }
}
public class SomeClass {
string name;
public string Name { get { return name; } set { name= value; } }
InnerClass numbers;
public InnerClass Numbers { get { return numbers; } set { numbers = …Run Code Online (Sandbox Code Playgroud) 我有以下powershell脚本:
param(
[Int32[]] $SomeInts = $null,
[String]$User = "SomeUser",
[String]$Password = "SomePassword"
)
New-Object PSObject -Property @{
Integers = $SomeInts;
Login = $User;
Password = $Password;
} | Format-List
Run Code Online (Sandbox Code Playgroud)
如果我执行,.\ParameterTest.ps1 (1..10)我得到以下内容:
Password : SomePassword
Login : SomeUser
Integers : {1, 2, 3, 4...}
Run Code Online (Sandbox Code Playgroud)
但是,如果我在像这样的单独的PowerShell实例中运行它,我就不会得到预期的结果powershell -file .\ParameterTest.ps1 (1..10).在那种情况下,我得到以下内容:
Password : 3
Login : 2
Integers : {1}
Run Code Online (Sandbox Code Playgroud)
我的问题是如何从命令行传递数组或其他复杂数据类型?
我在PowerShell函数中有一些代码如下所示:
try {
Invoke-SomethingThatFails
}
catch [System.Exception] {
Write-Error $_.Exception.Message;
return New-Object Namespace.CustomErrorType -Property @{
'Code' = "Fail";
"Message" = $_.Exception.Message;
}
}
Run Code Online (Sandbox Code Playgroud)
现在唯一的问题是我还想设置$?是$ false.这可能吗?
powershell ×5
acl ×1
appsettings ×1
asp.net-core ×1
cmdlets ×1
command-line ×1
constructor ×1
datetime ×1
java ×1
jpa ×1
mongodb ×1
psobject ×1
serilog ×1
soapfault ×1
spring-roo ×1
wcf ×1
web-services ×1