Example #1
0
        public async Task StoreId(LinkSet Set)
        {
            Set.LinkId = ToolKit.RandomString(8);
            await _context.Links.AddAsync(Set);

            await _context.SaveChangesAsync().ConfigureAwait(false);
        }
Example #2
0
 public virtual void SetLinkSet(LinkSet linkSet)
 {
     this.linkSet = linkSet;
     foreach (FONode child in children)
     {
         child.SetLinkSet(linkSet);
     }
 }
Example #3
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"));
            }
        }
Example #4
0
        /* Function: ExtractTypeLinks
         * Goes through the prototype of the passed <Topic> and adds any type links it finds to <LinkSet>.
         */
        protected void ExtractTypeLinks(Topic topic, LinkSet linkSet)
        {
            if (topic.Prototype == null)
            {
                return;
            }

            Language language = EngineInstance.Languages.FromID(topic.LanguageID);

            TokenIterator symbolStart = topic.ParsedPrototype.Tokenizer.FirstToken;
            TokenIterator symbolEnd;

            while (symbolStart.IsInBounds)
            {
                if (symbolStart.PrototypeParsingType == PrototypeParsingType.Type ||
                    symbolStart.PrototypeParsingType == PrototypeParsingType.TypeQualifier)
                {
                    symbolEnd = symbolStart;

                    do
                    {
                        symbolEnd.Next();
                    }while (symbolEnd.PrototypeParsingType == PrototypeParsingType.Type ||
                            symbolEnd.PrototypeParsingType == PrototypeParsingType.TypeQualifier);

                    if (language.IsBuiltInType(symbolStart, symbolEnd) == false)
                    {
                        Link link = new Link();

                        // ignore LinkID
                        link.Type    = LinkType.Type;
                        link.Symbol  = SymbolString.FromPlainText_NoParameters(symbolStart.Tokenizer.TextBetween(symbolStart, symbolEnd));
                        link.Context = topic.PrototypeContext;
                        // 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);
                    }

                    symbolStart = symbolEnd;
                }

                else
                {
                    symbolStart.Next();
                }
            }
        }
Example #5
0
        protected static int addRealText(BlockArea ba, FontState fontState,
                                         float red, float green, float blue,
                                         WrapOption wrapOption, LinkSet ls,
                                         int whiteSpaceCollapse, char[] data,
                                         int start, int end, TextState textState,
                                         VerticalAlign vAlign)
        {
            int ts, te;

            char[] ca;

            ts = start;
            te = end;
            ca = data;

            LineArea la = ba.getCurrentLineArea();

            if (la == null)
            {
                return(start);
            }

            la.changeFont(fontState);
            la.changeColor(red, green, blue);
            la.changeWrapOption(wrapOption);
            la.changeWhiteSpaceCollapse(whiteSpaceCollapse);
            la.changeVerticalAlign(vAlign);
            ba.setupLinkSet(ls);

            ts = la.addText(ca, ts, te, ls, textState);

            while (ts != -1)
            {
                la = ba.createNextLineArea();
                if (la == null)
                {
                    return(ts);
                }
                la.changeFont(fontState);
                la.changeColor(red, green, blue);
                la.changeWrapOption(wrapOption);
                la.changeWhiteSpaceCollapse(whiteSpaceCollapse);
                ba.setupLinkSet(ls);

                ts = la.addText(ca, ts, te, ls, textState);
            }
            return(-1);
        }
