예제 #1
0
        public void ResetCache()
        {
            DbContextOptionsBuilder <HoodDbContext> options = new DbContextOptionsBuilder <HoodDbContext>();

            options.UseSqlServer(_config["ConnectionStrings:DefaultConnection"]);
            HoodDbContext db = new HoodDbContext(options.Options);

            _directoriesById = new Lazy <Dictionary <int, MediaDirectory> >(() =>
            {
                IQueryable <MediaDirectory> q = from d in db.MediaDirectories
                                                select new MediaDirectory
                {
                    Id          = d.Id,
                    DisplayName = d.DisplayName,
                    Slug        = d.Slug,
                    Type        = d.Type,
                    OwnerId     = d.OwnerId,
                    ParentId    = d.ParentId,
                    Parent      = d.Parent,
                    Children    = d.Children
                };
                return(q.ToDictionary(c => c.Id));
            });
            _topLevel      = new Lazy <MediaDirectory[]>(() => _directoriesById.Value.Values.Where(c => c.ParentId == null).ToArray());
            _siteDirectory = new Lazy <MediaDirectory>(() => _directoriesById.Value.Values.SingleOrDefault(c => c.Slug == MediaManager.SiteDirectorySlug && c.Type == DirectoryType.System));
        }
예제 #2
0
 public AccountRepository()
 {
     _db = Engine.Services.Resolve <HoodDbContext>();
     _contextAccessor = Engine.Services.Resolve <IHttpContextAccessor>();
     _linkGenerator   = Engine.Services.Resolve <LinkGenerator>();
     _mailService     = Engine.Services.Resolve <IMailService>();
     _emailSender     = Engine.Services.Resolve <IEmailSender>();
 }
예제 #3
0
 public SettingsRepository(
     HoodDbContext db,
     IConfiguration config,
     IHoodCache cache)
 {
     _db     = db;
     _config = config;
     _cache  = cache;
 }
예제 #4
0
 public PropertyRepository(
     HoodDbContext db,
     IHoodCache cache,
     IMediaManager media)
 {
     _db    = db;
     _cache = cache;
     _media = media;
 }
예제 #5
0
        public void ResetCache()
        {
            if (!Engine.Services.Installed)
            {
                return;
            }
            var options = new DbContextOptionsBuilder <HoodDbContext>();

            options.UseSqlServer(_config["ConnectionStrings:DefaultConnection"]);
            var db = new HoodDbContext(options.Options);

            byKey = new Lazy <Dictionary <int, ContentCategory> >(() =>
            {
                var q = from d in db.ContentCategories
                        select new ContentCategory
                {
                    Id               = d.Id,
                    DisplayName      = d.DisplayName,
                    Slug             = d.Slug,
                    ContentType      = d.ContentType,
                    ParentCategoryId = d.ParentCategoryId,
                    ParentCategory   = d.ParentCategory,
                    Children         = d.Children,
                    Count            = d.Content.Where(c => c.Content.Status == ContentStatus.Published).Count(),
                };
                return(q.ToDictionary(c => c.Id));
            });

            ContentSettings contentSettings = Engine.Settings.Content;

            bySlug = new Dictionary <string, Lazy <Dictionary <string, ContentCategory> > >();
            foreach (var type in contentSettings.Types.Where(t => t.Enabled))
            {
                bySlug.Add(
                    type.Type,
                    new Lazy <Dictionary <string, ContentCategory> >(() =>
                {
                    var q = from d in db.ContentCategories
                            where d.ContentType == type.Type
                            select new ContentCategory
                    {
                        Id               = d.Id,
                        DisplayName      = d.DisplayName,
                        Slug             = d.Slug,
                        ContentType      = d.ContentType,
                        ParentCategoryId = d.ParentCategoryId,
                        ParentCategory   = d.ParentCategory,
                        Children         = d.Children,
                        Count            = d.Content.Where(c => c.Content.Status == ContentStatus.Published).Count(),
                    };
                    return(q.ToDictionary(c => c.Slug));
                })
                    );
            }
            topLevel = new Lazy <ContentCategory[]>(() => byKey.Value.Values.Where(c => c.ParentCategoryId == null).ToArray());
        }
