Ejemplo n.º 1
0
        public void ImportArduinoPlugAndPlayConfig()
        {
            Console.WriteLine("  Importing arduino plug and play config...");

            var installPath = GetInstallPath();

            Console.WriteLine("    Install path: " + installPath);

            if (Context == null)
            {
                throw new Exception("Context == null");
            }

            if (Context.Settings == null)
            {
                throw new Exception("Context.Settings == null");
            }

            Console.WriteLine("    Branch: " + Context.Settings.Branch);

            var url         = "https://raw.githubusercontent.com/GrowSense/Index/" + Context.Settings.Branch + "/scripts/apps/ArduinoPlugAndPlay/ArduinoPlugAndPlay.exe.config.system";
            var destination = Path.Combine(installPath, "ArduinoPlugAndPlay.exe.config");

            EnsureInstallDirectoryExists();

            Downloader.Download(url, destination);
        }
Ejemplo n.º 2
0
        private void SingleDownload(object data)
        {
            //this.Invoke(this.activeStateChanger, new object[]{true, true});


            try
            {
                DownloadInstructions instructions = (DownloadInstructions)data;
                //GetFileSize(url, out progressKnown);
                //this.Invoke(this.fileNameChanger, new object[]{Path.GetFileName(instructions.Destination)});


                using (FileDownloader dL = new FileDownloader())
                {
                    dL.ProgressChanged += new DownloadProgressHandler(this.SingleProgressChanged);
                    dL.StateChanged    += new DownloadProgressHandler(this.StateChanged);
                    dL.Download(instructions.URLs, instructions.Destination, this.cancelEvent);
                }
            }
            catch (Exception exp)
            {
                WebMeeting.Client.ClientUI.getInstance().ShowExceptionMessage("Managecontents==>frmDownloader.cs 354", exp, null, false);
            }

            //this.Invoke(this.activeStateChanger, new object[]{false, true});
        }
Ejemplo n.º 3
0
        public void DownloadFileWithAlternateFromWindowsShare()
        {
            // These download URLs need to be changed
            FileDownloader downloader = new FileDownloader();

            // Download them from a windows share.  We could get a C# MapDrive() function to allow this portion of the
            // test not to rely on a hardcoded SAMBA path.
            if (Directory.Exists(sambaPath))
            {
                foreach (String s in fileSizes.Keys)
                {
                    string fileUrl = "file:///" + sambaPath + s;

                    List <string> urlList = new List <string>();

                    urlList.Add("file://somebadpath" + s);
                    urlList.Add(fileUrl);
                    urlList.Add("file://somebadpath" + s);

                    downloader.Download(urlList, OUTPUT_DIRECTORY);

                    string fi = Path.Combine(OUTPUT_DIRECTORY, s);

                    Assert.IsTrue(InstallPadTest.VerifyExistenceAndSize(fi, fileSizes[s]));
                }
            }
            else
            {
                Assert.Ignore("Test ignored because share is not mapped or may not exist.");
            }
        }
Ejemplo n.º 4
0
 static void Main(string[] args)
 {
     FileDownloader downloader = new FileDownloader();
     downloader.DownloadComplete += new EventHandler(downloader_DownloadedComplete);
     downloader.ProgressChanged += new DownloadProgressHandler(downloader_ProgressChanged);
     downloader.Download("http://download.mozilla.org/?product=firefox-1.5.0.7&os=win&lang=en-US");
 }
Ejemplo n.º 5
0
    void OnGUI()
    {
        fileToDownload = GUILayout.TextField(fileToDownload);
        if (GUILayout.Button("Download") && !downloader.IsInQueue(fileToDownload))
        {
            // start downloading
            string pathToSave = System.IO.Path.Combine(Application.persistentDataPath, System.IO.Path.GetFileName(fileToDownload));
            downloader.Download(fileToDownload, pathToSave);
            fileToDownload = FILE_URL_FLV;
        }

        if (GUILayout.Button("Download in queue") && !downloader.IsInQueue(fileToDownload))
        {
            string pathToSave = System.IO.Path.Combine(Application.persistentDataPath, System.IO.Path.GetFileName(fileToDownload));
            downloader.DownloadInQueue(fileToDownload, pathToSave);
        }

        if (GUILayout.Button("Cancel"))
        {
            downloader.Cancel();
        }

        // status
        GUILayout.Label("Total Bytes : " + evt.totalBytes);
        GUILayout.Label("Downloaded Bytes : " + evt.downloadedBytes);
        GUILayout.Label("Downloading Progress (%): " + evt.progress);
        GUILayout.Label("\nStatus : " + evt.status);
        GUILayout.Label("\nError : " + ((!string.IsNullOrEmpty(evt.error)) ? evt.error : ""));
    }
