コード例 #1
0
    // Read Action page html Content
    public List<DataContent> ReadActionHtmlContent()
    {
        List<DataContent> ListDC = new List<DataContent>();

        SqlDateTime SqlDtTime = new SqlDateTime();
        CMSHelper ObjCMSHelper = null;
        try
        {
            string PdfFileUrl = string.Empty;
            string RetPageContent = string.Empty;
            string ContentFileFullPath = string.Empty;
            string HtmlPageFullPath = string.Empty;
            string HtmlPageName = string.Empty;
            HtmlDocument document = null;
            string ContentSummary = string.Empty;
            string ContentTitle = string.Empty;
            string ContentDate = string.Empty;
            string ImgUrl = string.Empty;
            string ContentPageUrl = string.Empty;
            string UserEmailID = string.Empty;
            string DatabaseLanguage = string.Empty;
            string UserName = string.Empty;
            string CurrentDbLangCode = string.Empty;
            string CountentUrl = string.Empty;
            string ArticleTags = string.Empty;
            //get name of news html page
            HtmlPageName = this.ActionHtmlFilenamePrefix + ".html";
            document = new HtmlDocument();
            // create html page full path
            HtmlPageFullPath = Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, Constants.FolderName.DiorgContent, HtmlPageName);
            if (!File.Exists(HtmlPageFullPath))
            {
                return ListDC;
            }
            // load html page
            document.Load(HtmlPageFullPath);
            // Targets a specific node(since all the page contains parent table tag with width 700)
            HtmlNode content_wrapper = document.DocumentNode.SelectNodes("//table[@width='700']").FirstOrDefault();
            // get html news collection
            HtmlNodeCollection search_results = content_wrapper.SelectNodes("//td[@class='news_space']");
            //itterate through loop
            foreach (HtmlNode result in search_results)
            {
                DataContent Content = new DataContent();

                // get title of news
                if (result.SelectNodes(".//p//span[@class='header']") != null && !string.IsNullOrEmpty(result.SelectNodes(".//p//span[@class='header']").FirstOrDefault().InnerText))
                {
                    ContentTitle = result.SelectNodes(".//p//span[@class='header']").FirstOrDefault().InnerText.Trim();
                }
                else if (result.SelectNodes(".//span//strong//a") != null && !string.IsNullOrEmpty(result.SelectNodes(".//span//strong//a").FirstOrDefault().InnerText))
                {
                    ContentTitle = result.SelectNodes(".//span//strong//a").FirstOrDefault().InnerText.Trim();
                }
                else if (result.SelectNodes(".//p//a//strong") != null && !string.IsNullOrEmpty(result.SelectNodes(".//p//a//strong").FirstOrDefault().InnerText.Trim()))
                {
                    ContentTitle = result.SelectNodes(".//p//a//strong").FirstOrDefault().InnerText.Trim();
                }
                else if (result.SelectNodes(".//p//strong//a") != null && !string.IsNullOrEmpty(result.SelectNodes(".//p//strong//a").FirstOrDefault().InnerText.Trim()))
                {
                    ContentTitle = result.SelectNodes(".//p//strong//a").FirstOrDefault().InnerText.Trim();
                }
                else if (result.SelectNodes(".//p//a") != null && !string.IsNullOrEmpty(result.SelectNodes(".//p//a").FirstOrDefault().InnerText))
                {
                    ContentTitle = result.SelectNodes(".//p//a").FirstOrDefault().InnerText.Trim();
                }
                else if (result.SelectNodes(".//p//strong") != null && !string.IsNullOrEmpty(result.SelectNodes(".//p//strong").FirstOrDefault().InnerText))
                {
                    ContentTitle = result.SelectNodes(".//p//strong").FirstOrDefault().InnerText.Trim();
                }

                // get summary of news
                if (result.SelectNodes(".//td[@width='71%']//tr/td") != null)
                {
                    ContentSummary = result.SelectNodes(".//td[@width='71%']//tr/td").ElementAt(1).InnerText.Trim().ToString();
                }
                // get date created of news
                if (result.SelectSingleNode(".//span[@class='adaptation_italic']") != null)
                {
                    ContentDate = result.SelectSingleNode(".//span[@class='adaptation_italic']").InnerText.Replace("(", "").Replace(")", "").Trim();
                }
                // get Thumbnail url of news
                if (result.SelectNodes(".//img[@class='reflect ropacity30']") != null)
                {
                    ImgUrl = result.SelectNodes(".//img[@class='reflect ropacity30']").FirstOrDefault().GetAttributeValue("src", "").ToString();
                }
                else if (result.SelectNodes(".//td//a//img[@width='140']") != null)
                {
                    ImgUrl = result.SelectNodes(".//td//a//img[@width='140']").FirstOrDefault().GetAttributeValue("src", "").ToString();
                }
                else if (result.SelectNodes(".//img[@class='reflect ropacity30 ']") != null)
                {
                    ImgUrl = result.SelectNodes(".//img[@class='reflect ropacity30 ']").FirstOrDefault().GetAttributeValue("src", "").ToString();
                }
                if (ImgUrl.Contains("diorg/"))
                {
                    ImgUrl = ImgUrl.Replace("diorg/", "../libraries/aspx/diorg/");
                }
                // get content page of url
                if (result.SelectNodes(".//td[@width='29%']//a") != null)
                {
                    ContentPageUrl = result.SelectNodes(".//td[@width='29%']//a").FirstOrDefault().GetAttributeValue("href", "").ToString();
                }
                else if (result.SelectNodes(".//td[@width='29%']//tr/td//a") != null)
                {
                    ContentPageUrl = result.SelectNodes(".//td[@width='29%']//tr/td//a").FirstOrDefault().GetAttributeValue("href", "").ToString();
                }
                else if (result.SelectNodes(".//td[@width='28%']//a") != null)
                {
                    ContentPageUrl = result.SelectNodes(".//td[@width='28%']//a").FirstOrDefault().GetAttributeValue("href", "").ToString();
                }
                //get content of inner html page
                if (ContentPageUrl.Contains("diorg/"))
                {
                    // create full path of inner html page
                    ContentFileFullPath = Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, Constants.FolderName.DiorgContent,
                        Global.SplitString(ContentPageUrl, "diorg/")[1].ToString().Replace(@"/", "\\"));
                    // check if file exist
                    if (File.Exists(ContentFileFullPath))
                    {
                        // call method to get content of html page
                        //get pdfurl as out parameter
                        RetPageContent = GetInnerContentNPdfUrl(ContentFileFullPath, out PdfFileUrl);
                    }
                }
                // Initlize object of class cmshelper
                ObjCMSHelper = new CMSHelper();
                // remove space and ;nbsp from date
                ContentDate = ObjCMSHelper.RemoveExtraCharsFromDate(ContentDate);
                // get created date of news
                SqlDtTime = new SqlDateTime(ObjCMSHelper.GetSqlDataTimeFromInptDate(ContentDate));
                // get user email id from session
                if (!string.IsNullOrEmpty(HttpContext.Current.Session[Constants.SessionNames.LoggedAdminUserNId].ToString()))
                {
                    UserEmailID = Global.Get_User_EmailId_ByAdaptationURL(HttpContext.Current.Session[Constants.SessionNames.LoggedAdminUserNId].ToString());
                }
                // get user name from session
                if (!string.IsNullOrEmpty(HttpContext.Current.Session[Constants.SessionNames.LoggedAdminUser].ToString()))
                {
                    UserName = HttpContext.Current.Session[Constants.SessionNames.LoggedAdminUser].ToString();
                }

                // Create url from title
                CountentUrl = ObjCMSHelper.CreateUrlFromInputString(ContentTitle);

                //Get language of current database
                CurrentDbLangCode = Global.GetDefaultLanguageCode();

                // innitlize of members of class Content
                Content.MenuCategory = "Action";
                Content.Date = SqlDtTime;
                Content.DateAdded = new SqlDateTime(DateTime.Now);
                Content.DateModified = new SqlDateTime(DateTime.Now);
                Content.Description = RetPageContent;
                Content.Title = ContentTitle;
                Content.PDFUpload = PdfFileUrl;
                Content.Summary = ContentSummary;
                Content.Thumbnail = ImgUrl;
                Content.URL = CountentUrl;
                Content.Archived = false;
                Content.UserNameEmail = UserName + " " + UserEmailID;
                Content.LngCode = CurrentDbLangCode;
                Content.ArticleTagID = -1;
                Content.IsDeleted = false;
                Content.IsDeleted = false;
                // all class Content to list
                ListDC.Add(Content);
            }
        }
        catch (Exception Ex)
        {
            Global.CreateExceptionString(Ex, null);
        }
        // return list containing all html pages
        return ListDC;
    }
