Ejemplo n.º 1
0
        public SimpleDocument(TextReader reader, ISetting setting)
        {
            IParser parser = ParserFactory.BuildParser(setting);
            Command root   = parser.Parse(reader);

            this.renderer = this.CompileCommand(root, setting.Trimmer);
            this.setting  = setting;
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            OptProperties props  = new OptProperties();
            Parser        parser = ParserFactory.BuildParser(props);

            parser.Parse(args);

            if (props.Help || props.CSVFile == null || props.OutFile == null || !(new FileInfo(props.CSVFile).Exists))
            {
                PrintUsageAndExit(parser);
            }

            Progress.Immediate(string.Format("Setting projection dimensions to {0}", props.ProjectionDimensions));
            Progress.Immediate(string.Format("Setting drawing width to {0}", props.Width));
            Progress.Immediate(string.Format("Setting drawing height to {0}", props.Width));
            Progress.Immediate(string.Format("Setting drawing line width to {0}", props.LineWidth));
            Progress.Immediate(string.Format("Setting drawing point size to {0}", props.PointSize));
            Progress.Immediate(string.Format("Setting bucket size to {0}", props.BucketSize));
            Progress.Immediate(string.Format("Setting ISplitDimensionSelector to '{0}'", props.ISplitDimensionSelector));
            Progress.Immediate(string.Format("Setting ISplitLocationSelector to '{0}'", props.ISplitLocationSelector));
            Progress.Immediate(string.Format("Setting ITrivialSplitResolver to '{0}'", props.ITrivialSplitResolver));

            IList <IVector> vecs = null;

            using (Progress p = new Progress(string.Format("Reading data from '{0}'", props.CSVFile))) {
                CSVReader r = new CSVReader(' ');
                vecs = r.Parse(props.CSVFile);
            }

            ISubdivisionPolicy policy =
                new SubdivisionPolicyConnector(props.BucketSize,
                                               props.ISplitDimensionSelectorInstance,
                                               props.ISplitLocationSelectorInstance,
                                               props.ITrivialSplitResolverInstance);

            KdTree <IVector> tree = null;

            using (Progress p = new Progress("Constructing kd-tree")) {
                tree = new KdTree <IVector>(vecs, policy);
            }

            using (Progress p = new Progress(string.Format("Rendering kd-tree to '{0}'", props.OutFile))) {
                Rendering.RenderTreeCairo render = new Rendering.RenderTreeCairo();
                render.Render(tree.Root,
                              props.ProjectionDimensions,
                              props.OutFile,
                              props.Width, props.Height,
                              props.LineWidth, props.PointSize);
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            string[] testargs = new string[] {
                @"-m C:\AnswerFile\MACHINE_ANSWER_FILE_MI.xml",
                @"-t C:\Integration\Framework2.0\Framework\Trunk\Integration.MassImport\Integration.MassImport.exe.config.template",
                @"-o C:\Integration\Framework2.0\Framework\Trunk\Integration.MassImport\Integration.MassImport.exe.config"
            };

            //Uncomment for testing
            //args = testargs;

            if (args.Length < 3)
            {
                Console.WriteLine(usage);
                Environment.Exit(1);
            }
            Arguments arguments = new Arguments();
            Parser    p         = ParserFactory.BuildParser(arguments);

            p.OptStyle = OptStyle.Unix;
            // Parse the args
            p.Parse(args);
            try
            {
                List <string> tokensNotInAnswerFile = new List <string>();
                TokenUtils.ReplaceTokens(arguments.MachineAnswerFile, arguments.TemplateFile, arguments.OutputFile, out tokensNotInAnswerFile);
                Console.WriteLine("Token replacement completed successfully.\r\nAnswer file: {0}\r\nTemplate file: {1}\r\nOutput file: {2}",
                                  arguments.MachineAnswerFile, arguments.TemplateFile, arguments.OutputFile);
                Environment.Exit(0);
            }
            catch (Exception ex)
            {
                string message = string.Format("An error occurred while performing the token replacement.Please check the below information to fix the error.\r\n\r\n1) Answer file: {0}\r\n2)  Template file: {1}\r\n3)  Output file: {2}\r\n4)  Error message: {3}",
                                               arguments.MachineAnswerFile, arguments.TemplateFile, arguments.OutputFile, ex.Message);
                Console.WriteLine(message);
                Console.WriteLine(ex.StackTrace);
                Environment.Exit(1);
            }
        }
Ejemplo n.º 4
0
        public static void Save(TextReader reader, ISetting setting, string assemblyName, string fileName)
        {
            IParser parser = ParserFactory.BuildParser(setting);

            Function.Save(parser.Parse(reader), setting.Trimmer, assemblyName, fileName);
        }
Ejemplo n.º 5
0
        public DynamicDocument(TextReader reader, ISetting setting)
        {
            IParser parser = ParserFactory.BuildParser(setting);

            this.main = new Function(Enumerable.Empty <string> (), parser.Parse(reader), setting.Trimmer);
        }
Ejemplo n.º 6
0
        public static void Main(string[] args)
        {
            Properties props = new Properties();

            try
            {
                Parser p;
                p                      = ParserFactory.BuildParser(props);
                p.OptStyle             = OptStyle.Unix;
                p.UnixShortOption      = UnixShortOption.CollapseShort;
                p.UnknownOptHandleType = UnknownOptHandleType.Warning;
                p.DupOptHandleType     = DupOptHandleType.Warning;
                p.CaseSensitive        = true;
                p.OptionWarning       += new WarningEventHandler(OnOptionWarning);
                p.SearchEnvironment    = true;
                p.Parse(args);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception!");
                return;
            }

            try
            {
                switch (props.operation)
                {
                case "interactive":
                {
                    ProcessInteractiveCommands(props);
                    break;
                }

                case "upload":
                {
                    ProcessUpload(props);
                    break;
                }

                case "download":
                {
                    ProcessDownload(props);
                    break;
                }

                case "list":
                {
                    ProcessList(props);
                    break;
                }

                default:
                    return;
                }
            }
            catch (Exception e)
            {
                System.IO.File.WriteAllText("./GlacierizerStackTrace.log", e.StackTrace);
                throw e;
            }
        }
Ejemplo n.º 7
0
        public DynamicDocument(TextReader reader, ISetting setting)
        {
            IParser parser = ParserFactory.BuildParser(setting);

            this.main = new Function(new string[0], parser.Parse(reader), setting.Trimmer, string.Empty);
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
#if RELEASE
            try
            {
#endif
            Console.CancelKeyPress += Console_CancelKeyPress;
            PrintBanner();

            // ****************************************************************
            // Parse command-line arguments
            // ****************************************************************
            PropertyFieldParserHelper parseHelper = new PropertyFieldParserHelper(options);
            Parser parser = ParserFactory.BuildParser(parseHelper);
            parser.CaseSensitive        = false;
            parser.DupOptHandleType     = DupOptHandleType.Error;
            parser.SearchEnvironment    = true;
            parser.UnixShortOption      = UnixShortOption.CollapseShort;
            parser.UnknownOptHandleType = UnknownOptHandleType.Warning;
            parser.OptionWarning       += parser_OptionWarning;

            try
            {
                options.ProcessArguments(parser.Parse());
            }
            catch (ParseException peX)
            {
                Console.Error.WriteLine("There was an error parsing the command-line arguments");
                Console.Error.WriteLine("    {0}", peX.Message);
                if (peX.InnerException != null)
                {
                    Console.Error.WriteLine("    {0}", peX.InnerException.Message);
                }
                Console.Error.WriteLine("See --help for proper use.");
                Environment.Exit(2);
            }

            // ****************************************************************
            // Print help or version
            // ****************************************************************
            if (options.Help)
            {
                // Print help and exit
                PrintHelp(parseHelper);
                Environment.Exit(0);
            }

            if (options.Version)
            {
                // Print help and exit
                PrintVersion("SMOz", 2012, "Nithin Philips");
                Environment.Exit(0);
            }

            if (options.StartMenuFolders.Count == 0)
            {
                string currentUserStartMenu = Win32.GetFolderPath(Win32.CSIDL.CSIDL_PROGRAMS);

                WriteInColor(ConsoleColor.Yellow, "Running as {0}.", Helpers.IsRunAsAdmin() ? "administrator" : "normal user");

                if (Helpers.IsRunAsAdmin())
                {
                    // We get the current user's start menu path and replace the user name
                    // with all available user names. This method is fairly naive.
                    // If the user's name is not unique in the path string, this method will
                    // fail to find the correct start menu location.
                    currentUserStartMenu = currentUserStartMenu.Replace(Environment.UserName, "{0}");

                    options.StartMenuFolders.AddRange(GetAllStartMenus(currentUserStartMenu));
                    options.StartMenuFolders.Add(Win32.GetFolderPath(Win32.CSIDL.CSIDL_COMMON_PROGRAMS));
                }
                else
                {
                    options.StartMenuFolders.Add(currentUserStartMenu);
                }
            }

            if (options.TemplateFiles.Count == 0)
            {
                // Look in cwd.
                string cwdTemplate = Path.Combine(Environment.CurrentDirectory, "Template.ini");
                if (File.Exists(cwdTemplate))
                {
                    options.TemplateFiles.Add(cwdTemplate);
                }
                else
                {
                    string exeDirTemplate = Path.Combine(
                        Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Template.ini");
                    if (File.Exists(exeDirTemplate))
                    {
                        options.TemplateFiles.Add(exeDirTemplate);
                    }
                    else
                    {
                        WriteError("Error: Could not find any template files and none specified.");
                        Console.WriteLine("See --help for usage.");
                        Environment.Exit(2);
                    }
                }
            }

            Template template = new Template();
            foreach (var t in options.TemplateFiles.Select(TemplateParser.Parse))
            {
                template.Merge(t);
            }

            foreach (var category in template)
            {
                Console.WriteLine(category.Name);
                _knownCategories.Add(category.Name);
            }

            StartMenu startMenu = new StartMenu(_knownCategories, options.StartMenuFolders);

            Console.WriteLine(startMenu);

            File.WriteAllText("knownCats.json", fastJSON.JSON.Instance.ToJSON(KnownCategories.Instance, true, true));
            //Console.ReadLine();

#if RELEASE
        }

        catch (Exception ex)
        {
            Console.Error.WriteLine("An exeption of type {0} has occured.", ex.GetType());
            Console.Error.WriteLine("   {0}", ex.Message);
            if (!options.Quiet)
            {
                Console.Error.WriteLine("Details:\n{0}", ex.StackTrace);
            }
        }
#endif
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.Error.WriteLine("Type `QaryanCLI -h` for help");
                Console.Error.WriteLine("If you meant input from stdin and output to soundcard, use `QaryanCLI -`");
                return;
            }
            OptionResultsDictionary opts = new OptionResultsDictionary();

            OptionDefinition[] optdefs = new OptionDefinition[] {
                new OptionDefinition("help", OptValType.Flag, typeof(string), "General options", "Show this help message", new char[] { 'h', '?' }, new string[] { "help" }),
                new OptionDefinition("verbose", OptValType.IncrementalFlag, typeof(IntPtr), "General options", "Verbose output", new char[] { 'v' }, new string[] { "verbose" }),
                new OptionDefinition("voice", OptValType.ValueReq, typeof(string), "Voice options", "Use the specified voice", new char[] { 'V' }, new string[] { "voice" }),
                new OptionDefinition("list-voices", OptValType.Flag, typeof(string), "Voice options", "List the available voices", new char[] { 'l' }, new string[] { "list-voices" }),
                new OptionDefinition("pho", OptValType.ValueOpt, typeof(string), "Output options", "Write phonetic information to the specified file ('-' for stdout, the default)", new char[] { 'P' }, new string[] { "pho" }),
                new OptionDefinition("out", OptValType.ValueOpt, typeof(string), "Output options", "Write audio to the specified file ('-' for stdout, the default)", new char[] { 'o' }, new string[] { "out", "audio" }),
                new OptionDefinition("raw", OptValType.Flag, typeof(string), "Output options", "Output raw audio data instead of WAV", new char[] { 'R' }, new string[] { "raw" })
            };

            CommandLine.OptParse.Parser optp = ParserFactory.BuildParser(optdefs, opts);
            string[] arguments = optp.Parse(OptStyle.Unix, UnixShortOption.CollapseShort, DupOptHandleType.Allow, UnknownOptHandleType.NoAction, true, args);
            if (opts["help"] != null)
            {
                Assembly asm = Assembly.GetEntryAssembly();
                //                string s = (asm.ManifestModule.GetCustomAttributes(typeof(AssemblyProductAttribute), true)[0] as AssemblyProductAttribute).Product;
                //s+= " " + (asm.ManifestModule.GetCustomAttributes(typeof(AssemblyVersionAttribute), true)[0] as AssemblyVersionAttribute).Version;
                UsageBuilder usage = new UsageBuilder();
                usage.GroupOptionsByCategory = true;
                //                usage.BeginSection(s);
                //                usage.EndSection();

                usage.BeginSection("Usage");
                usage.AddParagraph(Path.GetFileName(asm.CodeBase) + " [options] [infile] [-P phofile] [-o outfile]");
                usage.EndSection();

                usage.BeginSection("Description");
                usage.AddParagraph("Bare-bones command line interface to the Qaryan text-to-speech engine.");
                usage.EndSection();

                usage.BeginSection("Options");
                usage.AddOptions(optdefs);
                usage.EndSection();

                usage.BeginSection("Environment Variables");
                usage.AddParagraph("Setting the following variables is not required, but might help if the defaults don't work as expected.");
                usage.BeginList(ListType.Unordered);
                usage.AddListItem("MBROLA holds the path to the MBROLA executable.");
                usage.AddListItem("MBROLA_DATABASE_DIR holds the path where MBROLA databases may be found.");
                usage.AddListItem("QARYAN_ROOT holds the path where shared Qaryan files may be found.");
                usage.EndList();
                usage.EndSection();
                usage.ToText(Console.Error, OptStyle.Unix, true);
                return;
            }
            string qaryanpath = System.Environment.GetEnvironmentVariable("QARYAN_ROOT");

            if (qaryanpath != null)
            {
                FileBindings.EnginePath = qaryanpath;
            }
            if (opts["list-voices"] != null)
            {
                string dir = FileBindings.VoicePath;
                Console.Error.WriteLine("Available voices:");
                foreach (string file in Directory.GetFiles(dir + "/", "*.xml"))
                {
                    Voice voice = new Voice();
                    voice.Load(file);
                    if (voice.BackendSupported)
                    {
                        Console.Error.WriteLine("{2} voice {0} ({1})",
                                                Path.GetFileNameWithoutExtension(file), voice.DisplayName, voice.BackendName);
                    }
                    voice = null;
                }
                return;
            }


            //MBROLA.Mbrola.Binding = MBROLA.MbrolaBinding.Standalone;
            Console.InputEncoding = Encoding.UTF8;
            TextReaderCharProducer prod = new TextReaderCharProducer();

            prod.ItemProduced += new ProduceEventHandler <char>(prod_ItemProduced);
            QaryanEngine myEngine = new QaryanEngine();

            TextReader textSrc = Console.In;

            foreach (string argument in arguments)
            {
                if (File.Exists(argument))
                {
                    textSrc = File.OpenText(argument);
                    break;
                }
            }

            DelegateConsumer <MBROLAElement> cons = new DelegateConsumer <MBROLAElement>();

            cons.ItemConsumed += new ConsumeEventHandler <MBROLAElement>(cons_ItemConsumed);

            if (opts["verbose"] != null)
            {
                if (opts["verbose"].NumDefinitions > 2)
                {
                    LogFilter = LogLevel.All;
                }
                else if (opts["verbose"].NumDefinitions > 1)
                {
                    LogFilter = LogLevel.All ^ LogLevel.Debug;
                }
                else
                {
                    LogFilter = LogLevel.All ^ (LogLevel.Debug | LogLevel.Info);
                }
            }
            else
            {
                LogFilter = LogLevel.All ^ (LogLevel.Debug | LogLevel.Info | LogLevel.MajorInfo);
            }
            myEngine.LogLine += OnLogLine;
            string voiceName = "mbrola-hb2";

            if (opts["voice"] != null)
            {
                voiceName = opts["voice"].Value as string;
            }

            Voice myVoice;

            myVoice = new Voice();
            myVoice.Load(Path.Combine(FileBindings.VoicePath, voiceName + ".xml"));
            myEngine.Voice = myVoice;
            if (opts["pho"] != null)
            {
                if ((opts["pho"].Value as string == "-") || (opts["pho"].Value == null))
                {
                    (myEngine.Backend as MbrolaBackend).Translator.ItemProduced += delegate(Producer <MBROLAElement> sender, ItemEventArgs <MBROLAElement> e)
                    {
                        Console.Write(e.Item);
                    }
                }
                ;
                else
                {
                    StreamWriter sw = File.CreateText(opts["pho"].Value as string);
                    (myEngine.Backend as MbrolaBackend).Translator.ItemProduced += delegate(Producer <MBROLAElement> sender, ItemEventArgs <MBROLAElement> e)
                    {
                        sw.Write(e.Item);
                    };
                    (myEngine.Backend as MbrolaBackend).Translator.DoneProducing += delegate(object sender, EventArgs e)
                    {
                        sw.Close();
                    };
                }
            }

            if (opts["out"] != null)
            {
                if ((opts["out"].Value as string == "-") || (opts["out"].Value == null))
                {
                    if (opts["raw"] == null)
                    {
                        myEngine.SpeakToWavStream(textSrc, Console.OpenStandardOutput());
                    }
                    else
                    {
                        myEngine.SpeakToRawStream(textSrc, Console.OpenStandardOutput());
                    }
                }
                else
                {
                    if (opts["raw"] == null)
                    {
                        myEngine.SpeakToWavFile(textSrc, opts["out"].Value as string);
                    }
                    else
                    {
                        myEngine.SpeakToRawFile(textSrc, opts["out"].Value as string);
                    }
                }
            }
            else
            {
                myEngine.Speak(textSrc);
            }

            /*}
             * else
             * {
             *  myEngine.SpeakToNull(textSrc);
             * }*/
        }