Beispiel #1
0
        /// <summary>
        /// Gets colour from a string.
        /// </summary>
        /// <param name="Content">The string to determine an RGB(A) colour.</param>
        /// <returns>An RGBA colour.</returns>
        internal Color FMXAML_TextAPI_GetColourFromXMLValue(string Content)
        {
            byte[] FColours = Array.ConvertAll <string, byte>(Content.Split(','), Byte.Parse);


            if (FColours.Length < 3 | FColours.Length > 4)
            {
                FError.ThrowError(19, "Invalid colour supplied - not all or too many values present", FErrorSeverity.FatalError);
            }


            Color FForegroundColour = new Color {
                R = FColours[0], G = FColours[1], B = FColours[2]
            };

            if (FColours.Length > 3)
            {
                FForegroundColour.A = FColours[3];
            }
            else
            {
                FForegroundColour.A = 255; //otherwise stuff appears as invisible by default
            }

            return(FForegroundColour);
        }
Beispiel #2
0
        public IFApp FStartApp(string PathToApp) // "Compiled FApps" coming soon.
        {
            try
            {
                IFApp FApp = new FApp();

                FApp.AppPage = new XmlDocument();
                string _burn = $"{PathToApp}\\App.xml";

                if (_burn.Contains(':'))
                {
                    _burn.Remove(':');
                }

                FApp.AppPage.Load(_burn);
                FApp.AppPath   = PathToApp;
                FApp           = FStartApp_ParseAppXml(FApp, FApp.AppPage);
                FApp.Documents = new List <IFDocument>();
                FApp.Documents = FStartApp_LoadDocuments(FApp, FApp.Documents, false);
                FApp.TitlePage = FStartApp_LoadTitlePage(FApp, false);

                return(FApp);
            }
            catch (XmlException err)
            {
                FError.ThrowError(0, $"An error has occurred loading the app definition page located at {PathToApp}. Aborting load...", FErrorSeverity.Error, err);
                return(null);
            }
        }
