Exemplo n.º 1
0
 public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
 {
     if (!string.IsNullOrEmpty(BlogUrl) && BlogUrl.Contains("baidu.com"))
     {
         yield return(new ValidationResult("Url already taken", new [] { "BlogUrl" }));
     }
 }
Exemplo n.º 2
0
        string SubmitComment(IComment comment, Uri url)
        {
            //Not too many concatenations.  Might not need a string builder.
            string parameters = "blog=" + HttpUtility.UrlEncode(BlogUrl.ToString())
                                + "&user_ip=" + comment.IPAddress
                                + "&user_agent=" + HttpUtility.UrlEncode(comment.UserAgent);

            if (!String.IsNullOrEmpty(comment.Referrer))
            {
                parameters += "&referer=" + HttpUtility.UrlEncode(comment.Referrer);
            }

            if (comment.Permalink != null)
            {
                parameters += "&permalink=" + HttpUtility.UrlEncode(comment.Permalink.ToString());
            }

            if (!String.IsNullOrEmpty(comment.CommentType))
            {
                parameters += "&comment_type=" + HttpUtility.UrlEncode(comment.CommentType);
            }

            if (!String.IsNullOrEmpty(comment.Author))
            {
                parameters += "&comment_author=" + HttpUtility.UrlEncode(comment.Author);
            }

            if (!String.IsNullOrEmpty(comment.AuthorEmail))
            {
                parameters += "&comment_author_email=" + HttpUtility.UrlEncode(comment.AuthorEmail);
            }

            if (comment.AuthorUrl != null)
            {
                parameters += "&comment_author_url=" + HttpUtility.UrlEncode(comment.AuthorUrl.ToString());
            }

            if (!String.IsNullOrEmpty(comment.Content))
            {
                parameters += "&comment_content=" + HttpUtility.UrlEncode(comment.Content);
            }

            if (comment.ServerEnvironmentVariables != null)
            {
                foreach (string key in comment.ServerEnvironmentVariables)
                {
                    parameters += "&" + key + "=" + HttpUtility.UrlEncode(comment.ServerEnvironmentVariables[key]);
                }
            }

            return(_httpClient.PostRequest(url, UserAgent, Timeout, parameters).ToLowerInvariant());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Verifies the API key.  You really only need to
        /// call this once, perhaps at startup.
        /// </summary>
        /// <returns></returns>
        /// <exception type="Sytsem.Web.WebException">If it cannot make a request of Akismet.</exception>
        public bool VerifyApiKey()
        {
            string parameters = "key=" + HttpUtility.UrlEncode(ApiKey) + "&blog=" +
                                HttpUtility.UrlEncode(BlogUrl.ToString());
            string result = _httpClient.PostRequest(VerifyUrl, UserAgent, Timeout, parameters, Proxy);

            if (String.IsNullOrEmpty(result))
            {
                throw new InvalidResponseException(Resources.InvalidResponse_EmptyResponse);
            }

            return(String.Equals("valid", result, StringComparison.OrdinalIgnoreCase));
        }
Exemplo n.º 4
0
		/// <inheritdoc/>
		public override int GetHashCode()
		{
			var hashCode = 1122491329;
			hashCode = hashCode * -1521134295 + Type.GetHashCode();
			hashCode = hashCode * -1521134295 + Timestamp.GetHashCode();
			hashCode = hashCode * -1521134295 + BlogName.GetHashCode();
			hashCode = hashCode * -1521134295 + BlogUuid.GetHashCode();
			hashCode = hashCode * -1521134295 + BlogUrl.GetHashCode();
			hashCode = hashCode * -1521134295 + Followed.GetHashCode();
			hashCode = hashCode * -1521134295 + AvatarShape.GetHashCode();
			hashCode = hashCode * -1521134295 + ReplyText.GetHashCode();
			hashCode = hashCode * -1521134295 + PostId.GetHashCode();
			hashCode = hashCode * -1521134295 + ReblogParentBlogName.GetHashCode();
			return hashCode;
		}
Exemplo n.º 5
0
        protected override void Validate()
        {
            if (string.IsNullOrEmpty(FirstName))
            {
                AddBrokenRule(UserBusinessRule.UserFirstNameRequired);
            }
            if (string.IsNullOrEmpty(LastName))
            {
                AddBrokenRule(UserBusinessRule.UserLastNameRequired);
            }
            if (HomePhone != null && !string.IsNullOrEmpty(HomePhone.Number) && !IsValidPhoneNumberLength(HomePhone.Number))
            {
                AddBrokenRule(ValueObjects.ValueObjectBusinessRule.PhoneNumberMinimumLength);
            }
            if (MobilePhone != null && !string.IsNullOrEmpty(MobilePhone.Number) && !IsValidPhoneNumberLength(MobilePhone.Number))
            {
                AddBrokenRule(ValueObjects.ValueObjectBusinessRule.PhoneNumberMinimumLength);
            }
            if (WorkPhone != null && !string.IsNullOrEmpty(WorkPhone.Number) && !IsValidPhoneNumberLength(WorkPhone.Number))
            {
                AddBrokenRule(ValueObjects.ValueObjectBusinessRule.PhoneNumberMinimumLength);
            }
            if (Email != null && !string.IsNullOrEmpty(Email.EmailId) && !IsValidEmail(Email.EmailId))
            {
                AddBrokenRule(UserBusinessRule.UserPrimaryEmailRequired);
            }
            /*Validates if all the secondary emails are valid*/
            if (SecondaryEmails != null)
            {
                foreach (Email email in SecondaryEmails)
                {
                    if (!string.IsNullOrEmpty(email.EmailId) && !IsValidEmail(email.EmailId))
                    {
                        AddBrokenRule(ValueObjects.ValueObjectBusinessRule.EmailIsInvalid);
                    }
                }
            }
            /*Validates if all the emails are valid*/
            if (Emails != null)
            {
                foreach (Email email in Emails)
                {
                    if (!string.IsNullOrEmpty(email.EmailId) && !IsValidEmail(email.EmailId))
                    {
                        AddBrokenRule(ValueObjects.ValueObjectBusinessRule.EmailIsInvalid);
                    }
                }
            }

            /*Validate Facebook URL:*/
            if (!IsValidUrl(facebookUrl, "facebook.com/"))
            {
                AddBrokenRule(UserBusinessRule.UserFacebookUrlInvalid);
            }
            /*Validate Twitter URL:*/
            if (!IsValidUrl(twitterUrl, "twitter.com/"))
            {
                AddBrokenRule(UserBusinessRule.UserTwitterUrlInvalid);
            }
            /*Validate Google+ URL:*/
            if (!IsValidUrl(googlePlusUrl, "plus.google.com/"))
            {
                AddBrokenRule(UserBusinessRule.UserGooglePlusUrlInvalid);
            }
            /*Validate LinkedIn URL:*/
            if (!IsValidUrl(linkedInUrl, "linkedin.com/"))
            {
                AddBrokenRule(UserBusinessRule.UserLinkedInUrlInvalid);
            }
            /*Validate Blog URL:*/
            if (BlogUrl != null && !string.IsNullOrEmpty(BlogUrl.URL) && !BlogUrl.IsValidURL())
            {
                AddBrokenRule(UserBusinessRule.UserBlogInUrlInvalid);
            }
            /*Validate Web URL:*/
            if (WebsiteUrl != null && !string.IsNullOrEmpty(WebsiteUrl.URL) && !WebsiteUrl.IsValidURL())
            {
                AddBrokenRule(UserBusinessRule.UserWebURLInvalid);
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Validates Accounts model
 /// </summary>
 protected override void Validate()
 {
     if (string.IsNullOrEmpty(AccountName))
     {
         AddBrokenRule(AccountBusinessRule.AccountNameRequired);
     }
     if (string.IsNullOrEmpty(FirstName))
     {
         AddBrokenRule(AccountBusinessRule.AccountFirstNameRequired);
     }
     if (string.IsNullOrEmpty(LastName))
     {
         AddBrokenRule(AccountBusinessRule.AccountLastNameRequired);
     }
     if (HomePhone != null && !string.IsNullOrEmpty(HomePhone.Number) && !IsValidPhoneNumberLength(HomePhone.Number))
     {
         AddBrokenRule(ValueObjects.ValueObjectBusinessRule.PhoneNumberMinimumLength);
     }
     if (MobilePhone != null && !string.IsNullOrEmpty(MobilePhone.Number) && !IsValidPhoneNumberLength(MobilePhone.Number))
     {
         AddBrokenRule(ValueObjects.ValueObjectBusinessRule.PhoneNumberMinimumLength);
     }
     if (WorkPhone != null && !string.IsNullOrEmpty(WorkPhone.Number) && !IsValidPhoneNumberLength(WorkPhone.Number))
     {
         AddBrokenRule(ValueObjects.ValueObjectBusinessRule.PhoneNumberMinimumLength);
     }
     if (!string.IsNullOrEmpty(Email.EmailId) && !IsValidEmail(Email.EmailId))
     {
         AddBrokenRule(AccountBusinessRule.AccountPrimaryEmailRequired);
     }
     if (string.IsNullOrEmpty(DomainURL))
     {
         AddBrokenRule(AccountBusinessRule.AccountDomainNameRequired);
     }
     if (!IsDomainNameValid(DomainURL))
     {
         AddBrokenRule(AccountBusinessRule.AccountDomainNameInvalid);
     }
     if (string.IsNullOrEmpty(HelpURL))
     {
         AddBrokenRule(AccountBusinessRule.HelpURLIsRequired);
     }
     if (!IsValidURL())
     {
         AddBrokenRule(AccountBusinessRule.HelpURLIsInvalid);
     }
     //Validates if all the secondary emails are valid
     if (SecondaryEmails != null)
     {
         foreach (Email email in SecondaryEmails)
         {
             if (!string.IsNullOrEmpty(Email.EmailId) && !IsValidEmail(email.EmailId))
             {
                 AddBrokenRule(ValueObjects.ValueObjectBusinessRule.EmailIsInvalid);
             }
         }
     }
     //Validate Facebook URL:
     if (facebookUrl != null && !string.IsNullOrEmpty(facebookUrl.URL) && !ValidateURL(facebookUrl, "facebook.com/"))
     {
         AddBrokenRule(AccountBusinessRule.AccountFacebookUrlInvalid);
     }
     //Validate Twitter URL:
     if (twitterUrl != null && !string.IsNullOrEmpty(twitterUrl.URL) && !ValidateURL(twitterUrl, "twitter.com/"))
     {
         AddBrokenRule(AccountBusinessRule.AccountTwitterUrlInvalid);
     }
     //Validate Google+ URL:
     if (googlePlusUrl != null && !string.IsNullOrEmpty(googlePlusUrl.URL) && !ValidateURL(googlePlusUrl, "plus.google.com/"))
     {
         AddBrokenRule(AccountBusinessRule.AccountGooglePlusUrlInvalid);
     }
     //Validate LinkedIn URL:
     if (linkedInUrl != null && !string.IsNullOrEmpty(linkedInUrl.URL) && !ValidateURL(linkedInUrl, "linkedin.com/"))
     {
         AddBrokenRule(AccountBusinessRule.AccountLinkedInUrlInvalid);
     }
     //Validate Blog URL:
     if (BlogUrl != null && !string.IsNullOrEmpty(BlogUrl.URL) && !BlogUrl.IsValidURL())
     {
         AddBrokenRule(AccountBusinessRule.AccountBlogInUrlInvalid);
     }
     //Validate Web URL:
     if (WebsiteUrl != null && !string.IsNullOrEmpty(WebsiteUrl.URL) && !WebsiteUrl.IsValidURL())
     {
         AddBrokenRule(AccountBusinessRule.AccountWebURLInvalid);
     }
 }
Exemplo n.º 7
0
        protected override void Validate()
        {
            if (string.IsNullOrEmpty(AccountName))
            {
                AddBrokenRule(AccountBusinessRule.AccountNameRequired);
            }

            if (string.IsNullOrEmpty(FirstName))
            {
                AddBrokenRule(AccountBusinessRule.AccountFirstNameRequired);
            }

            if (string.IsNullOrEmpty(LastName))
            {
                AddBrokenRule(AccountBusinessRule.AccountLastNameRequired);
            }

            if (HomePhone != null && !string.IsNullOrEmpty(HomePhone.Number) && !IsValidPhoneNumberLength(HomePhone.Number))
            {
                AddBrokenRule(ValueObjects.ValueObjectBusinessRule.PhoneNumberMinimumLength);
            }

            if (MobilePhone != null && !string.IsNullOrEmpty(MobilePhone.Number) && !IsValidPhoneNumberLength(MobilePhone.Number))
            {
                AddBrokenRule(ValueObjects.ValueObjectBusinessRule.PhoneNumberMinimumLength);
            }

            if (WorkPhone != null && !string.IsNullOrEmpty(WorkPhone.Number) && !IsValidPhoneNumberLength(WorkPhone.Number))
            {
                AddBrokenRule(ValueObjects.ValueObjectBusinessRule.PhoneNumberMinimumLength);
            }

            if (!string.IsNullOrEmpty(Email.EmailId) && !IsValidEmail(Email.EmailId))
            {
                AddBrokenRule(AccountBusinessRule.AccountPrimaryEmailRequired);
            }

            foreach (Address address in Addresses)
            {
                if (!address.IsValidCountry())
                {
                    AddBrokenRule(ValueObjectBusinessRule.CountryInAddressRequired);
                }
                if (!address.IsValidState())
                {
                    AddBrokenRule(ValueObjectBusinessRule.StateInAddressRequired);
                }
                if (address.Country.Code == "US" && !string.IsNullOrEmpty(address.ZipCode) && !IsValidUSZipCode(address.ZipCode))
                {
                    AddBrokenRule(ValueObjectBusinessRule.ZipCodeFormatInvalid);
                }
                if (address.Country.Code == "CA" && !string.IsNullOrEmpty(address.ZipCode) && !IsValidCanadianPostalCode(address.ZipCode))
                {
                    AddBrokenRule(ValueObjectBusinessRule.PostalCodeFormatInvalid);
                }
            }

            //Validates if all the secondary emails are valid
            if (SecondaryEmails != null)
            {
                foreach (Email email in SecondaryEmails)
                {
                    if (!string.IsNullOrEmpty(Email.EmailId) && !IsValidEmail(email.EmailId))
                    {
                        AddBrokenRule(ValueObjects.ValueObjectBusinessRule.EmailIsInvalid);
                    }
                }
            }
            //Validate Facebook URL:
            //if (FacebookUrl !=null && !string.IsNullOrEmpty(FacebookUrl.URL) && (!FacebookUrl.IsValidURL() || !this.FacebookUrl.URL.ToLower().Contains("facebook.com")))
            if (facebookUrl != null && !string.IsNullOrEmpty(facebookUrl.URL) && !IsFacebookURLValid(facebookUrl))
            {
                AddBrokenRule(AccountBusinessRule.AccountFacebookUrlInvalid);
            }

            //Validate Twitter URL:
            if (twitterUrl != null && !string.IsNullOrEmpty(twitterUrl.URL) && !IsTwitterURLValid(twitterUrl))
            {
                AddBrokenRule(AccountBusinessRule.AccountTwitterUrlInvalid);
            }

            //Validate Google+ URL:
            if (googlePlusUrl != null && !string.IsNullOrEmpty(googlePlusUrl.URL) && !IsGooglePlusURLValid(googlePlusUrl))
            {
                AddBrokenRule(AccountBusinessRule.AccountGooglePlusUrlInvalid);
            }

            //Validate LinkedIn URL:
            if (linkedInUrl != null && !string.IsNullOrEmpty(linkedInUrl.URL) && !IsLinkedInURLValid(linkedInUrl))
            {
                AddBrokenRule(AccountBusinessRule.AccountLinkedInUrlInvalid);
            }

            //Validate Blog URL:
            if (BlogUrl != null && !string.IsNullOrEmpty(BlogUrl.URL) && !BlogUrl.IsValidURL())
            {
                AddBrokenRule(AccountBusinessRule.AccountBlogInUrlInvalid);
            }

            //Validate Web URL:
            if (WebsiteUrl != null && !string.IsNullOrEmpty(WebsiteUrl.URL) && !WebsiteUrl.IsValidURL())
            {
                AddBrokenRule(AccountBusinessRule.AccountWebURLInvalid);
            }
        }
Exemplo n.º 8
0
        protected override void Validate()
        {
            //if (!string.IsNullOrEmpty(ImageUrl) && !this.IsValidImageType())
            //{
            //        AddBrokenRule(ContactBusinessRule.ContactImageTypeInvalid);
            //}

            if (WorkPhone != null && !string.IsNullOrEmpty(WorkPhone.Number) && !IsValidPhoneNumberLength(WorkPhone.Number))
            {
                AddBrokenRule(ValueObjects.ValueObjectBusinessRule.PhoneNumberMinimumLength);
            }

            if (!string.IsNullOrEmpty(Email.EmailId) && !IsValidEmail(Email.EmailId))
            {
                AddBrokenRule(ContactBusinessRule.ContactPrimaryEmailRequired);
            }

            foreach (Address address in Addresses)
            {
                if (!address.IsValidCountry())
                {
                    AddBrokenRule(ValueObjectBusinessRule.CountryInAddressRequired);
                }
                if (!address.IsValidState())
                {
                    AddBrokenRule(ValueObjectBusinessRule.StateInAddressRequired);
                }
                if (address.Country.Code == "US" && !string.IsNullOrEmpty(address.ZipCode) && !IsValidUSZipCode(address.ZipCode))
                {
                    AddBrokenRule(ValueObjectBusinessRule.ZipCodeFormatInvalid);
                }
                if (address.Country.Code == "CA" && !string.IsNullOrEmpty(address.ZipCode) && !IsValidCanadianPostalCode(address.ZipCode))
                {
                    AddBrokenRule(ValueObjectBusinessRule.PostalCodeFormatInvalid);
                }
            }

            //If "LastContacted" is entered manually by the user then the following validation is valid
            if (LastContacted > DateTime.Today)
            {
                AddBrokenRule(ContactBusinessRule.ContactLastContactedDateInvalid);
            }

            //Validates if all the secondary emails are valid
            if (SecondaryEmails != null)
            {
                foreach (Email email in SecondaryEmails)
                {
                    if (!string.IsNullOrEmpty(Email.EmailId) && !IsValidEmail(email.EmailId))
                    {
                        AddBrokenRule(ValueObjects.ValueObjectBusinessRule.EmailIsInvalid);
                    }
                }
            }
            //Validate Facebook URL:
            //if (FacebookUrl !=null && !string.IsNullOrEmpty(FacebookUrl.URL) && (!FacebookUrl.IsValidURL() || !this.FacebookUrl.URL.ToLower().Contains("facebook.com")))
            if (facebookUrl != null && !string.IsNullOrEmpty(facebookUrl.URL) && !IsFacebookURLValid(facebookUrl))
            {
                AddBrokenRule(ContactBusinessRule.ContactFacebookUrlInvalid);
            }

            //Validate Twitter URL:
            if (twitterUrl != null && !string.IsNullOrEmpty(twitterUrl.URL) && !IsTwitterURLValid(twitterUrl))
            {
                AddBrokenRule(ContactBusinessRule.ContactTwitterUrlInvalid);
            }

            //Validate Google+ URL:
            if (googlePlusUrl != null && !string.IsNullOrEmpty(googlePlusUrl.URL) && !IsGooglePlusURLValid(googlePlusUrl))
            {
                AddBrokenRule(ContactBusinessRule.ContactGooglePlusUrlInvalid);
            }

            //Validate LinkedIn URL:
            if (linkedInUrl != null && !string.IsNullOrEmpty(linkedInUrl.URL) && !IsLinkedInURLValid(linkedInUrl))
            {
                AddBrokenRule(ContactBusinessRule.ContactLinkedInUrlInvalid);
            }

            //Validate Blog URL:
            if (BlogUrl != null && !string.IsNullOrEmpty(BlogUrl.URL) && !BlogUrl.IsValidURL())
            {
                AddBrokenRule(ContactBusinessRule.ContactBlogInUrlInvalid);
            }

            //Validate Web URL:
            if (WebsiteUrl != null && !string.IsNullOrEmpty(WebsiteUrl.URL) && !WebsiteUrl.IsValidURL())
            {
                AddBrokenRule(ContactBusinessRule.ContactWebURLInvalid);
            }
        }