示例#1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            long commentId = Int64.Parse(Request.Params.Get("commentId"));

            IUnityContainer container      = (IUnityContainer)HttpContext.Current.Application["unityContainer"];
            ICommentService commentService = container.Resolve <ICommentService>();
            ILinkService    linkService    = container.Resolve <ILinkService>();

            CommentDetails comment = commentService.GetComment(commentId);
            LinkDetails    link    = linkService.GetLink(comment.LinkId);

            lblLink.Text        = link.Name;
            lnkLink.NavigateUrl = Response.ApplyAppPathModifier("~/Pages/Link/Link.aspx?linkId=" + link.LinkId);

            lblAuthor.Text        = comment.AuthorName;
            lnkAuthor.NavigateUrl = Response.ApplyAppPathModifier("~/Pages/Comment/ListComments.aspx?userId=" + comment.AuthorId);
            lblDate.Text          = comment.Date.ToString();
            lblText.Text          = comment.Text;

            if (SessionManager.IsUserAuthenticated(Context))
            {
                long userId = SessionManager.GetUserSession(Context).UserProfileId;

                if ((userId == comment.AuthorId) || (userId == link.UserId))
                {
                    pControl.Visible = true;

                    lnkEditComment.NavigateUrl   = Response.ApplyAppPathModifier("~/Pages/Comment/EditComment.aspx?commentId=" + commentId);
                    lnkEditComment.Visible       = (userId == comment.AuthorId);
                    lnkRemoveComment.NavigateUrl = Response.ApplyAppPathModifier("~/Pages/Comment/RemoveComment.aspx?commentId=" + commentId);
                }
            }
        }
示例#2
0
        public void TestChangelogLinks(string link, string expectedArg)
        {
            LinkDetails result = MessageFormatter.GetLinkDetails(link);

            Assert.AreEqual(LinkAction.OpenChangelog, result.Action);
            Assert.AreEqual(expectedArg, result.Argument);
        }
示例#3
0
        protected void btnAddFavorite_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    IUnityContainer  container       = (IUnityContainer)HttpContext.Current.Application["unityContainer"];
                    ILinkService     linkService     = container.Resolve <ILinkService>();
                    IFavoriteService favoriteService = container.Resolve <IFavoriteService>();

                    UserSession userSession = (UserSession)this.Context.Session["userSession"];
                    long        userId      = userSession.UserProfileId;

                    LinkDetails link = linkService.GetLink(LinkId);

                    favoriteService.AddToFavorites(userId, LinkId, txtName.Text, txtDescription.Text);

                    Response.Redirect(Response.ApplyAppPathModifier("~/Pages/Favorite/ListFavorites.aspx"));
                }
                catch (DuplicateInstanceException <FavoriteDetails> )
                {
                    pError.Visible = true;
                    return;
                }
            }
        }
 public ImageShackImageInfo(Stream imageInfoXml)
 {
     Rating = new RatingDetails();
     Resolution = new ResolutionDetails();
     Links = new LinkDetails();
     ParseAndFillProperties(imageInfoXml);
 }
示例#5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            LinkId = Int64.Parse(Request.Params.Get("linkId"));

            IUnityContainer container   = (IUnityContainer)HttpContext.Current.Application["unityContainer"];
            ILinkService    linkService = container.Resolve <ILinkService>();

            LinkDetails link = linkService.GetLink(LinkId);

            MovieId = link.MovieId;

            if (!IsPostBack)
            {
                lblLinkName.Text        = link.Name;
                lnkLinkName.NavigateUrl = Response.ApplyAppPathModifier("~/Pages/Link/Link.aspx?linkId=" + LinkId);

                if (Request.UrlReferrer != null)
                {
                    lnkReturn.NavigateUrl = Response.ApplyAppPathModifier(Request.UrlReferrer.AbsoluteUri);
                }
                else
                {
                    lnkReturn.NavigateUrl = Response.ApplyAppPathModifier("~/Pages/Link/Link.aspx?linkId=" + LinkId);
                }

                if (link.Rating <= Settings.Default.WebMovies_demotedThreshold)
                {
                    pRemoveLink.CssClass += " demoted";
                }
                else if (link.Rating >= Settings.Default.WebMovies_promotedThreshold)
                {
                    pRemoveLink.CssClass += " promoted";
                }
            }
        }
示例#6
0
        public void CreatePosition(Link link, IPAddress remoteIp)
        {
            try
            {
                var ipStack = this.ipStackService.GetData(remoteIp);

                var detail = new LinkDetails(link)
                {
                    Ip            = ipStack.Ip,
                    ContinentName = ipStack.ContinentName,
                    CountryCode   = ipStack.CountryCode,
                    CountryName   = ipStack.CountryName,
                    RegionCode    = ipStack.RegionCode,
                    RegionName    = ipStack.RegionName,
                    City          = ipStack.City,
                    Latitude      = ipStack.Latitude,
                    Longitude     = ipStack.Longitude,
                    CountryEmoji  = ipStack.Location.CountryFlagEmoji,
                    Date          = DateTime.UtcNow,
                };

                this.mongoDBService.LinkDetails.InsertOne(detail);
            }
            catch (System.Exception)
            {
                // TODO: Log error
            }
        }
示例#7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            CommentId = Int64.Parse(Request.Params.Get("commentId"));

            IUnityContainer container      = (IUnityContainer)HttpContext.Current.Application["unityContainer"];
            ICommentService commentService = container.Resolve <ICommentService>();
            ILinkService    linkService    = container.Resolve <ILinkService>();

            CommentDetails comment = commentService.GetComment(CommentId);

            LinkId = comment.LinkId;
            LinkDetails link = linkService.GetLink(LinkId);

            lnkLink.NavigateUrl = Response.ApplyAppPathModifier("/Pages/Link/Link.aspx?linkId=" + LinkId);
            if (!IsPostBack)
            {
                txtText.Text = comment.Text;

                lblLink.Text  = link.Name;
                lblMovie.Text = ApplicationManager.GetMovieTitle(link.MovieId);
                if (CookiesManager.GetPreferredSearchEngine(Context) == "webshop")
                {
                    lnkMovie.NavigateUrl = Response.ApplyAppPathModifier("/Pages/Movie/Movie.aspx?movieId=" + link.MovieId);
                }
                else
                {
                    lnkMovie.NavigateUrl = Response.ApplyAppPathModifier("/Pages/Movie/MovieXml.aspx?movieId=" + link.MovieId);
                }
            }
        }
示例#8
0
        public bool UpdateLink(LinkDetails link)
        {
            using (var context = new RelayContext())
            {
                var linkEntity = context.Links.SingleOrDefault(p => p.Id == link.Id);

                if (linkEntity == null)
                {
                    return(false);
                }

                linkEntity.CreationDate = link.CreationDate;
                linkEntity.AllowLocalClientRequestsOnly        = link.AllowLocalClientRequestsOnly;
                linkEntity.ForwardOnPremiseTargetErrorResponse = link.ForwardOnPremiseTargetErrorResponse;
                linkEntity.IsDisabled   = link.IsDisabled;
                linkEntity.MaximumLinks = link.MaximumLinks;
                linkEntity.SymbolicName = link.SymbolicName;
                linkEntity.UserName     = link.UserName;

                linkEntity.TokenRefreshWindow         = link.TokenRefreshWindow;
                linkEntity.HeartbeatInterval          = link.HeartbeatInterval;
                linkEntity.ReconnectMinWaitTime       = link.ReconnectMinWaitTime;
                linkEntity.ReconnectMaxWaitTime       = link.ReconnectMaxWaitTime;
                linkEntity.AbsoluteConnectionLifetime = link.AbsoluteConnectionLifetime;
                linkEntity.SlidingConnectionLifetime  = link.SlidingConnectionLifetime;

                context.Entry(linkEntity).State = EntityState.Modified;

                return(context.SaveChanges() == 1);
            }
        }
