Beispiel #1
0
        /// <summary>
        /// Helper method to setup the pager
        /// </summary>
        private void SetupPager()
        {
            spPager.RecordCount             = (int)this.TotalNumberOfResults;
            spPager.RecordsPerPage          = ItemsPerPage;
            spPager.RecordsPerPageParamName = "pageunit";
            spPager.CurrentPage             = CurrentPage;
            spPager.PageParamName           = "page";
            spPager.ShowNumPages            = 2;
            spPager.PagerStyleSettings.SelectedIndexCssClass = "pager-SelectedPage";

            //"Serialize" OldKeywords to string
            if (OldKeywords.Count > 0)
            {
                spPager.BaseUrl = string.Format(
                    "{0}?swKeyword={1}&old_keywords={2}",
                    PageInstruction.GetUrl("PrettyUrl").UriStem,
                    Server.UrlEncode(Keyword),
                    Server.UrlEncode(OldKeywordsForQuery));
            }
            else
            {
                spPager.BaseUrl = string.Format(
                    "{0}?swKeyword={1}",
                    PageInstruction.GetUrl("PrettyUrl").UriStem,
                    Server.UrlEncode(Keyword));
            }

            if (PageDisplayInformation.Language == DisplayLanguage.Spanish)
            {
                spPager.BaseUrl += "&lang=spanish";
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            SetupCanonicalUrl(this.DictionaryRouter.GetBaseURL());
            GetDefinitionTerm();
            ValidateCDRID();

            //For Genetics dictionary language is always English
            DictionaryLanguage = "en";

            DictionaryAppManager _dictionaryAppManager = new DictionaryAppManager();

            DictionaryTerm dataItem = _dictionaryAppManager.GetTerm(Convert.ToInt32(CdrID), NCI.Web.Dictionary.DictionaryType.genetic, DictionaryLanguage, "v1");

            if (dataItem != null && dataItem.Term != null)
            {
                ActivateDefinitionView(dataItem);
                currentItem = dataItem;
                // Web Analytics *************************************************
                if (WebAnalyticsOptions.IsEnabled)
                {
                    // Set analytics for definition view page load
                    SetAnalytics();
                }

                PageInstruction.AddFieldFilter("browser_title", (name, data) =>
                {
                    data.Value = "Definition of " + dataItem.Term + " - NCI Dictionary of Genetics Terms";
                });
            }
            else
            {
                termDictionaryDefinitionView.Visible = false;
            }
        }
 // Sets the current page to not index for SEO
 private void SetDoNotIndex()
 {
     PageInstruction.AddFieldFilter("meta_robots", (name, data) =>
     {
         data.Value = "noindex, nofollow";
     });
 }
Beispiel #4
0
        private void SetupFieldAndUrlFilters(ClinicalTrial trial)
        {
            // Copying the Title & Short Title logic from Advanced Form
            //set the page title as the protocol title
            PageInstruction.AddFieldFilter("long_title", (fieldName, data) =>
            {
                data.Value = trial.BriefTitle;
            });

            PageInstruction.AddFieldFilter("short_title", (fieldName, data) =>
            {
                data.Value = trial.BriefTitle;

                //Eh, When would this happen???
                if (!string.IsNullOrWhiteSpace(trial.NCTID))
                {
                    data.Value += " - " + trial.NCTID;
                }
            });


            PageInstruction.AddFieldFilter("meta_description", (fieldname, data) =>
            {
                data.Value = trial.BriefTitle;
            });



            PageInstruction.AddUrlFilter("CurrentUrl", (name, url) =>
            {
                //Copy the params
                //TODO: Really determine what to do with these params.  If the search is invalid, we probably
                //hsould not show them all.
                foreach (KeyValuePair <string, string> param in this.ParsedReqUrlParams.QueryParameters)
                {
                    url.QueryParameters.Add(param.Key, param.Value);
                }
            });

            PageInstruction.AddUrlFilter("CanonicalUrl", (name, url) =>
            {
                // only the id should be provided for the canonical URL, so clear all query parameters and
                // then add back id
                url.QueryParameters.Clear();
                url.QueryParameters.Add("id", trial.NCIID);
                //url.QueryParameters.Add("id", TrialID);
            });

            // Override the social media URL (og:url)
            PageInstruction.AddFieldFilter("og:url", (fieldName, data) =>
            {
                //Ok, this is weird, but...  The OpenGraph URL is actually a field. It kind of makes sense,
                //and it kind of does not.  Really it should be a field that gets the og:url instead of the
                //pretty URL.
                //BUt here we are, and it is what we have.  So let's replace the og:url with the canonical URL.

                data.Value = PageInstruction.GetUrl(NCI.Web.CDE.PageAssemblyInstructionUrls.CanonicalUrl).ToString();
            });
        }
        public IPProxyCartridgeBase(string targetPageUrlPattern, PageInstruction pgInstruction, int startPageNo)
            : base(100, true, true, false)
        {
            IPProxies            = new List <IPProxy>();
            TargetPageUrlPattern = targetPageUrlPattern;
            PageInstruction      = pgInstruction;
            AgentStatus          = IPProxyAgentStatusEnum.Idle;
            PageNo = startPageNo == 0 ? 1 : startPageNo;

            var service = PhantomJSDriverService.CreateDefaultService(".\\");

            service.HideCommandPromptWindow = true;

            _driver = new PhantomJSDriver(service);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="pgInstruction"></param>
        /// <param name="pgNo"></param>
        /// <returns></returns>
        public static string PageNo(this PageInstruction pgInstruction, int pgNo)
        {
            if (pgNo.ToString().Length > pgInstruction.PadLength)
            {
                throw new InvalidOperationException(
                          "Page number character length exceeds page instruction pad length.");
            }
            var _pgNo = pgNo.ToString();

            if (pgInstruction.PaddingDirection == PaddingDirectionsEnum.ToLeft)
            {
                return(_pgNo.PadLeft(pgInstruction.PadLength, pgInstruction.PadCharacter));
            }
            else
            {
                return(_pgNo.PadRight(pgInstruction.PadLength, pgInstruction.PadCharacter));
            }
        }
Beispiel #7
0
        private int PrepareNumberForPaging(string numberStr, string paramName, IReadOnlyDictionary <string, int> specialValues = null)
        {
            if (_pageInstruction == null)
            {
                _pageInstruction = new PageInstruction();
            }

            if (specialValues != null && specialValues.ContainsKey(numberStr))
            {
                return(specialValues[numberStr]);
            }

            if (!int.TryParse(numberStr, out int number))
            {
                throw new FormatException("Page " + paramName + " argument cannot be parsed as an integer.");
            }

            return(number);
        }
Beispiel #8
0
        /// <summary>
        ///    Sets the meta tag description. The function checks if the Dictionary Term has a valid (not null and length greater than 0) definition.
        ///    If it is the case the function attempts to extract the first two sentences of the Definition and set them as the meta tag description.
        ///    If not, we revert to using the term itself has the meta tag description.
        ///
        ///    AUTHOR: CHRISTIAN RIKONG
        ///    LAST PUBLISHED DATE: 12/08/2017 11:47 AM
        /// </summary>
        /// <param name="dataItem">Stores the Dictionary Term that is used to create the description meta tag</param>
        private void SetMetaTagDescription(DictionaryTerm dataItem, string DictionaryLanguage)
        {
            string termName = dataItem.Term;

            if (dataItem.Definition != null && dataItem.Definition.Text != null && dataItem.Definition.Text.Length > 0)
            {
                string   sentences            = "";
                string[] definitionsSentences = System.Text.RegularExpressions.Regex.Split(dataItem.Definition.Text, @"(?<=[\.!\?])\s+");


                if (definitionsSentences != null && definitionsSentences.Length > 0)
                {
                    int sentencesCount = 0;

                    foreach (string existingSentence in definitionsSentences)
                    {
                        sentencesCount = sentencesCount + 1;

                        if (sentencesCount <= 2)
                        {
                            sentences = sentences + existingSentence + ". ";
                        }
                        else
                        {
                            break;
                        }
                    }

                    PageInstruction.AddFieldFilter("meta_description", (name, data) =>
                    {
                        data.Value = sentences;
                    });
                }
                else
                {
                    SetMetaTagDescriptionToTerm(PageInstruction, termName, DictionaryLanguage);
                }
            }
            else
            {
                SetMetaTagDescriptionToTerm(PageInstruction, termName, DictionaryLanguage);
            }
        }
Beispiel #9
0
        // Activate definition view for given term
        private void ActivateDefinitionView(DictionaryTerm dataItem)
        {
            var myDataSource = new List <DictionaryTerm> {
                dataItem
            };

            termDictionaryDefinitionView.Visible    = true;
            termDictionaryDefinitionView.DataSource = myDataSource;
            termDictionaryDefinitionView.DataBind();

            string termName = dataItem.Term;

            CdrID = dataItem.ID.ToString();

            if (DictionaryLanguage == "es")
            {
                PageInstruction.AddFieldFilter("browser_title", (name, data) =>
                {
                    data.Value = "Definici&oacute;n de " + termName + " - Diccionario de c&aacute;ncer";
                });

                this.Page.Title = PageInstruction.GetField("short_title");

                DictionaryDefinitionHelper.SetMetaTagDescription(dataItem, DictionaryLanguage, PageInstruction);
            }
            else
            {
                PageInstruction.AddFieldFilter("browser_title", (name, data) =>
                {
                    data.Value = "Definition of " + termName + " - NCI Dictionary of Cancer Terms";
                });

                //CHANGE MADE BY CHRISTIAN RIKONG ON 12/08/2017 AT 11:47 AM
                DictionaryDefinitionHelper.SetMetaTagDescription(dataItem, DictionaryLanguage, PageInstruction);
            }

            PageInstruction.AddFieldFilter("meta_keywords", (name, data) =>
            {
                data.Value = termName + ", definition";
            });
        }
Beispiel #10
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            fillFormattedDate();

            //set the page title as the protocol title
            PageInstruction.AddFieldFilter("long_title", (fieldName, data) =>
            {
                if (formattedDate == String.Empty)
                {
                    data.Value = String.Format((PageInstruction.Language == "es" ? espanolArchiveFormat : englishArchiveFormat),
                                               (String.IsNullOrEmpty(PageInstruction.GetField("short_title")) ? data.Value : PageInstruction.GetField("short_title")));
                }
                else
                {
                    data.Value = String.Format((PageInstruction.Language == "es" ? espanolDateFormat : englishDateFormat),
                                               (String.IsNullOrEmpty(PageInstruction.GetField("short_title")) ? data.Value : PageInstruction.GetField("short_title")), formattedDate);
                }
            });
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="proxy"></param>
        public void GrabFirstOrNextPage(IPProxy proxy = null)
        {
            if (AgentStatus != IPProxyAgentStatusEnum.Idle)
            {
                return;
            }

            var pgNo = PageNo.ToString();

            if (PageInstruction != null)
            {
                pgNo = PageInstruction.PageNo(PageNo);
            }
            TargetPgUrl = TargetPageUrlPattern.Replace("{PAGENO}", pgNo);

            AgentStatus = IPProxyAgentStatusEnum.Reading;
            InvokeEventFreeIPProxiesReading(new EventHandlers.FreeIPProxiesReadingEventArgs(TargetPgUrl));

            // Get the html response called from the url
            var contentDoc = ScraperBoxHelper.GrabPage(_driver as PhantomJSDriver, TargetPgUrl, proxy?.AsTuple());

            ValidatePage(contentDoc);
            if (!PageIsValid)
            {
                AgentStatus = IPProxyAgentStatusEnum.Completed;
                InvokeEventFreeIPProviderSourceCompleted(new EventHandlers.FreeIPProviderSourceCompletedEventArgs(PageNo));
                base.Shutdown();
                return;
            }

            // have the inheriting class parse the html result
            ParseProxyPage(contentDoc);
            TotalPagesScraped++;

            // increase the page no for next use.
            PageNo++;
        }
Beispiel #12
0
        public PageLinks Calculate(PageInstruction instruction, PageDetails details)
        {
            if (details == null || !details.HasNextPage)
            {
                return(null);
            }

            switch (_configuration.SuggestedNavigationType)
            {
            case PageNavigationType.PageNumber:
                return(new PageLinks
                {
                    Next = new PageInstruction
                    {
                        PageNumber = instruction.PageNumber + 1,
                        Size = instruction.Size
                    }
                });

            case PageNavigationType.Offset:
                return(new PageLinks
                {
                    Next = new PageInstruction
                    {
                        Offset = instruction.Offset + instruction.Size,
                        Size = instruction.Size
                    }
                });

            case PageNavigationType.SortAndFilter:
                throw new NotImplementedException("Not implemented next page URL for sort and filter strategy.");

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        public string GetPageUrl(PageInstruction pageInstruction)
        {
            var builder = new StringBuilder();

            builder.Append(_resourcePath);
            builder.Append('?');

            if (pageInstruction.PageNumber.HasValue)
            {
                builder.AppendFormat("page={0}&", pageInstruction.PageNumber.Value);
            }

            if (pageInstruction.Offset.HasValue)
            {
                builder.AppendFormat("offset={0}&", pageInstruction.Offset.Value);
            }

            if (pageInstruction.Size.HasValue)
            {
                builder.AppendFormat("size={0}&", pageInstruction.Size.Value);
            }

            return(builder.ToString(0, builder.Length - 1));
        }
Beispiel #14
0
        /// <summary>
        /// Goes and fetches the data from the API & Returns the results to base class to be bound to the template.
        /// </summary>
        /// <returns></returns>
        protected override object GetDataForTemplate()
        {
            //TODO: Don't do a search if there are param errors.
            if (SearchParams.HasInvalidParams() == true)
            {
                _results = new ClinicalTrialsCollection();
                _results.TotalResults = 0;
            }

            else
            {
                _results = CTSManager.Search(SearchParams, this.PageNum, this.ItemsPerPage);
            }

            //Let's setup some helpful items for the template, so they do not need to be helper functions
            //The start is either 0 if there are no results, or a 1 based offset based on Page number and items per page.
            int startItemNumber = _results.TotalResults == 0 ? _results.TotalResults : ((this.PageNum - 1) * this.ItemsPerPage) + 1;

            //Determine the last item.
            long lastItemNumber = (this.PageNum * this.ItemsPerPage);

            if (lastItemNumber > _results.TotalResults)
            {
                lastItemNumber = _results.TotalResults;
            }

            //Determine the max page
            int maxPage = (int)Math.Ceiling((double)_results.TotalResults / (double)this.ItemsPerPage);

            // Add URL filters
            PageInstruction.AddUrlFilter("CurrentUrl", (name, url) =>
            {
                //Convert the current search parameters into a NciUrl
                NciUrl paramsUrl = CTSSearchParamFactory.ConvertParamsToUrl(this.SearchParams);

                //Add or replace the currentURL params based on the *validated* query params.
                foreach (KeyValuePair <string, string> qp in paramsUrl.QueryParameters)
                {
                    if (!url.QueryParameters.ContainsKey(qp.Key))
                    {
                        url.QueryParameters.Add(qp.Key, qp.Value);
                    }
                    else
                    {
                        url.QueryParameters[qp.Key] = qp.Value;
                    }
                }

                url.QueryParameters.Add("ni", this.ItemsPerPage.ToString());
            });


            //Return the object for binding.
            return(new
            {
                Results = _results,
                Control = this,
                Parameters = SearchParams,
                PageInfo = new {
                    CurrentPage = this.PageNum,
                    MaxPage = maxPage,
                    ItemsPerPage = this.ItemsPerPage,
                    StartItemNumber = startItemNumber,
                    LastItemNumber = lastItemNumber
                },
                TrialTools = new TrialVelocityTools()
            });
        }
 public QueryablePager([CanBeNull] PageInstruction pageInstruction)
 {
     _pageInstruction = pageInstruction;
 }
Beispiel #16
0
        /// <summary>
        /// Helper method to setup the pager
        /// </summary>
        protected virtual void SetupPager(int recordsPerPage, int totalRecordCount, Dictionary <string, string> urlFilters)
        {
            SimplePager pager = new SimplePager();

            pager.RecordCount    = totalRecordCount;
            pager.RecordsPerPage = recordsPerPage;
            pager.CurrentPage    = CurrentPage;
            pager.PageParamName  = "page";
            pager.PagerStyleSettings.SelectedIndexCssClass = "pager-SelectedPage";
            pager.BaseUrl = PageInstruction.GetUrl(PageAssemblyInstructionUrls.PrettyUrl).ToString();

            string searchQueryParams = string.Empty;

            if (this.SearchList.SearchType.ToLower() == "keyword" || this.SearchList.SearchType.ToLower() == "keyword_with_date")
            {
                searchQueryParams = "?keyword=" + Server.HtmlEncode(KeyWords);
            }
            if (this.SearchList.SearchType.ToLower() == "date" || this.SearchList.SearchType.ToLower() == "keyword_with_date")
            {
                if (string.IsNullOrEmpty(searchQueryParams))
                {
                    searchQueryParams = "?";
                }
                else
                {
                    searchQueryParams += "&";
                }
                if (StartDate != DateTime.MinValue && EndDate != DateTime.MaxValue)
                {
                    searchQueryParams += string.Format("startMonth={0}&startyear={1}&endMonth={2}&endYear={3}", StartDate.Month, StartDate.Year, EndDate.Month, EndDate.Year);
                }
                else
                {
                    searchQueryParams += "startMonth=&startyear=&endMonth=&endYear=";
                }
            }

            foreach (KeyValuePair <string, string> entry in urlFilters)
            {
                if (string.IsNullOrEmpty(searchQueryParams))
                {
                    searchQueryParams = "?";
                }
                else
                {
                    searchQueryParams += "&";
                }

                searchQueryParams += string.Format("filter[{0}]={1}", entry.Key, entry.Value);
            }


            pager.BaseUrl += searchQueryParams;

            Controls.Add(pager);

            // check for existence of previous and and next urls
            string prevUrl = pager.GetPrevLinkUrl();
            string nextUrl = pager.GetNextLinkUrl();

            if (prevUrl != null)
            {
                this.PageInstruction.AddUrlFilter("RelPrev", (name, url) =>
                {
                    url.SetUrl(prevUrl);
                });
            }

            if (nextUrl != null)
            {
                this.PageInstruction.AddUrlFilter("RelNext", (name, url) =>
                {
                    url.SetUrl(nextUrl);
                });
            }
        }
Beispiel #17
0
        protected virtual void SetupBlogPager(int recordsPerPage, int totalRecordCount, Dictionary <string, string> urlFilters)
        {
            BlogPager blogLandingPager = new BlogPager();
            int       currentPage      = 0;

            string olderText = "< Older Posts";
            string newerText = "Newer Posts >";

            if (PageAssemblyContext.Current.PageAssemblyInstruction.GetField("Language") == "es")
            {
                olderText = "< Artículos anteriores";
                newerText = "Artículos siguientes >";
            }

            blogLandingPager.RecordCount    = totalRecordCount;
            blogLandingPager.RecordsPerPage = recordsPerPage;
            if (string.IsNullOrEmpty(this.Page.Request.Params["page"]))
            {
                currentPage = 1;
            }
            else
            {
                currentPage = Int32.Parse(this.Page.Request.Params["page"]);
            }

            blogLandingPager.CurrentPage   = currentPage;
            blogLandingPager.BaseUrl       = PageInstruction.GetUrl(PageAssemblyInstructionUrls.PrettyUrl).ToString();
            blogLandingPager.PageParamName = "page";
            blogLandingPager.CssClass      = "blog-pager clearfix";
            blogLandingPager.PagerStyleSettings.NextPageCssClass = "older";
            blogLandingPager.PagerStyleSettings.NextPageText     = olderText;
            blogLandingPager.PagerStyleSettings.PrevPageCssClass = "newer";
            blogLandingPager.PagerStyleSettings.PrevPageText     = newerText;


            string searchQueryParams = string.Empty;

            if (this.SearchList.SearchType.ToLower() == "keyword" || this.SearchList.SearchType.ToLower() == "keyword_with_date")
            {
                searchQueryParams = "?keyword=" + Server.HtmlEncode(KeyWords);
            }
            if (this.SearchList.SearchType.ToLower() == "date" || this.SearchList.SearchType.ToLower() == "keyword_with_date")
            {
                if (string.IsNullOrEmpty(searchQueryParams))
                {
                    searchQueryParams = "?";
                }
                else
                {
                    searchQueryParams += "&";
                }
                if (StartDate != DateTime.MinValue && EndDate != DateTime.MaxValue)
                {
                    searchQueryParams += string.Format("startMonth={0}&startyear={1}&endMonth={2}&endYear={3}", StartDate.Month, StartDate.Year, EndDate.Month, EndDate.Year);
                }
                else
                {
                    searchQueryParams += "startMonth=&startyear=&endMonth=&endYear=";
                }
            }

            foreach (KeyValuePair <string, string> entry in urlFilters)
            {
                if (string.IsNullOrEmpty(searchQueryParams))
                {
                    searchQueryParams = "?";
                }
                else
                {
                    searchQueryParams += "&";
                }

                searchQueryParams += string.Format("filter[{0}]={1}", entry.Key, entry.Value);
            }

            blogLandingPager.BaseUrl += searchQueryParams;

            Controls.Add(blogLandingPager);

            // check for existence of previous and and next urls
            string prevUrl = blogLandingPager.GetPrevLinkUrl();
            string nextUrl = blogLandingPager.GetNextLinkUrl();

            if (prevUrl != null)
            {
                this.PageInstruction.AddUrlFilter("RelPrev", (name, url) =>
                {
                    url.SetUrl(prevUrl);
                });
            }

            if (nextUrl != null)
            {
                this.PageInstruction.AddUrlFilter("RelNext", (name, url) =>
                {
                    url.SetUrl(nextUrl);
                });
            }
        }
 public IPProxyCartridgeBase(string targetPageUrlPattern, PageInstruction pgInstruction)
     : this(targetPageUrlPattern, pgInstruction, 0)
 {
 }