Beispiel #1
0
        private static void ThrowOnInvalidErrorReport(ErrorReport errorReport, string apiKey, App app)
        {
            var errorCodes = new List <ErrorCode>();

            if (errorReport == null)
            {
                errorCodes.Add(ErrorCode.ErrorReport_MissingErrorReport);
            }
            else
            {
                if (String.IsNullOrWhiteSpace(errorReport.AppId))
                {
                    errorCodes.Add(ErrorCode.ErrorReport_MissingAppId);
                }

                if (app == null)
                {
                    errorCodes.Add(ErrorCode.ErrorReport_AppDoesNotExist);
                }
                else
                {
                    if (!String.Equals(app.ApiKey, apiKey, StringComparison.Ordinal))
                    {
                        errorCodes.Add(ErrorCode.ErrorReport_InvalidApiKey);
                    }
                }

                if (String.IsNullOrWhiteSpace(errorReport.Message))
                {
                    errorCodes.Add(ErrorCode.ErrorReport_MissingMessage);
                }

                if (!String.IsNullOrWhiteSpace(errorReport.UserEmail) &&
                    !EmailValidator.Validate(errorReport.UserEmail))
                {
                    errorCodes.Add(ErrorCode.ErrorReport_InvalidUserEmail);
                }
            }

            if (errorCodes.Count > 0)
            {
                throw new ServiceValidationException(errorCodes);
            }
        }
Beispiel #2
0
        private static void ThrowOnInvalidAppModel(AppModel appModel)
        {
            var errorCodes = new List <ErrorCode>();

            if (appModel == null)
            {
                errorCodes.Add(ErrorCode.App_MissingAppModel);
            }
            else
            {
                if (string.IsNullOrWhiteSpace(appModel.Name))
                {
                    errorCodes.Add(ErrorCode.App_MissingName);
                }

                var emails = TrimmedEmails(appModel.ContactEmails);
                if (emails.Count == 0)
                {
                    errorCodes.Add(ErrorCode.App_MissingContactEmail);
                }
                else
                {
                    if (emails.Any(email => !EmailValidator.Validate(email)))
                    {
                        errorCodes.Add(ErrorCode.App_InvalidEmailFormat);
                    }

                    if (emails.HasDuplicate())
                    {
                        errorCodes.Add(ErrorCode.App_DuplicateContactEmails);
                    }
                }
            }
            if (errorCodes.Count > 0)
            {
                throw new ServiceValidationException(errorCodes);
            }
        }