Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version
Go to top

Sample speed test for Transport Stream construction

, 13 Apr 2004
A program that emulates the TS construction from ES files for the HDTV standard.
ts_constructor.zip
TS_constructor
TS_constructor.exe
ts_source_code.zip
TS_Source_Code
App.ico
ts.ico
mpeg_tst.csproj.user
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Management;
using System.IO;

namespace mpeg_tst
{
	public class Sample : System.Windows.Forms.Form
	{
		private diagram my_diagram=new diagram();
		private options my_options;
		private solver my_solver=new solver();
		private legend my_legend=new legend();
		private about my_about=new about();
		private System.Windows.Forms.Button generate;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Button start;
		private System.Windows.Forms.TextBox speed;
		private System.Windows.Forms.Button exit;
		private System.Windows.Forms.Button diagram;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.TextBox space;
		private System.Windows.Forms.Label label10;
		private System.Windows.Forms.Label label11;
		private System.Windows.Forms.TextBox ts_state;
		private System.Windows.Forms.TextBox es_state;
		private System.Windows.Forms.Label label12;
		private System.Windows.Forms.Button about;
		private System.Windows.Forms.Label label13;
		private System.Windows.Forms.Label label14;
		private System.Windows.Forms.Label label15;
		private System.Windows.Forms.Label space_msg;
		private System.Windows.Forms.Label label16;
		private System.Windows.Forms.TextBox avaible_space;
		private System.Windows.Forms.Label label17;
		private System.Windows.Forms.ProgressBar es_prg;
		public  System.Windows.Forms.ProgressBar ts_prg;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label18;
		private System.Windows.Forms.Button del_es;
		private System.Windows.Forms.Button del_ts;
		private System.Windows.Forms.Button set_opt;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Label label19;
		private System.Windows.Forms.TextBox el_time;
		private System.Windows.Forms.Label label20;
		private System.ComponentModel.IContainer components;

		public long TS_packs;
		private System.Windows.Forms.NumericUpDown nr_fis;
		private System.Windows.Forms.NumericUpDown fis_size;
		private System.Windows.Forms.NumericUpDown buff;
		private System.Windows.Forms.Label label21;
		public long est_TS_packs;


