protected override void OnDoWork(DoWorkEventArgs e)
        {  
            ReportProgress(0, SortingState.Start);

            TableController tableController = new TableController();
            AudioFileInfo audioFile  = new AudioFileInfo();
            
            tableController.InsertInitialize();

            while (FileListEnumerator.MoveNext())
            { 
                if (CancellationPending)
                {
                    e.Cancel = true;
                    break;
                } 
                
                FileInfo currentFile = new FileInfo(FileListEnumerator.Key.ToString());

                audioFile.GetInfo(currentFile);
                tableController.Insert(currentFile, audioFile);
            }

            ReportProgress(100, "Done!");
            e.Result = SortingState.Completed;
        }
        public void Insert(FileInfo fileInfo, AudioFileInfo audioFileInfo)
        {
            Database database = (new DbFactory()).CreateDatabase();

            string spName = ((new Resources()).CreateInsertSPList())[TableList.Track].ToString();

            ExecuteStoredProcWithParam executeStoredProcWithParam = 
                    new ExecuteStoredProcWithParam(database, spName);

            executeStoredProcWithParam.AddInParameter(database,
                InsertValueByTableName(fileInfo.DirectoryName, TableList.Path),
                @"PathID");

            executeStoredProcWithParam.AddInParameter(database,
                InsertValueByTableName(audioFileInfo.Artist, TableList.Artist),
                @"ArtistID");

            executeStoredProcWithParam.AddInParameter(database,
                InsertValueByTableName(audioFileInfo.Album, TableList.Album),
                @"AlbumID");

            executeStoredProcWithParam.AddInParameter(database,
                InsertValueByTableName(audioFileInfo.Genre, TableList.Genre),
                @"GenreID");

            executeStoredProcWithParam.AddInParameter(database,
                InsertValueByTableName(audioFileInfo.Bitrate, TableList.Bitrate),
                @"BitrateID");

            executeStoredProcWithParam.AddInParameter(database,
              audioFileInfo.Title,
              @"TrackTitle");

            executeStoredProcWithParam.AddInParameter(database,
              fileInfo.Name,
              @"FileName");

            executeStoredProcWithParam.AddInParameter(database,
              fileInfo.Length,
              @"FileSize");

            string newName = string.Empty;

            if (string.IsNullOrEmpty(audioFileInfo.Artist) && string.IsNullOrEmpty(audioFileInfo.Title))
            {
                newName = fileInfo.Name;
            }
            else
            {
                newName = audioFileInfo.Artist + "_" + audioFileInfo.Title;
            }

            executeStoredProcWithParam.AddInParameter(database,
              newName,
              @"NewFileName");

            executeStoredProcWithParam.AddOutParameter(database, @"return_value");
            executeStoredProcWithParam.ExecuteSpSetResultValue(database, @"return_value");

        }
        public void Insert(FileInfo fileInfo, AudioFileInfo audioFileInfo)
        {
            using (SqlConnection connection = DBConnectionFactory.GetConnection())
            {
                connection.Open();

                using (SqlCommand insertCommand = new SqlCommand(@"TrackInsert_SP", connection))
                {
                    insertCommand.CommandType = CommandType.StoredProcedure;

                    #region satelite table values

                    int result1 = InsertValueByTableName(fileInfo.DirectoryName, TableList.Path);
                    SqlParameter PathID = new SqlParameter("@PathID", result1);
                    insertCommand.Parameters.Add(PathID);
                    PathID.Direction = ParameterDirection.Input;

                    int result2 = InsertValueByTableName(audioFileInfo.Artist, TableList.Artist);
                    SqlParameter ArtistID = new SqlParameter("@ArtistID", result2);
                    insertCommand.Parameters.Add(ArtistID);
                    ArtistID.Direction = ParameterDirection.Input;

                    int result3 = InsertValueByTableName(audioFileInfo.Album, TableList.Album);
                    SqlParameter AlbumID = new SqlParameter("@AlbumID", result3);
                    insertCommand.Parameters.Add(AlbumID);
                    AlbumID.Direction = ParameterDirection.Input;

                    int result4 = InsertValueByTableName(audioFileInfo.Genre, TableList.Genre);
                    SqlParameter GenreID = new SqlParameter("@GenreID", result4);
                    insertCommand.Parameters.Add(GenreID);
                    GenreID.Direction = ParameterDirection.Input;

                    int result5 = InsertValueByTableName(audioFileInfo.Bitrate, TableList.Bitrate);
                    SqlParameter BitrateID = new SqlParameter("@BitrateID", result5);
                    insertCommand.Parameters.Add(BitrateID);
                    BitrateID.Direction = ParameterDirection.Input;

                    #endregion

                    SqlParameter TrackTitle = new SqlParameter("@TrackTitle", audioFileInfo.Title);
                    insertCommand.Parameters.Add(TrackTitle);
                    TrackTitle.Direction = ParameterDirection.Input;

                    SqlParameter FileName = new SqlParameter("@FileName", fileInfo.Name);
                    insertCommand.Parameters.Add(FileName);
                    FileName.Direction = ParameterDirection.Input;

                    SqlParameter FileSize = new SqlParameter("@FileSize", fileInfo.Length);
                    insertCommand.Parameters.Add(FileSize);
                    FileSize.Direction = ParameterDirection.Input;

                    string newName = audioFileInfo.Artist + "_" + audioFileInfo.Title;
                    SqlParameter NewFileName = new SqlParameter("@NewFileName", newName);
                    insertCommand.Parameters.Add(NewFileName);
                    NewFileName.Direction = ParameterDirection.Input;

                    int affectedRows = (int)insertCommand.ExecuteNonQuery();
                }
            }
        }