Example #6
0
        public override Status Layout(Area area)
        {
            string destination;

            Fonet.Pdf.LinkKind linkType;

            AccessibilityProps    mAccProps = propMgr.GetAccessibilityProps();
            AuralProps            mAurProps = propMgr.GetAuralProps();
            BorderAndPadding      bap       = propMgr.GetBorderAndPadding();
            BackgroundProps       bProps    = propMgr.GetBackgroundProps();
            MarginInlineProps     mProps    = propMgr.GetMarginInlineProps();
            RelativePositionProps mRelProps = propMgr.GetRelativePositionProps();

            if (!(destination =
                      this.properties.GetProperty("internal-destination").GetString()).Equals(""))
            {
                linkType = Pdf.LinkKind.Internal;
            }
            else if (!(destination =
                           this.properties.GetProperty("external-destination").GetString()).Equals(""))
            {
                linkType = Pdf.LinkKind.External;
            }
            else
            {
                throw new FonetException("internal-destination or external-destination must be specified in basic-link");
            }

            if (this.marker == MarkerStart)
            {
                string   id   = this.properties.GetProperty("id").GetString();
                MyIDRefs refs = (MyIDRefs)area.getIDReferences();

                refs.InitializeID(id, area);
                this.marker = 0;
            }

            LinkSet ls = new LinkSet(destination, area, linkType);

            AreaContainer ac = area.getNearestAncestorAreaContainer();

            while (ac != null && ac.getPosition() != Position.ABSOLUTE)
            {
                ac = ac.getNearestAncestorAreaContainer();
            }
            if (ac == null)
            {
                ac = area.getPage().getBody().getCurrentColumnArea();
            }

            int numChildren = this.children.Count;

            for (int i = this.marker; i < numChildren; i++)
            {
                FONode fo = (FONode)children[i];
                fo.SetLinkSet(ls);

                Status status;
                if ((status = fo.Layout(area)).isIncomplete())
                {
                    this.marker = i;
                    return(status);
                }
            }

            ls.applyAreaContainerOffsets(ac, area);
            area.getPage().addLinkSet(ls);

            return(new Status(Status.OK));
        }
Example #7
0
        /* Function: GetPrototypeLinks
         * Goes through the prototype of the passed <Topic> and adds any type links it finds to <LinkSet>.
         */
        protected void GetPrototypeLinks(Topic topic, ref LinkSet linkSet)
        {
            if (topic.Prototype == null)
            {
                return;
            }

            Language language = EngineInstance.Languages.FromID(topic.LanguageID);

            // We do this even for topics in the class hierarchy because the HTML output falls back to regular prototypes
            // if there's no class prototype.  Also, if there's parameter lists in the description the HTML generator will require
            // type links to exist regardless of what type of prototype it creates.  For example, this SystemVerilog interface:
            //
            //    // Interface: myInterface
            //    //
            //    // Parameters:
            //    //    PARAMNAME - description
            //
            //    interface myInterface #(parameter PARAMNAME = 8) (input reset, clk);
            //
            // The HTML generation for the Parameters section will expect a type link to exist for PARAMNAME.

            TokenIterator symbolStart = topic.ParsedPrototype.Tokenizer.FirstToken;
            TokenIterator symbolEnd;

            while (symbolStart.IsInBounds)
            {
                if (symbolStart.PrototypeParsingType == PrototypeParsingType.Type ||
                    symbolStart.PrototypeParsingType == PrototypeParsingType.TypeQualifier)
                {
                    symbolEnd = symbolStart;

                    do
                    {
                        symbolEnd.Next();
                    }while (symbolEnd.PrototypeParsingType == PrototypeParsingType.Type ||
                            symbolEnd.PrototypeParsingType == PrototypeParsingType.TypeQualifier);

                    if (language.Parser.IsBuiltInType(symbolStart, symbolEnd) == false)
                    {
                        Link link = new Link();

                        // ignore LinkID
                        link.Type    = LinkType.Type;
                        link.Symbol  = SymbolString.FromPlainText_NoParameters(symbolStart.TextBetween(symbolEnd));
                        link.Context = topic.PrototypeContext;
                        // 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);
                    }

                    symbolStart = symbolEnd;
                }

                else
                {
                    symbolStart.Next();
                }
            }
        }
Example #8
0
        // Group: Topic Functions
        // __________________________________________________________________________


        /* Function: GetLinks
         * Goes through the body and prototype of the passed <Topic> and adds any Natural Docs and image links it finds in the
         * <NDMarkup> to <LinkSet> and <ImageLinkSet>.
         */
        protected void GetLinks(Topic topic, ref LinkSet linkSet, ref ImageLinkSet imageLinkSet)
        {
            GetBodyLinks(topic, ref linkSet, ref imageLinkSet);
            GetPrototypeLinks(topic, ref linkSet);
        }
