Example #1
0
        private static List <Tuple <string, Exception> > ProcessContentResume(string sContentUniqueId, string sContentHashCode)
        {
            string sIP = "";
            List <Tuple <string, Exception> > listFailedSeed = new List <Tuple <string, Exception> >();

            try
            {
                // Check the specified torrent in the offical seeds
                IManagementTask oCheckTask = (IManagementTask) new GetTorrentFileListTask(sContentHashCode);
                // Resume the specified torrent in the offical seeds
                IManagementTask oTask = (IManagementTask) new ResumeTorrentTask(sContentHashCode);
                // Enumerate each seed web for sending the command
                AppConfig.ContentDeployJob.OfficalSeedWebList.ForEach(oSeedWeb =>
                {
                    try
                    {
                        sIP = oSeedWeb.IP;
                        QbtAdapter oAdapter = new QbtAdapter(
                            false,
                            sIP,
                            oSeedWeb.Port,
                            oSeedWeb.AdminName,
                            oSeedWeb.AdminPassword);
                        oAdapter.ExecuteTask(oCheckTask);
                        if (((ArrayList)oCheckTask.Result).Count > 0)
                        {
                            oAdapter.ExecuteTask(oTask);
                        }
                    }
                    catch (Exception oEx)
                    {
                        listFailedSeed.Add(new Tuple <string, Exception>(sIP, oEx));
                    }
                });
            }
            catch (Exception oEx)
            {
                throw oEx;
            }
            return(listFailedSeed);
        }
Example #2
0
        private static string ProcessSeedMonitor(AppConfig.ContentDeployJob.OfficalSeedWeb oSeedWeb)
        {
            try
            {
                // Retrieve all the torrent details in the offical seed
                IManagementTask oTask = (IManagementTask) new RetrieveTorrentDetailsTask();

                QbtAdapter oAdapter = new QbtAdapter(
                    false,
                    oSeedWeb.IP,
                    oSeedWeb.Port,
                    oSeedWeb.AdminName,
                    oSeedWeb.AdminPassword);
                oAdapter.ExecuteTask(oTask);
                // Serialize the torrent details to JSON and return
                return(JsonConvert.SerializeObject(oTask.Result));
            }
            catch (Exception oEx)
            {
                // Generate the exception in more detail
                throw new ApplicationException(string.Format(AppResource.OfficalSeedCmdFailed, oSeedWeb.IP, typeof(RetrieveTorrentDetailsTask).Name), oEx);
            }
        }
Example #3
0
        private static List <Tuple <string, Exception> > ProcessContentOffline(string sContentUniqueId, string sContentHashCode)
        {
            // Send the torrent remove command to the offical seeds first
            // then deleted the reployed torrent files afterward to make
            // the availability of the content files more consistent.

            string sIP = "";
            List <Tuple <string, Exception> > listFailedSeed = new List <Tuple <string, Exception> >();

            try
            {
                // Remove the deployed torrent files from the offical seeds
                IManagementTask oTask = (IManagementTask) new RemoveTorrentTask(sContentHashCode);
                // Enumerate each seed web for sending the command
                AppConfig.ContentDeployJob.OfficalSeedWebList.ForEach(oSeedWeb =>
                {
                    try
                    {
                        sIP = oSeedWeb.IP;
                        QbtAdapter oAdapter = new QbtAdapter(
                            false,
                            sIP,
                            oSeedWeb.Port,
                            oSeedWeb.AdminName,
                            oSeedWeb.AdminPassword);
                        oAdapter.ExecuteTask(oTask);
                    }
                    catch (Exception oEx)
                    {
                        listFailedSeed.Add(new Tuple <string, Exception>(sIP, oEx));
                    }
                });
            }
            catch (Exception oEx)
            {
                throw oEx;
            }

            try
            {
                // Delete the deployed torrent files if any
                if (File.Exists(
                        AppConfig.ContentDeployJob.TorrentDeployTarget + "\\" +
                        sContentHashCode + ContentGenJob.TorrentExtension))
                {
                    File.Delete(
                        AppConfig.ContentDeployJob.TorrentDeployTarget + "\\" +
                        sContentHashCode + ContentGenJob.TorrentExtension);
                }
                if (File.Exists(
                        AppConfig.ContentDeployJob.VipTorrentDeployTarget + "\\" +
                        sContentHashCode + ContentGenJob.TorrentVipExtension))
                {
                    File.Delete(
                        AppConfig.ContentDeployJob.VipTorrentDeployTarget + "\\" +
                        sContentHashCode + ContentGenJob.TorrentVipExtension);
                }
                if (File.Exists(
                        AppConfig.ContentDeployJob.FqdnTorrentDeployTarget + "\\" +
                        sContentHashCode + ContentGenJob.TorrentFqdnExtension))
                {
                    File.Delete(
                        AppConfig.ContentDeployJob.FqdnTorrentDeployTarget + "\\" +
                        sContentHashCode + ContentGenJob.TorrentFqdnExtension);
                }
                // Delete the deployed downloader (for portal users download) if any
                if (File.Exists(
                        AppConfig.ContentDeployJob.DownloaderDeployTarget + "\\" +
                        sContentUniqueId + "\\" +
                        sContentHashCode + ContentGenJob.DownloaderExtension))
                {
                    File.Delete(
                        AppConfig.ContentDeployJob.DownloaderDeployTarget + "\\" +
                        sContentUniqueId + "\\" +
                        sContentHashCode + ContentGenJob.DownloaderExtension);
                }
                // Delete the deployed torrent file (for portal users download) if any
                if (File.Exists(
                        AppConfig.ContentDeployJob.DownloaderDeployTarget + "\\" +
                        sContentUniqueId + "\\" +
                        sContentHashCode + ContentGenJob.TorrentExtension))
                {
                    File.Delete(
                        AppConfig.ContentDeployJob.DownloaderDeployTarget + "\\" +
                        sContentUniqueId + "\\" +
                        sContentHashCode + ContentGenJob.TorrentExtension);
                }
            }
            catch (Exception oEx)
            {
                throw oEx;
            }
            return(listFailedSeed);
        }