		public Sample()
		{
			InitializeComponent();
		}

		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Sample));
			this.generate = new System.Windows.Forms.Button();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.start = new System.Windows.Forms.Button();
			this.label5 = new System.Windows.Forms.Label();
			this.speed = new System.Windows.Forms.TextBox();
			this.label6 = new System.Windows.Forms.Label();
			this.exit = new System.Windows.Forms.Button();
			this.diagram = new System.Windows.Forms.Button();
			this.label7 = new System.Windows.Forms.Label();
			this.label8 = new System.Windows.Forms.Label();
			this.label9 = new System.Windows.Forms.Label();
			this.space = new System.Windows.Forms.TextBox();
			this.label10 = new System.Windows.Forms.Label();
			this.label11 = new System.Windows.Forms.Label();
			this.ts_state = new System.Windows.Forms.TextBox();
			this.es_state = new System.Windows.Forms.TextBox();
			this.label12 = new System.Windows.Forms.Label();
			this.about = new System.Windows.Forms.Button();
			this.label13 = new System.Windows.Forms.Label();
			this.label14 = new System.Windows.Forms.Label();
			this.label15 = new System.Windows.Forms.Label();
			this.space_msg = new System.Windows.Forms.Label();
			this.label16 = new System.Windows.Forms.Label();
			this.avaible_space = new System.Windows.Forms.TextBox();
			this.label17 = new System.Windows.Forms.Label();
			this.es_prg = new System.Windows.Forms.ProgressBar();
			this.ts_prg = new System.Windows.Forms.ProgressBar();
			this.label1 = new System.Windows.Forms.Label();
			this.label18 = new System.Windows.Forms.Label();
			this.del_es = new System.Windows.Forms.Button();
			this.del_ts = new System.Windows.Forms.Button();
			this.set_opt = new System.Windows.Forms.Button();
			this.button1 = new System.Windows.Forms.Button();
			this.label19 = new System.Windows.Forms.Label();
			this.el_time = new System.Windows.Forms.TextBox();
			this.label20 = new System.Windows.Forms.Label();
			this.nr_fis = new System.Windows.Forms.NumericUpDown();
			this.fis_size = new System.Windows.Forms.NumericUpDown();
			this.buff = new System.Windows.Forms.NumericUpDown();
			this.label21 = new System.Windows.Forms.Label();
			((System.ComponentModel.ISupportInitialize)(this.nr_fis)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.fis_size)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.buff)).BeginInit();
			this.SuspendLayout();
			// 
			// generate
			// 
			this.generate.BackColor = System.Drawing.SystemColors.Control;
			this.generate.Location = new System.Drawing.Point(32, 16);
			this.generate.Name = "generate";
			this.generate.Size = new System.Drawing.Size(120, 24);
			this.generate.TabIndex = 0;
			this.generate.Text = "Generate random ES";
			this.generate.Click += new System.EventHandler(this.generate_Click);
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(192, 10);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(80, 16);
			this.label2.TabIndex = 2;
			this.label2.Text = "Nr. of files :";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(192, 37);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(64, 32);
			this.label3.TabIndex = 4;
			this.label3.Text = "File Size  ( in MB )";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(18, 179);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(136, 16);
			this.label4.TabIndex = 6;
			this.label4.Text = "Start the TS construction :";
			// 
			// start
			// 
			this.start.BackColor = System.Drawing.SystemColors.Control;
			this.start.Location = new System.Drawing.Point(154, 176);
			this.start.Name = "start";
			this.start.Size = new System.Drawing.Size(72, 20);
			this.start.TabIndex = 7;
			this.start.Text = "START";
			this.start.Click += new System.EventHandler(this.start_Click);
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(16, 282);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(96, 16);
			this.label5.TabIndex = 8;
			this.label5.Text = "Estimated speed :";
			// 
			// speed
			// 
			this.speed.AllowDrop = true;
			this.speed.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.speed.Location = new System.Drawing.Point(112, 280);
			this.speed.MaxLength = 7;
			this.speed.Name = "speed";
			this.speed.ReadOnly = true;
			this.speed.Size = new System.Drawing.Size(112, 20);
			this.speed.TabIndex = 9;
			this.speed.Text = "";
			this.speed.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(224, 284);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(48, 16);
			this.label6.TabIndex = 10;
			this.label6.Text = "Mbit/sec.";
			// 
			// exit
			// 
			this.exit.BackColor = System.Drawing.SystemColors.Control;
			this.exit.Location = new System.Drawing.Point(296, 312);
			this.exit.Name = "exit";
			this.exit.Size = new System.Drawing.Size(72, 24);
			this.exit.TabIndex = 11;
			this.exit.Text = "EXIT";
			this.exit.Click += new System.EventHandler(this.exit_Click);
			// 
			// diagram
			// 
			this.diagram.BackColor = System.Drawing.SystemColors.Control;
			this.diagram.Location = new System.Drawing.Point(280, 280);
			this.diagram.Name = "diagram";
			this.diagram.Size = new System.Drawing.Size(88, 20);
			this.diagram.TabIndex = 12;
			this.diagram.Text = "See Diagram";
			this.diagram.Click += new System.EventHandler(this.diagram_Click);
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(193, 70);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(64, 32);
			this.label7.TabIndex = 13;
			this.label7.Text = "Buffer length";
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(312, 69);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(80, 16);
			this.label8.TabIndex = 15;
			this.label8.Text = "PES / file";
			// 
			// label9
			// 
			this.label9.Location = new System.Drawing.Point(-1, 59);
			this.label9.Name = "label9";
			this.label9.Size = new System.Drawing.Size(96, 16);
			this.label9.TabIndex = 16;
			this.label9.Text = "Space needed :";
			// 
			// space
			// 
			this.space.AllowDrop = true;
			this.space.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.space.Location = new System.Drawing.Point(80, 56);
			this.space.Name = "space";
			this.space.ReadOnly = true;
			this.space.Size = new System.Drawing.Size(48, 20);
			this.space.TabIndex = 17;
			this.space.Text = "";
			this.space.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			// 
			// label10
			// 
			this.label10.Location = new System.Drawing.Point(136, 59);
			this.label10.Name = "label10";
			this.label10.Size = new System.Drawing.Size(48, 16);
			this.label10.TabIndex = 18;
			this.label10.Text = "Mb";
			// 
			// label11
			// 
			this.label11.Location = new System.Drawing.Point(17, 211);
			this.label11.Name = "label11";
			this.label11.Size = new System.Drawing.Size(136, 16);
			this.label11.TabIndex = 19;
			this.label11.Text = "TS state :";
			// 
			// ts_state
			// 
			this.ts_state.AllowDrop = true;
			this.ts_state.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.ts_state.Location = new System.Drawing.Point(72, 208);
			this.ts_state.Name = "ts_state";
			this.ts_state.ReadOnly = true;
			this.ts_state.Size = new System.Drawing.Size(128, 20);
			this.ts_state.TabIndex = 20;
			this.ts_state.Text = "Not started";
			this.ts_state.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			// 
			// es_state
			// 
			this.es_state.AllowDrop = true;
			this.es_state.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.es_state.Location = new System.Drawing.Point(248, 120);
			this.es_state.Name = "es_state";
			this.es_state.ReadOnly = true;
			this.es_state.Size = new System.Drawing.Size(128, 20);
			this.es_state.TabIndex = 22;
			this.es_state.Text = "Not started";
			this.es_state.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			// 
			// label12
			// 
			this.label12.Location = new System.Drawing.Point(192, 122);
			this.label12.Name = "label12";
			this.label12.Size = new System.Drawing.Size(136, 16);
			this.label12.TabIndex = 21;
			this.label12.Text = "ES state :";
			// 
			// about
			// 
			this.about.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(192)), ((System.Byte)(0)));
			this.about.ForeColor = System.Drawing.Color.Blue;
			this.about.Location = new System.Drawing.Point(16, 312);
			this.about.Name = "about";
			this.about.Size = new System.Drawing.Size(72, 24);
			this.about.TabIndex = 23;
			this.about.Text = "ABOUT";
			this.about.Click += new System.EventHandler(this.about_Click);
			// 
			// label13
			// 
			this.label13.Location = new System.Drawing.Point(312, 85);
			this.label13.Name = "label13";
			this.label13.Size = new System.Drawing.Size(48, 16);
			this.label13.TabIndex = 24;
			this.label13.Text = "max. 99";
			// 
			// label14
			// 
			this.label14.Location = new System.Drawing.Point(312, 45);
			this.label14.Name = "label14";
			this.label14.Size = new System.Drawing.Size(48, 16);
			this.label14.TabIndex = 25;
			this.label14.Text = "max. 99";
			// 
			// label15
			// 
			this.label15.Location = new System.Drawing.Point(312, 12);
			this.label15.Name = "label15";
			this.label15.Size = new System.Drawing.Size(48, 16);
			this.label15.TabIndex = 26;
			this.label15.Text = "max. 99";
			// 
			// space_msg
			// 
			this.space_msg.Location = new System.Drawing.Point(56, 112);
			this.space_msg.Name = "space_msg";
			this.space_msg.Size = new System.Drawing.Size(128, 16);
			this.space_msg.TabIndex = 27;
			this.space_msg.Text = "Not tested...";
			// 
			// label16
			// 
			this.label16.Location = new System.Drawing.Point(34, 80);
			this.label16.Name = "label16";
			this.label16.Size = new System.Drawing.Size(96, 16);
			this.label16.TabIndex = 28;
			this.label16.Text = "Avaible :";
			// 
			// avaible_space
			// 
			this.avaible_space.AllowDrop = true;
			this.avaible_space.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.avaible_space.Location = new System.Drawing.Point(80, 80);
			this.avaible_space.Name = "avaible_space";
			this.avaible_space.ReadOnly = true;
			this.avaible_space.Size = new System.Drawing.Size(48, 20);
			this.avaible_space.TabIndex = 29;
			this.avaible_space.Text = "";
			this.avaible_space.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			// 
			// label17
			// 
			this.label17.Location = new System.Drawing.Point(136, 83);
			this.label17.Name = "label17";
			this.label17.Size = new System.Drawing.Size(48, 16);
			this.label17.TabIndex = 30;
			this.label17.Text = "Mb";
			// 
			// es_prg
			// 
			this.es_prg.Location = new System.Drawing.Point(248, 144);
			this.es_prg.Name = "es_prg";
			this.es_prg.Size = new System.Drawing.Size(128, 8);
			this.es_prg.Step = 5;
			this.es_prg.TabIndex = 31;
			// 
			// ts_prg
			// 
			this.ts_prg.Location = new System.Drawing.Point(72, 232);
			this.ts_prg.Name = "ts_prg";
			this.ts_prg.Size = new System.Drawing.Size(128, 8);
			this.ts_prg.Step = 5;
			this.ts_prg.TabIndex = 32;
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(196, 141);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(52, 16);
			this.label1.TabIndex = 33;
			this.label1.Text = "Progres :";
			// 
			// label18
			// 
			this.label18.Location = new System.Drawing.Point(21, 228);
			this.label18.Name = "label18";
			this.label18.Size = new System.Drawing.Size(52, 16);
			this.label18.TabIndex = 34;
			this.label18.Text = "Progres :";
			// 
			// del_es
			// 
			this.del_es.BackColor = System.Drawing.SystemColors.Control;
			this.del_es.Location = new System.Drawing.Point(40, 136);
			this.del_es.Name = "del_es";
			this.del_es.Size = new System.Drawing.Size(104, 24);
			this.del_es.TabIndex = 35;
			this.del_es.Text = "Delete all ES files";
			this.del_es.Click += new System.EventHandler(this.del_es_Click);
			// 
			// del_ts
			// 
			this.del_ts.BackColor = System.Drawing.SystemColors.Control;
			this.del_ts.Location = new System.Drawing.Point(232, 215);
			this.del_ts.Name = "del_ts";
			this.del_ts.Size = new System.Drawing.Size(104, 24);
			this.del_ts.TabIndex = 36;
			this.del_ts.Text = "Delete the TS file";
			this.del_ts.Click += new System.EventHandler(this.del_ts_Click);
			// 
			// set_opt
			// 
			this.set_opt.BackColor = System.Drawing.SystemColors.Control;
			this.set_opt.Location = new System.Drawing.Point(248, 174);
			this.set_opt.Name = "set_opt";
			this.set_opt.Size = new System.Drawing.Size(88, 24);
			this.set_opt.TabIndex = 37;
			this.set_opt.Text = "Set TS options";
			this.set_opt.Click += new System.EventHandler(this.set_opt_Click);
			// 
			// button1
			// 
			this.button1.BackColor = System.Drawing.SystemColors.Control;
			this.button1.Location = new System.Drawing.Point(144, 312);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(112, 24);
			this.button1.TabIndex = 38;
			this.button1.Text = "Legend of result file";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// label19
			// 
			this.label19.Location = new System.Drawing.Point(224, 260);
			this.label19.Name = "label19";
			this.label19.Size = new System.Drawing.Size(80, 16);
			this.label19.TabIndex = 41;
			this.label19.Text = "seconds";
			// 
			// el_time
			// 
			this.el_time.AllowDrop = true;
			this.el_time.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.el_time.Location = new System.Drawing.Point(112, 256);
			this.el_time.Name = "el_time";
			this.el_time.ReadOnly = true;
			this.el_time.Size = new System.Drawing.Size(112, 20);
			this.el_time.TabIndex = 40;
			this.el_time.Text = "";
			this.el_time.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			// 
			// label20
			// 
			this.label20.Location = new System.Drawing.Point(34, 261);
			this.label20.Name = "label20";
			this.label20.Size = new System.Drawing.Size(96, 16);
			this.label20.TabIndex = 39;
			this.label20.Text = "Elapsed time :";
			// 
			// nr_fis
			// 
			this.nr_fis.Location = new System.Drawing.Point(256, 8);
			this.nr_fis.Maximum = new System.Decimal(new int[] {
																   99,
																   0,
																   0,
																   0});
			this.nr_fis.Minimum = new System.Decimal(new int[] {
																   1,
																   0,
																   0,
																   0});
			this.nr_fis.Name = "nr_fis";
			this.nr_fis.Size = new System.Drawing.Size(48, 20);
			this.nr_fis.TabIndex = 45;
			this.nr_fis.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			this.nr_fis.Value = new System.Decimal(new int[] {
																 10,
																 0,
																 0,
																 0});
			this.nr_fis.TextChanged += new System.EventHandler(this.t_calc);
			this.nr_fis.ValueChanged += new System.EventHandler(this.recalc);
			// 
			// fis_size
			// 
			this.fis_size.Location = new System.Drawing.Point(256, 40);
			this.fis_size.Maximum = new System.Decimal(new int[] {
																	 99,
																	 0,
																	 0,
																	 0});
			this.fis_size.Minimum = new System.Decimal(new int[] {
																	 1,
																	 0,
																	 0,
																	 0});
			this.fis_size.Name = "fis_size";
			this.fis_size.Size = new System.Drawing.Size(48, 20);
			this.fis_size.TabIndex = 46;
			this.fis_size.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			this.fis_size.Value = new System.Decimal(new int[] {
																   1,
																   0,
																   0,
																   0});
			this.fis_size.TextChanged += new System.EventHandler(this.t_calc);
			this.fis_size.ValueChanged += new System.EventHandler(this.recalc);
			// 
			// buff
			// 
			this.buff.Location = new System.Drawing.Point(256, 72);
			this.buff.Maximum = new System.Decimal(new int[] {
																 99,
																 0,
																 0,
																 0});
			this.buff.Minimum = new System.Decimal(new int[] {
																 1,
																 0,
																 0,
																 0});
			this.buff.Name = "buff";
			this.buff.Size = new System.Drawing.Size(48, 20);
			this.buff.TabIndex = 47;
			this.buff.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			this.buff.Value = new System.Decimal(new int[] {
															   10,
															   0,
															   0,
															   0});
			// 
			// label21
			// 
			this.label21.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic), System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label21.ForeColor = System.Drawing.Color.Aqua;
			this.label21.Location = new System.Drawing.Point(96, 341);
			this.label21.Name = "label21";
			this.label21.Size = new System.Drawing.Size(200, 16);
			this.label21.TabIndex = 48;
			this.label21.Text = "March 2004  -  Program   by    Angel";
			// 
			// Sample
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(192)), ((System.Byte)(192)));
			this.ClientSize = new System.Drawing.Size(384, 358);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.label21,
																		  this.buff,
																		  this.fis_size,
																		  this.nr_fis,
																		  this.label19,
																		  this.el_time,
																		  this.label20,
																		  this.button1,
																		  this.set_opt,
																		  this.del_ts,
																		  this.del_es,
																		  this.label18,
																		  this.label1,
																		  this.ts_prg,
																		  this.es_prg,
																		  this.label17,
																		  this.avaible_space,
																		  this.label16,
																		  this.space_msg,
																		  this.label15,
																		  this.label14,
																		  this.label13,
																		  this.about,
																		  this.es_state,
																		  this.label12,
																		  this.ts_state,
																		  this.label11,
																		  this.label10,
																		  this.space,
																		  this.label9,
																		  this.label8,
																		  this.label7,
																		  this.diagram,
																		  this.exit,
																		  this.label6,
																		  this.speed,
																		  this.label5,
																		  this.start,
																		  this.label4,
																		  this.label3,
																		  this.label2,
																		  this.generate});
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MaximumSize = new System.Drawing.Size(392, 392);
			this.MinimumSize = new System.Drawing.Size(392, 392);
			this.Name = "Sample";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Sample speed test for TS construction";
			this.Load += new System.EventHandler(this.Sample_Load);
			((System.ComponentModel.ISupportInitialize)(this.nr_fis)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.fis_size)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.buff)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion
		[STAThread]
		static void Main() 
		{
			Application.Run(new Sample());
		}

		private void exit_Click(object sender, System.EventArgs e)
		{
			Dispose(true);
		}

		private void about_Click(object sender, System.EventArgs e)
		{
			my_about.Show();
		}

		public long free_space()
		{ 
			string root=System.IO.Directory.GetDirectoryRoot(System.IO.Directory.GetCurrentDirectory());
			root=root.Remove(root.Length-1,1);
			string path="Win32_LogicalDisk.DeviceID=\""+root+"\"";
			ManagementObject disk = new ManagementObject(path);
			PropertyData d = disk.Properties["FreeSpace"];			
			return long.Parse(d.Value.ToString())/(1024*1024);
		}

		public void calc_space()
		{int sp,mult=1;
		long free;
			if (my_options.ret_carrier()) mult=2;
			sp=Convert.ToInt16(mult*nr_fis.Value*fis_size.Value);
			space.Text=sp.ToString();
			free=free_space();
			avaible_space.Text=free.ToString();
			if (sp>=free) {
				space_msg.Text="Not enough free space";
				space_msg.ForeColor=Color.Red;}
			else {
				space_msg.Text="Free space OK";
				space_msg.ForeColor=Color.Blue;
				generate.Enabled=true;}
			if((sp==0)||(sp>=free))	generate.Enabled=false;
			env_set();
		}

		private void Sample_Load(object sender, System.EventArgs e)
		{my_options=new options(this);
			calc_space();
			
		}

		private void recalc(object sender, System.EventArgs e)
		{
			calc_space();
		}

		public void create_es(int nr,int size)
		{	int i,j;
			string[] f_name=new string[nr];
			byte[][] buf=new byte[nr][];
			FileStream[] file=new FileStream[nr];
			
			for(i=0;i<nr;i++) 
			{
				f_name[i]="ES_sample_"+i.ToString()+".es";
				file[i]=new FileStream(f_name[i],FileMode.Create);
				buf[i]=new byte[1024];
				for(j=0;j<1024;j++) buf[i][j]=Convert.ToByte((65+i)%256);
			}
			es_state.Text="Working...";
			this.Refresh();
			for(i=0;i<1024*size;i++) 
			{
				for(j=0;j<nr;j++)
				{
					file[j].Write(buf[j],0,1024);
				}
				es_prg.Value=Convert.ToInt16((100*i)/(size*1024));
			}

			for(i=0;i<nr;i++) file[i].Close();
		}

		private void generate_Click(object sender, System.EventArgs e)
		{
			int F_nr=int.Parse(nr_fis.Text); //Nr. of files
			int F_size=int.Parse(fis_size.Text); //Size of each file
					
			create_es(F_nr,F_size);
			es_state.Text="Done...";
			start.Enabled=true;
			calc_space();
		}

		private void env_set()
		{int nr_f=Convert.ToInt32(nr_fis.Value);
		 int f_s=Convert.ToInt32(fis_size.Value);
		 int i;
		 bool st_ok=true;
		 string[] files=Directory.GetFiles(".","*.es");
			FileInfo[] F = new FileInfo[files.Length];
			for(i=0;i<files.Length;i++)
							F[i]=new FileInfo(files[i]);
		 if(nr_f>files.Length) st_ok=false;
		 else 
		 	 for(i=0;i<nr_f;i++)
				 if (F[i].Length/(1024*1024)!=f_s) st_ok=false;
		 start.Enabled=st_ok;
		}

		private void del_es_Click(object sender, System.EventArgs e)
		{
			string[] files=Directory.GetFiles(".","*.es");
			FileInfo[] F = new FileInfo[files.Length];
			for(int i=0;i<files.Length;i++)
			{
				F[i]=new FileInfo(files[i]);
				F[i].Delete();
			}
			calc_space();
			es_state.Text="Not started...";
			start.Enabled=false;
			es_prg.Value=0;
			this.Refresh();
		}

		private void del_ts_Click(object sender, System.EventArgs e)
		{
			FileInfo F=new FileInfo("./result.ts");
			if (F.Exists) F.Delete();
			calc_space();
		}

		private void set_opt_Click(object sender, System.EventArgs e)
		{
			my_options.Show();
		}

		double measure_speed(int time)
		{double sp,load,tt;long size;
			size=TS_packs*188;
			load=size;
			load=load/(1024*1024);
			tt=time;
			tt=tt/1000000;
			sp=load/tt*8;
			return sp;
		}

		void calc_est_TS_packs(int pes_len,int h_len)
		{
			int nr_f,f_s;
			long data,nr_pes;
			nr_f=int.Parse(nr_fis.Text);
			f_s=int.Parse(fis_size.Text);
			
			data=nr_f*f_s*1024*1024;
			nr_pes=data/(pes_len-3-h_len);
			data=data+nr_pes*(9+h_len);
			est_TS_packs=data/184;
			est_TS_packs=est_TS_packs+10*est_TS_packs/100;
		}

		private void start_Click(object sender, System.EventArgs e)
		{int time;
			double tt;
		ts_prg.Value=0;
		ts_state.Text="Working...";
		this.Refresh();
		int f,b,h,p;
			bool c;
			f=int.Parse(nr_fis.Text);
			b=int.Parse(buff.Text);
			h=my_options.get_HL();
			p=my_options.get_PL();
			c=my_options.ret_carrier();
		calc_est_TS_packs(p,h);
		my_solver.set_solver(f,b,h,p,c);
		time=my_solver.simulation(this);
			tt=time;
			tt=tt/1000000;
			el_time.Text=tt.ToString();
		speed.Text=measure_speed(time).ToString().Substring(0,7);
		ts_prg.Value=100;
		ts_state.Text="Ready ! ";
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			my_legend.Show();
		}

		private void diagram_Click(object sender, System.EventArgs e)
		{
			my_diagram.set_draw(my_solver.mes,my_solver.nr_mes);
			my_diagram.Show();
		}

		private void t_calc(object sender, System.EventArgs e)
		{
			if(my_options!=null) calc_space();
		}



	
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

ro_angel_bv
Web Developer
Malaysia Malaysia
Dumitru Bogdan - alias Angel
 
Born 1980 , Brasov , Romania
 
Final year student at Transilvania University of Brasov , Faculty of Electrical Engineering & Computer Science , Department of Electronics & Computers
 
Programming : Visual C++ , Visual Fox Pro , Assembler & later , C#
 
Motto : "Nothing Last Forever" , and software is no exception

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 14 Apr 2004
Article Copyright 2004 by ro_angel_bv
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid