private IEnumerable <DownloadCount> GatherDownloadCounts(IEnumerable <DownloadEntity> downloads, out DateTime lastTime)
        {
            var countUpdates = new Dictionary <string, DownloadCount>();

            lastTime = DateTime.MinValue;

            foreach (var download in downloads)
            {
                var redirect = this.RedirectTable.GetRedirect(download.DownloadKey);

                if (redirect != null)
                {
                    // This protects against the case that the system transaction's download count last updated was not successfully
                    // written but the redirect count was updated.
                    if (redirect.DownloadCountLastUpdated.HasValue && redirect.DownloadCountLastUpdated < download.Timestamp)
                    {
                        DownloadCount dc;

                        if (!countUpdates.TryGetValue(download.DownloadKey, out dc))
                        {
                            dc = new DownloadCount(redirect);

                            countUpdates.Add(redirect.Id, dc);
                        }

                        ++dc.Count;
                    }
                }

                lastTime = (lastTime < download.Timestamp.DateTime) ? download.Timestamp.DateTime : lastTime;
            }

            return(countUpdates.Values);
        }
 public string GetDownloadCountDisplayText()
 {
     if (HasDownloadCount)
     {
         return(DownloadCount.ToString("N0"));
     }
     return(String.Empty);
 }
예제 #3
0
 public static void RecordDownload(string version, string file)
 {
     using (var db = new LiteDatabase(GetDBPath()))
     {
         var countCollection = db.GetCollection <DownloadCount>("DownloadCount");
         var counter         = countCollection.Find(x => x.File == file && x.Version == version).FirstOrDefault();
         if (counter == null)
         {
             counter = new DownloadCount()
             {
                 File    = file,
                 Version = version,
                 Count   = 1
             };
             countCollection.Insert(counter);
         }
         else
         {
             counter.Count++;
             countCollection.Update(counter);
         }
     }
 }