示例#1
0
        private static void UpdateData(Item item, string name, string description, string location)
        {
            try
            {
                item.Editing.BeginEdit();

                var userName = User.Current.LocalName;
                var userId   = GetUser(userName);

                item["Title"]   = name;
                item["Content"] = description;

                Sitecore.Data.Fields.ReferenceField referenceField = item.Fields["Organizer"];
                referenceField.Value = userId.ToString();

                Sitecore.Data.Fields.MultilistField multiselectField = item.Fields["Members"];
                multiselectField.Add(userId.ToString());

                item.Editing.EndEdit();
            }
            catch (Exception ex)
            {
                item.Editing.CancelEdit();
                throw ex;
            }
        }
        private WhoIsInformation GetMockData()
        {
            var result      = new WhoIsInformation();
            var managerPath = Settings.GetSetting("GeoIpFallback.Mocks.ManagerPath", "/sitecore/system/Modules/GeoIP Fallback/New GepIP Manager");

            if (!string.IsNullOrWhiteSpace(managerPath))
            {
                var manager = Sitecore.Configuration.Factory.GetDatabase(_database).GetItem(managerPath);

                if (manager != null)
                {
                    var cvCurrentLocation = CurrentLocation;
                    if (manager.Statistics.Updated <= LastModified && cvCurrentLocation != null)
                    {
                        return(cvCurrentLocation);
                    }

                    if (cvCurrentLocation != null)
                    {
                        Tracker.Current.Session.Interaction.CustomValues.Remove(LocationCustomValuesKey);
                        Tracker.Current.Session.Interaction.CustomValues.Remove(LastModifiedCustomValuesKey);
                    }

                    Sitecore.Data.Fields.ReferenceField currentLocation = manager.Fields[Constants.CurrentLocationFieldName];
                    if (currentLocation != null && currentLocation.TargetItem != null)
                    {
                        result.Country      = currentLocation.TargetItem[Constants.CountryFieldName];
                        result.City         = currentLocation.TargetItem[Constants.CityFieldName];
                        result.PostalCode   = currentLocation.TargetItem[Constants.PostalCodeFieldName];
                        result.Longitude    = currentLocation.TargetItem.Fields[Constants.LongitudeFieldName].HasValue ? double.Parse(currentLocation.TargetItem.Fields[Constants.LongitudeFieldName].Value) : (double?)null;
                        result.Latitude     = currentLocation.TargetItem.Fields[Constants.LatitudeFieldName].HasValue ? double.Parse(currentLocation.TargetItem.Fields[Constants.LongitudeFieldName].Value) : (double?)null;
                        result.AreaCode     = currentLocation.TargetItem[Constants.AreaCodeFieldName];
                        result.BusinessName = currentLocation.TargetItem[Constants.BusinessNameFieldName];
                        result.Dns          = currentLocation.TargetItem[Constants.DnsFieldName];
                        result.Isp          = currentLocation.TargetItem[Constants.IspFieldName];
                        result.MetroCode    = currentLocation.TargetItem[Constants.MetroCodeFieldName];
                        result.Region       = currentLocation.TargetItem[Constants.RegionFieldName];
                        result.Url          = currentLocation.TargetItem[Constants.UrlFieldName];

                        CurrentLocation = result;
                        LastModified    = manager.Statistics.Updated;

                        return(result);
                    }
                }
            }

            result.BusinessName = "Not Available";
            return(result);
        }
        private bool mapItemToStrategist(Sitecore.Data.Database database, string strategist, Item allocationItem, string strategy, ID itemId)
        {
            bool bOk = false;

            try
            {
                if (ID.IsNullOrEmpty(itemId))
                {
                    Log.Error(String.Format("Genworth.SitecoreExt.Importers.FactSheetImporter:mapMediaItemToStrategist, mediaItem cannot be null or empty. Strategist: {0}, allocation: {1}", strategist, allocationItem["Title"]), this);
                    return(false);
                }

                string sharedPath   = "/sitecore/content/Shared Content/Investments/Strategists/#" + strategist + "#/#" + allocationItem.Name + "#/*[@@templatekey = 'solution' and @Code='" + strategy + "']";
                Item   strategyItem = database.SelectSingleItem(sharedPath);

                if (strategyItem == null)
                {
                    Log.Error(String.Format("Genworth.SitecoreExt.Importers.FactSheetImporter:mapMediaItemToStrategist, solution node for strategy {0}, allocation approach {1}, does not exist, skipping. " +
                                            "This generally happens when the solution node is either missing or has a code that doesn't match the document naming convention. Path: {2}",
                                            strategist,
                                            allocationItem["Title"],
                                            sharedPath), this);
                    return(false);
                }

                Sitecore.Data.Fields.ReferenceField referenceField = strategyItem.Fields["Fact Sheet"];
                if (referenceField != null)
                {
                    using (new Sitecore.SecurityModel.SecurityDisabler())
                    {
                        strategyItem.Editing.BeginEdit();
                        referenceField.Value = itemId.ToString();
                        strategyItem.Editing.EndEdit();
                    }
                }

                bOk = true;
            }
            catch (Exception ex)
            {
                Log.Error(String.Format("Genworth.SitecoreExt.Importers.FactSheetImporter:mapMediaItemToStrategist, strategist: {0}, allocation: {1}, solution: {2}, exception: {3}", strategist, allocationItem["Title"], strategy, ex.ToString()), this);
                bOk = false;
            }

            return(bOk);
        }
        private static void UpdateData(Item item, string name, string description, string place, string startDate, string endDate, string eventtypes)
        {
            try
            {
                item.Editing.BeginEdit();

                var userName = User.Current.LocalName;
                var userId   = GetUser(userName);

                item["Title"]   = name;
                item["Content"] = description;

                Sitecore.Data.Fields.ReferenceField referenceField = item.Fields["Organizer"];
                referenceField.Value = userId.ToString();

                Sitecore.Data.Fields.MultilistField multiselectField = item.Fields["Members"];
                multiselectField.Add(userId.ToString());

                item.Editing.EndEdit();

                Item calendarEvent = item.Axes.SelectSingleItem("//*[@@templateid = '" + Sitecore.XA.Feature.Events.Templates.CalendarEvent.ID + "']");

                if (calendarEvent != null)
                {
                    calendarEvent.Editing.BeginEdit();
                    calendarEvent["EventPlace"]       = place;
                    calendarEvent["EventName"]        = name;
                    calendarEvent["EventDescription"] = description;
                    Sitecore.Data.Fields.MultilistField multiselectCalendarEvent = calendarEvent.Fields["EventType"];
                    multiselectCalendarEvent.Add(eventtypes.ToString());
                    calendarEvent.Editing.EndEdit();
                }
            }
            catch (Exception ex)
            {
                item.Editing.CancelEdit();
                throw ex;
            }
        }
        private bool mapItemToAllocation(Sitecore.Data.Database database, Item allocationItem, ID itemId, string dateRange)
        {
            bool bOk = false;

            try
            {
                if (database == null)
                {
                    Log.Error(String.Format("Genworth.SitecoreExt.Importers.MonthlyPerformanceImporter:mapItemToAllocation, database cannot be null or empty"), this);
                    return(false);
                }
                else if (String.IsNullOrEmpty(allocationItem["Title"]))
                {
                    Log.Error(String.Format("Genworth.SitecoreExt.Importers.MonthlyPerformanceImporter:mapItemToAllocation, allocation cannot be null or empty. Strategist: {0}", allocationItem["Title"]), this);
                    return(false);
                }
                else if (ID.IsNullOrEmpty(itemId))
                {
                    Log.Error(String.Format("Genworth.SitecoreExt.Importers.MonthlyPerformanceImporter:mapItemToAllocation, itemId to map cannot be null or empty. Allocation: {0}", allocationItem["Title"]), this);
                    return(false);
                }


                if (allocationItem["Title"] == null)
                {
                    Log.Error(String.Format("Genworth.SitecoreExt.Importers.MonthlyPerformanceImporter:mapItemToAllocation, allocation approach {0}, does not exist, skipping. Path: {1}",
                                            allocationItem["Title"],
                                            allocationItem.Paths.Path), this);
                    return(false);
                }

                Sitecore.Data.Fields.ReferenceField referenceField = null;

                if (dateRange == "M")
                {
                    referenceField = allocationItem.Fields["Calendar Month Performance"];
                }
                else if (dateRange == "C")
                {
                    referenceField = allocationItem.Fields["Calendar Year Performance"];
                }
                else
                {
                    Log.Error(String.Format("Genworth.SitecoreExt.Importers.MonthlyPerformanceImporter:mapItemToAllocation, unsupported date range -- must be 'C' or 'M'. Allocation: {0}, dateRange {1}",
                                            allocationItem["Title"],
                                            dateRange), this);
                    bOk = false;
                }

                if (referenceField != null)
                {
                    using (new Sitecore.SecurityModel.SecurityDisabler())
                    {
                        allocationItem.Editing.BeginEdit();
                        referenceField.Value = itemId.ToString();
                        allocationItem.Editing.EndEdit();
                    }
                }

                bOk = true;
            }
            catch (Exception ex)
            {
                Log.Error(String.Format("Genworth.SitecoreExt.Importers.MonthlyPerformanceImporter:mapItemToAllocation, allocation: {0}, dateRange: {1}, exception: {2}", allocationItem["Title"], dateRange, ex.ToString()), this);
            }

            return(bOk);
        }
