예제 #1
0
        /// <summary>
        /// Writes the content of a buffer into a LargeObject.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        /// <param name="largeObject">The large object.</param>
        /// <param name="rpu">The rpu.</param>
        /// <param name="caller">The calling object.</param>
        /// <remarks>Documented by Dev02, 2008-08-08</remarks>
        private void BufferToLargeObject(byte[] buffer, LargeObject largeObject, StatusMessageReportProgress rpu, object caller)
        {
            largeObject.Seek(0);

            int offset = 0;
            int size = buffer.Length;
            StatusMessageEventArgs args = new StatusMessageEventArgs(StatusMessageType.CreateMediaProgress, buffer.Length);
            while (offset < size)
            {
                largeObject.Write(buffer, offset, Math.Min(chunkSize, size - offset));
                offset += chunkSize;
                args.Progress = offset;
                if (rpu != null)
                    rpu(args, caller);
            }
        }
예제 #2
0
        /// <summary>
        /// Saves the dictionary to the new path.
        /// </summary>
        /// <param name="newPath">The new path.</param>
        /// <param name="overwrite">if set to <c>true</c> [overwrite] existing files.</param>
        /// <remarks>Documented by Dev03, 2007-08-13</remarks>
        public void SaveAs(string newPath, bool overwrite)
        {
            this.Version = m_CurrentVersion;

            StatusMessageEventArgs args = new StatusMessageEventArgs(StatusMessageType.SaveAsProgress);
            ReportProgressUpdate(args);

            FlushListsToXml();

            string srcPath = System.IO.Path.GetDirectoryName(m_path);
            string dstPath = System.IO.Path.GetDirectoryName(newPath);
            string dstFileName = System.IO.Path.GetFileName(newPath);
            if (dstFileName == String.Empty)
            {
                dstFileName = System.IO.Path.GetFileName(m_path);
            }

            if (srcPath != dstPath)
            {
                if (!System.IO.Directory.Exists(dstPath))
                    System.IO.Directory.CreateDirectory(dstPath);

                List<string> resources = GetResources();
                for (int i = 0; i < resources.Count; i++)
                {
                    string file = resources[i];
                    string absFilePath = file;
                    if (!System.IO.Path.IsPathRooted(file))
                        absFilePath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(m_path), file);

                    if (absFilePath.StartsWith(srcPath))
                    {
                        if (!System.IO.File.Exists(absFilePath))
                            continue;

                        //we need to check if the path goes any deeper from mediadir and handle this appropriatly
                        string dstDirPath = System.IO.Path.Combine(dstPath, System.IO.Path.GetDirectoryName(absFilePath).Replace(srcPath, String.Empty).Trim(new char[] { '\\', ' ' }));
                        if (!System.IO.Directory.Exists(dstDirPath))
                            System.IO.Directory.CreateDirectory(dstDirPath);

                        string fileName = System.IO.Path.GetFileName(file);
                        try
                        {
                            System.IO.File.Copy(absFilePath, System.IO.Path.Combine(dstDirPath, fileName), overwrite);
                        }
                        catch { }
                    }

                    if ((i % 10) == 0)
                    {
                        args.Progress = (int)Math.Floor(100.0 * (i + 1) / resources.Count);
                        ReportProgressUpdate(args);
                    }
                }
            }
            string orgDicPath = m_path;
            m_path = System.IO.Path.Combine(dstPath, dstFileName);

            SaveDictionary();

            args.Progress = 100;
            ReportProgressUpdate(args);
        }