コード例 #2
0
    //Create Datacontent Object from Input Params
    private DataContent CreateCMSDataContent(string requestParam)
    {
        CMSHelper ObjCMSHelper = new CMSHelper();
        DataContent RetValContent = null;
        string PdfFileUrl = string.Empty;

        string ContentSummary = string.Empty;
        string ContentTitle = string.Empty;
        string ContentDate = string.Empty;
        string ContentImgUrl = string.Empty;
        string ContentPageUrl = string.Empty;
        string UserEmailID = string.Empty;
        string DatabaseLanguage = string.Empty;
        string UserName = string.Empty;
        string CurrentDbLangCode = string.Empty;
        string CountentUrl = string.Empty;
        string ArticleTags = string.Empty;
        string MenuCategory = string.Empty;
        string ContentDescription = string.Empty;
        string ContentTag = string.Empty;
        int ContentTagNid = -1;
        SqlDateTime SqlDtTime = new SqlDateTime();
        string[] Params;
        try
        {
            // split Input Params
            Params = Global.SplitString(requestParam, Constants.Delimiters.ParamDelimiter);
            // Check if session is having nid for loggedin Admin
            if (!string.IsNullOrEmpty(HttpContext.Current.Session[Constants.SessionNames.LoggedAdminUserNId].ToString()))
            {// get user email
                UserEmailID = Global.Get_User_EmailId_ByAdaptationURL(HttpContext.Current.Session[Constants.SessionNames.LoggedAdminUserNId].ToString());
            }
            // Check if session is having username for loggedin Admin
            if (!string.IsNullOrEmpty(HttpContext.Current.Session[Constants.SessionNames.LoggedAdminUser].ToString()))
            { // get user name from session
                UserName = HttpContext.Current.Session[Constants.SessionNames.LoggedAdminUser].ToString();
            }

            // Initlize RetValContent Object
            RetValContent = new DataContent();
            ContentTitle = Params[0].ToString();
            ContentDate = Params[1].ToString();
            ContentSummary = Params[2].ToString();
            ContentSummary = ContentSummary.Replace("\n", "<br/>");
            ContentDescription = Params[3].ToString().Replace("diorg/images", "../libraries/aspx/diorg/images");
            PdfFileUrl = Params[4].ToString().Replace("diorg/", "../libraries/aspx/diorg/");
            MenuCategory = Params[5].ToString();
            ContentImgUrl = Params[6].ToString().Trim().Replace("diorg/","../libraries/aspx/diorg/");
            if (Params.Length > 7)
            {
                ContentTag = Params[7].ToString().Trim();
            }
            UserEmailID = UserName + " [" + UserEmailID + " ]";

            // Create Countent Url From Title
            CountentUrl = ObjCMSHelper.CreateUrlFromInputString(ContentTitle);
            // Getb current database language
            CurrentDbLangCode = Global.GetDefaultLanguageCode();
            //Get Tag Nid
            if (!string.IsNullOrEmpty(ContentTag))
            {
                ContentTagNid = ObjCMSHelper.CreateAndGetTagNid(ContentTag.Trim());
            }
            if(string.IsNullOrEmpty(ContentDate) && MenuCategory.ToLower()!=EnumHelper.PageName.News.ToString().ToLower())
            {

                SqlDtTime=DateTime.Now.AddYears(-100);
            }
            else
            {
            //Convert Date to sql date time
            SqlDtTime = ObjCMSHelper.GetSqlDataTimeFromInptDate(ContentDate);
            }
            // innitlize of members of class Content
            RetValContent.MenuCategory = MenuCategory;
            RetValContent.Date = SqlDtTime;
            RetValContent.DateAdded = new SqlDateTime(DateTime.Now);
            RetValContent.DateModified = new SqlDateTime(DateTime.Now);
            RetValContent.Description = ContentDescription;
            RetValContent.Title = ContentTitle;
            RetValContent.PDFUpload = PdfFileUrl;
            RetValContent.Summary = ContentSummary;
            RetValContent.Thumbnail = ContentImgUrl;
            RetValContent.URL = CountentUrl;
            RetValContent.Archived = false;
            // Username email filed is combination of username and email
            RetValContent.UserNameEmail = UserName + " " + UserEmailID;
            RetValContent.LngCode = CurrentDbLangCode;
            RetValContent.ArticleTagID = ContentTagNid;
            RetValContent.IsDeleted = false;
            RetValContent.IsHidden = false;

            //Extra fields to be used in future
            RetValContent.Fld1 = string.Empty;
            RetValContent.Fld2 = string.Empty;
            RetValContent.Fld3 = string.Empty;
            RetValContent.Fld4 = string.Empty;
            RetValContent.Fld5 = string.Empty;
            RetValContent.Fld6 = string.Empty;
            RetValContent.Fld1Text = string.Empty;
            RetValContent.Fld2Text = string.Empty;
            RetValContent.Fld3Text = string.Empty;
            RetValContent.Fld4Text = string.Empty;
            RetValContent.Fld5Text = string.Empty;
            RetValContent.Fld6Text = string.Empty;
        }
        catch (Exception Ex)
        {
            RetValContent = null;
            Global.CreateExceptionString(Ex, null);
        }
        // return news object
        return RetValContent;
    }