Example #9
0
        /* Function: ProcessNewOrChangedSourceFile
         * Takes a new or changed <File>, parses it, and updates <CodeDB.Manager> with its contents.  The <CodeDB.Accessor>
         * should NOT already hold a lock.
         */
        protected ProcessFileResult ProcessNewOrChangedSourceFile(File file, Engine.CodeDB.Accessor codeDBAccessor,
                                                                  CancelDelegate cancelDelegate)
        {
            try
            {
                var           language   = EngineInstance.Languages.FromFileName(file.FileName);
                IList <Topic> topics     = null;
                LinkSet       links      = null;
                ImageLinkSet  imageLinks = null;


                // Parse the file

                var parseResult = language.Parser.Parse(file.FileName, file.ID, cancelDelegate, out topics, out links);

                if (parseResult == Parser.ParseResult.Cancelled)
                {
                    return(ProcessFileResult.Cancelled);
                }
                else if (parseResult == Parser.ParseResult.CantAccessFile)
                {
                    return(ProcessFileResult.CantAccessFile);
                }
                else if (parseResult == Parser.ParseResult.FileDoesntExist)
                {
                    return(ProcessFileResult.FileDoesntExist);
                }


                // Extract links from the bodies and prototypes

                if (topics != null && topics.Count > 0)
                {
                    imageLinks = new ImageLinkSet();

                    foreach (Topic topic in topics)
                    {
                        GetLinks(topic, ref links, ref imageLinks);

                        if (cancelDelegate())
                        {
                            return(ProcessFileResult.Cancelled);
                        }
                    }
                }


                // Update the database

                codeDBAccessor.GetReadPossibleWriteLock();

                try
                {
                    if (topics != null && topics.Count > 0)
                    {
                        codeDBAccessor.UpdateTopicsInFile(file.ID, topics, cancelDelegate);
                    }
                    else
                    {
                        codeDBAccessor.DeleteTopicsInFile(file.ID, cancelDelegate);
                    }

                    if (links != null && links.Count > 0)
                    {
                        codeDBAccessor.UpdateLinksInFile(file.ID, links, cancelDelegate);
                    }
                    else
                    {
                        codeDBAccessor.DeleteLinksInFile(file.ID, cancelDelegate);
                    }

                    if (imageLinks != null && imageLinks.Count > 0)
                    {
                        codeDBAccessor.UpdateImageLinksInFile(file.ID, imageLinks, cancelDelegate);
                    }
                    else
                    {
                        codeDBAccessor.DeleteImageLinksInFile(file.ID, cancelDelegate);
                    }

                    // Need this check in case CodeDB quit early because of the cancel delegate.
                    if (cancelDelegate())
                    {
                        return(ProcessFileResult.Cancelled);
                    }
                }
                finally
                { codeDBAccessor.ReleaseLock(); }

                return(ProcessFileResult.Success);
            }

            catch (Exception e)
            {
                try
                { e.AddNaturalDocsTask("Parsing file " + file.FileName); }
                catch
                {  }

                throw;
            }
        }