예제 #6
0
 public ContentRepository(
     HoodDbContext db,
     IHoodCache cache,
     IWebHostEnvironment env,
     IEventsService eventService)
 {
     _db           = db;
     _cache        = cache;
     _eventService = eventService;
     _env          = env;
 }
예제 #7
0
        public void ResetCache()
        {
            var options = new DbContextOptionsBuilder <HoodDbContext>();

            options.UseSqlServer(_config["ConnectionStrings:DefaultConnection"]);
            var db = new HoodDbContext(options.Options);

            ContentSettings contentSettings = Engine.Settings.Content;

            bySlug = new Dictionary <string, Lazy <Dictionary <int, Content> > >();
            foreach (var type in contentSettings.Types.Where(t => t.Enabled && t.CachedByType))
            {
                bySlug.Add(
                    type.Type,
                    new Lazy <Dictionary <int, Content> >(() => db.Content.Where(c => c.ContentType == type.Type).ToDictionary(c => c.Id))
                    );
            }
        }
예제 #8
0
        public bool RunUpdate(HttpContext context)
        {
            try
            {
                Lock.AcquireWriterLock(Timeout.Infinite);
                Total           = 0;
                Processed       = 0;
                PercentComplete = 0.0;
                Running         = true;
                HasRun          = true;
                Cancelled       = false;
                Succeeded       = false;
                StatusMessage   = "Starting update...";
                _context        = context;
                // Get a new instance of the HoodDbContext for this import.
                var options = new DbContextOptionsBuilder <HoodDbContext>();
                options.UseSqlServer(_config["ConnectionStrings:DefaultConnection"]);
                Database = new HoodDbContext(options.Options);

                _media = new MediaManager(_env, _config);

                Lock.ReleaseWriterLock();

                ThreadStart pts    = new ThreadStart(RefreshAllMedia);
                Thread      thread = new Thread(pts)
                {
                    Name     = "RefreshAllMedia",
                    Priority = ThreadPriority.Normal
                };
                thread.Start();

                return(true);
            }
            catch (Exception ex)
            {
                Lock.AcquireWriterLock(Timeout.Infinite);
                Running       = false;
                StatusMessage = ex.Message;
                Lock.ReleaseWriterLock();
                return(false);
            }
        }
예제 #9
0
        private async Task AddLogAsync(string message, string detail = "", LogType type = LogType.Info, string source = "")
        {
            if (!Engine.Services.Installed)
            {
                return;
            }

            if (Engine.Configuration.LogLevel == LogLevel.None)
            {
                return;
            }

            switch (type)
            {
            case LogType.Error:
                if (Engine.Configuration.LogLevel >= LogLevel.None)
                {
                    return;
                }
                break;

            case LogType.Warning:
                if (Engine.Configuration.LogLevel >= LogLevel.Error)
                {
                    return;
                }
                break;

            case LogType.Info:
                if (Engine.Configuration.LogLevel >= LogLevel.Warning)
                {
                    return;
                }
                break;

            default:
                if (Engine.Configuration.LogLevel >= LogLevel.Information)
                {
                    return;
                }
                break;
            }

            string userId = null;

            if (Engine.Account != null)
            {
                userId = Engine.Account.GetLocalUserId();
            }

            string url = null;

            if (_contextAccessor.HttpContext != null)
            {
                url = _contextAccessor.HttpContext.GetSiteUrl(true, true);
            }

            using (HoodDbContext context = _hoodDbContext)
            {
                Log log = new Log()
                {
                    Type      = type,
                    Source    = source,
                    Detail    = detail,
                    Time      = DateTime.UtcNow,
                    Title     = message,
                    UserId    = userId,
                    SourceUrl = url
                };
                context.Logs.Add(log);
                await context.SaveChangesAsync();
            }
        }
예제 #10
0
 public Auth0Service()
 {
     _cache = Engine.Services.Resolve <IHoodCache>();
     _db    = Engine.Services.Resolve <HoodDbContext>();
 }