-->

VB.Net方法似乎被多次调用时,它实际上是没有,并返回不一致的结果(VB.Net Method a

2019-10-20 10:35发布

我已经在这个问题整天一直盯着,我完全被我所看到百思不得其解。 有出现两个问题,不幸的是,其中一人只发生在生产,所以我不能测试它,我想的方式。

我会给所有的背景和相关的信息前面,并在最后的代码。 直到您查看代码的一些什么,我在今后的几个部分说将没有多大意义。

背景信息:
(我有三重验证所有这些信息)

  1. 这个类正在从TFS 2010 WWF构建模板调用。 它依赖于我在另一个工具创建的文件部署到使用UniDK我们的宇宙环境中的图书馆
  2. 本身工作正常部署,问题是记录和返回代码。
  3. 构建被标记为“成功”,如果低于类返回0码,“部分成功”为1的返回代码,和“失败”,如果有任何其他返回代码。
  4. 该文件只部署一个时间(objDeploy.DeployFiles()只调用一次)
  5. serverInfo.ServerCount = 2
  6. serverInfo.ServerActive为第二环境(计数器= 1)为假
  7. 为了帮助追查的问题,我已经在ProcessResults()来输出不同集合到一个单独的文件的值增加了额外的日志记录,但我还没有与额外的代码运行的机会

症状:

  1. 在生产中,它与返回代码退出1(EXITCODE = 1)
  2. 这是由结果返回的字符串:

结果服务器名称
部署成功了!
***********************
结果服务器名称
部署成功了!
***********************
结果服务器名称
部署错误,请查看日志
***********************
结果服务器名称
部署成功了!
***********************
结果服务器名称
部署成功了!
***********************
3.在质量保证,我们有消息6倍“的服务器名称的结果”,但每次说的部署成功
4.在部署日志文件中的一切显示所有文件部署0返回代码(这意味着Result40Collection,BackupErrorCollection和BadErrorCollection应该是空的。我会在某一时刻解释为什么这一点尤其显著)

我希望发生:

  1. EXITCODE = 0
  2. 构建=成功
  3. 结果:

结果服务器名称
部署成功了!
***********************

我希望发生基于TFS生成日志的结果:在本节中,我忽略了一个事实,有返回多个条目,只聚焦于说有错误的一个

  1. EXITCODE = 2
  2. 构建=失败
  3. 结果:

结果服务器名称
部署错误,请查看日志
***********************

码:

Imports System
Imports Microsoft.TeamFoundation.Build.Client
Imports System.Activities
Imports RMUtilities

<BuildActivity(HostEnvironmentOption.All)>
Public NotInheritable Class DeployU2Files
    Inherits CodeActivity

#Region "Arguments"

    ' In Arguments
    Property inServerDataSet As InArgument(Of DataSet)  ' Dataset containing the server information
    Property inSourcesDirectory As InArgument(Of String)  ' Full path to the Source directory being deployed
    Property inBuildName As InArgument(Of String) ' Name of the build, to be used for backups
    Property inLogDirectory As InArgument(Of String) ' Path to the log folder

    ' Out Arguments
    Property outExitCode As OutArgument(Of Integer) ' Resulting error code, 0 is good
    Property outResult As OutArgument(Of String)     ' Result string

#End Region ' "Arguments"

#Region "Variables"

    ' Variables passed in from the build
    Dim dsServerDataSet As DataSet
    Dim strSourcesDirectory As String
    Dim strBuildName As String
    Dim strLogDirectory As String

    ' Variables used by the build
    Dim serverInfo As XMLReader
    Dim fileList As U2FileListParser

    ' Result variables
    Dim exitCode As Integer = 0
    Dim results As String = ""

#End Region '"Variables"

    Protected Overrides Sub Execute(context As System.Activities.CodeActivityContext)

        ' Sets the working variables
        dsServerDataSet = context.GetValue(Me.inServerDataSet)
        strSourcesDirectory = context.GetValue(Me.inSourcesDirectory)
        strBuildName = context.GetValue(Me.inBuildName)
        strLogDirectory = context.GetValue(Me.inLogDirectory)

        ' Creates the base objects needed for the deployment
        Try
            serverInfo = New XMLReader(dsServerDataSet)
            fileList = New U2FileListParser(strSourcesDirectory)
        Catch ex As NullReferenceException
            Throw New NullReferenceException("Invalid XML Dataset", ex)
            Exit Sub
        Catch ex As Exception
            Throw New Exception("Error processing file list: " & ex.Message, ex)
        End Try

        ' First, determine if there are files to deploy
        Dim fileCount As Integer
        Try
            With fileList
                fileCount = .DeployList.Count + .PreDeployList.Count + .PostDeployList.Count
            End With
        Catch ex As Exception
            Throw New ArgumentException("No files to deploy")
        End Try
        If fileCount = 0 Then Throw New ArgumentException("No files to deploy")

        ' Then, check to make sure there are servers to deploy to
        If serverInfo.ServerCount = 0 Then
            Throw New ArgumentException("No servers listed in XML file to deploy to")
        End If

        ' Iterates through each server in the XML file
        For counter = 0 To serverInfo.ServerCount - 1

            ' Sets the current environment
            serverInfo.ChosenEnvironment = counter

            ' Checks to make sure the server is active.  If it isn't, it's skipped
            If serverInfo.ServerActive Then

                ' Creates new logging object to log all output to a file with the name of the server being deployed to
                Dim logger = New RMLogging(strLogDirectory & "\" & serverInfo.ServerHostName & ".log")
                logger.Header = "Automated deploy" & vbCrLf & _
                    "Build Number: " & strBuildName & vbCrLf & _
                    "Date: " & DateTime.Now.ToString("MMM ddd d yyyy hh:mm:ss tt")

                ' Creates the deployment object
                Dim objDeploy As New U2Deploy(serverInfo, fileList, logger, strBuildName)

                ' Deploys the files to the environment, then checks the results to make sure they
                objDeploy.DeployFiles()

                ' This will determine the success level of the deployment, and also parses the message for the log
                ProcessResults(objDeploy, serverInfo.ServerHostName)

                ' If there was a problem writing the log, then add the full text of the log to the results
                If objDeploy.FullLog.Length > 0 Then
                    results &= objDeploy.FullLog & vbCrLf
                    results &= "**********************************" & vbCrLf
                End If ' objDeploy.FullLog.Length > 0

                ' Disposes the objects
                logger = Nothing
                objDeploy.Clear()
                objDeploy = Nothing

            End If ' serverInfo.ServerActive

        Next ' counter = 0 To serverInfo.ServerCount - 1

        SetResults(exitCode, results, context)

    End Sub

    ''' <summary>
    ''' Will change the exite code based on the results of the deployment
    ''' </summary>
    ''' <param name="objDeploy">U2Deploy object that contains the collections</param>
    ''' <remarks></remarks>
    Private Sub ProcessResults(objDeploy As U2Deploy, serverName As String)

        Dim currentErrorCode As Integer = 0


        results &= "Results for " & serverName & vbCrLf

        If objDeploy.Result40Collection.Count() > 0 Then
            currentErrorCode = 1
            results &= "Type 40 errors, please review the log" & vbCrLf
        End If ' objDeploy.Result40Collection.Count() > 0

        If objDeploy.BackupErrorCollection.Count > 0 Then
            currentErrorCode = 1
            results &= "File backup errors, please review the log" & vbCrLf
        End If ' objDeploy.BackupErrorCollection.Count > 0

        If objDeploy.BadErrorCollection.Count > 0 Then
            currentErrorCode = 2
            results &= "Deployment errors, please review the log" & vbCrLf
        End If

        If currentErrorCode = 0 Then results &= "Deployment successful!" & vbCrLf

        results &= "***********************" & vbCrLf

        If currentErrorCode > exitCode Then exitCode = currentErrorCode
    End Sub

    ' Sets the outgoing message and exit code.  This is used by the workflow to add messages to the buld itself
    Private Sub SetResults(ByVal exitCode As Int32, message As String, ByRef context As CodeActivityContext)

        context.SetValue(Me.outExitCode, exitCode)
        context.SetValue(Me.outResult, message)

    End Sub
End Class

更新:我已经能够在QA具有详细记录运行此两次开启,这里的结果(同样,完全不相符)。 我使用VS2013只能查看和运行构建,通过构建使用任何代码更改类VS2010中完成。

运行1:

运行2:

Answer 1:

其实我只是有一个解决这一昨晚。 这个问题实际上是与我曾在WWF过程阅读文档。 此代码实际上是正确地执行,并返回正确的价值观,但由于不正确的说明,这是走错路的工作流程,这使得它看起来,这段代码是错误的。

我花了一段时间与诊断日志功能再次出现这个错误,有一次我看到它,我就知道问题是什么,立即。

根本原因是,我的印象是为失败WriteBuildError将标志着打造下,而是将其标记为部分成功,这让我错了故障路径上。



文章来源: VB.Net Method appears to be called multiple times when it actually isn't, and returns inconsistent results