示例#1
0
        public PlateSolve(string psfilepath)
        //Creates a new instance of a plateImage and sets the filepath for storing it
        {
            plateImageName = psfilepath;
            ImageLink tsx_il = new ImageLink();

            tsx_il.pathToFITS = psfilepath;
            try
            {
                tsx_il.execute();
            }
            catch (Exception ex)
            {
                string evx = ex.Message;
                plateImageResult = ex.HResult;
                return;
            }
            ImageLinkResults tsx_ilr = new ImageLinkResults();

            plateImageRA    = tsx_ilr.imageCenterRAJ2000;
            plateImageDec   = tsx_ilr.imageCenterDecJ2000;
            plateImagePA    = tsx_ilr.imagePositionAngle;
            plateImageScale = tsx_ilr.imageScale;
            tsx_il          = null;
            tsx_ilr         = null;
            GC.Collect();
            return;
        }
示例#2
0
    const int ifilter      = 3;   ///4nd filter slot, probably clear/lumenscent

    public void ImageLinkerSample()
    {
        ///Create camera object and connect

        ImageLink        tsx_il  = new ImageLink();
        ImageLinkResults tsx_ilr = new ImageLinkResults();

        ///Set path to file
        tsx_il.pathToFITS = PathName;

        ///Run ImageLink
        tsx_il.execute();

        ///Check on result
        if (tsx_ilr.succeeded == 0)
        {
            MessageBox.Show("Error: " + tsx_ilr.errorCode.ToString() + "  " + tsx_ilr.errorText);
            return;
        }

        ///Print the image center location

        MessageBox.Show("RA: " + tsx_ilr.imageCenterRAJ2000.ToString() + "  Dec: " + tsx_ilr.imageCenterDecJ2000.ToString());
        return;
    }
示例#3
0
        /// <summary>
        /// Handles splitting the data for GetGame method of Friends
        /// </summary>
        public Game(string listingData)
        {
            Name      = listingData.Split('>')[2].Split('<')[0];
            StoreLink = listingData.Split('=')[3].Replace("\"", "").Split('?')[0];
            AppId     = int.Parse(listingData.Split('=')[1].Replace("\"", "").Split(' ')[0]);
            ImageLink = listingData.Split('>')[4].Replace("\"", "").Split('=')[1];
            if (ImageLink.Contains("?"))
            {
                ImageLink = ImageLink.Split('?')[0];
            }
            string priceCandidate = listingData.Split('>')[7].Split('<')[0];

            if (priceCandidate == null || priceCandidate.Length < 2)
            {
                Price    = null;
                SaleType = Friends.SaleType.NotAvailable;
            }
            else if (priceCandidate.IndexOf("free", StringComparison.OrdinalIgnoreCase) >= 0)
            {
                Price    = null;
                SaleType = Friends.SaleType.FreeToPlay;
            }
            else
            {
                Price    = double.Parse(priceCandidate.Substring(1), System.Globalization.CultureInfo.InvariantCulture);
                SaleType = Friends.SaleType.CostsMoney;
            }
        }
示例#4
0
        /// <summary>
        /// Sets an image link.
        /// </summary>
        /// <param name="link">The link</param>
        /// <returns>The image.</returns>
        public async Task <Image> SetImageLinks(ImageLink link)
        {
            var result = await this.ExecuteReader("img.setimagelink", parameters =>
            {
                parameters.AddWithValue("imageid", link.ImageId);
                parameters.AddWithValue("linkid", link.LinkId);
                parameters.AddWithValue("filetype", link.Format);
                parameters.AddWithValue("width", link.Width);
                parameters.AddWithValue("height", link.Height);
                parameters.AddWithValue("adapter", link.Adapter);
                parameters.AddWithValue("metadata", link.Metadata);
            },
                                                  CatiImageDataLayer.ReadLink,
                                                  CatiImageDataLayer.ReadImage);

            var linklookup = result.Item1.ToLookup(lnk => lnk.ImageId);

            foreach (var img in result.Item2)
            {
                if (linklookup.Contains(img.Id))
                {
                    foreach (var lnData in linklookup[img.Id])
                    {
                        img.Links.Add(lnData);
                    }
                }
            }

            return(result.Item2.Single());
        }
