Example #1
0
        public void directoryRead()
        {
            try {
                Regex reg       = new Regex("^.*/([^/]+)$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
                int   lastCount = 0;
                while (true)
                {
                    string[] filenames = Directory.GetFiles(homeDir, "*.log");
                    if (filenames.Length != lastCount)
                    {
                        files.Clear();
                        List <FileDescription> filesTmp = new List <FileDescription>();
                        foreach (string filename in filenames)
                        {
                            filesTmp.Add(new FileDescription(reg.Replace(filename.Replace('\\', '/'), "$1"), File.GetCreationTime(filename).ToString()));
                        }
                        lastCount = filenames.Length;
                        filesTmp.Sort(compareByCreateTime);
                        filesTmp.ForEach(delegate(FileDescription fd) {
                            files.Add(fd);
                        });

                        /*
                         * get reader
                         */
                        bool skip = reader == null;
                        reader = null;
                        string fn = homeDir + files[files.Count - 1].name;
                        logger.log("Using journal file: " + fn);
                        FileStream fs = new FileStream(fn, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                        reader = new StreamReader(fs, System.Text.Encoding.UTF8);
                        if (skip)
                        {
                            reader.ReadToEnd();
                        }
                    }
                    Thread.Sleep(1000);
                }
            }
            catch (Exception e1)
            {
            }
        }
Example #2
0
        public MainWindow()
        {
            InitializeComponent();


            TextLogger logger = TextLogger.instance;

            logger.output = logTextBox;

            /**
             * Initialize log4net
             */
            string log4netPath = "log4net/log4net.config";

            if (File.Exists(log4netPath))
            {
                XmlConfigurator.Configure(new FileInfo(log4netPath));
            }
            else if (File.Exists(Environment.ExpandEnvironmentVariables("%APPDATA%") + "/EliteVoice/" + log4netPath))
            {
                XmlConfigurator.Configure(new FileInfo(Environment.ExpandEnvironmentVariables("%APPDATA%") + "/EliteVoice/" + log4netPath));
            }
            else
            {
                logger.log("Not found log4net configuration. See documentation.");
            }

            var enumerator = new NAudio.CoreAudioApi.MMDeviceEnumerator();
            var dev        = enumerator.GetDefaultAudioEndpoint(NAudio.CoreAudioApi.DataFlow.Render, NAudio.CoreAudioApi.Role.Console);

            //logger.log(dev.DeviceFriendlyName);
            //logger.log(dev.FriendlyName);

            speech = Speech.instance;
            //speech.speech.
            audios = speech.speech.GetAudioOutputs();
            int idx = 0, i = 0;

            foreach (SpObjectToken audio in audios)
            {
                audioDevices.Items.Add(audio.GetDescription());
                //if (audio.GetDescription().Equals(speech.speech.AudioOutput.GetDescription()))
                if (audio.GetDescription().Equals(dev.FriendlyName))
                {
                    speech.speech.AudioOutput = audio;
                    idx = i;
                }
                i++;
            }
            audioDevices.SelectedIndex = idx;

            /*
             *
             */
            logger.log("Found voices:");
            foreach (ISpeechObjectToken voice in speech.speech.GetVoices())
            {
                logger.log(voice.GetDescription());
            }

            /**
             *
             */
            EliteVoice.ConfigReader.ConfigReader config = null;
            string configPath = "config/config.xml";

            if (File.Exists(configPath))
            {
                config = new EliteVoice.ConfigReader.ConfigReader(configPath);
            }
            else if (File.Exists(Environment.ExpandEnvironmentVariables("%APPDATA%") + "/EliteVoice/" + configPath))
            {
                config = new EliteVoice.ConfigReader.ConfigReader(Environment.ExpandEnvironmentVariables("%APPDATA%") + "/EliteVoice/" + configPath);
            }
            else
            {
                logger.log("Not found configuration!!!");
                return;
            }

            config.parse();

            /*
             *
             */
            commands = new CommandProcessor(config);
            List <FileDescription> files = new List <FileDescription>();

            fileGrid.ItemsSource = files;
            FileProcessor processor = new FileProcessor(files, commands);

            tProcessor = new Thread(new ThreadStart(processor.directoryRead));
            tProcessor.Start();
            lProcessor = new Thread(new ThreadStart(processor.processCurrentFile));
            lProcessor.Start();
        }
Example #3
0
        public void process(string jsonStr)
        {
            this.doNextLine = false;
            log.Debug(jsonStr);
            logger.log("Receive json: " + jsonStr);
            // Some test
            XmlDocument docXML = (XmlDocument)JsonConvert.DeserializeXmlNode(jsonStr, "root");
            XdmNode     doc    = XMLContext.instance.processor.NewDocumentBuilder().Wrap(docXML);

            if (doc != null)
            {
                log.Debug(doc.OuterXml);

                XdmNode eventElement = (XdmNode)XMLContext.instance.xpath.EvaluateSingle("/*/event", doc);
                if (eventElement != null)
                {
                    string   eventName = eventElement.GetStringValue();
                    ICommand command   = config.getEvent(eventName);
                    if (command != null)
                    {
                        logger.log("Command successfully found for event: " + eventName);
                        try
                        {
                            foreach (Replacer rp in EventContext.instance.replacers)
                            {
                                //rp.Replace(values);
                            }
                        }
                        catch (Exception e)
                        {
                            logger.log("Replace error result: " + e.Message);
                        }
                        command.runCommand(doc);
                    }
                    else
                    {
                        Boolean find = false;
                        foreach (string eventXpath in config.events.Keys)
                        {
                            XPathExpression exp = XMLContext.instance.getXPathExpression(eventXpath);
                            if (XMLContext.instance.xpath.EvaluateSingle(eventXpath, doc) != null)
                            {
                                command = config.getEvent(eventXpath);
                                if (command != null)
                                {
                                    logger.log("Command successfully found for event: " + eventName);
                                    try
                                    {
                                        foreach (Replacer rp in EventContext.instance.replacers)
                                        {
                                            //rp.Replace(values);
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        logger.log("Replace error result: " + e.Message);
                                    }
                                    command.runCommand(doc);
                                }
                                find = true;
                                break;
                            }
                        }
                        if (!find)
                        {
                            logger.log("No command found for event: " + eventName);
                        }
                    }
                }
                else
                {
                    log.Error("Error parsing to XML!!!");
                }
            }
            this.doNextLine = true;
        }