Exemplo n.º 1
0
        /*
         *  ---------------- / PRIVATE METHODS ----------------
         */

        /*
         *  ---------------- PUBLIC METHODS ----------------
         */
        public void CompileToNoteSheet() /* Compile the code into a note sheet instance serialzed to the filepath and filename */
        {
            Parser    parser    = new Parser(code, filename, filepath: filepath);
            NoteSheet noteSheet = parser.ParseScore();

            Serializer.Serialize(noteSheet, filepath, filename);
        }
Exemplo n.º 2
0
        public const string SERIALIZE_EXT = ".mkc";                                        /* File extension of serialized NoteSheet objects */

        public static void Serialize(NoteSheet instance, string filepath, string filename) /* Takes a NoteSheet instance, file name, and file path and uses them to */
                                                                                           /* serialize the instance and store it at the path with the name         */
        {
            /* Set up the formatter and stream object s */
            IFormatter formatter = new BinaryFormatter();
            Stream     stream    = new FileStream(Path.Combine(filepath, Path.ChangeExtension(filename, SERIALIZE_EXT)), FileMode.Create, FileAccess.Write, FileShare.None);

            /* Serialize the given obejct */
            formatter.Serialize(stream, instance);
            stream.Close();
        }
Exemplo n.º 3
0
        public static NoteSheet Deserialize(string filepath, string filename)   /* Takes a file name and file path, deserializes the file at that path, and returns the */
                                                                                /* NoteSheet instance                                                                   */
        {
            try
            {
                /* Set up the formatter and stream object */
                IFormatter formatter = new BinaryFormatter();
                Stream     stream    = new FileStream(Path.Combine(filepath, Path.ChangeExtension(filename, SERIALIZE_EXT)), FileMode.Open, FileAccess.Read, FileShare.Read);

                /* Deserialize the object and return it */
                NoteSheet instance = (NoteSheet)formatter.Deserialize(stream);
                return(instance);
            }

            /* Return null if the given file was not found */
            catch (FileNotFoundException)
            {
                return(null);
            }
        }