Hi Folks,



Need to do recalculations of 137 contexts for time-period of more than 1 month, and because of frequent requirement of these I needed some solution which can do this on my manual efforts behalf.



From the help provided on this thread, I could generate the code which helped me to complete the task . I found myself hard to find this code, so I am posting here code with tweak of few lines to have involved more than 1 module.


Code has comments also which are helpful in understanding.



Your Module Database look like as follows in PI SMT:

Use following code as a reference to do recalculation on the module(modules) you chose:

Imports PIACE
Imports PIACECommon

Public Class Form1

    Dim piAceMgmt As New PIACEModuleDBFunctions

    Dim startTime As Double    Dim endTime As Double
    Dim strContextPath As String
    Dim Output As Boolean

    Dim piDataArchiveName As String
    Dim aceExecutable As String
    Dim aceClassName As String
    Dim aceContextNames() As String = {"<Path_of_your_module>"} ' For more than 1 modules add as {"Module1_Path","Module2_Path"}

    ' Recalculate button event
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnRecalculate.Click

        ' Get time in UTC seconds format
        ' For confirmation you can match the below variables values on http://www.epochconverter.com/
        startTime = DateDiff("S", "01/01/1970 00:00:00", "10/14/2016 12:10:00")
        endTime = DateDiff("S", "01/01/1970 00:00:00", "10/17/2016 10:00:00")

        ' Refer image shown above  
        piDataArchiveName = "PI_Data_Archive"  
        aceExecutable = "A"  
        aceClassName = "B"

        piAceMgmt.SetACENet = True 'Ignore if you are using ACE 1.x scheduler

        Dim count As Integer = 0 ' To check if all contexts have been recalculated or not

        For i = 0 To aceContextNames.Length - 1
            aceContextName = aceContextNames(i)

            ' for PI ACE v.2.1.50 on target machine, strContextPath is  
            ' PI Data Archive name\scheduler name\executable name\Class name\context name  
            strContextPath = "\\" + piDataArchiveName + "\" + "default" + "\" + aceExecutable + "\" + aceClassName + "\" + aceContextName

            ' for previous PI ACE versions, strContextPath is  
            ' PI Data Archive name\executable name\Class name\context name  
            'strContextPath = "\\" + piDataArchiveName + "\" + aceExecutable + "\" + aceClassName + "\" + aceContextName

            'If Output value is true, than your recalculation has been executed
            '   false, then problem in the strContextPath, and if not then vCampus is here

                Output = piAceMgmt.AddManualRecalculation(strContextPath, startTime, endTime)

                If (Output = True) Then
                    Debug.WriteLine("Completed:" + aceContextNames(i))
                    count = count + 1
                    Debug.WriteLine("Not Completed:" + aceContextNames(i))
                End If
            Catch ex As Exception
                Debug.WriteLine("Error:" + ex.Message)
            End Try

        If (aceContextNames.Length = count) Then
            Debug.WriteLine("Completed with errors !!!")
        End If

    End Sub

End Class


Happy Learning !!!


- Paurav Joshi