示例#5
0
 private void SetImageLinks(User user)
 {
     if (user.Avatar != null)
     {
         user.Avatar = ImageLink.GetUserAvatarLink(user.Id);
     }
 }
示例#6
0
            // --

            public static Link ParseLink(JToken json)
            {
                if (json == null)
                {
                    return(null);
                }
                String  linkType = (string)json["type"];
                JObject value    = (JObject)json["value"];

                switch (linkType)
                {
                case "Link.web":
                    return(WebLink.Parse(value));

                case "Link.document":
                    return(DocumentLink.Parse(value));

                case "Link.file":
                    return(FileLink.Parse(value));

                case "Link.image":
                    return(ImageLink.Parse(value));
                }
                return(null);
            }
示例#7
0
            public static PlateSolution PlateSolve(string path)
            {
                ImageLink tsxl = new ImageLink
                {
                    pathToFITS = path
                };

                try
                { tsxl.execute(); }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return(null);
                }
                ImageLinkResults tsxr = new ImageLinkResults();
                ccdsoftCamera    tcam = new ccdsoftCamera();
                PlateSolution    ipa  = new PlateSolution
                {
                    ImageRA         = tsxr.imageCenterRAJ2000,
                    ImageDec        = tsxr.imageCenterDecJ2000,
                    ImagePA         = tsxr.imagePositionAngle,
                    ImageIsMirrored = Convert.ToBoolean(tsxr.imageIsMirrored)
                };

                return(ipa);
            }
