我在我们的应用程序中使用无状态来实现状态机的逻辑.我们有一个AcceptedFile具有其他内部(子)状态的状态.问题是我不知道如何在我的代码中指示初始内部状态,以便当机器转移到AccptedFile状态它也会自动转换到其初始内部状态.这就是我为模拟这种行为所做的:
machine.Configure(State.AcceptedFile)
.OnEntry(() => machine.Fire(Trigger.MakeReadyForAdvertising))
.Permit(Trigger.MakeReadyForAdvertising,State.ReadyForAdvertising)
Run Code Online (Sandbox Code Playgroud)
这ReadyForAdvertising是一个内部状态.AcceptedFile这在大多数情况下工作正常,但每当我将状态机的初始状态设置为AcceptedFile这样:
var statemachine=new StateMachine<State,Trigger>(State.AcceptedFile)
...
Run Code Online (Sandbox Code Playgroud)
不会发生自动转换,因此机器将处于AcceptedFile状态而不是ReadyForAdvertising.
有没有更好的方法来实现这种行为?
我的输出是一个多值、逗号分隔的字符串。
resource "azurerm_app_service" "testap" {
name = "MySuperCoolAppServer001"
location = "eastus"
resource_group_name = "notshown"
app_service_plan_id = "notshown"
}
Run Code Online (Sandbox Code Playgroud)
output "output_tf_testap_outbound_ip_addresses" {
value = "${azurerm_app_service.testap.outbound_ip_addresses}"
}
Run Code Online (Sandbox Code Playgroud)
我在控制台中得到这个:
output_tf_testap_outbound_ip_addresses = 1.2.3.4,1.2.3.5,1.2.3.6,1.2.3.7,1.2.3.8,1.2.3.9
如何获取列表中的第一项?在这种情况下,我试图隔离该值:
1.2.3.4
当运行时之前未知项目总数时,有没有办法获得所有项目的“集合”?(上面的列表有 6 项)。
下面的代码似乎不起作用:
output "first_ip" {
value = ["${azurerm_app_service.testap.outbound_ip_addresses[0]}"]
}
Run Code Online (Sandbox Code Playgroud)
===================== 附加 =================
first_ip_no_index 有效。first_ip 没有
output "first_ip_no_index" {
value = ["${split(",", azurerm_app_service.tf_middle_tier_azurerm_app_service.outbound_ip_addresses)}"]
}
output "first_ip" {
value = "${split(",", azurerm_app_service.tf_middle_tier_azurerm_app_service.outbound_ip_addresses)[0]}"
}
Run Code Online (Sandbox Code Playgroud)
first_ip 生成此错误:
读取输出first_ip的配置时出错:在1:91处解析错误:预期为“}”,但发现了“[”
所以我已经编写了一个自定义的jQuery验证器方法.它与一个或多个单独的下拉列表相关联.(我在asp.net,顺便说一句)
jQuery.validator.addMethod("dropdownBoxHasItemSelected", function (value, select, arg) {
var returnValue = false;
var selectedIndex = $(select).prop("selectedIndex");
if (selectedIndex != 0) {
returnValue = true;
}
return returnValue;
}, "Please select a item.");
Run Code Online (Sandbox Code Playgroud)
所以这不是我的问题.
我有一些必须在"页面级别"完成的验证.或者也许在"GridView"级别是一种更好的方式来表达它.
这是一个场景:(我正在使用虚拟数据来使解释更容易,也就是说,我真的没有玩具和食品)
我有一个网格视图.
Column A of the gridview is of no consequence of this, but it exists.
Column B of the gridview has a DropDownList for "FavoriteToy".
Column C of the gridview has a DropDownList for "FavoriteFood".
Run Code Online (Sandbox Code Playgroud)
所以规则就是这样的.
对于gridview中的每一行:
You must pick a FavoriteToy or a …Run Code Online (Sandbox Code Playgroud) 在我正在使用的 C# 解决方案中,应用程序逻辑的核心通过(非常好的)无状态库实现为状态机。对于应用程序显示的不同区域和功能,在许多其他类中建模了业务逻辑的其他部分,但这是推动底层应用程序状态发生主要变化的部分。
尽管每个状态转换本身都非常简单(通知事件、设置 eventArgs、侦听其他事件……)并且我在适用时使用了子状态,但对我来说它开始看起来有点太大了。我知道这不是一个精确的度量,但是如果您查看并考虑子状态,您很可能最终会发现它们本身可能是不同的状态机。
是否有一种明显的方法让我无法使用无状态构建单独的子状态机(可以这么说),将每个状态机映射到不同的类(和文件)?
我想到的第一个阻塞问题是(尤其是第二个):
在一个大的片上所有的状态变化的状态机触发事件:分裂后,每个单一的国家机器将火每个自己的触发器。所以最好有一个外观收集所有事件并为客户端重新触发它们,以便隐藏许多状态机(毕竟它们是客户端的实现细节)。
无状态子状态负责向上和向下的状态/子状态链的冒泡触发器。因此,例如对于A具有子状态的给定状态,您可以定义一个触发器(在一个地方,A配置),A无论A我们将处于哪个子状态,状态机都会离开。这如何与单独的子状态机一起工作?
在我的下面的代码中,我正在锁定guid,尝试使其线程安全.使用我的示例应用程序,每运行一次程序,我将获得一个"重复密钥".阿卡,我得到了副本,这不是我需要的.
反正是否使".NextGuid"线程安全?
using System;
namespace MyConsoleOne.BAL
{
public class GuidStore
{
private static object objectlock = new object();
private Guid StartingGuid { get; set; }
private Guid? LastGuidHolder { get; set; }
public GuidStore(Guid startingGuid)
{
this.StartingGuid = startingGuid;
}
public Guid? GetNextGuid()
{
lock (objectlock)
{
if (this.LastGuidHolder.HasValue)
{
this.LastGuidHolder = Increment(this.LastGuidHolder.Value);
}
else
{
this.LastGuidHolder = Increment(this.StartingGuid);
}
}
return this.LastGuidHolder;
}
private Guid Increment(Guid guid)
{
byte[] bytes = guid.ToByteArray();
byte[] order = { 15, 14, 13, …Run Code Online (Sandbox Code Playgroud) 我找到了这个问题的答案: 是否可以使用Azure Powershell创建App Service计划?
有人知道如何使用Azure 创建消费应用程序服务计划吗?
当我查看(由Gui制作)的一个属性(使用https://resources.azure.com/)时,看到以下属性;
},
"sku": {
"name": "Y1",
"tier": "Dynamic",
"size": "Y1",
"family": "Y",
"capacity": 0
}
{
"id": "/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxx/resourceGroups/MyResourceGroup/providers/Microsoft.Web/serverfarms/MyHandMadeConsumptionAppServicePlan",
"name": "MyHandMadeConsumptionAppServicePlan",
"type": "Microsoft.Web/serverfarms",
"kind": "functionapp",
"location": "East US",
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试(重要的部分是“-层动态”)
$plan = New-AzureRmAppServicePlan -Name 'MyPowershellCreatedAppServicePlan' -ResourceGroupName 'MyResourceGroup' -Location 'PickALocation' -Tier Dynamic
Run Code Online (Sandbox Code Playgroud)
我得到例外:
异常-+无法验证参数“层”上的参数。参数“动态”不属于ValidateSet属性指定的集合“ Free,Shared,Basic,Standard,Premium,PremiumV2”。提供集合中的参数,然后再次尝试命令。
这个网址
https://logging.apache.org/log4j/log4j-2.0/manual/appenders.html
有这个例子:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="error">
<Appenders>
<JDBC name="databaseAppender" tableName="dbo.application_log">
<DataSource jndiName="java:/comp/env/jdbc/LoggingDataSource" />
<Column name="eventDate" isEventTimestamp="true" />
<Column name="level" pattern="%level" />
<Column name="logger" pattern="%logger" />
<Column name="message" pattern="%message" />
<Column name="exception" pattern="%ex{full}" />
</JDBC>
</Appenders>
<Loggers>
<Root level="warn">
<AppenderRef ref="databaseAppender"/>
</Root>
</Loggers>
</Configuration>
Run Code Online (Sandbox Code Playgroud)
当我尝试连接到 sqlserver 数据库时......
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<JDBC name="SQLServerAppender" tableName="dbo.LogEntry">
<DataSource jndiName="jdbc:sqlserver://MyMachine\\MyInstance:1433;databaseName=LoggingDB;applicationName=myappname;integratedSecurity=true;" />
<Column name="EntryDateUtc" isEventTimestamp="true" />
<Column name="LOGGER" pattern="%C" />
<Column name="Level" pattern="%level" />
<Column name="Message" pattern="%m" />
<Column name="UserName" pattern="%x" />
<Column …Run Code Online (Sandbox Code Playgroud) 我正在尝试从特定实例类型的顶级异常中递归地找到所有内部异常(getCause的)。
public class MyCustomRunTimeException extends RuntimeException {
public MyCustomRunTimeException() {
}
public MyCustomRunTimeException(Exception innerException) {
super(innerException);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我尝试过的:
和我早期的“查找”方法:
private void findAllSpecificTypeOfInnerExceptions(Exception ex)
{
Collection<MyCustomRunTimeException> MyCustomRunTimeExceptions = Stream.iterate(ex, Throwable::getCause)
.filter(element ->
element != null
&& element instanceof MyCustomRunTimeException
)
.map(obj -> (MyCustomRunTimeException) obj)
.collect(Collectors.toList());
}
Run Code Online (Sandbox Code Playgroud)
它不起作用。:(我已经尝试了其他几件事(尚未显示)...如果我收到的任何内容都不会引发异常,则会将它们发布为“追加”到这个问题。获取NullPointers异常,以及(取决于我的调整)java.lang.reflect.InvocationTargetException异常。
这是一些可以找到1:N“匹配”的示例。
Exception exampleOne = new MyCustomRunTimeException();
Exception exampleTwo = new Exception(new MyCustomRunTimeException());
Exception exampleThree =new Exception(new Exception(new MyCustomRunTimeException()));
Exception exampleFour =new Exception(new Exception(new MyCustomRunTimeException(new ArithmeticException())));
Run Code Online (Sandbox Code Playgroud) 该示例有:
apiVersion: v1
kind: Pod
metadata:
name: secret-env-pod
spec:
containers:
- name: mycontainer
image: redis
env:
- name: SECRET_USERNAME
valueFrom:
secretKeyRef:
name: mysecret
key: usernamekey
- name: SECRET_PASSWORD
valueFrom:
secretKeyRef:
name: mysecret
key: passwordkey
restartPolicy: Never
Run Code Online (Sandbox Code Playgroud)
以上来自:
https://kubernetes.io/docs/concepts/configuration/secret/
我创建了一个这样的秘密:
kubectl --namespace=mycustomnamespace create secret generic mysecret --from-literal=passwordkey="abc123" --from-literal=usernamekey="mememe"
Run Code Online (Sandbox Code Playgroud)
我知道上述秘密存在于命名空间下。
但如果我尝试这个:
apiVersion: v1
kind: Pod
metadata:
name: secret-env-pod
namespace: mycustomnamespace
spec:
containers:
- name: mycontainer
image: redis
env:
- name: SECRET_USERNAME
valueFrom:
secretKeyRef:
name: mysecret
key: usernamekey
namespace: mycustomnamespace
- name: SECRET_PASSWORD …Run Code Online (Sandbox Code Playgroud) 这是一个奇怪的问题。我的 Entity Framework Core 项目将表和 Id 合并到一列中,如下所示:MonsterListMonsterId
这是错误:
Microsoft.Data.SqlClient.SqlException (0x80131904): Invalid column name 'MonsterListMonsterId'
Run Code Online (Sandbox Code Playgroud)
这是生成错误的控制器:
var treasuresByMonster = await _context.MonsterTreasures.Where(q => q.MonsterId == id).ToListAsync();
Run Code Online (Sandbox Code Playgroud)
显然该列名为 MonsterId。不是 MonsterListMonsterId。
这是 MonsterList 类:
public class MonsterList
{
public MonsterList()
{
MonsterTreasures = new HashSet<MonsterTreasures>();
}
public Guid MonsterId { get; set; }
public string MonsterText { get; set; }
public virtual ICollection<MonsterTreasures> MonsterTreasures { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这是 MonsterTreasure 类:
public partial class MonsterTreasures
{
public Guid TreasureId { get; set; } …Run Code Online (Sandbox Code Playgroud)