示例#6
0
        public override void Process(DetermineChannelProcessorArgs args)
        {
            if (!Initialize(args))
            {
                return;
            }

            bool channelSet = false;

            /**
             * Process all settings item for diffenet domain and query parameters.
             * If the match found and the channel id has been set, then exit and stop processing other items
             */
            foreach (var settingItem in this.channelizerSettingsItem.Children.Where(c => c.DescendsFrom(Templates.ChannelizerSettingItem.TemplateId)))
            {
                if (String.IsNullOrEmpty(settingItem[Templates.ChannelizerSettingItem.Fields.Channel]))
                {
                    Sitecore.Diagnostics.Log.Warn($"Channel item is not selected. ({settingItem.Paths.FullPath})", this);
                    continue;
                }
                var priority = settingItem[Templates.ChannelizerSettingItem.Fields.Priority];
                if (String.IsNullOrEmpty(priority))
                {
                    Sitecore.Diagnostics.Log.Debug($"{typeof(SetChannel).FullName} - Priority not selected, setting 'both' as the priority.", this);
                    priority = "both";
                }
                priority = priority.ToLowerInvariant();
                var referringDomain = settingItem[Templates.ChannelizerSettingItem.Fields.Domains];
                var channelItem     = new Sitecore.Data.Fields.ReferenceField(settingItem.Fields[Templates.ChannelizerSettingItem.Fields.Channel]).TargetItem;
                var queryParameters = settingItem[Templates.ChannelizerSettingItem.Fields.QueryParameters];
                var onlyCheckQueryParametersPresence    = Sitecore.MainUtil.GetBool(settingItem[Templates.ChannelizerSettingItem.Fields.OnlyCheckQueryParametersPresence], false);
                NameValueCollection queryParametersList = new NameValueCollection();
                if (!String.IsNullOrEmpty(queryParameters))
                {
                    queryParametersList = Sitecore.Web.WebUtil.ParseUrlParameters(queryParameters.ToLowerInvariant());
                }
                if (priority.Equals(Constants.CHANNELIZER_PRIORITY_BOTH))
                {
                    Sitecore.Diagnostics.Log.Debug($"{typeof(SetChannel).FullName} - priority - both", this);
                    if (MatchesReferrerDomain(referringDomain.ToLowerInvariant()) && MatchesQueryParameters(queryParametersList, onlyCheckQueryParametersPresence))
                    {
                        args.ChannelId = channelItem.ID;
                        Sitecore.Diagnostics.Log.Debug($"{typeof(SetChannel).FullName} - Assigned channel - {channelItem.Name}({channelItem.ID})", this);
                        channelSet = true;
                        break;
                    }
                }
                else if (priority.Equals(Constants.CHANNELIZER_PRIORITY_DOMAIN) && !String.IsNullOrEmpty(referringDomain))
                {
                    Sitecore.Diagnostics.Log.Debug($"{typeof(SetChannel).FullName} - priority - referring domain", this);
                    if (MatchesReferrerDomain(referringDomain.ToLowerInvariant()))
                    {
                        args.ChannelId = channelItem.ID;
                        Sitecore.Diagnostics.Log.Debug($"{typeof(SetChannel).FullName} - Assigned channel - {channelItem.Name}({channelItem.ID})", this);
                        channelSet = true;
                        break;
                    }
                }
                else if (priority.Equals(Constants.CHANNELIZER_PRIORITY_QUERYSTRING))
                {
                    Sitecore.Diagnostics.Log.Debug($"{typeof(SetChannel).FullName} - priority - query parameters", this);
                    if (MatchesQueryParameters(queryParametersList, onlyCheckQueryParametersPresence))
                    {
                        args.ChannelId = channelItem.ID;
                        Sitecore.Diagnostics.Log.Debug($"{typeof(SetChannel).FullName} - Assigned channel - {channelItem.Name}({channelItem.ID})", this);
                        channelSet = true;
                        break;
                    }
                }
            }

            if (!channelSet && HttpContext.Current.Request.UrlReferrer != null)
            {
                Sitecore.Diagnostics.Log.Debug($"{typeof(SetChannel).FullName} - channel not set by custom rules, and request has url referrer so setting the common referral channel from settings.", this);
                //Set the other referrals channel
                string channelId = this.channelizerSettingsItem[Templates.ChannelizerSettings.Fields.OtherReferralsChannel];
                if (!String.IsNullOrEmpty(channelId))
                {
                    var channleItem = Sitecore.Context.Database.GetItem(channelId);
                    if (channleItem != null && channleItem.DescendsFrom(Templates.ChannelTemplateId))
                    {
                        args.ChannelId = channleItem.ID;
                    }
                }
            }
        }