示例#8
0
 public static ImageLink GetImageInfo(string url)
 {
     try
     {
         System.Net.WebRequest req = System.Net.HttpWebRequest.Create(url);
         req.Method = "HEAD";
         ImageLink obj           = new ImageLink();
         int       ContentLength = 0;
         using (System.Net.WebResponse resp = req.GetResponse())
         {
             int.TryParse(resp.Headers.Get("Content-Length"), out ContentLength);
             obj.FileSizeBytes = ContentLength;
             obj.FileSizeKB    = ContentLength > 0 && ContentLength > 1024 ? ContentLength / 1024 : 0;
             obj.FileType      = resp.Headers.Get("Content-Type") ?? "";
             obj.Date          = resp.Headers.Get("Date") ?? "";
             obj.LastModified  = resp.Headers.Get("Last-Modified") ?? "";
         }
         obj.FileName = GetFileName(url);
         obj.Link     = url;
         return(obj);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
示例#9
0
 private void SetImageLinks(Food food)
 {
     if (food.Image != null)
     {
         food.Image = ImageLink.GetFoodImageLink(food.Id);
     }
     SetImageLinks(food.Author);
 }
示例#10
0
        /* Function: GetBodyLinks
         * Goes through the body of the passed <Topic> and adds any Natural Docs and image links it finds in the <NDMarkup>
         * to <LinkSet> and <ImageLinkSet>.
         */
        protected void GetBodyLinks(Topic topic, ref LinkSet linkSet, ref ImageLinkSet imageLinkSet)
        {
            if (topic.Body == null)
            {
                return;
            }

            NDMarkup.Iterator iterator = new NDMarkup.Iterator(topic.Body);

            // Doing two passes of GoToFirstTag is probably faster than iterating through each element

            if (iterator.GoToFirstTag("<link type=\"naturaldocs\""))
            {
                do
                {
                    Link link = new Link();

                    // ignore LinkID
                    link.Type    = LinkType.NaturalDocs;
                    link.Text    = iterator.Property("originaltext");
                    link.Context = topic.BodyContext;
                    // ignore contextID
                    link.FileID      = topic.FileID;
                    link.ClassString = topic.ClassString;
                    // ignore classID
                    link.LanguageID = topic.LanguageID;
                    // ignore EndingSymbol
                    // ignore TargetTopicID
                    // ignore TargetScore

                    linkSet.Add(link);
                }while (iterator.GoToNextTag("<link type=\"naturaldocs\""));
            }

            iterator = new NDMarkup.Iterator(topic.Body);

            if (iterator.GoToFirstTag("<image"))
            {
                do
                {
                    ImageLink imageLink = new ImageLink();

                    // ignore ImageLinkID
                    imageLink.OriginalText = iterator.Property("originaltext");
                    imageLink.Path         = new Path(iterator.Property("target"));
                    // ignore FileName, generated from Path
                    imageLink.FileID      = topic.FileID;
                    imageLink.ClassString = topic.ClassString;
                    // ignore classID
                    // ignore TargetFileID
                    // ignore TargetScore

                    imageLinkSet.Add(imageLink);
                }while (iterator.GoToNextTag("<image"));
            }
        }
示例#11
0
            public static Fragment Parse(String type, JToken json)
            {
                switch (type)
                {
                case "StructuredText":
                    return(StructuredText.Parse(json));

                case "Image":
                    return(Image.Parse(json));

                case "Link.web":
                    return(WebLink.Parse(json));

                case "Link.document":
                    return(DocumentLink.Parse(json));

                case "Link.file":
                    return(FileLink.Parse(json));

                case "Link.image":
                    return(ImageLink.Parse(json));

                case "Text":
                    return(Text.Parse(json));

                case "Select":
                    return(Text.Parse(json));

                case "Date":
                    return(Date.Parse(json));

                case "Timestamp":
                    return(Timestamp.Parse(json));

                case "Number":
                    return(Number.Parse(json));

                case "Color":
                    return(Color.Parse(json));

                case "Embed":
                    return(Embed.Parse(json));

                case "GeoPoint":
                    return(GeoPoint.Parse(json));

                case "Group":
                    return(Group.Parse(json));

                case "SliceZone":
                    return(SliceZone.Parse(json));

                default:
                    return(json != null?Raw.Parse(json) : null);
                }
            }
示例#12
0
        public Task <string> GetUrl(ImageLink link)
        {
            if (link.Adapter != ImageAdapter.AzureFile)
            {
                throw new NotImplementedException("Only azure storage is supproted");
            }

            var meta = AzureAdapterMetadata.Parse(link.Metadata);

            return(Task.FromResult(meta.Url));
        }
示例#13
0
        public void OnDeleteImageLink(ImageLink imageLink, CodeDB.EventAccessor eventAccessor)
        {
            // We don't have to force any HTML to be rebuilt here.  This can only happen if the containing topic was
            // changed so we can rely on the topic code to handle that.

            // However, this could change whether the image file is used or unused, so we have to add it to the list.
            if (imageLink.TargetFileID != 0)
            {
                unprocessedChanges.AddImageFileUseCheck(imageLink.TargetFileID);
            }
        }
示例#14
0
        public void TestImageLink()
        {
            var link = new ImageLink(imageid: 9, linkId: 3, width: 2, height: 1000, format: "asdf", adapter: ImageAdapter.AzureFile, metadata: "la la la");

            Assert.AreEqual(9, link.ImageId);
            Assert.AreEqual(3, link.LinkId);
            Assert.AreEqual(2, link.Width);
            Assert.AreEqual(1000, link.Height);
            Assert.AreEqual("asdf", link.Format);
            Assert.AreEqual(ImageAdapter.AzureFile, link.Adapter);
            Assert.AreEqual("la la la", link.Metadata);
        }
示例#15
0
        public void TestImage()
        {
            var testTime = new DateTime(2000, 1, 1);

            var link  = new ImageLink(0, 0, 0, 0, "asdf", ImageAdapter.Unknown, "");
            var image = new Image(id: 5, slug: "slug", description: "description", whenCreated: testTime, links: new[] { link });

            Assert.AreEqual(5, image.Id);
            Assert.AreEqual("slug", image.Slug);
            Assert.AreEqual("description", image.Description);
            Assert.AreEqual(1, image.Links.Count);
            Assert.AreEqual(testTime, image.WhenCreated);
        }
示例#16
0
        /// <summary>
        /// Asks TSX for the star count in an image
        /// </summary>
        /// <param name="fPath"></param>
        /// <returns></returns>
        private static int CountStars(string fPath)
        {
            //Have TSX open the fits file fPath
            ImageLink tsxil = new ImageLink();

            tsxil.pathToFITS = fPath;
            //Image Link the image, return 0 if it fails
            try { tsxil.execute(); }
            catch (Exception ex) { return(0); }
            //return the count of stars
            ImageLinkResults tsxilr = new ImageLinkResults();

            return(tsxilr.imageStarCount);
        }
示例#17
0
        public ActionResult AddAvatar(Guid articleId)
        {
            ImageLink _model = new ImageLink();

            _model.ArticleId = articleId;
            if (Request.IsAjaxRequest())
            {
                return(PartialView("Articles/_AddAvatar", _model));
            }
            else
            {
                return(View("Articles/_AddAvatar", _model));
            }
        }
示例#18
0
 private static String serialize(Span span, String content, DocumentLinkResolver linkResolver, HtmlSerializer htmlSerializer)
 {
     if (htmlSerializer != null)
     {
         String customHtml = htmlSerializer.Serialize(span, content);
         if (customHtml != null)
         {
             return(customHtml);
         }
     }
     if (span is Strong)
     {
         return("<strong>" + content + "</strong>");
     }
     if (span is Em)
     {
         return("<em>" + content + "</em>");
     }
     if (span is LabelSpan)
     {
         return("<span class=\"" + ((LabelSpan)span).Label + "\">" + content + "</span>");
     }
     if (span is Hyperlink)
     {
         Hyperlink hyperlink = (Hyperlink)span;
         if (hyperlink.Link is WebLink)
         {
             WebLink webLink = (WebLink)hyperlink.Link;
             return("<a href=\"" + webLink.Url + "\">" + content + "</a>");
         }
         else if (hyperlink.Link is FileLink)
         {
             FileLink fileLink = (FileLink)hyperlink.Link;
             return("<a href=\"" + fileLink.Url + "\">" + content + "</a>");
         }
         else if (hyperlink.Link is ImageLink)
         {
             ImageLink imageLink = (ImageLink)hyperlink.Link;
             return("<a href=\"" + imageLink.Url + "\">" + content + "</a>");
         }
         else if (hyperlink.Link is DocumentLink)
         {
             DocumentLink documentLink = (DocumentLink)hyperlink.Link;
             String       url          = linkResolver.Resolve(documentLink);
             return("<a " + (linkResolver.GetTitle(documentLink) == null ? "" : "title=\"" + linkResolver.GetTitle(documentLink) + "\" ") + "href=\"" + url + "\">" + content + "</a>");
         }
     }
     return("<span>" + content + "</span>");
 }
示例#19
0
        private double PlateSolve()
        {
            //runs an image link on the current location to get PA data
            //assume camera, mount etc are connected and properly configured.
            ccdsoftCamera tsxcc = new ccdsoftCamera
            {
                Autoguider   = 0,
                Frame        = ccdsoftImageFrame.cdLight,
                ExposureTime = 10,
                Delay        = 0,
                Asynchronous = 0,
                AutoSaveOn   = 1,
                Subframe     = 0
            };

            try { tsxcc.TakeImage(); }
            catch (Exception ex)
            {
                WriteLog(ex.Message);
                return(0);
            }

            ccdsoftImage tsxi  = new ccdsoftImage();
            ImageLink    tsxil = new ImageLink
            {
                pathToFITS = tsxcc.LastImageFileName,
                scale      = 1.70
            };

            try { tsxil.execute(); }
            catch (Exception ex)
            {
                return(0);
            }
            ImageLinkResults tsxir = new ImageLinkResults();
            double           iPA   = tsxir.imagePositionAngle;

            //Check for image link success, return 0 if not.
            if (tsxir.succeeded == 1)
            {
                return(iPA);
            }
            else
            {
                return(0);
            }
        }
示例#20
0
        public void OnChangeImageLinkTarget(ImageLink imageLink, int oldTargetFileID, CodeDB.EventAccessor eventAccessor)
        {
            // Here we have to rebuild the HTML containing the link because this could happen without the containing
            // topic changing, such as if an image file was deleted or a new one served as a better target.

            unprocessedChanges.AddSourceFile(imageLink.FileID);

            if (imageLink.ClassID != 0)
            {
                unprocessedChanges.AddClass(imageLink.ClassID);
            }


            // We also have to check both image files because they could have changed between used and unused.

            if (imageLink.TargetFileID != 0)
            {
                unprocessedChanges.AddImageFileUseCheck(imageLink.TargetFileID);
            }
            if (oldTargetFileID != 0)
            {
                unprocessedChanges.AddImageFileUseCheck(oldTargetFileID);
            }


            // We also have to see if it appears in the summary for any topics.  This would mean that it appears in these topics'
            // tooltips, so we have to find any links to these topics and rebuild the files those links appear in.

            // Why do we have to do this if links aren't added to tooltips?  Because how it's resolved can affect it's appearance.
            // It will show up as "(see diagram)" versus "(see images/diagram.jpg)" if it's resolved or not.

            IDObjects.NumberSet fileIDs, classIDs;
            eventAccessor.GetInfoOnLinksToTopicsWithImageLinkInSummary(imageLink, out fileIDs, out classIDs);

            if (fileIDs != null)
            {
                unprocessedChanges.AddSourceFiles(fileIDs);
            }
            if (classIDs != null)
            {
                unprocessedChanges.AddClasses(classIDs);
            }
        }
示例#21
0
        /* Function: AppendInlineImageLink
         */
        protected void AppendInlineImageLink(NDMarkup.Iterator iterator, StringBuilder output)
        {
            // Create a link object with the identifying properties needed to look it up in the list of links.

            ImageLink imageLinkStub = new ImageLink();

            imageLinkStub.OriginalText = iterator.Property("originaltext");
            imageLinkStub.FileID       = context.Topic.FileID;
            imageLinkStub.ClassString  = context.Topic.ClassString;
            imageLinkStub.ClassID      = context.Topic.ClassID;


            // Find the actual link so we know if it resolved to anything.

            ImageLink fullImageLink = null;

            foreach (var imageLink in imageLinks)
            {
                if (imageLink.SameIdentifyingPropertiesAs(imageLinkStub))
                {
                    fullImageLink = imageLink;
                    break;
                }
            }

                        #if DEBUG
            if (fullImageLink == null)
            {
                throw new Exception("All image links in a topic must be in the list passed to HTMLTooltip.");
            }
                        #endif


            if (fullImageLink.IsResolved)
            {
                output.EntityEncodeAndAppend(iterator.Property("linktext"));
            }
            else
            {
                output.EntityEncodeAndAppend(iterator.Property("originaltext"));
            }
        }
示例#22
0
        public ActionResult Create(ImageLink imageLink, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                if (image != null)
                {
                    var webImage = new WebImage(image.InputStream) { FileName = image.FileName };
                    var imageLinkCategory = db.ImageLinkCategories.Single(ilc => ilc.Id == imageLink.ImageLinkCategoryId);
                    imageLink.ImagePath = ImagesManager.UploadImage(webImage.Resize(imageLinkCategory.MaxWidth, imageLinkCategory.MaxHeight, true, true), "ImageLink");

                    db.ImageLinks.AddObject(imageLink);

                    db.SaveChanges();

                    TempData["Result"] = Resource.ChangesSaved;
                    return RedirectToAction("Index");
                }
            }
            return Create();
        }
示例#23
0
        public BaseResponse <User> Get()
        {
            BaseResponse <User> response = null;

            try
            {
                int  userId = int.Parse(Request.Query["userId"]);
                User user   = userRepository.Get(userId);
                user = user.Clone();

                user.Token  = null;
                user.Avatar = ImageLink.GetUserAvatarLink(user.Id);
                response    = new BaseResponse <User>(user);
            }
            catch (Exception ex)
            {
                response = new BaseResponse <User> {
                    Error = ex.Message
                };
            }
            return(response);
        }
示例#24
0
        public ImageLink GetImageLink(IPublishedContent imageLinkContentItem)
        {
            var imageLink = new ImageLink();

            if (imageLinkContentItem == null)
            {
                return(imageLink);
            }

            imageLink.Image = _mediaModelService
                              .GetMediaModel(imageLinkContentItem
                                             .GetPropertyValue <IPublishedContent>(PropertyAliases.ImageLink.Image));

            var multiUrls = imageLinkContentItem.GetPropertyValue <MultiUrls>(PropertyAliases.ImageLink.Link);

            if (!multiUrls.IsNullOrEmpty())
            {
                imageLink.Link = multiUrls.FirstOrDefault();
            }

            return(imageLink);
        }
示例#25
0
        public ActionResult AddAvatar(ImageLink model)
        {
            try
            {
                var _object = _articleManager.GetByIdAsync(model.ArticleId.Value).Result;
                _object.AvatarPath = model.Link;
                _object.UpdatedBy  = User.Identity.Name;
                _articleManager.Update(_object);

                if (Request.IsAjaxRequest())
                {
                    return(PartialView("Messages/_HtmlString", "Changed avatar"));
                }
                else
                {
                    return(RedirectToAction("Details", "Articles", new { id = _object.Id }));
                }
            }
            catch
            {
                return(View());
            }
        }
示例#26
0
        static double PlateSolve()
        {
            //runs an image link on the current location to get PA data
            //assume camera, mount etc are connected and properly configured.
            ccdsoftCamera tsxcc = new ccdsoftCamera
            {
                Autoguider   = 0,
                Frame        = ccdsoftImageFrame.cdLight,
                ExposureTime = 10,
                Delay        = 0,
                Asynchronous = 0,
                AutoSaveOn   = 1
            };

            tsxcc.TakeImage();

            ccdsoftImage tsxi  = new ccdsoftImage();
            ImageLink    tsxil = new ImageLink
            {
                scale      = TSXLink.FOVI.GetFOVScale(), //set Scale
                pathToFITS = tsxcc.LastImageFileName
            };

            tsxil.execute();
            ImageLinkResults tsxir = new ImageLinkResults();
            double           iPA   = tsxir.imagePositionAngle;

            //Check for image link success, return 0 if not.
            if (tsxir.succeeded == 1)
            {
                return(iPA);
            }
            else
            {
                return(0);
            }
        }
示例#27
0
 public void IncrementRating(ImageLink imageLink)
 {
     _userVoteProvider.Put(new UserVoteImpl(this, imageLink));
 }
示例#28
0
 public void OnDeleteImageLink(ImageLink imageLink, CodeDB.EventAccessor eventAccessor)
 {
     // xxx placeholder
 }
示例#29
0
 public void OnChangeImageLinkTarget(ImageLink imageLink, int oldTargetFileID, CodeDB.EventAccessor eventAccessor)
 {
     // xxx placeholder
 }
示例#30
0
        public ActionResult Edit(ImageLink imageLink, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                if (image != null)
                {
                    if (!String.IsNullOrWhiteSpace(imageLink.ImagePath))
                        ImagesManager.DeleteImage(Path.GetFileName(imageLink.ImagePath), "ImageLink");
                    var webImage = new WebImage(image.InputStream) { FileName = image.FileName };
                    var imageLinkCategory = db.ImageLinkCategories.Single(ilc => ilc.Id == imageLink.ImageLinkCategoryId);
                    imageLink.ImagePath = ImagesManager.UploadImage(webImage.Resize(imageLinkCategory.MaxWidth, imageLinkCategory.MaxHeight, true, true), "ImageLink");
                }
                db.ImageLinks.Attach(imageLink);
                db.ObjectStateManager.ChangeObjectState(imageLink, EntityState.Modified);

                db.SaveChanges();

                TempData["Result"] = Resource.ChangesSaved;
                return RedirectToAction("Index");
            }
            return Edit(imageLink.Id);
        }
 public UserVoteImpl(User user, ImageLink imageLink)
 {
     User = user;
     ImageLink = imageLink;
 }
