Browse Source

Add new : verifyLockTableAutomaticUpload (test)

Marino Faggiana 8 years ago
parent
commit
fb7d7efbf7
3 changed files with 42 additions and 3 deletions
  1. 34 3
      iOSClient/AppDelegate.m
  2. 1 0
      iOSClient/FileSystem/CCCoreData.h
  3. 7 0
      iOSClient/FileSystem/CCCoreData.m

+ 34 - 3
iOSClient/AppDelegate.m

@@ -311,7 +311,7 @@
 //
 - (void)applicationWillEnterForeground:(UIApplication *)application
 {    
-    // facciamo partire il timer per il controllo delle sessioni
+    // facciamo partire il timer per il controllo delle sessioni e dei Lock
     [self.timerVerifySessionInProgress invalidate];
     self.timerVerifySessionInProgress = [NSTimer scheduledTimerWithTimeInterval:k_timerVerifySession target:self selector:@selector(verifyDownloadUploadInProgress) userInfo:nil repeats:YES];
     
@@ -1244,7 +1244,7 @@
     // Only one
     if ([[self verifyExistsInQueuesUploadSelector:selector] count] > 1)
         return;
-
+    
     // Verify num error if selectorUploadAutomaticAll
     if ([selector isEqualToString:selectorUploadAutomaticAll]) {
     
@@ -1270,13 +1270,17 @@
         PHFetchResult *result = [PHAsset fetchAssetsWithLocalIdentifiers:@[metadataNet.identifier] options:nil];
 
         if (!result.count) {
-           [CCCoreData addActivityClient:metadataNet.fileName fileID:metadataNet.identifier action:k_activityDebugActionUpload selector:selector note:@"Internal error image/video not found" type:k_activityVerboseDefault verbose:k_activityVerboseHigh account:_activeAccount activeUrl:_activeUrl];
+            
+            [CCCoreData addActivityClient:metadataNet.fileName fileID:metadataNet.identifier action:k_activityDebugActionUpload selector:selector note:@"Internal error image/video not found" type:k_activityVerboseDefault verbose:k_activityVerboseHigh account:_activeAccount activeUrl:_activeUrl];
             [CCCoreData unlockTableAutomaticUploadForAccount:_activeAccount identifier:metadataNet.identifier];
+            
             return;
         }
         
         if(![self createFolderSubFolderAutomaticUploadFolderPhotos:folderPhotos useSubFolder:useSubFolder assets:[[NSArray alloc] initWithObjects:result[0], nil] selector:selectorUploadAutomatic]) {
+            
             [CCCoreData unlockTableAutomaticUploadForAccount:_activeAccount identifier:metadataNet.identifier];
+            
             return;
         }
     }
@@ -1297,6 +1301,30 @@
     }
 }
 
+- (void)verifyLockTableAutomaticUpload
+{
+    NSArray *UploadAutomaticInQueue = [self verifyExistsInQueuesUploadSelector:selectorUploadAutomatic];
+    NSArray *UploadAutomaticAllInQueue = [self verifyExistsInQueuesUploadSelector:selectorUploadAutomaticAll];
+    NSMutableArray *UploadInQueue = [NSMutableArray new];
+    [UploadInQueue addObjectsFromArray:UploadAutomaticInQueue];
+    [UploadInQueue addObjectsFromArray:UploadAutomaticAllInQueue];
+    
+    NSArray *recordAutomaticUploadInLock = [CCCoreData getAllLockTableAutomaticUploadForAccount:_activeAccount];
+    
+    for (TableAutomaticUpload *tableAutomaticUpload in recordAutomaticUploadInLock) {
+        
+        BOOL recordFound = NO;
+        
+        for (CCMetadataNet *metadataNet in UploadInQueue) {
+            if (metadataNet.identifier == tableAutomaticUpload.identifier)
+                recordFound = YES;
+        }
+        
+        if (!recordFound)
+            [CCCoreData unlockTableAutomaticUploadForAccount:_activeAccount identifier:tableAutomaticUpload.identifier];
+    }
+}
+
 - (void)verifyDownloadUploadInProgress
 {
     BOOL callVerifyDownload = NO;
@@ -1324,6 +1352,9 @@
             
             [self.timerVerifySessionInProgress invalidate];
         }
+        
+        // Verify Lock in Table Automatic Upload
+        //[self verifyLockTableAutomaticUpload];
     }
 }
 

+ 1 - 0
iOSClient/FileSystem/CCCoreData.h

@@ -191,6 +191,7 @@
 
 + (BOOL)addTableAutomaticUpload:(CCMetadataNet *)metadataNet account:(NSString *)account;
 + (CCMetadataNet *)getTableAutomaticUploadForAccount:(NSString *)account selector:(NSString *)selector;
++ (NSArray *)getAllLockTableAutomaticUploadForAccount:(NSString *)account;
 + (void)unlockTableAutomaticUploadForAccount:(NSString *)account identifier:(NSString *)identifier;
 + (void)deleteTableAutomaticUploadForAccount:(NSString *)account identifier:(NSString *)identifier;
 + (NSUInteger)countTableAutomaticUploadForAccount:(NSString *)account selector:(NSString *)selector;

+ 7 - 0
iOSClient/FileSystem/CCCoreData.m

@@ -1571,6 +1571,13 @@
     return nil;
 }
 
++ (NSArray *)getAllLockTableAutomaticUploadForAccount:(NSString *)account
+{
+    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(account == %@) AND (lock == 1)", account];
+    
+    return [TableAutomaticUpload MR_findAllWithPredicate:predicate];
+}
+
 + (void)unlockTableAutomaticUploadForAccount:(NSString *)account identifier:(NSString *)identifier
 {
     NSManagedObjectContext *context = [NSManagedObjectContext MR_context];