KickStarter15

Server Locked issue

8 posts in this topic

#1 ·  Posted (edited)

Hi Expert,

I would like to ask if is there any function that can prevent server locking?

Recently, when I've finished my program and run thru server base, it won't work when we close the remote assistance. But if not, then the program ran perfectly. Not sure how to prevent such case and hoping there is any function/code that can manage how to do this.

 

Thanks in advance Experts.:sweating:

KS15

Edited by KickStarter15
P:S, I tried using Sleep() but still the same.

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

@spudw2k, Actually, it's a combination of other languages like Java, MySQL, Autoit, ClickOnce and C# codes and it was already compiled to .exe so I ideally convert it to AutoIt of whatever that program is doing.

It's kind of messy but it's all what it is and it is 237 lines.

#include <Crypt.au3>
#include <File.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1_1 = GUICreate("Epsilon Feeder v.0.2", 611, 116, 192, 124)
GUISetBkColor(0xFFFFFF)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1_1Close")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1_1Minimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form1_1Maximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "Form1_1Restore")
$Group1 = GUICtrlCreateGroup("Original PDF", 8, 8, 473, 41)
$Input1 = GUICtrlCreateInput("", 16, 22, 438, 21, $ES_READONLY)
GUICtrlSetState($Input1, $GUI_Disable)
GUICtrlSetOnEvent(-1, "Input1Change")
$Group2 = GUICtrlCreateGroup("", 488, 8, 113, 81)
$Button1 = GUICtrlCreateButton("Start", 496, 21, 97, 61)
GUICtrlSetOnEvent(-1, "Button1Click")
$Group3 = GUICtrlCreateGroup("Edited PDF", 8, 48, 473, 41)
$Input2 = GUICtrlCreateInput("", 16, 62, 437, 21, $ES_READONLY)
GUICtrlSetOnEvent(-1, "Input2Change")
GUICtrlSetState($Input2, $GUI_Disable)
$Label3 = GUICtrlCreateLabel("Waiting...", 17, 95, 580, 17)
GUICtrlSetColor(-1, 0x002200)
GUICtrlSetOnEvent(-1, "Label3Click")
$Label4 = GUICtrlCreateLabel("File(s) count:", 500, 95, 580, 17)
GUICtrlSetColor(-1, 0x002200)
$Label5 = GUICtrlCreateLabel("", 566, 95, 50, 17)
GUICtrlSetColor(-1, 0x002200)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $InputPath,$OutputPath,$HotfolderIn,$HotfolderOut
Local $sFilePath = @ScriptDir & "\Config.ini"
Local $LogPath = @ScriptDir & "\Log\"
Local $tLogPath = @ScriptDir & "\Temp\"
DirCreate($LogPath)
DirCreate($tLogPath)

If Not FileExists($sFilePath) Then
   MsgBox(16,"Error!", "Could not locate path." & @CRLF & "Check with Config.ini if missing. Thanks!")
EndIf

$string = FileRead ($sFilePath)
If $string = "" Then
    MsgBox (16,"Error!","No path declared!")
    Exit
EndIf

If $sFilePath = -1 Then
   MsgBox($MB_SYSTEMMODAL, "", "An error occurred when opening the file.")
EndIf

FileSetPos($sFilePath, 0, $FILE_BEGIN)
;server path
;~ $InputPath="D:\Programs\Epsilon\In\"
Local $aFileRead = FileReadLine ($sFilePath,2)
;~ $OutputPath="D:\Programs\Epsilon\Out\"
Local $bFileRead = FileReadLine ($sFilePath,3)


;local path
;~ $HotfolderIn="D:\Programs\Epsilon\Compare\IN\"
Local $cFileRead = FileReadLine ($sFilePath,6)
;~ $HotfolderOut="D:\Programs\Epsilon\Compare\OUT\"
Local $dFileRead = FileReadLine ($sFilePath,-1)
FileClose($sFilePath)

Func _RemoveFileExt($string)
    Return StringLeft($string,StringInStr($string,".",Default,-1)-5)
 EndFunc

While 1
   Sleep(1000)
;~    main loop
   If Not FileExists ($aFileRead & "*.pdf") Then
   GUICtrlSetData($Label3, "No input files found.")
   Sleep(1000)
Else
      If GUICtrlRead($Button1) = "Stop" Then
         If GUICtrlRead($Input1) = "Reading directory" Then
             Local $FileList = _FileListToArray($aFileRead)
             For $i = 1 To $FileList[0]
