public void TestDownload()
 {
     DownloadEngine downloader = new DownloadEngine(@"http://open-media-library.googlecode.com/files/Open_Media_Library_User_Manual%280.3b%29.pdf");
     downloader.Log += new DownloadEngine.DownloadEventsHandler(downloader_Log);
     if (downloader.Download()) {
         Assert.IsTrue(File.Exists(downloader.DownloadedFile));
         FileInfo fi = new FileInfo(downloader.DownloadedFile);
         Assert.AreEqual(fi.Length, downloader.TotalBytes);
     }
 }
Ejemplo n.º 2
0
        public static ActionResult DownloadAndInstallMediaInfo(Session session)
        {
            sessionObj = session;
            string type = Environment.GetEnvironmentVariable(@"PROCESSOR_ARCHITECTURE");
            string miUrl = type.ToUpperInvariant().Contains("86")
                ? CustomActions.MediaInfoX86Url
                : CustomActions.MediaInfoX64Url;

            CustomActions.LogToSession(string.Format("MediaInfo: Selected {0} based on detected processor architecture of {1}",
                miUrl, Environment.GetEnvironmentVariable(@"PROCESSOR_ARCHITECTURE")));

            DownloadEngine miEngine = new DownloadEngine(miUrl);

            miEngine.Bytes += (i) => {
                if (i > 0) {
                    int pct = Convert.ToInt32((Convert.ToDouble(i) / Convert.ToDouble(miEngine.TotalBytes)) * 100);
                    CustomActions.LogToSession(string.Format("MediaInfo: ({0}) {1}b of {2}b", pct, i, miEngine.TotalBytes));
                }
            };

            CustomActions.LogToSession("MediaInfo: Beginning download");
            bool miDownloaded = false;
            try {
                miDownloaded = miEngine.Download(true);
            } catch (Exception ex) {
                CustomActions.LogToSession(string.Format("MediaInfo: Error {0}", ex.Message));
                return ActionResult.Failure;
            }

            if (!miDownloaded) {
                CustomActions.LogToSession("MediaInfo: Failed to download");
                return ActionResult.Failure;
            }
            CustomActions.LogToSession(string.Format("MediaInfo: Downloaded File Location {0}", miEngine.DownloadedFile));
            CustomActions.LogToSession(string.Format("MediaInfo: Final destination is {0}", CustomActions.MediaInfoLocalPath));

            try {
                CustomActions.LogToSession("MediaInfo: copying into final location");
                File.Copy(miEngine.DownloadedFile, CustomActions.MediaInfoLocalPath, true);
            } catch (Exception ex) {
                CustomActions.LogToSession(string.Format("MediaInfo Error: {0}", ex.Message));
                return ActionResult.Failure;
            }

            return ActionResult.Success;
        }
Ejemplo n.º 3
0
        public static ActionResult DownloadSQLServer(Session session)
        {
            sessionObj = session;
            string type = Environment.GetEnvironmentVariable(@"PROCESSOR_ARCHITECTURE");
            string sqlUrl = type.ToUpperInvariant().Contains("86")
                ? CustomActions.SqlServerX86Url
                : CustomActions.SqlServer64Url;

            DownloadEngine sqlEngine = new DownloadEngine(sqlUrl);
            sqlEngine.Log += (s) => {
                int pct = Convert.ToInt32((Convert.ToDouble(Int32.Parse(s)) / Convert.ToDouble(sqlEngine.TotalBytes)) * 100);
                CustomActions.LogToSession(string.Format("SqlServer: {0}", pct));
            };
            bool sqlDownloaded = sqlEngine.Download();
            if (!sqlDownloaded) {
                CustomActions.LogToSession("SqlServer Failed to download");
                return ActionResult.Failure;
            }
            CustomActions.LogToSession(string.Format("File is: {0}", sqlEngine.DownloadedFile));
            session["SQLSERVERFILE"] = sqlEngine.DownloadedFile;

            return ActionResult.Success;
        }