示例#9
0
        public void TestAbsoluteExternalLinks()
        {
            LinkDetails result = MessageFormatter.GetLinkDetails("https://google.com");

            Assert.AreEqual(LinkAction.External, result.Action);
            Assert.AreEqual("https://google.com", result.Argument);
        }
示例#10
0
        public void TestRelativeExternalLinks()
        {
            LinkDetails result = MessageFormatter.GetLinkDetails("/relative");

            Assert.AreEqual(LinkAction.External, result.Action);
            Assert.AreEqual("/relative", result.Argument);
        }
示例#11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            LinkId = Int64.Parse(Request.Params.Get("linkId"));

            if (!IsPostBack)
            {
                UserSession userSession = (UserSession)this.Context.Session["userSession"];
                long        userId      = userSession.UserProfileId;

                IUnityContainer  container       = (IUnityContainer)HttpContext.Current.Application["unityContainer"];
                IFavoriteService favoriteService = container.Resolve <IFavoriteService>();
                ILinkService     linkService     = container.Resolve <ILinkService>();

                LinkDetails     link     = linkService.GetLink(LinkId);
                FavoriteDetails favorite = favoriteService.GetFavorite(userId, LinkId);

                lblLink.Text        = "'" + link.Name + "'";
                lblName.Text        = favorite.Name;
                lblDescription.Text = favorite.Description;

                if (Request.UrlReferrer != null)
                {
                    lnkReturn.NavigateUrl = Response.ApplyAppPathModifier(Request.UrlReferrer.AbsoluteUri);
                }
                else
                {
                    lnkReturn.NavigateUrl = Response.ApplyAppPathModifier("~/Pages/Favorite/ListFavorites.aspx");
                }
            }
        }
示例#12
0
        public bool RateEnabled(long linkId)
        {
            if (SessionManager.IsUserAuthenticated(Context))
            {
                UserSession userSession = (UserSession)this.Context.Session["userSession"];
                long        userId      = userSession.UserProfileId;

                IUnityContainer container   = (IUnityContainer)HttpContext.Current.Application["unityContainer"];
                ILinkService    linkService = container.Resolve <ILinkService>();

                LinkDetails link = linkService.GetLink(linkId);

                if (link.UserId == userId)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                return(true);
            }
        }
 public ImageShackImageInfo(Stream imageInfoXml)
 {
     Rating     = new RatingDetails();
     Resolution = new ResolutionDetails();
     Links      = new LinkDetails();
     ParseAndFillProperties(imageInfoXml);
 }
示例#14
0
        public string LinkName(long linkId)
        {
            IUnityContainer container   = (IUnityContainer)HttpContext.Current.Application["unityContainer"];
            ILinkService    linkService = container.Resolve <ILinkService>();

            LinkDetails link = linkService.GetLink(linkId);

            return(link.Name);
        }
示例#15
0
        public string MovieTitle(long linkId)
        {
            IUnityContainer container   = (IUnityContainer)HttpContext.Current.Application["unityContainer"];
            ILinkService    linkService = container.Resolve <ILinkService>();

            LinkDetails link = linkService.GetLink(linkId);

            return(ApplicationManager.GetMovieTitle(link.MovieId));
        }
示例#16
0
        public IHttpActionResult UpdateLink(LinkDetails link)
        {
            if (link == null)
            {
                return(BadRequest());
            }

            var result = _linkRepository.UpdateLink(link);

            return(result ? (IHttpActionResult)Ok() : BadRequest());
        }
示例#17
0
        public bool AssertMatch(LinkDetails linkDetails, long linkId, long userId, string userName, long movieId, string name, string description, string url, long rating)
        {
            Assert.AreEqual(linkId, linkDetails.LinkId);
            Assert.AreEqual(userId, linkDetails.UserId);
            Assert.AreEqual(userName, linkDetails.UserName);
            Assert.AreEqual(movieId, linkDetails.MovieId);
            Assert.AreEqual(name, linkDetails.Name);
            Assert.AreEqual(description, linkDetails.Description);
            Assert.AreEqual(url, linkDetails.Url);
            Assert.AreEqual(rating, linkDetails.Rating);

            return(true);
        }
示例#18
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                long linkId = Int32.Parse(Request.Params.Get("linkId"));

                IUnityContainer container = (IUnityContainer)HttpContext.Current.Application["unityContainer"];

                ILinkService linkService = container.Resolve <ILinkService>();
                LinkDetails  link        = linkService.GetLink(linkId);
            }
            catch (Exception)
            {
            }
        }
示例#19
0
文件: Program.cs 项目: natav/MiscCode
        private static void SaveDataInDB(LinkDetails responseJsonObj)
        {
            string myConnectionString = "Data Source=NATALYAVARS-WIN;Initial Catalog=dbComms;Integrated Security=True";

            using (SqlConnection myConnection = new SqlConnection(myConnectionString))
            {
                DataSet myDataset = new DataSet();

                XmlDocument xmlDoc      = JsonConvert.DeserializeXmlNode(File.ReadAllText(linksFileName), "root");
                XmlReader   myXMLReader = new XmlNodeReader(xmlDoc);
                myDataset.ReadXml(myXMLReader);

                DataTable dtLinkDetails = myDataset.Tables[0];

                //foreach (DataColumn c in dtLinkDetails.Columns)
                //{
                //    Console.WriteLine(c.ColumnName);
                //}
                //Console.WriteLine(new string('=', 60));

                myConnection.Open();

                using (SqlCommand myCommand = myConnection.CreateCommand())
                {
                    myCommand.CommandText = "DELETE FROM tblLinkDetails"; // clean table
                    myCommand.ExecuteNonQuery();
                }

                using (SqlBulkCopy myBulkCopy = new SqlBulkCopy(myConnection))
                {
                    myBulkCopy.DestinationTableName = "tblLinkDetails";

                    myBulkCopy.ColumnMappings.Add("link_url", "link_url");
                    myBulkCopy.ColumnMappings.Add("subject", "subject");
                    myBulkCopy.ColumnMappings.Add("sent_at", "sent_at");
                    myBulkCopy.ColumnMappings.Add("sender_email", "sender_email");
                    myBulkCopy.ColumnMappings.Add("unique_click_count", "unique_click_count");
                    myBulkCopy.ColumnMappings.Add("total_click_count", "total_click_count");
                    myBulkCopy.ColumnMappings.Add("bulletins_links_details_Id", "bulletins_links_details_Id");
                    myBulkCopy.WriteToServer(dtLinkDetails);
                }

                Console.WriteLine("JSON data saved in the database table dbComms.tblLinkDetails");
                Console.WriteLine(new string('=', 60));
            }
        }
示例#20
0
文件: Program.cs 项目: natav/MiscCode
        //private static Tuple<List<HPCharacters>, string> GetData()
        //{
        //    using (HttpClient client = new HttpClient())
        //    {
        //        string Url = "http://hp-api.herokuapp.com/api/characters";

        //        Console.WriteLine("Endpoint URL: " + Url);
        //        Console.WriteLine(new string('=', 60));
        //        client.BaseAddress = new Uri(Url);

        //        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

        //        client.Timeout = new TimeSpan(0, 5, 0);

        //        HttpResponseMessage response = client.GetAsync(Url).Result;

        //        Console.WriteLine("Response Status Code: " + response.StatusCode.ToString());
        //        Console.WriteLine(new string('=', 60));

        //        if (response.IsSuccessStatusCode)
        //        {
        //            var tmp = response.Content.ReadAsStringAsync().Result;

        //            Console.WriteLine("Response Content:");
        //            Console.WriteLine(new string('=', 60));
        //            Console.WriteLine(tmp);
        //            Console.WriteLine(new string('=', 60));

        //            List<HPCharacters> listOfOblects = JsonConvert.DeserializeObject<List<HPCharacters>>(tmp);
        //            Tuple<List<HPCharacters>, string> returnObj = new Tuple<List<HPCharacters>, string>(listOfOblects, tmp.ToString());

        //            return returnObj;
        //        }
        //        else
        //        {
        //            var message = response.Content.ReadAsStringAsync();
        //            string outMessage = string.Format("{0} ({1}):{2}{3}", (int)response.StatusCode, response.ReasonPhrase, Environment.NewLine, message.Result);
        //            Console.WriteLine("Error: " + outMessage);
        //            Console.WriteLine(new string('=', 60));
        //            return new Tuple<List<HPCharacters>, string>(default(List<HPCharacters>), "");
        //            //return Helper.buildFailedHPCharactersString(outMessage);
        //        }
        //    }
        //}


        private static Tuple <LinkDetails, string> GetLinkDetails()
        {
            using (HttpClient client = new HttpClient())
            {
                string Url = "https://api.govdelivery.com/api/v2/accounts/26363/reports/bulletins/links?start_date=2018-03-01&end_date=2018-03-30";

                Console.WriteLine("Endpoint URL: " + Url);
                Console.WriteLine(new string('=', 60));
                client.BaseAddress = new Uri(Url);

                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("*/*"));

                client.DefaultRequestHeaders.Add("X-AUTH-TOKEN", "woVFp-DET1fMd1wmgzmMimqyw6_blFEgp4YssH0QwnRtP85F95zIJKsgmQhdz9BteBCGBEMPsk9_iNB0vZbiRg");

                client.Timeout = new TimeSpan(0, 5, 0);

                HttpResponseMessage response = client.GetAsync(Url).Result;

                Console.WriteLine("Response Status Code: " + response.StatusCode.ToString());
                Console.WriteLine(new string('=', 60));

                if (response.IsSuccessStatusCode)
                {
                    var tmp = response.Content.ReadAsStringAsync().Result;

                    Console.WriteLine("Response Content:");
                    Console.WriteLine(new string('=', 60));
                    Console.WriteLine(tmp);
                    Console.WriteLine(new string('=', 60));

                    LinkDetails listOfOblects             = JsonConvert.DeserializeObject <LinkDetails>(tmp);
                    Tuple <LinkDetails, string> returnObj = new Tuple <LinkDetails, string>(listOfOblects, tmp.ToString());

                    return(returnObj);
                }
                else
                {
                    var    message    = response.Content.ReadAsStringAsync();
                    string outMessage = string.Format("{0} ({1}):{2}{3}", (int)response.StatusCode, response.ReasonPhrase, Environment.NewLine, message.Result);
                    Console.WriteLine("Error: " + outMessage);
                    Console.WriteLine(new string('=', 60));
                    return(new Tuple <LinkDetails, string>(default(LinkDetails), ""));
                }
            }
        }
示例#21
0
        public bool ReportReadVisible(long linkId)
        {
            if (SessionManager.IsUserAuthenticated(Context))
            {
                UserSession userSession = (UserSession)this.Context.Session["userSession"];
                long        userId      = userSession.UserProfileId;

                IUnityContainer container   = (IUnityContainer)HttpContext.Current.Application["unityContainer"];
                ILinkService    linkService = container.Resolve <ILinkService>();
                LinkDetails     link        = linkService.GetLink(linkId);

                return((link.UserId == userId) && (link.Rating <= Settings.Default.WebMovies_demotedThreshold) && (!link.ReportRead));
            }
            else
            {
                return(false);
            }
        }
示例#22
0
        protected void Page_Load(object sender, EventArgs e)
        {
            LinkId = Int64.Parse(Request.Params.Get("linkId"));

            if (!IsPostBack)
            {
                IUnityContainer container   = (IUnityContainer)HttpContext.Current.Application["unityContainer"];
                ILinkService    linkService = container.Resolve <ILinkService>();

                LinkDetails link = linkService.GetLink(LinkId);

                lclAdd.Text             += " " + (string)GetLocalResourceObject("lblLink.Text");
                lnkAddWhat.NavigateUrl   = Response.ApplyAppPathModifier("~/Pages/Link/Link.aspx?linkId=" + LinkId);
                lblAddWhat.Text          = "'" + link.Name + "'";
                imgAddWhat.ImageUrl      = (string)GetLocalResourceObject("imgLink.ImageUrl");
                imgAddWhat.AlternateText = (string)GetLocalResourceObject("imgLink.AlternateText");
            }
        }
示例#23
0
 private void createLink(IEnumerable <Drawable> drawables, LinkDetails link, string tooltipText, Action action = null)
 {
     AddInternal(new DrawableLinkCompiler(drawables.OfType <SpriteText>().ToList())
     {
         RelativeSizeAxes = Axes.Both,
         TooltipText      = tooltipText,
         Action           = () =>
         {
             if (action != null)
             {
                 action();
             }
             else
             {
                 game?.HandleLink(link);
             }
         },
     });
 }
示例#24
0
        //Metodas sukuria nuorodos objektą "LinkDetails",
        //t.y kiekvienai nuorodai priskiria jos title.
        static List <LinkDetails> GetLinkDetails(List <string> urls)
        {
            var linkDetailList = new List <LinkDetails>();

            foreach (var url in urls)
            {
                var htmlNode    = GetHtml(url);
                var linkDetails = new LinkDetails();

                //Nukerpamos "- DELFI..." galūnės lengvesniam sortinimui ir agregavimui
                var trim    = htmlNode.OwnerDocument.DocumentNode.SelectSingleNode("//html/head/title").InnerText;
                var trimRes = trim.Substring(0, trim.LastIndexOf("-"));

                linkDetails.Title = trimRes;
                linkDetails.Url   = url;
                linkDetailList.Add(linkDetails);
            }

            return(linkDetailList);
        }
示例#25
0
        public string Css(long linkId)
        {
            string css = "link";

            IUnityContainer container   = (IUnityContainer)HttpContext.Current.Application["unityContainer"];
            ILinkService    linkService = container.Resolve <ILinkService>();

            LinkDetails link = linkService.GetLink(linkId);

            if (link.Rating <= Settings.Default.WebMovies_demotedThreshold)
            {
                css += " demoted";
            }
            else if (link.Rating >= Settings.Default.WebMovies_promotedThreshold)
            {
                css += " promoted";
            }

            return(css);
        }
示例#26
0
        public void GetLinkTest()
        {
            /* Initialization */
            UserProfile user  = testUtil.CreateTestUser();
            UserProfile user2 = testUtil.CreateTestUserTwo();
            UserProfile user3 = testUtil.CreateTestUserThree();
            UserProfile user4 = testUtil.CreateTestUserFour();

            Link link = testUtil.CreateTestLink(user);

            testUtil.CreateTestRating(user2, link, 1);
            testUtil.CreateTestRating(user3, link, 1);
            testUtil.CreateTestRating(user4, link, -1);

            /* Use case */
            LinkDetails actual = linkService.GetLink(link.linkId);

            /* Check */
            testUtil.AssertMatch(link, actual); // Double checked
            testUtil.AssertMatch(actual, link.linkId, user.userId, user.userLogin, link.movieId, testUtil.TestData.linkName, testUtil.TestData.linkDescription, testUtil.TestData.linkUrl, 1 + 1 - 1);
        }
