Пример #1
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);
        }
Пример #2
0
 public virtual void VerifyCredentialsAsync(SirenOfShameSettings settings, Action onSuccess, Action<string, Exception> 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());
 }
Пример #3
0
 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));
     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());
 }
Пример #4
0
 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.UploadValuesAndReturnXmlAsync(url,
                                                doc =>
                                                {
                                                    string success = doc.Descendants("Success").First().Value;
                                                    if (success != "true")
                                                    {
                                                        string errorMessage = doc.Descendants("ErrorMessage").First().Value;
                                                        _log.Error("Error publishing to: " + url + " error: " + errorMessage);
                                                    }
                                                }, ex => _log.Error("Error publishing to: " + url, ex), settings.GetSosOnlineProxy());
 }
Пример #5
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));
        }
Пример #6
0
 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);
 }
Пример #7
0
 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());
 }
Пример #8
0
 public virtual void Synchronize(SirenOfShameSettings settings, string exportedBuilds, string exportedAchievements, Action<DateTime> onSuccess, Action<string, Exception> 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);
         }
     }, ex => onFail("Failed to connect to SoS Online", ex), settings.GetSosOnlineProxy());
 }
Пример #9
0
 protected virtual XDocument DownloadXml(string url, string userName, string password, string cookie = null)
 {
     WebClientXml webClientXml = new WebClientXml();
     return webClientXml.DownloadXml(url, userName, password, cookie);
 }
Пример #10
0
        protected virtual XDocument DownloadXml(string url, string userName, string password, string cookie = null)
        {
            WebClientXml webClientXml = new WebClientXml();

            return(webClientXml.DownloadXml(url, userName, password, cookie));
        }
        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();
            }
        }
 private static void SendBuildStatusChanged(SirenOfShameSettings settings, IList<BuildStatus> changedBuildStatuses, List<InstanceUserDto> changedUsers)
 {
     var 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());
 }