我正在寻找一个设计模式来解决以下问题:
阅读输入
处理数据(包含验证)
保存结果
示例如下:读取csv文件,处理数据,另存为xml读取MQ消息,处理数据,保存到数据库.
我在考虑一个BusinessObject:
IInput实现来处理读取和加载自身.IOutput实现来处理自己保存.例如(伪代码!)
public abstract class BusinessObject
{
public IInput Input { get; set; }
public IOutput Output { get; set; }
public BusinessObject(IInput input, IOutput output)
{ }
}
Run Code Online (Sandbox Code Playgroud)
然后有一个Load,Process和Save方法.
但是,这对我来说似乎不对.我认为 BO应该能够加载和保存自己?
如果有人知道这可能是什么样的模式,那么我可以阅读它,或者给我一个例子/解释,我将非常感激.
让我们试着清楚地解释一下.
我有一个自定义控件作为WPF应用程序构建,它工作正常.我已将所有代码移动到外部DLL中.在此更改之后,当我加载应用程序时,不再调用OnApplyTemplate()方法,并且不会呈现控件
你对这个解决方案有什么想法吗?
提前致谢...
我认为这是一个棘手的问题,但我想验证我的软件架构足够强大.
我计划在我的代码上执行这些工具:
但我想要一些工具来检查(除其他外):
总之,我想要开源工具来突出我项目的任何建筑故障.
我知道最好的工具是经验丰富的建筑师,但即使是最好的木匠也需要一把好的锤子;)
所以我在这里遇到了一些问题,我似乎无法弄清楚如何更新Object中的数据值
让我们举个例如关注的json
{
"People": 263,
"Hungry": true,
"Fruits": {
"Apples": 1 "Oranges": 2
},
"Places": {
"Places": [{
"Baskets": "true",
"name": "Room 1",
"candycount": 1500,
"candytypespresent": {
"candies": [
"caramel"
]
}
},
{
"Baskets": "false",
"name": "Room 2",
"candycount": 2000,
"candytypespresent": {
"candies": [
"caramel",
"jawbreaker",
"butterscotch"
]
}
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
我有Powershell顺利阅读它 convertfrom-json
我该怎么做:
A)将"橘子"从"2"改为"100"
B)房间2中的"篮子"从"假"到"真"
C)在Room1中将"bubblegum"添加到"糖果"中
如何在不重写WHOLE json或对象的情况下更新此内容?
我想制作一个简单的CSV解析器.它应该通过逗号分隔值列表并将它们放在一个IList<int>.这些值应该是整数.如果值不可解析,我只想省略它.
这是我到目前为止的代码:
csv.Split(',').Select(item =>
{
int parsed;
if (int.TryParse(item, out parsed))
{
return parsed;
}
continue; //is not allowed here
}).ToList();
Run Code Online (Sandbox Code Playgroud)
但是,continue这里不允许使用(当然).如何在我的select实现中省略一个值?
注意:当然可以使用foreach或LINQ表达式,但我想知道如何使用lambda.
我有一个使用WebHttpBinding托管的WCF服务.服务非常简单,是一个接受多个参数的操作合同.使用"添加服务引用"后自动生成的我的WCF客户端无法直接使用WCF服务.该错误仅发生在WebHttpBinding而不是其他错误.
服务器端
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "Submit2String", RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped)]
string Submit2String(string input1, string input2);
Run Code Online (Sandbox Code Playgroud)
客户端
ExpenseServiceClient proxy = new ExpenseServiceClient();
proxy.Submit2String("test1", "test2");
Run Code Online (Sandbox Code Playgroud)
当我测试运行上面的代码时,我收到以下错误:
Error: InvalidOperationException was unhandled by user code
Manual addressing is enabled on this factory, so all messages sent must be pre-addressed.
Run Code Online (Sandbox Code Playgroud)
以下是使用"添加服务引用"后自动生成的配置文件的外观:
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webHttp">
<security mode="None">
<transport clientCredentialType="None" />
</security>
</binding>
</webHttpBinding>
</bindings>
<client>
<endpoint binding="webHttpBinding"
bindingConfiguration="webHttp"
contract="ExpenseService.IExpenseService"
address="http://localhost/myservices/ExpenseService.svc">
</endpoint>
</client>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud) 我有一个ItemsControl,其ItemsSource绑定到项目列表。每个项目的大小都尽可能小,我需要的是控件,控件中的项目可以拉伸以适合所有可用空间。
我尝试在控件及其项目上(使用样式)将VerticalAlignment设置为Stretch。我还尝试将ItemsControl包装在DockPanel中,并将ItemsControl停靠在底部。我如何让ItemsControl动态调整大小?
某些(但不是全部)项目的可见性也设置为“已折叠”(通过相同样式)。这将是完成此工作的一个因素吗?
<DockPanel HorizontalAlignment="Stretch">
<ItemsControl DockPanel.Dock="Bottom"
ItemsSource="{Binding Owner.LoadPointCharts}"
HorizontalAlignment="Stretch"
x:Name="ItemsControl">
<ItemsControl.ItemContainerStyle><!--Height="{Binding Path=Height, RelativeSource={RelativeSource AncestorType={x:Type DockPanel}}}"-->
<Style TargetType="ContentPresenter">
<Setter Property="VerticalAlignment"
Value="Stretch" />
<Setter Property="Visibility">
<Setter.Value>
<MultiBinding Converter="{StaticResource CompareIndexToVisibilityConverter}">
<Binding Path="Index" />
<Binding Path="SelectedIndex" />
</MultiBinding>
</Setter.Value>
</Setter>
</Style >
</ItemsControl.ItemContainerStyle>
</ItemsControl>
</DockPanel>
Run Code Online (Sandbox Code Playgroud) 我在列表中有一些数据我想要进行查询.然而,在此期间,其他用户可以添加到此列表,我得到错误的项目作为回报:
var query = from s in selected
where s.contains("www")
select s);
Run Code Online (Sandbox Code Playgroud)
然后,用户可以在运行查询之前将项目添加到选定列表,我也会得到这个.我可以阻止这种行为吗?:
selected.add("123www")
foreach (var s in query)
/// gives me 123www
Run Code Online (Sandbox Code Playgroud) 我有 Caliburn.Micro 的问题:我有 ShellView.xaml 和 ShellViewModel.cs,我想从 ShellViewModel 打开新的对话窗口“NewDialogView.xaml”。
<StackPanel>
<Button x:Name="Click"
Content="Click"
/>
</StackPanel>
internal class ShellViewModel
{
public void Click()
{
Window newDialogView = new NewDialogView();
newDialogView.Show();
}
}
Run Code Online (Sandbox Code Playgroud)
然后当用户在那个新窗口中时,他/她可以点击按钮并收到一些消息:
<StackPanel>
<Button x:Name="ShowMessage"
Content="Click"
/>
</StackPanel>
internal class NewDialogViewModel
{
public void ShowMessage()
{
MessageBox.Show("Hello!");
}
}
Run Code Online (Sandbox Code Playgroud)
问题是当用户单击 NewDialogView.xaml 中的按钮时,什么也没有发生。没有内容为“你好”的消息框。请帮忙!