Beispiel #1
0
        private bool isNewTimePeriod(DateTime utcNow)
        {
            /* The last time of consumed message */

            string lastTimestampOfConsumedMsg = _redisCacheHelper.GetValueByKey(_cachekey_message_consumed_date);

            if (lastTimestampOfConsumedMsg == null)
            {
                _consoleLog.Info("Redis Cache {0} was NOT found", _cachekey_message_consumed_date.ToString());
                _consoleLog.BlobLogInfo("Redis Cache {0} was NOT found", _cachekey_message_consumed_date.ToString());
                // THIS IS A NEW DAY!
                return(true);
            }
            else
            {
                DateTime lastTimestamp = DateTime.Parse((string)lastTimestampOfConsumedMsg);
                /* The period is 1 day */
                DateTime timeup = DateTime.Parse(lastTimestamp.AddDays(1).ToString("yyyy-MM-ddT00:00:00.000"));
                /* This is a sample for that the period is 1 minute */
                //DateTime timeup = DateTime.Parse(lastTimestamp.AddMinutes(1).ToString("yyyy-MM-ddTHH:mm:00.000"));

                if (DateTime.Compare(utcNow, timeup) >= 0)
                {
                    // THIS IS A NEW DAY!
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Beispiel #2
0
        public IHttpActionResult GetCompanyById(int id)
        {
            RedisKey cacheKey   = "company_" + id;
            string   cacheValue = null;

            if (Global._enableRedisCache)
            {
                cacheValue = RedisCacheHelper.GetValueByKey(cacheKey);
            }
            if (cacheValue == null)
            {
                CompanyModel companyModel = new CompanyModel();
                try
                {
                    CompanyModel.Format_Detail company = companyModel.GetById(id);
                    //RedisCacheHelper.SetKeyValue(cacheKey, JsonConvert.SerializeObject(company));
                    return(Content(HttpStatusCode.OK, company));
                }
                catch (CDSException cdsEx)
                {
                    return(Content(HttpStatusCode.BadRequest, CDSException.GetCDSErrorMessageByCode(cdsEx.ErrorId)));
                }
                catch (Exception ex)
                {
                    return(Content(HttpStatusCode.InternalServerError, ex));
                }
            }
            else
            {
                return(Content(HttpStatusCode.OK, JsonConvert.DeserializeObject(cacheValue)));
            }
        }
Beispiel #3
0
        public HttpResponseMessage GetAllowDomainByCompanyId(int id)
        {
            RedisKey cacheKey   = "company_" + id + "_allowDomain";
            string   cacheValue = null;

            if (Global._enableRedisCache)
            {
                cacheValue = RedisCacheHelper.GetValueByKey(cacheKey);
            }

            if (cacheValue == null)
            {
                CompanyModel companyModel = new Models.CompanyModel();
                try
                {
                    CompanyModel.Format_Detail company = companyModel.GetById(id);
                    //RedisCacheHelper.SetKeyValue(cacheKey, new JavaScriptSerializer().Serialize(company));
                    return(Request.CreateResponse(HttpStatusCode.OK, company.AllowDomain));
                }
                catch (CDSException cdsEx)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, CDSException.GetCDSErrorMessageByCode(cdsEx.ErrorId)));
                }
                catch (Exception ex)
                {
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex));
                }
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.OK, JsonConvert.DeserializeObject <CompanyModel.Format_Detail>(cacheValue).AllowDomain));
            }
        }
        public IHttpActionResult GetEmployeeById(int id)
        {
            RedisKey cacheKey   = "employee_" + id;
            string   cacheValue = null;

            if (Global._enableRedisCache)
            {
                cacheValue = RedisCacheHelper.GetValueByKey(cacheKey);
            }

            if (cacheValue == null)
            {
                try
                {
                    EmployeeModel model    = new EmployeeModel();
                    var           employee = model.GetById(id);
                    //RedisCacheHelper.SetKeyValue(cacheKey, new JavaScriptSerializer().Serialize(employee));
                    return(Content(HttpStatusCode.OK, employee));
                }
                catch (CDSException cdsEx)
                {
                    return(Content(HttpStatusCode.BadRequest, CDSException.GetCDSErrorMessageByCode(cdsEx.ErrorId)));
                }
                catch (Exception ex)
                {
                    return(Content(HttpStatusCode.InternalServerError, ex));
                }
            }
            else
            {
                return(Ok(JsonConvert.DeserializeObject <Object>(cacheValue)));
            }
        }
        public IHttpActionResult GetRolesByEmployeeId(int id)
        {
            RedisKey cacheKey   = "employee_" + id + "_Role";
            string   cacheValue = null;

            if (Global._enableRedisCache)
            {
                cacheValue = RedisCacheHelper.GetValueByKey(cacheKey);
            }

            if (cacheValue == null)
            {
                try
                {
                    EmployeeInRoleModel model = new EmployeeInRoleModel();
                    model.GetAllByEmployeeId(id);
                    return(Content(HttpStatusCode.OK, model.GetAllByEmployeeId(id)));
                }
                catch (CDSException cdsEx)
                {
                    return(Content(HttpStatusCode.BadRequest, CDSException.GetCDSErrorMessageByCode(cdsEx.ErrorId)));
                }
                catch (Exception ex)
                {
                    return(Content(HttpStatusCode.InternalServerError, ex));
                }
            }
            else
            {
                return(Content(HttpStatusCode.OK, JsonConvert.DeserializeObject <List <Object> >(cacheValue)));
            }
        }
        public IHttpActionResult GetRolesByEmployeeId(int id)
        {
            RedisKey cacheKey   = "employee_" + id + "_Role";
            string   cacheValue = RedisCacheHelper.GetValueByKey(cacheKey);

            if (cacheValue == null)
            {
                using (var ctx = new SFDatabaseEntities())
                {
                    var roles = ctx.EmployeeInRole
                                .Where(s => s.EmployeeID == id && s.DeletedFlag == false)
                                .Select(s => new EmployeeRoleModels.Detail()
                    {
                        UserRoleId   = s.UserRoleID,
                        UserRoleName = s.UserRole.Name
                    }).ToList <EmployeeRoleModels.Detail>();

                    RedisCacheHelper.SetKeyValue(cacheKey, new JavaScriptSerializer().Serialize(roles));
                    return(Ok(roles));
                }
            }
            else
            {
                return(Ok(new JavaScriptSerializer().Deserialize <List <Object> >(cacheValue)));
            }
        }
        public IHttpActionResult GetCompanyById()
        {
            int      companyId  = GetCompanyIdFromToken();
            RedisKey cacheKey   = "external_company_" + companyId;
            string   cacheValue = RedisCacheHelper.GetValueByKey(cacheKey);

            if (cacheValue == null)
            {
                CompanyModels companyModel = new CompanyModels();
                try
                {
                    CompanyModels.Detail_readonly company = companyModel.getCompanyByIdReadonly(Convert.ToInt32(companyId.ToString()));
                    RedisCacheHelper.SetKeyValue(cacheKey, JsonConvert.SerializeObject(company));
                    return(Ok(company));
                }
                catch (Exception ex)
                {
                    StringBuilder logMessage = LogUtility.BuildExceptionMessage(ex);
                    string        logAPI     = "[Get] " + Request.RequestUri.ToString();
                    Startup._sfAppLogger.Error(logAPI + logMessage);

                    return(InternalServerError());
                }
            }
            else
            {
                return(Ok(new JavaScriptSerializer().Deserialize <Object>(cacheValue)));
            }
        }
