/// <summary>
        /// Used to set up <see cref="Receive"/> methods for <see cref="FeedParserCoordinator"/>
        /// </summary>
        private void Initialize()
        {
            //Give the Sender a copy of our latest DownloadStats
            Receive <GetStats>(stats => Sender.Tell(_downloadStats));

            //Get an update on remaining downloads that need to be processed
            Receive <RemainingDownloadCount>(count =>
            {
                _downloadStats = _downloadStats.Merge(count);
                SendMessage(string.Format("Need to process an additional {0} pages and {1} images for {2}", count.HtmlPages, count.Images, count.FeedUrl));
            });

            //Process an update on completed downloads
            Receive <DownloadComplete>(complete =>
            {
                _downloadStats = _downloadStats.Merge(complete);
                SendMessage(string.Format("Completed processing of {0} pages and {1} images for {2}", complete.HtmlPages, complete.Images, complete.FeedUrl), PipeToSampleStatusCode.Success);

                //Check to see if this is the last outstanding item that needs to be downloaded
                if (_downloadStats.IsComplete)
                {
                    SignalFeedProcessingCompleted();
                }
            });

            //Feed contained no itmes
            Receive <EmptyFeed>(feed => SignalFeedProcessingCompleted());

            Receive <ErrorParsingFeed>(
                feed => SignalFeedProcessingFailure(string.Format("Error parsing feed {0}", _feedUri), _feedUri.ToString()));
        }
 /// <summary>
 /// This constructor is for unit testing.
 /// </summary>
 public FeedParserCoordinator(Uri feedUri, DownloadStats downloadStats, string consoleWriterActorPath)
 {
     _feedUri                = feedUri;
     _downloadStats          = downloadStats;
     _consoleWriterActorPath = consoleWriterActorPath;
     Initialize();
 }
예제 #3
0
        public ActionResult GetStatsAsync(int pid, int relid, string period, string arg)
        {
            DateTime   end;
            DateTime   start;
            TimePeriod pd = TimePeriod.Auto;

            DownloadStats.ParseQuery(period, arg, out pd, out start, out end);
            DownloadStats stats = relid != -1 ? CurrentUserModel.Stats.GetReleaseDownloadStats(relid, pd, start, end) : CurrentUserModel.Stats.GetProjectDownloadStats(pid, pd, start, end);

            return(Content(stats.ToJson()));
        }
예제 #4
0
        public ActionResult GetRepoDownloadStatsAsync(string period, string arg)
        {
            CurrentUserModel.CheckIsAdmin();
            DateTime   end;
            DateTime   start;
            TimePeriod pd = TimePeriod.Auto;

            DownloadStats.ParseQuery(period, arg, out pd, out start, out end);
            DownloadStats stats = CurrentUserModel.Stats.GetTotalRepoDownloadStats(pd, start, end);

            return(Content(stats.ToJson()));
        }
예제 #5
0
        public ActionResult GetTopDownloads(string period, string arg)
        {
            CurrentUserModel.CheckIsAdmin();
            DateTime   end;
            DateTime   start;
            TimePeriod pd = TimePeriod.Auto;

            DownloadStats.ParseQuery(period, arg, out pd, out start, out end);

            List <DownloadInfo> stats = CurrentUserModel.Stats.GetTopDownloads(start, end);
            StringBuilder       sb    = new StringBuilder();

            foreach (var di in stats)
            {
                if (sb.Length > 0)
                {
                    sb.Append(',');
                }
                sb.AppendFormat("{{\"count\":{0},\"platform\":\"{1}\",\"projectId\":{2},\"appVersion\":\"{3}\",\"name\":\"{4}\"}}", di.Count, di.Platform, di.Release.ProjectId, di.Release.TargetAppVersion, di.Release.AddinName + " v" + di.Release.Version);
            }
            return(Content("[" + sb + "]"));
        }
