protected void OnTestButtonClicked(object sender, EventArgs e)
 {
     testButton.State = Gtk.StateType.Insensitive;
     speedStatus.Text = "Testing... ";
     WebClient japan = new WebClient ();
     japan.Proxy = new WebProxy ("127.0.0.1:13370");
     japan.DownloadDataAsync (new Uri ("http://ipv4.download.thinkbroadband.com:8080/5MB.zip"));
     Stopwatch tmr = new Stopwatch ();
     tmr.Start ();
     double jSpeed;
     japan.DownloadDataCompleted += delegate(object sdr, DownloadDataCompletedEventArgs E) {
         if (true) {
             speedStatus.Text = "";
             jSpeed = (5000000 / 1024.0) / (tmr.ElapsedMilliseconds / 1000);
             GLib.Timeout.Add (200, updateStatus);
             theSpeed = jSpeed.ToString ().Substring (0, 6);
             theSpeed = "Result: " + Math.Round (jSpeed).ToString () + " KiB/s";
             tmr.Reset ();
             tmr.Stop ();
             japan.CancelAsync ();
             japan.CancelAsync ();
             japan.CancelAsync ();
             testButton.Sensitive = true;
         }
     };
 }
    public override System.Collections.IEnumerator Execute(UTContext context)
    {
        if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.WebPlayer ||
            EditorUserBuildSettings.activeBuildTarget == BuildTarget.WebPlayerStreamed) {
            Debug.LogWarning("You have currently set the build target to 'Web Player'. This may cause interference with actions that access the internet. If you get an error message about cross domain policy from this action, switch the target to 'PC and Mac Standalone' and try again.");
        }

        var theNexusUrl = nexusUrl.EvaluateIn (context);
        if (string.IsNullOrEmpty (theNexusUrl)) {
            throw new UTFailBuildException ("You need to specify the nexus URL", this);
        }

        var theRepoId = repositoryId.EvaluateIn (context);
        if (string.IsNullOrEmpty (theRepoId)) {
            throw new UTFailBuildException ("You need to specify the repository id.", this);
        }

        var theUserName = userName.EvaluateIn (context);
        var thePassword = password.EvaluateIn (context);

        var theGroupId = groupId.EvaluateIn (context);
        if (string.IsNullOrEmpty (theGroupId)) {
            throw new UTFailBuildException ("You need to specify the group id.", this);
        }

        var theArtifactId = artifactId.EvaluateIn (context);
        if (string.IsNullOrEmpty (theArtifactId)) {
            throw new UTFailBuildException ("You need to specify the artifact id.", this);
        }

        var theVersion = version.EvaluateIn (context);
        if (string.IsNullOrEmpty (theVersion)) {
            throw new UTFailBuildException ("You need to specify the version.", this);
        }

        var thePackaging = packaging.EvaluateIn (context);
        if (string.IsNullOrEmpty (thePackaging)) {
            throw new UTFailBuildException ("You need to specify the packaging.", this);
        }

        var theExtension = extension.EvaluateIn (context);
        var theClassifier = classifier.EvaluateIn (context);

        var theInputFileName = inputFileName.EvaluateIn (context);
        if (string.IsNullOrEmpty (theInputFileName)) {
            throw new UTFailBuildException ("You need to specify the input file name.", this);
        }

        if (Directory.Exists (theInputFileName)) {
            throw new UTFailBuildException ("The specified input file " + theInputFileName + " is a directory.", this);
        }

        if (!File.Exists (theInputFileName)) {
            throw new UTFailBuildException ("The specified input file " + theInputFileName + " does not exist.", this);
        }

        WWWForm form = new WWWForm ();
        form.AddField ("r", theRepoId);
        form.AddField ("g", theGroupId);
        form.AddField ("a", theArtifactId);
        form.AddField ("v", theVersion);

        if (!string.IsNullOrEmpty (thePackaging)) {
            form.AddField ("p", thePackaging);
        }

        if (!string.IsNullOrEmpty (theClassifier)) {
            form.AddField ("c", theClassifier);
        }

        if (!string.IsNullOrEmpty (theExtension)) {
            form.AddField ("e", theExtension);
        }

        var bytes = File.ReadAllBytes (theInputFileName);
        form.AddBinaryData ("file", bytes, new FileInfo (theInputFileName).Name);

        var hash = UTils.ComputeHash (bytes);
        if (UTPreferences.DebugMode) {
            Debug.Log ("SHA1-Hash of file to upload: " + hash);
        }

        string authString = theUserName + ":" + thePassword;
        var authBytes = System.Text.UTF8Encoding.UTF8.GetBytes (authString);

        var headers = new Hashtable ();
        foreach (var key in form.headers.Keys) {
            headers.Add (key, form.headers [key]);
        }

        headers.Add ("Authorization", "Basic " + System.Convert.ToBase64String (authBytes));
        var url = UTils.BuildUrl (theNexusUrl, "/service/local/artifact/maven/content");
        using (var www = new WWW (url, form.data, headers)) {
            do {
                yield return "";
            } while(!www.isDone && !context.CancelRequested);

            if (UTPreferences.DebugMode) {
                Debug.Log ("Server Response: " + www.text);
            }
        }

        if (!context.CancelRequested) {

            using (var wc = new WebClient()) {

                if (!string.IsNullOrEmpty (theUserName)) {
                    Debug.Log("Setting credentials" );
                    wc.Credentials = new NetworkCredential (theUserName, thePassword);
                }

                Uri uri = new Uri (UTils.BuildUrl (theNexusUrl, "/service/local/artifact/maven/resolve?") +
            "g=" + Uri.EscapeUriString (theGroupId) +
            "&a=" + Uri.EscapeUriString (theArtifactId) +
            "&v=" + Uri.EscapeUriString (theVersion) +
            "&r=" + Uri.EscapeUriString (theRepoId) +
            "&p=" + Uri.EscapeUriString (thePackaging) +
            (!string.IsNullOrEmpty (theClassifier) ? "&c=" + Uri.EscapeUriString (theClassifier) : "") +
            (!string.IsNullOrEmpty (theExtension) ? "&e=" + Uri.EscapeUriString (theExtension) : ""));

                var downloadFinished = false;
                var error = false;
                string result = null;
                wc.DownloadStringCompleted += delegate( object sender, DownloadStringCompletedEventArgs e) {
                    downloadFinished = true;
                    error = e.Error != null;
                    if (error) {
                        Debug.LogError ("An error occured while downloading artifact information. " + e.Error.Message, this);
                    } else {
                        result = (string)e.Result;
                    }
                };

                wc.DownloadStringAsync (uri);

                do {
                    yield return "";
                    if (context.CancelRequested) {
                        wc.CancelAsync ();
                    }
                } while(!downloadFinished);

                if (!context.CancelRequested) {

                    if (!error) {
                        if (UTPreferences.DebugMode) {
                            Debug.Log ("Server Response: " + result);
                        }
                        if (result.Contains ("<sha1>" + hash + "</sha1>")) {
                            Debug.Log ("Successfully uploaded artifact " + theInputFileName + ".", this);
                        } else {
                            throw new UTFailBuildException ("Upload failed. Checksums do not match.", this);
                        }
                    } else {
                        throw new UTFailBuildException ("Artifact verification failed", this);
                    }
                }
            }
        }
    }
    public override System.Collections.IEnumerator Execute(UTContext context)
    {
        if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.WebPlayer ||
            EditorUserBuildSettings.activeBuildTarget == BuildTarget.WebPlayerStreamed) {
            Debug.LogWarning("You have currently set the build target to 'Web Player'. This may cause interference with actions that access the internet. If you get an error message about cross domain policy from this action, switch the target to 'PC and Mac Standalone' and try again.");
        }

        var theNexusUrl = nexusUrl.EvaluateIn (context);
        if (string.IsNullOrEmpty (theNexusUrl)) {
            throw new UTFailBuildException ("You need to specify the nexus URL", this);
        }

        var theRepoId = repositoryId.EvaluateIn (context);
        if (string.IsNullOrEmpty (theRepoId)) {
            throw new UTFailBuildException ("You need to specify the repository id.", this);
        }

        var theUserName = userName.EvaluateIn (context);
        var thePassword = password.EvaluateIn (context);

        var theGroupId = groupId.EvaluateIn (context);
        if (string.IsNullOrEmpty (theGroupId)) {
            throw new UTFailBuildException ("You need to specify the group id.", this);
        }

        var theArtifactId = artifactId.EvaluateIn (context);
        if (string.IsNullOrEmpty (theArtifactId)) {
            throw new UTFailBuildException ("You need to specify the artifact id.", this);
        }

        var theVersion = version.EvaluateIn (context);
        if (string.IsNullOrEmpty (theVersion)) {
            throw new UTFailBuildException ("You need to specify the version.", this);
        }

        var thePackaging = packaging.EvaluateIn(context);
        if (string.IsNullOrEmpty (thePackaging)) {
            throw new UTFailBuildException ("You need to specify the packaging.", this);
        }

        var theExtension = extension.EvaluateIn(context);
        var theClassifier = classifier.EvaluateIn(context);

        var theOutputFileName = outputFileName.EvaluateIn (context);
        if (string.IsNullOrEmpty (theOutputFileName)) {
            throw new UTFailBuildException ("You need to specify the output file name.", this);
        }

        if (Directory.Exists (theOutputFileName)) {
            throw new UTFailBuildException ("The specified output file " + theOutputFileName + " is a directory.", this);
        }

        UTFileUtils.EnsureParentFolderExists (theOutputFileName);

        // TODO: ignore SSL certs if required
        using (var wc = new WebClient()) {

            if (!string.IsNullOrEmpty (theUserName)) {
                wc.Credentials = new NetworkCredential (theUserName, thePassword);
            }

            Uri uri = new Uri (theNexusUrl + "/service/local/artifact/maven/content?" +
            "g=" + Uri.EscapeUriString (theGroupId) +
            "&a=" + Uri.EscapeUriString (theArtifactId) +
            "&v=" + Uri.EscapeUriString (theVersion) +
            "&r=" + Uri.EscapeUriString (theRepoId) +
            "&p=" + Uri.EscapeUriString(thePackaging) +
            (!string.IsNullOrEmpty(theClassifier) ? "&c=" + Uri.EscapeUriString(theClassifier) : "") +
            (!string.IsNullOrEmpty(theExtension) ? "&e=" + Uri.EscapeUriString(theExtension) : ""));

            downloadFinished = false;
            error = false;
            wc.DownloadFileCompleted += delegate( object sender, AsyncCompletedEventArgs e) {
                downloadFinished = true;
                error = e.Error != null;
                if (error) {
                    Debug.LogError ("An error occured while downloading. " + e.Error.Message, this);
                }
            };

            wc.DownloadFileAsync (uri, theOutputFileName);

            do {
                yield return "";
                if (context.CancelRequested) {
                    wc.CancelAsync ();
                }
            } while(!downloadFinished);

            if (!error && !context.CancelRequested) {
                Debug.Log ("Successfully downloaded artifact to " + theOutputFileName + ".", this);
            }

            if (context.CancelRequested) {
                File.Delete(theOutputFileName);
            }

        }
    }