예제 #1
0
        public string TryGetUrl(EntityToken entityToken)
        {
            var dataEntityToken = entityToken as DataEntityToken;

            if (dataEntityToken == null)
            {
                return(null);
            }

            var data = dataEntityToken.Data;

            if (data == null)
            {
                return(null);
            }


            PageUrlData pageUrlData;

            var page = data as IPage;

            if (page != null)
            {
                pageUrlData = new PageUrlData(page);
            }
            else
            {
                pageUrlData = DataUrls.TryGetPageUrlData(data.ToDataReference());
            }

            return(pageUrlData != null?GetPagePreviewUrl(pageUrlData) : null);
        }
        public static void OnInitialized()
        {
            DataEventSystemFacade.SubscribeToDataBeforeUpdate <NewsItem>(NewsFacade.SetTitleUrl, true);
            DataEventSystemFacade.SubscribeToDataBeforeAdd <NewsItem>(NewsFacade.SetTitleUrl, true);

            DataUrls.RegisterGlobalDataUrlMapper <NewsItem>(new NewsDataUrlMapper());
        }
예제 #3
0
        public EntityToken TryGetEntityToken(string url)
        {
            UrlKind urlKind;

            PageUrlData pageUrlData = PageUrls.ParseUrl(url, out urlKind);

            if (pageUrlData == null)
            {
                return(null);
            }

            if (pageUrlData.PublicationScope == PublicationScope.Published)
            {
                pageUrlData.PublicationScope = PublicationScope.Unpublished;
            }

            if (!string.IsNullOrEmpty(pageUrlData.PathInfo) || pageUrlData.HasQueryParameters)
            {
                IData data;
                var   dataReference = DataUrls.TryGetData(pageUrlData);
                if (dataReference != null && (data = dataReference.Data) != null)
                {
                    return(data.GetDataEntityToken());
                }
            }

            IPage page = pageUrlData.GetPage();

            if (page == null)
            {
                return(null);
            }

            return(page.GetDataEntityToken());
        }
예제 #4
0
        public static void OnInitialized()
        {
            DataEventSystemFacade.SubscribeToDataBeforeUpdate <Entries>(BlogFacade.SetTitleUrl, true);
            DataEventSystemFacade.SubscribeToDataBeforeAdd <Entries>(BlogFacade.SetTitleUrl, true);

            DataEventSystemFacade.SubscribeToDataAfterAdd <Entries>(BlogFacade.ClearRssFeedCache, true);
            DataEventSystemFacade.SubscribeToDataAfterUpdate <Entries>(BlogFacade.ClearRssFeedCache, true);
            DataEventSystemFacade.SubscribeToDataDeleted <Entries>(BlogFacade.ClearRssFeedCache, true);

            DataUrls.RegisterGlobalDataUrlMapper <Entries>(new BlogEntryDataUrlMapper());
            UrlToEntityTokenFacade.Register(new BlogUrlToEntityTokenMapper());
        }
예제 #5
0
        private void AttachDynamicDataUrlMappers()
        {
            var currentPageId = PageRenderer.CurrentPageId;

            if (currentPageId == Guid.Empty)
            {
                return;
            }

            foreach (var mapperInfo in _dataUrlMappers)
            {
                DataUrls.RegisterDynamicDataUrlMapper(currentPageId, mapperInfo.Item1, mapperInfo.Item2);
            }
        }
예제 #6
0
        private SitemapEntry CreateSitemapEntryFromRelatedData(string baseUrl, IPageRelatedData relatedData)
        {
            var baseUrlWithoutEndSlash = baseUrl.TrimEnd('/');

            var dataRef     = relatedData.ToDataReference();
            var pageUrlData = DataUrls.TryGetPageUrlData(dataRef);

            if (pageUrlData == null)
            {
                return(null);
            }
            var url = PageUrls.BuildUrl(pageUrlData).TrimStart('/');

            return(new SitemapEntry
            {
                Location = $"{baseUrlWithoutEndSlash}/{url}",
            });
        }
