Esempio n. 1
0
        private IEnumerable <EntityContainer> GetEntityContainers(IContentTypeComposition?contentType,
                                                                  UmbracoObjectTypes type)
        {
            if (contentType == null)
            {
                return(Enumerable.Empty <EntityContainer>());
            }

            switch (type)
            {
            case UmbracoObjectTypes.DocumentType:
                if (contentType is IContentType documentContentType)
                {
                    return(ContentTypeService.GetContainers(documentContentType));
                }

                return(Enumerable.Empty <EntityContainer>());

            case UmbracoObjectTypes.MediaType:
                if (contentType is IMediaType mediaContentType)
                {
                    return(MediaTypeService.GetContainers(mediaContentType));
                }

                return(Enumerable.Empty <EntityContainer>());

            case UmbracoObjectTypes.MemberType:
                return(Enumerable.Empty <EntityContainer>());

            default:
                throw new ArgumentOutOfRangeException("The entity type was not a content type");
            }
        }
        protected virtual void Reset()
        {
            // reset and dispose scopes
            // ensures we don't leak an opened database connection
            // which would lock eg SqlCe .sdf files
            if (Factory?.TryGetInstance <IScopeProvider>() is ScopeProvider scopeProvider)
            {
                Scope scope;
                while ((scope = scopeProvider.AmbientScope) != null)
                {
                    scope.Reset();
                    scope.Dispose();
                }
            }

            Current.Reset(); // disposes the factory

            // reset all other static things that should not be static ;(
            UriUtility.ResetAppDomainAppVirtualPath();
            SettingsForTests.Reset(); // fixme - should it be optional?

            Mapper.Reset();

            // clear static events
            DocumentRepository.ClearScopeEvents();
            MediaRepository.ClearScopeEvents();
            MemberRepository.ClearScopeEvents();
            ContentTypeService.ClearScopeEvents();
            MediaTypeService.ClearScopeEvents();
            MemberTypeService.ClearScopeEvents();
        }
Esempio n. 3
0
        private void Initialize(string url)
        {
            _serializerSettings = new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore,
                Converters        = new JsonConverter[]
                {
                    new Newtonsoft.Json.Converters.JavaScriptDateTimeConverter(),
                    new MaintenanceJsonConverter()
                }
            };

            Check.IsNotNullOrWhiteSpace(url, "ZabbixApi.url");

            _url        = url;
            _webClient  = new WebClient();
            _httpClient = new HttpClient();

            Actions            = new ActionService(this);
            Alerts             = new AlertService(this);
            ApiInfo            = new ApiInfoService(this);
            Applications       = new ApplicationService(this);
            Correlations       = new CorrelationService(this);
            DiscoveredHosts    = new DiscoveredHostService(this);
            DiscoveredServices = new DiscoveredServiceService(this);
            DiscoveryChecks    = new DiscoveryCheckService(this);
            DiscoveryRules     = new DiscoveryRuleService(this);
            Events             = new EventService(this);
            GraphItems         = new GraphItemService(this);
            GraphPrototypes    = new GraphPrototypeService(this);
            Graphs             = new GraphService(this);
            History            = new HistoryService(this);
            HostGroups         = new HostGroupService(this);
            HostInterfaces     = new HostInterfaceService(this);
            HostPrototypes     = new HostPrototypeService(this);
            Hosts               = new HostService(this);
            IconMaps            = new IconMapService(this);
            ServiceService      = new ServiceService(this);
            Images              = new ImageService(this);
            ItemPrototypes      = new ItemPrototypeService(this);
            Items               = new ItemService(this);
            LLDRules            = new LLDRuleService(this);
            Maintenance         = new MaintenanceService(this);
            Maps                = new MapService(this);
            MediaTypes          = new MediaTypeService(this);
            Proxies             = new ProxyService(this);
            ScreenItems         = new ScreenItemService(this);
            Screens             = new ScreenService(this);
            Scripts             = new ScriptService(this);
            TemplateScreenItems = new TemplateScreenItemService(this);
            TemplateScreens     = new TemplateScreenService(this);
            Templates           = new TemplateService(this);
            TriggerPrototypes   = new TriggerPrototypeService(this);
            Triggers            = new TriggerService(this);
            UserGroups          = new UserGroupService(this);
            GlobalMacros        = new GlobalMacroService(this);
            HostMacros          = new HostMacroService(this);
            Users               = new UserService(this);
            ValueMaps           = new ValueMapService(this);
        }