示例#27
0
        protected void Page_Load(object sender, EventArgs e)
        {
            CommentId = Int64.Parse(Request.Params.Get("commentId"));

            IUnityContainer container      = (IUnityContainer)HttpContext.Current.Application["unityContainer"];
            ICommentService commentService = container.Resolve <ICommentService>();
            ILinkService    linkService    = container.Resolve <ILinkService>();

            CommentDetails comment = commentService.GetComment(CommentId);
            LinkDetails    link    = linkService.GetLink(comment.LinkId);

            MovieId = link.MovieId;

            lblLink.Text        = link.Name;
            lnkLink.NavigateUrl = Response.ApplyAppPathModifier("~/Pages/Link/Link.aspx?linkId=" + link.LinkId);

            lblAuthor.Text        = comment.AuthorName;
            lnkAuthor.NavigateUrl = Response.ApplyAppPathModifier("~/Pages/Comment/ListComments.aspx?userId=" + comment.AuthorId);
            lblDate.Text          = comment.Date.ToString();
            lblText.Text          = comment.Text;
        }
示例#28
0
        protected void Page_Load(object sender, EventArgs e)
        {
            LinkId = Int64.Parse(Request.Params.Get("linkId"));

            atvName.Visible = false;

            if (!IsPostBack)
            {
                IUnityContainer container    = (IUnityContainer)HttpContext.Current.Application["unityContainer"];
                ILinkService    linkService  = container.Resolve <ILinkService>();
                ILabelService   labelService = container.Resolve <ILabelService>();

                LinkDetails link = linkService.GetLink(LinkId);

                lclEditLink.Text = GetLocalResourceObject("lclEditLink.Text") + " " + link.Name;
                string movieTitle = ApplicationManager.GetMovieTitle(link.MovieId);
                if (movieTitle != null)
                {
                    lclEditLink.Text = GetLocalResourceObject("lclEditLink.Text") + " " + link.Name + " " + GetLocalResourceObject("lclFor.Text") + " \"" + movieTitle + "\"";
                }
                lblUrl.Text         = link.Url;
                txtName.Text        = link.Name;
                txtDescription.Text = link.Description;
                string labelsString = "";
                foreach (string label in labelService.GetLabelsForLink(LinkId, 0, int.MaxValue - 1).Keys)
                {
                    labelsString += label + " ";
                }
                txtLabels.Text = labelsString;

                if (link.Rating <= Settings.Default.WebMovies_demotedThreshold)
                {
                    pEditLink.CssClass += " demoted";
                }
                else if (link.Rating >= Settings.Default.WebMovies_promotedThreshold)
                {
                    pEditLink.CssClass += " promoted";
                }
            }
        }
示例#29
0
        public string Remove(long commentId)
        {
            IUnityContainer container      = (IUnityContainer)HttpContext.Current.Application["unityContainer"];
            ICommentService commentService = container.Resolve <ICommentService>();
            ILinkService    linkService    = container.Resolve <ILinkService>();

            CommentDetails comment             = commentService.GetComment(commentId);
            long           commentLinkAuthorId = comment.AuthorId;

            LinkDetails link = linkService.GetLink(comment.LinkId);

            UserSession userSession = (UserSession)this.Context.Session["userSession"];
            long        userId      = userSession.UserProfileId;

            if ((comment.AuthorId == userId) || (link.UserId == userId))
            {
                return("<a href=\"/Pages/Comment/RemoveComment.aspx?commentId=" + commentId + "\"><img src=\"" + GetLocalResourceObject("lnkRemoveComment.ImageUrl") + "\" alt=\"" + GetLocalResourceObject("lnkRemoveComment.AlternateText") + "\" /></a>");
            }
            else
            {
                return("");
            }
        }
示例#30
0
        protected void Page_Load(object sender, EventArgs e)
        {
            LinkId = Int64.Parse(Request.Params.Get("linkId"));

            if (!IsPostBack)
            {
                try
                {
                    UserSession userSession = (UserSession)this.Context.Session["userSession"];
                    long        userId      = userSession.UserProfileId;

                    IUnityContainer  container       = (IUnityContainer)HttpContext.Current.Application["unityContainer"];
                    ILinkService     linkService     = container.Resolve <ILinkService>();
                    IFavoriteService favoriteService = container.Resolve <IFavoriteService>();

                    LinkDetails link = linkService.GetLink(LinkId);

                    lclEdit.Text             += " " + (string)GetLocalResourceObject("lblLink.Text");
                    lnkEditWhat.NavigateUrl   = Response.ApplyAppPathModifier("~/Pages/Link/Link.aspx?linkId=" + LinkId);
                    lblEditWhat.Text          = "'" + link.Name + "'";
                    imgEditWhat.ImageUrl      = (string)GetLocalResourceObject("imgLink.ImageUrl");
                    imgEditWhat.AlternateText = (string)GetLocalResourceObject("imgLink.AlternateText");

                    FavoriteDetails favorite = favoriteService.GetFavorite(userId, LinkId);

                    txtName.Text        = favorite.Name;
                    txtDescription.Text = favorite.Description;
                }
                catch (InstanceNotFoundException <FavoriteDetails> )
                {
                    pFavorite.Visible = false;
                    pError.Visible    = true;
                    return;
                }
            }
        }
示例#31
0
        public string Favorite(long linkId)
        {
            if (SessionManager.IsUserAuthenticated(Context))
            {
                UserSession userSession = (UserSession)this.Context.Session["userSession"];
                long        userId      = userSession.UserProfileId;

                IUnityContainer  container       = (IUnityContainer)HttpContext.Current.Application["unityContainer"];
                ILinkService     linkService     = container.Resolve <ILinkService>();
                IFavoriteService favoriteService = container.Resolve <IFavoriteService>();

                LinkDetails link = linkService.GetLink(linkId);

                string href     = " href=\"/Pages/Favorite/AddFavorite.aspx?linkId=" + linkId + "\"";
                string image    = (string)GetLocalResourceObject("lnkFavorite.ImageURL");
                string text     = (string)GetLocalResourceObject("lnkFavorite.Text");
                string disabled = "";
                if (favoriteService.HasInFavorites(userId, linkId))
                {
                    href  = " href=\"/Pages/Favorite/RemoveFavorite.aspx?linkId=" + linkId + "\"";
                    image = (string)GetLocalResourceObject("lnkUnfavorite.ImageURL");
                    text  = (string)GetLocalResourceObject("lnkUnfavorite.Text");
                }
                if (link.UserId == userId)
                {
                    href     = "";
                    disabled = " disabled=\"disabled\"";
                }

                return("<a" + href + disabled + "><img src=\"" + image + "\" alt=\"" + text + "\" /></a>");
            }
            else
            {
                return("<a href=\"/Pages/Favorite/AddFavorite.aspx?linkId=" + linkId + "\"><img src=\"" + GetLocalResourceObject("lnkFavorite.ImageURL") + "\" alt=\"" + GetLocalResourceObject("lnkFavorite.Text") + "\" /></a>");
            }
        }