;~  second loop fed
                  If StringRight($FileList[$i],8) = "_Old.pdf" Then
                     $InputX = $FileList[$i]
                     GUICtrlSetData($Input1,$FileList[$i])

                      If FileExists($aFileRead & StringLeft($InputX, StringLen($InputX) - 8) & "_New.pdf") Then
                         Local $hSearch = FileFindFirstFile($aFileRead & "*New.pdf")
                         $aFileName = FileFindNextFile($hSearch)
                         Local $Search = FileFindFirstFile($aFileRead & "*Old.pdf")
                         $bFileName = FileFindNextFile($Search)
                         _FileCreate($LogPath&"\"&_RemoveFileExt($aFileName)&".log")
                         FileCopy($LogPath&"\"&_RemoveFileExt($aFileName)&".log", $tLogPath)
                         GUICtrlSetData($Label3, "Creating ticket...")
                         GUICtrlSetData($Input2,StringLeft($InputX, StringLen($InputX) - 8) & "_New.pdf")
                         $ticketX='<?xml version="1.0"?>' & @CRLF & "<Set>"  & @CRLF & "<OlderDocument>" & $cFileRead & GUICtrlRead($Input1) & "</OlderDocument>"  & @CRLF & "<OlderDocumentStage></OlderDocumentStage>"  & @CRLF & "<NewerDocument>" & $cFileRead & GUICtrlRead($Input2) & "</NewerDocument>"  & @CRLF & "<NewerDocumentStage></NewerDocumentStage>"  & @CRLF & "</Set>"
                         Sleep(1000)
                         _FileCreate($cFileRead & _RemoveFileExt($aFileName) & "_ticket.xml")
                         FileWriteLine($cFileRead & _RemoveFileExt($aFileName) & "_ticket.xml", $ticketX)
                         FileWriteLine(@ScriptDir & "\ForProcessFiles.log",  _RemoveFileExt($aFileName) & "_ticket.pdf")
;~                       FileWriteLine(@ScriptDir & "\ForProcessFiles.log",  _RemoveFileExt($aFileName) & "_Old.pdf")
                         Sleep(1000)
                         FileMove($aFileRead & StringLeft($InputX, StringLen($InputX) - 8) & "_New.pdf", $cFileRead & StringLeft($InputX, StringLen($InputX) - 8) & "_New.pdf", 9)
                         FileMove($aFileRead & StringLeft($InputX, StringLen($InputX) - 8) & "_Old.pdf", $cFileRead & StringLeft($InputX, StringLen($InputX) - 8) & "_Old.pdf", 9)
                         FileClose($aFileRead & StringLeft($InputX, StringLen($InputX) - 8) & "_ticket.xml")
                         Sleep(500)
                         FileMove($aFileRead & StringLeft($InputX, StringLen($InputX) - 8) & "_ticket.xml", $cFileRead & StringLeft($InputX, StringLen($InputX) - 8) & "_ticket.xml", 9)
                         GUICtrlSetData($Label3, "Transfering files...")
                         FileCopy($cFileRead&_RemoveFileExt($aFileName)&"_New.pdf", $tLogPath)
                         FileCopy($cFileRead&_RemoveFileExt($bFileName)&"_Old.pdf", $tLogPath)
                         Sleep(1000)
                         GUICtrlSetData($Input1, "Reading directory")
                         GUICtrlSetData($Input2, "Reading directory")
                      Else
                         GUICtrlSetData($Label3, "Missing input file (Edited PDF)")
                         FileDelete($aFileRead & StringLeft($InputX, StringLen($InputX) - 8) & "_Old.pdf")
                         FileDelete($aFileRead & StringLeft($InputX, StringLen($InputX) - 8) & "_New.pdf")
                         GUICtrlSetData($Input1, "Reading directory")
                         GUICtrlSetData($Input2, "Reading directory")
                      EndIf
                   EndIf
             Next
         EndIf
      EndIf
    EndIf

 ProcessList()
    Sleep(3000)
    Global $InputX
    Global $sLog, $aFileName, $bFileName
    $FP = 0
    Local $ForProcLogFile = FileOpen(@ScriptDir & "\ForProcessFiles.log", 0)
    For $FP = 1 To _FileCountLines(@ScriptDir & "\ForProcessFiles.log")
      $retrivF = StringTrimRight(FileReadLine($ForProcLogFile, $FP),4) & ".pdf"
         If FileExists($dFileRead&"*.pdf") = 1 Then
            $aPath = $dFileRead & $retrivF
            Local $iFileSize = FileGetSize($aPath)
            GUICtrlSetData($Label3, "Matching file: " & $retrivF & " :: Size(" & ByteSuffix($iFileSize) &")")
            Sleep(1000)
         EndIf
         If Not ProcessExists("SPi - PDF Compare Server.exe") Then ; Check if the compare tool process is not running. change to compare tool name
                  GUICtrlSetData($Input1, "Transfering "&StringLeft($retrivF, StringLen($retrivF) - 11) & "_Old.pdf")
                  GUICtrlSetData($Input2, "Transfering "&StringLeft($retrivF, StringLen($retrivF) - 11) & "_New.pdf")
                  Sleep(1000)
                  GUICtrlSetData($Input1, "Reading directory")
                  GUICtrlSetData($Input2, "Reading directory")
                  sleep(1000)
                  GUICtrlSetData($Label3, "Completed...")
                  FileDelete($LogPath&StringLeft($retrivF, StringLen($retrivF) - 11)& ".log")
                  Run("D:\Programs\SPiPDFCompareServer\SPi - PDF Compare Server.exe") ; Change this to compare program tool path
            Else
               Local $FileCount = _FileListToArray($dFileRead) ; Change this
                  If $FileCount = 0 Then
                     GUICtrlSetData($Label5, " 0")
                  EndIf
            GUICtrlSetData($Label3, "Checking Compare tool (Running)...")
            sleep(2000)
            GUICtrlSetData($Label3, "Waiting for epsilon output...")
            FileDelete($LogPath&StringLeft($retrivF, StringLen($retrivF) - 11)& ".log")
            Sleep(1000)
         EndIf

      If FileExists($dFileRead & $retrivF) Then
       Sleep (1000)
            $sFile = @ScriptDir & '\ForProcessFiles.log'
            $aFiles = FileReadToArray($sFile)
            $content = FileRead($sFile)
            For $i = 0 to UBound($aFiles)-1
               If FileExists($dFileRead & $aFiles[$i]) Then
;~                ProcessClose("ServerDatabase_Updater.exe") ; change to compare tool name
                  Local $xFileSize = FileGetSize($dFileRead & $aFiles[$i])
                  GUICtrlSetData($Input1, "Transfering "&StringLeft($aFiles[$i], StringLen($aFiles[$i]) - 11) & "_ticket.pdf")
                  GUICtrlSetData($Input2, "Transfering "&StringLeft($aFiles[$i], StringLen($aFiles[$i]) - 11) & "_ticket.pdf")
                  GUICtrlSetData($Label3, "Moving " & $aFiles[$i] & " to out folder... Size(" & ByteSuffix($xFileSize) &")")
                  Sleep(1000)
                  GUICtrlSetData($Input1, "Reading directory")
                  GUICtrlSetData($Input2, "Reading directory")
                  Global $FileCount = _FileListToArray($dFileRead)
                     If $FileCount = 0 Then
                           GUICtrlSetData($Label5, " 0")
                        Else
                           GUICtrlSetData($Label5, $FileCount[0])
                     EndIf
                  FileMove($dFileRead & $aFiles[$i], $bFileRead & $aFiles[$i])
                  FileDelete($cFileRead & StringLeft($aFiles[$i], StringLen($aFiles[$i]) - 11) & "_Old.pdf")
                  FileDelete($cFileRead & StringLeft($aFiles[$i], StringLen($aFiles[$i]) - 11) & "_New.pdf")
                  Sleep(1000)
                  $content = StringRegExpReplace($content, $aFiles[$i] & '\R?', "")
               EndIf
            Next
         $hFile = FileOpen($sFile, 2)
         FileWrite($hFile, $content)
         FileClose($hFile)
      EndIf
   FileDelete($LogPath&StringLeft($retrivF, StringLen($retrivF) - 8)& ".log")
   Next
   FileClose($ForProcLogFile)
WEnd
Func ByteSuffix($iBytes)
    Local $iIndex = 0, $aArray = [' bytes', ' KB', ' MB', ' GB', ' TB', ' PB', ' EB', ' ZB', ' YB']
    While $iBytes > 1023
        $iIndex += 1
        $iBytes /= 1024
    WEnd
    Return Round($iBytes) & $aArray[$iIndex]
EndFunc
Func Button1Click()
If GUICtrlRead($Button1) = "Start" Then
   GUICtrlSetData($Button1, "Stop")
   GUICtrlSetData($Label3, "Program running!")
   GUICtrlSetData($Input1, "Reading directory")
   GUICtrlSetData($Input2, "Reading directory")
   Sleep(500)
Else
   GUICtrlSetData($Button1, "Start")
   GUICtrlSetData($Label3, "Program pause!")
   GUICtrlSetData($Input1, "")
   GUICtrlSetData($Input2, "")
   Sleep(500)
EndIf
EndFunc
Func Form1_1Close()
If GUICtrlRead($Button1) = "Start" Then
   GUICtrlSetData($Label3, "Clossing program...")
   Sleep(500)
Exit
Else
   GUICtrlSetData($Label3, "Warning: Currently processing files, unable to close program!")
EndIf
EndFunc

After running this program, it will call the other program to finish the flow but it won't produce any output when remote assistance is close.

Now, my confusion is, is it my program that has issue or the other program that was being called? if the other program, then is there a way to create a code to prevent server locked?^_^

 

Thanks!

KS15

Edited by KickStarter15

Share this post


Link to post
Share on other sites

Hmm, nothing specifically jumping out at me which would cause the script to hang.  

A few comments though:

  1. One thing I'd recommend though would be to create events--as you have for GUi close and button click--to kick off your file list loop (after checking the label value="stop") instead of checking every second if the label value is set and the logic/process starting at line 139.  Put them in functions that get triggered instead of in a while loop.
  2. You declare events for minimize and maximize, but I don't see the functions. O.o
  3. You have a ProcessList function call, but don't store the returned array.  Probably not hurting anything, but it's also not accomplishing anything useful.  Perhaps it's incomplete or left over code?

That's all I've got for now; sorry that 2 & 3 are more critiques in nature instead of troubleshooting help.

Share this post


Link to post
Share on other sites

No, it's fine. No worries and thanks, I'll consider it as a compliment.:D

For the item 2, yup part of my old Autoit version. It was not removed.

For the item 3, its actually the process line where i can do process the files and my trigger for processing. I missed to removed some unuseful functions. This is my source code where I test everything before compiling and due to excitement in posting the code, I did not even noticed to clean-up all the messy things before posting.

In my self study with Autoit, I have my own list of "Lesson Learn List" where all my mistake was taking note.:> that's so funny right? but just need to enhance my learning, that's all.

Now, back to my concern, for the item 1. I'll check on that but that line is for the .log file where I added all files for my FileMove() and then clear it back to empty when all were moved. That my trigger so far...:sweating: Ok... Ok... checking on that later.

So basically base on your testing with the code, so the problem is in the other program that was being called right?

Share this post


Link to post
Share on other sites

Regarding your script not working when the remote console is closed, I have had the same problem a few months ago, have a look at my workaround here: https://stackoverflow.com/a/45746816/3815591

Quoting the text for reference:

Quote

I managed to workaround the issue by actually connecting to the server to itself (to 127.0.0.1) via RDP so that it will always have an active RDP session for the automation script to run.

I am not happy with the results but it works... I cannot give clear instructions on how you would need to modify the settings in Windows to allow RDP connections from self, it was a one big trial and error process, I have to modify some policies in the Group Policy Editor and then some stuff that I don't remember.

There is another downside to this, a Windows server will allow 2 simultaneous connections to it but by using this method we are reserving a slot so only 1 connection at a given time is possible, something to be aware of.

 


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

@TheDcoder, hmm, that seems interesting to check with. Thanks, I'll check on this and see what will be the result.^_^

However, when I tried not calling the other program, my program work's perfectly even if RDP was closed. Now, that program is from other developer that do file compare from New.pdf and Old.pdf and then give the result in a PDF format.

The problem with that program is maybe it was using send keys where the server needs to be active. In this way, I can maybe report that to our heads for checking. But still I'll try with your suggestion TheDcoder. Thank you.

Share this post


Link to post
Share on other sites
24 minutes ago, KickStarter15 said:

The problem with that program is maybe it was using send keys where the server needs to be active.

Yes, all automation functions or operations will freeze if there is no session with a virtual display attached to it. Stuff like conversion and comparison will work because it does not involve anything which requires a display.

 

26 minutes ago, KickStarter15 said:

Thank you

Your welcome :)


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now