Esempio n. 4
0
        public void ItWillReturnTrueIfLinkedRepresentation(string acceptHeader, bool expected)
        {
            var service = new MediaTypeService();

            var result = service.IsLinkedRepresentation(acceptHeader);

            Assert.Equal(expected, result);
        }
Esempio n. 5
0
        private void Initialize(string url)
        {
            Check.IsNotNullOrWhiteSpace(url, "ZabbixApi.url");

            _url        = url;
            _webClient  = new WebClient();
            _httpClient = new HttpClient();

            Actions            = new ActionService(this);
            Alerts             = new AlertService(this);
            ApiInfo            = new ApiInfoService(this);
            Applications       = new ApplicationService(this);
            DiscoveredHosts    = new DiscoveredHostService(this);
            DiscoveredServices = new DiscoveredServiceService(this);
            DiscoveryChecks    = new DiscoveryCheckService(this);
            DiscoveryRules     = new DiscoveryRuleService(this);
            Events             = new EventService(this);
            GraphItems         = new GraphItemService(this);
            GraphPrototypes    = new GraphPrototypeService(this);
            Graphs             = new GraphService(this);
            History            = new HistoryService(this);
            HostGroups         = new HostGroupService(this);
            HostInterfaces     = new HostInterfaceService(this);
            HostPrototypes     = new HostPrototypeService(this);
            Hosts               = new HostService(this);
            IconMaps            = new IconMapService(this);
            ITServiceService    = new ITServiceService(this);
            Images              = new ImageService(this);
            ItemPrototypes      = new ItemPrototypeService(this);
            Items               = new ItemService(this);
            LLDRules            = new LLDRuleService(this);
            Maintenance         = new MaintenanceService(this);
            Maps                = new MapService(this);
            Medias              = new MediaService(this);
            MediaTypes          = new MediaTypeService(this);
            Proxies             = new ProxyService(this);
            ScreenItems         = new ScreenItemService(this);
            Screens             = new ScreenService(this);
            Scripts             = new ScriptService(this);
            TemplateScreenItems = new TemplateScreenItemService(this);
            TemplateScreens     = new TemplateScreenService(this);
            Templates           = new TemplateService(this);
            TriggerPrototypes   = new TriggerPrototypeService(this);
            Triggers            = new TriggerService(this);
            UserGroups          = new UserGroupService(this);
            GlobalMacros        = new GlobalMacroService(this);
            HostMacros          = new HostMacroService(this);
            Users               = new UserService(this);
        }
Esempio n. 6
0
        /// <summary>
        /// 获取资源分类
        /// </summary>
        /// <returns></returns>
        public JsonResult GetMediaType()
        {
            MediaTypeService service = new MediaTypeService();

            return(Json(service.GetAll(), JsonRequestBehavior.AllowGet));
        }