Example #4
0
        public static void Rollback(string sContentHashCode)
        {
            lock (ContentGenJob.sigLock)
            {
                if (sContentHashCode != "")
                {
                    // Delete the deployed torrent files if any
                    if (File.Exists(
                            AppConfig.ContentDeployJob.TorrentDeployTarget + "\\" +
                            sContentHashCode + ContentGenJob.TorrentExtension))
                    {
                        File.Delete(
                            AppConfig.ContentDeployJob.TorrentDeployTarget + "\\" +
                            sContentHashCode + ContentGenJob.TorrentExtension);
                    }
                    if (File.Exists(
                            AppConfig.ContentDeployJob.VipTorrentDeployTarget + "\\" +
                            sContentHashCode + ContentGenJob.TorrentVipExtension))
                    {
                        File.Delete(
                            AppConfig.ContentDeployJob.VipTorrentDeployTarget + "\\" +
                            sContentHashCode + ContentGenJob.TorrentVipExtension);
                    }
                    if (File.Exists(
                            AppConfig.ContentDeployJob.FqdnTorrentDeployTarget + "\\" +
                            sContentHashCode + ContentGenJob.TorrentFqdnExtension))
                    {
                        File.Delete(
                            AppConfig.ContentDeployJob.FqdnTorrentDeployTarget + "\\" +
                            sContentHashCode + ContentGenJob.TorrentFqdnExtension);
                    }
                    if (File.Exists(
                            AppConfig.ContentDeployJob.DownloaderDeployTarget + "\\" +
                            sContentHashCode + ContentGenJob.DownloaderExtension))
                    {
                        File.Delete(
                            AppConfig.ContentDeployJob.DownloaderDeployTarget + "\\" +
                            sContentHashCode + ContentGenJob.DownloaderExtension);
                    }
                    if (File.Exists(
                            AppConfig.ContentDeployJob.DownloaderDeployTarget + "\\" +
                            sContentHashCode + ContentGenJob.TorrentExtension))
                    {
                        File.Delete(
                            AppConfig.ContentDeployJob.DownloaderDeployTarget + "\\" +
                            sContentHashCode + ContentGenJob.TorrentExtension);
                    }

                    // Remove the deployed torrent files from the offical seeds by sending the remove command anyway
                    IManagementTask oTask = (IManagementTask) new RemoveTorrentTask(sContentHashCode);
                    // Enumerate each seed web for sending the command
                    AppConfig.ContentDeployJob.OfficalSeedWebList.ForEach(oSeedWeb =>
                    {
                        QbtAdapter oAdapter = new QbtAdapter(
                            false,
                            oSeedWeb.IP,
                            oSeedWeb.Port,
                            oSeedWeb.AdminName,
                            oSeedWeb.AdminPassword);
                        // Supress the exception if occurs to keep on trying the next seed
                        try
                        {
                            oAdapter.ExecuteTask(oTask);
                        }
                        catch { }
                    });
                }
            }
        }