예제 #3
0
        /// <summary>
        /// Reports the progress update.
        /// </summary>
        /// <param name="args">The <see cref="MLifter.DAL.Tools.StatusMessageEventArgs"/> instance containing the event data.</param>
        /// <returns>[true] if the process has been canceled.</returns>
        /// <remarks>Documented by Dev03, 2007-09-03</remarks>
        private bool ReportProgressUpdate(StatusMessageEventArgs args)
        {
            switch (args.MessageType)
            {
                case StatusMessageType.XmlProgress:
                    if (XmlProgressChanged != null) XmlProgressChanged(null, args);
                    break;
                case StatusMessageType.MoveProgress:
                    if (MoveProgressChanged != null) MoveProgressChanged(null, args);
                    break;
                case StatusMessageType.SaveAsProgress:
                    if (SaveAsProgressChanged != null) SaveAsProgressChanged(null, args);
                    break;
                case StatusMessageType.CreateMediaProgress:
                    if (CreateMediaProgressChanged != null) CreateMediaProgressChanged(null, args);
                    break;
            }

            bool cancelProcess = false;
            if (m_BackgroundWorker != null)
            {
                if (m_BackgroundWorker.CancellationPending)
                {
                    cancelProcess = true;
                }
                else
                {
                    m_BackgroundWorker.ReportProgress(args.ProgressPercentage);
                }
            }
            return !cancelProcess;
        }
예제 #4
0
 /// <summary>
 /// Sends the status message update.
 /// </summary>
 /// <param name="args">The <see cref="MLifter.DAL.Tools.StatusMessageEventArgs"/> instance containing the event data.</param>
 /// <param name="caller">The caller.</param>
 /// <returns>
 /// [true] if the process should be canceled.
 /// </returns>
 /// <remarks>
 /// Documented by AAB, 20.8.2008.
 /// </remarks>
 private bool ReportProgressUpdate(StatusMessageEventArgs args, object caller)
 {
     switch (args.MessageType)
     {
         case StatusMessageType.CreateMediaProgress:
             if ((caller != null) && (caller is DbCard) && ((caller as DbCard).CreateMediaProgressChanged != null))
                 (caller as DbCard).CreateMediaProgressChanged(null, args);
             break;
     }
     return true;
 }
예제 #5
0
        /// <summary>
        /// Handles the CreateMediaProgressChanged event of the card control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="args">The <see cref="MLifter.DAL.Tools.StatusMessageEventArgs"/> instance containing the event data.</param>
        /// <remarks>Documented by Dev03, 2008-08-25</remarks>
        private void card_CreateMediaProgressChanged(object sender, StatusMessageEventArgs args)
        {
            if (statusDialog != null)
            {
                statusDialog.SetProgress(args.ProgressPercentage);

                //ML-1767 Extremely long time to add large video file to card (and no accurate progress meter)
                if (args.ProgressPercentage >= 99)
                {
                    if (statusDialog.EnableProgressbar)
                    {
                        statusDialog.EnableProgressbar = false;
                        statusDialog.Refresh();
                    }
                }
                else
                {
                    if (!statusDialog.EnableProgressbar)
                    {
                        statusDialog.EnableProgressbar = true;
                        statusDialog.Refresh();
                    }
                }
            }
        }
예제 #6
0
파일: Exporter.cs 프로젝트: hmehr/OSS
 void dictionary_XmlProgressChanged(object sender, StatusMessageEventArgs e)
 {
     this.ProgressChanged(sender, e);
 }
예제 #7
0
파일: Exporter.cs 프로젝트: hmehr/OSS
 internal ExportStatusReport(Exporter exporter, int cardCount)
 {
     this.exporter = exporter;
     CardCount = cardCount;
     status = new StatusMessageEventArgs(StatusMessageType.ExporterProgress, CardCount);
 }
예제 #8
0
        /// <summary>
        /// Saves the copy to.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="destination">The destination.</param>
        /// <param name="overwrite">if set to <c>true</c> [overwrite].</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev09, 2009-03-06</remarks>
        public static bool SaveCopyTo(string source, string destination, bool overwrite)
        {
            //StreamReader reader = new StreamReader(source);
            //StreamWriter writer = new StreamWriter(destination, false);

            int nBytes = 2048;
            byte[] data = new byte[nBytes];
            using (FileStream writer = new FileStream(destination, FileMode.Create, FileAccess.ReadWrite, FileShare.Read))
            using (FileStream reader = new FileStream(source, FileMode.Open, FileAccess.Read))
            {
                StatusMessageEventArgs args = new StatusMessageEventArgs(StatusMessageType.SaveAsProgress, (int)reader.Length);
                int counter = 0;
                while ((nBytes = reader.Read(data, 0, data.Length)) > 0)
                {
                    writer.Write(data, 0, nBytes);
                    args.Progress = counter++ * data.Length;
                    ReportSaveCopyToProgress(args);
                }
                reader.Close();
                writer.Close();
            }

            return false;
        }