コード例 #3
0
    // Read facts page html content
    public List<DataContent> ReadFactsHtmlContent()
    {
        List<DataContent> ListDC = new List<DataContent>();
        string PdfFileUrl = string.Empty;
        string RetPageContent = string.Empty;
        string NewsContentFullPath = string.Empty;
        string HtmlPageFullPath = string.Empty;
        string HtmlPageName = string.Empty;
        HtmlDocument document = null;
        string NewsSummary = string.Empty;
        string NewsTitle = string.Empty;
        string NewsContentDate = string.Empty;
        string ImgUrl = string.Empty;
        string ContentPageUrl = string.Empty;
        string UserEmailID = string.Empty;
        string DatabaseLanguage = string.Empty;
        string UserName = string.Empty;
        string CurrentDbLangCode = string.Empty;
        string NewsUrl = string.Empty;
        string ArticleTags = string.Empty;
        SqlDateTime SqlDtTime;
        // Initlize object of class cmshelper
        CMSHelper ObjCMSHelper = null;
        try
        {
            //get name of news html page
            HtmlPageName = this.FactsHtmlFilenamePrefix + ".html";
            document = new HtmlDocument();
            // create html page full path
            HtmlPageFullPath = Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, Constants.FolderName.DiorgContent, HtmlPageName);
            if (!File.Exists(HtmlPageFullPath))
            {
                return ListDC;
            }
            // load html page
            document.Load(HtmlPageFullPath);
            // Targets a specific node(since all the page contains parent table tag with width 700)
            HtmlNode content_wrapper = document.DocumentNode.SelectNodes("//table[@width='700']//tr//td[@height='450']").FirstOrDefault();
            // get html news collection
            if (content_wrapper.SelectNodes("//table[@width='700']//tr//td") != null)
            {
                HtmlNodeCollection SplitString = content_wrapper.SelectNodes("//div[@class='goal']");
                foreach (HtmlNode HtmlNodResult in SplitString)
                {
                    //HtmlNodResult.se
                    DataContent Content = new DataContent();

                    // Initlize object of class cmshelper
                    ObjCMSHelper = new CMSHelper();
                    // remove space and ;nbsp from date
                    NewsContentDate = ObjCMSHelper.RemoveExtraCharsFromDate(NewsContentDate);
                    // get created date of news
                    SqlDtTime = new SqlDateTime(ObjCMSHelper.GetSqlDataTimeFromInptDate(NewsContentDate));

                    // get user email id from session
                    if (!string.IsNullOrEmpty(HttpContext.Current.Session[Constants.SessionNames.LoggedAdminUserNId].ToString()))
                    {
                        UserEmailID = Global.Get_User_EmailId_ByAdaptationURL(HttpContext.Current.Session[Constants.SessionNames.LoggedAdminUserNId].ToString());
                    }
                    // get user name from session
                    if (!string.IsNullOrEmpty(HttpContext.Current.Session[Constants.SessionNames.LoggedAdminUser].ToString()))
                    {
                        UserName = HttpContext.Current.Session[Constants.SessionNames.LoggedAdminUser].ToString();
                    }

                    // Create url from title
                    NewsUrl = ObjCMSHelper.CreateUrlFromInputString(NewsTitle);

                    //Get language of current database
                    CurrentDbLangCode = Global.GetDefaultLanguageCode();

                    // innitlize of members of class Content
                    Content.Date = SqlDtTime;
                    Content.DateAdded = new SqlDateTime(DateTime.Now);
                    Content.DateModified = new SqlDateTime(DateTime.Now);
                    Content.Description = RetPageContent;
                    Content.Title = NewsTitle;
                    Content.PDFUpload = PdfFileUrl;
                    Content.Summary = NewsSummary;
                    Content.Thumbnail = ImgUrl;
                    Content.URL = NewsUrl;
                    Content.Archived = false;
                    Content.UserNameEmail = UserName + " " + UserEmailID;
                    Content.LngCode = CurrentDbLangCode;
                    Content.ArticleTagID = -1;
                    // all class Content to list
                    ListDC.Add(Content);
                }

            }
        }
        catch (Exception Ex)
        {
            Global.CreateExceptionString(Ex, null);
        }
        // return list containing all html pages
        return ListDC;
    }