小编stt*_*taq的帖子

在Java中使用Enum工厂是最佳实践吗?

Java允许我们在Enum上嵌入数据和行为.我不想直接在Enum上实现工厂,因为我认为这不是它的作用.

但我可以在枚举上放置类引用,并在外部工厂上构造对象.与传统工厂模式相比,您的最佳实施方案是什么?在哪种情况下哪种解决方案更好用?

现在,代码.

两种解决方案中用于构造对象的函数.如果需要,可以使用Map实现fly-weight模式.

private Action getAction(Class<? extends Action> actionClazz) {
    // logger + error handling
    return actionClazz.newInstance();
}
Run Code Online (Sandbox Code Playgroud)

1)与传统工厂:

public enum ActionEnum {
    LOAD_DATA,
    LOAD_CONFIG;
}

public Action getAction(ActionEnum action) {
    switch (action) {
    case LOAD_CONFIG:
        return getAction(ActionLoadConfig.class);
    case LOAD_DATA:
        return getAction(ActionLoadData.class);
    }
}
Run Code Online (Sandbox Code Playgroud)

2)使用Enum风格的工厂:

public enum ActionEnum {
    LOAD_DATA(ActionLoadConfig.class),
    LOAD_CONFIG(ActionLoadData.class);

    public ActionEnum(Class<? extends Action> clazz){...}
    public Class<? extends Action> getClazz() {return this.clazz}
}

public Action getAction(ActionEnum action) {
    return getAction(action.getClazz());
}
Run Code Online (Sandbox Code Playgroud)

java enums factory

24
推荐指数
4
解决办法
2万
查看次数

wix HeatDirectory ServiceInstall

我正在使用HeatDirectory来创建源.wxs文件.在拾取目录中有一个exe应该作为服务安装.实际上,如果我自己创建组件,我知道如何安装服务,但我不知道如何在自动生成的组件中包含ServiceInstall.有什么建议吗?

        <HeatDirectory DirectoryRefId="Guardian" OutputFile="Source\GuardianSource.wxs" Transforms="Filter.xsl" Directory="..\Setup\C24.Guardian\bin\Debug" PreprocessorVariable="var.GuardianPath" ComponentGroupName="GuardianGroup" ToolPath="$(WixToolPath)" SuppressCom="true" SuppressFragments="true" SuppressRegistry="true" SuppressRootDirectory="true" AutoGenerateGuids="true" GenerateGuidsNow="false">
    </HeatDirectory>



<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
    <DirectoryRef Id="Guardian">
        <Component Id="cmp70BEDA00F3161F3FB5E847EB1136B1D5" Guid="*">
            <File Id="fil26DCBF1E4218C7363018FBA2CD456633" KeyPath="yes" Source="$(var.GuardianPath)\C24.Guardian.exe" />
        </Component>
        <Component Id="cmp2EE8126A193FA022ED35FAD8F182E65A" Guid="*">
            <File Id="fil785CD681C496EDDAB457E8314C49D686" KeyPath="yes" Source="$(var.GuardianPath)\C24.Guardian.exe.config" />
        </Component>
        <Component Id="cmp0CC91B457FBC44F978A2AD6B24043DCF" Guid="*">
            <File Id="fil2D304D0395599AAAAAF975A2DBFD530F" KeyPath="yes" Source="$(var.GuardianPath)\C24.Guardian.pdb" />
        </Component>
        <Component Id="cmpFB799FA015274DDBE2C337C60667D2C5" Guid="*">
            <File Id="filB9C39B394CAD03F5A1BC3262C61EDDEB" KeyPath="yes" Source="$(var.GuardianPath)\C24.Guardian.vshost.exe" />
        </Component>
        <Component Id="cmp28C29865AE85B067BCEEBD70EFDB19D5" Guid="*">
            <File Id="fil0A756B711769AAD657F306B3A6EA7134" KeyPath="yes" Source="$(var.GuardianPath)\C24.Guardian.vshost.exe.config" />
        </Component>
        <Component Id="cmp92A715A4BD4B580A6E70362230170428" Guid="*">
            <File Id="filBD9D504F303A6EEC9E340E3872BBB0AE" KeyPath="yes" Source="$(var.GuardianPath)\C24.Guardian.vshost.exe.manifest" />
        </Component>
        <Component Id="cmp8AB6A241FA2D13F296CBD946C9711579" …
Run Code Online (Sandbox Code Playgroud)

wix heat

13
推荐指数
2
解决办法
3959
查看次数

.Net中的自定义安装程序显示安装程序后面的表单

[RunInstaller(true)]
public partial class Installer1 : Installer
{
    public Installer1()
    {
        InitializeComponent();
    }

