44using System . Diagnostics ;
55using System . IO ;
66using System . Linq ;
7+ using System . Runtime . InteropServices ;
78using System . Text ;
89using System . Threading ;
910using System . Threading . Tasks ;
@@ -68,10 +69,6 @@ public EditProgram() {
6869 /// <param name="index">The index where the value is in the array.</param>
6970 /// <param name="dataValues">The array of data.</param>
7071 private void AddRow ( Table table , int rowsAddedValue , string value , int index , List < string > dataValues ) {
71- //if (value == "") {
72- // return;
73- //}
74-
7572 table . RowGroups [ 0 ] . Rows . Add ( new TableRow ( ) ) ;
7673 TableRow newRow = null ;
7774
@@ -336,12 +333,102 @@ private void CalculatePercentage() {
336333 /// Updates values from editing file.
337334 /// </summary>
338335 private void Read ( ) {
339- while ( Passthrough . IsAdding ) {
336+ while ( true ) {
340337 Thread . Sleep ( 1000 ) ;
341-
342- if ( Passthrough . IsDeleting ) {
338+ if ( Passthrough . IsAdding ) {
343339 Passthrough . IsAdding = false ;
340+ string json = File . ReadAllText ( editingFile ) ;
341+ MainTableManifest . Rootobject values = JsonConvert . DeserializeObject < MainTableManifest . Rootobject > ( json ) ;
342+
343+ // Set values for saving feature to rewrite
344+ projectTitle = values . Title ;
345+ errors = values . Errors . ToList ( ) ;
346+ errorsData = values . ErrorsData . ToList ( ) ;
347+ features = values . Features . ToList ( ) ;
348+ featuresData = values . FeaturesData . ToList ( ) ;
349+ comments = values . Comments . ToList ( ) ;
350+ commentsData = values . CommentsData . ToList ( ) ;
351+ duration = values . Duration ;
352+ percentComplete = values . Percent ;
353+
354+ for ( int i = 0 ; i < errors . Count ; i ++ ) {
355+ if ( errors [ i ] == "" ) {
356+ errors . RemoveAt ( i ) ;
357+ }
358+ }
359+ for ( int i = 0 ; i < features . Count ; i ++ ) {
360+ if ( features [ i ] == "" ) {
361+ features . RemoveAt ( i ) ;
362+ }
363+ }
364+ for ( int i = 0 ; i < comments . Count ; i ++ ) {
365+ if ( comments [ i ] == "" ) {
366+ comments . RemoveAt ( i ) ;
367+ }
368+ }
344369
370+ CalculatePercentage ( ) ;
371+
372+ this . Dispatcher . Invoke ( ( ) =>
373+ {
374+ if ( switchLabels . SelectedIndex == 0 ) { // Errors
375+ errorsRowsAdded = 0 ;
376+ try {
377+ for ( int i = 0 ; i < errors . Count ; i ++ ) {
378+ errorTable . RowGroups [ 0 ] . Rows [ i ] . Cells . RemoveRange ( 0 , 1 ) ;
379+ }
380+ }
381+ catch ( ArgumentOutOfRangeException ) {
382+ // They just added a new value
383+ SelectionChange ( 0 , 0 , errorsRowsAdded , errorTable , errorsData ) ;
384+ }
385+ int index = 0 ;
386+ foreach ( string value in errors ) {
387+ AddRow ( errorTable , 0 , value , index , errorsData ) ;
388+ index ++ ;
389+ }
390+ SelectionChange ( rowSelectionID , rowSelectionID , errorsRowsAdded , errorTable , errorsData ) ;
391+ }
392+ else if ( switchLabels . SelectedIndex == 1 ) { // Features
393+ featuresRowsAdded = 0 ;
394+ try {
395+ for ( int i = 0 ; i < features . Count ; i ++ ) {
396+ featureTable . RowGroups [ 0 ] . Rows [ i ] . Cells . RemoveRange ( 0 , 1 ) ;
397+ }
398+ }
399+ catch ( ArgumentOutOfRangeException ) {
400+ // They just added a new value
401+ SelectionChange ( 0 , 0 , featuresRowsAdded , featureTable , featuresData ) ;
402+ }
403+ int index = 0 ;
404+ foreach ( string value in features ) {
405+ AddRow ( featureTable , 1 , value , index , featuresData ) ;
406+ index ++ ;
407+ }
408+ SelectionChange ( rowSelectionID , rowSelectionID , featuresRowsAdded , featureTable , featuresData ) ;
409+ }
410+ else if ( switchLabels . SelectedIndex == 2 ) { // Comments
411+ commentsRowsAdded = 0 ;
412+ try {
413+ for ( int i = 0 ; i < comments . Count ; i ++ ) {
414+ commentTable . RowGroups [ 0 ] . Rows [ i ] . Cells . RemoveRange ( 0 , 1 ) ;
415+ }
416+ }
417+ catch ( ArgumentOutOfRangeException ) {
418+ // They just added a new value
419+ SelectionChange ( 0 , 0 , commentsRowsAdded , commentTable , commentsData ) ;
420+ }
421+ int index = 0 ;
422+ foreach ( string value in comments ) {
423+ AddRow ( commentTable , 2 , value , index , commentsData ) ;
424+ index ++ ;
425+ }
426+ SelectionChange ( rowSelectionID , rowSelectionID , commentsRowsAdded , commentTable , commentsData ) ;
427+ }
428+ } ) ;
429+ break ;
430+ }
431+ else if ( Passthrough . IsDeleting ) {
345432 isStopwatchRunning = false ;
346433
347434 // Exit out of all threads forcefully
@@ -356,82 +443,6 @@ private void Read() {
356443 } ) ;
357444 break ;
358445 }
359-
360-
361- CalculatePercentage ( ) ;
362- string json = File . ReadAllText ( editingFile ) ;
363- MainTableManifest . Rootobject values = JsonConvert . DeserializeObject < MainTableManifest . Rootobject > ( json ) ;
364-
365- // Set values for saving feature to rewrite
366- projectTitle = values . Title ;
367- errors = values . Errors . ToList ( ) ;
368- errorsData = values . ErrorsData . ToList ( ) ;
369- features = values . Features . ToList ( ) ;
370- featuresData = values . FeaturesData . ToList ( ) ;
371- comments = values . Comments . ToList ( ) ;
372- commentsData = values . CommentsData . ToList ( ) ;
373- duration = values . Duration ;
374- percentComplete = values . Percent ;
375-
376-
377- this . Dispatcher . Invoke ( ( ) =>
378- {
379- if ( switchLabels . SelectedIndex == 0 ) { // Errors
380- errorsRowsAdded = 0 ;
381- try {
382- for ( int i = 0 ; i < errors . Count ; i ++ ) {
383- errorTable . RowGroups [ 0 ] . Rows [ i ] . Cells . RemoveRange ( 0 , 1 ) ;
384- }
385- }
386- catch ( ArgumentOutOfRangeException ) {
387- // They just added a new value
388- SelectionChange ( 0 , 0 , errorsRowsAdded , errorTable , errorsData ) ;
389- }
390- int index = 0 ;
391- foreach ( string value in errors ) {
392- AddRow ( errorTable , 0 , value , index , errorsData ) ;
393- index ++ ;
394- }
395- SelectionChange ( rowSelectionID , rowSelectionID , errorsRowsAdded , errorTable , errorsData ) ;
396- }
397- else if ( switchLabels . SelectedIndex == 1 ) { // Features
398- featuresRowsAdded = 0 ;
399- try {
400- for ( int i = 0 ; i < features . Count ; i ++ ) {
401- featureTable . RowGroups [ 0 ] . Rows [ i ] . Cells . RemoveRange ( 0 , 1 ) ;
402- }
403- }
404- catch ( ArgumentOutOfRangeException ) {
405- // They just added a new value
406- SelectionChange ( 0 , 0 , featuresRowsAdded , featureTable , featuresData ) ;
407- }
408- int index = 0 ;
409- foreach ( string value in features ) {
410- AddRow ( featureTable , 1 , value , index , featuresData ) ;
411- index ++ ;
412- }
413- SelectionChange ( rowSelectionID , rowSelectionID , featuresRowsAdded , featureTable , featuresData ) ;
414- }
415- else if ( switchLabels . SelectedIndex == 2 ) { // Comments
416- commentsRowsAdded = 0 ;
417- try {
418- for ( int i = 0 ; i < comments . Count ; i ++ ) {
419- commentTable . RowGroups [ 0 ] . Rows [ i ] . Cells . RemoveRange ( 0 , 1 ) ;
420- }
421- }
422- catch ( ArgumentOutOfRangeException ) {
423- // They just added a new value
424- SelectionChange ( 0 , 0 , commentsRowsAdded , commentTable , commentsData ) ;
425- }
426- int index = 0 ;
427- foreach ( string value in comments ) {
428- AddRow ( commentTable , 2 , value , index , commentsData ) ;
429- index ++ ;
430- }
431- SelectionChange ( rowSelectionID , rowSelectionID , commentsRowsAdded , commentTable , commentsData ) ;
432- }
433- } ) ;
434-
435446 }
436447 }
437448
@@ -635,7 +646,6 @@ private void Edit(object sender, MouseButtonEventArgs e) {
635646 Passthrough . EditingFile = editingFile ;
636647 Passthrough . SelectedIndex = switchLabels . SelectedIndex ;
637648
638- Passthrough . IsAdding = true ;
639649 readThread = new Thread ( Read ) ;
640650 readThread . Start ( ) ;
641651
@@ -850,7 +860,6 @@ private void AddValue(object sender, MouseButtonEventArgs e) {
850860 Passthrough . EditingFile = editingFile ;
851861 Passthrough . SelectedIndex = switchLabels . SelectedIndex ;
852862
853- Passthrough . IsAdding = true ;
854863 readThread = new Thread ( Read ) ;
855864 readThread . Start ( ) ;
856865
0 commit comments