示例#1
0
        public static bool IsChordsFileValid(HttpPostedFileBase chordsFileHandler, SongFileType fileType, out IList <IBar> bars, out string errorMessage)
        {
            bars         = null;
            errorMessage = null;

            try
            {
                // build a stream reader for reading the chord progression
                StreamReader streamReader = new StreamReader(chordsFileHandler.InputStream);
                bars = CompositionContext.ReadChordsFromFile(streamReader);

                // reset stream origin seek to beginning
                chordsFileHandler.InputStream.Position = 0;

                // no errors found while parsing the file
                return(true);
            }
            catch (Exception ex)
            {
                // if this is a chord file validation, return any found errors if such exist
                if (fileType == SongFileType.ChordProgressionFile)
                {
                    errorMessage = ex.Message;
                    return(false);
                }

                // if this is a check for midi file, no need to fail on chords
                return(true);
            }
        }