Ejemplo n.º 1
0
            /// <summary>
            /// Retourne l'élément identifié par la chaine
            /// </summary>
            /// <param name="ident">chaine identifiant</param>
            /// <returns>Retourne l'élément identifié si réussi et null sinon</returns>
            public PropertyElement GetElement(string ident)
            {
                if (ident == name)
                {
                    return(this);
                }
                if (ident.Length < name.Length)
                {
                    return(null);
                }

                string tmp = ident.Substring(0, name.Length);

                if (tmp != name)
                {
                    return(null);
                }

                ident = ident.Substring(name.Length);
                if (IsList)
                {
                    if (ident[0] == '.')
                    {
                        ident = ident.Substring(1);
                        string var_name = PropertyRegex.GetVariable(ident);
                        foreach (PropertyElement e in (List <PropertyElement>)value)
                        {
                            if (e.Name == var_name)
                            {
                                return(e.GetElement(ident));
                            }
                        }
                        return(null);
                    }
                    else if (ident[0] == '[')
                    {
                        ident = ident.Substring(1);
                        int idx = PropertyRegex.GetUint(ident);
                        ident = ident.Substring((idx / 10) + 2);
                        int it = 0;
                        foreach (PropertyElement e in (List <PropertyElement>)value)
                        {
                            if (e.Name == "" && (it++) == idx)
                            {
                                return(e.GetElement(ident));
                            }
                        }
                        return(null);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
Ejemplo n.º 2
0
        /// <summary>
        /// Permet de récupérer un élément par son nom
        /// </summary>
        /// <param name="name">nom de l'élément à identifier</param>
        /// <returns>Retourne l'élément s'il existe et null sinon</returns>
        public PropertyElement GetElement(string name)
        {
            string var_name = PropertyRegex.GetVariable(name);

            foreach (PropertyElement e in this.E)
            {
                if (var_name == e.Name)
                {
                    return((PropertyElement)e.GetElement(name));
                }
            }
            return(null);
        }
Ejemplo n.º 3
0
        // Split: Split on ';'
        //	   Eg. Property values don't need to be split
        //
        // AllowItems: if false, item refs should not be treated as item refs!
        //	        it converts them to strings in the final expressionCollection
        //
        // AllowMetadata: same as AllowItems, for metadata
        public void Parse(string expression, ParseOptions options)
        {
            bool split      = (options & ParseOptions.Split) == ParseOptions.Split;
            bool allowItems = (options & ParseOptions.AllowItems) == ParseOptions.AllowItems;
            bool allowMd    = (options & ParseOptions.AllowMetadata) == ParseOptions.AllowMetadata;

            expression = expression.Replace('\\', Path.DirectorySeparatorChar);

            string [] parts;
            if (split)
            {
                parts = expression.Split(new char [] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            }
            else
            {
                parts = new string [] { expression }
            };

            List <ArrayList> p1 = new List <ArrayList> (parts.Length);
            List <ArrayList> p2 = new List <ArrayList> (parts.Length);
            List <ArrayList> p3 = new List <ArrayList> (parts.Length);

            Prepare(p1, parts.Length);
            Prepare(p2, parts.Length);
            Prepare(p3, parts.Length);

            for (int i = 0; i < parts.Length; i++)
            {
                p1 [i] = SplitItems(parts [i], allowItems);
            }

            for (int i = 0; i < parts.Length; i++)
            {
                p2 [i] = new ArrayList();
                foreach (object o in p1[i])
                {
                    if (o is string)
                    {
                        p2 [i].AddRange(SplitProperties((string)o));
                    }
                    else
                    {
                        p2 [i].Add(o);
                    }
                }
            }

            for (int i = 0; i < parts.Length; i++)
            {
                p3 [i] = new ArrayList();
                foreach (object o in p2[i])
                {
                    if (o is string)
                    {
                        p3 [i].AddRange(SplitMetadata((string)o));
                    }
                    else
                    {
                        p3 [i].Add(o);
                    }
                }
            }

            CopyToExpressionCollection(p3, allowItems, allowMd);
        }

        void Prepare(List <ArrayList> l, int length)
        {
            for (int i = 0; i < length; i++)
            {
                l.Add(null);
            }
        }

        void CopyToExpressionCollection(List <ArrayList> lists, bool allowItems, bool allowMd)
        {
            for (int i = 0; i < lists.Count; i++)
            {
                foreach (object o in lists[i])
                {
                    if (o is string)
                    {
                        expressionCollection.Add(Utilities.Unescape((string)o));
                    }
                    else if (!allowItems && o is ItemReference)
                    {
                        expressionCollection.Add(((ItemReference)o).OriginalString);
                    }
                    else if (!allowMd && o is MetadataReference)
                    {
                        expressionCollection.Add(((MetadataReference)o).OriginalString);
                    }
                    else if (o is IReference)
                    {
                        expressionCollection.Add((IReference)o);
                    }
                }
                if (i < lists.Count - 1)
                {
                    expressionCollection.Add(";");
                }
            }
        }

        ArrayList SplitItems(string text, bool allowItems)
        {
            ArrayList phase1 = new ArrayList();
            Match     m;

            m = ItemRegex.Match(text);

            while (m.Success)
            {
                string        name = null, transform = null, separator = null;
                ItemReference ir;

                name = m.Groups [ItemRegex.GroupNumberFromName("itemname")].Value;

                if (m.Groups [ItemRegex.GroupNumberFromName("has_transform")].Success)
                {
                    transform = m.Groups [ItemRegex.GroupNumberFromName("transform")].Value;
                }

                if (m.Groups [ItemRegex.GroupNumberFromName("has_separator")].Success)
                {
                    separator = m.Groups [ItemRegex.GroupNumberFromName("separator")].Value;
                }

                ir = new ItemReference(text.Substring(m.Groups [0].Index, m.Groups [0].Length),
                                       name, transform, separator, m.Groups [0].Index, m.Groups [0].Length);
                phase1.Add(ir);
                m = m.NextMatch();
            }

            ArrayList phase2   = new ArrayList();
            int       last_end = -1;
            int       end      = text.Length - 1;

            foreach (ItemReference ir in phase1)
            {
                int a, b;

                a = last_end;
                b = ir.Start;

                if (b - a - 1 > 0)
                {
                    phase2.Add(text.Substring(a + 1, b - a - 1));
                }

                last_end = ir.End;
                phase2.Add(ir);
            }

            if (last_end < end)
            {
                phase2.Add(text.Substring(last_end + 1, end - last_end));
            }

            return(phase2);
        }

        ArrayList SplitProperties(string text)
        {
            ArrayList phase1 = new ArrayList();
            Match     m;

            m = PropertyRegex.Match(text);

            while (m.Success)
            {
                string            name = null;
                PropertyReference pr;

                name = m.Groups [PropertyRegex.GroupNumberFromName("name")].Value;

                pr = new PropertyReference(name, m.Groups [0].Index, m.Groups [0].Length);
                phase1.Add(pr);
                m = m.NextMatch();
            }

            ArrayList phase2   = new ArrayList();
            int       last_end = -1;
            int       end      = text.Length - 1;

            foreach (PropertyReference pr in phase1)
            {
                int a, b;

                a = last_end;
                b = pr.Start;

                if (b - a - 1 > 0)
                {
                    phase2.Add(text.Substring(a + 1, b - a - 1));
                }

                last_end = pr.End;
                phase2.Add(pr);
            }

            if (last_end < end)
            {
                phase2.Add(text.Substring(last_end + 1, end - last_end));
            }

            return(phase2);
        }

        ArrayList SplitMetadata(string text)
        {
            ArrayList phase1 = new ArrayList();
            Match     m;

            m = MetadataRegex.Match(text);

            while (m.Success)
            {
                string            name = null, meta = null;
                MetadataReference mr;

                if (m.Groups [MetadataRegex.GroupNumberFromName("name")].Success)
                {
                    name = m.Groups [MetadataRegex.GroupNumberFromName("name")].Value;
                }

                meta = m.Groups [MetadataRegex.GroupNumberFromName("meta")].Value;

                mr = new MetadataReference(text.Substring(m.Groups [0].Index, m.Groups [0].Length),
                                           name, meta, m.Groups [0].Index, m.Groups [0].Length);
                phase1.Add(mr);
                m = m.NextMatch();
            }

            ArrayList phase2   = new ArrayList();
            int       last_end = -1;
            int       end      = text.Length - 1;

            foreach (MetadataReference mr in phase1)
            {
                int a, b;

                a = last_end;
                b = mr.Start;

                if (b - a - 1 > 0)
                {
                    phase2.Add(text.Substring(a + 1, b - a - 1));
                }

                last_end = mr.End;
                phase2.Add(mr);
            }

            if (last_end < end)
            {
                phase2.Add(text.Substring(last_end + 1, end - last_end));
            }

            return(phase2);
        }
Ejemplo n.º 4
0
            /// <summary>
            /// Constructeur de la class PropertyElement
            /// </summary>
            /// <param name="syntax">une structure FIFO contenant les lignes du fichier à lire</param>
            public PropertyElement(ref Queue <string> syntax)
            {
                int space_level;

                // Initialisation
                valid = false;
                while (syntax.Count > 0 && !PropertyRegex.IsUseful(syntax.Peek()))
                {
                    syntax.Dequeue();
                }
                if (syntax.Count == 0)
                {
                    return;
                }

                // Assignation du niveau d'espacement et du nom
                string peek = syntax.Dequeue();

                space_level = PropertyRegex.GetSpaceLevel(peek);
                peek        = peek.Substring(space_level);
                if (!PropertyRegex.IsVariable(peek))
                {
                    // C'est un élément de liste
                    name = "";
                }
                else
                {
                    name = PropertyRegex.GetVariable(peek);
                }

                // Assignation si présente de la valeur sur la ligne
                peek = peek.Substring(name.Length);
                peek = peek.Substring(PropertyRegex.GetSpaceLevel(peek) + 1);
                if (PropertyRegex.IsValue(peek))
                {
                    value = PropertyRegex.GetValue(peek);
                    valid = true;
                    return;
                }

                // Vérification d'une valeur valide après
                while (syntax.Count > 0 && !PropertyRegex.IsUseful(syntax.Peek()))
                {
                    syntax.Dequeue();
                }
                if (syntax.Count == 0)
                {
                    return;
                }


                // On ajoute les éléments
                List <PropertyElement> elems = new List <PropertyElement>();
                PropertyElement        tmp;

                do
                {
                    peek = syntax.Peek();
                    if (PropertyRegex.GetSpaceLevel(peek) > space_level)
                    {
                        tmp = new PropertyElement(ref syntax);
                        if (!tmp.Valid)
                        {
                            break;
                        }
                        elems.Add(tmp);
                        valid = true;
                    }
                    else
                    {
                        break;
                    }

                    while (syntax.Count > 0 && !PropertyRegex.IsUseful(syntax.Peek()))
                    {
                        syntax.Dequeue();
                    }
                } while (syntax.Count > 0);

                // On met les éléments dans la valeur
                if (valid)
                {
                    value = elems;
                }
            }
Ejemplo n.º 5
0
        private void Run(string sourceCodePath, string wikiOutputPath)
        {
            if (!File.Exists(sourceCodePath))
            {
                throw new ArgumentException($"'{sourceCodePath}' does not exist.");
            }

            if (!Directory.Exists(wikiOutputPath))
            {
                throw new ArgumentException($"'{wikiOutputPath}' does not exist.");
            }

            Console.WriteLine($"classDiagram");
            Console.WriteLine($"");

            var baseClass     = string.Empty;
            var className     = string.Empty;
            var propertyNames = new List <string>();

            var summaryBuilder = new StringBuilder();

            summaryBuilder
            .AppendLine($"# Configuration Summary")
            .AppendLine()
            .AppendLine($"The following definitions are supported:")
            .AppendLine()
            .AppendLine($"| Definition | Summary |")
            .AppendLine($"|---|---|");

            void CloseClassDefinition()
            {
                if (string.IsNullOrEmpty(className))
                {
                    return;
                }

                summaryBuilder
                .AppendLine($"| [{className}](./{className}) | |");

                var builder = new StringBuilder();

                builder
                .AppendLine($"# {className} Details")
                .AppendLine()
                .AppendLine($"The {className} definition derives from the [{baseClass}](./{baseClass}) definition, and includes all of the base class properties.")
                .AppendLine()
                .AppendLine($"| PropertyName | Required | Description |")
                .AppendLine($"|---|---|---|");

                foreach (var propertyName in propertyNames)
                {
                    var required = propertyNames.IndexOf(propertyName) == 0
                        ? "Y"
                        : "N";

                    builder
                    .AppendLine($"| {propertyName} | {required} | |");
                }

                builder
                .AppendLine();

                File.WriteAllText(Path.Combine(wikiOutputPath, $"{className}.md"), builder.ToString());

                Console.WriteLine($"  {baseClass} <|-- {className}");
                Console.WriteLine($"  class {className} {{");

                foreach (var propertyName in propertyNames)
                {
                    Console.WriteLine($"    {propertyName}");
                }

                Console.WriteLine($"  }}");
                Console.WriteLine($"  link {className} \"https://github.com/AquaticInformatics/tabular-field-data-plugin/wiki/{className}\" \"See {className} details\"");
                Console.WriteLine($"  ");

                propertyNames.Clear();
            }

            foreach (var line in File.ReadAllLines(sourceCodePath))
            {
                var match = ClassRegex.Match(line);

                if (match.Success)
                {
                    CloseClassDefinition();

                    baseClass = SanitizeClassName(match.Groups["baseClass"].Value);
                    className = SanitizeClassName(match.Groups["derivedClass"].Value);

                    continue;
                }

                match = PropertyRegex.Match(line);

                if (!match.Success)
                {
                    continue;
                }

                var propertyName = match.Groups["propertyName"].Value;

                propertyNames.Add(propertyName);
            }

            CloseClassDefinition();

            File.WriteAllText(Path.Combine(wikiOutputPath, $"Summary.md"), summaryBuilder.ToString());
        }