Ejemplo n.º 1
0
        public bool RemoveTagFromFile(int tagType)
        {
            bool result = false;

            LogDelegator.GetLocateDelegate()(fileName);

            try
            {
                using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite, FileShare.Read, bufferSize, fileOptions))
                    using (BinaryReader reader = new BinaryReader(fs))
                    {
                        result = read(reader, false, false, true);

                        IMetaDataIO metaIO = getMeta(tagType);
                        if (metaIO.Exists)
                        {
                            using (BinaryWriter writer = new BinaryWriter(fs))
                            {
                                metaIO.Remove(writer);
                            }
                        }
                    }
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.Message);
                System.Console.WriteLine(e.StackTrace);
                LogDelegator.GetLogDelegate()(Log.LV_ERROR, e.Message);
                result = false;
            }

            return(result);
        }
Ejemplo n.º 2
0
        public bool ReadFromFile(TagData.PictureStreamHandlerDelegate pictureStreamHandler, bool readAllMetaFrames = false)
        {
            bool result = false;

            LogDelegator.GetLocateDelegate()(fileName);

            resetData();

            try
            {
                // Open file, read first block of data and search for a frame
                Stream       s      = (null == stream) ? new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize, fileOptions) : stream;
                BinaryReader source = new BinaryReader(s);
                try
                {
                    result = read(source, pictureStreamHandler, readAllMetaFrames);
                }
                finally
                {
                    if (null == stream)
                    {
                        source.Close();
                    }
                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.Message);
                System.Console.WriteLine(e.StackTrace);
                LogDelegator.GetLogDelegate()(Log.LV_ERROR, e.Message);
                result = false;
            }

            return(result);
        }
Ejemplo n.º 3
0
        public bool ReadFromFile(bool readEmbeddedPictures = false, bool readAllMetaFrames = false)
        {
            bool result = false;

            LogDelegator.GetLocateDelegate()(fileName);

            resetData();

            try
            {
                // Open file, read first block of data and search for a frame
                using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize, fileOptions))
                    using (BinaryReader source = new BinaryReader(fs))
                    {
                        result = read(source, readEmbeddedPictures, readAllMetaFrames);
                    }
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.Message);
                System.Console.WriteLine(e.StackTrace);
                LogDelegator.GetLogDelegate()(Log.LV_ERROR, e.Message);
                result = false;
            }

            return(result);
        }
Ejemplo n.º 4
0
        public void Log_Location_MultiThread()
        {
            messages.Clear();

            Thread thread = new Thread(log_Location_MultiThread_sub);

            thread.Start();

            LogDelegator.GetLocateDelegate()("here");
            LogDelegator.GetLogDelegate()(Log.LV_ERROR, "testI");
            LogDelegator.GetLogDelegate()(Log.LV_ERROR, "testD");

            Thread.Sleep(200);

            Assert.AreEqual(messages.Count, 4);
            foreach (Log.LogItem logItem in messages)
            {
                if (logItem.Level.Equals(Log.LV_WARNING))
                {
                    Assert.AreEqual(logItem.Location, "over there");
                }
                if (logItem.Level.Equals(Log.LV_ERROR))
                {
                    Assert.AreEqual(logItem.Location, "here");
                }
            }
        }
Ejemplo n.º 5
0
        public bool UpdateTagInFile(TagData theTag, int tagType)
        {
            bool        result = true;
            IMetaDataIO theMetaIO;

            LogDelegator.GetLocateDelegate()(fileName);
            theTag.DurationMs = audioDataIO.Duration;

            if (audioDataIO.IsMetaSupported(tagType))
            {
                try
                {
                    theMetaIO = getMeta(tagType);

                    Stream       s = (null == stream) ? new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite, FileShare.Read, bufferSize, fileOptions) : stream;
                    BinaryReader r = new BinaryReader(s);
                    BinaryWriter w = new BinaryWriter(s);
                    try
                    {
                        // If current file can embed metadata, do a 1st pass to detect embedded metadata position
                        if (audioDataIO is IMetaDataEmbedder)
                        {
                            MetaDataIO.ReadTagParams readTagParams = new MetaDataIO.ReadTagParams(false, false);
                            readTagParams.PrepareForWriting = true;

                            audioDataIO.Read(r, sizeInfo, readTagParams);
                            theMetaIO.SetEmbedder((IMetaDataEmbedder)audioDataIO);
                        }

                        result = theMetaIO.Write(r, w, theTag, writeProgress);
                        if (result)
                        {
                            setMeta(theMetaIO);
                        }
                    } finally
                    {
                        if (null == stream)
                        {
                            r.Close();
                            w.Close();
                        }
                    }
                }
                catch (Exception e)
                {
                    System.Console.WriteLine(e.Message);
                    System.Console.WriteLine(e.StackTrace);
                    LogDelegator.GetLogDelegate()(Log.LV_ERROR, e.Message);
                    result = false;
                }
            }
            else
            {
                LogDelegator.GetLogDelegate()(Log.LV_DEBUG, "Tag type " + tagType + " not supported");
            }

            return(result);
        }
Ejemplo n.º 6
0
        public void TestSyncMessage()
        {
            messages.Clear();

            LogDelegator.GetLocateDelegate()("file name");
            LogDelegator.GetLogDelegate()(Log.LV_DEBUG, "test message 1");
            LogDelegator.GetLogDelegate()(Log.LV_WARNING, "test message 2");

            System.Console.WriteLine(messages[0].Message);
        }
