Пример #1
0
        public void Setup()
        {
            var pathResolver = new Mock<IPathResolver>();

            pathResolver.Setup(p => p.GetFullPath(It.IsAny<string>())).Returns<string>(s => s);

            TheCache = new HttpCache(Http.Object, pathResolver.Object);
        }
Пример #2
0
        private void MockBanStorage()
        {
            var context = this.mockSecurityDataContext.Object;
            Func<ISecurityDataContext> createSecurityDataContext = () => { return context; };

            var dbbanStorage = new DatabaseBanStorage(this.mockLmsService.Object, createSecurityDataContext);
            var cachePrvoider = new HttpCache();
            this.banStorage = new CachedBanStorage(dbbanStorage, cachePrvoider);
        }
Пример #3
0
        public static T_COM_Master_PositionCollection GetAll()
        {
            T_COM_Master_PositionCollection items = new T_COM_Master_PositionCollection();
            string key  = SETTINGS_ALL_KEY;
            object obj2 = HttpCache.Get(key);

            if ((obj2 != null))
            {
                return((T_COM_Master_PositionCollection)obj2);
            }
            using (var client = WebApiHelper.myclient(HouseEndpoint, SystemConst.APIJosonReturnValue))
            {
                HttpResponseMessage response = client.GetAsync(Resource).GetAwaiter().GetResult();

                if (response.IsSuccessStatusCode)
                {
                    items = response.Content.ReadAsAsync <T_COM_Master_PositionCollection>().GetAwaiter().GetResult();
                }
            }
            HttpCache.Max(key, items);
            return(items);
        }
Пример #4
0
        public static AccessRightsCollection GetAll(int CompanyID)
        {
            AccessRightsCollection items = new AccessRightsCollection();
            string key  = String.Format(SETTINGS_ALL_KEY, CompanyID);
            object obj2 = HttpCache.Get(key);

            if ((obj2 != null))
            {
                return((AccessRightsCollection)obj2);
            }
            using (var client = WebApiHelper.myclient(HouseEndpoint, SystemConst.APIJosonReturnValue))
            {
                HttpResponseMessage response = client.GetAsync(string.Format(Resource + "?CompanyID={0}", CompanyID)).GetAwaiter().GetResult();

                if (response.IsSuccessStatusCode)
                {
                    items = response.Content.ReadAsAsync <AccessRightsCollection>().GetAwaiter().GetResult();
                }
            }
            HttpCache.Max(key, items);
            return(items);
        }
Пример #5
0
        public static UsersInRolesCollection GetByUsername(string userName, int companyID)
        {
            UsersInRolesCollection items = new UsersInRolesCollection();
            string key  = string.Format(SETTINGS_User_KEY, userName, companyID);
            object obj2 = HttpCache.Get(key);

            if ((obj2 != null))
            {
                return((UsersInRolesCollection)obj2);
            }
            using (var client = WebApiHelper.myclient(HouseEndpoint, SystemConst.APIJosonReturnValue))
            {
                HttpResponseMessage response = client.GetAsync(string.Format(Resource + "?usr={0}&companyID={1}&getBy=username", userName, companyID)).GetAwaiter().GetResult();

                if (response.IsSuccessStatusCode)
                {
                    items = response.Content.ReadAsAsync <UsersInRolesCollection>().GetAwaiter().GetResult();
                }
            }
            HttpCache.Max(key, items);
            return(items);
        }