Beispiel #3
0
        /// <summary>
        ///
        /// Parses MXaml in an arbitrary XmlNode.
        ///
        /// </summary>
        public RichTextBox FReadMXamlXml(XmlNode FXmlNode, RichTextBox BoxToPopulate)
        {
            try
            {
                XmlNodeList FXmlNodeList = FXmlNode.ChildNodes;

                foreach (XmlNode FPageContentElement in FXmlNodeList)
                {
                    // LAZY UGLY BAD HACK

                    MxamlNode MXaml_Parse = (MxamlNode)Enum.Parse(typeof(MxamlNode), FPageContentElement.Name);
                    switch (MXaml_Parse)
                    {
                    case MxamlNode.Paragraph:     // Temporary code for development of FMXAML_Parse_Paragraph
                        BoxToPopulate = FMXAML_Parse_Paragraph(FPageContentElement, BoxToPopulate);
                        continue;

                    case MxamlNode.TextBlock:
                        BoxToPopulate = FMXAML_Parse_TextBlock(FPageContentElement, BoxToPopulate);
                        continue;
                    }
                }

                return(BoxToPopulate);
            }
            catch (ArgumentException err)
            {
                FError.ThrowError(14, "An invalid mXAML node was found.", FErrorSeverity.FatalError, err);
                return(null);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Internal API for verifying that an XML node has child nodes. Throws error 24 and returns false if failed.
        /// </summary>
        /// <param name="DocumentToVerify">The XmlDocument to verify</param>
        /// <returns>true if the verification was successful, throws error 24 and returns false otherwise.</returns>
        internal bool FStartApp_VerifyChildNodes(XmlDocument DocumentToVerify)//public variant too
        {
            XmlNode FFirstChildToVerify = DocumentToVerify.FirstChild;

            if (FFirstChildToVerify != null)
            {
                while (FFirstChildToVerify.Name == "#comment")
                {
                    FFirstChildToVerify = FFirstChildToVerify.NextSibling;
                }

                if (!FFirstChildToVerify.HasChildNodes)
                {
                    FError.ThrowError(24, $"The node {FFirstChildToVerify.Name} in an XmlDocument must have child nodes.", FErrorSeverity.Error);
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                FError.ThrowError(24, $"The XmlDocument must have child nodes.", FErrorSeverity.Error);
                return(false);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Internal API for parsing textblocks.
        /// </summary>
        /// <param name="NodeToParse">The node to parse.</param>
        /// <param name="BoxToPopulate">The richtextbox to populate. </param>
        /// <returns></returns>
        internal RichTextBox FMXAML_Parse_TextBlock(XmlNode NodeToParse, RichTextBox BoxToPopulate)
        {
            XmlAttributeCollection FXmlNodeAttributes = NodeToParse.Attributes; // should be verified by now.

            foreach (XmlAttribute FXmlAttribute in FXmlNodeAttributes)
            {
                switch (FXmlAttribute.Name) // TEMP, Pre-Factory Class code.
                {
                case "content":
                case "Content":
                    try
                    {      //TEMPCODE
                        BoxToPopulate = FMXAML_TextAPI_AddText(BoxToPopulate, FXmlAttribute.Value, 18);
                    }
                    catch (NotImplementedException)
                    {
                        FError.ThrowError(12, $"API call not implemented", FErrorSeverity.FatalError);
                    }
                    continue;

                case "fontstyle":
                case "FontStyle":
                    continue;
                }
            }

            return(BoxToPopulate);
        }
Beispiel #6
0
        /// <summary>
        /// Internal API for loading text. Sets a text block's font weight. (INLINE OVERLOAD)
        /// </summary>
        /// <param name="FBlockToSet">The Block to set the font weight of.</param>
        /// <param name="FontWght">The font family in string form to set the Block's font weight to.</param>
        /// <returns>A Block with the font weight set.</returns>
        internal Inline FMXAML_TextAPI_SetFontWeight(Inline FBlockToSet, int FontWght) // Sets the font weight.
        {
            if (FontWght < 1 | FontWght > 999)
            {
                FError.ThrowError(17, "The font weight must be between 1 and 999. The font weight has not been set.", FErrorSeverity.Warning);
                return(FBlockToSet);
            }

            FBlockToSet.FontWeight = FontWeight.FromOpenTypeWeight(FontWght);

            return(FBlockToSet);
        }
Beispiel #7
0
 /// <summary>
 /// Internal API for verifying that an XML node has child nodes. Throws error 13 and returns false if failed.
 /// </summary>
 /// <param name="DocumentToVerify">The FDocument to verify</param>
 /// <returns>true if the verification was successful, throws error 13 and returns false otherwise.</returns>
 internal bool FStartApp_VerifyChildNodes(IFDocument DocumentToVerify)//public variant too
 {
     if (!DocumentToVerify.DocumentXML.FirstChild.HasChildNodes)
     {
         FError.ThrowError(13, $"The node {DocumentToVerify.DocumentXML.FirstChild.Name} in document {DocumentToVerify.DocumentPath} must have child nodes.", FErrorSeverity.FatalError);
         return(false);
     }
     else
     {
         return(true);
     }
 }
Beispiel #8
0
 internal bool FStartApp_VerifyAttributes(XmlNode NodeToVerify)
 {
     if (NodeToVerify.Attributes.Count == 0)
     {
         FError.ThrowError(11, $"The node {NodeToVerify.Name} must have attributes.", FErrorSeverity.FatalError);
         return(false);
     }
     else
     {
         return(true);
     }
 }
Beispiel #9
0
 /// <summary>
 /// Internal API for verifying that an XML node has attributes. Throws error 11 and returns false if failed.
 /// </summary>
 /// <param name="DocumentToVerify">The FDocument to verify</param>
 /// <returns>true if the verification was successful, throws error 11 and returns false otherwise.</returns>
 internal bool FStartApp_VerifyAttributes(IFDocument DocumentToVerify)
 {
     if (DocumentToVerify.DocumentXML.FirstChild.Attributes.Count == 0)
     {
         FError.ThrowError(11, $"The node {DocumentToVerify.DocumentXML.FirstChild.Name} in document {DocumentToVerify.DocumentPath} must have attributes.", FErrorSeverity.FatalError);
         return(false);
     }
     else
     {
         return(true);
     }
 }
Beispiel #10
0
 /// <summary>
 /// Internal API for loading text. Sets a text block's font style. (INLINE OVERLOAD)
 /// </summary>
 /// <param name="FBlockToSet">The Block to set the font style of.</param>
 /// <param name="FontStyle">The font family in string form to set the Block's font style to.</param>
 /// <returns>An Inline with the font style set.</returns>
 internal Inline FMXAML_TextAPI_SetFontStyle(Inline FBlockToSet, string FontStyle) // Sets the font style.
 {
     try
     {
         FontStyleConverter _FontStyleConverter = new FontStyleConverter();
         FontStyle          _FinalFontStyle     = (FontStyle)_FontStyleConverter.ConvertFromString(FontStyle);
         FBlockToSet.FontStyle = _FinalFontStyle;
         return(FBlockToSet);
     }
     catch (FormatException err)
     {
         FError.ThrowError(15, "An invalid string was supplied.", FErrorSeverity.FatalError, err);
         return(null);
     }
 }
Beispiel #11
0
        /// <summary>
        /// Internal API for loading XML.
        /// </summary>
        /// <param name="Path">The path to the XML file.</param>
        /// <returns></returns>
        internal XmlDocument FLoadXml(string Path)
        {
            try
            {
                XmlDocument FXmlLoad = new XmlDocument();

                if (Path.Contains(':'))
                {
                    Path.Remove(':');
                }

                FXmlLoad.Load(Path);
                return(FXmlLoad);
            }
            catch (XmlException err)
            {
                FError.ThrowError(8, $"An error has occurred loading XML file {Path}. Aborting load...", FErrorSeverity.Error, err);
                return(null);
            }
        }
Beispiel #12
0
        /// <summary>
        /// Internal API for loading XML.
        /// </summary>
        /// <param name="Path"></param>
        /// <param name="VerifyNodeName"></param>
        /// <returns></returns>
        internal XmlDocument FLoadXml(string Path, string VerifyNodeName = null)
        {
            try
            {
                XmlDocument FXmlLoad = new XmlDocument();
                FXmlLoad.Load(Path);

                if (FXmlLoad.FirstChild.Name != VerifyNodeName)
                {
                    FError.ThrowError(10, $"XML file {Path} does not have {VerifyNodeName} as its root node. Aborting load...", FErrorSeverity.Error);
                }

                return(FXmlLoad);
            }
            catch (XmlException err)
            {
                FError.ThrowError(9, $"An error has occurred loading XML file {Path}. Aborting load...", FErrorSeverity.Error, err);
                return(null);
            }
        }
Beispiel #13
0
        /// <summary>
        /// Internal API for loading text. Parses the Paragraph node. UNDER CONSTRUCTION - SUBJECT TO CHANGE AT ANY POINT..
        /// </summary>
        /// <param name="BoxToPopulate">The box to populate </param>
        /// <param name="FPageContentElement">The xmlnode to use to parse the subnodes of the Paragraph.</param>
        /// <returns></returns>
        internal RichTextBox FMXAML_Parse_Paragraph(XmlNode FPageContentElement, RichTextBox BoxToPopulate) // Parses a paragraph.
        {
            Paragraph   TheParagraph       = new Paragraph();
            XmlNodeList FParagraphChildren = FPageContentElement.ChildNodes;

            TheParagraph = FMXAML_TextAPI_CreateParagraph();

            foreach (XmlNode FParagraphChild in FParagraphChildren)
            {
                if (FParagraphChild.Name == "#comment")
                {
                    continue;
                }

                MxamlNode MXamlChild_Parse = (MxamlNode)Enum.Parse(typeof(MxamlNode), FParagraphChild.Name);

                switch (MXamlChild_Parse)
                {
                case MxamlNode.TextBlock:
                    TheParagraph = FMXAML_Parse_TextBlock(FParagraphChild, TheParagraph);
                    continue;

                case MxamlNode.Doclink:
                    TheParagraph = FMXAML_Parse_Doclink(FParagraphChild, TheParagraph);
                    continue;

                default:
                    FError.ThrowError(14, "An invalid mXAML node was found.", FErrorSeverity.FatalError);
                    continue;
                }
            }

            if (TheParagraph.Inlines.Count > 0)
            {
                BoxToPopulate = FMXAML_TextAPI_AddParagraphToTextBox(BoxToPopulate, TheParagraph);
            }

            return(BoxToPopulate);
        }
Beispiel #14
0
 public bool FGetDocumentMetadata(IFDocument DocumentToGetMetadata)
 {
     FError.ThrowError(12, $"API call not implemented", FErrorSeverity.FatalError);
     return(false);
 }
Beispiel #15
0
        /// <summary>
        /// Internal API for parsing the App Definition XML.
        /// </summary>
        /// <param name="FApp">The IFApp to load.</param>
        /// <param name="FAppXml">The XML file to load the IFApp attributes from.</param>
        /// <returns></returns>
        ///
        internal IFApp FStartApp_ParseAppXml(IFApp FApp, XmlDocument FAppXml)
        {
            try
            {
                XmlNode FXmlRootNode = FAppXml.FirstChild;

                if (FXmlRootNode.Name != "Fuchsia")
                {
                    FError.ThrowError(1, $"App App.xml does not have Fuchsia as its first node. Aborting load...", FErrorSeverity.Error);
                    return(null);
                }

                XmlNodeList FXmlFirstLevelNodes = FXmlRootNode.ChildNodes;

                foreach (XmlNode FXmlFirstLevelNode in FXmlFirstLevelNodes)
                {
                    switch (FXmlFirstLevelNode.Name)
                    {
                    case "AppInformation":
                        if (FXmlFirstLevelNode.Attributes.Count == 0)
                        {
                            FError.ThrowError(4, $"App definition empty. Aborting load...", FErrorSeverity.Error);
                        }
                        XmlAttributeCollection FXmlAppInfoAttributes = FXmlFirstLevelNode.Attributes;

                        foreach (XmlAttribute FXmlAppInfoAttribute in FXmlAppInfoAttributes)
                        {
                            switch (FXmlAppInfoAttribute.Name)
                            {
                            case "author":
                                FApp.AppAuthor = FXmlAppInfoAttribute.Value;
                                continue;

                            case "description":
                                FApp.AppDescription = FXmlAppInfoAttribute.Value;
                                continue;

                            case "developer":
                                FApp.AppDeveloper = FXmlAppInfoAttribute.Value;
                                continue;

                            case "name":
                                FApp.AppName = FXmlAppInfoAttribute.Value;
                                continue;

                            case "purpose":
                                FApp.AppPurpose = FXmlAppInfoAttribute.Value;
                                continue;
                            }

                            if (FApp.AppName == null)
                            {
                                FError.ThrowError(5, $"Attempted to load app with no name. Aborting load...", FErrorSeverity.Error);
                            }
                        }

                        continue;

                    default:
                        FError.ThrowError(3, $"Invalid node name present in App.xml, aborting load...", FErrorSeverity.Error);
                        return(null);
                    }
                }

                return(FApp);
            }
            catch (XmlException err)
            {
                FError.ThrowError(2, $"App App.xml corrupted. Aborting load...", FErrorSeverity.Error, err);
                return(null);
            }
            catch (FileNotFoundException err)
            {
                FError.ThrowError(6, $"Attempted to load a nonexistent App.xml.", FErrorSeverity.Error, err);
                return(null);
            }
            catch (DirectoryNotFoundException err)
            {
                FError.ThrowError(7, $"Attempted to load a nonexistent App.xml.", FErrorSeverity.Error, err);
                return(null);
            }
        }
Beispiel #16
0
        /// <summary>
        /// Internal API for parsing textblocks. (OVERLOAD)
        /// </summary>
        /// <param name="NodeToParse">The node to parse.</param>
        /// <param name="ParaToPopulate">The paragraph to populate. </param>
        /// <returns></returns>
        internal Paragraph FMXAML_Parse_TextBlock(XmlNode NodeToParse, Paragraph ParaToPopulate) // maybe we need to split the code for this up into various fmxamlreader stuff
        {
            XmlAttributeCollection FXmlNodeAttributes = NodeToParse.Attributes;                  // should be verified by now.

            Inline TextToAdd = new Run();

            foreach (XmlAttribute FXmlAttribute in FXmlNodeAttributes)
            {
                switch (FXmlAttribute.Name) // TODO: FACTORY CLASS? AND ENUM.
                {
                case "content":             // the content of the textblock
                case "Content":
                    try
                    {      //TEMPCODE
                        TextToAdd = FMXAML_TextAPI_AddText(ParaToPopulate, FXmlAttribute.Value, 18);
                    }
                    catch (NotImplementedException)
                    {
                        FError.ThrowError(12, $"API call not implemented", FErrorSeverity.FatalError);
                    }
                    continue;

                case "fontfamily":     // the font family of the textblock
                case "FontFamily":
                    try
                    {
                        TextToAdd = FMXAML_TextAPI_SetFontFamily(TextToAdd, FXmlAttribute.Value);
                    }
                    catch (ArgumentException err)
                    {
                        FError.ThrowError(18, "Invalid font size supplied", FErrorSeverity.FatalError, err);
                    }
                    continue;

                case "fontstyle":     // the font family of the textblock
                case "FontStyle":
                    string FXmlAttributeValue = FXmlAttribute.Value;

                    if (FXmlAttributeValue.Contains("bold"))
                    {
                        TextToAdd = FMXAML_TextAPI_SetFontWeight(TextToAdd, 500);     //temp
                    }
                    else if (FXmlAttributeValue.Contains("italic"))
                    {
                        TextToAdd = FMXAML_TextAPI_SetFontStyle(TextToAdd, "Italic");
                    }
                    else if (FXmlAttributeValue.Contains("oblique"))
                    {
                        TextToAdd = FMXAML_TextAPI_SetFontStyle(TextToAdd, "Oblique");
                    }

                    continue;

                case "fontsize":     // the font size of the textblock
                case "FontSize":
                    try
                    {
                        double FFontSize = Convert.ToInt32(FXmlAttribute.Value);

                        TextToAdd = FMXAML_TextAPI_SetFontSize(TextToAdd, FFontSize);
                    }
                    catch (FormatException err)
                    {
                        FError.ThrowError(17, "Invalid font size supplied", FErrorSeverity.FatalError, err);
                    }
                    continue;

                case "fontweight":     // the font weight of the textblock
                case "FontWeight":
                    try
                    {
                        int FFontWeight = Convert.ToInt32(FXmlAttribute.Value);

                        TextToAdd = FMXAML_TextAPI_SetFontWeight(TextToAdd, FFontWeight);
                    }
                    catch (FormatException err)
                    {
                        FError.ThrowError(16, "Invalid font weight supplied", FErrorSeverity.FatalError, err);
                    }
                    continue;

                case "foreground":
                case "Foreground":     // the foreground colour of the textblock
                case "ForegroundColor":
                case "ForegroundColour":
                    try
                    {
                        Color FForegroundColour = FMXAML_TextAPI_GetColourFromXMLValue(FXmlAttribute.Value);

                        TextToAdd = FMXAML_TextAPI_SetFontFgColour(TextToAdd, FForegroundColour);
                    }
                    catch (FormatException err)
                    {
                        FError.ThrowError(20, "Invalid foreground colour supplied", FErrorSeverity.FatalError, err);
                    }
                    catch (OverflowException err)
                    {
                        FError.ThrowError(21, "Invalid foreground colour supplied - every RGB(A) component must be between 0 and 255", FErrorSeverity.FatalError, err);
                    }
                    continue;

                case "background":
                case "Background":
                case "BackgroundColor":
                case "BackgroundColour":
                    try
                    {
                        Color FBackgroundColour = FMXAML_TextAPI_GetColourFromXMLValue(FXmlAttribute.Value);

                        TextToAdd = FMXAML_TextAPI_SetFontBgColour(TextToAdd, FBackgroundColour);
                    }
                    catch (FormatException err)
                    {
                        FError.ThrowError(22, "Invalid background colour supplied", FErrorSeverity.FatalError, err);
                    }
                    catch (OverflowException err)
                    {
                        FError.ThrowError(23, "Invalid background colour supplied - every RGB(A) component must be between 0 and 255", FErrorSeverity.FatalError, err);
                    }
                    continue;
                }
            }

            ParaToPopulate = FMXAML_TextAPI_AddTextToParagraph(ParaToPopulate, TextToAdd);

            return(ParaToPopulate);
        }