Пример #1
0
        public async Task <T> GetAsync <T>() where T : class
        {
            var singleton = SingletonProvider.Get <T>();

            if (singleton == null)
            {
                return(null);
            }

            return((T)await ContentGetter.GetAsync(singleton.ContentTypeId, singleton.KeyValues).ConfigureAwait(false));
        }
Пример #2
0
        public async Task <object> GetAsync(string contentTypeId)
        {
            var singleton = SingletonProvider.Get(contentTypeId);

            if (singleton == null)
            {
                return(null);
            }

            return(await ContentGetter.GetAsync(singleton.ContentTypeId, singleton.KeyValues).ConfigureAwait(false));
        }
Пример #3
0
        public T Get <T>(string language) where T : class
        {
            var singleton = SingletonProvider.Get <T>();

            if (singleton == null)
            {
                return(null);
            }

            return(ContentGetter.Get <T>(singleton.Id, language));
        }
Пример #4
0
        public async Task InitializeAsync()
        {
            foreach (var singleton in SingletonProvider.GetAll())
            {
                var content = await ContentGetter.GetAsync(singleton.ContentTypeId, singleton.KeyValues);

                var contentType = ContentTypeProvider.Get(singleton.ContentTypeId);

                if (content != null)
                {
                    continue;
                }

                content = ContentInstanceCreator.Create(contentType);

                PrimaryKeySetter.Set(singleton.KeyValues, content);

                await ContentInserter.InsertAsync(content).ConfigureAwait(false);
            }
        }
Пример #5
0
        public void Initialize()
        {
            foreach (var singleton in SingletonProvider.GetAll())
            {
                var content     = ContentGetter.Get <IContent>(singleton.Id, null);
                var contentType = ContentTypeProvider.Get(singleton.ContentTypeId);

                if (content != null)
                {
                    if (content.ContentTypeId != contentType.Id)
                    {
                        throw new SingletonWithIdIsOfWrongType(singleton.Id, contentType, content.GetType(), content.ContentTypeId);
                    }

                    continue;
                }

                content = (IContent)Activator.CreateInstance(contentType.Type);

                content.Id = singleton.Id;

                ContentInserter.Insert(content);
            }
        }