private void Initialize (Client client)
        {
            Application.ClientStarted -= Initialize;

            var handler = Started;
            if (handler != null) {
                handler ();
            }

            Application.RunTimeout (5*1000, delegate {
                if (BansheeMetrics.Instance == null) {
                    return false;
                }

                metrics.AddDefaults ();
                AddMetrics ();

                ThreadAssist.SpawnFromMain (delegate {
                    if (ApplicationContext.CommandLine.Contains ("debug-metrics")) {
                        Log.InformationFormat ("Anonymous usage data collected:\n{0}", metrics.ToJsonString ());
                        System.IO.File.WriteAllText ("usage-data.json", metrics.ToJsonString ());
                    }

                    // Don't post to server more than every 48 hours
                    var last_post_time = DatabaseConfigurationClient.Client.Get<DateTime> (last_post_key, DateTime.MinValue);
                    var last_post_rel = (DateTime.Now - last_post_time).TotalHours;
                    if (last_post_rel < 0 || last_post_rel > 48.0) {
                        var poster = new HttpPoster ("http://metrics.banshee.fm/submit/", metrics);
                        bool posted = poster.Post ();
                        Log.InformationFormat ("Posted usage data? {0}", posted);
                        if (posted) {
                            metrics.Store.Clear ();
                            DatabaseConfigurationClient.Client.Set<DateTime> (last_post_key, DateTime.Now);
                        }
                    }
                });
                return false;
            });
        }
Esempio n. 2
0
        private void Initialize (Client client)
        {
            Application.ClientStarted -= Initialize;

            var handler = Started;
            if (handler != null) {
                handler ();
            }

            Application.RunTimeout (5*1000, delegate {
                if (BansheeMetrics.Instance == null) {
                    return false;
                }

                ThreadAssist.SpawnFromMain (delegate {
                    metrics.AddDefaults ();
                    AddMetrics ();

                    if (ApplicationContext.CommandLine.Contains ("debug-metrics")) {
                        Log.InformationFormat ("Anonymous usage data collected:\n{0}", metrics.ToJsonString ());
                        System.IO.File.WriteAllText ("usage-data.json", metrics.ToJsonString ());
                    }

                    if (!ServiceManager.Get<Network> ().Connected) {
                        return;
                    }

                    // Don't post to server more than every 48 hours
                    var last_post_time = DatabaseConfigurationClient.Client.Get<DateTime> (last_post_key, DateTime.MinValue);
                    var last_post_rel = (DateTime.Now - last_post_time).TotalDays;
                    if (last_post_rel < 0 || last_post_rel > 4.0) {
                        var poster = new HttpPoster ("http://metrics.banshee.fm/submit/", metrics);
                        bool posted = poster.Post ();
                        Log.InformationFormat ("Posted usage data? {0}", posted);

                        // Clear the old metrics, even if we failed to post them; it might be a server-side
                        // problem w/ the data we want to send (eg too big, out of space) and we don't want
                        // to keep retrying to send the same data.
                        metrics.Store.Clear ();
                        DatabaseConfigurationClient.Client.Set<DateTime> (last_post_key, DateTime.Now);
                    }
                });

                return false;
            });
        }