Example #5
0
        public static List <Tuple <string, Exception> > ProcessContentDeploy(string sContentUniqueId, string sContentHashCode)
        {
            try
            {
                // Deploy Torrent File to the target folder
                CopyFile(
                    AppConfig.ContentDeployJob.TorrentDeployTarget,
                    sContentUniqueId,
                    sContentHashCode,
                    ContentGenJob.TorrentExtension);
                // Deploy Vip Torrent File to the target folder
                CopyFile(
                    AppConfig.ContentDeployJob.VipTorrentDeployTarget,
                    sContentUniqueId,
                    sContentHashCode,
                    ContentGenJob.TorrentVipExtension);
                // Deploy FQDN Torrent File to the target folder
                CopyFile(
                    AppConfig.ContentDeployJob.FqdnTorrentDeployTarget,
                    sContentUniqueId,
                    sContentHashCode,
                    ContentGenJob.TorrentFqdnExtension);
                // Deploy Content Downloader (for portal users download) to the target folder
                CopyFile(
                    AppConfig.ContentDeployJob.DownloaderDeployTarget,
                    sContentUniqueId,
                    sContentHashCode,
                    ContentGenJob.DownloaderExtension,
                    true);
                // Deploy Torrent File (for portal users download) to the target folder
                CopyFile(
                    AppConfig.ContentDeployJob.DownloaderDeployTarget,
                    sContentUniqueId,
                    sContentHashCode,
                    ContentGenJob.TorrentExtension);
            }
            catch (Exception oEx)
            {
                Rollback(sContentHashCode);
                throw oEx;
            }

            string sIP = "";
            List <Tuple <string, Exception> > listFailedSeed = new List <Tuple <string, Exception> >();

            try
            {
                string          sFqdnTorrentPublishUrl = AppConfig.ContentDeployJob.FqdnTorrentPublishUrl + "//" + sContentHashCode + ContentGenJob.TorrentFqdnExtension;
                IManagementTask oTask = (IManagementTask) new AddTorrentByUrlTask(sFqdnTorrentPublishUrl);
                // Enumerate each seed web for sending the command
                AppConfig.ContentDeployJob.OfficalSeedWebList.ForEach(oSeedWeb =>
                {
                    try
                    {
                        sIP = oSeedWeb.IP;
                        QbtAdapter oAdapter = new QbtAdapter(
                            false,
                            sIP,
                            oSeedWeb.Port,
                            oSeedWeb.AdminName,
                            oSeedWeb.AdminPassword);
                        oAdapter.ExecuteTask(oTask);
                    }
                    catch (Exception oEx)
                    {
                        listFailedSeed.Add(new Tuple <string, Exception>(sIP, oEx));
                    }
                });
            }
            catch (Exception oEx)
            {
                Rollback(sContentHashCode);
                throw oEx;
            }
            return(listFailedSeed);
        }
