Beispiel #1
0
        private void ProcessCrmTerms(PropertyListType lst)
        {
            var termsType = _ctx.ValueTypes.First(x => x.Name == lst.Type);

            foreach (var source in lst.Items)
            {
                var target = _ctx.Values.FirstOrDefault(t => t.ListPropertyId == source.Guid);
                if (target == null)
                {
                    target = new ListProperty
                    {
                        ListPropertyId = source.Guid,
                        Value          = source.Value,
                        IsFromCrm      = true
                    };
                    _ctx.Values.Add(target);
                }
                else
                {
                    target.Value = source.Value;
                }
                target.Types.Add(termsType);

                UpdateUrlsFromService(target, source);
            }
        }
Beispiel #2
0
        public void ProcessListProperty(PropertyListType lst)
        {
            if (lst.Type == "meeting")
            {
                ProcessCrmMeetings(lst);
            }
            else if (lst.Type == "term")
            {
                ProcessCrmTerms(lst);
            }
            else
            {
                ProcessList(lst);
            }


            using (var trans = _ctx.Database.BeginTransaction())
            {
                try
                {
                    _ctx.SaveChanges();
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();

                    ClassLogger.Error($"ProcessListProperty {ex.Message} {lst.Type}");
                    throw;
                }
            }
        }
Beispiel #3
0
        private void ProcessCrmMeetings(PropertyListType lst)
        {
            var meetingsType = _ctx.ValueTypes.FirstOrDefault(x => x.Name == lst.Type);

            var serviceMeetings = _parent.Conferences.Meetings;

            foreach (var source in lst.Items)
            {
                Meetings meetingInService;
                serviceMeetings.TryGetValue(source.Guid, out meetingInService);
                if (meetingInService == null)
                {
                    ClassLogger.Warn(
                        $"Not found {source.Guid} ({source.Value}) in the service {_parent.Conferences.ServiceUri}");
                }

                var url    = meetingInService != null? $"{_parent.Conferences.ServiceUri}/Meetings(guid'{source.Guid}')":null;
                var target = _ctx.Values.FirstOrDefault(t => t.ListPropertyId == source.Guid);
                if (target == null)
                {
                    target = new ListProperty
                    {
                        ListPropertyId = source.Guid,
                        Value          = source.Value,
                        Url            = url,
                        IsFromCrm      = true
                    };
                    _ctx.Values.Add(target);
                }
                else
                {
                    target.Value = source.Value;
                    target.Url   = url;
                }

                target.Types.Add(meetingsType);
            }
        }
Beispiel #4
0
        private void ProcessList(PropertyListType lst)
        {
            var listType = _ctx.ValueTypes.First(x => x.Name == lst.Type);

            foreach (var source in lst.Items)
            {
                var target = _ctx.Values.OfType <ListProperty>().FirstOrDefault(t => t.ListPropertyId == source.Guid);
                if (target == null)
                {
                    target = new ListProperty
                    {
                        ListPropertyId = source.Guid,
                        Value          = source.Value,
                        IsFromCrm      = true
                    };
                    _ctx.Values.Add(target);
                }
                else
                {
                    target.Value = source.Value;
                }
                target.Types.Add(listType);
            }
        }