Example #10
0
        override public ParseResult Parse(Path filePath, int fileID, CancelDelegate cancelDelegate,
                                          out IList <Topic> topics, out LinkSet classParentLinks)
        {
            topics           = null;
            classParentLinks = null;

            StreamReader file     = null;
            Language     language = null;
            string       content  = null;

            try
            {
                file = new StreamReader(filePath.ToString(), System.Text.Encoding.UTF8, true);

                // If there's no shebang line we treat it as a successful parse with no content.
                if ((char)file.Read() != '#')
                {
                    return(ParseResult.Success);
                }
                if ((char)file.Read() != '!')
                {
                    return(ParseResult.Success);
                }

                // If there's a shebang then it should be safe to use ReadLine().  There's a chance extensionless files are binary so
                // we don't want to use ReadLine() right away in case it returns the entire file and the file is huge.
                string shebangLine = file.ReadLine();

                language = Manager.FromShebangLine(shebangLine);

                if (language != null)
                {
                    content = file.ReadToEnd() ?? "";
                }
            }

            catch (System.IO.FileNotFoundException)
            { return(ParseResult.FileDoesntExist); }
            catch (System.IO.DirectoryNotFoundException)
            { return(ParseResult.FileDoesntExist); }
            catch
            { return(ParseResult.CantAccessFile); }
            finally
            {
                if (file != null)
                {
                    file.Dispose();
                    file = null;
                }
            }

            if (language == null)
            {
                return(ParseResult.Success);
            }

            // Since we ate the first line, start the tokenizer at line 2.
            Tokenizer tokenizedContent = new Tokenizer(content, startingLineNumber: 2, tabWidth: EngineInstance.Config.TabWidth);

            return(language.Parse(tokenizedContent, fileID, cancelDelegate, out topics, out classParentLinks));
        }
Example #11
0
        public static int addText(BlockArea ba, FontState fontState, float red,
                                  float green, float blue, WrapOption wrapOption,
                                  LinkSet ls, int whiteSpaceCollapse,
                                  char[] data, int start, int end,
                                  TextState textState, VerticalAlign vAlign)
        {
            if (fontState.FontVariant == FontVariant.SMALL_CAPS)
            {
                FontState smallCapsFontState;
                try
                {
                    int smallCapsFontHeight =
                        (int)(((double)fontState.FontSize) * 0.8d);
                    smallCapsFontState = new FontState(fontState.FontInfo,
                                                       fontState.FontFamily,
                                                       fontState.FontStyle,
                                                       fontState.FontWeight,
                                                       smallCapsFontHeight,
                                                       FontVariant.NORMAL);
                }
                catch (FonetException ex)
                {
                    smallCapsFontState = fontState;
                    FonetDriver.ActiveDriver.FireFonetError(
                        "Error creating small-caps FontState: " + ex.Message);
                }

                char      c;
                bool      isLowerCase;
                int       caseStart;
                FontState fontStateToUse;
                for (int i = start; i < end;)
                {
                    caseStart   = i;
                    c           = data[i];
                    isLowerCase = (Char.IsLetter(c) && Char.IsLower(c));
                    while (isLowerCase == (Char.IsLetter(c) && Char.IsLower(c)))
                    {
                        if (isLowerCase)
                        {
                            data[i] = Char.ToUpper(c);
                        }
                        i++;
                        if (i == end)
                        {
                            break;
                        }
                        c = data[i];
                    }
                    if (isLowerCase)
                    {
                        fontStateToUse = smallCapsFontState;
                    }
                    else
                    {
                        fontStateToUse = fontState;
                    }
                    int index = addRealText(ba, fontStateToUse, red, green, blue,
                                            wrapOption, ls, whiteSpaceCollapse,
                                            data, caseStart, i, textState,
                                            vAlign);
                    if (index != -1)
                    {
                        return(index);
                    }
                }

                return(-1);
            }

            return(addRealText(ba, fontState, red, green, blue, wrapOption, ls,
                               whiteSpaceCollapse, data, start, end, textState,
                               vAlign));
        }
Example #12
0
 public override void SetLinkSet(LinkSet linkSet)
 {
 }
Example #13
0
        public async Task <IActionResult> link(LinkSet Set)
        {
            await _repo.StoreId(Set);

            return(Ok(Set.LinkId));
        }
