Beispiel #1
0
        public void GetProjects(string rootUrl, string userName, string password, GetProjectsCompleteDelegate complete, Action <Exception> onError)
        {
            WebClientXml webClient = new WebClientXml
            {
                AuthenticationType = AuthenticationTypeEnum.Base64EncodeInHeader,
                UserName           = userName,
                Password           = password
            };

            rootUrl = GetRootUrl(rootUrl);

            webClient.DownloadXmlAsync(rootUrl + "/api/xml", onSuccess: doc =>
            {
                if (doc.Root == null)
                {
                    onError(new Exception("No results returned"));
                    return;
                }
                HudsonBuildDefinition[] buildDefinitions = doc.Root
                                                           .Elements("job")
                                                           .Select(projectXml => new HudsonBuildDefinition(rootUrl, projectXml))
                                                           .ToArray();
                complete(buildDefinitions);
            }, onError: OnError(onError));
        }
        public virtual void Synchronize(SirenOfShameSettings settings, string exportedBuilds, string exportedAchievements, Action <DateTime> onSuccess, Action <string, ServerUnavailableException> onFail)
        {
            WebClientXml webClientXml = new WebClientXml();

            AddSosOnlineCredentials(settings, webClientXml);
            webClientXml.Add("Builds", exportedBuilds);
            webClientXml.Add("Achievements", exportedAchievements);
            if (settings.SoftwareInstanceId.HasValue)
            {
                webClientXml.Add("SoftwareInstanceId", settings.SoftwareInstanceId.Value.ToString(CultureInfo.InvariantCulture));
            }
            webClientXml.UploadValuesAndReturnXmlAsync(SOS_URL + "/ApiV1/Synchronize", doc =>
            {
                string success = doc.Descendants("Success").First().Value;
                if (success == "true")
                {
                    string newHighWaterMarkStr = doc.Descendants("NewHighWaterMark").First().Value;
                    DateTime newHighWaterMark  = new DateTime(long.Parse(newHighWaterMarkStr));
                    onSuccess(newHighWaterMark);
                }
                else
                {
                    string errorMessage = doc.Descendants("ErrorMessage").First().Value;
                    onFail(errorMessage, null);
                }
            }, OnConnectionFail(onFail), settings.GetSosOnlineProxy());
        }
Beispiel #3
0
        private void SendNewCustomImages(SirenOfShameSettings settings, List <InstanceUserDto> changedUsers)
        {
            var changedPeople = changedUsers
                                .Select(changedUser => settings.FindPersonByRawName(changedUser.RawName))
                                .Where(person => person != null);

            var changedPeopleWithUnUploadedCustomImages = changedPeople
                                                          .Where(i => !string.IsNullOrEmpty(i.AvatarImageName) && !i.AvatarImageUploaded);

            foreach (var person in changedPeopleWithUnUploadedCustomImages)
            {
                var webClientXml = new WebClientXml();
                AddSosOnlineCredentials(settings, webClientXml);
                webClientXml.Add("AvatarImageName", person.AvatarImageName);
                var avatarImagePath = SirenOfShameSettings.GetAvatarImagePath(person.AvatarImageName);
                var imageAsBytes    = File.ReadAllBytes(avatarImagePath);
                var imageAsString   = Convert.ToBase64String(imageAsBytes);
                webClientXml.Add("AvatarImage", imageAsString);
                string url     = SOS_URL + "/ApiV1/AddImage";
                var    person1 = person;
                webClientXml.UploadValuesAndReturnStringAsync(url, s => _log.Debug("Uploaded " + person1.AvatarImageName), ex => _log.Error("Error uploading image for " + person1.AvatarImageName), settings.GetSosOnlineProxy());
                person.AvatarImageUploaded = true;
                settings.Save();
            }
        }
        public virtual void BuildStatusChanged(SirenOfShameSettings settings, IList <BuildStatus> changedBuildStatuses)
        {
            WebClientXml webClientXml = new WebClientXml();

            AddSosOnlineCredentials(settings, webClientXml);
            string json = JsonConvert.SerializeObject(changedBuildStatuses);

            webClientXml.Add("ChangedBuildStatuses", json);
            if (settings.SoftwareInstanceId.HasValue)
            {
                webClientXml.Add("SoftwareInstanceId", settings.SoftwareInstanceId.Value.ToString(CultureInfo.InvariantCulture));
            }
            const string url = SOS_URL + "/ApiV1/BuildStatusChangedV1";

            webClientXml.UploadValuesAndReturnStringAsync(url,
                                                          resultsStr =>
            {
                var result = JsonConvert.DeserializeObject <ApiResultBase>(resultsStr);
                if (!result.Success)
                {
                    string errorMessage = result.Message;
                    _log.Error("Error publishing to: " + url + " error: " + errorMessage);
                }
            }, ex => _log.Error("Error publishing to: " + url, ex), settings.GetSosOnlineProxy());
        }
        public void TeamCityBuildDefinitionUnavailable()
        {
            const string message = @"Error has occurred during request processing (Not Found).
Error: jetbrains.buildServer.server.rest.errors.NotFoundException: No build type or template is found by id, internal id or name 'SimpleApp_MainBuildConfiguration'.
Could not find the entity requested. Check the reference is correct and the user has permissions to access the entity.";
            var          result  = WebClientXml.ToServerUnavailableException("http://localhost:8083/httpAuth/app/rest/builds/buildType:SimpleApp_MainBuildConfiguration", new WebException(message), message);

            Assert.IsTrue(result is BuildDefinitionNotFoundException);
        }