Пример #6
0
        public virtual IEnumerable <DNHLocaleStringResource> SearchData(SearchFilter value)
        {
            DNHLocaleStringResourceCollection items = new DNHLocaleStringResourceCollection();

            if (value.OrderBy.ToLower() == "id")
            {
                value.OrderBy = "LocaleStringResourceID";
            }
            string key = string.Format(SETTINGS_Search_KEY, value.CompanyID, value.Keyword, value.Page, value.PageSize, value.OrderBy, value.OrderDirection, value.Condition);

            if (SystemConfig.AllowSearchCache)
            {
                object obj2 = HttpCache.Get(key);

                if ((obj2 != null))
                {
                    return((DNHLocaleStringResourceCollection)obj2);
                }
            }

            using (var client = WebApiHelper.myclient(HouseEndpoint, SystemConst.APIJosonReturnValue))
            {
                HttpResponseMessage response = client.PostAsJsonAsync(Resource + "?method=search", value).GetAwaiter().GetResult();

                if (response.IsSuccessStatusCode)
                {
                    items = response.Content.ReadAsAsync <DNHLocaleStringResourceCollection>().GetAwaiter().GetResult();
                }
            }

            if (SystemConfig.AllowSearchCache && items.Count > 0)
            {
                HttpCache.Max(key, items);
            }
            return(items);

            //   return Search(value);
        }
Пример #7
0
        public static T_COM_Master_LocationCollection GetAllByEntityID(int EntityID)
        {
            T_COM_Master_LocationCollection items = new T_COM_Master_LocationCollection();
            string key  = String.Format(SETTINGS_ALL_KEY_EntityID, EntityID);
            object obj2 = HttpCache.Get(key);

            if ((obj2 != null))
            {
                return((T_COM_Master_LocationCollection)obj2);
            }
            using (var client = WebApiHelper.myclient(HouseEndpoint, SystemConst.APIJosonReturnValue))
            {
                //HttpResponseMessage response = client.GetAsync(Resource).GetAwaiter().GetResult();
                HttpResponseMessage response = client.GetAsync(string.Format(Resource + "?EntityID={0}&method=1", EntityID)).GetAwaiter().GetResult();

                if (response.IsSuccessStatusCode)
                {
                    items = response.Content.ReadAsAsync <T_COM_Master_LocationCollection>().GetAwaiter().GetResult();
                }
            }
            HttpCache.Max(key, items);
            return(items);
        }
Пример #8
0
        public void SetToCache(string key, object obj, HttpCache expiraton)
        {
            if (_cache == null || key == null)
            {
                return;
            }

            lock (GetFromCacheLocker)
            {
                if (obj != null)
                {
                    _cache.Insert(
                        key, obj, null,
                        DateTime.Now.Add(GetExpirationTimeSpan(expiraton)),
                        System.Web.Caching.Cache.NoSlidingExpiration
                        );
                }
                else
                {
                    _cache.Remove(key);
                }
            }
        }
Пример #9
0
    public async Task TimeoutUseStale()
    {
        HttpClient httpClient = new()
        {
            Timeout = TimeSpan.FromMilliseconds(1)
        };

        httpCache = new(CachePath, httpClient);
        httpCache.Purge();
        var uri = "https://httpbin.org/delay/1";

        #region AddItem

        using HttpResponseMessage response = new(HttpStatusCode.OK)
              {
                  Content = new StringContent("the content")
              };
        await httpCache.AddItemAsync(uri, response);

        #endregion

        await Verifier.Verify(httpCache.DownloadAsync(uri, true));
    }