예제 #7
0
        /// <summary>
        /// Creates an instace of <see cref="PathInfoRoutedData{T}"/>
        /// </summary>
        protected PathInfoRoutedData()
        {
            var urlMapper = GetUrlMapper();

            Verify.IsNotNull(urlMapper, "UrlMapper is null");

            DataUrls.RegisterDynamicDataUrlMapper(PageRenderer.CurrentPageId, typeof(T), new RoutedData.RoutedDataUrlMapperAdapter(urlMapper));

            var pageUrlData = C1PageRoute.PageUrlData;

            RoutedDataModel model;

            try
            {
                model = urlMapper.GetRouteDataModel(pageUrlData) ?? new RoutedDataModel();
            }
            catch (DataUrlCollisionException)
            {
                C1PageRoute.RegisterPathInfoUsage();
                throw;
            }

            SetModel(model);

            if (!string.IsNullOrEmpty(pageUrlData.PathInfo) && model.IsRouteResolved)
            {
                if (model.IsItem)
                {
                    var canonicalUrlData = urlMapper.BuildItemUrl(model.Item);
                    if (canonicalUrlData.PathInfo != pageUrlData.PathInfo)
                    {
                        string newUrl = PageUrls.BuildUrl(canonicalUrlData);
                        if (newUrl != null)
                        {
                            PermanentRedirect(newUrl);
                        }
                    }
                }

                C1PageRoute.RegisterPathInfoUsage();
            }
        }
예제 #8
0
        public string ToPublicUrl(string internalDataUrl, UrlSpace urlSpace)
        {
            object keyValue = ExtractKeyValue(internalDataUrl);

            if (keyValue == null)
            {
                return(null);
            }

            var data = DataFacade.TryGetDataByUniqueKey(_type, keyValue);

            if (data == null)
            {
                return(null);
            }

            var pageUrlData = DataUrls.TryGetPageUrlData(data.ToDataReference());

            return(pageUrlData != null?PageUrls.BuildUrl(pageUrlData, UrlKind.Public, urlSpace) : null);
        }
예제 #9
0
        private Element CreateElement(IData data)
        {
            string label = data.GetLabel();

            var element = new Element(_elementProviderContext.CreateElementHandle(data.GetDataEntityToken()))
            {
                VisualData = new ElementVisualizedData
                {
                    Label       = label,
                    ToolTip     = label,
                    HasChildren = false,
                    Icon        = data is IPublishControlled publishedControlled
                            ? DataIconLookup[publishedControlled.PublicationStatus]
                            : DataIconFacade.DataPublishedIcon
                }
            };

            AddEditAssociatedDataAction(element);
            AddDeleteAssociatedDataAction(element);
            AddDuplicateAssociatedDataAction(element);

            if (InternalUrls.DataTypeSupported(data.DataSourceId.InterfaceType))
            {
                var dataReference = data.ToDataReference();

                if (DataUrls.CanBuildUrlForData(dataReference))
                {
                    string internalUrl = InternalUrls.TryBuildInternalUrl(dataReference);
                    if (internalUrl != null)
                    {
                        element.PropertyBag.Add("Uri", internalUrl);
                    }
                }
            }

            return(element);
        }
        public string ToPublicUrl(string internalDataUrl, UrlSpace urlSpace)
        {
            object keyValue = ExtractKeyValue(internalDataUrl);

            if (keyValue == null)
            {
                return(null);
            }

            var data = DataFacade.TryGetDataByUniqueKey(_type, keyValue);

            if (data == null)
            {
                return(null);
            }

            var pageUrlData = DataUrls.TryGetPageUrlData(data.ToDataReference());

            if (internalDataUrl.IndexOf("?", StringComparison.Ordinal) > 0)
            {
                var parameters = new UrlBuilder(internalDataUrl).GetQueryParameters();

                if (parameters.HasKeys())
                {
                    if (pageUrlData.QueryParameters == null)
                    {
                        pageUrlData.QueryParameters = parameters;
                    }
                    else
                    {
                        pageUrlData.QueryParameters.Add(parameters);
                    }
                }
            }

            return(pageUrlData != null?PageUrls.BuildUrl(pageUrlData, UrlKind.Public, urlSpace) : null);
        }