示例#32
0
        public static string buttonsaveclick(List<string> arraylinks)
        {
            string htmlcontent = "";
            DataTable dt = new DataTable();
            LinkDetails link = new LinkDetails();
            LBR_LINKS obj = new LBR_LINKS();
            string id = "";
            try
            {
                string linknew = arraylinks[0];

                if (linknew != string.Empty)
                {

                    if (!linknew.Trim().Contains("http://") && !linknew.Trim().Contains("https://"))
                    {
                        linknew = "http://" + linknew;
                    }

                    link.Url = linknew;
                    link = getlinkdetailsnew(link);
                    Match regx = Regex.Match(link.Url, @"http://([\\w+?\\.\\w+])+([a-zA-Z0-9\\~\\!\\@\\#\\$\\%\\^\\&amp;\\*\\(\\)_\\-\\=\\+\\\\\\/\\?\\.\\:\\;\\'\\,]*)?",
                      RegexOptions.IgnoreCase);
                    //Regex regx = new Regex("http://([\\w+?\\.\\w+])+([a-zA-Z0-9\\~\\!\\@\\#\\$\\%\\^\\&amp;\\*\\(\\)_\\-\\=\\+\\\\\\/\\?\\.\\:\\;\\'\\,]*)?", RegexOptions.IgnoreCase);
                    //HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("" + link.Url + "");
                    //request.Proxy = null;
                    //request.Method = "HEAD";
                    //bool exists;
                    //try
                    //{
                    //    request.GetResponse();
                    //    exists = true;
                    //}
                    //catch
                    //{
                    //    exists = false;
                    //}

                    if (link.status != false)
                    {

                        if (link.Description != null)
                        {
                            obj.LINK_DESCRIPTION = (link.Description.ToString().Replace("{", "").Replace("}", "")).Trim().Replace("'", "");
                        }
                        if (link.Image != null)
                        {
                            obj.LINK_IMAGEPATH = link.Image.Url.ToString();
                        }
                        // if (dt_user.Rows.Count > 0)
                        {
                            obj.LINK_MODIFIEDBY = Int32.Parse(arraylinks[1]);
                            obj.CREATEDBY = Int32.Parse(arraylinks[1]);
                        }
                        obj.LINK_PATH = link.Url;
                        obj.LINK_STATUS = 1;
                        if (link.Title != null)
                        {
                            obj.LINK_TITLE = (link.Title.ToString()).Replace("{", "").Replace("}", "").Trim().Replace("'", "");
                        }
                        obj.LINK_TYPE = 1;
                        //string[] values = hid_tab.Value.Split('_');

                        if (arraylinks.Count == 3)
                        {
                            obj.LINK_TABID = Int32.Parse(arraylinks[2]);
                            obj.LINK_SIGNUPID = Int32.Parse(arraylinks[1]);

                            if (link.Title == null || link.Title == "")
                            {
                                obj.LINK_TITLE = link.Url.Replace("{", "").Replace("}", "").Trim().Replace("'", "");
                            }
                            if (link.Url.Contains("fb.com") || link.Url.Contains("facebook.com"))
                            {
                                obj.LINK_TITLE = "Facebook<br/>" + link.Url.Replace("{", "").Replace("}", "") + "";
                                obj.LINK_IMAGEPATH = "../images/fb_icon_325x325.png";
                            }

                            //  dt = BLL.set_link(obj);

                            //  id = dt.Rows[0]["link_id"].ToString();
                            // if (dt.Rows.Count > 0)
                            {

                                obj.LINK_PATH = linknew;

                                string url = "";
                                Match regexMatch = Regex.Match(obj.LINK_PATH, @"youtu(?:\.be|be\.com)/(?:.*v(?:/|=)|(?:.*/)?)([a-zA-Z0-9-_]+)",
                        RegexOptions.IgnoreCase);
                                Match vimeoMatch = Regex.Match(obj.LINK_PATH, @"vimeo\.com/(?:.*#|.*/videos/)?([0-9]+)",
                                    RegexOptions.IgnoreCase);

                                if (regexMatch.Success || vimeoMatch.Success)
                                {
                                    string value = "";
                                    if (regexMatch.Success)
                                    {
                                        value = regexMatch.Groups[1].Value;
                                        htmlcontent = "1";
                                        htmlcontent = htmlcontent + "!@#" + value + "!@#" + obj.LINK_TITLE.Replace("{", "").Replace("}", "") + "!@#" + obj.LINK_DESCRIPTION.Replace("{", "").Replace("}", "");
                                        // htmlcontent = "<div class=\"box\" id=\"divbox_" + id + "\" style=\"cursor:pointer\" onclick=\"OpenInNewTab('" + obj.LINK_PATH + "','divbox_" + id + "')\" ><span class=\"delete\"><a href=\"#\" onclick=\"deletebox('divbox_" + id + "')\"><i class=\"fa fa-trash\"></i></a></span><iframe class=\"boxvideo\" style=\"margin-left:-6px;margin-top:-6px;\" src=\"http://www.youtube.com/embed/" + value + "\" frameborder=\"0\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>";

                                    }
                                    else if (vimeoMatch.Success)
                                    {
                                        value = vimeoMatch.Groups[1].Value;
                                        htmlcontent = "2";
                                        htmlcontent = htmlcontent + "!@#" + value + "!@#" + obj.LINK_TITLE.Replace("{", "").Replace("}", "") + "!@#" + obj.LINK_DESCRIPTION.Replace("{", "").Replace("}", "");
                                        //   htmlcontent = "<div class=\"box\" id=\"divbox_" + id + "\" style=\"cursor:pointer\" onclick=\"OpenInNewTab('" + obj.LINK_PATH + "','divbox_" + id + "')\" ><span class=\"delete\"><a href=\"#\" onclick=\"deletebox('divbox_" + id + "')\"><i class=\"fa fa-trash\"></i></a></span><iframe class=\"boxvideo\" style=\"margin-left:-6px;margin-top:-6px;\" src=\"//player.vimeo.com/video/" + value + "\" frameborder=\"0\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>";

                                    }
                                    htmlcontent = htmlcontent + "!@#" + obj.LINK_PATH + "!@#" + obj.LINK_IMAGEPATH;

                                }

                                else
                                {
                                    htmlcontent = "3";
                                    if (obj.LINK_IMAGEPATH != "" && obj.LINK_IMAGEPATH != null)
                                    {

                                        if (obj.LINK_TITLE != null && obj.LINK_TITLE != "")
                                        {
                                            htmlcontent = htmlcontent + "!@#" + obj.LINK_IMAGEPATH + "!@#" + obj.LINK_TITLE.Replace("{", "").Replace("}", "");
                                            if (obj.LINK_DESCRIPTION != null && obj.LINK_DESCRIPTION != "")
                                            {
                                                htmlcontent = htmlcontent + "!@#" + obj.LINK_DESCRIPTION.Replace("{", "").Replace("}", "");
                                            }
                                            else
                                            {
                                                htmlcontent = htmlcontent + "!@#" + "0";
                                            }
                                        }
                                        else
                                        {
                                            htmlcontent = htmlcontent + "!@#" + obj.LINK_IMAGEPATH + "!@#" + "0";
                                            if (obj.LINK_DESCRIPTION != null && obj.LINK_DESCRIPTION != "")
                                            {
                                                htmlcontent = htmlcontent + "!@#" + obj.LINK_DESCRIPTION.Replace("{", "").Replace("}", "");
                                            }
                                            else
                                            {
                                                htmlcontent = htmlcontent + "!@#" + "0";
                                            }
                                        }
                                        // htmlcontent = "<div class=\"box\" id=\"divbox_" + id + "\" style=\"cursor:pointer\"  ><div class=\"boximage\" onclick=\"OpenInNewTab('" + obj.LINK_PATH + "','divbox_" + id + "')\" style=\"background-image:url('" + obj.LINK_IMAGEPATH + "');\"><span class=\"delete\"><a href=\"#\" onclick=\"deletebox('divbox_" + id + "')\"><i class=\"fa fa-trash\"></i></a></span></div><div class=\"boxtext\" ><a href='#' onclick=\"OpenInNewTab('" + obj.LINK_PATH + "','divbox_" + id + "')\">" + dt.Rows[0]["link_title"].ToString() + "</a></div></div>";
                                        ////  htmlcontent = "<div class=\"box\" id=\"divbox_" + id + "\" style=\"cursor:pointer\" onclick=\"OpenInNewTab('" + obj.LINK_PATH + "','divbox_" + id + "')\" ><span class=\"delete\"><a href=\"#\" onclick=\"deletebox('divbox_" + id + "')\"><i class=\"fa fa-trash\"></i></a></span>" + dt.Rows[0]["link_title"].ToString() + "</div>";

                                    }
                                    else
                                    {

                                        if (obj.LINK_TITLE != null && obj.LINK_TITLE != "")
                                        {
                                            htmlcontent = htmlcontent + "!@#" + "0" + "!@#" + obj.LINK_TITLE.Replace("{", "").Replace("}", "");
                                            if (obj.LINK_DESCRIPTION != null && obj.LINK_DESCRIPTION != "")
                                            {
                                                htmlcontent = htmlcontent + "!@#" + obj.LINK_DESCRIPTION.Replace("{", "").Replace("}", "");
                                            }
                                            else
                                            {
                                                htmlcontent = htmlcontent + "!@#" + "0";
                                            }
                                        }
                                        else
                                        {
                                            htmlcontent = htmlcontent + "!@#" + "0" + "!@#" + "0";
                                            if (obj.LINK_DESCRIPTION != null && obj.LINK_DESCRIPTION != "")
                                            {
                                                htmlcontent = htmlcontent + "!@#" + obj.LINK_DESCRIPTION.Replace("{", "").Replace("}", "");
                                            }
                                            else
                                            {
                                                htmlcontent = htmlcontent + "!@#" + "0";
                                            }
                                        }
                                        // htmlcontent = "<div class=\"box\" id=\"divbox_" + id + "\" style=\"cursor:pointer\" onclick=\"OpenInNewTab('" + obj.LINK_PATH + "','divbox_" + id + "')\" ><span class=\"delete\"><a href=\"#\" onclick=\"deletebox('divbox_" + id + "')\"><i class=\"fa fa-trash\"></i></a></span>" + new Uri("" + link.Url + "").GetLeftPart(UriPartial.Path) + "<br/>" + dt.Rows[0]["link_title"].ToString() + "</div>";
                                    }
                                    Uri myUri = new Uri(obj.LINK_PATH);
                                    string host = myUri.Host;
                                    // HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority);
                                    htmlcontent = htmlcontent + "!@#" + obj.LINK_PATH + "!@#" + host;

                                }
                                if (htmlcontent != "")
                                {

                                    //bool status = BLL.ExecuteNonQuery("update lbr_links set link_data='" + BLL.ReplaceQuote(htmlcontent) + "' where link_id='" + id + "'");
                                    //txt_url.Text = string.Empty;
                                    //hid_html.Value = htmlcontent;
                                    //ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "myJsFn", "saveurl();return false;", true);

                                }
                            }

                        }

                        //}
                    }
                    else
                    {
                        //BLL.ShowMessage(this, "Please enter a valid URL");
                        //txt_url.Focus();
                        htmlcontent = "invalid";
                    }
                }
                else
                {
                    //BLL.ShowMessage(this, "Please enter URL");
                    //txt_url.Focus();
                }
            }
            catch (Exception ex)
            {

            }
            return htmlcontent;
        }
