Beispiel #1
0
        private void AnalyseButton_Click(object sender, EventArgs e)
        {
            try
            {
                listView1.Items.Clear(); //
                listExtension.Clear();   //isprazni listu

                DirectoryName = DirectoryBox.Text;
                if (DirectoryName == "")
                {
                    throw new DirectoryNotFoundException("Enter directory path!");
                }

                //pregledavam checkirane ekstenzije
                if (ExtensionC.Checked)
                {
                    listExtension.Add(ExtensionC.Text);
                }
                if (ExtensionH.Checked)
                {
                    listExtension.Add(ExtensionH.Text);
                }
                if (ExtensionCPP.Checked)
                {
                    listExtension.Add(ExtensionCPP.Text);
                }
                if (ExtensionJAVA.Checked)
                {
                    listExtension.Add(ExtensionJAVA.Text);
                }
                if (ExtensionCS.Checked)
                {
                    listExtension.Add(ExtensionCS.Text);
                }

                EnumerateFiles EnumFiles = new EnumerateFiles(DirectoryName);
                EnumFiles.Enumerate();

                //ispis (broj datoteka, direktorija)
                Directories.Text = (EnumFiles.Directories).ToString();
                Files.Text       = (EnumFiles.Files).ToString();


                FileCodeInfo Info;

                al.Clear();
                //BindingList<FileCodeInfo> bindList= new BindingList<FileCodeInfo>();

                for (int i = 0; i < EnumFiles.Duljina; i++)
                {
                    if (listExtension.Contains(((FileInfo)EnumFiles[i]).Extension))
                    {
                        Data1 data = new Data1((FileInfo)EnumFiles[i]);
                        Info = FileAnalyzer.AnalyseFile(data);

                        al.Add(Info);
                        //bindList.Add(Info);
                        //Binding_source.Add(Info);
                        //ResultRow = new string[] { Info.FileName, ((FileInfo)EnumFiles[i]).Extension, (Info.NumberOfLines).ToString(), (Info.NumberOfEmptyLines).ToString(), (Info.NumberOfComments).ToString(), (Info.NumberOfMixedLines).ToString() };
                        //ResultGrid.Rows.Add(ResultRow);

                        data.Dispose();
                    }
                }

                for (int j = 0; j < al.Count; j++)
                {
                    ListViewItem listItem = new ListViewItem(al[j].FileName);
                    listItem.SubItems.Add(al[j].Extension);
                    listItem.SubItems.Add((al[j].NumberOfLines).ToString());
                    listItem.SubItems.Add((al[j].NumberOfEmptyLines).ToString());
                    listItem.SubItems.Add((al[j].NumberOfComments).ToString());
                    listItem.SubItems.Add((al[j].NumberOfMixedLines).ToString());
                    listView1.Items.Add(listItem);
                }
            }
            catch (Exception ex)
            {
                //alert
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #2
0
        private void AnalyseButton_Click(object sender, EventArgs e)
        {
            try
            {
                ResultGrid.RowCount = 1; //prebriše dosadašnje rezultate (ako ih je bilo)
                listExtension.Clear();   //isprazni listu

                DirectoryName = DirectoryBox.Text;
                if (DirectoryName == "")
                {
                    throw new DirectoryNotFoundException("Enter directory path!");
                }

                //pregledavam checkirane ekstenzije
                if (ExtensionC.Checked)
                {
                    listExtension.Add(ExtensionC.Text);
                }
                if (ExtensionH.Checked)
                {
                    listExtension.Add(ExtensionH.Text);
                }
                if (ExtensionCPP.Checked)
                {
                    listExtension.Add(ExtensionCPP.Text);
                }
                if (ExtensionJAVA.Checked)
                {
                    listExtension.Add(ExtensionJAVA.Text);
                }
                if (ExtensionCS.Checked)
                {
                    listExtension.Add(ExtensionCS.Text);
                }

                EnumerateFiles EnumFiles = new EnumerateFiles(DirectoryName);
                EnumFiles.Enumerate();

                //ispis (broj datoteka, direktorija)
                Directories.Text = (EnumFiles.Directories).ToString();
                Files.Text       = (EnumFiles.Files).ToString();

                //ispis rezultata za pojedinu datoteku
                FileCodeInfo Info;
                string[]     ResultRow;
                for (int i = 0; i < EnumFiles.Duljina; i++)
                {
                    if (listExtension.Contains(((FileInfo)EnumFiles[i]).Extension))
                    {
                        Data1 data = new Data1((FileInfo)EnumFiles[i]);
                        Info      = FileAnalyzer.AnalyseFile(data);
                        ResultRow = new string[] { Info.FileName, ((FileInfo)EnumFiles[i]).Extension, (Info.NumberOfLines).ToString(), (Info.NumberOfEmptyLines).ToString(), (Info.NumberOfComments).ToString(), (Info.NumberOfMixedLines).ToString() };
                        ResultGrid.Rows.Add(ResultRow);
                        data.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                //alert
                MessageBox.Show(ex.Message);
            }
        }