|
@@ -369,15 +369,103 @@
|
|
if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) {
|
|
if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) {
|
|
|
|
|
|
// ONLY BACKGROUND
|
|
// ONLY BACKGROUND
|
|
- [[NCAutoUpload sharedInstance] performSelectorOnMainThread:@selector(loadAutoUpload:) withObject:[NSNumber numberWithInt:k_maxConcurrentOperationDownloadUploadBackground] waitUntilDone:NO];
|
|
|
|
|
|
+ [self performSelectorOnMainThread:@selector(loadAutoUpload:) withObject:[NSNumber numberWithInt:k_maxConcurrentOperationDownloadUploadBackground] waitUntilDone:NO];
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
// ONLY FOREFROUND
|
|
// ONLY FOREFROUND
|
|
- [[NCAutoUpload sharedInstance] performSelectorOnMainThread:@selector(loadAutoUpload:) withObject:[NSNumber numberWithInt:k_maxConcurrentOperationDownloadUpload] waitUntilDone:NO];
|
|
|
|
|
|
+ [self performSelectorOnMainThread:@selector(loadAutoUpload:) withObject:[NSNumber numberWithInt:k_maxConcurrentOperationDownloadUpload] waitUntilDone:NO];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+- (void)loadAutoUpload:(NSNumber *)maxConcurrent
|
|
|
|
+{
|
|
|
|
+ CCMetadataNet *metadataNet;
|
|
|
|
+
|
|
|
|
+ // Stop Timer
|
|
|
|
+ [_timerProcessAutoUpload invalidate];
|
|
|
|
+
|
|
|
|
+ NSInteger maxConcurrentUpload = [maxConcurrent integerValue];
|
|
|
|
+ NSInteger counterUploadInSessionAndInLock = [[[NCManageDatabase sharedInstance] getTableMetadataUpload] count] + [[[NCManageDatabase sharedInstance] getTableMetadataUploadWWan] count] + [[[NCManageDatabase sharedInstance] getLockQueueUpload] count];
|
|
|
|
+ NSInteger counterNewUpload = 0;
|
|
|
|
+
|
|
|
|
+ // ------------------------- <selector Auto Upload> -------------------------
|
|
|
|
+
|
|
|
|
+ while (counterUploadInSessionAndInLock < maxConcurrentUpload) {
|
|
|
|
+
|
|
|
|
+ metadataNet = [[NCManageDatabase sharedInstance] getQueueUploadWithSelector:selectorUploadAutoUpload];
|
|
|
|
+ if (metadataNet) {
|
|
|
|
+
|
|
|
|
+ // Priority Error only in Foreground
|
|
|
|
+ if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground && metadataNet.priority <= k_priorityAutoUploadError)
|
|
|
|
+ continue;
|
|
|
|
+
|
|
|
|
+ [[CCNetworking sharedNetworking] uploadFileFromAssetLocalIdentifier:metadataNet delegate:_activeMain];
|
|
|
|
+
|
|
|
|
+ counterNewUpload++;
|
|
|
|
+
|
|
|
|
+ } else
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ counterUploadInSessionAndInLock = [[[NCManageDatabase sharedInstance] getTableMetadataUpload] count] + [[[NCManageDatabase sharedInstance] getTableMetadataUploadWWan] count] + [[[NCManageDatabase sharedInstance] getLockQueueUpload] count];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // ------------------------- <selector Auto Upload All> ----------------------
|
|
|
|
+
|
|
|
|
+ // Verify num error MAX 10 after STOP
|
|
|
|
+ NSArray *metadatas = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND sessionSelector = %@ AND (sessionTaskIdentifier = %i OR sessionTaskIdentifierPlist = %i)", _activeAccount, selectorUploadAutoUploadAll, k_taskIdentifierError, k_taskIdentifierError] sorted:nil ascending:NO];
|
|
|
|
+
|
|
|
|
+ NSInteger errorCount = [metadatas count];
|
|
|
|
+
|
|
|
|
+ if (errorCount >= 10) {
|
|
|
|
+
|
|
|
|
+ [self messageNotification:@"_error_" description:@"_too_errors_automatic_all_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:0];
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ while (counterUploadInSessionAndInLock < maxConcurrentUpload) {
|
|
|
|
+
|
|
|
|
+ metadataNet = [[NCManageDatabase sharedInstance] getQueueUploadWithSelector:selectorUploadAutoUploadAll];
|
|
|
|
+ if (metadataNet) {
|
|
|
|
+
|
|
|
|
+ // Priority Error only in Foreground
|
|
|
|
+ if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground && metadataNet.priority <= k_priorityAutoUploadError)
|
|
|
|
+ continue;
|
|
|
|
+
|
|
|
|
+ [[CCNetworking sharedNetworking] uploadFileFromAssetLocalIdentifier:metadataNet delegate:_activeMain];
|
|
|
|
+
|
|
|
|
+ counterNewUpload++;
|
|
|
|
+
|
|
|
|
+ } else
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ counterUploadInSessionAndInLock = [[[NCManageDatabase sharedInstance] getTableMetadataUpload] count] + [[[NCManageDatabase sharedInstance] getTableMetadataUploadWWan] count] + [[[NCManageDatabase sharedInstance] getLockQueueUpload] count];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Verify Lock
|
|
|
|
+ NSInteger counterUploadInSession = [[[NCManageDatabase sharedInstance] getTableMetadataUpload] count] + [[[NCManageDatabase sharedInstance] getTableMetadataUploadWWan] count];
|
|
|
|
+ NSArray *tableMetadatasInLock = [[NCManageDatabase sharedInstance] getLockQueueUpload];
|
|
|
|
+
|
|
|
|
+ if (counterNewUpload == 0 && counterUploadInSession == 0 && [tableMetadatasInLock count] > 0) {
|
|
|
|
+
|
|
|
|
+ // Unlock
|
|
|
|
+ for (tableMetadata *metadata in tableMetadatasInLock) {
|
|
|
|
+
|
|
|
|
+ if ([[NCManageDatabase sharedInstance] isTableInvalidated:metadata] == NO)
|
|
|
|
+ [[NCManageDatabase sharedInstance] unlockQueueUploadWithAssetLocalIdentifier:metadata.assetLocalIdentifier];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // In background verify Upload in error
|
|
|
|
+ if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) {
|
|
|
|
+ [[CCNetworking sharedNetworking] verifyUploadInError];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Start Timer
|
|
|
|
+ _timerProcessAutoUpload = [NSTimer scheduledTimerWithTimeInterval:k_timerProcessAutoUpload target:app selector:@selector(processAutoUpload) userInfo:nil repeats:YES];
|
|
|
|
+}
|
|
|
|
+
|
|
#pragma --------------------------------------------------------------------------------------------
|
|
#pragma --------------------------------------------------------------------------------------------
|
|
#pragma mark ===== Setting Active Account =====
|
|
#pragma mark ===== Setting Active Account =====
|
|
#pragma --------------------------------------------------------------------------------------------
|
|
#pragma --------------------------------------------------------------------------------------------
|