Пример #10
0
        public static PositionRCollection GetPositionRange(int EntityID)
        {
            PositionRCollection items = new PositionRCollection();
            string key = SETTINGS_ALL_KEY;

            //object obj2 = HttpCache.Get(key);

            //if ((obj2 != null))
            //{
            //    return (PositionRCollection)obj2;
            //}
            using (var client = WebApiHelper.myclient(HouseEndpoint, SystemConst.APIJosonReturnValue))
            {
                HttpResponseMessage response = client.GetAsync(string.Format(Resource + "?EntityID={0}&Mode=0", EntityID)).GetAwaiter().GetResult();

                if (response.IsSuccessStatusCode)
                {
                    items = response.Content.ReadAsAsync <PositionRCollection>().GetAwaiter().GetResult();
                }
            }
            HttpCache.Max(key, items);
            return(items);
        }
        public static T_CMS_Master_EmploymentSubTypeCollection GetAllByEmpTypeID(int EmpTypeID)
        {
            T_CMS_Master_EmploymentSubTypeCollection items = new T_CMS_Master_EmploymentSubTypeCollection();

            string key  = String.Format(SETTINGS_User_KEY, EmpTypeID);
            object obj2 = HttpCache.Get(key);

            if ((obj2 != null))
            {
                return((T_CMS_Master_EmploymentSubTypeCollection)obj2);
            }
            using (var client = WebApiHelper.myclient(HouseEndpoint, SystemConst.APIJosonReturnValue))
            {
                HttpResponseMessage response = client.GetAsync(string.Format(Resource + "/GetAllByEmpType?EmpTypeID={0}&ev=", EmpTypeID)).GetAwaiter().GetResult();

                if (response.IsSuccessStatusCode)
                {
                    items = response.Content.ReadAsAsync <T_CMS_Master_EmploymentSubTypeCollection>().GetAwaiter().GetResult();
                }
            }
            HttpCache.Max(key, items);
            return(items);
        }
        public static T_COM_Master_UniversityCollection GetAllByUser(string CreatedUser)
        {
            T_COM_Master_UniversityCollection items = new T_COM_Master_UniversityCollection();

            string key  = String.Format(SETTINGS_User_KEY, CreatedUser);
            object obj2 = HttpCache.Get(key);

            if ((obj2 != null))
            {
                return((T_COM_Master_UniversityCollection)obj2);
            }
            using (var client = WebApiHelper.myclient(HouseEndpoint, SystemConst.APIJosonReturnValue))
            {
                HttpResponseMessage response = client.GetAsync(string.Format(Resource + "/GetbyUser?usr={0}", CreatedUser)).GetAwaiter().GetResult();

                if (response.IsSuccessStatusCode)
                {
                    items = response.Content.ReadAsAsync <T_COM_Master_UniversityCollection>().GetAwaiter().GetResult();
                }
            }
            HttpCache.Max(key, items);
            return(items);
        }
Пример #13
0
        public static ScanTimeApprovalCollection GetAllByUser(string createdUser)
        {
            ScanTimeApprovalCollection items = new ScanTimeApprovalCollection();

            string key  = String.Format(SETTINGS_User_KEY, createdUser);
            object obj2 = HttpCache.Get(key);

            if ((obj2 != null))
            {
                return((ScanTimeApprovalCollection)obj2);
            }
            using (var client = WebApiHelper.myclient(HouseEndpoint, SystemConst.APIJosonReturnValue))
            {
                HttpResponseMessage response = client.GetAsync(Resource + $"/GetbyUser?usr={createdUser}").GetAwaiter().GetResult();

                if (response.IsSuccessStatusCode)
                {
                    items = response.Content.ReadAsAsync <ScanTimeApprovalCollection>().GetAwaiter().GetResult();
                }
            }
            HttpCache.Max(key, items);
            return(items);
        }
Пример #14
0
        /// <summary>
        /// Get DNH template by Company
        /// </summary>
        /// <param name="messageTemplateName"></param>
        /// <param name="CompanyID"></param>
        /// <returns></returns>
        public static DNHMessageTemplate GetMessageTemplateByName(string messageTemplateName, int CompanyID)
        {
            string key  = String.Format(SETTINGS_ID_KEY, messageTemplateName, CompanyID);
            object obj2 = HttpCache.Get(key);

            if (obj2 != null)
            {
                return((DNHMessageTemplate)obj2);
            }

            DNHMessageTemplate b = new DNHMessageTemplate();

            using (var client = WebApiHelper.myclient(HouseEndpoint, SystemConst.APIJosonReturnValue))
            {
                HttpResponseMessage response = client.GetAsync(string.Format(Resource + "?Temp={0}&CompanyID={1}&temp=", messageTemplateName, CompanyID)).GetAwaiter().GetResult();

                if (response.IsSuccessStatusCode)
                {
                    b = response.Content.ReadAsAsync <DNHMessageTemplate>().GetAwaiter().GetResult();
                }
            }
            HttpCache.Max(key, b);
            return(b);
        }
