Option Compare Text
Imports Microsoft.VisualBasic
Imports System
Imports System.IO
Imports System.Collections.Generic
Imports System.Data

Imports JF.PlmJobManager.JobServer
Imports JF.Tools 
Imports JF.PlmJobManager



' Imports JF.ScriptingEngine


'' Information for developer:
'' All Lines with mark "##" should be edit by the developer

'' # ---------------------------------------------------------------------------------------
'' # Documentation:
'' # Description  : ## please add the description for this script in this line
'' # Parameters   : ## /Para1=MyPara1 /Para2=MyPara2  

'' # History:
'' # Date         Person        ChangeInfo
'' # ##12.04.2007 ##Developer   createt
'' # ---------------------------------------------------------------------------------------

Namespace JS_ScriptingTemplate
	
    Public Class ScriptingEngineClass2

		Private Debug_NLog as NLog.Logger 

		Private MyScriptOutput_frm As JobServer_ScriptRun_frm

        Public Sub ParseResultFromFile(ByVal FileToParseResultsFrom_DPNE As String)
            Me.MyScriptOutput_frm.InfoSysHeader.PrintInfoLine("FileToParseResultsFrom_DPNE:" + FileToParseResultsFrom_DPNE)
		End Sub


		Dim	DataSource_Obj As New MyAppl_DataSource_cls("XX")
		
        Public Function ScriptMain(ByVal JS_ScriptingInterface As ScriptingInterface.Methodes) As JF_Return_cls

            ' Required class for returning script results
            Dim MyScriptReturn As New JF_Return_cls
            Dim MyCallReturn As New JF_Return_cls
			Dim TextStr As String = ""
			Dim Text_str As String 
            Dim I As Integer
			Dim DebugUse As Boolean = False
			
			MyScriptOutput_frm = New JobServer_ScriptRun_frm(JS_ScriptingInterface.ScriptDef)
			MyScriptOutput_frm.InfoSysProtocol.PrintTrennStrich()
			
			
			'-- Step Read from TC IrPuid 
			Dim TcDbConnection as System.Data.Common.DbConnection 
			Dim SiteDef_Obj As New SiteDef_cls
			'-- #Step: Read SiteDef
			'MyScriptOutput_frm.Pause("1. SiteDef_Obj.SiteInfoWith_SiteId_and_pName:" + " " + SiteDef_Obj.DBProvider_enum.ToString)
			SiteDef_Obj = DataSource_Obj.Sites_tbl_SiteDefGet_by_SiteId("HIL_QS")
			MyScriptOutput_frm.Show 
			'MyScriptOutput_frm.Pause("1. SiteDef_Obj.SiteInfoWith_SiteId_and_pName:" + " " + SiteDef_Obj.SiteInfoWith_SiteId_and_pName)
			
			'Dim TcDataTool_Obj as New TcDataTool_cls(SiteDef_Obj, DataSource_Obj)
			'Dim TcDataTool_Obj as New TcDataTool_cls("HIL_QS")
			'Dim Ir_Obj as new Ir_cls
			'Ir_Obj.ir_puid = TcDataTool_Obj.IrPuid_get_from_Tc("65010000029","000",Ir_Obj.i_puid)
			
			Dim Datasets_and_Irs_Obj as new Datasets_and_Irs_cls
			
			Datasets_and_Irs_Obj = DataSource_Obj.MyObjectData_ReadFromDB("HIL_QS","65010000029","000","65010000029_000",NameMapping.UGDataSetTypes_MapTcCliName("MASTER",JF.PlmJobManager.JobServer.NameMapping.UGDataSetTypes_MapTcCli_Enum.Cli_To_Tc))    
			
			' Dim TcDataTool_Obj as New TcDataTool_cls(SiteDef_Obj, TcDbConnection, DataSource_Obj)
											
			'TcDataTool_Obj.IrPuid_get_from_Tc(KuA_Data.Target_Item,KuA_Data.Target_Rev,Target_Obj.IrPuid) 
			
			MyScriptOutput_frm.Pause("Datasets_and_Irs_Obj.IrPuid:" + " " + Datasets_and_Irs_Obj.IrPuid)
			
			goto EndOfScript:

			Debug_NLog = NLog.LogManager.GetLogger("Stript.Test")
			Debug_NLog.Debug("##Debug Msg:")
			Debug_NLog.Debug("##Debug Msg:xxx")

			'- using "standard form" for printing script informations 
			MyScriptOutput_frm = New JobServer_ScriptRun_frm(JS_ScriptingInterface.ScriptDef)
            MyScriptOutput_frm.Show()

			'- for printing Informations to the header textbox 
			Me.MyScriptOutput_frm.InfoSysHeader.PrintInfoLine("Step - 1 Script started")
			
			'Debug_NLog.Debug("Me.MyScriptOutput_frm.InfoSysHeader.PrintString:{0}", Me.MyScriptOutput_frm.InfoSysHeader.PrintString)

			'- Handling Exeptions
			Try
                '-- parsing parameters 
                Dim NewFileBasedJobsSearchInDIR As String = JS_ScriptingInterface.ParameterValueGet("NewFileBasedJobsSearchInDIR")
				
                Text_str = _
                             "Script started with parameters:" + vbCrLf + _
                                         "[" + JS_ScriptingInterface.ParameterStr + "]" + vbCrLf + _
                                         vbCrLf + _
                             "/NewFileBasedJobsSearchInDIR=" + NewFileBasedJobsSearchInDIR + vbCrLf + _
                             vbCrLf + _
                             "..\10-JobLogArchiv :" + vbCrLf + _
                                         "[" + JS_ScriptingInterface.ServerSettings.Dir_DataRoot_DP_10JobLogArchiv + "]"


                '-- starting the progress bar
                Me.MyScriptOutput_frm.InfoSysProtocol.StatusBarProgressBarStart()

                Select Case JS_ScriptingInterface.JobDefCurrJob.JobDef.JobServerScript_RunCondition

                    Case ScriptingDef.RunCondition_enum.Cond01_GenNewJob_Bevor_SelectObjectData
                        '-- Aktion vor Selection der Objekt Daten:
                        With JS_ScriptingInterface.JobDefCurrJob.JobDef.JobFiles
                            '-- erstellt ein File der dem JobFiles hinzugefügt wird
                            '-- Info der File wird im Speicher erzeugt und beim erstellen den JobPacket(.Zip) File hinzugefügt (Neu 9.8.2010)
                            'Dim fileToAdd_DPNE As String = Path.Combine(JS_ScriptingInterface.JobDefCurrJob.JobDef.JobFiles.JobDestRootDir_DP, "_MySpecialJobFile.txt")
                            Dim JobCustomFile As New JobFile_cls.JobCustomFileDef_cls("TEST", "_MySpecialJobFile.txt")
                            JobCustomFile.File_TEXT = "TEST" + vbCrLf + "..\" + JobCustomFile.File_NE
                            .JobCustomFiles.Add(JobCustomFile)
                            'File.WriteAllText(fileToAdd_DPNE, "TEST" + vbCrLf + fileToAdd_DPNE)
                            MyScriptOutput_frm.InfoSysProtocol.Print("..\" + JobCustomFile.File_NE)
                        End With

                        ' suche nach Files in einem bestimmten Verzeichniss:
                        Dim FileList As System.Collections.ObjectModel.ReadOnlyCollection(Of String)
                        FileList = My.Computer.FileSystem.GetFiles(NewFileBasedJobsSearchInDIR, FileIO.SearchOption.SearchAllSubDirectories, "*.XML")

                        If FileList.Count > 0 Then
                            Me.ParseResultFromFile(NewFileBasedJobsSearchInDIR)
                            MyScriptOutput_frm.InfoSysProtocol.Print("List of Files to process:")
                            For Each FileItem_DPNE As String In FileList
                                MyScriptOutput_frm.InfoSysProtocol.Print(FileItem_DPNE)
                            Next
                            '-- Vorgaben fuer weiteres Verhalten einstellen: "JobPaket an den Client senden:Yes"
                            JS_ScriptingInterface.JobDefCurrJob.JobDef.JobControlRule.JobControlInterface.JobPaket_SendToJobClient = True
                        Else
                            MyScriptOutput_frm.InfoSysProtocol.Print("No Files to process:")
                            '-- Vorgaben fuer weiteres Verhalten einstellen: "JobPaket an den Client senden:No"
                            JS_ScriptingInterface.JobDefCurrJob.JobDef.JobControlRule.JobControlInterface.JobPaket_SendToJobClient = False
                        End If

                        '-- Vorgaben fuer weiteres Verhalten einstellen: "Keine Objekte selectieren lassen"
                        JS_ScriptingInterface.JobDefCurrJob.JobDef.JobControlRule.JobControlInterface.SelectObjects_ViaJobRule = False
                        '-- Vorgaben fuer weiteres Verhalten einstellen: "JobPaket an den Client senden"
                        JS_ScriptingInterface.JobDefCurrJob.JobDef.JobControlRule.JobControlInterface.JobPaket_SendToJobClient_AlsoWennObjektPaketEmty = False

                    Case ScriptingDef.RunCondition_enum.Cond02_GenNewJob_After_SelectObjectData
                        '-- Aktion wenn Daten selectiert wurden -> Bietet die Möglchkeit ermittelte Daten zu verwenden oder zu bearbeiten

                    Case ScriptingDef.RunCondition_enum.Cond10_JobResults_Get
                        '-- Aktion wenn das Ergebniss vom JobClient an den JobServer zurück übermittelt wird

                End Select

            Catch ex As Exception
                MyScriptReturn.Ex = ex
                MyScriptReturn.ExUp = True
                MyScriptReturn.ExMsg = "ScriptTemplate"
                MyScriptOutput_frm.InfoSysProtocol.PrintEx(ex, MyScriptReturn.ExMsg)
                GoTo EndOfScript
            End Try

            ' returning results 
            I = 0
            If I = 0 Then
				MyScriptReturn.ResultCode = 0
				MyScriptReturn.ResultMsgAdd(Text_str)  
				MyScriptReturn.ResultMsgAdd("OK : this schript ends with no errors (this message generated with current script)")
			Else
				MyScriptReturn.ResultCode = 10
                MyScriptReturn.ResultMsgAdd("ERR: this schript ends with ERRORS! (this message generated with current script)")
			End If

			MyScriptReturn.ResultMsgAdd(JS_ScriptingInterface.ScriptDef.Script_DPNE)
			Call MyScriptOutput_frm.InfoSysProtocol.StatusBarProgressBarSetIdle()

EndOfScript:
            Call MyScriptOutput_frm.InfoSysProtocol.PrintInfoLine(MyScriptReturn.ResultMsg)

            TextStr = "Step - 4 Script will end after clicking the button"
            MyScriptOutput_frm.InfoSysHeader.Print(TextStr)
            MyScriptOutput_frm.InfoSysProtocol.Print_and_StatusBarSetCurrActionStatusInfo_Panel3(TextStr)
			'If DebugUse Then
			MyScriptOutput_frm.Pause("click me and script will end")
			System.Threading.Thread.Sleep(1000)
			'End If

            ' closing the ScriptRun form 
            MyScriptOutput_frm.Close()
            MyScriptOutput_frm.Dispose()

            Return MyScriptReturn
        End Function
    End Class
End Namespace