示例#33
0
        /// <summary>
        /// Populates the fields for multiple objects from the columns found in an open reader.
        /// </summary>
        ///
        /// <param name="rdr" type="IDataReader">An object that implements the IDataReader interface</param>
        ///
        /// <returns>Object of LinkDetails</returns>
        ///
        /// <remarks>
        ///
        /// <RevisionHistory>
        /// Author				Date			Description
        /// DLGenerator			12/16/2009 3:09:15 PM		Created function
        /// 
        /// </RevisionHistory>
        ///
        /// </remarks>
        ///
        internal static LinkDetails PopulateObjectsFromReader(IDataReader rdr, string ConnectionString)
        {
            LinkDetails list = new LinkDetails();

            while (rdr.Read())
            {
                LinkDetail obj = new LinkDetail(ConnectionString);
                PopulateObjectFromReader(obj, rdr);
                list.Add(obj);
            }
            return list;
        }
示例#34
0
        /// <summary>
        /// Populates the fields for multiple objects from the columns found in an open reader.
        /// </summary>
        ///
        /// <param name="rdr" type="IDataReader">An object that implements the IDataReader interface</param>
        ///
        /// <returns>Object of LinkDetails</returns>
        ///
        /// <remarks>
        ///
        /// <RevisionHistory>
        /// Author				Date			Description
        /// DLGenerator			12/16/2009 3:09:15 PM		Created function
        /// 
        /// </RevisionHistory>
        ///
        /// </remarks>
        ///
        internal static LinkDetails PopulateObjectsFromReaderWithCheckingReader(IDataReader rdr, DatabaseHelper oDatabaseHelper, string ConnectionString)
        {
            LinkDetails list = new LinkDetails();

            if (rdr.Read())
            {
                LinkDetail obj = new LinkDetail(ConnectionString);
                PopulateObjectFromReader(obj, rdr);
                list.Add(obj);
                while (rdr.Read())
                {
                    obj = new LinkDetail(ConnectionString);
                    PopulateObjectFromReader(obj, rdr);
                    list.Add(obj);
                }
                oDatabaseHelper.Dispose();
                return list;
            }
            else
            {
                oDatabaseHelper.Dispose();
                return null;
            }
        }
示例#35
0
        public LinkDetails getlinkdetails(LinkDetails linkDetails)
        {
            //http://htmlagilitypack.codeplex.com/
            string url = linkDetails.Url;
            linkDetails.Url = url;
            linkDetails = GetHeaders(linkDetails.Url, linkDetails);

            if (linkDetails.MimeType.ToLower().Contains("text/html"))
            {
                linkDetails.LinkType = 1;
                HtmlDocument htmlDocument = new HtmlDocument();
                System.Net.WebClient webClient = new System.Net.WebClient();
                string download = webClient.DownloadString(linkDetails.Url);

                htmlDocument.LoadHtml(download);
                HtmlNode htmlNode = htmlDocument.DocumentNode.SelectSingleNode("html/head");

                linkDetails = GetStandardInfo(linkDetails, htmlNode);

                linkDetails = GetOpenGraphInfo(linkDetails, htmlNode);

                if (linkDetails.Image == null)
                {
                    linkDetails = GuessImage(htmlDocument, linkDetails);
                }
            }

            if (linkDetails.MimeType.ToLower().Contains("image/"))
            {
                linkDetails.LinkType = 2;
                linkDetails.Image = new ImageLink(linkDetails.Url);
            }
            return linkDetails;
        }