Esempio n. 7
0
        /// <summary>
        ///     Returns the available composite content types for a given content type
        /// </summary>
        /// <param name="type"></param>
        /// <param name="filterContentTypes">
        ///     This is normally an empty list but if additional content type aliases are passed in, any content types containing
        ///     those aliases will be filtered out
        ///     along with any content types that have matching property types that are included in the filtered content types
        /// </param>
        /// <param name="filterPropertyTypes">
        ///     This is normally an empty list but if additional property type aliases are passed in, any content types that have
        ///     these aliases will be filtered out.
        ///     This is required because in the case of creating/modifying a content type because new property types being added to
        ///     it are not yet persisted so cannot
        ///     be looked up via the db, they need to be passed in.
        /// </param>
        /// <param name="contentTypeId"></param>
        /// <param name="isElement">Whether the composite content types should be applicable for an element type</param>
        /// <returns></returns>
        protected ActionResult <IEnumerable <Tuple <EntityBasic?, bool> > > PerformGetAvailableCompositeContentTypes(
            int contentTypeId,
            UmbracoObjectTypes type,
            string[]?filterContentTypes,
            string[]?filterPropertyTypes,
            bool isElement)
        {
            IContentTypeComposition?source = null;

            //below is all ported from the old doc type editor and comes with the same weaknesses /insanity / magic

            IContentTypeComposition[] allContentTypes;

            switch (type)
            {
            case UmbracoObjectTypes.DocumentType:
                if (contentTypeId > 0)
                {
                    source = ContentTypeService.Get(contentTypeId);
                    if (source == null)
                    {
                        return(NotFound());
                    }
                }

                allContentTypes = ContentTypeService.GetAll().Cast <IContentTypeComposition>().ToArray();
                break;

            case UmbracoObjectTypes.MediaType:
                if (contentTypeId > 0)
                {
                    source = MediaTypeService.Get(contentTypeId);
                    if (source == null)
                    {
                        return(NotFound());
                    }
                }

                allContentTypes = MediaTypeService.GetAll().Cast <IContentTypeComposition>().ToArray();
                break;

            case UmbracoObjectTypes.MemberType:
                if (contentTypeId > 0)
                {
                    source = MemberTypeService.Get(contentTypeId);
                    if (source == null)
                    {
                        return(NotFound());
                    }
                }

                allContentTypes = MemberTypeService.GetAll().Cast <IContentTypeComposition>().ToArray();
                break;

            default:
                throw new ArgumentOutOfRangeException("The entity type was not a content type");
            }

            ContentTypeAvailableCompositionsResults availableCompositions =
                ContentTypeService.GetAvailableCompositeContentTypes(source, allContentTypes, filterContentTypes,
                                                                     filterPropertyTypes, isElement);


            IContentTypeComposition[] currCompositions =
                source == null ? new IContentTypeComposition[] { } : source.ContentTypeComposition.ToArray();
            var compAliases = currCompositions.Select(x => x.Alias).ToArray();
            IEnumerable <string> ancestors = availableCompositions.Ancestors.Select(x => x.Alias);

            return(availableCompositions.Results
                   .Select(x =>
                           new Tuple <EntityBasic?, bool>(UmbracoMapper.Map <IContentTypeComposition, EntityBasic>(x.Composition),
                                                          x.Allowed))
                   .Select(x =>
            {
                //we need to ensure that the item is enabled if it is already selected
                // but do not allow it if it is any of the ancestors
                if (compAliases.Contains(x.Item1?.Alias) && ancestors.Contains(x.Item1?.Alias) == false)
                {
                    //re-set x to be allowed (NOTE: I didn't know you could set an enumerable item in a lambda!)
                    x = new Tuple <EntityBasic?, bool>(x.Item1, true);
                }

                //translate the name
                if (x.Item1 is not null)
                {
                    x.Item1.Name = TranslateItem(x.Item1.Name);
                }

                IContentTypeComposition?contentType = allContentTypes.FirstOrDefault(c => c.Key == x.Item1?.Key);
                EntityContainer[] containers = GetEntityContainers(contentType, type).ToArray();
                var containerPath =
                    $"/{(containers.Any() ? $"{string.Join("/", containers.Select(c => c.Name))}/" : null)}";
                if (x.Item1 is not null)
                {
                    x.Item1.AdditionalData["containerPath"] = containerPath;
                }

                return x;
            })
                   .ToList());
        }
Esempio n. 8
0
        /// <summary>
        ///     Returns a list of content types where a particular composition content type is used
        /// </summary>
        /// <param name="type">Type of content Type, eg documentType or mediaType</param>
        /// <param name="contentTypeId">Id of composition content type</param>
        /// <returns></returns>
        protected ActionResult <IEnumerable <EntityBasic> > PerformGetWhereCompositionIsUsedInContentTypes(
            int contentTypeId, UmbracoObjectTypes type)
        {
            var id = 0;

            if (contentTypeId > 0)
            {
                IContentTypeComposition?source;

                switch (type)
                {
                case UmbracoObjectTypes.DocumentType:
                    source = ContentTypeService.Get(contentTypeId);
                    break;

                case UmbracoObjectTypes.MediaType:
                    source = MediaTypeService.Get(contentTypeId);
                    break;

                case UmbracoObjectTypes.MemberType:
                    source = MemberTypeService.Get(contentTypeId);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(type));
                }

                if (source == null)
                {
                    return(NotFound());
                }

                id = source.Id;
            }

            IEnumerable <IContentTypeComposition> composedOf;

            switch (type)
            {
            case UmbracoObjectTypes.DocumentType:
                composedOf = ContentTypeService.GetComposedOf(id);
                break;

            case UmbracoObjectTypes.MediaType:
                composedOf = MediaTypeService.GetComposedOf(id);
                break;

            case UmbracoObjectTypes.MemberType:
                composedOf = MemberTypeService.GetComposedOf(id);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(type));
            }

            EntityBasic TranslateName(EntityBasic e)
            {
                e.Name = TranslateItem(e.Name);
                return(e);
            }

            return(composedOf
                   .Select(UmbracoMapper.Map <IContentTypeComposition, EntityBasic>)
                   .WhereNotNull()
                   .Select(TranslateName)
                   .ToList());
        }
Esempio n. 9
0
 public static ObservableCollection <MediaTypeViewModel> GetMediaTypeViewModels()
 {
     return(MediaTypeService.GetMediaTypes().ToMediaTypeViewModelCollection());
 }