Пример #1
0
        public static Report Create()
        {
            Report report = new Report();

            report.Id = EntityIdGenerator.GenerateIdSignature(Constants.IdPrefixTemplate.REPORT);
            return(report);
        }
Пример #2
0
        public static Subscription Create(string userId, string productId, string name,
                                          SubscriptionDateSettings dateSettings = null,
                                          SubscriptionState state = SubscriptionState.submitted,
                                          string primaryKey       = null, string secondaryKey = null)
        {
            if (String.IsNullOrWhiteSpace(userId) &&
                userId.StartsWith(Constants.IdPrefixTemplate.USER))
            {
                throw new InvalidEntityException("subscription's userId is required");
            }
            if (String.IsNullOrWhiteSpace(productId) &&
                userId.StartsWith(Constants.IdPrefixTemplate.PRODUCT))
            {
                throw new InvalidEntityException("subscription's product is required");
            }
            if (String.IsNullOrWhiteSpace(name))
            {
                throw new InvalidEntityException("subscription's name is required");
            }

            Subscription subscription = new Subscription();

            subscription.Id             = EntityIdGenerator.GenerateIdSignature(Constants.IdPrefixTemplate.SUBSCRIPTION);
            subscription.UserId         = userId;
            subscription.ProductId      = productId;
            subscription.Name           = name;
            subscription.PrimaryKey     = primaryKey;
            subscription.SecondaryKey   = secondaryKey;
            subscription.State          = state;
            subscription.StartDate      = dateSettings.StartDate;
            subscription.ExpirationDate = dateSettings.ExpirationDate;

            return(subscription);
        }
Пример #3
0
        public static User Create(string firstName, string lastName,
                                  string email, string password,
                                  UserState state = UserState.active,
                                  string note     = "",
                                  string userId   = null)
        {
            if (String.IsNullOrEmpty(firstName) && firstName.Length > 100)
            {
                throw new InvalidEntityException("User configuration is not valid. 'FirstName' is required and must not exceed 100 characters.");
            }
            if (String.IsNullOrEmpty(lastName) && lastName.Length > 100)
            {
                throw new InvalidEntityException("User configuration is not valid. 'LastName' is required and must not exceed 100 characters.");
            }
            if (String.IsNullOrEmpty(email) && email.Length > 254)
            {
                throw new InvalidEntityException("User configuration is not valid. 'Email' is required and must not exceed 254 characters.");
            }
            if (String.IsNullOrWhiteSpace(password))
            {
                throw new InvalidEntityException("Invalid password: " + password);
            }

            User user = new User();

            user.Id        = userId ?? EntityIdGenerator.GenerateIdSignature(Constants.IdPrefixTemplate.USER);
            user.FirstName = firstName;
            user.LastName  = lastName;
            user.Email     = email;
            user.Password  = password;
            user.State     = state;
            user.Note      = note;
            return(user);
        }
Пример #4
0
        public static APIOperation Create(string name,
                                          RequestMethod method, string urlTemplate,
                                          ParameterContract[] parameters,
                                          RequestContract request, ResponseContract[] responses, string description = null)
        {
            if (String.IsNullOrWhiteSpace(name))
            {
                throw new InvalidEntityException("Operation's is required");
            }
            if (name.Length > 100)
            {
                throw new InvalidEntityException("Length of operation's name must be < 100");
            }
            if (String.IsNullOrWhiteSpace(urlTemplate))
            {
                throw new InvalidEntityException("Operation's urlTemplate is required");
            }


            APIOperation operation = new APIOperation();

            operation.Id                 = EntityIdGenerator.GenerateIdSignature(Constants.IdPrefixTemplate.APIOPERATION);
            operation.Name               = name;
            operation.Method             = method.ToString();
            operation.TemplateParameters = parameters;
            operation.Request            = request;
            operation.Responses          = responses;
            operation.Description        = description;

            operation.UrlTemplate = urlTemplate;
            //operation.UrlTemplate = APIOperationHelper.BuildURL(urlTemplate, parameters);

            return(operation);
        }
Пример #5
0
        public static Property Create()
        {
            Property property = new Property();

            property.Id = EntityIdGenerator.GenerateIdSignature(Constants.IdPrefixTemplate.PROPERTY);

            return(property);
        }
Пример #6
0
        public static Tenant Create()
        {
            Tenant tenant = new Tenant();

            tenant.Id = EntityIdGenerator.GenerateIdSignature(Constants.IdPrefixTemplate.TENANT);

            return(tenant);
        }
Пример #7
0
        public static Logger Create(string loggerType, string name, string description, object credentials, bool isBuffered = true)
        {
            Logger logger = new Logger();

            logger.Id          = EntityIdGenerator.GenerateIdSignature(Constants.IdPrefixTemplate.Logger);
            logger.LoggerType  = loggerType;
            logger.Name        = name;
            logger.Description = description;
            logger.Credentials = credentials;
            logger.IsBuffered  = isBuffered;
            return(logger);
        }
Пример #8
0
        public static Group Create(string name, string description = "",
                                   GroupType type = GroupType.custom, string externalId = null)
        {
            if (String.IsNullOrEmpty(name))
            {
                throw new InvalidEntityException("group's name is required");
            }
            if (type == GroupType.system)
            {
                throw new InvalidEntityException("group's type can't be set to system");
            }

            Group group = new Group();

            group.Id          = EntityIdGenerator.GenerateIdSignature(Constants.IdPrefixTemplate.GROUP);
            group.Name        = name;
            group.Description = description;
            group.Type        = type;
            group.ExternalId  = externalId;
            return(group);
        }
Пример #9
0
        public static Product Create(string name, string description,
                                     ProductState state        = ProductState.notPublished,
                                     bool subscriptionRequired = true,
                                     bool?approvalRequired     = true,
                                     int?subscriptionsLimit    = 0,
                                     string terms     = null,
                                     string productId = null)
        {
            if (String.IsNullOrWhiteSpace(name))
            {
                throw new InvalidEntityException("Product's name is required");
            }

            if (String.IsNullOrEmpty(description) && description.Length > 1000)
            {
                throw new InvalidEntityException("Product configuration is not valid. 'Description' is required and must not exceed 1000 characters.");
            }

            if (!subscriptionRequired)
            {
                if (approvalRequired.HasValue || subscriptionsLimit.HasValue)
                {
                    throw new InvalidEntityException("Product configuration is not valid. Subscription requirement cannot be false while either Subscription limit or Approval required is set");
                }
            }

            Product product = new Product();

            product.Id                   = productId ?? EntityIdGenerator.GenerateIdSignature(Constants.IdPrefixTemplate.PRODUCT);
            product.Name                 = name;
            product.Description          = description;
            product.Terms                = terms;
            product.State                = state;
            product.SubscriptionRequired = subscriptionRequired;
            product.ApprovalRequired     = approvalRequired;
            product.SubscriptionsLimit   = subscriptionsLimit;
            return(product);
        }
Пример #10
0
        public static API Create(string name,
                                 string serviceUrl, string path,
                                 string[] protocols, string description         = "",
                                 AuthenticationSettingsConstract authentication = null,
                                 SubscriptionKeyParameterNames customNames      = null,
                                 string apiId = null)
        {
            if (String.IsNullOrWhiteSpace(name))
            {
                throw new InvalidEntityException("API's name is required");
            }
            if (String.IsNullOrWhiteSpace(serviceUrl))
            {
                throw new InvalidEntityException("API's service url is required");
            }
            if (String.IsNullOrWhiteSpace(path))
            {
                throw new InvalidEntityException("API's path is required");
            }
            if (protocols == null || protocols.Length == 0)
            {
                throw new InvalidEntityException("API's protocol is missing");
            }

            API api = new API();

            api.Id             = apiId ?? EntityIdGenerator.GenerateIdSignature(Constants.IdPrefixTemplate.API);
            api.Name           = name;
            api.Description    = description;
            api.ServiceUrl     = api.GetServiceUrlFormat(serviceUrl);
            api.Path           = path.ToLower();
            api.Protocols      = protocols;
            api.ApiRevision    = "1";
            api.CustomNames    = customNames;
            api.Authentication = authentication;
            return(api);
        }