예제 #1
0
        void IStreamCopyTransactionResultCompleted(object sender, Common.Extensions.Stream.StreamExtensions.ITransactionResult t)
        {
            Buffering = false;

            if (t != null)
            {
                t.TransactionCompleted -= IStreamCopyTransactionResultCompleted;

                t.Dispose();
            }
        }
예제 #2
0
        void IStreamCopyTransactionResultCompleted(object sender, Common.Extensions.Stream.StreamExtensions.ITransactionResult t)
        {
            Buffering = false;

            if (Object.ReferenceEquals(t, null).Equals(false))
            {
                t.TransactionCompleted -= IStreamCopyTransactionResultCompleted;

                t.Dispose();
            }
        }
예제 #3
0
        public MediaFileStream(Uri source, System.IO.Stream stream, DateTime?quantifier = null, int size = 8192, bool shouldDelete = true)
            : base(GetCurrentWorkingDirectory().Directory.ToString() + (quantifier.HasValue ? quantifier.Value.ToFileTimeUtc() : DateTime.UtcNow.ToFileTimeUtc()).ToString(), System.IO.FileMode.CreateNew, System.IO.FileAccess.ReadWrite, System.IO.FileShare.ReadWrite)
        {
            m_Source = source;

            FileInfo = new System.IO.FileInfo(Name);

            Buffering = true;

            Common.Extensions.Stream.StreamExtensions.ITransactionResult result = Common.Extensions.Stream.StreamExtensions.BeginCopyTo(stream, this, size, WriteAt);

            //Race, the transaction might have already finished on small files...
            if (result.IsCompleted)
            {
                IStreamCopyTransactionResultCompleted(this, result);
            }
            else
            {
                result.TransactionCompleted += IStreamCopyTransactionResultCompleted;
            }

            if (shouldDelete)
            {
                AfterClose = new Action(DeleteFromFileInfoIfExists);
            }

            //SetEndOfFile
            //SetLength(result.ExpectedLength);

            //Done by WriteAt
            ////result.TransactionWrite += (s, e) =>
            ////{
            ////    m_Position += e.LastRead;

            ////    m_Length = e.Total;

            ////};

            //Wait for the end of the transaction or the root to be valid
            //Buffering && Root == null
            while (result.IsTransactionDone == false && Root == null)
            {
                result.AsyncWaitHandle.WaitOne(0);
            }
        }