Ejemplo n.º 1
0
        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());
        }
Ejemplo n.º 2
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.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());
        }
Ejemplo n.º 3
0
        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());
        }
Ejemplo n.º 4
0
        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());
        }
Ejemplo n.º 5
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());
        }
Ejemplo n.º 6
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();
            }
        }