def ParseSessionIdAndStartTime(sessionId):
  # NOTE: If the session ID looks too much like a serialized json date/time then the deserializer will
  #       deserialize it into a date/time object, which is undesirable in this case.
  #       Hence the addition of the surrounding angle brackets to thwart this behaviour.
  haveSessionId = (sessionId is not None and (sessionId.StartsWith("<") and sessionId.EndsWith(">")))

  if haveSessionId:
    sessionStartTime = time_util.GetDateTimeUtcFromISO8601FormattedDate(sessionId[1:-1])
  else:
    sessionStartTime = time_util.GetDateTimeUtcNow()
    sessionId = "<" + time_util.GetISO8601FormattedUtcDate(sessionStartTime) + ">"
  return sessionId, sessionStartTime
Beispiel #2
0
            def monitoringAction():
                pendingProcessOutputReadLineTask[0] = ShowRevitProcessOutput(
                    hostRevitProcess.StandardOutput, output,
                    pendingProcessOutputReadLineTask[0])
                pendingProcessErrorReadLineTask[0] = ShowRevitProcessError(
                    hostRevitProcess.StandardError,
                    showRevitProcessErrorMessages, output,
                    pendingProcessErrorReadLineTask[0])
                pendingReadLineTask[0] = ShowRevitScriptOutput(
                    scriptOutputStreamReader, output, pendingReadLineTask[0])

                if time_util.GetSecondsElapsedSinceUtc(
                        progressRecordCheckTimeUtc[0]
                ) > REVIT_PROGRESS_CHECK_INTERVAL_IN_SECONDS:
                    progressRecordCheckTimeUtc[
                        0] = time_util.GetDateTimeUtcNow()
                    progressRecordNumber = ScriptDataUtil.GetProgressNumber(
                        progressRecordFilePath)
                    if progressRecordNumber is not None:
                        if currentProgressRecordNumber[
                                0] != progressRecordNumber:
                            # Progress update detected.
                            currentProgressRecordNumber[
                                0] = progressRecordNumber
                            progressRecordChangedTimeUtc[
                                0] = time_util.GetDateTimeUtcNow()

                if processingTimeOutInMinutes > 0:
                    if currentProgressRecordNumber[0] != 0:
                        if time_util.GetSecondsElapsedSinceUtc(
                                progressRecordChangedTimeUtc[0]) > (
                                    processingTimeOutInMinutes *
                                    SECONDS_PER_MINUTE):
                            output()
                            output(
                                "WARNING: Timed-out waiting for Revit task / file to be processed. Forcibly terminating the Revit process..."
                            )
                            TerminateHostRevitProcess(hostRevitProcess, output)

                if currentProgressRecordNumber[0] == 0:
                    if time_util.GetSecondsElapsedSinceUtc(
                            progressRecordChangedTimeUtc[0]
                    ) > REVIT_PROCESS_BEGIN_PROCESSING_TIMEOUT_IN_SECONDS:
                        output()
                        output(
                            "WARNING: Timed-out waiting for Revit script host to begin task / file processing. Forcibly terminating the Revit process..."
                        )
                        TerminateHostRevitProcess(hostRevitProcess, output)

                if snapshotDataFilesExistTimestamp[0] is not None:
                    if time_util.GetSecondsElapsedSinceUtc(
                            snapshotDataFilesExistTimestamp[0]
                    ) > REVIT_PROCESS_EXIT_TIMEOUT_IN_SECONDS:
                        output()
                        output(
                            "WARNING: Timed-out waiting for the Revit process to exit. Forcibly terminating the Revit process..."
                        )
                        TerminateHostRevitProcess(hostRevitProcess, output)
                elif snapshotDataFilePaths.All(
                        lambda snapshotDataFilePath: File.Exists(
                            snapshotDataFilePath)):
                    output()
                    output(
                        "Detected snapshot data files. Waiting for Revit process to exit..."
                    )
                    snapshotDataFilesExistTimestamp[
                        0] = time_util.GetDateTimeUtcNow()

                try:
                    revit_dialog_detection.DismissCheekyRevitDialogBoxes(
                        hostRevitProcessId, output)
                except Exception, e:
                    output()
                    output(
                        "WARNING: an error occurred in the cheeky Revit dialog box dismisser!"
                    )
                    exception_util.LogOutputErrorDetails(e, output)