Beispiel #8
0
        public IHttpActionResult GetAllDeviceTypes()
        {
            string cacheValue = RedisCacheHelper.GetValueByKey(cacheKey);

            if (string.IsNullOrEmpty(cacheValue) || cacheValue.Length < 10)
            {
                DeviceTypeModels deviceTypeModel = new Models.DeviceTypeModels();
                List <DeviceTypeModels.Detail> deviceTypeList = deviceTypeModel.GetAllDeviceType();
                RedisCacheHelper.SetKeyValue(cacheKey, new JavaScriptSerializer().Serialize(deviceTypeList));
                return(Ok(deviceTypeList));
            }
            else
            {
                return(Ok(new JavaScriptSerializer().Deserialize <Object>(cacheValue)));
            }
        }
        public IHttpActionResult GetPermissionsByEmployeeId(int id)
        {
            RedisKey cacheKey   = "employee_" + id + "_Permission";
            string   cacheValue = RedisCacheHelper.GetValueByKey(cacheKey);

            if (cacheValue == null)
            {
                EmployeeModels employeeModel  = new EmployeeModels();
                var            empPermissions = employeeModel.GetAllPermissionById(id);
                RedisCacheHelper.SetKeyValue(cacheKey, new JavaScriptSerializer().Serialize(empPermissions));
                return(Ok(empPermissions));
            }
            else
            {
                return(Ok(new JavaScriptSerializer().Deserialize <List <Object> >(cacheValue)));
            }
        }
