Ejemplo n.º 1
0
 private static void UpdateTorrentSeedDetail(ContentDetail oContentDetail, TorrentSeedDetail oDetail)
 {
     // Try to find the corresponding TorrentSeedDetail in the pre-created list
     // and update it with the given data
     foreach (VersionDetail oVerDetail in oContentDetail.Versions)
     {
         if (oVerDetail.Hash == oDetail.Hash)
         {
             List <TorrentSeedDetail> oSeeds = oVerDetail.TorrentSeeds;
             // Update the pre-created TorrentSeedDetail object contained in the VersionDetail's if any
             TorrentSeedDetail oToBeUpdate = oSeeds.Find(o => { return(o.IP == oDetail.IP); });
             if (oToBeUpdate != null)
             {
                 oToBeUpdate.Name          = oDetail.Name;
                 oToBeUpdate.TotalSize     = oDetail.TotalSize;
                 oToBeUpdate.PartDone      = oDetail.PartDone;
                 oToBeUpdate.StatusCode    = oDetail.StatusCode;
                 oToBeUpdate.DatePublished = oDetail.DatePublished;
                 oToBeUpdate.Error         = oDetail.Error;
             }
         }
     }
 }
Ejemplo n.º 2
0
        private static string ProcessContentMonitor(List <string> listVersion, JobExecutionContext context)
        {
            JobDataMap oJobDataMap = context.JobDetail.JobDataMap;

            string[]      listSeedWebIP  = AppConfig.ContentDeployJob.OfficalSeedWebIPList;
            ContentDetail oContentDetail = new ContentDetail();

            // Construct the hierarchy per the Version list & registered Seed Web IP list first
            oContentDetail.Name        = context.JobDetail.Name;
            oContentDetail.DateCreated = GetContentCreateDate(context.JobDetail.Name);
            foreach (string sVer in listVersion)
            {
                VersionDetail     oVerDetail      = new VersionDetail();
                ContentGenRecipes oContentRecipes = GetContentRecipes(oContentDetail.Name, sVer);

                if (oContentRecipes != null)
                {
                    oVerDetail.Name        = oContentRecipes.ContentFileName;
                    oVerDetail.DateCreated = oContentRecipes.CreateDateTime;
                }
                else
                {
                    oVerDetail.Name        = "";
                    oVerDetail.DateCreated = DateTime.MaxValue;
                }
                oVerDetail.Hash            = sVer;
                oVerDetail.DeployToTracker = QueryTrackerTorrentDeploymentStatus(sVer);
                oContentDetail.Versions.Add(oVerDetail);
                foreach (string sIP in listSeedWebIP)
                {
                    TorrentSeedDetail oDetail = new TorrentSeedDetail();

                    // Create the TorrentSeedDetail first with the unknown status
                    // And replace the unkown status with the real status parsed from JSON later
                    oDetail.IP            = sIP;
                    oDetail.Hash          = oVerDetail.Hash.ToUpper();
                    oDetail.Name          = "";
                    oDetail.TotalSize     = 0;
                    oDetail.PartDone      = 0f;
                    oDetail.StatusCode    = TorrentStatus.Unknown;
                    oDetail.DatePublished = DateTime.MaxValue;
                    oDetail.Error         = AppResource.SeedWebConnectionFailed;
                    oVerDetail.TorrentSeeds.Add(oDetail);
                }
            }
            // Enumerate all the registered seed web IP for walking through all the seed monitors
            foreach (string sIP in listSeedWebIP)
            {
                JobDetail oSeedJob = context.Scheduler.GetJobDetail(
                    sIP, SeedMonitorConstants.SeedMonitorGroupName);
                // Check to see if the seed monitor job exists
                if (oSeedJob != null)
                {
                    string sTorrentDetails = (string)oSeedJob.JobDataMap[SeedMonitorJobDataMapConstants.TorrentDetails];
                    // Check to see if the seed monitor has torrent detail JSON ready
                    if (sTorrentDetails != null)
                    {
                        List <TorrentDetail> listTorrentDetail = JsonConvert.DeserializeObject <List <TorrentDetail> >(sTorrentDetails);
                        List <string>        listTorrentInSeed = new List <string>();
                        // Enumerate all the TorrentDetail to update to the pre-created TorrentSeedDetail
                        foreach (TorrentDetail oTorrentDetail in listTorrentDetail)
                        {
                            TorrentSeedDetail oDetail = new TorrentSeedDetail();
                            oDetail.IP            = sIP;
                            oDetail.Hash          = oTorrentDetail.UniqueID.ToUpper();
                            oDetail.Name          = oTorrentDetail.Name;
                            oDetail.TotalSize     = oTorrentDetail.TotalSize;
                            oDetail.PartDone      = oTorrentDetail.PartDone;
                            oDetail.StatusCode    = oTorrentDetail.StatusCode;
                            oDetail.DatePublished = oTorrentDetail.DateAdded;
                            oDetail.Error         = oTorrentDetail.Error;
                            // Use the TorrentSeedDetail object to update the corresponding list
                            // in the VersionDetails list so the JSON just needs to be parsed just once
                            UpdateTorrentSeedDetail(oContentDetail, oDetail);
                            // Add the torrent hash for later use of checking the exclusion of the torrents
                            listTorrentInSeed.Add(oDetail.Hash);
                        }
                        // Update TorrentSeedDetail not found in the seed's torrent list to "content not deployed" error
                        foreach (VersionDetail oVersion in oContentDetail.Versions.FindAll
                                     (x => { return(!listTorrentInSeed.Contains(x.Hash)); }))
                        {
                            TorrentSeedDetail oTorrentSeed = oVersion.TorrentSeeds.Find(x => { return(x.IP == sIP); });
                            if (oTorrentSeed != null)
                            {
                                oTorrentSeed.Error = AppResource.ContentNotDeployToSeed;
                            }
                        }
                    }
                }
            }
            // Serialize the content detail to JSON and return
            return(JsonConvert.SerializeObject(oContentDetail));
        }