Beispiel #3
0
        def streamReaderAction():
            scriptOutputPipeHandleString = serverStream.GetClientHandleAsString(
            )

            def clientHandleAction():
                hostRevitProcess = revit_process_host.StartHostRevitProcess(
                    revitVersion, batchRvtScriptsFolderPath, scriptFilePath,
                    scriptDataFilePath, progressNumber,
                    scriptOutputPipeHandleString, testModeFolderPath)
                return hostRevitProcess

            hostRevitProcess = UsingClientHandle(serverStream,
                                                 clientHandleAction)

            hostRevitProcessId = hostRevitProcess.Id

            global_test_mode.ExportRevitProcessId(hostRevitProcessId)

            snapshotDataFilePaths = [
                snapshot_data_util.GetSnapshotDataFilePath(
                    scriptData.DataExportFolderPath.GetValue())
                for scriptData in scriptDatas
            ]

            pendingReadLineTask = [
                None
            ]  # Needs to be a list so it can be captured by reference in closures.
            pendingProcessOutputReadLineTask = [None]  # As above.
            pendingProcessErrorReadLineTask = [None]  # As above.

            snapshotDataFilesExistTimestamp = [
                None
            ]  # Needs to be a list so it can be captured by reference in closures.

            currentProgressRecordNumber = [
                0
            ]  # Needs to be a list so it can be captured by reference in closures.
            progressRecordCheckTimeUtc = [time_util.GetDateTimeUtcNow()
                                          ]  # As above.
            progressRecordChangedTimeUtc = [time_util.GetDateTimeUtcNow()
                                            ]  # As above.

            def monitoringAction():
                pendingProcessOutputReadLineTask[0] = ShowRevitProcessOutput(
                    hostRevitProcess.StandardOutput, output,
                    pendingProcessOutputReadLineTask[0])
                pendingProcessErrorReadLineTask[0] = ShowRevitProcessError(
                    hostRevitProcess.StandardError,
                    showRevitProcessErrorMessages, output,
                    pendingProcessErrorReadLineTask[0])
                pendingReadLineTask[0] = ShowRevitScriptOutput(
                    scriptOutputStreamReader, output, pendingReadLineTask[0])

                if time_util.GetSecondsElapsedSinceUtc(
                        progressRecordCheckTimeUtc[0]
                ) > REVIT_PROGRESS_CHECK_INTERVAL_IN_SECONDS:
                    progressRecordCheckTimeUtc[
                        0] = time_util.GetDateTimeUtcNow()
                    progressRecordNumber = ScriptDataUtil.GetProgressNumber(
                        progressRecordFilePath)
                    if progressRecordNumber is not None:
                        if currentProgressRecordNumber[
                                0] != progressRecordNumber:
                            # Progress update detected.
                            currentProgressRecordNumber[
                                0] = progressRecordNumber
                            progressRecordChangedTimeUtc[
                                0] = time_util.GetDateTimeUtcNow()

                if processingTimeOutInMinutes > 0:
                    if currentProgressRecordNumber[0] != 0:
                        if time_util.GetSecondsElapsedSinceUtc(
                                progressRecordChangedTimeUtc[0]) > (
                                    processingTimeOutInMinutes *
                                    SECONDS_PER_MINUTE):
                            output()
                            output(
                                "WARNING: Timed-out waiting for Revit task / file to be processed. Forcibly terminating the Revit process..."
                            )
                            TerminateHostRevitProcess(hostRevitProcess, output)

                if currentProgressRecordNumber[0] == 0:
                    if time_util.GetSecondsElapsedSinceUtc(
                            progressRecordChangedTimeUtc[0]
                    ) > REVIT_PROCESS_BEGIN_PROCESSING_TIMEOUT_IN_SECONDS:
                        output()
                        output(
                            "WARNING: Timed-out waiting for Revit script host to begin task / file processing. Forcibly terminating the Revit process..."
                        )
                        TerminateHostRevitProcess(hostRevitProcess, output)

                if snapshotDataFilesExistTimestamp[0] is not None:
                    if time_util.GetSecondsElapsedSinceUtc(
                            snapshotDataFilesExistTimestamp[0]
                    ) > REVIT_PROCESS_EXIT_TIMEOUT_IN_SECONDS:
                        output()
                        output(
                            "WARNING: Timed-out waiting for the Revit process to exit. Forcibly terminating the Revit process..."
                        )
                        TerminateHostRevitProcess(hostRevitProcess, output)
                elif snapshotDataFilePaths.All(
                        lambda snapshotDataFilePath: File.Exists(
                            snapshotDataFilePath)):
                    output()
                    output(
                        "Detected snapshot data files. Waiting for Revit process to exit..."
                    )
                    snapshotDataFilesExistTimestamp[
                        0] = time_util.GetDateTimeUtcNow()

                try:
                    revit_dialog_detection.DismissCheekyRevitDialogBoxes(
                        hostRevitProcessId, output)
                except Exception, e:
                    output()
                    output(
                        "WARNING: an error occurred in the cheeky Revit dialog box dismisser!"
                    )
                    exception_util.LogOutputErrorDetails(e, output)

                return