Example #1
0
 private void Reset(SearchDataProvider currentSearchDP, DateTime currentSearchStarted)
 {
     CurrentSearchDP       = currentSearchDP;
     CurrentSearchStarted  = currentSearchStarted;
     CurrentUrl            = null;
     CurrentPageSecurity   = PageDefinition.PageSecurityType.Any;
     CurrentAllowAnonymous = false;
     CurrentAllowAnyUser   = false;
     CurrentDateCreated    = DateTime.MinValue;
     CurrentDateUpdated    = null;
     CurrentSearchData     = new List <SearchData>();
     CurrentCustomData     = null;
 }
Example #2
0
            public async Task <bool> SetUrlAsync(string url, PageDefinition.PageSecurityType pageSecurity, MultiString title, MultiString summary, DateTime dateCreated, DateTime?dateUpdated, bool allowAnonymous, bool allowUser, string customData)
            {
                YetaWFManager manager = YetaWFManager.Manager;

                if (CurrentUrl != null)
                {
                    throw new InternalError("Already have an active Url - {nameof(SetUrlAsync)} {url} called");
                }
                if (!url.StartsWith("/"))
                {
                    throw new InternalError("Urls for search terms must be local and start with \"/\"");
                }
                CurrentPageSecurity   = pageSecurity;
                CurrentAllowAnonymous = allowAnonymous;
                CurrentAllowAnyUser   = allowUser;
                CurrentTitle          = title;
                CurrentSummary        = summary;
                CurrentDateCreated    = dateCreated;
                CurrentDateUpdated    = dateUpdated;
                CurrentSearchData     = new List <SearchData>();
                CurrentCustomData     = customData;
                if (!CurrentAllowAnonymous && !CurrentAllowAnyUser)
                {
                    Logging.AddLog("No search keywords for Url {0} - neither Anonymous nor User role has access to the page", url);
                    return(false);
                }
                if (!await CurrentSearchDP.PageUpdated(url, CurrentDateCreated, CurrentDateUpdated))
                {
                    Logging.AddLog("Page {0} not evaluated as it has not changed", url);
                    return(false);
                }
                CurrentUrl = url;
                Logging.AddLog("Adding search keywords for page {0}", CurrentUrl);
                AddTitle(CurrentTitle);
                AddContent(CurrentSummary);
                return(true);
            }
Example #3
0
        /// <summary>
        /// Renders an image &lt;img&gt; tag with specified attributes and returns HTML.
        /// </summary>
        /// <param name="imageType">The image type which must match a registered image handler. The YetaWF.Core.Image.ImageSupport.AddHandler method is used to register an image handler.</param>
        /// <param name="width">The width of the image. Both <paramref name="width"/> and <paramref name="height"/> may be 0, in which case no size attributes are rendered.</param>
        /// <param name="height">The height of the image. Both <paramref name="width"/> and <paramref name="height"/> may be 0, in which case no size attributes are rendered.</param>
        /// <param name="model">The model representing the image.</param>
        /// <param name="CacheBuster">A value that becomes part of the image URL, which can be used to defeat client-side caching. May be null.</param>
        /// <param name="Alt">The text that is rendered as part of the &lt;img&gt; tag's Alt attribute. May be null in which case the text "Image" is used.</param>
        /// <param name="ExternalUrl">Defines whether a full URL including domain is rendered (true) or whether just the path is used (false).</param>
        /// <param name="SecurityType">The security type of the rendered image URL.</param>
        /// <returns></returns>
        public static string RenderImage(string imageType, int width, int height, string model,
                                         string CacheBuster = null, string Alt = null, bool ExternalUrl = false, PageDefinition.PageSecurityType SecurityType = PageDefinition.PageSecurityType.Any)
        {
            string      url = ImageHTML.FormatUrl(imageType, null, model, width, height, CacheBuster: CacheBuster, ExternalUrl: ExternalUrl, SecurityType: SecurityType);
            YTagBuilder img = new YTagBuilder("img");

            img.AddCssClass("t_preview");
            img.Attributes.Add("src", url);
            img.Attributes.Add("alt", Alt ?? __ResStr("altImg", "Image"));
            return(img.ToString(YTagRenderMode.StartTag));
        }
Example #4
0
        public async Task <bool> AddItemsAsync(List <SearchData> list, string pageUrl, PageDefinition.PageSecurityType pageSecurity, string pageDescription, string pageSummary, DateTime pageCreated, DateTime?pageUpdated, DateTime searchStarted, string customData)
        {
            if (!IsUsable)
            {
                return(false);
            }
            bool status = false;

            using (ILockObject lockObject = await YetaWF.Core.IO.Caching.LockProvider.LockResourceAsync($"{AreaRegistration.CurrentPackage.AreaName}_{nameof(SearchDataProvider)}")) {
                if (pageUpdated != null && (DateTime)pageUpdated < pageCreated)
                {
                    pageCreated = (DateTime)pageUpdated;
                }
                using (SearchDataUrlDataProvider searchUrlDP = new SearchDataUrlDataProvider()) {
                    SearchDataUrl searchUrl = await searchUrlDP.GetItemByUrlAsync(pageUrl);

                    if (searchUrl == null)
                    {
                        searchUrl = new SearchDataUrl {
                            DatePageCreated = pageCreated,
                            DatePageUpdated = pageUpdated,
                            PageTitle       = pageDescription.Truncate(SearchDataUrl.MaxTitle),
                            PageUrl         = pageUrl,
                            PageSecurity    = pageSecurity,
                            PageSummary     = pageSummary.Truncate(SearchDataUrl.MaxSummary),
                            CustomData      = customData,
                        };
                        if (!await searchUrlDP.AddItemAsync(searchUrl))
                        {
                            throw new InternalError("Unexpected error adding SearchDataUrl for url {0}", pageUrl);
                        }
                    }
                    else
                    {
                        searchUrl.PageTitle       = pageDescription.Truncate(SearchDataUrl.MaxTitle);
                        searchUrl.PageSummary     = pageSummary.Truncate(SearchDataUrl.MaxSummary);
                        searchUrl.DatePageCreated = pageCreated;
                        searchUrl.DatePageUpdated = pageUpdated ?? pageCreated;
                        searchUrl.PageSecurity    = pageSecurity;
                        searchUrl.CustomData      = customData;
                        UpdateStatusEnum updStatus = await searchUrlDP.UpdateItemAsync(searchUrl);

                        if (updStatus != UpdateStatusEnum.OK)
                        {
                            throw new InternalError("Unexpected error updating SearchDataUrl for url {0} - {1}", pageUrl, updStatus);
                        }
                    }
                    foreach (SearchData data in list)
                    {
                        data.SearchDataUrlId = searchUrl.SearchDataUrlId;
                        data.DateAdded       = searchStarted;
                        await AddItemAsync(data);
                    }
                }
                status = true;
                await lockObject.UnlockAsync();
            }
            return(status);
        }
Example #5
0
 public Task <bool> SetUrlAsync(string url, PageDefinition.PageSecurityType pageSecurity, MultiString title, MultiString summary, DateTime dateCreated, DateTime?dateUpdated, bool allowAnonymous, bool allowUser)
 {
     return(SetUrlAsync(url, pageSecurity, title, summary, dateCreated, dateUpdated, allowAnonymous, allowUser, null));
 }