Example #6
0
        public void ExecuteTask(IManagementTask task)
        {
            switch (task.Method)
            {
            case TaskMethod.RetrieveTorrentDetails:
            {
                RetrieveTorrentDetailsTask theTask = (RetrieveTorrentDetailsTask)task;
                // Request the details of all torrents from server
                JArray details = JArray.Parse(MakeRequest(BuildWebUIUrl("/json/events")));
                theTask.Result = ParseJsonTorrentDetails(details);
            }
            break;

            case TaskMethod.GetTorrentFileList:
            {
                GetTorrentFileListTask theTask = (GetTorrentFileListTask)task;
                // Request files listing for a specific torrent
                string hash     = theTask.TorrentHash.ToLower();     // <== Must be lower cases!!
                JArray filelist = JArray.Parse(MakeRequest(BuildWebUIUrl("/json/propertiesFiles/") + hash));
                theTask.Result = ParseJsonFiles(filelist);
            }
            break;

            case TaskMethod.AddTorrentByFile:
            {
                AddTorrentByFileTask theTask = (AddTorrentByFileTask)task;
                // Upload a local .torrent file
                string file = theTask.TorrentFilePath;
                MakeUploadRequest(BuildWebUIUrl("/command/upload"), file);
            }
            break;

            case TaskMethod.AddTorrentByUrl:
            {
                AddTorrentByUrlTask theTask = (AddTorrentByUrlTask)task;
                // Request to add a torrent by URL
                string url = theTask.TorrentFileUrl;
                MakeRequest(BuildWebUIUrl("/command/download"), new KeyValuePair <string, string>("urls", url));
            }
            break;

            case TaskMethod.AddTorrentByMagnetUrl:
            {
                AddTorrentByMagnetUrlTask theTask = (AddTorrentByMagnetUrlTask)task;
                // Request to add a magnet link by URL
                string magnet = theTask.TorrentMagnetUrl;
                MakeRequest(BuildWebUIUrl("/command/download"), new KeyValuePair <string, string>("urls", magnet));
            }
            break;

            case TaskMethod.RemoveTorrent:
            {
                RemoveTorrentTask theTask = (RemoveTorrentTask)task;
                // Remove a torrent
                string hash = theTask.TorrentHash.ToLower();         // <== Must be lower cases!!
                MakeRequest(BuildWebUIUrl("/command/deletePerm"), new KeyValuePair <string, string>("hashes", hash));
            }
            break;

            case TaskMethod.PauseTorrent:
            {
                PauseTorrentTask theTask = (PauseTorrentTask)task;
                // Pause a torrent
                string hash = theTask.TorrentHash.ToLower();         // <== Must be lower cases!!
                MakeRequest(BuildWebUIUrl("/command/pause"), new KeyValuePair <string, string>("hash", hash));
            }
            break;

            case TaskMethod.ResumeTorrent:
            {
                ResumeTorrentTask theTask = (ResumeTorrentTask)task;
                // Resume a torrent
                string hash = theTask.TorrentHash.ToLower();         // <== Must be lower cases!!
                MakeRequest(BuildWebUIUrl("/command/resume"), new KeyValuePair <string, string>("hash", hash));
            }
            break;

            case TaskMethod.PauseAllTorrents:
            {
                // Resume all torrents
                MakeRequest(BuildWebUIUrl("/command/pauseall"));
            }
            break;

            case TaskMethod.ResumeAllTorrents:
            {
                // Resume all torrents
                MakeRequest(BuildWebUIUrl("/command/resumeall"));
            }
            break;

            case TaskMethod.SetTorrentFilePriorities:
            {
                throw new NotImplementedException();
                //// Update the priorities to a set of files
                //SetTorrentFilePrioritiesTask setPrio = (SetTorrentFilePrioritiesTask)task;
                //String newPrio = "0";
                //if (setPrio.getNewPriority() == Priority.Low) {
                //    newPrio = "1";
                //} else if (setPrio.getNewPriority() == Priority.Normal) {
                //    newPrio = "2";
                //} else if (setPrio.getNewPriority() == Priority.High) {
                //    newPrio = "7";
                //}
                //// We have to make a separate request per file, it seems
                //for (TorrentFile file in setPrio.FileList) {
                //    MakeRequest("/command/setFilePrio",
                //        new KeyValuePair<string, string>("hash", setPrio.TorrentHash),
                //        new KeyValuePair<string, string>("id", file.Key),
                //        new KeyValuePair<string, string>("priority", newPrio));
                //}
            }
            break;

            case TaskMethod.SetTorrentTransferRates:
            {
                throw new NotImplementedException();
                //// TODO: This doesn't seem to work yet
                //// Request to set the maximum transfer rates
                //SetTorrentTransferRatesTask ratesTask = (SetTorrentTransferRatesTask)task;
                //int dl = (ratesTask.getDownloadRate() == null ? -1 : ratesTask.getDownloadRate().intValue());
                //int ul = (ratesTask.getUploadRate() == null ? -1 : ratesTask.getUploadRate().intValue());

                //// First get the preferences
                //JObject prefs = JObject.Parse(MakeRequest("/json/preferences"));
                //prefs.Add("dl_limit", dl);
                //prefs.Add("up_limit", ul);
                //MakeRequest("/command/setPreferences", new KeyValuePair<string, string>("json", URLEncoder.encode(prefs.toString(), HTTP.UTF_8)));
            }
            break;

            default:
                throw new NotImplementedException(task.Method.ToString() + " is not supported by " + this.GetType().Name);
                break;
            }
        }