예제 #11
0
        private Element BuildElement(IData data,
                                     DynamicValuesHelperReplaceContext replaceContext,
                                     TreeNodeDynamicContext dynamicContext,
                                     bool localizationEnabled,
                                     List <object> itemKeys,
                                     ref IEnumerable <object> keysJoinedByParentFilters,
                                     EntityToken parentEntityToken
                                     )
        {
            replaceContext.CurrentDataItem = data;

            object keyValue = this.KeyPropertyInfo.GetValue(data, null);

            bool itemLocalizationEnabledAndForeign = localizationEnabled && !data.DataSourceId.LocaleScope.Equals(UserSettings.ActiveLocaleCultureInfo);

            if (itemLocalizationEnabledAndForeign && itemKeys.Contains(keyValue))
            {
                return(null);
            }

            var currentEntityToken = data.GetDataEntityToken();

            var element = new Element(new ElementHandle
                                      (
                                          dynamicContext.ElementProviderName,
                                          currentEntityToken,
                                          dynamicContext.Piggybag.PreparePiggybag(this.ParentNode, parentEntityToken)
                                      ));


            bool           hasChildren;
            bool           isDisabled = false;
            ResourceHandle icon, openedIcon;

            if (itemLocalizationEnabledAndForeign)
            {
                hasChildren = false;
                isDisabled  = !data.IsTranslatable();

                if (this.Icon != null)
                {
                    icon       = this.Icon;
                    openedIcon = this.OpenedIcon;
                }
                else
                {
                    icon       = data.GetForeignIcon();
                    openedIcon = icon;
                }
            }
            else
            {
                if (this.Display != LeafDisplayMode.Auto)
                {
                    hasChildren = ChildNodes.Any();
                }
                else
                {
                    hasChildren = ChildNodes.OfType <SimpleElementTreeNode>().Any();

                    if (!hasChildren)
                    {
                        if (keysJoinedByParentFilters != null)
                        {
                            keysJoinedByParentFilters = keysJoinedByParentFilters.Evaluate();

                            hasChildren = keysJoinedByParentFilters.Contains(keyValue);
                        }
                    }

                    // Checking children filtered by FunctionFilters
                    if (!hasChildren)
                    {
                        foreach (var childNode in this.ChildNodes.OfType <DataElementsTreeNode>()
                                 .Where(n => n.FilterNodes.OfType <FunctionFilterNode>().Any()))
                        {
                            var newDynamicContext = new TreeNodeDynamicContext(TreeNodeDynamicContextDirection.Down)
                            {
                                ElementProviderName = dynamicContext.ElementProviderName,
                                Piggybag            = dynamicContext.Piggybag.PreparePiggybag(this.ParentNode, parentEntityToken),
                                CurrentEntityToken  = currentEntityToken
                            };

                            if (childNode.GetDataset(newDynamicContext, false).DataItems.Any())
                            {
                                hasChildren = true;
                                break;
                            }
                        }
                    }
                }

                if (this.Icon != null)
                {
                    icon       = this.Icon;
                    openedIcon = this.OpenedIcon;
                }
                else
                {
                    openedIcon = icon = data.GetIcon();
                }
            }

            string label = this.Label.IsNullOrEmpty()
                            ? data.GetLabel()
                            : this.LabelDynamicValuesHelper.ReplaceValues(replaceContext);

            string toolTip = this.ToolTip.IsNullOrEmpty()
                            ? label
                            : this.ToolTipDynamicValuesHelper.ReplaceValues(replaceContext);

            if (itemLocalizationEnabledAndForeign)
            {
                label = string.Format("{0} ({1})", label, DataLocalizationFacade.GetCultureTitle(UserSettings.ForeignLocaleCultureInfo));

                if (!data.IsTranslatable())
                {
                    toolTip = StringResourceSystemFacade.GetString("Composite.C1Console.Trees", "LocalizeDataWorkflow.DisabledData");
                }
                else
                {
                    toolTip = string.Format("{0} ({1})", toolTip, DataLocalizationFacade.GetCultureTitle(UserSettings.ForeignLocaleCultureInfo));
                }
            }

            element.VisualData = new ElementVisualizedData
            {
                Label       = label,
                ToolTip     = toolTip,
                HasChildren = hasChildren,
                Icon        = icon,
                OpenedIcon  = openedIcon,
                IsDisabled  = isDisabled
            };


            if (InternalUrls.DataTypeSupported(data.DataSourceId.InterfaceType))
            {
                var dataReference = data.ToDataReference();

                if (DataUrls.CanBuildUrlForData(dataReference))
                {
                    string internalUrl = InternalUrls.TryBuildInternalUrl(dataReference);

                    if (internalUrl != null)
                    {
                        element.PropertyBag.Add("Uri", internalUrl);
                    }
                }
            }


            if (itemLocalizationEnabledAndForeign)
            {
                var actionToken = new WorkflowActionToken(
                    WorkflowFacade.GetWorkflowType("Composite.C1Console.Trees.Workflows.LocalizeDataWorkflow"),
                    LocalizeDataPermissionTypes);

                element.AddAction(new ElementAction(new ActionHandle(actionToken))
                {
                    VisualData = new ActionVisualizedData
                    {
                        Label          = StringResourceSystemFacade.GetString("Composite.C1Console.Trees", "LocalizeDataWorkflow.LocalizeDataLabel"),
                        ToolTip        = StringResourceSystemFacade.GetString("Composite.C1Console.Trees", "LocalizeDataWorkflow.LocalizeDataToolTip"),
                        Icon           = LocalizeDataTypeIcon,
                        Disabled       = false,
                        ActionLocation = ActionLocation.OtherPrimaryActionLocation
                    }
                });
            }

            return(element);
        }