Beispiel #5
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);
        }
        private void AddPropertiesTranslations(XmlDocument doc, XmlNode root, PropertyListType type)
        {
            XmlNode contentTypes = doc.CreateElement("contenttypes");

            switch (type)
            {
            case PropertyListType.PageTypeGeneral:
                XmlNode pageData   = doc.CreateElement("icontentdata");
                XmlNode properties = doc.CreateElement("properties");
                pageData.AppendChild(properties);
                contentTypes.AppendChild(pageData);
                root.AppendChild(contentTypes);

                foreach (GridViewRow item in this.GeneralPropertiesViewControl.Rows)
                {
                    this._captionText = ((TextBox)item.FindControl("TxtPropCaption")).Text;
                    this._helpText    = ((TextBox)item.FindControl("TxtPropHelp")).Text;
                    this._propName    = ((Label)item.FindControl("LblProp")).Text;

                    XmlNode propertyNode = doc.CreateElement(this._propName.ToLower());

                    XmlNode caption = doc.CreateElement("caption");
                    caption.AppendChild(doc.CreateTextNode(this._captionText));
                    propertyNode.AppendChild(caption);

                    XmlNode helptext = doc.CreateElement("help");
                    helptext.AppendChild(doc.CreateTextNode(this._helpText));
                    propertyNode.AppendChild(helptext);

                    properties.AppendChild(propertyNode);
                }
                break;

            case PropertyListType.PageType:

                XmlNode pageTypeNode          = null;
                XmlNode pagePropertiesElement = null;

                foreach (GridViewRow item in this.PropertiesViewControl.Rows)
                {
                    this._captionText = ((TextBox)item.FindControl("TxtPropCaption")).Text;
                    this._helpText    = ((TextBox)item.FindControl("TxtPropHelp")).Text;
                    this._propName    = ((Label)item.FindControl("LblProp")).Text;
                    this._typeName    = ((Label)item.FindControl("LblTypeName")).Text;

                    if (!string.IsNullOrEmpty(this._typeName))
                    {
                        pageTypeNode          = doc.CreateElement(this._typeName);
                        pagePropertiesElement = doc.CreateElement("properties");
                        pageTypeNode.AppendChild(pagePropertiesElement);
                    }

                    XmlNode propertytypeNode = doc.CreateElement(this._propName);
                    if (pagePropertiesElement != null)
                    {
                        pagePropertiesElement.AppendChild(propertytypeNode);
                    }

                    XmlNode caption = doc.CreateElement("caption");
                    caption.AppendChild(doc.CreateTextNode(this._captionText));
                    propertytypeNode.AppendChild(caption);

                    XmlNode helptext = doc.CreateElement("help");
                    helptext.AppendChild(doc.CreateTextNode(this._helpText));
                    propertytypeNode.AppendChild(helptext);

                    contentTypes.AppendChild(pageTypeNode);
                }

                root.AppendChild(contentTypes);
                break;

            case PropertyListType.BlockGeneral:
                break;

            case PropertyListType.Block:

                XmlNode typeNode          = null;
                XmlNode propertiesElement = null;

                foreach (GridViewRow item in this.BlockPropertiesViewControl.Rows)
                {
                    this._captionText = ((TextBox)item.FindControl("TxtBlockPropCaption")).Text;
                    this._helpText    = ((TextBox)item.FindControl("TxtBlockPropDescription")).Text;
                    this._propName    = ((Label)item.FindControl("LblBlockPropertyName")).Text;
                    this._typeName    = ((Label)item.FindControl("LblBlockType")).Text;

                    if (!string.IsNullOrEmpty(this._typeName))
                    {
                        typeNode          = doc.CreateElement(this._typeName);
                        propertiesElement = doc.CreateElement("properties");
                        typeNode.AppendChild(propertiesElement);
                    }

                    XmlNode propertytypeNode = doc.CreateElement(this._propName);
                    if (propertiesElement != null)
                    {
                        propertiesElement.AppendChild(propertytypeNode);
                    }

                    XmlNode caption = doc.CreateElement("caption");
                    caption.AppendChild(doc.CreateTextNode(this._captionText));
                    propertytypeNode.AppendChild(caption);

                    XmlNode helptext = doc.CreateElement("help");
                    helptext.AppendChild(doc.CreateTextNode(this._helpText));
                    propertytypeNode.AppendChild(helptext);

                    contentTypes.AppendChild(typeNode);
                }

                root.AppendChild(contentTypes);

                break;
            }
        }