Beispiel #10
0
        public IHttpActionResult GetAll()
        {
            RedisKey cacheKey   = "cultureCodesJson";
            string   cacheValue = null;

            if (Global._enableRedisCache)
            {
                cacheValue = RedisCacheHelper.GetValueByKey(cacheKey);
            }
            if (cacheValue == null)
            {
                RefCultureInfoModel model = new RefCultureInfoModel();
                return(Ok(model.GetAll()));
            }
            else
            {
                return(Ok(JsonConvert.DeserializeObject(cacheValue)));
                //return Ok(new JavaScriptSerializer().Deserialize<List<RefCultureInfoModels>>(cacheValue));
            }
        }
Beispiel #11
0
        public IHttpActionResult GetCompanyById(int id)
        {
            RedisKey cacheKey   = "company_" + id;
            string   cacheValue = RedisCacheHelper.GetValueByKey(cacheKey);

            if (cacheValue == null)
            {
                CompanyModels companyModel = new CompanyModels();
                try
                {
                    CompanyModels.Detail company = companyModel.getCompanyById(id);
                    RedisCacheHelper.SetKeyValue(cacheKey, new JavaScriptSerializer().Serialize(company));
                    return(Ok(company));
                }
                catch
                {
                    return(NotFound());
                }
            }
            else
            {
                return(Ok(new JavaScriptSerializer().Deserialize <Object>(cacheValue)));
            }
        }
Beispiel #12
0
        public IHttpActionResult GetEmployeeById(int id)
        {
            RedisKey cacheKey   = "employee_" + id;
            string   cacheValue = RedisCacheHelper.GetValueByKey(cacheKey);

            if (cacheValue == null)
            {
                EmployeeModels employeeMode = new EmployeeModels();
                try
                {
                    var employee = employeeMode.GetEmployeeById(id);
                    RedisCacheHelper.SetKeyValue(cacheKey, new JavaScriptSerializer().Serialize(employee));
                    return(Ok(employee));
                }
                catch
                {
                    return(NotFound());
                }
            }
            else
            {
                return(Ok(new JavaScriptSerializer().Deserialize <Object>(cacheValue)));
            }
        }
Beispiel #13
0
        public IHttpActionResult GetAll()
        {
            RedisKey cacheKey   = "cultureCodesJson";
            string   cacheValue = RedisCacheHelper.GetValueByKey(cacheKey);

            if (cacheValue == null)
            {
                using (var ctx = new SFDatabaseEntities())
                {
                    var cultureCodes = ctx.RefCultureInfo
                                       .Select(s => new RefCultureInfoModels()
                    {
                        CultureCode = s.CultureCode,
                        Name        = s.Name
                    }).ToList <RefCultureInfoModels>();
                    RedisCacheHelper.SetKeyValue(cacheKey, new JavaScriptSerializer().Serialize(cultureCodes));
                    return(Ok(cultureCodes));
                }
            }
            else
            {
                return(Ok(new JavaScriptSerializer().Deserialize <List <RefCultureInfoModels> >(cacheValue)));
            }
        }