Пример #15
0
        public static UsersInRoles GetById(String id, int CompanyID)
        {
            string key  = String.Format(SETTINGS_ID_KEY, id, CompanyID);
            object obj2 = HttpCache.Get(key);

            if (obj2 != null)
            {
                return((UsersInRoles)obj2);
            }

            UsersInRoles b = new UsersInRoles();

            using (var client = WebApiHelper.myclient(HouseEndpoint, SystemConst.APIJosonReturnValue))
            {
                HttpResponseMessage response = client.GetAsync(string.Format(Resource + "?Username={0}", id)).GetAwaiter().GetResult();

                if (response.IsSuccessStatusCode)
                {
                    b = response.Content.ReadAsAsync <UsersInRoles>().GetAwaiter().GetResult();
                }
            }
            HttpCache.Max(key, b);
            return(b);
        }
Пример #16
0
        public static hrm_atd_ScanTime GetById(string[] id, string[] select, string[] manual_in, string[] manual_out, string[] requestor_note, string Event)
        {
            string key  = String.Format(SETTINGS_ID_KEY, id);
            object obj2 = HttpCache.Get(key);

            if (obj2 != null)
            {
                return((hrm_atd_ScanTime)obj2);
            }

            hrm_atd_ScanTime b = new hrm_atd_ScanTime();

            using (var client = WebApiHelper.myclient(HouseEndpoint, SystemConst.APIJosonReturnValue))
            {
                HttpResponseMessage response = client.GetAsync(string.Format(Resource + "?ID={0}", id)).GetAwaiter().GetResult();

                if (response.IsSuccessStatusCode)
                {
                    b = response.Content.ReadAsAsync <hrm_atd_ScanTime>().GetAwaiter().GetResult();
                }
            }
            HttpCache.Max(key, b);
            return(b);
        }
Пример #17
0
        public static ScheduleTask GetByType(string Type, int CompanyID)
        {
            string key  = String.Format(SETTINGS_Type_KEY, Type, CompanyID);
            object obj2 = HttpCache.Get(key);

            if (obj2 != null)
            {
                return((ScheduleTask)obj2);
            }

            ScheduleTask b = new ScheduleTask();

            using (var client = WebApiHelper.myclient(HouseEndpoint, SystemConst.APIJosonReturnValue))
            {
                HttpResponseMessage response = client.GetAsync(string.Format(Resource + "?Type={0}&CompanyID={1}", Type, CompanyID)).GetAwaiter().GetResult();

                if (response.IsSuccessStatusCode)
                {
                    b = response.Content.ReadAsAsync <ScheduleTask>().GetAwaiter().GetResult();
                }
            }
            HttpCache.Max(key, b);
            return(b);
        }
Пример #18
0
        public static T_COM_Master_Degree GetById(int id)
        {
            string key  = String.Format(SETTINGS_ID_KEY, id);
            object obj2 = HttpCache.Get(key);

            if (obj2 != null)
            {
                return((T_COM_Master_Degree)obj2);
            }

            T_COM_Master_Degree b = new T_COM_Master_Degree();

            using (var client = WebApiHelper.myclient(HouseEndpoint, SystemConst.APIJosonReturnValue))
            {
                HttpResponseMessage response = client.GetAsync(string.Format(Resource + "?DegreeID={0}", id)).GetAwaiter().GetResult();

                if (response.IsSuccessStatusCode)
                {
                    b = response.Content.ReadAsAsync <T_COM_Master_Degree>().GetAwaiter().GetResult();
                }
            }
            HttpCache.Max(key, b);
            return(b);
        }
Пример #19
0
        public static ScanTimeApproval GetById(Guid id)
        {
            string key  = String.Format(SETTINGS_ID_KEY, id);
            object obj2 = HttpCache.Get(key);

            if (obj2 != null)
            {
                return((ScanTimeApproval)obj2);
            }

            ScanTimeApproval b = new ScanTimeApproval();

            using (var client = WebApiHelper.myclient(HouseEndpoint, SystemConst.APIJosonReturnValue))
            {
                HttpResponseMessage response = client.GetAsync(Resource + $"?ID={id}").GetAwaiter().GetResult();

                if (response.IsSuccessStatusCode)
                {
                    b = response.Content.ReadAsAsync <ScanTimeApproval>().GetAwaiter().GetResult();
                }
            }
            HttpCache.Max(key, b);
            return(b);
        }
