Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.VisualBasic;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Data;
- using System.Diagnostics;
- public sealed class Form1
- {
- /// <summary>
- /// Handles the <see cref="FileSplitter"/> instance.
- /// </summary>
- private FileSplitter withEventsField_splitter = new FileSplitter { BufferSize = .BufferSize };
- private FileSplitter splitter {
- get { return withEventsField_splitter; }
- set {
- if (withEventsField_splitter != null) {
- withEventsField_splitter.SplitProgressChanged -= Splitter_SplitProgressChangedArgs;
- withEventsField_splitter.MergeProgressChanged -= Splitter_MergeProgressChangedArgs;
- }
- withEventsField_splitter = value;
- if (withEventsField_splitter != null) {
- withEventsField_splitter.SplitProgressChanged += Splitter_SplitProgressChangedArgs;
- withEventsField_splitter.MergeProgressChanged += Splitter_MergeProgressChangedArgs;
- }
- }
- }
- // Splitter settings.
- private readonly string workingDir = "C:\\Test";
- private readonly string fileName = "File.mp3";
- private readonly string filePath = IO.Path.Combine(workingDir, fileName);
- private readonly string chunkName = "File.Part";
- private readonly string chunkExt = "fs";
- // Merger settings.
- private readonly string firstChunkPath = string.Format("{0}\\{1}.01.{2}", workingDir, chunkName, chunkExt);
- private readonly string targetFileName = string.Format("{0}\\{1}.{2}", workingDir, "Merged", IO.Path.GetExtension(fileName));
- // Some default chunk sizes to split a file.
- private readonly int kilobyte = 1024;
- private readonly int megabyte = 1048576;
- private readonly int gigabyte = 1073741824;
- private readonly int halfFileSize = Convert.ToInt32(new IO.FileInfo(filePath).Length / 2);
- // The label controls that will display the progress.
- private Label labelSplit1 = new Label();
- private Label labelSplit2 = new Label();
- private Label labelSplit3 = new Label();
- private Label labelMerge1 = new Label();
- private Label labelMerge2 = new Label();
- private Label labelMerge3 = new Label();
- // The button controls to start a split or merge operation.
- private Button withEventsField_buttonSplit;
- private Button buttonSplit {
- get { return withEventsField_buttonSplit; }
- set {
- if (withEventsField_buttonSplit != null) {
- withEventsField_buttonSplit.Click -= ButtonSplit_Click;
- }
- withEventsField_buttonSplit = value;
- if (withEventsField_buttonSplit != null) {
- withEventsField_buttonSplit.Click += ButtonSplit_Click;
- }
- }
- }
- private Button withEventsField_buttonMerge = new Button();
- private Button buttonMerge {
- get { return withEventsField_buttonMerge; }
- set {
- if (withEventsField_buttonMerge != null) {
- withEventsField_buttonMerge.Click -= ButtonMerge_Click;
- }
- withEventsField_buttonMerge = value;
- if (withEventsField_buttonMerge != null) {
- withEventsField_buttonMerge.Click += ButtonMerge_Click;
- }
- }
- }
- /// <summary>
- /// Initializes a new instance of the <see cref="Form1"/> class.
- /// </summary>
- public Form1()
- {
- // This call is required by the designer.
- this.InitializeComponent();
- // Set the controls properties.
- buttonSplit.Text = "Split";
- buttonSplit.Font = new Font(this.Font.FontFamily, 14f, FontStyle.Bold);
- buttonSplit.Size = new Size(200, 75);
- buttonSplit.Location = new Point(0, 0);
- buttonSplit.Cursor = Cursors.Hand;
- buttonMerge.Text = "Merge";
- buttonMerge.Font = new Font(this.Font.FontFamily, 14f, FontStyle.Bold);
- buttonMerge.Size = new Size(200, 75);
- buttonMerge.Location = new Point(buttonSplit.Location.X + buttonSplit.Width, 0);
- buttonMerge.Cursor = Cursors.Hand;
- labelSplit1.Text = "Total Progress:";
- labelSplit1.AutoSize = true;
- labelSplit1.Font = new Font(this.Font.FontFamily, 9f, FontStyle.Regular);
- labelSplit1.Location = new Point(0, buttonSplit.Location.Y + buttonSplit.Height + 10);
- labelSplit2.Text = "Chunk Progress:";
- labelSplit2.AutoSize = true;
- labelSplit2.Font = new Font(this.Font.FontFamily, 9f, FontStyle.Regular);
- labelSplit2.Location = new Point(0, labelSplit1.Location.Y + labelSplit1.Height);
- labelSplit3.Text = "Chunk Count:";
- labelSplit3.AutoSize = true;
- labelSplit3.Font = new Font(this.Font.FontFamily, 9f, FontStyle.Regular);
- labelSplit3.Location = new Point(0, labelSplit2.Location.Y + labelSplit2.Height);
- labelMerge1.Text = "Total Progress:";
- labelMerge1.AutoSize = true;
- labelMerge1.Font = new Font(this.Font.FontFamily, 9f, FontStyle.Regular);
- labelMerge1.Location = new Point(buttonMerge.Location.X, buttonMerge.Location.Y + buttonMerge.Height + 10);
- labelMerge2.Text = "Chunk Progress:";
- labelMerge2.AutoSize = true;
- labelMerge2.Font = new Font(this.Font.FontFamily, 9f, FontStyle.Regular);
- labelMerge2.Location = new Point(buttonMerge.Location.X, labelMerge1.Location.Y + labelMerge1.Height);
- labelMerge3.Text = "Chunk Count:";
- labelMerge3.AutoSize = true;
- labelMerge3.Font = new Font(this.Font.FontFamily, 9f, FontStyle.Regular);
- labelMerge3.Location = new Point(buttonMerge.Location.X, labelMerge2.Location.Y + labelMerge2.Height);
- // Add the controls on the UI.
- this.Controls.AddRange({
- labelSplit1, labelSplit2, labelSplit3,
- labelMerge1, labelMerge2, labelMerge3,
- buttonSplit, buttonMerge
- })
- // Set the Form properties.
- this.Size = new Size(buttonSplit.Width + buttonMerge.Width + 20, 200);
- this.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedDialog;
- this.MaximizeBox = false;
- }
- /// <summary>
- /// Handles the <see cref="Button.Click"/> event of the <see cref="ButtonSplit"/> control.
- /// </summary>
- private void ButtonSplit_Click()
- {
- this.splitter.Split(sourceFile: this.filePath,
- chunkSize: this.halfFileSize,
- chunkName: this.chunkName,
- chunkExt: this.chunkExt,
- overwrite: true,
- deleteAfterSplit: false);
- // Or...
- //Me.splitter.Split(sourceFile:=Me.filePath,
- // chunkCount:=2,
- // chunkName:=Me.chunkName,
- // chunkExt:=Me.chunkExt,
- // overwrite:=True,
- // deleteAfterSplit:=False)
- }
- /// <summary>
- /// Handles the <see cref="Button.Click"/> event of the <see cref="ButtonMerge"/> control.
- /// </summary>
- private void ButtonMerge_Click()
- {
- this.splitter.Merge(sourceChunk: this.firstChunkPath,
- targetFile: this.targetFileName,
- overwrite: true,
- deleteChunksAfterMerged: false);
- }
- /// <summary>
- /// Handles the <see cref="FileSplitter.SplitProgressChangedArgs"/> event of the <see cref="Splitter"/> instance.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="FileSplitter.SplitProgressChangedArgs"/> instance containing the event data.</param>
- private void Splitter_SplitProgressChangedArgs(object sender, FileSplitter.SplitProgressChangedArgs e)
- {
- labelSplit1.Text = string.Format("Total Progress: {0}%", e.TotalProgress.ToString("n1"));
- labelSplit2.Text = string.Format("Chunk Progress: {0}%", e.ChunkProgress.ToString("n1"));
- labelSplit3.Text = string.Format("Current Chunk: {0} of {1}", Convert.ToString(e.ChunksCreated + 1), Convert.ToString(e.ChunksToCreate));
- Application.DoEvents();
- }
- /// <summary>
- /// Handles the <see cref="FileSplitter.MergeProgressChangedArgs"/> event of the <see cref="Splitter"/> instance.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="FileSplitter.MergeProgressChangedArgs"/> instance containing the event data.</param>
- private void Splitter_MergeProgressChangedArgs(object sender, FileSplitter.MergeProgressChangedArgs e)
- {
- labelMerge1.Text = string.Format("Total Progress: {0}%", e.TotalProgress.ToString("n1"));
- labelMerge2.Text = string.Format("Chunk Progress: {0}%", e.ChunkProgress.ToString("n1"));
- labelMerge3.Text = string.Format("Current Chunk: {0} of {1}", Convert.ToString(e.ChunksMerged + 1), Convert.ToString(e.ChunksToMerge));
- Application.DoEvents();
- }
- }
- //=======================================================
- //Service provided by Telerik (www.telerik.com)
- //=======================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement