Esempio n. 1
0
        public async Task <List <ExternalServiceType> > GetExternalServiceTypes(bool includeProperties = false, CancellationToken cancellationToken = default(CancellationToken))
        {
            var getAllSpec = new ExternalServiceTypeFilterSpecification();

            if (includeProperties)
            {
                getAllSpec.Includes.Add(s => s.ExternalServiceProperties);
            }

            return((await _externalServiceTypeRepository.GetBySpec(getAllSpec, cancellationToken)).ToList());
        }
Esempio n. 2
0
        public async Task <TaskProvider> AddTaskProvider(string name, string type, string author, string version, string[] requiredServices, string displayName, string description, string thumbnailUrl,
                                                         string tags, DateTime created, DateTime?updated, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();

            List <ExternalServiceType> serviceTypes = null;
            string requiredServicesString           = null;

            if (requiredServices != null && requiredServices.Length > 0)
            {
                requiredServicesString = string.Join(DataDelimiter.Comma.ToString(), requiredServices);
                var serviceTypeSpec = new ExternalServiceTypeFilterSpecification(requiredServices);
                serviceTypes = (await _externalServiceTypeRepository.GetBySpec(serviceTypeSpec, cancellationToken)).ToList();

                var notSupportedServices = requiredServices.Where(s => !serviceTypes.Any(t => t.Name == s)).ToArray();

                if (notSupportedServices.Length > 0)
                {
                    throw new RequiredServicesNotSupportedException(notSupportedServices);
                }
            }

            List <Tag> tagList = null;

            if (!string.IsNullOrEmpty(tags))
            {
                var tagArray = tags.Split(DataDelimiter.Comma);

                var tagSpec = new TagFilterSpecification(tagArray);
                tagList = (await _tagRepository.GetBySpec(tagSpec, cancellationToken)).ToList();

                var newTags = tagArray.Where(tag => !tagList.Any(t => tag.ToLower() == t.Name.ToLower()));
                foreach (var newTagName in newTags)
                {
                    var newTagId = await _tagRepository.Create(new Tag
                    {
                        Name = newTagName
                    }, cancellationToken);

                    tagList.Add(new Tag
                    {
                        Id   = newTagId,
                        Name = newTagName
                    });
                }
            }

            var taskProvider = new TaskProvider
            {
                Name                   = name,
                DisplayName            = displayName,
                Description            = description,
                ThumbnailUrl           = thumbnailUrl,
                Type                   = type,
                Author                 = author,
                Version                = version,
                RequiredServicesString = requiredServicesString,
                Created                = created > DateTime.MinValue ? created : DateTime.UtcNow,
                Updated                = updated,
                Tags                   = tagList?.Select(t => new TaskProviderTag
                {
                    TagId = t.Id
                }).ToList()
            };

            var id = await _taskProviderRepository.Create(taskProvider, cancellationToken);

            return(await _taskProviderRepository.GetById(id, cancellationToken));
        }