Ejemplo n.º 1
0
        public void ShowFragments(
            [Argument(Description = "Path to the OML file to be loaded. It is possible to read from stdin instead of a file by using UNIX pipe access syntax (e.g.: 'pipe:').")]
            string input,
            [Argument(Description = "Target platform version to use for loading the OML file. For the latest compatible version, use the value 'OL'.")]
            string version,
            [Argument(Description = "If set, prints the XML content of the desired fragment.")]
            string fragmentName = null)
        {
            Oml oml = _GetOmlInstance(input, version);

            if (string.IsNullOrEmpty(fragmentName))
            {
                foreach (string innerFragmentName in oml.GetFragmentNames())
                {
                    Console.WriteLine(innerFragmentName);
                }
            }
            else
            {
                XElement fragment = oml.GetFragmentXml(fragmentName);

                if (fragment == null)
                {
                    throw new Exception("Unable to get XML content of fragment \"" + fragmentName + "\".");
                }

                Console.WriteLine(fragment.ToString(SaveOptions.DisableFormatting));
            }
        }
Ejemplo n.º 2
0
        public void ShowHeaders(
            [Argument(Description = "Path to the OML file to be loaded. It is possible to read from stdin instead of a file by using UNIX pipe access syntax (e.g.: 'pipe:').")]
            string input,
            [Argument(Description = "Target platform version to use for loading the OML file. For the latest compatible version, use the value 'OL'.")]
            string version,
            [Argument(Description = "If set, returns only the value of the specified header.")]
            string headerName = null)
        {
            Oml  oml   = _GetOmlInstance(input, version);
            bool found = false;

            foreach (PropertyInfo property in typeof(OmlHeader).GetProperties())
            {
                OmlHeaderAttribute attribute = (OmlHeaderAttribute)Attribute.GetCustomAttribute(property, typeof(OmlHeaderAttribute));

                if (attribute == null || !string.IsNullOrEmpty(headerName) && !headerName.Equals(property.Name, StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }

                if (!string.IsNullOrEmpty(headerName))
                {
                    Console.WriteLine(property.GetValue(oml.Header, null));
                }
                else
                {
                    Console.WriteLine("{0}:{1}", property.Name, property.GetValue(oml.Header, null));
                }

                found = true;
            }

            if (!string.IsNullOrEmpty(headerName) && !found)
            {
                throw new Exception("Header name \"" + headerName + "\" was not found.");
            }
        }
Ejemplo n.º 3
0
        public void TextSearch(
            [Argument(Description = "Path to the directory with OML files to be examined.")]
            string omlPathDir,
            [Argument(Description = "Text to be searched inside an OML file.")]
            string keywordSearch,
            [Argument(Description = "Target platform version to use for loading the OML file. For the latest compatible version, use the value 'OL'.")]
            string version)
        {
            if (String.IsNullOrEmpty(keywordSearch))
            {
                Console.WriteLine("Please inform a expression for search and try again.");
            }
            else
            {
                Console.WriteLine("Search for keyword '{0}'", keywordSearch);
            }


            if (Directory.Exists(omlPathDir))
            {
                var watch = System.Diagnostics.Stopwatch.StartNew();

                Console.WriteLine("Search OMLs inside of {0} ...", omlPathDir);

                DirectoryInfo omlDir = new DirectoryInfo(omlPathDir);
                FileInfo[]    Files  = omlDir.GetFiles("*.oml");

                Console.WriteLine("{0} files found.", Files.Count());

                int CountFile = 0;
                foreach (FileInfo file in Files)
                {
                    Oml    oml    = _GetOmlInstance(omlPathDir + Path.DirectorySeparatorChar + file, version);
                    String txtXml = oml.GetXml().ToString();

                    int i     = 0;
                    int count = 0;
                    while ((i = txtXml.IndexOf(keywordSearch, i)) != -1)
                    {
                        i += keywordSearch.Length;
                        count++;
                    }

                    CountFile++;

                    Console.WriteLine("[{0}/{1}] - {2} ocurrences found in {3}.", CountFile, Files.Count(), count, file);
                }

                watch.Stop();
                TimeSpan ElapsedMS         = TimeSpan.FromMilliseconds(watch.ElapsedMilliseconds);
                string   formatElapsedTime = string.Format("{0:D2}h:{1:D2}m:{2:D2}s",
                                                           ElapsedMS.Hours,
                                                           ElapsedMS.Minutes,
                                                           ElapsedMS.Seconds);

                Console.WriteLine("Elapsed time of {0}", formatElapsedTime);
            }
            else
            {
                Console.WriteLine("Directory not found.");
            }
        }
Ejemplo n.º 4
0
        public void Manipulate(
            [Argument(Description = "Path to the OML file to be loaded. It is possible to read from stdin instead of a file by using UNIX pipe access syntax (e.g.: 'pipe:').")]
            string input,
            [Argument(Description = "Destination path to save the manipulated OML file. It is possible to send the data stream to stdout instead by using UNIX pipe access syntax (e.g.: 'pipe:').")]
            string output,
            [Argument(Description = "Target platform version to use for loading the OML file. For the latest compatible version, use the value 'OL'.")]
            string version,
            [Option(Description = "Destination file format. Possible formats are 'oml' and 'xml'. If not set, will be guessed according to the output file extension.",
                    LongName = "format",
                    ShortName = "f")]
            string format = null,
            [Option(Description = "Sets a header value. Name and value must be separated by colon (':').",
                    LongName = "header",
                    ShortName = "H")]
            List <string> headers = null,
            [Option(Description = "Sets the content of a fragment. Name and value must be separated by colon (':').",
                    LongName = "fragment",
                    ShortName = "F")]
            List <string> fragments = null)
        {
            Oml oml = _GetOmlInstance(input, version);

            // Set headers
            if (headers != null)
            {
                foreach (string headerLine in headers)
                {
                    int colonIndex = headerLine.IndexOf(':');

                    if (colonIndex == -1)
                    {
                        throw new Exception("Unable to parse header value \"" + headerLine + "\". Name and value must be separated by colon (':').");
                    }

                    string headerName = headerLine.Substring(0, colonIndex);

                    if (string.IsNullOrEmpty(headerName))
                    {
                        throw new Exception("The header name in the header parameter is mandatory.");
                    }

                    bool found = false;

                    foreach (PropertyInfo property in typeof(OmlHeader).GetProperties())
                    {
                        OmlHeaderAttribute attribute = (OmlHeaderAttribute)Attribute.GetCustomAttribute(property, typeof(OmlHeaderAttribute));

                        if (attribute == null || !headerName.Equals(property.Name, StringComparison.InvariantCultureIgnoreCase))
                        {
                            continue;
                        }

                        if (attribute.IsReadOnly)
                        {
                            throw new Exception("Cannot change header \"" + property.Name + "\" because it is read-only.");
                        }

                        string headerValue = headerLine.Substring(colonIndex + 1);
                        property.SetValue(oml.Header, headerValue);
                        found = true;
                    }

                    if (!found)
                    {
                        throw new Exception("Header name \"" + headerName + "\" was not found.");
                    }
                }
            }

            // Set fragments
            if (fragments != null)
            {
                foreach (string fragmentLine in fragments)
                {
                    int colonIndex = fragmentLine.IndexOf(':');

                    if (colonIndex == -1)
                    {
                        throw new Exception("Unable to parse fragment value \"" + fragmentLine + "\". Name and value must be separated by colon (':').");
                    }

                    string fragmentName = fragmentLine.Substring(0, colonIndex);

                    if (string.IsNullOrEmpty(fragmentName))
                    {
                        throw new Exception("The fragment name in the fragment parameter is mandatory.");
                    }

                    XElement fragment = XElement.Parse(fragmentLine.Substring(colonIndex + 1));
                    oml.SetFragmentXml(fragmentName, fragment);
                }
            }

            // Save manipulated OML
            Stream outputStream = _GetStream(output, false);

            if (format != null && format.Equals("xml", StringComparison.InvariantCultureIgnoreCase) || format == null && output.EndsWith(".xml", StringComparison.InvariantCultureIgnoreCase))
            {
                StreamWriter sw = new StreamWriter(outputStream);
                sw.Write(oml.GetXml().ToString(SaveOptions.DisableFormatting)); // Export XML
                sw.Flush();
                sw.Close();
            }
            else
            {
                oml.Save(outputStream); // Export OML
            }

            outputStream.Close();
        }