예제 #12
0
 public void AddUrlMapping(Type dataType, Guid pageId, string actionName = null, string fieldName = null)
 {
     DataUrls.RegisterGlobalDataUrlMapper(dataType, new MvcFunctionDataUrlMapper(dataType, pageId, actionName, fieldName));
 }
예제 #13
0
        private static IEnumerable <SearchResultEntry> SearchInType <T>(string[] keywords, bool currentWebsiteOnly) where T : class, IData
        {
            var stringFields = typeof(T).GetPropertiesRecursively()
                               .Where(p => p.PropertyType == typeof(string) &&
                                      p.ReflectedType != typeof(IPublishControlled) &&
                                      p.ReflectedType != typeof(ILocalizedControlled) &&
                                      p.ReflectedType != typeof(IPageMetaData) &&
                                      !p.GetCustomAttributes <ForeignKeyAttribute>().Any()).ToList();

            if (stringFields.Count == 0)
            {
                return(null);
            }


            Expression searchExpr = null;
            var        parameter  = Expression.Parameter(typeof(T), "p");

            foreach (string keyword in keywords)
            {
                Expression keywordSearchExpr = null;

                foreach (var stringField in stringFields)
                {
                    // Building the following expression:
                    // p => (p.{stringField} != null && p.{stringField}.ToLower().Contains(keyword))

                    var propertyExpression = Expression.Property(parameter, stringField);

                    var notNullExpression = Expression.NotEqual(propertyExpression, Expression.Constant(null, typeof(string)));

                    var toLowerExpression  = Expression.Call(propertyExpression, String_ToLower);
                    var containsExpression = Expression.Call(toLowerExpression, String_Contains,
                                                             new Expression[] { Expression.Constant(keyword) });

                    var andExpression = Expression.AndAlso(notNullExpression, containsExpression);

                    keywordSearchExpr = keywordSearchExpr.OrElse(andExpression);
                }

                searchExpr = searchExpr.AndAlso(keywordSearchExpr);
            }

            if (searchExpr == null)
            {
                return(null);
            }

            var searchPredicate = Expression.Lambda <Func <T, bool> >(searchExpr, parameter);

            HashSet <Guid> pagesIdsOfCurrentSite = null;

            if (currentWebsiteOnly)
            {
                using (var c = new DataConnection())
                {
                    pagesIdsOfCurrentSite = new HashSet <Guid>(c.SitemapNavigator.CurrentPageNode
                                                               .GetPageIds(SitemapScope.Level1AndDescendants));
                }
            }

            var result = new List <SearchResultEntry>();

            foreach (var data in DataFacade.GetData(searchPredicate))
            {
                if (currentWebsiteOnly &&
                    data is IPageRelatedData &&
                    !pagesIdsOfCurrentSite.Contains((data as IPageRelatedData).PageId))
                {
                    continue;
                }

                var dataReference = data.ToDataReference();

                string url;

                if (currentWebsiteOnly && !(data is IPageRelatedData))
                {
                    // Getting public url data to see if it is pointing to the website
                    var pageUrlData = DataUrls.TryGetPageUrlData(dataReference);
                    if (pageUrlData == null || !pagesIdsOfCurrentSite.Contains(pageUrlData.PageId))
                    {
                        continue;
                    }

                    url = PageUrls.BuildUrl(pageUrlData);
                }
                else
                {
                    url = InternalUrls.TryBuildInternalUrl(dataReference);
                }

                if (url == null)
                {
                    continue;
                }

                string label = data.GetLabel();

                // TODO: support for current website only for global data types
                result.Add(new SearchResultEntry
                {
                    Url   = url,
                    Title = label
                });
            }

            return(result);
        }