示例#32
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;
        }
示例#33
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;
        }
示例#34
0
        /* Function: AppendInlineImageLink
         */
        protected void AppendInlineImageLink(NDMarkup.Iterator iterator, StringBuilder linkOutput, StringBuilder imageOutput, int imageNumber)
        {
            // Create a link object with the identifying properties needed to look it up in the list of links.

            ImageLink imageLinkStub = new ImageLink();

            imageLinkStub.OriginalText = iterator.Property("originaltext");
            imageLinkStub.FileID       = context.Topic.FileID;
            imageLinkStub.ClassString  = context.Topic.ClassString;
            imageLinkStub.ClassID      = context.Topic.ClassID;


            // Find the actual link so we know if it resolved to anything.

            ImageLink fullImageLink = null;

            foreach (var imageLink in imageLinks)
            {
                if (imageLink.SameIdentifyingPropertiesAs(imageLinkStub))
                {
                    fullImageLink = imageLink;
                    break;
                }
            }

                        #if DEBUG
            if (fullImageLink == null)
            {
                throw new Exception("All image links in a topic must be in the list passed to HTMLTopic.");
            }
                        #endif


            // If it didn't resolve, we just output the original text and we're done.

            if (!fullImageLink.IsResolved)
            {
                linkOutput.EntityEncodeAndAppend(iterator.Property("originaltext"));
                return;
            }


            Files.ImageFile targetFile  = (Files.ImageFile)EngineInstance.Files.FromID(fullImageLink.TargetFileID);
            string          description = targetFile.FileName.NameWithoutPathOrExtension;
            string          anchor      = "Topic" + context.Topic.TopicID + "_Image" + imageNumber;

            var  fileSource               = EngineInstance.Files.FileSourceOf(targetFile);
            Path relativeTargetPath       = fileSource.MakeRelative(targetFile.FileName);
            Path targetOutputPath         = Paths.Image.OutputFile(context.Target.OutputFolder, fileSource.Number, fileSource.Type, relativeTargetPath);
            Path relativeTargetOutputPath = targetOutputPath.MakeRelativeTo(context.OutputFile.ParentFolder);

            linkOutput.Append(
                "<a href=\"#" + anchor + "\" class=\"SeeImageLink\">" +
                iterator.Property("linktext").EntityEncode() +
                "</a>");

            imageOutput.Append(
                "<div class=\"CImage\">" +

                "<a name=\"" + anchor + "\"></a>" +

                "<a href=\"" + relativeTargetOutputPath.ToURL().EntityEncode() + "\" target=\"_blank\" class=\"ZoomLink\">" +

                "<img src=\"" + relativeTargetOutputPath.ToURL().EntityEncode() + "\" loading=\"lazy\" " +
                (targetFile.DimensionsKnown ?
                 "class=\"KnownDimensions\" width=\"" + targetFile.Width + "\" height=\"" + targetFile.Height + "\" " +
                 "style=\"max-width: " + targetFile.Width + "px\" " :
                 "class=\"UnknownDimensions\" ") +
                "alt=\"" + description.EntityEncode() + "\" />" +

                "</a>" +

                "<div class=\"CICaption\">" +
                description.EntityEncode() +
                "</div>" +

                "</div>");
        }
示例#35
0
 public void OnDeleteImageLink(ImageLink imageLink, CodeDB.EventAccessor eventAccessor)
 {
     // We don't care about image links.
 }
示例#36
0
 public void OnChangeImageLinkTarget(ImageLink imageLink, int oldTargetFileID, CodeDB.EventAccessor eventAccessor)
 {
     // We don't care about image links.
 }