Ejemplo n.º 7
0
        public void Log_Location()
        {
            messages.Clear();

            LogDelegator.GetLocateDelegate()("here");
            LogDelegator.GetLogDelegate()(Log.LV_INFO, "test1");
            Assert.AreEqual("here", messages[0].Location);

            LogDelegator.GetLocateDelegate()("there");
            LogDelegator.GetLogDelegate()(Log.LV_INFO, "test2");
            Assert.AreEqual("there", messages[1].Location);
        }
Ejemplo n.º 8
0
        public Boolean RemoveTagFromFile(Int32 tagType)
        {
            var result = false;

            LogDelegator.GetLocateDelegate()(fileName);

            try
            {
                var s = (null == stream)
                    ? new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite, FileShare.Read, bufferSize,
                                     fileOptions)
                    : stream;
                var          reader = new BinaryReader(s);
                BinaryWriter writer = null;
                try
                {
                    result = read(reader, false, false, true);

                    var metaIO = getMeta(tagType);
                    if (metaIO.Exists)
                    {
                        writer = new BinaryWriter(s);
                        metaIO.Remove(writer);
                    }
                }
                finally
                {
                    if (null == stream)
                    {
                        reader.Close();
                        if (writer != null)
                        {
                            writer.Close();
                        }
                    }
                }
            }
            catch (ArgumentOutOfRangeException e)
            {
                throw new AudioDataCorruptionException(
                          "Possible audio data corruption, check Inner Exception for details", e);
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.Message);
                System.Console.WriteLine(e.StackTrace);
                LogDelegator.GetLogDelegate()(Log.LV_ERROR, e.Message);
                result = false;
            }

            return(result);
        }
Ejemplo n.º 9
0
        public bool RemoveTagFromFile(int tagType)
        {
            bool result = false;

            LogDelegator.GetLocateDelegate()(fileName);

            try
            {
                Stream       s      = (null == stream) ? new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite, FileShare.Read, bufferSize, fileOptions) : stream;
                BinaryReader reader = new BinaryReader(s);
                BinaryWriter writer = null;
                try
                {
                    result = read(reader, false, false, true);

                    IMetaDataIO metaIO = getMeta(tagType);
                    if (metaIO.Exists)
                    {
                        writer = new BinaryWriter(s);
                        metaIO.Remove(writer);
                    }
                } finally
                {
                    if (null == stream)
                    {
                        reader.Close();
                        if (writer != null)
                        {
                            writer.Close();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.Message);
                System.Console.WriteLine(e.StackTrace);
                LogDelegator.GetLogDelegate()(Log.LV_ERROR, e.Message);
                result = false;
            }

            return(result);
        }
Ejemplo n.º 10
0
        public Boolean ReadFromFile(TagData.PictureStreamHandlerDelegate pictureStreamHandler,
                                    Boolean readAllMetaFrames = false)
        {
            var result = false;

            LogDelegator.GetLocateDelegate()(fileName);

            resetData();

            try
            {
                // Open file, read first block of data and search for a frame
                var s = (null == stream)
                    ? new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize, fileOptions)
                    : stream;
                var source = new BinaryReader(s);
                try
                {
                    result = read(source, pictureStreamHandler, readAllMetaFrames);
                }
                finally
                {
                    if (null == stream)
                    {
                        source.Close();
                    }
                }
            }
            catch (ArgumentOutOfRangeException e)
            {
                throw new AudioDataCorruptionException(
                          "Possible audio data corruption, check Inner Exception for details", e);
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.Message);
                System.Console.WriteLine(e.StackTrace);
                LogDelegator.GetLogDelegate()(Log.LV_ERROR, e.Message);
                result = false;
            }

            return(result);
        }
Ejemplo n.º 11
0
 private void log_Location_MultiThread_sub()
 {
     LogDelegator.GetLocateDelegate()("over there");
     LogDelegator.GetLogDelegate()(Log.LV_WARNING, "testE");
     LogDelegator.GetLogDelegate()(Log.LV_WARNING, "testW");
 }
Ejemplo n.º 12
0
        public Boolean UpdateTagInFile(TagData theTag, Int32 tagType)
        {
            var         result = true;
            IMetaDataIO theMetaIO;

            LogDelegator.GetLocateDelegate()(fileName);

            if (audioDataIO.IsMetaSupported(tagType))
            {
                try
                {
                    theMetaIO = getMeta(tagType);

                    var s = (null == stream)
                        ? new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite, FileShare.Read, bufferSize,
                                         fileOptions)
                        : stream;
                    var r = new BinaryReader(s);
                    var w = new BinaryWriter(s);
                    try
                    {
                        // If current file can embed metadata, do a 1st pass to detect embedded metadata position
                        if (audioDataIO is IMetaDataEmbedder)
                        {
                            var readTagParams = new MetaDataIO.ReadTagParams(false, false);
                            readTagParams.PrepareForWriting = true;

                            audioDataIO.Read(r, sizeInfo, readTagParams);
                            theMetaIO.SetEmbedder((IMetaDataEmbedder)audioDataIO);
                        }

                        result = theMetaIO.Write(r, w, theTag);
                    }
                    finally
                    {
                        if (null == stream)
                        {
                            r.Close();
                            w.Close();
                        }
                    }
                }
                catch (ArgumentOutOfRangeException e)
                {
                    throw new AudioDataCorruptionException(
                              "Possible audio data corruption, check Inner Exception for details", e);
                }
                catch (Exception e)
                {
                    System.Console.WriteLine(e.Message);
                    System.Console.WriteLine(e.StackTrace);
                    LogDelegator.GetLogDelegate()(Log.LV_ERROR, e.Message);
                    result = false;
                }
            }
            else
            {
                LogDelegator.GetLogDelegate()(Log.LV_DEBUG, "Tag type " + tagType + " not supported");
            }

            return(result);
        }