Example #1
0
        private IEnumerable <DocumentWithContinuationToken> GetDocumentsFromScope(
            PublicationScope publicationScope,
            CultureInfo culture,
            object continueFromKey)
        {
            using (new DataConnection(publicationScope, culture))
            {
                var query = DataFacade.GetData(_interfaceType);

                query = FilterAndOrderByKey(query, continueFromKey);

                if (publicationScope == PublicationScope.Unpublished)
                {
                    query = query
                            .Cast <IPublishControlled>()
                            .Where(data => data.PublicationStatus != GenericPublishProcessController.Published);
                }
                var dataSet = query.Cast <IData>().Evaluate();

                foreach (var data in dataSet)
                {
                    var document = FromData(data, culture);
                    if (document == null)
                    {
                        continue;
                    }

                    yield return(new DocumentWithContinuationToken
                    {
                        Document = document,
                        ContinuationToken = GetContinuationToken(data, publicationScope)
                    });
                }
            }
        }
        /// <summary>
        /// Documentation pending
        /// </summary>
        /// <param name="scope"></param>
        /// <param name="locale"></param>
        /// <returns></returns>
        public virtual DataConnectionImplementation CreateDataConnection(PublicationScope?scope, CultureInfo locale)
        {
            PublicationScope scopeToUse  = ResolvePublicationScope(scope);
            CultureInfo      localeToUse = ResolveLocale(locale);

            return(new DataConnectionImplementation(scopeToUse, localeToUse));
        }
        /// <summary>
        /// Documentation pending
        /// </summary>
        /// <param name="scope"></param>
        /// <param name="locale"></param>
        public DataConnectionImplementation(PublicationScope scope, CultureInfo locale)
        {
            InitializeThreadData();
            InitializeScope(scope, locale);

            _dataScope = new DataScope(this.DataScopeIdentifier, locale);
        }
        private static PageUrlData ParseRendererUrl(UrlBuilder urlBuilder)
        {
            NameValueCollection queryString = urlBuilder.GetQueryParameters();

            Verify.That(!string.IsNullOrEmpty(queryString["pageId"]), "Invalid query string. The 'pageId' parameter of the GUID type is expected.");

            string dataScopeName = queryString["dataScope"];

            PublicationScope publicationScope = PublicationScope.Published;

            if (dataScopeName != null &&
                string.Compare(dataScopeName, DataScopeIdentifier.AdministratedName, StringComparison.OrdinalIgnoreCase) == 0)
            {
                publicationScope = PublicationScope.Unpublished;
            }


            string cultureInfoStr = queryString["cultureInfo"];

            if (cultureInfoStr.IsNullOrEmpty())
            {
                cultureInfoStr = queryString["CultureInfo"];
            }

            CultureInfo cultureInfo;

            if (!cultureInfoStr.IsNullOrEmpty())
            {
                cultureInfo = new CultureInfo(cultureInfoStr);
            }
            else
            {
                cultureInfo = LocalizationScopeManager.CurrentLocalizationScope;
                if (cultureInfo.Equals(CultureInfo.InvariantCulture))
                {
                    cultureInfo = DataLocalizationFacade.DefaultLocalizationCulture;
                }
            }

            Guid pageId = new Guid(queryString["pageId"]);

            var queryParameters = new NameValueCollection();

            var queryKeys = new[] { "pageId", "dataScope", "cultureInfo", "CultureInfo" };

            var notUsedKeys = queryString.AllKeys.Where(key => !queryKeys.Contains(key, StringComparer.OrdinalIgnoreCase));

            foreach (string key in notUsedKeys)
            {
                queryParameters.Add(key, queryString[key]);
            }

            string pathInfo = urlBuilder.PathInfo != null?HttpUtility.UrlDecode(urlBuilder.PathInfo) : null;

            return(new PageUrlData(pageId, publicationScope, cultureInfo)
            {
                PathInfo = pathInfo,
                QueryParameters = queryParameters,
            });
        }
        public void FirePublicationScopeChanging(PublicationScope publicationScope)
        {
            _publicationScope = publicationScope;

            if (PublicationScopeChanged != null)
            {
                PublicationScopeChanged(this, new EventArgs());
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="StoreEventArgs"/> class.
        /// </summary>
        /// <param name="dataType">Type of the data.</param>
        /// <param name="publicationScope">The publication scope.</param>
        /// <param name="locale">The locale.</param>
        /// <param name="dataEventsFired">Value indicating whether detailed data events have been fired for this change event.
        /// When <c>false</c> the change happened outside the current process
        /// (in the physical store, perhaps done by another running instance). </param>
        /// <exclude/>
        internal StoreEventArgs(Type dataType, PublicationScope publicationScope, CultureInfo locale, bool dataEventsFired)
        {
            Verify.ArgumentNotNull(dataType, "dataType");
            Verify.ArgumentNotNull(publicationScope, "publicationScope");

            _dataType         = dataType;
            _publicationScope = publicationScope;
            _locale           = locale;
            _dataEventsFired  = dataEventsFired;
        }
Example #7
0
        /// <exclude />
        public PageUrl(PublicationScope publicationScope, CultureInfo locale, Guid pageId, PageUrlType urlType)
        {
            Verify.ArgumentNotNull(locale, "locale");
            Verify.ArgumentCondition(pageId != Guid.Empty, "pageId", "PageId should not be an empty guid.");

            this.PublicationScope = publicationScope;
            Locale  = locale;
            PageId  = pageId;
            UrlType = urlType;
        }
Example #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StoreEventArgs"/> class.
        /// </summary>
        /// <param name="dataType">Type of the data.</param>
        /// <param name="publicationScope">The publication scope.</param>
        /// <param name="locale">The locale.</param>
        /// <param name="dataEventsFired">Value indicating whether detailed data events have been fired for this change event. 
        /// When <c>false</c> the change happened outside the current process 
        /// (in the physical store, perhaps done by another running instance). </param>
        /// <exclude/>
        internal StoreEventArgs(Type dataType, PublicationScope publicationScope, CultureInfo locale, bool dataEventsFired)
        {
            Verify.ArgumentNotNull(dataType, "dataType");
            Verify.ArgumentNotNull(publicationScope, "publicationScope");

            _dataType = dataType;
            _publicationScope = publicationScope;
            _locale = locale;
            _dataEventsFired = dataEventsFired;
        }
Example #9
0
        /// <summary>
        /// Call this indirectly. Use FireStoreChangedEvent or FireExternalStoreChangedEvent above.
        /// </summary>
        private static void FireStoreChangedEvent(Type dataType, PublicationScope publicationScope, CultureInfo locale, bool dataEventsFired)
        {
            var args = new StoreEventArgs(dataType, publicationScope, locale, dataEventsFired);

            // switch to the scope where event is happening
            using (new DataConnection(publicationScope, locale))
            {
                _storeChangedEventDictionary.Fire <StoreEventHandler>(dataType, callback => callback(null, args));
            }
        }
Example #10
0
        /// <exclude />
        public PageUrl(PublicationScope publicationScope, CultureInfo locale, Guid pageId, PageUrlType urlType)
        {
            Verify.ArgumentNotNull(locale, "locale");
            Verify.ArgumentCondition(pageId != Guid.Empty, "pageId", "PageId should not be an empty guid.");

            this.PublicationScope = publicationScope;
            Locale = locale;
            PageId = pageId;
            UrlType = urlType;
        }
Example #11
0
        /// <summary>
        /// To be used for handling 'internal' links.
        /// </summary>
        /// <param name="queryString">Query string.</param>
        /// <param name="notUsedQueryParameters">Query string parameters that were not used.</param>
        /// <returns></returns>
        internal static PageUrl ParseQueryString(NameValueCollection queryString, out NameValueCollection notUsedQueryParameters)
        {
            if (string.IsNullOrEmpty(queryString["pageId"]))
            {
                throw new InvalidOperationException("Invalid query string. The 'pageId' parameter of the GUID type is expected.");
            }

            string dataScopeName = queryString["dataScope"];

            PublicationScope publicationScope = PublicationScope.Published;

            if (dataScopeName != null &&
                string.Compare(dataScopeName, DataScopeIdentifier.AdministratedName, StringComparison.OrdinalIgnoreCase) == 0)
            {
                publicationScope = PublicationScope.Unpublished;
            }


            string cultureInfoStr = queryString["cultureInfo"];

            if (cultureInfoStr.IsNullOrEmpty())
            {
                cultureInfoStr = queryString["CultureInfo"];
            }

            CultureInfo cultureInfo;

            if (!cultureInfoStr.IsNullOrEmpty())
            {
                cultureInfo = new CultureInfo(cultureInfoStr);
            }
            else
            {
                cultureInfo = LocalizationScopeManager.CurrentLocalizationScope;
                if (cultureInfo == CultureInfo.InvariantCulture)
                {
                    cultureInfo = DataLocalizationFacade.DefaultLocalizationCulture;
                }
            }

            Guid pageId = new Guid(queryString["pageId"]);

            notUsedQueryParameters = new NameValueCollection();

            var queryKeys = new[] { "pageId", "dataScope", "cultureInfo", "CultureInfo" };

            var notUsedKeys = queryString.AllKeys.Where(key => !queryKeys.Contains(key, StringComparer.OrdinalIgnoreCase));

            foreach (string key in notUsedKeys)
            {
                notUsedQueryParameters.Add(key, queryString[key]);
            }

            return(new PageUrl(publicationScope, cultureInfo, pageId, PageUrlType.Internal));
        }
Example #12
0
        private string GetContinuationToken(IData data, PublicationScope publicationScope)
        {
            if (_interfaceType.GetKeyProperties().Count > 1)
            {
                return(null);                                             // Not supported
            }
            var    key    = data.GetUniqueKey();
            string keyStr = ValueTypeConverter.Convert <string>(key);

            return($"{publicationScope}:{keyStr}");
        }
Example #13
0
        /// <summary>
        /// Creates a new <see cref="DataConnection"/> instance with the given <paramref name="scope"/>
        /// and the given <paramref name="locale"/>. <see cref="DataConnection"/> can be used to access the C1 CMS storage.
        /// </summary>
        /// <param name="scope">The <see cref="Composite.Data.PublicationScope"/> data should be read from.</param>
        /// <param name="locale">The desired locale. This should be one of the locale found in <see cref="Composite.Data.DataConnection.AllLocales"/></param>
        /// <example>
        /// Here is an example of how to use it
        /// <code>
        /// using (DataConnection connection = new DataConnection(PublicationScope.Published, new CultureInfo("da-DK")))
        /// {
        ///    var q =
        ///       from d in connection.Get&lt;IMyDataType&gt;()
        ///       where d.Name == "Foo"
        ///       select d;
        /// }
        /// </code>
        /// </example>
        public DataConnection(PublicationScope scope, CultureInfo locale)
            : base(() => ImplementationFactory.CurrentFactory.CreateDataConnection(scope, locale))
        {
            if ((scope < PublicationScope.Unpublished) || (scope > PublicationScope.Published))
            {
                throw new ArgumentOutOfRangeException("scope");
            }

            CreateImplementation();

            //_pageDataConnection = new ImplementationContainer<PageDataConnection>(() => new PageDataConnection(scope, locale));
            _sitemapNavigator = new ImplementationContainer <SitemapNavigator>(() => new SitemapNavigator(this));
        }
Example #14
0
        public EventPublication(string eventName, PublicationScope scope)
        {
            if (eventName == null)
            {
                throw new ArgumentNullException();
            }
            if (eventName == string.Empty)
            {
                throw new ArgumentException();
            }

            this.EventName        = eventName;
            this.PublicationScope = scope;
        }
        private PageUrlData ParsePagePath(string pagePath, PublicationScope publicationScope, CultureInfo locale, IHostnameBinding hostnameBinding)
        {
            // Parshing what's left:
            // [/Path to a page][UrlSuffix]{/PathInfo}
            string pathInfo = null;

            bool canBePublicUrl    = true;
            bool pathInfoExtracted = false;

            if (!string.IsNullOrEmpty(UrlSuffix))
            {
                string urlSuffixPlusSlash = UrlSuffix + "/";

                int suffixOffset = pagePath.IndexOf(urlSuffixPlusSlash, StringComparison.OrdinalIgnoreCase);
                if (suffixOffset > 0)
                {
                    pathInfo = pagePath.Substring(suffixOffset + UrlSuffix.Length);
                    pagePath = pagePath.Substring(0, suffixOffset);

                    pathInfoExtracted = true;
                }
                else if (pagePath.EndsWith(UrlSuffix, StringComparison.OrdinalIgnoreCase))
                {
                    pagePath = pagePath.Substring(0, pagePath.Length - UrlSuffix.Length);

                    pathInfoExtracted = true;
                }
                else
                {
                    canBePublicUrl = pagePath == "/"; // Only root page may not have a UrlSuffix
                }
            }

            if (canBePublicUrl)
            {
                IPage page = TryGetPageByUrlTitlePath(pagePath, pathInfoExtracted, hostnameBinding, ref pathInfo);

                if (page != null)
                {
                    return(new PageUrlData(page.Id, publicationScope, locale)
                    {
                        VersionId = page.VersionId,
                        PathInfo = pathInfo
                    });
                }
            }

            return(null);
        }
Example #16
0
        private void SetDataScopeIdentifier(PublicationScope scope)
        {
            switch (scope)
            {
            case PublicationScope.Published:
                this.DataScopeIdentifier = DataScopeIdentifier.Public;
                break;

            case PublicationScope.Unpublished:
                this.DataScopeIdentifier = DataScopeIdentifier.Administrated;
                break;

            default:
                throw new ArgumentException("PublicationScope {0} not supported".FormatWith(scope), "scope");
            }
        }
Example #17
0
        private void SetDataScopeIdentifier(PublicationScope scope)
        {
            switch (scope)
            {
                case PublicationScope.Published:
                    this.DataScopeIdentifier = DataScopeIdentifier.Public;
                    break;

                case PublicationScope.Unpublished:
                    this.DataScopeIdentifier = DataScopeIdentifier.Administrated;
                    break;

                default:
                    throw new ArgumentException("PublicationScope {0} not supported".FormatWith(scope), "scope");
            }
        }
        private static string ParseAndRemovePublicationScopeMarker(string filePath, out PublicationScope publicationScope)
        {
            publicationScope = PublicationScope.Published;

            if (filePath.Contains(UrlMarker_Unpublished))
            {
                publicationScope = PublicationScope.Unpublished;

                filePath = filePath.Replace(UrlMarker_Unpublished, string.Empty);
                if (filePath == string.Empty)
                {
                    filePath = "/";
                }
            }

            return(filePath);
        }
Example #19
0
        public PageUrlBuilder(PublicationScope publicationScope, CultureInfo localizationScope, UrlSpace urlSpace)
        {
            _publicationScope  = publicationScope;
            _localizationScope = localizationScope;

            var localeMappedName = DataLocalizationFacade.GetUrlMappingName(localizationScope) ?? string.Empty;

            _forceRelativeUrls = urlSpace != null && urlSpace.ForceRelativeUrls;

            if (!_forceRelativeUrls &&
                urlSpace != null &&
                urlSpace.Hostname != null)
            {
                List <IHostnameBinding> hostnameBindings = DataFacade.GetData <IHostnameBinding>().ToList();

                _hostnameBinding = hostnameBindings.FirstOrDefault(b => b.Hostname == urlSpace.Hostname);

                bool knownHostname = _hostnameBinding != null;

                if (knownHostname)
                {
                    _hostnameBindings = hostnameBindings;

                    _urlSpace = urlSpace;
                }
            }

            if (_hostnameBinding != null &&
                !_hostnameBinding.IncludeCultureInUrl &&
                _hostnameBinding.Culture == localizationScope.Name)
            {
                _friendlyUrlPrefix = UrlUtils.PublicRootPath;

                if (!localeMappedName.IsNullOrEmpty())
                {
                    _friendlyUrlPrefixWithLanguageCode = UrlUtils.PublicRootPath + "/" + localeMappedName;
                }
            }
            else
            {
                _friendlyUrlPrefix = UrlUtils.PublicRootPath + (localeMappedName.IsNullOrEmpty() ? string.Empty : "/" + localeMappedName);
            }

            UrlSuffix = DataFacade.GetData <IUrlConfiguration>().Select(c => c.PageUrlSuffix).FirstOrDefault() ?? string.Empty;
        }
Example #20
0
        private List <IData> GetMetaData(Guid pageId, Guid versionId, PublicationScope publicationScope, CultureInfo culture)
        {
            var result = new List <IData>();

            using (var conn = new DataConnection(publicationScope, culture))
            {
                conn.DisableServices();

                foreach (var metaDataType in PageMetaDataFacade.GetAllMetaDataTypes()
                         .Where(type => typeof(IPageMetaData).IsAssignableFrom(type)))
                {
                    result.AddRange(DataFacade.GetData(metaDataType).OfType <IPageMetaData>()
                                    .Where(md => md.PageId == pageId && md.VersionId == versionId));
                }
            }

            return(result);
        }
Example #21
0
        public PageUrlBuilder(PublicationScope publicationScope, CultureInfo localizationScope, UrlSpace urlSpace)
        {
            _publicationScope = publicationScope;
            _localizationScope = localizationScope;

            var localeMappedName = DataLocalizationFacade.GetUrlMappingName(localizationScope) ?? string.Empty;
            _forceRelativeUrls = urlSpace != null && urlSpace.ForceRelativeUrls;

            if (!_forceRelativeUrls
                && urlSpace != null
                && urlSpace.Hostname != null)
            {
                List<IHostnameBinding> hostnameBindings = DataFacade.GetData<IHostnameBinding>().ToList();

                _hostnameBinding = hostnameBindings.FirstOrDefault(b => b.Hostname == urlSpace.Hostname);

                bool knownHostname = _hostnameBinding != null;

                if(knownHostname)
                {
                    _hostnameBindings = hostnameBindings;

                    _urlSpace = urlSpace;
                }
            }

            if(_hostnameBinding != null
                && !_hostnameBinding.IncludeCultureInUrl
                && _hostnameBinding.Culture == localizationScope.Name)
            {
                _friendlyUrlPrefix = UrlUtils.PublicRootPath;

                if (!localeMappedName.IsNullOrEmpty())
                {
                    _friendlyUrlPrefixWithLanguageCode = UrlUtils.PublicRootPath + "/" + localeMappedName;
                }
            }
            else
            {
                _friendlyUrlPrefix = UrlUtils.PublicRootPath + (localeMappedName.IsNullOrEmpty() ? string.Empty : "/" + localeMappedName);
            }

            UrlSuffix = DataFacade.GetData<IUrlConfiguration>().Select(c => c.PageUrlSuffix).FirstOrDefault() ?? string.Empty;
        }
        public override bool OnBeginRecipe(object currentValue, out object newValue)
        {
            newValue = null;
            IDictionaryService dict = GetService <IDictionaryService>();

            if (dict.GetValue("PublicationScope") == null)
            {
                return(false);
            }

            Project          current = dict.GetValue("CurrentProject") as Project;
            Project          common  = dict.GetValue("CommonProject") as Project;
            PublicationScope scope   = (PublicationScope)dict.GetValue("PublicationScope");

            newValue = current;
            if (scope == PublicationScope.Global && common != null)
            {
                newValue = common;
            }
            return(true);
        }
Example #23
0
        private Dictionary <Tuple <Guid, Guid>, List <IData> > GetAllMetaData(PublicationScope publicationScope, CultureInfo culture)
        {
            var result = new Dictionary <Tuple <Guid, Guid>, List <IData> >();

            using (var conn = new DataConnection(publicationScope, culture))
            {
                conn.DisableServices();

                foreach (var metaDataType in PageMetaDataFacade.GetAllMetaDataTypes()
                         .Where(type => typeof(IPageMetaData).IsAssignableFrom(type)))
                {
                    foreach (var dataItem in DataFacade.GetData(metaDataType).OfType <IPageMetaData>())
                    {
                        var key  = new Tuple <Guid, Guid>(dataItem.PageId, dataItem.VersionId);
                        var list = result.GetOrAdd(key, () => new List <IData>());
                        list.Add(dataItem);
                    }
                }
            }

            return(result);
        }
Example #24
0
        /// <summary>
        /// Documentation pending
        /// </summary>
        /// <param name="scope"></param>
        /// <returns></returns>
        public virtual PublicationScope ResolvePublicationScope(PublicationScope?scope)
        {
            PublicationScope scopeToUse = PublicationScope.Published;

            if (scope.HasValue)
            {
                scopeToUse = scope.Value;
            }
            else
            {
                if (DataScopeManager.CurrentDataScope.Equals(DataScopeIdentifier.Administrated))
                {
                    scopeToUse = PublicationScope.Unpublished;
                }
                else if (DataScopeManager.CurrentDataScope.Equals(DataScopeIdentifier.Public))
                {
                    scopeToUse = PublicationScope.Published;
                }
            }

            return(scopeToUse);
        }
Example #25
0
            /// <exclude />
            public static SiteMapContainer LoadSiteMap(CompositeC1SiteMapProvider provider, CultureInfo culture, PublicationScope publicationScope, Guid rootPageId)
            {
                using (var data = new DataConnection(publicationScope, culture))
                {
                    PageManager.PreloadPageCaching();

                    var rootPage = data.SitemapNavigator.GetPageNodeById(rootPageId);

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

                    var container = new SiteMapContainer
                    {
                        Root = new CompositeC1SiteMapNode(provider, rootPage, data, 1)
                    };

                    LoadNodes(provider, rootPage, null, container, data, 1);

                    return container;
                }
            }
Example #26
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Publication"/> class
        /// </summary>
        public Publication(EventTopic topic, object publisher, string eventName, WorkItem workItem, PublicationScope scope)
        {
            this.topic = topic;
            this.wrPublisher = new WeakReference(publisher);
            this.scope = scope;
            this.eventName = eventName;
            this.wrWorkItem = new WeakReference(workItem);

            EventInfo publishedEvent =
                publisher.GetType().GetEvent(eventName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);

            if (publishedEvent == null)
            {
                throw new EventBrokerException(String.Format(CultureInfo.CurrentCulture,
                    Properties.Resources.CannotFindPublishedEvent, eventName));
            }

            ThrowIfInvalidEventHandler(publishedEvent);
            ThrowIfEventIsStatic(publishedEvent);

            Delegate handler = Delegate.CreateDelegate(publishedEvent.EventHandlerType, this, this.GetType().GetMethod("PublicationHandler"));
            publishedEvent.AddEventHandler(publisher, handler);
        }
Example #27
0
        /// <summary>
        /// Fires the <see cref="EventTopic"/>.
        /// </summary>
        /// <param name="sender">The object that acts as the sender of the event to the subscribers.</param>
        /// <param name="e">An <see cref="EventArgs"/> instance to be passed to the subscribers.</param>
        /// <param name="workItem">The <see cref="WorkItem"/> where the object firing the event is.</param>
        /// <param name="scope">A <see cref="PublicationScope"/> value stating the scope of the firing behavior.</param>
        public virtual void Fire(object sender, EventArgs e, WorkItem workItem, PublicationScope scope)
        {
            Guard.EnumValueIsDefined(typeof(PublicationScope), scope, "scope");

            if (enabled)
            {
                if (traceSource != null)
                {
                    traceSource.TraceInformation(Properties.Resources.EventTopicTraceFireStarted, name);
                }

                Clean();

                switch (scope)
                {
                case PublicationScope.WorkItem:
                    CallSubscriptionHandlers(sender, e, GetWorkItemHandlers(workItem));
                    break;

                case PublicationScope.Global:
                    CallSubscriptionHandlers(sender, e, GetAllHandlers());
                    break;

                case PublicationScope.Descendants:
                    CallSubscriptionHandlers(sender, e, GetDescendantsHandlers(workItem));
                    break;

                default:
                    throw new ArgumentException(Properties.Resources.InvalidPublicationScope);
                }

                if (traceSource != null)
                {
                    traceSource.TraceInformation(Properties.Resources.EventTopicTraceFireCompleted, name);
                }
            }
        }
Example #28
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Publication"/> class
        /// </summary>
        public Publication(EventTopic topic, object publisher, string eventName, WorkItem workItem, PublicationScope scope)
        {
            this.topic       = topic;
            this.wrPublisher = new WeakReference(publisher);
            this.scope       = scope;
            this.eventName   = eventName;
            this.wrWorkItem  = new WeakReference(workItem);

            EventInfo publishedEvent =
                publisher.GetType().GetEvent(eventName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);

            if (publishedEvent == null)
            {
                throw new EventBrokerException(String.Format(CultureInfo.CurrentCulture,
                                                             Properties.Resources.CannotFindPublishedEvent, eventName));
            }

            ThrowIfInvalidEventHandler(publishedEvent);
            ThrowIfEventIsStatic(publishedEvent);

            Delegate handler = Delegate.CreateDelegate(publishedEvent.EventHandlerType, this, this.GetType().GetMethod("PublicationHandler"));

            publishedEvent.AddEventHandler(publisher, handler);
        }
Example #29
0
            /// <exclude />
            public static SiteMapContainer LoadSiteMap(CompositeC1SiteMapProvider provider, CultureInfo culture, PublicationScope publicationScope, Guid rootPageId)
            {
                using (var data = new DataConnection(publicationScope, culture))
                {
                    PageManager.PreloadPageCaching();

                    var rootPage = data.SitemapNavigator.GetPageNodeById(rootPageId);

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

                    var container = new SiteMapContainer
                    {
                        Root = new CompositeC1SiteMapNode(provider, rootPage, data, 1)
                    };

                    LoadNodes(provider, rootPage, null, container, data, 1);

                    return(container);
                }
            }
 /// <summary>
 /// Declares an event publication for an <see cref="EventTopic"/> with the specified topic and
 /// <see cref="PublicationScope"/>.
 /// </summary>
 /// <param name="topic">The name of the <see cref="EventTopic"/> the event will publish.</param>
 /// <param name="scope">The scope for the publication.</param>
 public EventPublicationAttribute(string topic, PublicationScope scope)
 {
     this.topic = topic;
     this.scope = scope;
 }
 public void ShowPublicationScope(List <PublicationScope> publicationScopes, PublicationScope selected)
 {
     _publicationScopeComboBox.DataSource   = publicationScopes;
     _publicationScopeComboBox.SelectedItem = selected;
 }
Example #32
0
        private async Task <XhtmlDocument> ExecuteRouteAsync(RouteData routeData, HttpContext parentContext, CultureInfo culture, PublicationScope publicationScope)
        {
            if (HttpContext.Current == null)
            {
                HttpContext.Current = parentContext;
            }

            Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture = culture;

            string xhtml;

            using (var writer = new StringWriter())
            {
                var httpResponse   = new HttpResponse(writer);
                var httpContext    = new HttpContext(parentContext.Request, httpResponse);
                var requestContext = new RequestContext(new HttpContextWrapper(httpContext), routeData);

                CopyHttpContextData(parentContext, httpContext);

                var handler = routeData.RouteHandler.GetHttpHandler(requestContext);
                Verify.IsNotNull(handler, "No handler found for the function '{0}'", Namespace + "." + Name);

                var asyncHandler = handler as IHttpAsyncHandler;
                Verify.IsNotNull(asyncHandler, "The handler class '{0}' does not implement IHttpAsyncHandler interface", handler.GetType());

                // var asyncResult = asyncHandler.BeginProcessRequest(httpContext, null, null);

                try
                {
                    using (new DataScope(publicationScope, culture))
                    {
                        await Task.Factory.FromAsync((a, b) => asyncHandler.BeginProcessRequest(httpContext, a, b), asyncHandler.EndProcessRequest, null);
                    }
                }
                catch (HttpException httpException)
                {
                    if (httpException.GetHttpCode() == 404)
                    {
                        return(null);
                    }

                    // TODO: embed exception with the route path

                    throw;
                }

                xhtml = writer.ToString();
            }

            return(ParseOutput(xhtml));
        }
 public IPageUrlBuilder CreateUrlBuilder(PublicationScope publicationScope, CultureInfo localizationScope, UrlSpace urlSpace)
 {
     return(new PageUrlBuilder(publicationScope, localizationScope, urlSpace));
 }
Example #34
0
 /// <exclude />
 public static DataScopeIdentifier FromPublicationScope(PublicationScope publicationScope)
 {
     return publicationScope == PublicationScope.Published ? Public : Administrated;
 }
Example #35
0
 /// <exclude />
 public PageUrl(PublicationScope publicationScope, CultureInfo locale, Guid pageId) :
     this(publicationScope, locale, pageId, PageUrlType.Undefined)
 {
 }
 /// <exclude />
 public PageDataConnectionImplementation(PublicationScope scope, CultureInfo locale)
 {
     InitializeScope(scope, locale);
 }
 public static IPageUrlBuilder GetPageUrlBuilder(PublicationScope publicationScope, CultureInfo localizationScope, UrlSpace urlSpace)
 {
     return GetMap(publicationScope, localizationScope, urlSpace).PageUrlBuilder;
 }
Example #38
0
        private static Tuple<PublicationScope, string, string> GetScopeKey(PublicationScope publicationScope, CultureInfo cultureInfo, UrlSpace urlSpace)
        {
            string hostnameScopeKey = urlSpace.ForceRelativeUrls ? "relative urls" : urlSpace.Hostname;

            return new Tuple<PublicationScope, string, string>(publicationScope, cultureInfo.Name, hostnameScopeKey);
        }
Example #39
0
 private static Map GetMap(PublicationScope publicationScope, CultureInfo localizationScope)
 {
     return GetMap(publicationScope, localizationScope, new UrlSpace());
 }
Example #40
0
        /// <summary>
        /// Fires the <see cref="EventTopic"/>.
        /// </summary>
        /// <param name="sender">The object that acts as the sender of the event to the subscribers.</param>
        /// <param name="e">An <see cref="EventArgs"/> instance to be passed to the subscribers.</param>
        /// <param name="workItem">The <see cref="WorkItem"/> where the object firing the event is.</param>
        /// <param name="scope">A <see cref="PublicationScope"/> value stating the scope of the firing behavior.</param>
        public virtual void Fire(object sender, EventArgs e, WorkItem workItem, PublicationScope scope)
        {
            Guard.EnumValueIsDefined(typeof(PublicationScope), scope, "scope");

            if (enabled)
            {
                if (traceSource != null)
                    traceSource.TraceInformation(Properties.Resources.EventTopicTraceFireStarted, name);

                Clean();

                switch (scope)
                {
                    case PublicationScope.WorkItem:
                        CallSubscriptionHandlers(sender, e, GetWorkItemHandlers(workItem));
                        break;
                    case PublicationScope.Global:
                        CallSubscriptionHandlers(sender, e, GetAllHandlers());
                        break;
                    case PublicationScope.Descendants:
                        CallSubscriptionHandlers(sender, e, GetDescendantsHandlers(workItem));
                        break;
                    default:
                        throw new ArgumentException(Properties.Resources.InvalidPublicationScope);
                }

                if (traceSource != null)
                    traceSource.TraceInformation(Properties.Resources.EventTopicTraceFireCompleted, name);
            }
        }
Example #41
0
 /// <exclude />
 public DataScope(PublicationScope publicationScope)
     : this(DataScopeIdentifier.FromPublicationScope(publicationScope), null)
 {
 }
Example #42
0
        /// <summary>
        /// Adds a publication to the topic.
        /// </summary>
        /// <param name="publisher">The object that publishes the event that will fire the topic.</param>
        /// <param name="eventName">The name of the event.</param>
        /// <param name="workItem">The <see cref="WorkItem"/> where the publisher is.</param>
        /// <param name="scope">A <see cref="PublicationScope"/> value which states scope for the publication.</param>
        public virtual void AddPublication(object publisher, string eventName, WorkItem workItem, PublicationScope scope)
        {
            Guard.ArgumentNotNull(publisher, "publisher");
            Guard.ArgumentNotNullOrEmptyString(eventName, "eventName");
            Guard.ArgumentNotNull(workItem, "workItem");
            Guard.EnumValueIsDefined(typeof(PublicationScope), scope, "scope");
            Clean();
            ThrowIfRepeatedPublication(publisher, eventName);

            Publication publication = new Publication(this, publisher, eventName, workItem, scope);

            publications.Add(publication);

            if (traceSource != null)
                traceSource.TraceInformation(Properties.Resources.EventTopicTracePublicationAdded,
                    name, eventName, publisher.GetType().ToString());
        }
Example #43
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="publicationScope">Publication scope</param>
 /// <param name="cultureInfo">null for default culture</param>
 public DataScope(PublicationScope publicationScope, CultureInfo cultureInfo)
     : this(DataScopeIdentifier.FromPublicationScope(publicationScope), cultureInfo)
 {
 }
Example #44
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PageUrlData"/> class.
 /// </summary>
 /// <param name="pageId">The page id.</param>
 /// <param name="publicationScope">The publication scope.</param>
 /// <param name="localizationScope">The localization scope.</param>
 public PageUrlData(Guid pageId, PublicationScope publicationScope, CultureInfo localizationScope)
 {
     PageId            = pageId;
     PublicationScope  = publicationScope;
     LocalizationScope = localizationScope;
 }
Example #45
0
 public override void Fire(object sender, EventArgs e, WorkItem workItem, PublicationScope scope)
 {
     FireCalled = true;
     base.Fire(sender, e, workItem, scope);
 }
Example #46
0
        private PageUrlData ParsePagePath(string pagePath, PublicationScope publicationScope, CultureInfo locale, IHostnameBinding hostnameBinding)
        {
            // Parshing what's left:
            // [/Path to a page][UrlSuffix]{/PathInfo}
            string pathInfo = null;

            bool canBePublicUrl = true;
            bool pathInfoExctracted = false;

            if (!string.IsNullOrEmpty(UrlSuffix))
            {
                string urlSuffixPlusSlash = UrlSuffix + "/";

                int suffixOffset = pagePath.IndexOf(urlSuffixPlusSlash, StringComparison.OrdinalIgnoreCase);
                if (suffixOffset > 0)
                {
                    pathInfo = pagePath.Substring(suffixOffset + UrlSuffix.Length);
                    pagePath = pagePath.Substring(0, suffixOffset);

                    pathInfoExctracted = true;
                }
                else if (pagePath.EndsWith(UrlSuffix, StringComparison.OrdinalIgnoreCase))
                {
                    pagePath = pagePath.Substring(0, pagePath.Length - UrlSuffix.Length);

                    pathInfoExctracted = true;
                }
                else
                {
                    canBePublicUrl = pagePath == "/"; // Only root page may not have a UrlSuffix
                }
            }

            if (canBePublicUrl)
            {
                Guid? pageId = TryGetPageByUrlTitlePath(pagePath, pathInfoExctracted, hostnameBinding, ref pathInfo);

                if (pageId != null && pageId != Guid.Empty)
                {
                    return new PageUrlData(pageId.Value, publicationScope, locale) { PathInfo = pathInfo};
                }
            }

            return null;
        }
Example #47
0
 public IPageUrlBuilder CreateUrlBuilder(PublicationScope publicationScope, CultureInfo localizationScope, UrlSpace urlSpace)
 {
     return new PageUrlBuilder(publicationScope, localizationScope, urlSpace);
 }
 private static string GetLegacyPublicationScopeIdentifier(PublicationScope publicationScope)
 {
     return(publicationScope == PublicationScope.Published ? "public" : "administrated");
 }
Example #49
0
 private static string GetLegacyPublicationScopeIdentifier(PublicationScope publicationScope)
 {
     return publicationScope == PublicationScope.Published ? "public" : "administrated";
 }
Example #50
0
        private async Task<XhtmlDocument> ExecuteRouteAsync(RouteData routeData, HttpContext parentContext, CultureInfo culture, PublicationScope publicationScope)
        {
            if (HttpContext.Current == null)
            {
                HttpContext.Current = parentContext;
            }

            Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture = culture;

            string xhtml;

            using (var writer = new StringWriter())
            {
                var httpResponse = new HttpResponse(writer);
                var httpContext = new HttpContext(parentContext.Request, httpResponse);
                var requestContext = new RequestContext(new HttpContextWrapper(httpContext), routeData);

                CopyHttpContextData(parentContext, httpContext);

                var handler = routeData.RouteHandler.GetHttpHandler(requestContext);
                Verify.IsNotNull(handler, "No handler found for the function '{0}'", Namespace + "." + Name);

                var asyncHandler = handler as IHttpAsyncHandler;
                Verify.IsNotNull(asyncHandler, "The handler class '{0}' does not implement IHttpAsyncHandler interface", handler.GetType());

                // var asyncResult = asyncHandler.BeginProcessRequest(httpContext, null, null);

                try
                {
                    using (new DataScope(publicationScope, culture))
                    {
                        await Task.Factory.FromAsync((a, b) => asyncHandler.BeginProcessRequest(httpContext, a, b), asyncHandler.EndProcessRequest, null);
                    }
                }
                catch (HttpException httpException)
                {
                    if (httpException.GetHttpCode() == 404)
                    {
                        return null;
                    }

                    // TODO: embed exception with the route path

                    throw;
                }

                xhtml = writer.ToString();
            }

            return ParseOutput(xhtml);
        }
Example #51
0
 /// <summary>
 /// Documentation pending
 /// </summary>
 /// <param name="scope"></param>
 /// <param name="locale"></param>
 protected void InitializeScope(PublicationScope scope, CultureInfo locale)
 {
     this.PublicationScope = scope;
     SetDataScopeIdentifier(scope);
     this.Locale = locale;
 }
Example #52
0
        private static Map GetMap(PublicationScope publicationScope, CultureInfo localizationScope, UrlSpace urlSpace)
        {
            Verify.ArgumentNotNull(localizationScope, "localizationScope");
            Verify.ArgumentNotNull(urlSpace, "urlSpace");

            if (System.Transactions.Transaction.Current != null)
            {
                var exceptionToLog = new Exception("It is not safe to use PageStructureInfo/SiteMap functionality in transactional context. Method Composite.Data.PageManager can be used instead.");
                Log.LogWarning(typeof(PageStructureInfo).Name, exceptionToLog);
            }

            var scopeKey = GetScopeKey(publicationScope, localizationScope, urlSpace);
            Map map = _generatedMaps[scopeKey];

            if (map != null)
            {
                return map;
            }

            // Using different sync roots for different datascopes
            //object buildingLock = _buildingLock[scopeKey.First == DataScopeIdentifier.Public.Name ? 0 : 1];

            // NOTE: Do not using a lock because it could because GetAssociatedPageIds is used inside transactions on some sites and it causes deadlocks 

            // lock (buildingLock)
            {
                map = _generatedMaps[scopeKey];
                if (map != null)
                {
                    return map;
                }


                Version version = _versions[scopeKey];
                if (version == null)
                {
                    lock (_updatingLock)
                    {
                        version = _versions[scopeKey];
                        if (version == null)
                        {
                            _versions.Add(scopeKey, version = new Version());
                        }
                    }
                }

                Thread.MemoryBarrier();
                int currentVersion = version.VersionNumber;
                Thread.MemoryBarrier();

                using(new DataScope(publicationScope, localizationScope))
                {
                    map = BuildMap(urlSpace);
                }

                lock (_updatingLock)
                {
                    if (_versions[scopeKey].VersionNumber == currentVersion)
                    {
                        _generatedMaps.Remove(scopeKey);
                        _generatedMaps.Add(scopeKey, map);
                    }
                }

                return map;
            }
        }
Example #53
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PageUrlData"/> class.
 /// </summary>
 /// <param name="pageId">The page id.</param>
 /// <param name="publicationScope">The publication scope.</param>
 /// <param name="localizationScope">The localization scope.</param>
 public PageUrlData(Guid pageId, PublicationScope publicationScope, CultureInfo localizationScope)
 {
     PageId = pageId;
     PublicationScope = publicationScope;
     LocalizationScope = localizationScope;
 }