Jump to content

Translate C# to Autoit


AutID
 Share

Recommended Posts

Some time ago i had created a function in C# and i need it know for a project i am working on in Autoit.
The code looks like this


static void _Stream(string sUrl, string existingFilename)

 {

            HttpWebRequest webRequest;

            HttpWebResponse webResponse;

            IWebProxy proxy = null; //SA???

            FileStream fs = null;

            try

  {

                string fname = existingFilename;

                if (fname == null)

                    fname = ConvertUrlToFileName(sUrl);   No need translation

                webRequest = (HttpWebRequest)WebRequest.Create(sUrl);

                long preloadedLength = GetExistingFileLength(fname); No need translation

                if (preloadedLength > 0)

                    webRequest.AddRange((int)preloadedLength);

                webRequest.Proxy = proxy;

                webResponse = (HttpWebResponse)webRequest.GetResponse();

                fs = new FileStream(

                    fname, FileMode.Append, FileAccess.Write);

                long fileLength = webResponse.ContentLength;

                Stream strm = webResponse.GetResponseStream();

                int arrSize = 10 * 1024 * 1024; //SA???                

                byte[] barr = new byte[arrSize];

                long bytesCounter = preloadedLength;

                string fmtPercent = string.Empty;

                while (true)

  {

                    int actualBytes = strm.Read(barr, 0, arrSize);

                    if (actualBytes <= 0)

                        break;

                    fs.Write(barr, 0, actualBytes);

                    bytesCounter += actualBytes;

                    double percent = 0d;

                    if (fileLength > 0)

                        percent =

                            100.0d * bytesCounter /

                            (preloadedLength + fileLength);

                }

             }

  catch (Exception e) {

                //do nothing

            }

  finally {

                if (fs != null) {

                    fs.Flush();

                    fs.Close();

                } //if

            }

        }

Can someone help me translate this code to autoit. I gave it a try but it was a total failure so i am not willing to share it here...

Link to comment
Share on other sites

You want WinHttp. Look in the Examples section.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Please add comments to the code to describe exactly what each line is doing.

Be easier to translate then.

If you know C# then i belive it is easy to understand what the code is doing.

You want WinHttp. Look in the Examples section.

I know but i have difficult time understanding winhttp.au3. I like trancexx but the udf is simply beyond what i usually do.

This looks like a poor implementation of the AutoIt InetGet function with some non-functional code related to progress measurement, which InetGet can do.

I know. It is not the entire code. Just a small sample. The part that i am having difficulties to translate.

I don't want to use INetGet for some reasons.

 

Link to comment
Share on other sites

If you know C# then i belive it is easy to understand what the code is doing.

 

I know that, but it will be much simpler with your comments in the code, then people who don't know C# can help too, I assume help is what you want here, and it wont take you a few minutes to write the cooments.

You did write that code right?

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

It is entirely irrelevant if he wrote the code or not. @OP, you do want WinHttp unfortunately. The help file on that is pretty good so it should be doable.

If you have this code as part of a working program, you can use Wireshark or Fiddler (I see parts of proxy support in there which is how Fiddler captures traffic) to capture the traffic then compare it with your own attempts at generating a valid HTTP request and reading the response.

Link to comment
Share on other sites

It's polite to link or attribute to the person(s) who wrote that code. Otherwise we all think you know what you're doing.

Edit: Oh and the whole "I have been trying for hours comment" doesn't work around here. Do us a favour and show us the fruits of your "hard" labour.

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

I see, sorry, I though you understood it because you created it.

I understand it but translating it is difficult for me because i dont understand winhttp.au3. C# has nothing to do with autoit and C++. You must know it...

It's polite to link or attribute to the person(s) who wrote that code. Otherwise we all think you know what you're doing.

Edit: Oh and the whole "I have been trying for hours comment" doesn't work around here. Do us a favour and show us the fruits of your "hard" labour.

Remind me when i forced you to help me and i will apologise.

If i simply wanted to download a file with winhttp.au3 i would have already done it without even posting here. The reason i am posting is because i want an exact translate of my code. Not for actual use but for some other reason that i could probably tell you but i won't because i know the only reason you are here in this thread is because you are curious and you want some attention. Go get a pet, it will work trust me.

Edit: Oh and the whole "i want to help but i only ask questions" doesn't work with me. Go play somewhere else please.

Edited by AutID
Link to comment
Share on other sites

I understand it but translating it is difficult for me because i dont understand winhttp.au3. C# has nothing to do with autoit and C++. You must know it...

If you understand it, please do yourself a favour and just comment what each line is doing.

How hard can it be?

It will be easier for others to translate.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

  • Developers

I understand it but translating it is difficult for me because i dont understand winhttp.au3. C# has nothing to do with autoit and C++. You must know it...

Remind me when i forced you to help me and i will apologise.

If i simply wanted to download a file with winhttp.au3 i would have already done it without even posting here. The reason i am posting is because i want an exact translate of my code. Not for actual use but for some other reason that i could probably tell you but i won't because i know the only reason you are here in this thread is because you are curious and you want some attention. Go get a pet, it will work trust me.

Edit: Oh and the whole "i want to help but i only ask questions" doesn't work with me. Go play somewhere else please.

You are now way out of line ... next post like this will get this locked!

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...