예제 #1
0
        public static List <PropertyModel> GetProperties(string accountNameKey, PropertyListType propertyListType, out ExecutionType executionTypeResult)
        {
            List <PropertyModel> properties = null;

            executionTypeResult = ExecutionType.redis_main;


            #region (Plan A) Get data from Redis Cache

            try
            {
                IDatabase cache = CoreServices.RedisConnectionMultiplexers.RedisMultiplexer.GetDatabase();

                string hashMainKey   = accountNameKey + ":properties";
                string hashMainField = propertyListType.ToString().ToLower();

                try
                {
                    var redisValue = cache.HashGet(hashMainKey, hashMainField);

                    if (redisValue.HasValue)
                    {
                        properties          = JsonConvert.DeserializeObject <List <PropertyModel> >(redisValue);
                        executionTypeResult = ExecutionType.redis_main;
                    }
                }
                catch
                {
                }
            }
            catch (Exception e)
            {
                var error = e.Message;
                //TODO: Log: error message for Redis call
            }

            #endregion

            if (properties == null)
            {
                #region (Plan D) Get data from WCF

                var applicationPropertiesServiceClient = new ApplicationPropertiesService.ApplicationPropertiesServiceClient();

                try
                {
                    applicationPropertiesServiceClient.Open();

                    properties = applicationPropertiesServiceClient.GetProperties(accountNameKey, propertyListType, Common.SharedClientKey).ToList();

                    executionTypeResult = ExecutionType.wcf;

                    WCFManager.CloseConnection(applicationPropertiesServiceClient);
                }
                catch (Exception e)
                {
                    #region Manage Exception

                    string exceptionMessage = e.Message.ToString();

                    var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                    string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                    // Abort the connection & manage the exception
                    WCFManager.CloseConnection(applicationPropertiesServiceClient, exceptionMessage, currentMethodString);

                    #endregion
                }

                #endregion
            }

            return(properties);
        }
예제 #2
0
        internal static List <string> GetSearchFields(string accountNameKey, PropertyListType propertyListType)
        {
            List <string> searchFields = null;

            string localCacheKey = accountNameKey + ":searchFields:" + propertyListType.ToString().ToLower();

            #region (Plan A) Get search fields list from local cache

            try
            {
                searchFields = (List <string>)HttpRuntime.Cache[localCacheKey];
            }
            catch (Exception e)
            {
                var error = e.Message;
                //TODO: Log: error message for local cache call
            }

            #endregion

            if (searchFields == null)
            {
                #region (Plan B) Get from second layer of Redis Cache

                IDatabase cache = CoreServices.RedisConnectionMultiplexers.RedisMultiplexer.GetDatabase();

                string hashApiKey   = accountNameKey + ":apicache";
                string hashApiField = "searchFields:" + propertyListType.ToString().ToLower();

                try
                {
                    var redisApiValue = cache.HashGet(hashApiKey, hashApiField);

                    if (redisApiValue.HasValue)
                    {
                        searchFields = JsonConvert.DeserializeObject <List <string> >(redisApiValue);
                    }
                }
                catch
                {
                }

                #endregion

                if (searchFields == null)
                {
                    #region (Plan C) Get Fresh Set of Properties and Rebuild

                    #region Build fresh version of searchFieldList using properties list from Redis Cache or WCF

                    ExecutionType executionTypeResults;
                    var           properties = DataAccess.Properties.GetProperties(accountNameKey, propertyListType, out executionTypeResults);

                    searchFields = new List <string>();

                    #region Build Global Fields

                    searchFields.Add("id");
                    searchFields.Add("name");
                    searchFields.Add("nameKey");

                    searchFields.Add("locationPath");
                    searchFields.Add("fullyQualifiedName");

                    searchFields.Add("categoryName");
                    searchFields.Add("categoryNameKey");

                    searchFields.Add("subcategoryName");
                    searchFields.Add("subcategoryNameKey");

                    searchFields.Add("subsubcategoryName");
                    searchFields.Add("subsubcategoryNameKey");

                    searchFields.Add("subsubsubcategoryName");
                    searchFields.Add("subsubsubcategoryNameKey");

                    searchFields.Add("orderId");

                    #endregion

                    #region Add Custom Fields

                    foreach (PropertyModel property in properties)
                    {
                        searchFields.Add(property.SearchFieldName);

                        if (property.PropertyTypeNameKey == "location")
                        {
                            searchFields.Add(property.SearchFieldName + "LocationMetadata"); //<-- Add LocationMetadata
                        }
                    }

                    #endregion

                    #endregion

                    #endregion

                    try
                    {
                        //Cache on Secondary/ APIRedis:
                        cache.HashSet(hashApiKey, hashApiField, JsonConvert.SerializeObject(searchFields), When.Always, CommandFlags.FireAndForget);
                    }
                    catch
                    {
                    }
                }

                //Cache Localy
                HttpRuntime.Cache.Insert(localCacheKey, searchFields, null, DateTime.Now.AddMinutes(Common.SearchFieldsCacheTimeInMinutes), TimeSpan.Zero);
            }


            return(searchFields);
        }