예제 #9
0
        /// <summary>
        /// Gets the byte array from stream.
        /// </summary>
        /// <param name="media">The media.</param>
        /// <param name="rpu">The rpu.</param>
        /// <param name="caller">The caller.</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev05, 2009-01-16</remarks>
        private static byte[] GetByteArrayFromStream(System.IO.Stream media, MLifter.DAL.Tools.StatusMessageReportProgress rpu, object caller)
        {
            int buffer_length = 10240;
            byte[] data = new byte[media.Length];
            StatusMessageEventArgs args = new StatusMessageEventArgs(StatusMessageType.CreateMediaProgress, (int)media.Length);

            media.Seek(0, SeekOrigin.Begin);

            int read = 0;
            int pos = 0;
            do
            {
                read = media.Read(data, pos, Math.Min(buffer_length, data.Length - pos));
                pos += read;
                args.Progress = pos;
                if (rpu != null)
                    rpu.Invoke(args, caller);
            }
            while (read == buffer_length);
            return data;
        }
예제 #10
0
 private static void ReportSaveCopyToProgress(StatusMessageEventArgs args)
 {
     if (SaveCopyToProgressChanged != null)
         SaveCopyToProgressChanged(null, args);
 }
예제 #11
0
파일: Dictionary.cs 프로젝트: hmehr/OSS
 void Dictionary_XmlProgressChanged(object sender, StatusMessageEventArgs args)
 {
     if (XmlProgressChanged != null) XmlProgressChanged(this, args);
 }
예제 #12
0
파일: Dictionary.cs 프로젝트: hmehr/OSS
 void Dictionary_CreateMediaProgressChanged(object sender, StatusMessageEventArgs args)
 {
     if (CreateMediaProgressChanged != null) CreateMediaProgressChanged(this, args);
 }
예제 #13
0
 /// <summary>
 /// Adds the media to the card.
 /// </summary>
 /// <param name="media">The media.</param>
 /// <param name="side">The side.</param>
 /// <returns>The media object.</returns>
 /// <remarks>Documented by Dev03, 2007-08-07</remarks>
 public IMedia AddMedia(IMedia media, Side side)
 {
     if (media == null) throw new NullReferenceException("Media object must not be null!");
     if (!(media is XmlMedia))
         media = CreateMedia(media.MediaType, media.Filename, media.Active.Value, media.Default.Value, media.Example.Value);
     RemoveMediaNodes(media, side); //cleanup old media nodes with the same path
     StatusMessageEventArgs args = new StatusMessageEventArgs(StatusMessageType.CreateMediaProgress);
     ReportProgressUpdate(args);
     if (CopyFileToMediaFolder(media, side))
     {
         ReportProgressUpdate(args);
         CreateMediaNode(media, side);
         return media;
     }
     else
     {
         ReportProgressUpdate(args);
         return null;
     }
 }
예제 #14
0
 /// <summary>
 /// Sends the status message update.
 /// </summary>
 /// <param name="args">The <see cref="MLifter.DAL.Tools.StatusMessageEventArgs"/> instance containing the event data.</param>
 /// <returns>
 /// [true] if the process should be canceled.
 /// </returns>
 /// <remarks>Documented by Dev03, 2008-08-20</remarks>
 private bool ReportProgressUpdate(StatusMessageEventArgs args)
 {
     switch (args.MessageType)
     {
         case StatusMessageType.CreateMediaProgress:
             if (CreateMediaProgressChanged != null)
                 CreateMediaProgressChanged(this, args);
             break;
     }
     return true;
 }