Beispiel #6
0
        protected override XDocument DownloadXml(string url, string userName, string password, string cookie = null)
        {
            WebClientXml webClientXml = new WebClientXml
            {
                // hudson/jenkins api's apparently always require base64 encoded credentials rather than basic auth
                AuthenticationType = AuthenticationTypeEnum.Base64EncodeInHeader
            };

            return(webClientXml.DownloadXml(url, userName, password, cookie));
        }
        public virtual void BuildStatusChanged(SirenOfShameSettings settings, IList <BuildStatus> changedBuildStatuses, List <InstanceUserDto> changedUsers)
        {
            WebClientXml webClientXml = new WebClientXml();

            AddSosOnlineCredentials(settings, webClientXml);
            webClientXml.Add("ChangedBuildStatuses", JsonConvert.SerializeObject(changedBuildStatuses));
            webClientXml.Add("ChangedUsers", JsonConvert.SerializeObject(changedUsers));
            if (settings.SoftwareInstanceId.HasValue)
            {
                webClientXml.Add("SoftwareInstanceId", settings.SoftwareInstanceId.Value.ToString(CultureInfo.InvariantCulture));
            }
            string url = SOS_URL + "/ApiV1/BuildStatusChangedV1";

            webClientXml.UploadValuesAndReturnStringAsync(url, ReadResult, ex => _log.Error("Error publishing to: " + url, ex), settings.GetSosOnlineProxy());
        }
        public virtual void VerifyCredentialsAsync(SirenOfShameSettings settings, Action onSuccess, Action <string, ServerUnavailableException> onFail)
        {
            WebClientXml webClientXml = new WebClientXml();

            AddSosOnlineCredentials(settings, webClientXml);
            webClientXml.UploadValuesAndReturnXmlAsync(SOS_URL + "/ApiV1/VerifyCredentials", doc =>
            {
                string success = doc.Descendants("Success").First().Value;
                if (success == "true")
                {
                    onSuccess();
                }
                else
                {
                    string errorMessage = doc.Descendants("ErrorMessage").First().Value;
                    onFail(errorMessage, null);
                }
            }, OnConnectionFail(onFail), settings.GetSosOnlineProxy());
        }
Beispiel #9
0
        private TravisCiBuildStatus GetBuildStatus(BuildDefinitionSetting buildDefinitionSetting)
        {
            var webClient          = new WebClient();
            var travisBuildDef     = TravisCiBuildDefinition.FromIdString(buildDefinitionSetting.Id);
            var buildDefinitionUrl = "https://api.travis-ci.org/repositories/" + travisBuildDef.OwnerName + "/" + travisBuildDef.ProjectName + ".json";

            try
            {
                var json        = webClient.DownloadString(buildDefinitionUrl);
                var lastBuildId = GetJsonValue(json, "last_build_id");
                var buildUrl    = "https://api.travis-ci.org/builds/" + lastBuildId + ".json";
                json = webClient.DownloadString(buildUrl);
                return(new TravisCiBuildStatus(travisBuildDef, json, buildDefinitionSetting));
            }
            catch (WebException webException)
            {
                throw WebClientXml.ToServerUnavailableException(buildDefinitionUrl, webException);
            }
        }
        public virtual void SendMessage(SirenOfShameSettings settings, string message)
        {
            WebClientXml webClientXml = new WebClientXml();

            AddSosOnlineCredentials(settings, webClientXml);
            webClientXml.Add("Message", message);
            webClientXml.UploadValuesAndReturnXmlAsync(SOS_URL + "/ApiV1/AddMessage", doc =>
            {
                string success = doc.Descendants("Success").First().Value;
                if (success == "true")
                {
                    _log.Debug("Message successfully added");
                }
                else
                {
                    string errorMessage = doc.Descendants("ErrorMessage").First().Value;
                    _log.Error("Failed to add message: " + errorMessage);
                }
            }, OnConnectionFail, settings.GetSosOnlineProxy());
        }
        private TravisCiBuildStatus GetBuildStatus(CiEntryPointSetting ciEntryPointSetting, BuildDefinitionSetting buildDefinitionSetting)
        {
            var webClient = new WebClient();
            var authToken = ciEntryPointSetting.GetPassword();

            AddTravisHeaders(webClient, authToken);
            var travisBuildDef     = TravisCiBuildDefinition.FromIdString(buildDefinitionSetting.Id);
            var buildDefinitionUrl = GetUrl(ciEntryPointSetting.Url, travisBuildDef.OwnerName, travisBuildDef.ProjectName);

            try
            {
                var json        = webClient.DownloadString(buildDefinitionUrl);
                var lastBuildId = GetJsonValue(json, "last_build_id");
                var buildUrl    = string.Format("{0}builds/{1}", ciEntryPointSetting.Url, lastBuildId);
                json = webClient.DownloadString(buildUrl);
                return(new TravisCiBuildStatus(travisBuildDef, json, buildDefinitionSetting));
            }
            catch (WebException webException)
            {
                throw WebClientXml.ToServerUnavailableException(buildDefinitionUrl, webException);
            }
        }
 private static void AddSosOnlineCredentials(SirenOfShameSettings settings, WebClientXml webClientXml)
 {
     webClientXml.Add("UserName", settings.SosOnlineUsername);
     // send the encrypted version of the password since we're too cheap to support SSL at present
     webClientXml.Add("Password", settings.SosOnlinePassword);
 }