    public override void Install(System.Collections.IDictionary stateSaver)
    {
        base.Install(stateSaver);
    }
    private void Installer1_AfterInstall(object sender, InstallEventArgs e)
    {
        Form1 topmostForm = new Form1();
        topmostForm.BringToFront();
        topmostForm.TopMost = true;            
        topmostForm.ShowDialog();
  } }
Run Code Online (Sandbox Code Playgroud)

我需要在默认的Windows Installer UI前面显示topmostForm.以上是我用于创建表单的CustomAction中的示例代码.设置TopMost属性或使用ShowDialog没有帮助.有没有其他解决方案可以让我的表格成为最重要的?

c# installer windows-installer custom-action winforms

8
推荐指数
1
解决办法
7652
查看次数

ICE03:字符串溢出(大于列中允许的长度); 表:CustomAction

我收到以下代码的ICE03:字符串溢出警告:

<CustomAction Id="CustomActionID"
          Return="check"
          Property="SomeProperty"
          Value="VERY LONG STRING COMES HERE"
          Execute="immediate"/>
Run Code Online (Sandbox Code Playgroud)

此代码包含在片段中的单独.wxs文件中.如果我将其直接包含在"Product"标签中,则警告消失.使用以下代码也会发生这种情况:

<Binary Id="SomeBinaryWithAVeryLongName" SourceFile="SOURCEFILE" />
Run Code Online (Sandbox Code Playgroud)

我想知道为什么会这样?

wix wix3.7

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

表单身份验证cookie未过期

我正在尝试为MVC站点实现一个非常基本的Asp.net表单身份验证机制.我得到的问题是我的身份验证cookie设置为在一年后过期,而我不希望它在这么长时间后过期.这是我的一些代码:

web.config中

<authentication mode="Forms">
  <forms loginUrl="~/Account/Login" timeout="2" />
</authentication>
Run Code Online (Sandbox Code Playgroud)

调节器

...
FormsAuthentication.SetAuthCookie(username, false);
...
Run Code Online (Sandbox Code Playgroud)

我找到了这个答案(这个问题类似,但在我的情况下,超时永远不会发生),但这是使cookie过期或我在这里做错了什么的唯一方法吗?

当我查看cookie时,它会在一年后过期,即使它会在几分钟后过期,为什么呢?

我想要的是某种程度上用户在一段时间后退出并且我认为在forms标签中设置过期会完成这项工作吗?

asp.net-mvc forms-authentication asp.net-mvc-4

3
推荐指数
1
解决办法
7257
查看次数

詹金斯没有运行任何作业

我在尝试解决其他一些问题时成功地破坏了詹金斯。现在,每当我运行作业时,它都会立即失败并出现以下错误:

java.lang.NullPointerException
at java.util.TreeMap.putAll(TreeMap.java:313)
at hudson.slaves.EnvironmentVariablesNodeProperty.buildEnvVars(EnvironmentVariablesNodeProperty.java:85)
at hudson.model.Computer.buildEnvironment(Computer.java:1195)
at hudson.model.Job.getEnvironment(Job.java:385)
at hudson.model.Run.getEnvironment(Run.java:2419)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.getEnvironment(WorkflowRun.java:500)
at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:112)
at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:68)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:310)
at hudson.model.ResourceController.execute(ResourceController.java:99)
at hudson.model.Executor.run(Executor.java:432)
Finished: FAILURE
Run Code Online (Sandbox Code Playgroud)

我找到了这个答案Jenkins - Problem: hudson.model.Queue$MaintainTask failed但它建议重写config.xml文件。当我这样做并从磁盘重新加载配置时,config.xml文件会被詹金斯覆盖。我已将 jenkins 升级到最新可用版本,并更新了大部分插件。我还尝试通过 UI 添加回环境变量,但这样做会引发以下异常:

2022-01-06 17:21:50.894+0000 [id=10]    WARNING o.e.j.s.h.ContextHandler$Context#log: Error while serving https://<jenkins-url>:<port>/configSubmit
java.lang.ClassCastException: java.lang.Integer cannot be cast to hudson.model.Describable
        at hudson.util.DescribableList.get(DescribableList.java:126)
        at hudson.util.DescribableList.rebuild(DescribableList.java:168)
        at jenkins.model.GlobalNodePropertiesConfiguration.configure(GlobalNodePropertiesConfiguration.java:25)
        at jenkins.model.Jenkins.configureDescriptor(Jenkins.java:3846)
        at jenkins.model.Jenkins.doConfigSubmit(Jenkins.java:3810)
        at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
        at org.kohsuke.stapler.Function$MethodFunction.invoke(Function.java:396)
Caused: java.lang.reflect.InvocationTargetException
        at org.kohsuke.stapler.Function$MethodFunction.invoke(Function.java:400)
        at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:408)
        at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:212)
        at …
Run Code Online (Sandbox Code Playgroud)

jenkins

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