示例#36
0
        private LinkDetails GetOpenGraphInfo(LinkDetails linkDetails, HtmlNode head)
        {
            foreach (HtmlNode headNode in head.ChildNodes)
            {
                switch (headNode.Name.ToLower())
                {
                    case "link": break;

                    case "meta":
                        if (headNode.Attributes["property"] != null && headNode.Attributes["content"] != null)
                        {
                            switch (headNode.Attributes["property"].Value.ToLower())
                            {
                                case "og:title":
                                    linkDetails.Title = HttpUtility.HtmlDecode(headNode.Attributes["content"].Value);
                                    break;
                                case "og:type":
                                    linkDetails.Type = headNode.Attributes["content"].Value;
                                    break;
                                case "og:url":
                                    linkDetails.Url = headNode.Attributes["content"].Value;
                                    break;
                                case "og:image":
                                    linkDetails.Image = new ImageLink(headNode.Attributes["content"].Value, linkDetails.Url);
                                    break;
                                case "og:site_name":
                                    linkDetails.SiteName = HttpUtility.HtmlDecode(headNode.Attributes["content"].Value);
                                    break;
                                case "og:description":
                                    linkDetails.Description = HttpUtility.HtmlDecode(headNode.Attributes["content"].Value);
                                    break;
                                case "og:email":
                                    linkDetails.Email = HttpUtility.HtmlDecode(headNode.Attributes["content"].Value);
                                    break;
                                case "og:phone_number":
                                    linkDetails.PhoneNumber = HttpUtility.HtmlDecode(headNode.Attributes["content"].Value);
                                    break;
                                case "og:fax_number":
                                    linkDetails.FaxNumber = HttpUtility.HtmlDecode(headNode.Attributes["content"].Value);
                                    break;

                            }
                        }
                        break;
                }

            }
            return linkDetails;
        }
示例#37
0
        private static LinkDetails GuessImagenew(HtmlDocument htmlDocument, LinkDetails linkDetails)
        {
            LinkDetails detail = linkDetails;
            HtmlNodeCollection imageNodes = htmlDocument.DocumentNode.SelectNodes("//img");
            string h1 = string.Empty;
            HtmlNode h1Node = htmlDocument.DocumentNode.SelectSingleNode("//h1");
            if (h1Node != null)
            {
                h1 = h1Node.InnerText;
            }
            int bestScore = -1;
            if (imageNodes != null)
            {
                foreach (HtmlNode imageNode in imageNodes)
                {
                    //if (imageNode.Attributes["alt"]==null)
                    //{
                    //    imageNode.Attributes["alt"].Value = Path.GetFileName(@"" + imageNode.Attributes["src"].Value + "");
                    //}

                    if (imageNode != null && imageNode.Attributes["data-old-hires"] != null)
                    {
                        if (imageNode.Attributes["alt"] != null && imageNode.Attributes["alt"].Value != "")
                        {
                            Uri absolute = new Uri(linkDetails.Url);
                            Uri result = new Uri(absolute, imageNode.Attributes["data-old-hires"].Value);
                            ImageLink imageLink = new ImageLink(result.AbsoluteUri, detail.Url);
                            //ImageLink imageLink = new ImageLink(imageNode.Attributes["data-old-hires"].Value, detail.Url);
                            if (!(imageLink.Width > 0 && imageLink.Width < 50)) //if we don't have a width go with it but if we know width is less than 50 don't use it
                            {
                                int myScore = ScoreImagenew(imageNode.Attributes["alt"].Value, linkDetails.Title);
                                myScore += ScoreImagenew(imageNode.Attributes["alt"].Value, h1);

                                if (myScore > bestScore)
                                {
                                    detail.Image = imageLink;
                                    bestScore = myScore;
                                }

                                if (!detail.Images.Contains(imageLink)) { detail.Images.Add(imageLink); }
                            }
                        }
                    }
                    if (detail.Images.Count == 0 || detail.Images.Count == null)
                    {
                        if (imageNode != null && imageNode.Attributes["src"] != null)
                        {
                            if (imageNode.Attributes["alt"] != null && imageNode.Attributes["alt"].Value != "")
                            {
                                Uri absolute = new Uri(linkDetails.Url);
                                Uri result = new Uri(absolute, imageNode.Attributes["src"].Value);
                                ImageLink imageLink = new ImageLink(result.AbsoluteUri, detail.Url);
                                //ImageLink imageLink = new ImageLink(imageNode.Attributes["src"].Value, detail.Url);
                                if (!(imageLink.Width > 0 && imageLink.Width < 50)) //if we don't have a width go with it but if we know width is less than 50 don't use it
                                {
                                    int myScore = ScoreImagenew(imageNode.Attributes["alt"].Value, linkDetails.Title);
                                    myScore += ScoreImagenew(imageNode.Attributes["alt"].Value, h1);

                                    if (myScore > bestScore)
                                    {
                                        detail.Image = imageLink;
                                        bestScore = myScore;
                                    }

                                    if (!detail.Images.Contains(imageLink)) { detail.Images.Add(imageLink); }
                                }
                            }

                        }
                    }
                }
                if (detail.Images.Count == 0 || detail.Images.Count == null)
                {
                    foreach (HtmlNode imageNode in imageNodes)
                    {
                        string value = "";
                        if (imageNode.Attributes["src"] != null)
                        {
                            value = Path.GetFileName(@"" + imageNode.Attributes["src"].Value + "");
                        }
                        else if (imageNode.Attributes["ng-src"] != null)
                        {
                            value = Path.GetFileName(@"" + imageNode.Attributes["ng-src"].Value + "");
                        }
                        if (value != "")
                        {
                            Uri absolute = new Uri(linkDetails.Url);
                            if (imageNode.Attributes["src"] != null)
                            {
                                Uri result = new Uri(absolute, imageNode.Attributes["src"].Value);
                                ImageLink imageLink = new ImageLink(result.AbsoluteUri, detail.Url);

                                if (!(imageLink.Width > 0 && imageLink.Width < 50)) //if we don't have a width go with it but if we know width is less than 50 don't use it
                                {
                                    int myScore = ScoreImagenew(value, linkDetails.Title);
                                    myScore += ScoreImagenew(value, h1);

                                    if (myScore > bestScore)
                                    {
                                        detail.Image = imageLink;
                                        bestScore = myScore;
                                    }
                                    // Uri ur = new System.Uri(linkDetails.Url,  ("~/mypage.aspx")).AbsoluteUri;
                                    if (!detail.Images.Contains(imageLink)) { detail.Images.Add(imageLink); }
                                }
                            }
                            else if (imageNode.Attributes["ng-src"] != null)
                            {
                                Uri result = new Uri(absolute, imageNode.Attributes["ng-src"].Value);
                                ImageLink imageLink = new ImageLink(result.AbsoluteUri, detail.Url);

                                if (!(imageLink.Width > 0 && imageLink.Width < 50)) //if we don't have a width go with it but if we know width is less than 50 don't use it
                                {
                                    int myScore = ScoreImagenew(value, linkDetails.Title);
                                    myScore += ScoreImagenew(value, h1);

                                    if (myScore > bestScore)
                                    {
                                        detail.Image = imageLink;
                                        bestScore = myScore;
                                    }
                                    // Uri ur = new System.Uri(linkDetails.Url,  ("~/mypage.aspx")).AbsoluteUri;
                                    if (!detail.Images.Contains(imageLink)) { detail.Images.Add(imageLink); }
                                }
                            }

                        }

                    }
                }
            }

            return detail;
        }
