Beispiel #1
0
        private void LoadFiles(IEnumerable <string> files)
        {
            string text = "";

            foreach (var f in files)
            {
                var fi = new System.IO.FileInfo(f);
                if (text.Length > 0)
                {
                    text += ",";
                }
                text += fi.Name;
            }

            text = StringExtras.Truncate(text, 100);
            Text = defaultTitle + " - " + text;

            var op        = new textoptions(ignoreHTML.Checked, ignoreNonAlphabetCharactersToolStripMenuItem.Checked);
            var errorfile = controller.LoadFiles(files.ToList(), op);

            if (errorfile != null)
            {
                MessageBox.Show("Error loading file:" + errorfile);
                return;
            }

            SetControlsEnable(true);
            RefreshCharts();
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="options"></param>
        /// <returns>return null if no error, and return an error string if there was one</returns>
        public static string LoadFiles(List <string> filename, textoptions options)
        {
            var files = "";

            foreach (var f in filename)
            {
                var s = FileExtras.LoadFile(f);
                if (s == null)
                {
                    return(f);
                }

                if (string.IsNullOrEmpty(s))
                {
                    continue;
                }
                files += "\n" + s;
            }

            if (string.IsNullOrWhiteSpace(files))
            {
                return(null);
            }

            M = new model(SanatiseFile(files, options), filename);

            return(null);
        }
        private static List <List <string> > SanatiseFile(string filestr, textoptions options)
        {
            var sepNewLine  = new[] { "\r\n", "\n" };
            var sepWord     = new[] { " " };
            var sepWordChar = new[] { ' ' };
            //split by new lines
            var lines = filestr.Split(sepNewLine, StringSplitOptions.RemoveEmptyEntries);

            var output = new List <List <string> >();

            //split into words
            foreach (var sentence in lines)
            {
                var sentence1 = sentence;

                if (options.ignoreHTML)
                {
                    sentence1 = Regex.Replace(sentence1, "<.*?>", "");
                }

                if (options.ignoreNonAlpha)
                {
                    sentence1 = StringExtras.RemoveAllNonAlphabetChars(sentence1);
                }

                //trim trailing whitespace
                sentence1 = sentence1.Trim(sepWordChar);

                if (String.IsNullOrWhiteSpace(sentence1))
                {
                    continue;
                }

                var words = sentence1.Split(sepWord, StringSplitOptions.RemoveEmptyEntries);

                var newSentence = new List <string>();
                foreach (var word in words)
                {
                    var word1 = word;

                    word1 = word1.ToLower();

                    if (word1.Length > 0)
                    {
                        newSentence.Add(word1);
                    }
                }

                if (newSentence.Count > 0)
                {
                    output.Add(newSentence);
                }
            }

            return(output);
        }
        private static List<List<string>> SanatiseFile(string filestr, textoptions options)
        {
            var sepNewLine = new[] { "\r\n", "\n" };
            var sepWord = new[] { " " };
            var sepWordChar = new[] { ' ' };
            //split by new lines
            var lines = filestr.Split(sepNewLine, StringSplitOptions.RemoveEmptyEntries);

            var output = new List<List<string>>();

            //split into words
            foreach (var sentence in lines)
            {
                var sentence1 = sentence;

                if (options.ignoreHTML)
                    sentence1 = Regex.Replace(sentence1, "<.*?>", "");

                if (options.ignoreNonAlpha)
                    sentence1 = StringExtras.RemoveAllNonAlphabetChars(sentence1);

                //trim trailing whitespace
                sentence1 = sentence1.Trim(sepWordChar);

                if (String.IsNullOrWhiteSpace(sentence1))
                    continue;

                var words = sentence1.Split(sepWord, StringSplitOptions.RemoveEmptyEntries);

                var newSentence = new List<string>();
                foreach (var word in words)
                {
                    var word1 = word;

                    word1 = word1.ToLower();

                    if (word1.Length > 0)
                    {
                        newSentence.Add(word1);
                    }
                }

                if (newSentence.Count > 0)
                    output.Add(newSentence);
            }

            return output;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="options"></param>
        /// <returns>return null if no error, and return an error string if there was one</returns>
        public static string LoadFiles(List<string> filename, textoptions options)
        {
            var files = "";
            foreach (var f in filename)
            {
                var s = FileExtras.LoadFile(f);
                if (s == null)
                    return f;

                if (string.IsNullOrEmpty(s))
                    continue;
                files += "\n" + s;
            }

            if (string.IsNullOrWhiteSpace(files))
                return null;

            M = new model(SanatiseFile(files, options),filename);

            return null;
        }
Beispiel #6
0
        private void LoadFiles(IEnumerable<string> files)
        {
            string text = "";
            foreach (var f in files)
            {
                var fi = new System.IO.FileInfo(f);
                if (text.Length > 0)
                    text += ",";
                text += fi.Name;
            }

            text = StringExtras.Truncate(text, 100);
            Text = defaultTitle + " - " + text;

            var op = new textoptions(ignoreHTML.Checked, ignoreNonAlphabetCharactersToolStripMenuItem.Checked);
            var errorfile = controller.LoadFiles(files.ToList(), op);
            if (errorfile != null)
            {
                MessageBox.Show("Error loading file:" + errorfile);
                return;
            }

            SetControlsEnable(true);
            RefreshCharts();
        }