Пример #1
0
 public PostController(FujiyBlogDatabase db, PostRepository postRepository, UserRepository userRepository, DateTimeUtil dateTimeUtil)
 {
     this.db             = db;
     this.postRepository = postRepository;
     this.userRepository = userRepository;
     this.dateTimeUtil   = dateTimeUtil;
 }
Пример #2
0
 public CommentController(FujiyBlogDatabase db, SettingRepository settings, ICompositeViewEngine viewEngine, IEmailSender emailSender)
 {
     this.db          = db;
     this.settings    = settings;
     this.viewEngine  = viewEngine;
     this.emailSender = emailSender;
 }
Пример #3
0
        public static TResult FromCacheOrExecute <TResult>(FujiyBlogDatabase db, Expression <Func <TResult> > func, MemoryCacheEntryOptions cacheItemPolicy = null, bool condition = true)
        {
            if (func == null)
            {
                throw new ArgumentNullException("func");
            }

            string key = ExtractKeyFromExpression(func);

            return(FromCacheOrExecute(db, func.Compile(), key, cacheItemPolicy, condition));
        }
Пример #4
0
        public WidgetViewComponent(FujiyBlogDatabase db, WidgetSettingRepository widgetSettingRepository)
        {
            this.db = db;
            this.widgetSettingRepository = widgetSettingRepository;

            if (widgets == null)
            {
                var diretorio = new DirectoryInfo(Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, "Views", "Shared", "Components", "Widget"));
                widgets = (from file in diretorio.GetFiles()
                           let fileWithoutExtension = Path.GetFileNameWithoutExtension(file.FullName)
                                                      where fileWithoutExtension != "Index" && fileWithoutExtension != "Widget" && !fileWithoutExtension.EndsWith("Edit")
                                                      select fileWithoutExtension).ToArray();
            }
        }
Пример #5
0
        public static TResult FromCacheOrExecute <TResult>(FujiyBlogDatabase db, Func <TResult> func, string key, MemoryCacheEntryOptions cacheItemPolicy = null, bool condition = true)
        {
            if (func == null)
            {
                throw new ArgumentNullException(nameof(func));
            }

            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            string lastDatabaseChangeAtDb = db.LastDatabaseChange;

            if (lastDatabaseChangeAtDb != lastDatabaseChange)
            {
                lastDatabaseChange = lastDatabaseChangeAtDb;
                ClearCache();
            }

            if (!condition)
            {
                return(func());
            }

            object returnObject = DefaultCache.Get(key);

            bool hasValueAndIsSameType = (returnObject is TResult);

            if (hasValueAndIsSameType)
            {
                Task taskValue = returnObject as Task;
                if (taskValue != null && (taskValue.Status == TaskStatus.Canceled || taskValue.Status == TaskStatus.Faulted))
                {
                    hasValueAndIsSameType = false;
                }
            }

            if (hasValueAndIsSameType == false)
            {
                returnObject = func();
                if (returnObject != null)
                {
                    DefaultCache.Set(key, returnObject, cacheItemPolicy);
                }
            }

            return((TResult)returnObject);
        }
Пример #6
0
        public WidgetViewComponent(FujiyBlogDatabase db, WidgetSettingRepository widgetSettingRepository)
        {
            this.db = db;
            this.widgetSettingRepository = widgetSettingRepository;

            if (widgets == null || widgets.Length == 0)
            {
                var widgetsViews = CompiledViewsHelper.GetViewsTypes <WidgetSetting>();

                widgets = (from widgetView in widgetsViews
                           let nameWithoutPrefix = widgetView.Name.Substring("Views_Shared_Components_Widget_".Length)
                                                   where nameWithoutPrefix != "Index" && nameWithoutPrefix != "Widget" && !nameWithoutPrefix.EndsWith("Edit")
                                                   select nameWithoutPrefix).ToArray();
            }
        }
Пример #7
0
        public static Post GetCompletePost(this FujiyBlogDatabase database, string slug, HttpContext httpContext)
        {
            Post post = database.Posts.WhereHaveRoles(httpContext).Include(x => x.Author).SingleOrDefault(x => x.Slug == slug);

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

            database.Tags.Include(x=>x.PostTags).Where(x => x.PostTags.Any(y => y.PostId == post.Id)).Load();
            database.Categories.Include(x=>x.PostCategories).Where(x => x.PostCategories.Any(y => y.PostId == post.Id)).Load();
            database.PostComments.Include(x=>x.Author).WhereHaveRoles(httpContext).Load();

            return post;
        }
Пример #8
0
        public static TResult FromCacheOrExecute <TResult>(FujiyBlogDatabase db, Expression <Func <TResult> > func, string key = null, MemoryCacheEntryOptions cacheItemPolicy = null, bool condition = true)
        {
            string lastDatabaseChangeAtDb = db.LastDatabaseChange;

            if (lastDatabaseChangeAtDb != lastDatabaseChange)
            {
                lastDatabaseChange = lastDatabaseChangeAtDb;
                ClearCache();
            }

            if (!condition)
            {
                return(func.Compile()());
            }

            if (func == null)
            {
                throw new ArgumentNullException("func");
            }

            if (string.IsNullOrEmpty(key))
            {
                MethodCallExpression method = func.Body as MethodCallExpression;

                if (method == null)
                {
                    throw new InvalidCachedFuncException("Body must be MethodCallExpression to auto generate a cache key");
                }

                key = CacheKeyGenerator.GenerateKey(method);
            }

            object returnObject = DefaultCache.Get(key);

            if (!(returnObject is TResult))
            {
                returnObject = func.Compile()();
                if (returnObject != null)
                {
                    DefaultCache.Set(key, returnObject, cacheItemPolicy);
                }
            }

            return((TResult)returnObject);
        }
Пример #9
0
 public AccountController(
     FujiyBlogDatabase db,
     UserManager <ApplicationUser> userManager,
     RoleManager <IdentityRole> roleManager,
     SignInManager <ApplicationUser> signInManager,
     IOptions <IdentityCookieOptions> identityCookieOptions,
     IEmailSender emailSender,
     ISmsSender smsSender,
     ILoggerFactory loggerFactory)
 {
     this.db               = db;
     _userManager          = userManager;
     _roleManager          = roleManager;
     _signInManager        = signInManager;
     _externalCookieScheme = identityCookieOptions.Value.ExternalCookieAuthenticationScheme;
     _emailSender          = emailSender;
     _smsSender            = smsSender;
     _logger               = loggerFactory.CreateLogger <AccountController>();
 }
Пример #10
0
 public WidgetController(FujiyBlogDatabase db, WidgetSettingRepository widgetSettingRepository)
 {
     this.db = db;
     this.widgetSettingRepository = widgetSettingRepository;
 }
Пример #11
0
 public PageController(FujiyBlogDatabase db)
 {
     this.db = db;
 }
Пример #12
0
 public CommentController(FujiyBlogDatabase db, SettingRepository settings, ICompositeViewEngine viewEngine)
 {
     this.db         = db;
     this.settings   = settings;
     this.viewEngine = viewEngine;
 }
Пример #13
0
 public SearchController(FujiyBlogDatabase db, SettingRepository settings)
 {
     this.db       = db;
     this.settings = settings;
 }
Пример #14
0
 public PostController(PostRepository postRepository, SettingRepository settings, FujiyBlogDatabase db)
 {
     this.postRepository = postRepository;
     this.settings       = settings;
     this.db             = db;
 }
Пример #15
0
 public CommentController(FujiyBlogDatabase db)
 {
     this.db = db;
 }
Пример #16
0
 public SettingController(FujiyBlogDatabase db, SettingRepository settings, TelemetryConfiguration configuration)
 {
     this.db = db;
     this.settingRepository = settings;
     this.configuration     = configuration;
 }
Пример #17
0
 public PageController(FujiyBlogDatabase db, DateTimeUtil dateTimeUtil)
 {
     this.db           = db;
     this.dateTimeUtil = dateTimeUtil;
 }
Пример #18
0
 public UserController(FujiyBlogDatabase db, UserManager <ApplicationUser> userManager, RoleManager <IdentityRole> roleManager)
 {
     this.db          = db;
     this.userManager = userManager;
     this.roleManager = roleManager;
 }