Exemplo n.º 1
0
        public void DownloadOpen()
        {
            var dhdl = new FileDownloadHandler(FileDownloadOptionEnum.Open);

            var ie = new IE();

            ie.AddDialogHandler(dhdl);
            ie.WaitForComplete();
            ie.GoTo("http://watin.sourceforge.net/WatiNRecorder.zip");

            dhdl.WaitUntilFileDownloadDialogIsHandled(5);
            dhdl.WaitUntilDownloadCompleted(20);
            ie.Close();
        }
Exemplo n.º 2
0
        public void Excel()
        {
            var file = Path.Combine(Path.GetFullPath("."), "Акт сверки.xls");

            if (File.Exists(file))
            {
                File.Delete(file);
            }

            Open("RevisionActs/{0}", payer.Id);
            var handler = new FileDownloadHandler(file);

            browser.AddDialogHandler(handler);
            ClickLink("Excel");

            Assert.That(File.Exists("Акт сверки.xls"), Is.True);
        }
        public static string open_and_HandleFileDownload(this WatiN_IE watinIe, string url, string fileName)
        {
            var tmpFile           = fileName.tempFile();
            var waitUntilHandled  = 20;
            var waitUntilDownload = 300;

            var fileDownloadHandler = watinIe.dialogHandler <FileDownloadHandler>();

            if (fileDownloadHandler.notNull())
            {
                watinIe.IE.RemoveDialogHandler(fileDownloadHandler);
            }

            fileDownloadHandler = new FileDownloadHandler(tmpFile);
            watinIe.IE.AddDialogHandler(fileDownloadHandler);


            fileDownloadHandler.field("saveAsFilename", tmpFile);
            fileDownloadHandler.field("hasHandledFileDownloadDialog", false);

            watinIe.open_ASync(url);
            try
            {
                fileDownloadHandler.WaitUntilFileDownloadDialogIsHandled(waitUntilHandled);
                "after: {0}".info("WaitUntilFileDownloadDialogIsHandled");
                fileDownloadHandler.WaitUntilDownloadCompleted(waitUntilDownload);
                "after: {0}".info("WaitUntilDownloadCompleted");
            }
            catch (Exception ex)
            {
                "[WatiN_IE][open_and_HandleFileDownload] {0}".error(ex.Message);
            }

            if (fileDownloadHandler.SaveAsFilename.fileExists())
            {
                "[WatiN_IE] downloaded ok '{0}' into '{1}'".info(url, fileDownloadHandler.SaveAsFilename);
                watinIe.IE.RemoveDialogHandler(fileDownloadHandler);
                return(fileDownloadHandler.SaveAsFilename);
            }
            "[WatiN_IE] failed to download '{0}' ".info(url);
            return(null);
        }
Exemplo n.º 4
0
        [Test]         // Ignore("Because of timeout issues, run this test manually and not automated"), Category("InternetConnectionNeeded")]
        public void DownloadSave()
        {
            var file = new FileInfo(@"c:\temp\test.zip");

            file.Directory.Create();
            file.Delete();
            Assert.That(file.Exists, Is.False, file.FullName + " file should not exist before download");

            var fileDownloadHandler = new FileDownloadHandler(file.FullName);

            using (var ie = new IE())
            {
                ie.AddDialogHandler(fileDownloadHandler);

//				ie.GoTo("http://watin.sourceforge.net/WatiN-1.0.0.4000-net-1.1.msi");
                ie.GoTo("http://watin.sourceforge.net/WatiNRecorder.zip");

                fileDownloadHandler.WaitUntilFileDownloadDialogIsHandled(15);
                fileDownloadHandler.WaitUntilDownloadCompleted(200);
            }

            file = new FileInfo(@"c:\temp\test.zip");
            Assert.IsTrue(file.Exists, file.FullName + " file does not exist after download");
        }
    private IEnumerator DownloadNext(bool pauseOnStart = false)
    {
        cancelLoading = false;
        if (resorcesQuery.Count == 0)
        {
            yield break;
        }

        DownloadItem resourceInWork = resorcesQuery.Pop();

        downloadWebRequest = new UnityWebRequest(resourceInWork.path);

        Debug.Log($"start load form path {resourceInWork.path} ");
        if (pauseOnStart)
        {
            yield return(new WaitForSeconds(2));
        }

        string directoryName = Application.persistentDataPath + "/Documents/";

        if (!Directory.Exists(Application.persistentDataPath + "/Documents/"))
        {
            Directory.CreateDirectory(Application.persistentDataPath + "/Documents/");
        }
        string fileName = "";

        if (resourceInWork.id != "-1")
        {
            fileName = "video_" + resourceInWork.id + ".mp4";
        }
        else
        {
            fileName = "audio.mp3";
        }

        FileDownloadHandler downloadHandler = new FileDownloadHandler(new byte[4 * 1024], directoryName, fileName);

        downloadWebRequest.downloadHandler = downloadHandler;
        downloadWebRequest.SendWebRequest();

        while (downloadWebRequest != null && !downloadWebRequest.isDone)
        {
            yield return(new WaitForSeconds(0.5f));

            if (cancelLoading)
            {
                yield break;
            }

            List <IDownloadHandler> safeList = new List <IDownloadHandler>(dowloadHandlers); //aviod list content changes while iterate

            foreach (IDownloadHandler item in safeList)
            {
                item.OnProgress(resourceInWork, downloadHandler.Progress);
            }
        }

        bool mustPauseOnStart = true;

        if (!String.IsNullOrEmpty(downloadWebRequest.error) || downloadWebRequest.isNetworkError || downloadWebRequest.isHttpError)
        {
            Debug.LogError($"Download error: {resourceInWork.id}, Error: {downloadWebRequest.error}");
            string filePath = directoryName + "video_" + resourceInWork.id + ".mp4";
            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            List <IDownloadHandler> safeList = new List <IDownloadHandler>(dowloadHandlers);
            foreach (IDownloadHandler item in safeList)
            {
                item.OnDone(resourceInWork, $"error: {downloadWebRequest.error}");
            }
        }
        else if (downloadWebRequest.responseCode == 410)
        {
            Debug.LogError($"File {resourceInWork.id} is gone, must send another request");
        }
        else
        {
            List <IDownloadHandler> safeList = new List <IDownloadHandler>(dowloadHandlers);
            foreach (IDownloadHandler item in safeList)
            {
                item.OnDone(resourceInWork, "done");
            }
            mustPauseOnStart = false;
        }

        resourceInWork     = null;
        downloadWebRequest = null;

        if (resorcesQuery.Count > 0)
        {
            StartCoroutine(DownloadNext(mustPauseOnStart));
        }
    }