Example #14
0
        /* Function: ProcessChangedFile
         * Takes a changed <File>, parses it, and updates <CodeDB.Manager> with its contents.  It returns the result code that
         * should be passed to <ReleaseClaimedFile()> if the file was retrieved with <ClaimChangedFile()>.  The <CodeDB.Accessor>
         * should NOT already hold a lock.
         */
        public ReleaseClaimedFileReason ProcessChangedFile(File file, Engine.CodeDB.Accessor codeDBAccessor,
                                                           CancelDelegate cancelDelegate)
        {
            // Process source files

            if (file.Type == FileType.Source)
            {
                try
                {
                    var           language   = EngineInstance.Languages.FromFileName(file.FileName);
                    IList <Topic> topics     = null;
                    LinkSet       links      = null;
                    ImageLinkSet  imageLinks = null;

                    var parseResult = language.Parse(file.FileName, file.ID, cancelDelegate, out topics, out links);

                    if (parseResult == Language.ParseResult.FileDoesntExist)
                    {
                        return(ReleaseClaimedFileReason.FileDoesntExist);
                    }
                    else if (parseResult == Language.ParseResult.CantAccessFile)
                    {
                        return(ReleaseClaimedFileReason.CantAccessFile);
                    }
                    else if (parseResult == Language.ParseResult.Cancelled)
                    {
                        return(ReleaseClaimedFileReason.CancelledProcessing);
                    }


                    // Parse the topic bodies for Natural Docs links and image links.  Parse the prototypes for type links.

                    if (topics != null && topics.Count > 0)
                    {
                        imageLinks = new ImageLinkSet();

                        foreach (Topic topic in topics)
                        {
                            if (topic.Body != null)
                            {
                                ExtractBodyLinks(topic, links, imageLinks);

                                if (cancelDelegate())
                                {
                                    return(ReleaseClaimedFileReason.CancelledProcessing);
                                }
                            }

                            // We want to extract type links even for prototypes in the class hierarchy because the HTML output falls back to
                            // regular prototypes if there's no class prototype.  Also, if there's parameter lists in the description the HTML
                            // generator will require type links to exist regardless of what type of prototype it creates.  For example, this
                            // SystemVerilog interface:
                            //
                            //    // Interface: myInterface
                            //    //
                            //    // Parameters:
                            //    //    PARAMNAME - description
                            //
                            //    interface myInterface #(parameter PARAMNAME = 8) (input reset, clk);
                            //
                            // The HTML generation for the Parameters section will expect a type link to exist for PARAMNAME.
                            //
                            if (topic.Prototype != null
                                )
                            {
                                ExtractTypeLinks(topic, links);

                                if (cancelDelegate())
                                {
                                    return(ReleaseClaimedFileReason.CancelledProcessing);
                                }
                            }
                        }
                    }


                    // Update the database

                    codeDBAccessor.GetReadPossibleWriteLock();

                    try
                    {
                        if (topics != null && topics.Count > 0)
                        {
                            codeDBAccessor.UpdateTopicsInFile(file.ID, topics, cancelDelegate);
                        }
                        else
                        {
                            codeDBAccessor.DeleteTopicsInFile(file.ID, cancelDelegate);
                        }

                        if (links != null && links.Count > 0)
                        {
                            codeDBAccessor.UpdateLinksInFile(file.ID, links, cancelDelegate);
                        }
                        else
                        {
                            codeDBAccessor.DeleteLinksInFile(file.ID, cancelDelegate);
                        }

                        if (imageLinks != null && imageLinks.Count > 0)
                        {
                            codeDBAccessor.UpdateImageLinksInFile(file.ID, imageLinks, cancelDelegate);
                        }
                        else
                        {
                            codeDBAccessor.DeleteImageLinksInFile(file.ID, cancelDelegate);
                        }
                    }
                    finally
                    { codeDBAccessor.ReleaseLock(); }

                    // Need this final check in case CodeDB quit with a cancellation.
                    if (cancelDelegate())
                    {
                        return(ReleaseClaimedFileReason.CancelledProcessing);
                    }

                    return(ReleaseClaimedFileReason.SuccessfullyProcessed);
                }
                catch (Exception e)
                {
                    try
                    { e.AddNaturalDocsTask("Parsing File: " + file.FileName); }
                    catch
                    {  }

                    throw;
                }
            }


            // Process style and image files

            else
            {
                // These are only processed by output builders.  They're not in CodeDB so we don't need to do anything here.
                return(ReleaseClaimedFileReason.SuccessfullyProcessed);
            }
        }