Beispiel #7
0
        public JsonNetResult GetProductProperties(string type, string filter = null)
        {
            ExecutionType executionType = ExecutionType.local;
            Stopwatch     stopWatch     = new Stopwatch();

            stopWatch.Start();

            //Get the subdomain (if exists) for the api call
            string accountNameKey = Common.GetSubDomain(Request.Url);

            if (String.IsNullOrEmpty(accountNameKey))
            {
                return(new JsonNetResult {
                    Data = "Not found"
                });                                              //return Request.CreateResponse(HttpStatusCode.NotFound);
            }

            List <PropertyModel> properties     = null;
            PropertiesResultJson propertiesJson = null;

            string           localCacheKey    = accountNameKey + ":properties:all";
            PropertyListType propertyListType = PropertyListType.All;

            if (!String.IsNullOrEmpty(type))
            {
                if (type == "listings" || type == "listing" || type == "list")
                {
                    localCacheKey    = accountNameKey + ":properties:listings";
                    propertyListType = PropertyListType.Listings;
                }
                else if (type == "details" || type == "detail")
                {
                    localCacheKey    = accountNameKey + ":properties:details";
                    propertyListType = PropertyListType.Details;
                }
                else if (type == "featured" || type == "feature")
                {
                    if (filter == "listingsOnly")
                    {
                        localCacheKey    = accountNameKey + ":properties:featured:listingsOnly";
                        propertyListType = PropertyListType.Featured;
                    }
                    else
                    {
                        localCacheKey    = accountNameKey + ":properties:featured";
                        propertyListType = PropertyListType.Featured;
                    }
                }
            }

            #region (Plan A) Get json from local cache

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

            #endregion

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

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

                string pathAndQuery = Common.GetApiPathAndQuery(Request.Url);

                string hashApiKey   = accountNameKey + ":apicache";
                string hashApiField = pathAndQuery;

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

                    if (redisApiValue.HasValue)
                    {
                        propertiesJson = JsonConvert.DeserializeObject <PropertiesResultJson>(redisApiValue);
                        executionType  = ExecutionType.redis_secondary;
                    }
                }
                catch
                {
                }


                #endregion

                if (propertiesJson == null)
                {
                    #region (Plan C) Get property data from Redis Cache or WCF and Rebuild

                    properties = DataAccess.Properties.GetProperties(accountNameKey, propertyListType, out executionType);

                    #endregion
                }

                #region Transform into json object, add images & cache locally or locally and radisAPI layer

                if (propertiesJson != null)
                {
                    //Just cache locally (we got json from the api redis layer)
                    HttpRuntime.Cache.Insert(localCacheKey, propertiesJson, null, DateTime.Now.AddMinutes(Common.PropertiesCacheTimeInMinutes), TimeSpan.Zero);
                }
                else if (properties != null)
                {
                    //Transform properties into JSON and cache BOTH locally AND into redis
                    propertiesJson = Transforms.Json.PropertyTransforms.Properties(accountNameKey, properties, filter);
                    HttpRuntime.Cache.Insert(localCacheKey, propertiesJson, null, DateTime.Now.AddMinutes(Common.PropertiesCacheTimeInMinutes), TimeSpan.Zero);
                    try
                    {
                        cache.HashSet(hashApiKey, hashApiField, JsonConvert.SerializeObject(propertiesJson), When.Always, CommandFlags.FireAndForget);
                    }
                    catch
                    {
                    }
                }

                #endregion
            }

            //Add execution data
            stopWatch.Stop();
            propertiesJson.executionType = executionType.ToString();
            propertiesJson.executionTime = stopWatch.Elapsed.TotalMilliseconds + "ms";

            JsonNetResult jsonNetResult = new JsonNetResult();
            jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
            jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
            jsonNetResult.Data = propertiesJson;

            return(jsonNetResult);
        }
Beispiel #8
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);
        }
        private void AddPropertiesTranslations(XmlDocument doc, XmlNode root, PropertyListType type)
        {
            XmlNode contentTypes = doc.CreateElement("contenttypes");

            switch (type)
            {
                case PropertyListType.PageTypeGeneral:

                    XmlNode pageData = doc.CreateElement("icontentdata");
                    XmlNode properties = doc.CreateElement("properties");
                    pageData.AppendChild(properties);
                    contentTypes.AppendChild(pageData);
                    root.AppendChild(contentTypes);

                    foreach (GridViewRow item in this.PropertiesViewControl.Rows)
                    {
                        this._captionText = ((TextBox)item.FindControl("TxtPropCaption")).Text;
                        this._helpText = ((TextBox)item.FindControl("TxtPropHelp")).Text;
                        this._propName = ((Label)item.FindControl("LblProp")).Text;

                        XmlNode propertyNode = doc.CreateElement(this._propName.ToLower());

                        XmlNode caption = doc.CreateElement("caption");
                        caption.AppendChild(doc.CreateTextNode(this._captionText));
                        propertyNode.AppendChild(caption);

                        XmlNode helptext = doc.CreateElement("help");
                        helptext.AppendChild(doc.CreateTextNode(this._helpText));
                        propertyNode.AppendChild(helptext);

                        properties.AppendChild(propertyNode);
                    }

                break;
                case PropertyListType.BlockGeneral:
                break;
                case PropertyListType.Block:

                    XmlNode typeNode = null;
                    XmlNode propertiesElement = null;

                    foreach (GridViewRow item in this.BlockPropertiesViewControl.Rows)
                    {
                        this._captionText = ((TextBox)item.FindControl("TxtBlockPropCaption")).Text;
                        this._helpText = ((TextBox)item.FindControl("TxtBlockPropDescription")).Text;
                        this._propName = ((Label)item.FindControl("LblBlockPropertyName")).Text;
                        this._typeName = ((Label)item.FindControl("LblBlockType")).Text;

                        if (!string.IsNullOrEmpty(this._typeName))
                        {
                            typeNode = doc.CreateElement(this._typeName);
                            propertiesElement = doc.CreateElement("properties");
                            typeNode.AppendChild(propertiesElement);
                        }

                        XmlNode propertytypeNode = doc.CreateElement(this._propName);
                        if (propertiesElement != null)
                        {
                            propertiesElement.AppendChild(propertytypeNode);
                        }

                        XmlNode caption = doc.CreateElement("caption");
                        caption.AppendChild(doc.CreateTextNode(this._captionText));
                        propertytypeNode.AppendChild(caption);

                        XmlNode helptext = doc.CreateElement("help");
                        helptext.AppendChild(doc.CreateTextNode(this._helpText));
                        propertytypeNode.AppendChild(helptext);

                        contentTypes.AppendChild(typeNode);
                    }

                    root.AppendChild(contentTypes);

                break;
            }
        }