Ejemplo n.º 4
0
        public static ActionResult DownloadAndInstallUserManual(Session session)
        {
            sessionObj = session;
            DownloadEngine umEngine = new DownloadEngine(CustomActions.UserManualUrl);
            umEngine.Log += (s) => {
                int pct = Convert.ToInt32((Convert.ToDouble(Int32.Parse(s)) / Convert.ToDouble(umEngine.TotalBytes)) * 100);
                CustomActions.LogToSession(string.Format("PDF: {0}", pct));
            };
            bool umDownloaded = umEngine.Download();
            if (!umDownloaded) {
                CustomActions.LogToSession("Open_Media_Library_User_Manual Failed to download");
                return ActionResult.Failure;
            }
            CustomActions.LogToSession(string.Format("File is: {0}", umEngine.DownloadedFile));
            try {
                if (Directory.Exists(CustomActions.UserManualHelpPath)) {
                    CustomActions.LogToSession(string.Format(@"Creating folder: {0}", CustomActions.UserManualHelpPath));
                    Directory.CreateDirectory(CustomActions.UserManualHelpPath);
                    CustomActions.LogToSession("setting access controls");
                //    DirectoryInfo dInfo = new DirectoryInfo(CustomActions.UserManualHelpPath);
                //    System.Security.AccessControl.DirectorySecurity dSec = dInfo.GetAccessControl();
                //    dSec.AddAccessRule(new System.Security.AccessControl.FileSystemAccessRule(
                //        "Users", System.Security.AccessControl.FileSystemRights.FullControl, System.Security.AccessControl.AccessControlType.Allow
                //        ));
                //    dInfo.SetAccessControl(dSec);
                }
                CustomActions.LogToSession("Copying file");
                File.Copy(umEngine.DownloadedFile, CustomActions.UserManualPath, true);
            } catch (Exception ex) {
                CustomActions.LogToSession(string.Format("Open_Media_Library_User_Manual Error: {0}", ex.Message));
                return ActionResult.Failure;
            }

            return ActionResult.Success;
        }
Ejemplo n.º 5
0
        public static ActionResult DownloadAndInstallMEncoder(Session session)
        {
            sessionObj = session;
            DownloadEngine meEngine = new DownloadEngine(CustomActions.MEncoderUrl);
            meEngine.Log += (s) => {
                int pct = Convert.ToInt32((Convert.ToDouble(Int32.Parse(s)) / Convert.ToDouble(meEngine.TotalBytes)) * 100);
                CustomActions.LogToSession(string.Format("MEncoder: {0}", pct));
            };
            bool meDownloaded = meEngine.Download();
            if (!meDownloaded) {
                CustomActions.LogToSession("MEncoder Failed to download");
                return ActionResult.Failure;
            }
            CustomActions.LogToSession(string.Format("File is: {0}", meEngine.DownloadedFile));
            try {
                File.Copy(meEngine.DownloadedFile, CustomActions.MEncoderPath, true);
            } catch (Exception ex) {
                CustomActions.LogToSession(string.Format("MEncoder Error: {0}", ex.Message));
                return ActionResult.Failure;
            }

            return ActionResult.Success;
        }
Ejemplo n.º 6
0
        private void ProcessSingleFileUpdate(System.Version newVersion, bool updateGAC, string type, string url, string assemblyFile)
        {
            System.Version currentVersion = VersionOfAssembly(assemblyFile);
            if (currentVersion != null && (currentVersion < newVersion)) {
                DownloadEngine downloader = new DownloadEngine(url);
                if (downloader.Download()) {
                    string newfile = downloader.DownloadedFile;
                    if (updateGAC) {
                        RemoveOldGACEntry(assemblyFile);
                        downloader = null;
                    }

                    switch (type) {
                        case "Full":
                            break;
                        case "Replace":
                            File.Move(assemblyFile, assemblyFile + currentVersion);
                            File.Move(downloader.DownloadedFile, assemblyFile);
                            break;
                        case "Restart":
                            File.Move(assemblyFile, assemblyFile + currentVersion);
                            File.Move(downloader.DownloadedFile, assemblyFile);
                            break;
                        default:
                            break;
                    }
                    if (updateGAC)
                        AddNewGACEntry(assemblyFile);
                }
            }
        }