Browse files

More work! Semi-functional build...

  • Loading branch information...
1 parent c23ab43 commit 6c921024e6a2bbf47a4373f77d16fa5c5faba7ac @Valien committed Oct 16, 2012
View
48 CSV_Splitter_WF/WindowsFormsApplication1/CSVSplitter.csproj
@@ -11,6 +11,22 @@
<AssemblyName>CSVSplitter</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
+ <IsWebBootstrapper>false</IsWebBootstrapper>
+ <PublishUrl>C:\temp\csv\</PublishUrl>
+ <Install>true</Install>
+ <InstallFrom>Disk</InstallFrom>
+ <UpdateEnabled>false</UpdateEnabled>
+ <UpdateMode>Foreground</UpdateMode>
+ <UpdateInterval>7</UpdateInterval>
+ <UpdateIntervalUnits>Days</UpdateIntervalUnits>
+ <UpdatePeriodically>false</UpdatePeriodically>
+ <UpdateRequired>false</UpdateRequired>
+ <MapFileExtensions>true</MapFileExtensions>
+ <ApplicationRevision>1</ApplicationRevision>
+ <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
+ <UseApplicationTrust>false</UseApplicationTrust>
+ <PublishWizardCompleted>true</PublishWizardCompleted>
+ <BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -31,6 +47,18 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
+ <PropertyGroup>
+ <ManifestCertificateThumbprint>672677597D115547AE2915D0F6B05ABE2ED0F0DF</ManifestCertificateThumbprint>
+ </PropertyGroup>
+ <PropertyGroup>
+ <ManifestKeyFile>CSVSplitter_TemporaryKey.pfx</ManifestKeyFile>
+ </PropertyGroup>
+ <PropertyGroup>
+ <GenerateManifests>true</GenerateManifests>
+ </PropertyGroup>
+ <PropertyGroup>
+ <SignManifests>true</SignManifests>
+ </PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
@@ -52,7 +80,7 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="SplitCSV.cs" />
+ <Compile Include="SplitClass.cs" />
<EmbeddedResource Include="CSVSplitterForm.resx">
<DependentUpon>CSVSplitterForm.cs</DependentUpon>
</EmbeddedResource>
@@ -66,6 +94,7 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
+ <None Include="CSVSplitter_TemporaryKey.pfx" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
@@ -79,6 +108,23 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
+ <ItemGroup>
+ <BootstrapperPackage Include=".NETFramework,Version=v4.5">
+ <Visible>False</Visible>
+ <ProductName>Microsoft .NET Framework 4.5 %28x86 and x64%29</ProductName>
+ <Install>true</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
+ <Install>false</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1</ProductName>
+ <Install>false</Install>
+ </BootstrapperPackage>
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
View
10 CSV_Splitter_WF/WindowsFormsApplication1/CSVSplitterForm.Designer.cs
@@ -37,6 +37,7 @@ private void InitializeComponent()
this.browse_Button = new System.Windows.Forms.Button();
this.splitNow_Button = new System.Windows.Forms.Button();
this.cancel_Button = new System.Windows.Forms.Button();
+ this.lblStatus = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.nol_NumericUpDown)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.maxPieces_NumericUpDown)).BeginInit();
this.SuspendLayout();
@@ -139,11 +140,19 @@ private void InitializeComponent()
this.cancel_Button.UseVisualStyleBackColor = true;
this.cancel_Button.Click += new System.EventHandler(this.cancel_Button_Click);
//
+ // lblStatus
+ //
+ this.lblStatus.Location = new System.Drawing.Point(66, 129);
+ this.lblStatus.Name = "lblStatus";
+ this.lblStatus.Size = new System.Drawing.Size(300, 16);
+ this.lblStatus.TabIndex = 9;
+ //
// CSVSplitterForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(484, 162);
+ this.Controls.Add(this.lblStatus);
this.Controls.Add(this.cancel_Button);
this.Controls.Add(this.splitNow_Button);
this.Controls.Add(this.browse_Button);
@@ -173,6 +182,7 @@ private void InitializeComponent()
private System.Windows.Forms.Button splitNow_Button;
private System.Windows.Forms.Button cancel_Button;
internal System.Windows.Forms.Button browse_Button;
+ private System.Windows.Forms.Label lblStatus;
}
}
View
176 CSV_Splitter_WF/WindowsFormsApplication1/CSVSplitterForm.cs
@@ -9,6 +9,7 @@
using System.Windows.Forms;
using System.IO;
+
namespace CSVSplitter
{
public partial class CSVSplitterForm : Form
@@ -18,27 +19,194 @@ public CSVSplitterForm()
InitializeComponent();
}
+ public delegate void UpdateProgressSub(int CurrentLine);
private Boolean _IsAbort;
OpenFileDialog OFD = new OpenFileDialog();
+ private void SplitCSV(string FilePath, int LineCount, int MaxOutputFile, Action<int> UpdateProgress, bool IsAbort)
+ {
+ // Validate first
+ if (LineCount < 100) throw new Exception("Number of lines must be more than 100.");
+
+ // Open the CSV file for reading
+ StreamReader Reader = new StreamReader(FilePath);
+
+ // Create the output directory
+ string OutputFolder = FilePath + "_Pieces";
+ if (Directory.Exists(FilePath) == false)
+ {
+ Directory.CreateDirectory(OutputFolder);
+ }
+
+ // Read the CSV column's header
+ string strHeader = Reader.ReadLine();
+
+ // Start splitting!
+ int FileIndex = 0;
+
+ while (true)
+ {
+ // Update progress
+ FileIndex += 1;
+ if ((UpdateProgress != null))
+ {
+ UpdateProgress.Invoke((FileIndex - 1) * LineCount);
+ }
+
+ // Check if the number of split files do not exceed the limit
+ if ((MaxOutputFile < FileIndex) & (MaxOutputFile > 0))
+ {
+ break;
+ }
+
+ // Create new file to store a piece of the CSV file
+ string PiecePath = OutputFolder + "\\" + Path.GetFileNameWithoutExtension(FilePath) + "_" + FileIndex + Path.GetExtension(FilePath);
+ StreamWriter Writer = new StreamWriter(PiecePath, false);
+ Writer.AutoFlush = false;
+ Writer.WriteLine(strHeader);
+
+ // Read and write precise number of rows
+ for (int i = 0; i < LineCount; i++)
+ {
+ string s = Reader.ReadLine();
+ if ((s != null) & (_IsAbort = false))
+ {
+ Writer.WriteLine(s);
+ }
+ else
+ {
+ Writer.Flush();
+ Writer.Close();
+ break;
+ }
+ }
+
+
+ }
+ // flush and close the split file
+ Writer.Flush();
+ Writer.Close();
+ //do
+ //{
+ // // Update progress
+ // FileIndex += 1;
+ // if ((UpdateProgress != null))
+ // {
+ // UpdateProgress.Invoke((FileIndex - 1) * LineCount);
+ // }
+
+ // // Check if the number of split files do not exceed the limit
+ // if ((MaxOutputFile < FileIndex) & (MaxOutputFile > 0))
+ // {
+ // break;
+ // }
+
+ // // Create new file to store a piece of the CSV file
+ // string PiecePath = OutputFolder + "\\" + Path.GetFileNameWithoutExtension(FilePath) + "_" + FileIndex + Path.GetExtension(FilePath);
+ // StreamWriter Writer = new StreamWriter(PiecePath, false);
+ // Writer.AutoFlush = false;
+ // Writer.WriteLine(strHeader);
+
+ // // Read and write precise number of rows
+ // for (int i = 0; i < LineCount; i++)
+ // {
+ // string s = Reader.ReadLine();
+ // if ((s != null) & (_IsAbort = false))
+ // {
+ // Writer.WriteLine(s);
+ // }
+ // else
+ // {
+ // Writer.Flush();
+ // Writer.Close();
+ // break;
+ // }
+ // }
+
+ // // flush and close the split file
+ // //Writer.Flush();
+ // //Writer.Close();
+
+ //} while (true);
+
+ Reader.Close();
+ }
+
+ //private void SplitCSV(string p1, decimal p2, decimal p3, Action<int> UpdateProgress, bool _IsAbort)
+ //{
+ // throw new NotImplementedException();
+ //}
+
+
private void browse_Button_Click(object sender, EventArgs e)
{
-
- if (OFD.ShowDialog() == DialogResult.OK) {
+
+ if (OFD.ShowDialog() == DialogResult.OK)
+ {
csv_TextBox.Text = OFD.FileName.ToString();
}
}
private void cancel_Button_Click(object sender, EventArgs e)
{
+ _IsAbort = true;
this.Close();
}
private void splitNow_Button_Click(object sender, EventArgs e)
{
-
+ System.Threading.Thread th = new System.Threading.Thread(SplitIt);
+ th.Start();
+ }
+
+ public void SplitIt()
+ {
+
+ splitNow_Button.Enabled = false;
+ cancel_Button.Enabled = true;
+
+ // Kick it off!
+ try
+ {
+ //Split SplitCSV = new Split();
+
+ //SplitCSV(csv_TextBox.Text, nol_NumericUpDown.Value, maxPieces_NumericUpDown.Value, UpdateProgress, _IsAbort);
+
+ SplitCSV(csv_TextBox.Text, (int)nol_NumericUpDown.Value, (int)maxPieces_NumericUpDown.Value, UpdateProgress, _IsAbort);
+
+
+ if (!_IsAbort)
+ {
+ MessageBox.Show("Completed Successfully!", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+ else
+ {
+ _IsAbort = false;
+ MessageBox.Show("Split process aborted by user.", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
+ }
+
+ } // end try
+ catch (Exception e)
+ {
+ MessageBox.Show("Unable to split the CSV file. Reason: " + e.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ }
+
+ finally
+ {
+ splitNow_Button.Enabled = true;
+ cancel_Button.Enabled = false;
+ }
+
+
+ }
+
+
+
+ public void UpdateProgress(int CurrentLine)
+ {
+ lblStatus.Text = "Approximately " + CurrentLine.ToString() + " lines have been split.";
}
-
+
}
}
View
BIN CSV_Splitter_WF/WindowsFormsApplication1/CSVSplitter_TemporaryKey.pfx
Binary file not shown.
View
11 ...r_WF/WindowsFormsApplication1/SplitCSV.cs → ...WF/WindowsFormsApplication1/SplitClass.cs
@@ -6,14 +6,13 @@
namespace CSVSplitter
{
- class SplitCSV
+ class Split
{
- // Validate file first
+ //public void SplitCSV(); //(string FilePath, int LineCount, int MaxOutputFile, UpdateProgressSub Status, ref bool IsAbort)
+ // Validate file first
+ //if
}
- class SplitIt
- {
- //split info
- }
}
+

0 comments on commit 6c92102

Please sign in to comment.