public static void Send(Analytics.Category category, Analytics.Action action, String label)
        {
            String cid = GoogleOgcs.Authenticator.HashedGmailAccount ?? "1";
            String baseAnalyticsUrl = "https://www.google-analytics.com/collect?v=1&t=event&tid=UA-19426033-4&aip=1&cid=" + cid;

            if (action == Analytics.Action.debug)
            {
                label = "v" + System.Windows.Forms.Application.ProductVersion + ";" + label;
            }
            String analyticsUrl = baseAnalyticsUrl + "&ec=" + category.ToString() + "&ea=" + action.ToString() + "&el=" + System.Net.WebUtility.UrlEncode(label);

            log.Debug("Retrieving URL: " + analyticsUrl);

            if (Settings.Instance.TelemetryDisabled || Program.InDeveloperMode)
            {
                log.Debug("Telemetry is disabled.");
                return;
            }

            Extensions.OgcsWebClient wc = new Extensions.OgcsWebClient();
            wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(sendTelemetry_completed);
            wc.DownloadStringAsync(new Uri(analyticsUrl), analyticsUrl);
        }
        private void checkForUpdate(String localVersion)
        {
            try {
                if (Program.InDeveloperMode && File.Exists(tzdbFile))
                {
                    return;
                }

                log.Debug("Checking for new timezone database...");
                String nodatimeURL          = "http://nodatime.org/tzdb/latest.txt";
                String html                 = "";
                Extensions.OgcsWebClient wc = new Extensions.OgcsWebClient();
                try {
                    html = wc.DownloadString(nodatimeURL);
                } catch (System.Exception ex) {
                    log.Error("Failed to get latest NodaTime db version.");
                    OGCSexception.Analyse(ex);
                    return;
                }

                if (string.IsNullOrEmpty(html))
                {
                    log.Warn("Empty response from " + nodatimeURL);
                }
                else
                {
                    html = html.TrimEnd('\r', '\n');
                    if (html.EndsWith(localVersion + ".nzd"))
                    {
                        log.Debug("Already have latest TZDB version.");
                    }
                    else
                    {
                        Regex           rgx     = new Regex(@"https*:.*/tzdb(.*)\.nzd$", RegexOptions.IgnoreCase);
                        MatchCollection matches = rgx.Matches(html);
                        if (matches.Count > 0)
                        {
                            String remoteVersion = matches[0].Result("$1");
                            if (string.Compare(localVersion, remoteVersion, System.StringComparison.InvariantCultureIgnoreCase) < 0)
                            {
                                log.Debug("There is a new version " + remoteVersion);
                                try {
                                    wc.DownloadFile(html, tzdbFile);
                                    log.Debug("New TZDB version downloaded - disposing of reference to old db data.");
                                    instance = null;
                                } catch (System.Exception ex) {
                                    log.Error("Failed to download new TZDB database from " + html);
                                    OGCSexception.Analyse(ex);
                                }
                            }
                        }
                        else
                        {
                            log.Warn("Regex to extract latest version is no longer working!");
                        }
                    }
                }
            } catch (System.Exception ex) {
                OGCSexception.Analyse("Could not check for timezone data update.", ex);
            }
        }
        private void checkForZip(object sender, DoWorkEventArgs e)
        {
            string releaseURL     = null;
            string releaseVersion = null;
            string releaseType    = null;

            log.Debug("Checking for ZIP update...");
            string html         = "";
            String errorDetails = "";

            try {
                html = new Extensions.OgcsWebClient().DownloadString("https://github.com/phw198/OutlookGoogleCalendarSync/blob/master/docs/latest_zip_release.md");
            } catch (System.Net.WebException ex) {
                if (OGCSexception.GetErrorCode(ex) == "0x80131509")
                {
                    log.Warn("Failed to retrieve data (no network?): " + ex.Message);
                }
                else
                {
                    OGCSexception.Analyse("Failed to retrieve data", ex);
                }
            } catch (System.Exception ex) {
                OGCSexception.Analyse("Failed to retrieve data: ", ex);
            }

            if (!string.IsNullOrEmpty(html))
            {
                log.Debug("Finding Beta release...");
                MatchCollection release = getRelease(html, @"<strong>Beta</strong>: <a href=""(.*?)"">v([\d\.]+)</a>");
                if (release.Count > 0)
                {
                    releaseType    = "Beta";
                    releaseURL     = release[0].Result("$1");
                    releaseVersion = release[0].Result("$2");
                }
                if (Settings.Instance.AlphaReleases)
                {
                    log.Debug("Finding Alpha release...");
                    release = getRelease(html, @"<strong>Alpha</strong>: <a href=""(.*?)"">v([\d\.]+)</a>");
                    if (release.Count > 0)
                    {
                        releaseType    = "Alpha";
                        releaseURL     = release[0].Result("$1");
                        releaseVersion = release[0].Result("$2");
                    }
                }
            }

            if (releaseVersion != null)
            {
                String paddedVersion = "";
                foreach (String versionBit in releaseVersion.Split('.'))
                {
                    paddedVersion += versionBit.PadLeft(2, '0');
                }
                Int32 releaseNum = Convert.ToInt32(paddedVersion);
                paddedVersion = "";
                foreach (String versionBit in Application.ProductVersion.Split('.'))
                {
                    paddedVersion += versionBit.PadLeft(2, '0');
                }
                Int32 myReleaseNum = Convert.ToInt32(paddedVersion);
                if (releaseNum > myReleaseNum)
                {
                    log.Info("New " + releaseType + " ZIP release found: " + releaseVersion);
                    DialogResult dr = OgcsMessageBox.Show("A new " + releaseType + " release is available for OGCS. Would you like to upgrade to v" + releaseVersion + "?", "New OGCS Release Available", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (dr == DialogResult.Yes)
                    {
                        System.Diagnostics.Process.Start(releaseURL);
                    }
                }
                else
                {
                    log.Info("Already on latest ZIP release.");
                    if (isManualCheck)
                    {
                        OgcsMessageBox.Show("You are already on the latest release", "No Update Required", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            else
            {
                log.Info("Did not find ZIP release.");
                if (isManualCheck)
                {
                    OgcsMessageBox.Show("Failed to check for ZIP release." + (string.IsNullOrEmpty(errorDetails) ? "" : "\r\n" + errorDetails),
                                        "Update Check Failed", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }