コード例 #1
0
        public async Task <ServiceResult> CheckDb(BlobCacheType blobCache = BlobCacheType.LocalMachine)
        {
            var serviceResult = new ServiceResult();

            var allKeysResult = await GetAllKeys(blobCache);

            serviceResult.Success = allKeysResult.Success && allKeysResult.Result.Any();

            return(serviceResult);
        }
コード例 #2
0
        private static void SetUp()
        {
            BlobCacheType cacheType = BlobCacheType.None;

            Enum.TryParse(ValidationHelper.GetString(SettingsHelper.AppSettings[nameof(WebConfigKeys.AzureStorageProviderCacheType)], nameof(BlobCacheType.None)), out cacheType);

            SetUp(
                accountName: ValidationHelper.GetString(SettingsHelper.AppSettings[nameof(WebConfigKeys.CMSAzureAccountName)], string.Empty),
                sharedKey: ValidationHelper.GetString(SettingsHelper.AppSettings[nameof(WebConfigKeys.CMSAzureSharedKey)], string.Empty),
                endPoint: ValidationHelper.GetString(SettingsHelper.AppSettings[nameof(WebConfigKeys.CMSAzureCDNEndpoint)], string.Empty),
                publicContainer: ValidationHelper.GetBoolean(SettingsHelper.AppSettings[nameof(WebConfigKeys.CMSAzurePublicContainer)], false),
                rootContainer: ValidationHelper.GetString(SettingsHelper.AppSettings[nameof(WebConfigKeys.CMSAzureRootContainer)], string.Empty),
                blobCacheType: cacheType,
                blobCacheMinutes: ValidationHelper.GetInteger(SettingsHelper.AppSettings[nameof(WebConfigKeys.AzureStorageProviderCacheClearMinutes)], 60)
                );
        }
コード例 #3
0
        public async Task <ServiceResult> RemoveObject(string token, BlobCacheType blobCache = BlobCacheType.LocalMachine)
        {
            var serviceResult = new ServiceResult();

            try
            {
                var result = await GetBlobCache(blobCache).Invalidate(token);

                serviceResult.Success = true;
            }
            catch (Exception ex)
            {
                serviceResult.Success           = false;
                serviceResult.Error.Description = ex.Message;
            }

            return(serviceResult);
        }
コード例 #4
0
        public async Task <ServiceResult <IEnumerable <string> > > GetAllKeys(BlobCacheType blobCache = BlobCacheType.LocalMachine)
        {
            var serviceResult = new ServiceResult <IEnumerable <string> >();

            try
            {
                var result = await GetBlobCache(blobCache).GetAllKeys();

                serviceResult.Success = true;
                serviceResult.Result  = result;
            }
            catch (Exception ex)
            {
                serviceResult.Success           = false;
                serviceResult.Error.Description = ex.Message;
            }

            return(serviceResult);
        }
コード例 #5
0
        private IBlobCache GetBlobCache(BlobCacheType blobCache = BlobCacheType.LocalMachine)
        {
            IBlobCache blobCacheObject = BlobCache.LocalMachine;

            switch (blobCache)
            {
            case BlobCacheType.InMemory:
                blobCacheObject = BlobCache.InMemory;
                break;

            case BlobCacheType.Secure:
                blobCacheObject = BlobCache.Secure;
                break;

            case BlobCacheType.UserAccount:
                blobCacheObject = BlobCache.UserAccount;
                break;
            }
            return(blobCacheObject);
        }
コード例 #6
0
        public static void SetUp(string accountName, string sharedKey, string endPoint, bool publicContainer, string rootContainer, BlobCacheType blobCacheType, int blobCacheMinutes)
        {
            _instance = new AccountInfo
            {
                AccountName      = accountName,
                SharedKey        = sharedKey,
                EndPoint         = endPoint,
                PublicContainer  = publicContainer,
                RootContainer    = rootContainer,
                BlobCacheType    = blobCacheType,
                BlobCacheMinutes = blobCacheMinutes
            };

            // set up cache clearing task
            if (blobCacheType != BlobCacheType.None)
            {
                var exists = TaskInfoProvider.GetTasks()
                             .Column(nameof(TaskInfo.TaskID))
                             .WhereEquals(nameof(TaskInfo.TaskName), typeof(CacheClearingTask).FullName)
                             .TopN(1)
                             .Any();

                if (!exists)
                {
                    var taskInfo = new TaskInfo
                    {
                        TaskName         = typeof(CacheClearingTask).FullName,
                        TaskDisplayName  = "Clear Azure cached metadata and binary objects",
                        TaskAssemblyName = typeof(CacheClearingTask).Assembly.GetName().Name,
                        TaskClass        = typeof(CacheClearingTask).FullName,
                        TaskInterval     = SchedulingHelper.EncodeInterval(
                            new TaskInterval
                        {
                            Period    = SchedulingHelper.PERIOD_MINUTE,
                            StartTime = DateTime.Now,
                            Every     = blobCacheMinutes
                        }),
                        TaskNextRunTime         = DateTime.Now,
                        TaskRunInSeparateThread = true,
                        TaskGUID = Guid.NewGuid(),
                        TaskData = string.Empty,
                        TaskAllowExternalService = false,
                        TaskEnabled = true,
                        TaskType    = ScheduledTaskTypeEnum.System
                    };
                    TaskInfoProvider.SetTaskInfo(taskInfo);
                }
            }
        }
コード例 #7
0
 public void SetCacheType(BlobCacheType cacheType)
 {
     _cacheType = cacheType;
 }