Ejemplo n.º 6
0
        private static RunWebCommandResult RunWebCommand(string commandName, string commandParametersJson)
        {
            if (commandName == "RunApplication")
            {
                RunApplicationParameters runParams = JsonConvert.DeserializeObject <RunApplicationParameters>(commandParametersJson);

                if (runParams.CommandStartTimeoutMS == 0)
                {
                    runParams.CommandStartTimeoutMS = 30000;
                }

                IRunApplication commandTextRunner = new WindowsCommandTextRunner();
                return(commandTextRunner.Execute(runParams));
            }
            else if (commandName == "DownloadFile")
            {
                var            downloadParams = JsonConvert.DeserializeObject <FileDownloaderParams>(commandParametersJson);
                FileDownloader fd             = new FileDownloader();
                return(fd.Download(downloadParams.RemoteUri, downloadParams.FileName, downloadParams.TargetDirPath));
            }
            else if (commandName == "ImportFromGoogleSheetToExcel")
            {
                var importGSParams = JsonConvert.DeserializeObject <ImportFromGoogleSheetParameters>(commandParametersJson);
                var igs            = new ImportFromGoogleSheetToExcel();
                return(igs.Execute(importGSParams));
            }
            else
            {
                throw new NotSupportedException("CommandName not supported: " + commandName);
            }
        }
Ejemplo n.º 7
0
        public void Should_be_able_to_download_a_small_file_from_the_internet()
        {
            var fileDownloader = new FileDownloader("http://www.google.co.uk/intl/en_uk/images/logo.gif");

            byte[] fileData = fileDownloader.Download();

            Assert.IsTrue(fileData.Length > 0);
        }
        public void Should_be_able_to_download_a_small_file_from_the_internet()
        {
            var fileDownloader = new FileDownloader("http://www.google.co.uk/intl/en_uk/images/logo.gif");

            byte[] fileData = fileDownloader.Download();

            Assert.IsTrue(fileData.Length > 0);
        }
Ejemplo n.º 9
0
        public void DownloadRelativePathFile()
        {
            FileDownloader downloader = new FileDownloader();
            var            request    = new Request("file://Downloader/1.html");
            var            spider     = new DefaultSpider();
            var            page       = downloader.Download(request, spider);

            Assert.Equal("hello", page.Content);
        }
Ejemplo n.º 10
0
        public void DownloadRelativeAbsolutePathFile()
        {
            FileDownloader downloader = new FileDownloader();
            var            path       = Path.Combine(Env.BaseDirectory, "Downloader\\1.html");
            var            request    = new Request($"file://{path}");
            var            spider     = new DefaultSpider();
            var            page       = downloader.Download(request, spider);

            Assert.Equal("hello", page.Content);
        }
Ejemplo n.º 11
0
        public void DownloadRelativePathFile()
        {
            FileDownloader downloader = new FileDownloader();
            var            path       = Path.Combine("source", "1.html");
            var            request    = new Request($"file://{path}");
            var            spider     = new DefaultSpider();
            var            page       = downloader.Download(request, spider);

            Assert.Equal("hello", page.Content);
        }
