小编pmc*_*ath的帖子

Json.net实现IEnumerable <T>的自定义集合的序列化

我有一个实现IEnumerable的集合类,我无法反序列化相同的序列化版本.我正在使用Json.net v 4.0.2.13623

这是我的集合类的简化版本,它说明了我的问题

public class MyType
{
  public int Number { get; private set; }
  public MyType(int number)
  {
    this.Number = number;
  }
}

public class MyTypes : IEnumerable<MyType>
{
  private readonly Dictionary<int, MyType> c_index;
  public MyTypes(IEnumerable<MyType> seed)
  {
    this.c_index = seed.ToDictionary(item => item.Number);
  }
  public IEnumerator<MyType> GetEnumerator()
  {
    return this.c_index.Values.GetEnumerator();
  }
  IEnumerator IEnumerable.GetEnumerator()
  {
    return this.GetEnumerator();
  }
  public int CustomMethod()
  {
    return 1;  // Just for illustration
  }
}
Run Code Online (Sandbox Code Playgroud)

当我序列化它时,我得到以下json

[
  {
    "Number": 1
  },
  {
    "Number": 2 …
Run Code Online (Sandbox Code Playgroud)

c# serialization json json.net

15
推荐指数
2
解决办法
1万
查看次数

获取无符号长整数c#中的位数

我正在尝试确定ac#ulong数字中的位数,我试图使用一些数学逻辑而不是使用ToString().长度.我没有对这两种方法进行基准测试,但已经看到有关使用System.Math.Floor(System.Math.Log10(number))+ 1来确定位数的其他帖子.似乎工作正常,直到我从999999999999997过渡到999999999999998,此时,我开始得到一个不正确的计数.

有没有人遇到过这个问题?

我看过类似帖子的Java重点@ 为什么log(1000)/ log(10)与log10(1000)不一样?还有一个帖子@ 如何获取一个int数字的单独数字?这表明我如何使用%运算符实现相同的功能,但代码更多

这是我用来模拟这个的代码

Action<ulong> displayInfo = number => 
 Console.WriteLine("{0,-20} {1,-20} {2,-20} {3,-20} {4,-20}", 
  number, 
  number.ToString().Length, 
  System.Math.Log10(number), 
  System.Math.Floor(System.Math.Log10(number)),
  System.Math.Floor(System.Math.Log10(number)) + 1);

Array.ForEach(new ulong[] {
 9U,
 99U,
 999U,
 9999U,
 99999U,
 999999U,
 9999999U,
 99999999U,
 999999999U,
 9999999999U,
 99999999999U,
 999999999999U,
 9999999999999U,
 99999999999999U,
 999999999999999U,
 9999999999999999U,
 99999999999999999U,
 999999999999999999U,
 9999999999999999999U}, displayInfo);

Array.ForEach(new ulong[] {
 1U,
 19U,
 199U,
 1999U,
 19999U,
 199999U,
 1999999U,
 19999999U,
 199999999U,
 1999999999U,
 19999999999U,
 199999999999U,
 1999999999999U,
 19999999999999U,
 199999999999999U,
 1999999999999999U,
 19999999999999999U,
 199999999999999999U,
 1999999999999999999U
}, displayInfo);
Run Code Online (Sandbox Code Playgroud)

提前致谢

c# algorithm numbers

11
推荐指数
2
解决办法
4408
查看次数

IIS 7.5 powershell模块使用问题

有没有人设法成功使用这个模块,我正在运行32位Windows 7,我已经使用run as administrator打开了一个管理员shell,我已经导入了WebAdministration模块然后尝试使用这些命令有一些问题,提供了两个这里的例子

网站

我使用以下命令创建了一个网站

new-website -name testsite -port 80 -hostheader testsite -physicalpath c:\temp
Run Code Online (Sandbox Code Playgroud)

然后我尝试使用命令get-website -name testsite获取站点详细信息,但它总是返回所有站点,似乎忽略-name参数.只有我可以获得该网站的方式是使用过滤器

get-website | ? { $_.name -eq 'testsite' } | get-member
Run Code Online (Sandbox Code Playgroud)

当我使用appcmd时,它使用以下命令按预期工作

C:\> C:\Windows\System32\inetsrv\appcmd.exe list site testsite
Run Code Online (Sandbox Code Playgroud)

AppPools

当我尝试使用以下命令列出apppools时

dir iis:\apppools
Run Code Online (Sandbox Code Playgroud)

我收到以下错误

Get-ChildItem : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
Run Code Online (Sandbox Code Playgroud)

然而,当我按如下方式使用appcmd时,我可以按预期获得所有apppool,而不会出现任何错误

C:\Windows\System32\inetsrv\appcmd.exe list apppool
Run Code Online (Sandbox Code Playgroud)

有没有人成功设法使用WebAdministration模块?

在此先感谢
Pat

powershell module iis-7.5

9
推荐指数
2
解决办法
1841
查看次数

在 kubeadm 集群上配置 PodSecurityPolicy

我尝试使用 kubeadm 在 ubuntu 16.04 上安装的 1.10.1 集群上设置 PodSecurityPolicy,已按照https://kubernetes.io/docs/concepts/policy/pod-security-policy/ 上的说明进行操作

所以我改变了API服务器清单上的主,在/etc/kubernetes/manifests/kube-apiserver.yaml 加入",PodSecurityPolicy"--admission-controlARG

当我执行此操作并运行kubectl get pods -n kube-system api-server 未列出时,显然我已经设法命中 apiserver 的一个正在运行的实例,因为我获得了 kube-system 命名空间中所有其他 pod 的列表

我可以看到一个新的 docker 容器已经使用 PodSecurityPolicy 准入控制器启动,它显然正在服务 kubectl 请求

当我检查 kubelet 日志时,journalctl -u kubelet我可以看到

Apr 15 18:14:23 pmcgrath-k8s-3-master kubelet[993]: E0415 18:14:23.087361 993 kubelet.go:1617] Failed creating a mirror pod for "kube-apiserver-pmcgrath-k8s-3-master_kube-system(46dbb13cd345f9fbb9e18e2229e2e dd1)": pods "kube-apiserver-pmcgrath-k8s-3-master" is forbidden: unable to validate against any pod security policy: []

我已经添加了一个特权 PSP 并创建了一个集群角色和绑定并确认 …

kubernetes kubernetes-security

6
推荐指数
1
解决办法
1776
查看次数

如何覆盖配置属性?

我试图在.Net v4.0上进行发布和调试构建,其中我有一个MSBuild项目文件而不是解决方案文件.我想使用相同的构建项目文件,但只是覆盖"Debug"和"Release"之间的Configuration属性切换.

当我执行如下

c:\windows\microsoft.net\framework\v4.0.30319\msbuild.exe buildinv.proj
/target:rebuild "/property:Configuration=Debug" /verbosity:Diagnostic
Run Code Online (Sandbox Code Playgroud)

我收到以下错误

c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(483,9):
error : The OutputPath property is not set for project
'buildinv.proj'.  Please check to make sure that you have specified a
valid combination of Configuration and Platform for this project. 
Configuration='Debug'  Platform=''.
Run Code Online (Sandbox Code Playgroud)

我可以看到错误发生在_CheckForInvalidConfigurationAndPlatform.

如果我传递一个OutputPath属性,它将工作

c:\windows\microsoft.net\framework\v4.0.30319\msbuild.exe buildinv.proj
/target:rebuild "/property:Configuration=Debug" "/property:OutputPath=."
Run Code Online (Sandbox Code Playgroud)

这是一个已知的错误 ?在我需要覆盖Configuration属性的地方,即使我不希望,我也会被迫覆盖OutputPath属性.

提前致谢.

msbuild-4.0

5
推荐指数
1
解决办法
1万
查看次数

NServiceBus Xml序列化问题与具有IEnumerable <T>属性的消息

我正在尝试发送带有IEnumerable属性的消息,我是否认为NServiceBus Xml序列化程序不支持这个?如果我切换到使用数组而不是IEnumerable它将工作,如果我使用二进制序列化器它也可以工作

我的消息看起来像这样

[Serializable]
public class Parent : IMessage
{
  public string Identifier { get; private set; }
  public IEnumerable<Child> Children { get; private set; }

  public Parent(string identifier, IEnumerable<Child> children)
  {
    this.Identifier = identifier;
    this.Children = children;
  }
}

[Serializable]
public class Child
{
  public string Identifier { get; private set; }
}  
Run Code Online (Sandbox Code Playgroud)

如果默认的Xml序列化程序无法满足此要求,有没有办法配置替代的Xml序列化程序,如BCL的DataContractSerializer?

提前致谢

nservicebus xml-serialization

4
推荐指数
1
解决办法
4635
查看次数