예제 #14
0
        public void AutoDiscoverFunctions(Assembly assembly)
        {
            foreach (var type in assembly.GetTypes().Where(IsController))
            {
                // Searching for [C1Function] attribute on controller or on its methods
                var attribute = type.GetCustomAttributes <C1FunctionAttribute>(false).SingleOrDefault();

                MvcControllerFunction controllerFunction = null;
                if (attribute != null)
                {
                    controllerFunction = RegisterController(type, attribute, null);
                }


                foreach (var method in type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
                {
                    var    actionNameAttribute = method.GetCustomAttributes <ActionNameAttribute>(false).SingleOrDefault();
                    string actionName          = actionNameAttribute != null ? actionNameAttribute.Name : method.Name;

                    MvcFunctionBase controlerToAttachUrlMapperTo = controllerFunction;
                    string          urlMapperAction = actionName;

                    attribute = method.GetCustomAttributes <C1FunctionAttribute>(false).SingleOrDefault();
                    if (attribute != null)
                    {
                        var routeAttribute = method.GetCustomAttributes <RouteAttribute>(false)
                                             .SingleOrDefaultOrException(
                            "Multiple [Route] attributes defined on method '{0}' of controller class '{1}'",
                            method.Name, type.FullName);

                        var parameters = routeAttribute != null?GetFunctionParameters(method, routeAttribute) : GetFunctionParameters(method);

                        var methodBasedMvcFunction = RegisterActionFunction(type, actionName, routeAttribute != null, attribute, parameters);

                        controlerToAttachUrlMapperTo = methodBasedMvcFunction;
                        urlMapperAction = null;
                    }

                    // Attaching url mappers
                    if (controlerToAttachUrlMapperTo != null)
                    {
                        var dynamicUrlMapperAttributes = method.GetCustomAttributes <DynamicUrlMapperAttribute>(false).ToList();
                        var globalUrlMapperAttributes  = method.GetCustomAttributes <GlobalUrlMapperAttribute>(false).ToList();

                        foreach (var mapperAttr in dynamicUrlMapperAttributes)
                        {
                            var mapper = new MvcFunctionDataUrlMapper(mapperAttr.DataType, null, urlMapperAction, mapperAttr.FieldName);
                            controlerToAttachUrlMapperTo.AssignDynamicUrlMapper(mapperAttr.DataType, mapper);
                        }

                        foreach (var mapperAttr in globalUrlMapperAttributes)
                        {
                            var mapper = new MvcFunctionDataUrlMapper(mapperAttr.DataType, mapperAttr.PageId, urlMapperAction, mapperAttr.FieldName);
                            DataUrls.RegisterGlobalDataUrlMapper(mapperAttr.DataType, mapper);
                        }
                    }
                }
            }

            MvcFunctionProvider.Reload();
        }
예제 #15
0
 public Urls(UrlHelper urlHelper)
 {
     Url       = urlHelper;
     Data      = new DataUrls(urlHelper);
     Templates = new TemplatesUrls(urlHelper);
 }