Beispiel #10
0
        public static List <PropertyModel> GetProperties(Account account, PropertyListType listType, bool useCachedVersion = true)
        {
            List <PropertyModel> properties = null;

            //IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.AccountManager_Multiplexer.GetDatabase();
            IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.RedisMultiplexer.GetDatabase();

            string redisHashField = ApplicationPropertiesHash.Fields.All();

            switch (listType)
            {
            case PropertyListType.All:
                redisHashField = ApplicationPropertiesHash.Fields.All();
                break;

            case PropertyListType.Listings:
                redisHashField = ApplicationPropertiesHash.Fields.Listings();
                break;

            case PropertyListType.Details:
                redisHashField = ApplicationPropertiesHash.Fields.Details();
                break;

            case PropertyListType.Featured:
                redisHashField = ApplicationPropertiesHash.Fields.Featured();
                break;
            }



            if (useCachedVersion)
            {
                #region Get properties from cache

                try
                {
                    var redisValue = cache.HashGet(ApplicationPropertiesHash.Key(account.AccountNameKey), redisHashField);
                    if (redisValue.HasValue)
                    {
                        properties = JsonConvert.DeserializeObject <List <PropertyModel> >(redisValue);
                    }
                }
                catch
                {
                }

                #endregion
            }
            if (properties == null)
            {
                #region Get properties from SQL

                properties = Sql.Statements.SelectStatements.SelectPropertyList(account.SqlPartition, account.SchemaName);

                #region Append account cdn link to all swatch images

                var cdnEndpoint = Core.Settings.Azure.Storage.GetStoragePartition(account.StoragePartition).CDN;

                foreach (var property in properties)
                {
                    if (property.PropertyTypeNameKey == "swatch")
                    {
                        foreach (var swatch in property.Swatches)
                        {
                            swatch.PropertySwatchImage       = "https://" + cdnEndpoint + "/" + swatch.PropertySwatchImage;
                            swatch.PropertySwatchImageMedium = "https://" + cdnEndpoint + "/" + swatch.PropertySwatchImageMedium;
                            swatch.PropertySwatchImageSmall  = "https://" + cdnEndpoint + "/" + swatch.PropertySwatchImageSmall;
                        }
                    }
                }

                #endregion

                #endregion

                #region Store properties into cache (by all, listing & details)

                #region build seperate property lists

                var listingProperties = new List <PropertyModel>();
                var detailProperties  = new List <PropertyModel>();
                var feturedProperties = new List <PropertyModel>();

                foreach (var property in properties)
                {
                    if (property.Listing)
                    {
                        listingProperties.Add(property);
                    }
                    if (property.Details)
                    {
                        detailProperties.Add(property);
                    }
                    if (property.FeaturedID > 0)
                    {
                        feturedProperties.Add(property);
                    }
                }

                listingProperties = listingProperties.OrderBy(o => o.OrderID).ToList();
                detailProperties  = detailProperties.OrderBy(o => o.OrderID).ToList();
                feturedProperties = feturedProperties.OrderBy(o => o.FeaturedID).ToList();

                #endregion

                try
                {
                    //All
                    cache.HashSet(ApplicationPropertiesHash.Key(account.AccountNameKey), ApplicationPropertiesHash.Fields.All(), JsonConvert.SerializeObject(properties), When.Always, CommandFlags.FireAndForget);

                    //Listing
                    cache.HashSet(ApplicationPropertiesHash.Key(account.AccountNameKey), ApplicationPropertiesHash.Fields.Listings(), JsonConvert.SerializeObject(listingProperties), When.Always, CommandFlags.FireAndForget);

                    //Details
                    cache.HashSet(ApplicationPropertiesHash.Key(account.AccountNameKey), ApplicationPropertiesHash.Fields.Details(), JsonConvert.SerializeObject(detailProperties), When.Always, CommandFlags.FireAndForget);

                    //Featured
                    cache.HashSet(ApplicationPropertiesHash.Key(account.AccountNameKey), ApplicationPropertiesHash.Fields.Featured(), JsonConvert.SerializeObject(feturedProperties), When.Always, CommandFlags.FireAndForget);
                }
                catch
                {
                }

                #endregion

                //Assign the correct propertyListType to the return object:
                switch (listType)
                {
                case PropertyListType.Listings:
                    properties = listingProperties;
                    break;

                case PropertyListType.Details:
                    properties = detailProperties;
                    break;

                case PropertyListType.Featured:
                    properties = feturedProperties;
                    break;
                }
            }

            return(properties);
        }