예제 #1
0
        public static void AddProvider(Provider provider, ProvidersSection section)
        {
            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            if (provider.Name == null)
            {
                throw new ArgumentNullException("provider.Name");
            }

            ProvidersCollection collection = section.Providers;

            if (collection.Any(r => r.Name.Equals(provider.Name)))
            {
                throw new AlreadyExistsException("provider");
            }

            try {
                collection.Add(provider);
            }
            catch (FileLoadException e) {
                throw new LockedException(section.SectionPath, e);
            }
            catch (DirectoryNotFoundException e) {
                throw new ConfigScopeNotFoundException(e);
            }
        }
예제 #2
0
        public static void DeleteProvider(Provider provider, ProvidersSection section)
        {
            if (provider == null)
            {
                return;
            }

            ProvidersCollection collection = section.Providers;

            // To utilize the remove functionality we must pull the element directly from the collection
            provider = collection.FirstOrDefault(p => p.Name.Equals(provider.Name));

            if (provider != null)
            {
                try {
                    collection.Remove(provider);
                }
                catch (FileLoadException e) {
                    throw new LockedException(section.SectionPath, e);
                }
                catch (DirectoryNotFoundException e) {
                    throw new ConfigScopeNotFoundException(e);
                }
            }
        }
        public object Get()
        {
            string providersId = Context.Request.Query[Defines.IDENTIFIER];

            if (string.IsNullOrEmpty(providersId))
            {
                return(NotFound());
            }

            var sectionId = new RewriteId(providersId);

            Site site = sectionId.SiteId == null ? null : SiteHelper.GetSite(sectionId.SiteId.Value);

            ProvidersCollection providers = ProvidersHelper.GetSection(site, sectionId.Path).Providers;

            // Set HTTP header for total count
            this.Context.Response.SetItemsCount(providers.Count());

            return(new {
                entries = providers.Select(provider => ProvidersHelper.ProviderToJsonModelRef(provider, site, sectionId.Path, Context.Request.GetFields()))
            });
        }