예제 #1
0
        public async Task <Plugin> AddPlugin(string name, string type, string author, string version, string[] requiredServices, 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);
                }
            }

            var plugin = new Plugin
            {
                Name    = name,
                Type    = type,
                Author  = author,
                Version = version,
                RequiredServicesString = requiredServicesString
            };

            var id = await _pluginRepository.Create(plugin, cancellationToken);

            return(await _pluginRepository.GetById(id, cancellationToken));
        }
예제 #2
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());
        }
예제 #3
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));
        }