예제 #6
0
        public static string ReloadEverything()
        {
#if (!DEBUG)
            try {
#endif
            //if dlstats was initialized, write them to disk before reloading.
            if (dlStatsInitialized)
            {
                dlStats.VerifyStatisticsIntegrity(U.GetPackageListInLatestPackageset());
                File.WriteAllText((Config + "/dlstats.bin").AsPath(), dlStats.ToDataBinary(U.GetPackageList(latestPackageset)));
            }

            //use temporary variables so if anything goes wrong, values wont be out of sync.
            Dictionary <string, string> _Manifests = new Dictionary <string, string>();

            string _Temp   = (AppContext.BaseDirectory + "/temp").AsPath();
            string _Files  = (AppContext.BaseDirectory + "/files").AsPath();
            string _Config = (AppContext.BaseDirectory + "/config").AsPath();

            if (!Directory.Exists(_Temp))
            {
                Directory.CreateDirectory(_Temp);
            }
            if (!Directory.Exists(_Files))
            {
                Directory.CreateDirectory(_Files);
            }
            if (!Directory.Exists(_Config))
            {
                Directory.CreateDirectory(_Config);
            }
            if (!File.Exists((_Config + "/latestpackageset.txt").AsPath()))
            {
                File.WriteAllText((_Config + "/latestpackageset.txt").AsPath(), "default");
            }
            if (!File.Exists((_Config + "/latestappversion.txt").AsPath()))
            {
                File.WriteAllText((_Config + "/latestappversion.txt").AsPath(), "NO VERSION");
            }
            if (!File.Exists((_Config + "/validchannels.txt").AsPath()))
            {
                File.WriteAllLines((_Config + "/validchannels.txt").AsPath(), new string[] { "latest", "nightly" });
            }

            foreach (string n in Directory.EnumerateDirectories(_Files))
            {
                string k = n.Split(Path.DirectorySeparatorChar).Last();
                if (!File.Exists((_Files + "/" + k + "/manifest6.json").AsPath()))
                {
                    File.WriteAllText(_Files + "/" + k + "/manifest6.json", "{}");
                }
            }

            string _latestPackageset = File.ReadAllText((_Config + "/latestpackageset.txt").AsPath());
            string _latestAppVersion = File.ReadAllText((_Config + "/latestappversion.txt").AsPath());
            string[] _validChannels  = File.ReadAllLines((_Config + "/validchannels.txt").AsPath());

            //look away
            foreach (string n in Directory.EnumerateDirectories(_Files))
            {
                string   k = n.Split(Path.DirectorySeparatorChar).Last();
                Manifest m = JsonConvert.DeserializeObject <Manifest>(File.ReadAllText((_Files + "/" + k + "/manifest6.json").AsPath()));
                foreach (string c in Directory.EnumerateDirectories((_Files + "/" + k).AsPath()))
                {
                    string  f = c.Split(Path.DirectorySeparatorChar).Last();
                    Package p = JsonConvert.DeserializeObject <Package>(File.ReadAllText((_Files + "/" + k + "/" + f + "/info.json").AsPath()));
                    m.Platforms[p.Platform].PackageSections[p.Section].Categories[p.Category].Subcategories[p.Subcategory].Packages[p.ID] = p;
                }
                _Manifests[k] = JsonConvert.SerializeObject(m, Formatting.Indented);
            }

            //this must be set before GetPackageListInLatestPackageset() is called
            Files = _Files;

            DownloadStats _dlStats;

            if (File.Exists((_Config + "/dlstats.bin").AsPath()))
            {
                _dlStats = DownloadStats.FromDataBinary(File.ReadAllText((_Config + "/dlstats.bin").AsPath()));
            }
            else
            {
                _dlStats = new DownloadStats();
            }

            Manifest latestManifest = JsonConvert.DeserializeObject <Manifest>(_Manifests[_latestPackageset]);
            _dlStats.VerifyStatisticsIntegrity(U.GetPackageList(_latestPackageset), latestManifest);
            _Manifests[_latestPackageset] = JsonConvert.SerializeObject(latestManifest);

            if (dlStatsSaveTimer != null)
            {
                dlStatsSaveTimer.Stop();
            }
            dlStatsSaveTimer = new Timer();
#if (DEBUG)
            dlStatsSaveTimer.Interval = 10000;     //10 seconds
#else
            dlStatsSaveTimer.Interval = 600000;    //10 minutes
#endif
            dlStatsSaveTimer.AutoReset = true;
            dlStatsSaveTimer.Elapsed  += (sender, e) => {
                dlStats.VerifyStatisticsIntegrity(U.GetPackageListInLatestPackageset());
                File.WriteAllText((Config + "/dlstats.bin").AsPath(), dlStats.ToDataBinary(U.GetPackageList(latestPackageset)));
                Console.WriteLine("[ SAVE ] Wrote download stats to file (" + DateTime.Now.ToShortDateString() + " | " + DateTime.Now.ToShortTimeString() + ").");
            };
            dlStatsSaveTimer.Start();

            //update the real variables
            Temp             = _Temp;
            Config           = _Config;
            latestPackageset = _latestPackageset;
            latestAppVersion = _latestAppVersion;
            validChannels    = _validChannels;
            Manifests        = _Manifests;
            dlStats          = _dlStats;

            dlStatsInitialized = true;
#if (!DEBUG)
        }

        catch (Exception e) {
            return("[ERROR] Something went wrong while reloading: \n\n\nMessage:\n   " + e.Message + "\n\nStack Trace:\n" + e.StackTrace + "\n\n\nThe server will continue running and no changes will be saved");
        }
#endif
            return("Success");
        }
        /// <summary>
        /// Used to set up <see cref="Receive"/> methods for <see cref="FeedParserCoordinator"/>
        /// </summary>
        private void Initialize()
        {
            //Give the Sender a copy of our latest DownloadStats
            Receive<GetStats>(stats => Sender.Tell(_downloadStats));

            //Get an update on remaining downloads that need to be processed
            Receive<RemainingDownloadCount>(count =>
            {
                _downloadStats = _downloadStats.Merge(count);
               SendMessage(string.Format("Need to process an additional {0} pages and {1} images for {2}", count.HtmlPages, count.Images, count.FeedUrl));
            });

            //Process an update on completed downloads
            Receive<DownloadComplete>(complete =>
            {
                _downloadStats = _downloadStats.Merge(complete);
                SendMessage(string.Format("Completed processing of {0} pages and {1} images for {2}", complete.HtmlPages, complete.Images, complete.FeedUrl), PipeToSampleStatusCode.Success);

                //Check to see if this is the last outstanding item that needs to be downloaded
                if (_downloadStats.IsComplete)
                {
                    SignalFeedProcessingCompleted();
                }
            });

            //Feed contained no itmes
            Receive<EmptyFeed>(feed => SignalFeedProcessingCompleted());

            Receive<ErrorParsingFeed>(
                feed => SignalFeedProcessingFailure(string.Format("Error parsing feed {0}", _feedUri), _feedUri.ToString()));
        }
 /// <summary>
 /// This constructor is for unit testing.
 /// </summary>
 public FeedParserCoordinator(Uri feedUri, DownloadStats downloadStats, string consoleWriterActorPath)
 {
     _feedUri = feedUri;
     _downloadStats = downloadStats;
     _consoleWriterActorPath = consoleWriterActorPath;
     Initialize();
 }
예제 #9
0
 public ActionResult GetDownloadStatsDebug()
 {
     //TODO: dont do this
     return(new ObjectResult(JsonConvert.SerializeObject(DownloadStats.FromDataBinary(Program.dlStats.ToDataBinary(U.GetPackageListInLatestPackageset())), Formatting.Indented)));
 }