Ejemplo n.º 12
0
        private void DownloadUpdate(UpdateDetails details)
        {
            _realCloseWindow = true;
            Log.Info("Not up to date.");
            IsClosingDown = true;

            var    downloadUri = new Uri(details.InstallUrl);
            string filename    = System.IO.Path.GetFileName(downloadUri.LocalPath);

            if (details.UpdateDownloaded)
            {
                UpdateStatus("Launching Updater");
                Log.Info("Launching updater");
                Close();
                return;
            }

            UpdateStatus("Downloading new version.");

            var fd = new FileDownloader(downloadUri, Path.Combine(Directory.GetCurrentDirectory(), filename));

            progressBar1.Maximum         = 100;
            progressBar1.IsIndeterminate = false;
            progressBar1.Value           = 0;

            var myBinding = new Binding("Progress");

            myBinding.Source = fd;
            progressBar1.SetBinding(ProgressBar.ValueProperty, myBinding);

            var downloadTask = fd.Download();

            downloadTask.ContinueWith((t) =>
            {
                Log.Info("Download Complete");

                if (fd.DownloadFailed || !fd.DownloadComplete)
                {
                    Log.Info("Download Failed");
                    UpdateStatus("Downloading the new version failed. Please manually download.");
                    Program.LaunchUrl(details.InstallUrl);
                }
                else
                {
                    Log.Info("Launching updater");
                    UpdateStatus("Launching Updater");
                }
                Dispatcher.Invoke(new Action(() =>
                {
                    progressBar1.IsIndeterminate = true;
                    Close();
                }));
            });
            downloadTask.Start();
        }
Ejemplo n.º 13
0
        public void FileNotExists()
        {
            FileDownloader downloader = new FileDownloader();
            var            request    = new Request("file://Downloader/2.html");
            var            spider     = new DefaultSpider();
            var            page       = downloader.Download(request, spider);

            Assert.True(string.IsNullOrEmpty(page.Content));
            Assert.Equal("File downloader\\2.html unfound.", page.Exception.Message);
            Assert.True(page.Skip);
        }
Ejemplo n.º 14
0
        public void FileNotExists()
        {
            FileDownloader downloader = new FileDownloader();
            var            request    = new Request("file://Downloader/2.html");
            var            spider     = new DefaultSpider();
            var            page       = downloader.Download(request, spider).Result;

            Assert.True(string.IsNullOrEmpty(page.Content));
            Assert.True(page.Exception is FileNotFoundException);
            Assert.True(page.Skip);
        }
Ejemplo n.º 15
0
        public void DownloadFile_Test()
        {
            //string remoteUri = "https://docs.google.com/spreadsheets/d/1-vTMclGuOJeaw4yqm3AWvg04q-C4sHyQ0zmKiQTY9aY/export?format=xlsx&id=1-vTMclGuOJeaw4yqm3AWvg04q-C4sHyQ0zmKiQTY9aY";
            string remoteUri     = "http://www.ya.ru";
            string fileName      = "file.html";
            string backupDirName = "c:\\work\\backup";

            var fd     = new FileDownloader();
            var result = fd.Download(remoteUri, fileName, backupDirName);

            Assert.AreEqual(0, result.ResultCode);
        }