示例#38
0
        //get info off of basic meta tags
        private LinkDetails GetStandardInfo(LinkDetails linkDetails, HtmlNode head)
        {
            foreach (HtmlNode headNode in head.ChildNodes)
            {
                switch (headNode.Name.ToLower())
                {
                    case "link": break;
                    case "title":
                        linkDetails.Title = HttpUtility.HtmlDecode(headNode.InnerText);
                        break;
                    case "meta":
                        if (headNode.Attributes["name"] != null && headNode.Attributes["content"] != null)
                        {
                            switch (headNode.Attributes["name"].Value.ToLower())
                            {
                                case "description":
                                    linkDetails.Description = HttpUtility.HtmlDecode(headNode.Attributes["content"].Value);
                                    break;
                            }
                        }
                        break;
                }

            }
            // look for apple touch icon in header
            HtmlNode imageNode = head.SelectSingleNode("link[@rel='apple-touch-icon']");
            if (imageNode != null)
            {
                if (imageNode.Attributes["href"] != null) { linkDetails.Image = new ImageLink(imageNode.Attributes["href"].Value, linkDetails.Url); }
                if (imageNode.Attributes["src"] != null) { linkDetails.Image = new ImageLink(imageNode.Attributes["src"].Value, linkDetails.Url); }
            }
            //look for link image in header
            imageNode = head.SelectSingleNode("link[@rel='image_src']");
            if (imageNode != null)
            {
                if (imageNode.Attributes["href"] != null) { linkDetails.Image = new ImageLink(imageNode.Attributes["href"].Value, linkDetails.Url); }
                if (imageNode.Attributes["src"] != null) { linkDetails.Image = new ImageLink(imageNode.Attributes["src"].Value, linkDetails.Url); }
            }

            return linkDetails;
        }
示例#39
0
        private LinkDetails GuessImage(HtmlDocument htmlDocument, LinkDetails linkDetails)
        {
            LinkDetails detail = linkDetails;
            HtmlNodeCollection imageNodes = htmlDocument.DocumentNode.SelectNodes("//img");
            string h1 = string.Empty;
            HtmlNode h1Node = htmlDocument.DocumentNode.SelectSingleNode("//h1");
            if (h1Node != null)
            {
                h1 = h1Node.InnerText;
            }
            int bestScore = -1;
            if (imageNodes != null)
            {
                foreach (HtmlNode imageNode in imageNodes)
                {
                    if (imageNode != null && imageNode.Attributes["src"] != null && imageNode.Attributes["alt"] != null)
                    {
                        ImageLink imageLink = new ImageLink(imageNode.Attributes["src"].Value, detail.Url);
                        if (!(imageLink.Width > 0 && imageLink.Width < 50)) //if we don't have a width go with it but if we know width is less than 50 don't use it
                        {
                            int myScore = ScoreImage(imageNode.Attributes["alt"].Value, linkDetails.Title);
                            myScore += ScoreImage(imageNode.Attributes["alt"].Value, h1);

                            if (myScore > bestScore)
                            {
                                detail.Image = imageLink;
                                bestScore = myScore;
                            }

                            if (!detail.Images.Contains(imageLink)) { detail.Images.Add(imageLink); }
                        }
                    }
                }
            }

            return detail;
        }
示例#40
0
        public static LinkDetails getlinkdetailsnew(LinkDetails linkDetails)
        {
            try
            {
                //bool sta = false;
                //http://htmlagilitypack.codeplex.com/
                string url = linkDetails.Url;
                linkDetails.Url = url.Replace(" ", "").Trim();
                //     linkDetails = GetHeadersnew(linkDetails.Url, linkDetails);
                // if (linkDetails.MimeType!="Don't Download")
                //  {
                //if (linkDetails.MimeType.ToLower().Contains("text/html"))
                //{
                linkDetails.LinkType = 1;
                HtmlDocument htmlDocument = new HtmlDocument();
                System.Net.WebClient webClient = new System.Net.WebClient();
                // ServicePointManager.DefaultConnectionLimit = 20000;
                webClient.Proxy = null;
                WebRequest.DefaultWebProxy = null;
                webClient.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0");

                string download = webClient.DownloadString(linkDetails.Url);

                htmlDocument.LoadHtml(download);
                HtmlNode htmlNode = htmlDocument.DocumentNode.SelectSingleNode("//html//head");
                if (htmlNode == null)
                {
                    htmlNode = htmlDocument.DocumentNode.SelectSingleNode("//head");
                }
                if (htmlNode == null)
                {
                    htmlNode = htmlDocument.DocumentNode.SelectSingleNode("//html");
                }

                if (htmlNode != null)
                {
                    linkDetails.status = true;
                    // sta = true;
                    linkDetails = GetStandardInfonew(linkDetails, htmlNode);

                    linkDetails = GetOpenGraphInfonew(linkDetails, htmlNode);
                    if (linkDetails.Image != null)
                    {
                        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("" + linkDetails.Image.Url + "");
                        request.Proxy = null;
                        request.Method = "HEAD";
                        bool exists;
                        try
                        {
                            request.GetResponse();
                            exists = true;
                        }
                        catch
                        {
                            exists = false;
                        }
                        if (exists == false)
                        {
                            linkDetails.Image = null;
                        }
                    }

                    if (linkDetails.Image == null)
                    {
                        linkDetails = GuessImagenew(htmlDocument, linkDetails);
                    }
                }

                else
                {
                    linkDetails = GetHeadersnew(linkDetails.Url, linkDetails);
                    if (linkDetails.MimeType.ToLower().Contains("image/"))
                    {
                        linkDetails.LinkType = 2;
                        linkDetails.Image = new ImageLink(linkDetails.Url);
                    }
                    else
                    {
                        linkDetails.status = false;
                        // sta = false;
                    }
                }
            }
            catch (Exception ex)
            {
                //     linkDetails = GetHeadersnew(linkDetails.Url, linkDetails);
                //sta = false;
            }
            //if (linkDetails.MimeType.ToLower().Contains("image/"))
            //{
            //    linkDetails.LinkType = 2;
            //    linkDetails.Image = new ImageLink(linkDetails.Url);
            //}
            //  }
            //  }
            return linkDetails;
        }
示例#41
0
        public static LinkDetails GetHeadersnew(string link, LinkDetails linkDetails)
        {
            try
            {

                System.Net.WebClient wc = new System.Net.WebClient();
                wc.Headers.Add("user-agent", "Only a test!");

                wc.OpenRead(link);
                linkDetails.ContentLength = Convert.ToInt64(wc.ResponseHeaders["Content-Length"]);
                linkDetails.MimeType = wc.ResponseHeaders["Content-Type"];
            }
            catch
            {
                linkDetails.MimeType = "Don't Download";
            }
            return linkDetails;
        }
示例#42
0
        public static string buttonsaveNewclick(List<string> array)
        {
            string htmlcontent = "";
            DataTable dt = new DataTable();
            LinkDetails link = new LinkDetails();
            LBR_LINKS obj = new LBR_LINKS();
            string id = "";
            try
            {

                if (array.Count == 4)
                {
                    string[] arraylinks = array[3].Split(new string[] { "!@#" }, StringSplitOptions.None);
                    if (arraylinks.Length == 6)
                    {
                        obj.LINK_CREATEDDBY = Int32.Parse(array[1]);
                        obj.LINK_MODIFIEDBY = Int32.Parse(array[1]);
                        obj.LINK_DESCRIPTION = arraylinks[3].Replace("{", "").Replace("}", "").Trim();
                        if (arraylinks[0] == "3")
                        {
                            obj.LINK_IMAGEPATH = arraylinks[1];
                        }
                        else
                        {
                            obj.LINK_IMAGEPATH = arraylinks[5];
                        }
                        obj.LINK_PATH = arraylinks[4];
                        obj.LINK_SIGNUPID = Int32.Parse(array[1]);
                        obj.LINK_STATUS = 1;
                        obj.LINK_TABID = Int32.Parse(array[2]);
                        obj.LINK_SIGNUPID = Int32.Parse(array[1]);
                        obj.LINK_TYPE = 1;
                        obj.LINK_TITLE = arraylinks[2].Replace("{", "").Replace("}", "").Trim();

                        dt = BLL.set_link(obj);

                        if (dt.Rows.Count > 0)
                        {

                         htmlcontent=LoadlinksStatic(dt);

                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return htmlcontent;
        }