Пример #20
0
        public static ls_PayrollDOWS_RBVH GetById(int id)
        {
            string key  = String.Format(SETTINGS_ID_KEY, id);
            object obj2 = HttpCache.Get(key);

            if (obj2 != null)
            {
                return((ls_PayrollDOWS_RBVH)obj2);
            }

            ls_PayrollDOWS_RBVH b = new ls_PayrollDOWS_RBVH();

            using (var client = WebApiHelper.myclient(HouseEndpoint, SystemConst.APIJosonReturnValue))
            {
                HttpResponseMessage response = client.GetAsync(string.Format(Resource + "?id={0}&action=getid", id)).GetAwaiter().GetResult();

                if (response.IsSuccessStatusCode)
                {
                    b = response.Content.ReadAsAsync <ls_PayrollDOWS_RBVH>().GetAwaiter().GetResult();
                }
            }
            HttpCache.Max(key, b);
            return(b);
        }
        public static RBVHEmployee GetByDomainId(string DomainId)
        {
            string key  = String.Format(SETTINGS_Domain_KEY, DomainId);
            object obj2 = HttpCache.Get(key);

            if (obj2 != null)
            {
                return((RBVHEmployee)obj2);
            }

            RBVHEmployee b = new RBVHEmployee();

            using (var client = WebApiHelper.myclient(HouseEndpoint, SystemConst.APIJosonReturnValue))
            {
                HttpResponseMessage response = client.GetAsync(string.Format(Resource + "?DomainId={0}", DomainId)).GetAwaiter().GetResult();

                if (response.IsSuccessStatusCode)
                {
                    b = response.Content.ReadAsAsync <RBVHEmployee>().GetAwaiter().GetResult();
                }
            }
            HttpCache.Max(key, b);
            return(b);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="UniversityName"></param>
        /// <returns></returns>
        public static T_COM_Master_University GetByName(string UniversityName)
        {
            string key  = String.Format(SETTINGS_ID_Name, UniversityName);
            object obj2 = HttpCache.Get(key);

            if (obj2 != null)
            {
                return((T_COM_Master_University)obj2);
            }

            T_COM_Master_University b = new T_COM_Master_University();

            using (var client = WebApiHelper.myclient(HouseEndpoint, SystemConst.APIJosonReturnValue))
            {
                HttpResponseMessage response = client.GetAsync(string.Format(Resource + "?UniversityName={0}&ev=e", UniversityName)).GetAwaiter().GetResult();

                if (response.IsSuccessStatusCode)
                {
                    b = response.Content.ReadAsAsync <T_COM_Master_University>().GetAwaiter().GetResult();
                }
            }
            HttpCache.Max(key, b);
            return(b);
        }
Пример #23
0
        public static T_COm_Master_Org GetByOrgName(string OrgName)
        {
            string key  = String.Format(SETTINGS_User_KEY, OrgName);
            object obj2 = HttpCache.Get(key);

            if (obj2 != null)
            {
                return((T_COm_Master_Org)obj2);
            }

            T_COm_Master_Org b = new T_COm_Master_Org();

            using (var client = WebApiHelper.myclient(HouseEndpoint, SystemConst.APIJosonReturnValue))
            {
                HttpResponseMessage response = client.GetAsync(string.Format(Resource + "/GetbyUser?usr={0}", OrgName)).GetAwaiter().GetResult();

                if (response.IsSuccessStatusCode)
                {
                    b = response.Content.ReadAsAsync <T_COm_Master_Org>().GetAwaiter().GetResult();
                }
            }
            HttpCache.Max(key, b);
            return(b);
        }
Пример #24
0
        public static SiteMap GetById(Guid id, int CompanyID)
        {
            string key  = String.Format(SETTINGS_ID_KEY, id, CompanyID);
            object obj2 = HttpCache.Get(key);

            if (obj2 != null)
            {
                return((SiteMap)obj2);
            }

            SiteMap b = new SiteMap();

            using (var client = WebApiHelper.myclient(HouseEndpoint, SystemConst.APIJosonReturnValue))
            {
                HttpResponseMessage response = client.GetAsync(string.Format(Resource + "?NodeID={0}&CompanyID={1}", id, CompanyID)).GetAwaiter().GetResult();

                if (response.IsSuccessStatusCode)
                {
                    b = response.Content.ReadAsAsync <SiteMap>().GetAwaiter().GetResult();
                }
            }
            HttpCache.Max(key, b);
            return(b);
        }
        public static Contract GetbyEmpCode(int EmployeeCode)
        {
            string key  = String.Format(SETTINGS_EmployeeCode_KEY, EmployeeCode);
            object obj2 = HttpCache.Get(key);

            if (obj2 != null)
            {
                return((Contract)obj2);
            }

            Contract b = new Contract();

            using (var client = WebApiHelper.myclient(HouseEndpoint, SystemConst.APIJosonReturnValue))
            {
                HttpResponseMessage response = client.GetAsync(string.Format(Resource + "?EmployeeCode={0}", EmployeeCode)).GetAwaiter().GetResult();

                if (response.IsSuccessStatusCode)
                {
                    b = response.Content.ReadAsAsync <Contract>().GetAwaiter().GetResult();
                }
            }
            HttpCache.Max(key, b);
            return(b);
        }
Пример #26
0
 public void Init()
 {
     cache = new HttpCache();
 }
Пример #27
0
        public override Task <ResponseDisposeHandling> ProcessResponse(JsonOperationContext context, HttpCache cache, HttpResponseMessage response, string url)
        {
            if (response.StatusCode == HttpStatusCode.NotModified)
            {
                Result = _changeVector;
                return(Task.FromResult(ResponseDisposeHandling.Automatic));;
            }

            if (response.StatusCode == HttpStatusCode.NotFound)
            {
                Result = null;
                return(Task.FromResult(ResponseDisposeHandling.Automatic));
            }

            Result = response.GetRequiredEtagHeader();
            return(Task.FromResult(ResponseDisposeHandling.Automatic));
        }
Пример #28
0
            public override async Task <ResponseDisposeHandling> ProcessResponse(JsonOperationContext context, HttpCache cache, HttpResponseMessage response, string url)
            {
                using (var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
                {
                    await _handleStreamResponse(stream).ConfigureAwait(false);
                }

                return(ResponseDisposeHandling.Automatic);
            }
Пример #29
0
 public RavenCommand GetCommand(IDocumentStore store, DocumentConventions conventions, JsonOperationContext context, HttpCache cache)
 {
     return(new DeleteAttachmentCommand(_documentId, _name, _changeVector));
 }
Пример #30
0
        private void MockSecurityStorage()
        {
            var context = this.mockSecurityDataContext.Object;

            Func<ISecurityDataContext> createSecurityDataContext = () => { return context; };

            var dbsecurityStorage = new DatabaseSecurityStorage(createSecurityDataContext);
            var cachePrvoider = new HttpCache();
            this.securityStorage = new CachedSecurityStorage(dbsecurityStorage, cachePrvoider);
        }
Пример #31
0
 public HttpCacheTests()
 {
     httpCache = new(CachePath);
     httpCache.Purge();
 }
Пример #32
0
 public RavenCommand <CountersDetail> GetCommand(IDocumentStore store, DocumentConventions conventions, JsonOperationContext context, HttpCache cache)
 {
     return(new CounterBatchCommand(_counterBatch));
 }
Пример #33
0
 public RavenCommand <JsonPatchResult> GetCommand(IDocumentStore store, DocumentConventions conventions, JsonOperationContext context, HttpCache cache)
 {
     return(new JsonPatchCommand(Id, JsonPatchDocument));
 }
Пример #34
0
 public RavenCommand <string> GetCommand(IDocumentStore store, DocumentConventions conventions, JsonOperationContext context, HttpCache cache)
 {
     return(this);
 }