Ejemplo n.º 16
0
        private void DownloadUpdate(UpdateDetails details)
        {
            _realCloseWindow = true;
            Log.Info("Not up to date.");
            IsClosingDown = true;

            var    downloadUri = new Uri(details.InstallUrl);
            string filename    = System.IO.Path.GetFileName(downloadUri.LocalPath);

            if (details.UpdateDownloaded)
            {
                UpdateStatus("Launching Updater");
                Log.Info("Launching updater");
                Close();
                return;
            }

            UpdateStatus("Downloading new version.");

            var fd = new FileDownloader(downloadUri, Path.Combine(Config.Instance.Paths.UpdatesPath, filename));

            progressBar1.Maximum         = 100;
            progressBar1.IsIndeterminate = false;
            progressBar1.Value           = 0;

            var myBinding = new Binding("Progress");

            myBinding.Source = fd;
            progressBar1.SetBinding(ProgressBar.ValueProperty, myBinding);

            var downloadTask = fd.Download();

            downloadTask.ContinueWith((t) => {
                Log.Info("Download Complete");

                if (fd.DownloadFailed || !fd.DownloadComplete)
                {
                    Log.Info("Download Failed");
                    UpdateStatus("Downloading the new version failed. Please manually download.");
                    TopMostMessageBox.Show("Downloading the latest version of OCTGN failed. Please visit http://www.octgn.net to download manually.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
                else
                {
                    Log.Info("Launching updater");
                    UpdateStatus("Launching Updater");
                }
                Dispatcher.Invoke(new Action(() => {
                    progressBar1.IsIndeterminate = true;
                    Close();
                }));
            });
            downloadTask.Start();
        }
Ejemplo n.º 17
0
        public void Download()
        {
            IFileDownloader downloader = new FileDownloader();

            downloader.Initialize();
            using (var file = downloader.Download(new Uri("http://www.google.co.nz/")))
            {
                Assert.IsNotNull(file);
                file.File.Refresh();
                Assert.IsTrue(file.File.Length > 0);
            }
        }
Ejemplo n.º 18
0
        public static void CheckForNews(Form parent, bool manual)
        {
            String url = GetUrlBase();

            if (!System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName.StartsWith("de", StringComparison.InvariantCultureIgnoreCase))
            {
                url += "en/";
            }
            url += "ares_news.html";
            FileDownloader <bool> downloader = new FileDownloader <bool>(parent, manual, manual);

            downloader.Download(url, StringResources.SearchingNews, NewsDownloaded);
        }
Ejemplo n.º 19
0
        public void DownloadFtp()
        {
            FileInfo info;

            // We expect no exceptions
            downloadFtpTestDownloader = new FileDownloader();
            downloadFtpTestDownloader.ProgressChanged += new DownloadProgressHandler(DownloadFtp_ProgressChanged);
            downloadFtpTestDownloader.Download(firefoxFtpUrl, OUTPUT_DIRECTORY);

            string fi = Path.Combine(OUTPUT_DIRECTORY, Path.GetFileName(new Uri(firefoxFtpUrl).ToString()));

            // Ensure the file size is 1KB, meaning we were notified of progress information
            // and Cancel worked.
            info = new FileInfo(fi);
            Assert.AreEqual(info.Length, 1024);

            // Trying (and failing) to resume an ftp source should result
            // in the file getting deleted and starting over at 0 KB.
            downloadFtpTestDownloader.Download(firefoxFtpUrl, OUTPUT_DIRECTORY);
            info = new FileInfo(fi);
            Assert.AreEqual(info.Length, 1024);
        }
Ejemplo n.º 20
0
        private static void DoCheckForUpdate(Form parent, bool mainProgram, bool verbose, bool directDownload)
        {
            String url = GetUrlBase() + "ares_version.txt";
            FileDownloader <bool> downloader = new FileDownloader <bool>(parent, verbose, verbose);

            if (mainProgram && directDownload)
            {
                downloader.Download(url, StringResources.SearchingVersion, DownloadMainSetup);
            }
            else if (mainProgram && !directDownload)
            {
                downloader.Download(url, StringResources.SearchingVersion, VersionDownloadedMain);
            }
            else if (directDownload)
            {
                downloader.Download(url, StringResources.SearchingVersion, DownloadPluginSetup);
            }
            else
            {
                downloader.Download(url, StringResources.SearchingVersion, VersionDownloadedPlugin);
            }
        }
Ejemplo n.º 21
0
    private void ProcessDownloadBundleResponse(
        GetDownloadableResponse response,
        string crc,
        string bundleId,
        System.Action <bool> callback)
    {
        if (response.HasErrors)
        {
            if (callback != null)
            {
                callback(false);
            }

            return;
        }

        var basePath = Application.persistentDataPath + "/Bundles/";

        if (!System.IO.Directory.Exists(basePath))
        {
            Debug.LogErrorFormat("Path {0} doesn't exist.", basePath);

            if (callback != null)
            {
                callback(false);
            }

            return;
        }

        var dstPath    = basePath + bundleId + ".pixbundle";
        var dstPathCrc = basePath + bundleId + ".pixcrc";

        FileDownloader.Download(response.Url, dstPath, (success) =>
        {
            if (success)
            {
                System.IO.File.WriteAllText(dstPathCrc, crc.ToString());
            }
            else
            {
                Debug.LogErrorFormat("Couldn't download bundle {0}", bundleId);
            }

            if (callback != null)
            {
                callback(success);
            }
        });
    }
Ejemplo n.º 22
0
    IEnumerator DownloadBigZipFile()
    {
        downloading = true;
        yield return(null);

        downloader.Init();

        zipFile = guideZipId + ".zip";

        string pathToSave     = ppath + "/" + zipFile;
        string fileToDownload = serverURL + "data.aspx?gId=" + guideZipId;

        downloader.Download(fileToDownload, pathToSave);
    }
Ejemplo n.º 23
0
        public void DownloadRelativeAbsolutePathFile()
        {
            if (Environment.GetEnvironmentVariable("TRAVIS") == "1")
            {
                return;
            }
            FileDownloader downloader = new FileDownloader();
            var            path       = Path.Combine(Env.BaseDirectory, "source", "1.html");
            var            request    = new Request($"file://{path}");
            var            spider     = new DefaultSpider();
            var            page       = downloader.Download(request, spider);

            Assert.Equal("hello", page.Content);
        }
Ejemplo n.º 24
0
        public void DownloadHttp()
        {
            FileDownloader downloader = new FileDownloader();

            foreach (String s in fileSizes.Keys)
            {
                downloader.Download(InstallPadTest.GetDownloadPath(s), OUTPUT_DIRECTORY);

                string fi = Path.Combine(OUTPUT_DIRECTORY, s);

                // Veryify file exists and is the correct size
                Assert.IsTrue(InstallPadTest.VerifyExistenceAndSize(fi, fileSizes[s]));
            }
        }
Ejemplo n.º 25
0
        public void Should_unzip_when_double_star_used([Frozen] IFileSystem fileSystem, FileDownloader downloader)
        {
            var file = new File()
            {
                Name = "web.zip!**", ContentHref = ""
            };

            string tempFile = @"c:\temp\abc.tmp";

            fileSystem.CreateTempFile().Returns(tempFile);

            downloader.Download(@"c:\temp", file).Wait();

            fileSystem.Received().ExtractToDirectory(tempFile, @"c:\temp");
        }
 private string  DownloadUpdateFile(UpdatePackageInfo updateinfo)
 {
     _Downloader = new FileDownloader();
     _Downloader.DownloadStarting += downloader_DownloadStarting;
     _Downloader.ProgressChanged  += downloader_ProgressChanged;
     try
     {
         _Downloader.Download(updateinfo.UpdateFileUri, DownloadFolder);
         return(_Downloader.DownloadingTo);
     }
     catch
     {
         return("");
     }
 }
Ejemplo n.º 27
0
        public void TestDownload()
        {
            TransferStatus status = FileDownloader.Download(RemotePathDownload, LocalPathDownload, _adlsClient, 25, IfExists.Overwrite, null, false, false, default(CancellationToken), false, 4194304, TransferChunkSize);//,null,IfExists.Overwrite,false,4194304,251658240L,true);

            Assert.IsTrue(status.EntriesFailed.Count == 0);
            Assert.IsTrue(status.EntriesSkipped.Count == 0);
            long origSuccess = status.FilesTransfered;
            Queue <DirectoryInfo>  localQueue  = new Queue <DirectoryInfo>();
            Queue <DirectoryEntry> remoteQueue = new Queue <DirectoryEntry>();

            localQueue.Enqueue(new DirectoryInfo(LocalPathDownload));
            remoteQueue.Enqueue(_adlsClient.GetDirectoryEntry(RemotePathDownload));
            Verify(localQueue, remoteQueue);
            status = FileDownloader.Download(RemotePathDownload, LocalPathDownload, _adlsClient, 10, IfExists.Fail);
            Assert.IsTrue(origSuccess == status.EntriesSkipped.Count);
        }
Ejemplo n.º 28
0
 public void DownloadLatestVersion()
 {
     lock (LatestDetails)
     {
         if (LatestDetails.CanUpdate && !LatestDetails.UpdateDownloaded)
         {
             var    downloadUri = new Uri(LatestDetails.InstallUrl);
             string filename    = System.IO.Path.GetFileName(downloadUri.LocalPath);
             var    filePath    = Path.Combine(Directory.GetCurrentDirectory(), filename);
             var    fd          = new FileDownloader(downloadUri, filePath);
             var    dtask       = fd.Download();
             dtask.Start();
             dtask.Wait();
         }
     }
 }
Ejemplo n.º 29
0
        public void DownloadFile()
        {
            FileDownloader downloader = new FileDownloader();

            foreach (String s in fileSizes.Keys)
            {
                string fileUrl = "file:///" + Path.Combine(DATA_DIRECTORY, s);

                downloader.Download(fileUrl, OUTPUT_DIRECTORY);

                string fi = Path.Combine(OUTPUT_DIRECTORY, s);

                // Veryify file exists and is the correct size
                Assert.IsTrue(InstallPadTest.VerifyExistenceAndSize(fi, fileSizes[s]));
            }
        }
Ejemplo n.º 30
0
        private bool CopyAsMediaFileFromUri(string mediaFolder, string uri)
        {
            var filename = Path.GetFileName(uri);

            if (string.IsNullOrEmpty(filename))
            {
                return(false);
            }

            var destFile = Path.Combine(mediaFolder, filename);

            if (File.Exists(destFile))
            {
                return(false);
            }

            var sourceFile = Path.Combine(GetWebDownloadTempFolder(), filename);

            if (string.IsNullOrEmpty(sourceFile))
            {
                return(false);
            }

            // download a local copy of the media.
            var downloader = new FileDownloader();

            if (!downloader.Download(new Uri(uri), sourceFile, true))
            {
                return(false);
            }

            if (!File.Exists(sourceFile))
            {
                return(false);
            }

            if (!CopyFileInternal(sourceFile, destFile))
            {
                return(false);
            }

            FileUtils.SafeDeleteFile(sourceFile);

            return(true);
        }
Ejemplo n.º 31
0
        public static async Task <List <RestUserMessage> > Echo(SocketTextChannel from, SocketTextChannel to, ulong fromMessageID, int count)
        {
            if (from is null)
            {
                throw new ArgumentException("to");
            }

            if (to is null)
            {
                throw new ArgumentException("to");
            }

            List <RestUserMessage> results = new List <RestUserMessage>();

            List <IMessage> messages = new List <IMessage>(await from.GetMessagesAsync(fromMessageID, Discord.Direction.Before, count).FlattenAsync());

            for (int i = messages.Count - 1; i >= 0; i--)
            {
                IMessage prevMessage = messages[i];
                if (prevMessage.Embeds.Count > 0)
                {
                    await from.SendMessageAsync("Sorry, I can't echo message embeds.");

                    continue;
                }

                if (prevMessage.Attachments.Count == 1)
                {
                    string attachmentURL = prevMessage.Attachments.Getfirst().Url;
                    string filePath      = "./Temp/" + prevMessage.Id + Path.GetExtension(attachmentURL);

                    await FileDownloader.Download(attachmentURL, filePath);

                    results.Add(await to.SendFileAsync(filePath, prevMessage.Content));
                }

                if (!string.IsNullOrEmpty(prevMessage.Content))
                {
                    results.Add(await to.SendMessageAsync(prevMessage.Content, prevMessage.IsTTS));
                }
            }

            return(results);
        }
Ejemplo n.º 32
0
        public void Cancel()
        {
            cancelTestDownloader = new FileDownloader();

            cancelTestDownloader.ProgressChanged += new DownloadProgressHandler(Cancel_ProgressChanged);
            cancelTestDownloader.Download(InstallPadTest.GetDownloadPath("test3.txt"), OUTPUT_DIRECTORY);

            string fi = Path.Combine(OUTPUT_DIRECTORY, "test3.txt");

            // Ensure file exists but is not full, since our block size is 1k and we've only downloaded
            // one block by this point.
            Assert.IsTrue(File.Exists(fi));

            FileInfo info = new FileInfo(fi);

            // If block size is 1K, which it is by default, then info.Length should be 1024
            Assert.IsTrue(info.Length != 0);
            Assert.IsTrue(info.Length < fileSizes["test3.txt"]);
        }