|
@@ -25,6 +25,8 @@
|
|
|
#import "AppDelegate.h"
|
|
|
#import "NCBridgeSwift.h"
|
|
|
|
|
|
+#pragma GCC diagnostic ignored "-Wundeclared-selector"
|
|
|
+
|
|
|
@interface NCAutoUpload ()
|
|
|
{
|
|
|
PHFetchResult *_assetsFetchResult;
|
|
@@ -551,12 +553,16 @@
|
|
|
CCMetadataNet *metadataNet;
|
|
|
PHFetchResult *result;
|
|
|
|
|
|
- NSInteger maxConcurrentUpload = [maxConcurrent integerValue];
|
|
|
- NSInteger counterUpload = [app getNumberUploadInQueues] + [app getNumberUploadInQueuesWWan] + [[[NCManageDatabase sharedInstance] getLockAutoUpload] count];
|
|
|
+ // Stop Timer
|
|
|
+ [app.timerProcessAutoUpload invalidate];
|
|
|
|
|
|
+ NSInteger maxConcurrentUpload = [maxConcurrent integerValue];
|
|
|
+ NSInteger counterUploadInQueueAndInLock = [app getNumberUploadInQueues] + [app getNumberUploadInQueuesWWan] + [[[NCManageDatabase sharedInstance] getLockAutoUpload] count];
|
|
|
+ NSInteger counterNewUpload = 0;
|
|
|
+
|
|
|
// ------------------------- <selector Auto Upload> -------------------------
|
|
|
|
|
|
- while (counterUpload < maxConcurrentUpload) {
|
|
|
+ while (counterUploadInQueueAndInLock < maxConcurrentUpload) {
|
|
|
|
|
|
metadataNet = [[NCManageDatabase sharedInstance] getAutoUploadWithSelector:selectorUploadAutoUpload];
|
|
|
if (metadataNet) {
|
|
@@ -573,6 +579,8 @@
|
|
|
|
|
|
[[CCNetworking sharedNetworking] uploadFileFromAssetLocalIdentifier:metadataNet.assetLocalIdentifier fileName:metadataNet.fileName serverUrl:metadataNet.serverUrl cryptated:metadataNet.cryptated session:metadataNet.session taskStatus:metadataNet.taskStatus selector:metadataNet.selector selectorPost:metadataNet.selectorPost errorCode:metadataNet.errorCode delegate:app.activeMain];
|
|
|
|
|
|
+ counterNewUpload++;
|
|
|
+
|
|
|
} else {
|
|
|
|
|
|
[[NCManageDatabase sharedInstance] addActivityClient:metadataNet.fileName fileID:metadataNet.assetLocalIdentifier action:k_activityDebugActionUpload selector:selectorUploadAutoUploadAll note:@"Internal error image/video not found [0]" type:k_activityTypeFailure verbose:k_activityVerboseHigh activeUrl:app.activeUrl];
|
|
@@ -580,7 +588,7 @@
|
|
|
[[NCManageDatabase sharedInstance] deleteAutoUploadWithAssetLocalIdentifier:metadataNet.assetLocalIdentifier];
|
|
|
}
|
|
|
|
|
|
- counterUpload = [app getNumberUploadInQueues] + [app getNumberUploadInQueuesWWan] + [[[NCManageDatabase sharedInstance] getLockAutoUpload] count];
|
|
|
+ counterUploadInQueueAndInLock = [app getNumberUploadInQueues] + [app getNumberUploadInQueuesWWan] + [[[NCManageDatabase sharedInstance] getLockAutoUpload] count];
|
|
|
}
|
|
|
|
|
|
// ------------------------- <selector Auto Upload All> ----------------------
|
|
@@ -593,35 +601,55 @@
|
|
|
if (errorCount >= 10) {
|
|
|
|
|
|
[app messageNotification:@"_error_" description:@"_too_errors_automatic_all_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:0];
|
|
|
- return;
|
|
|
- }
|
|
|
|
|
|
- while (counterUpload < maxConcurrentUpload) {
|
|
|
+ } else {
|
|
|
+
|
|
|
+ while (counterUploadInQueueAndInLock < maxConcurrentUpload) {
|
|
|
|
|
|
- metadataNet = [[NCManageDatabase sharedInstance] getAutoUploadWithSelector:selectorUploadAutoUploadAll];
|
|
|
- if (metadataNet) {
|
|
|
+ metadataNet = [[NCManageDatabase sharedInstance] getAutoUploadWithSelector:selectorUploadAutoUploadAll];
|
|
|
+ if (metadataNet) {
|
|
|
|
|
|
- PHFetchOptions *fetchOptions = [PHFetchOptions new];
|
|
|
- fetchOptions.includeAssetSourceTypes = PHAssetSourceTypeNone | PHAssetSourceTypeUserLibrary | PHAssetSourceTypeCloudShared | PHAssetSourceTypeiTunesSynced;
|
|
|
+ PHFetchOptions *fetchOptions = [PHFetchOptions new];
|
|
|
+ fetchOptions.includeAssetSourceTypes = PHAssetSourceTypeNone | PHAssetSourceTypeUserLibrary | PHAssetSourceTypeCloudShared | PHAssetSourceTypeiTunesSynced;
|
|
|
|
|
|
- result = [PHAsset fetchAssetsWithLocalIdentifiers:@[metadataNet.assetLocalIdentifier] options:fetchOptions];
|
|
|
+ result = [PHAsset fetchAssetsWithLocalIdentifiers:@[metadataNet.assetLocalIdentifier] options:fetchOptions];
|
|
|
|
|
|
- } else
|
|
|
- break;
|
|
|
+ } else
|
|
|
+ break;
|
|
|
|
|
|
- if (result.count > 0) {
|
|
|
+ if (result.count > 0) {
|
|
|
|
|
|
- [[CCNetworking sharedNetworking] uploadFileFromAssetLocalIdentifier:metadataNet.assetLocalIdentifier fileName:metadataNet.fileName serverUrl:metadataNet.serverUrl cryptated:metadataNet.cryptated session:metadataNet.session taskStatus:metadataNet.taskStatus selector:metadataNet.selector selectorPost:metadataNet.selectorPost errorCode:metadataNet.errorCode delegate:app.activeMain];
|
|
|
+ [[CCNetworking sharedNetworking] uploadFileFromAssetLocalIdentifier:metadataNet.assetLocalIdentifier fileName:metadataNet.fileName serverUrl:metadataNet.serverUrl cryptated:metadataNet.cryptated session:metadataNet.session taskStatus:metadataNet.taskStatus selector:metadataNet.selector selectorPost:metadataNet.selectorPost errorCode:metadataNet.errorCode delegate:app.activeMain];
|
|
|
+
|
|
|
+ counterNewUpload++;
|
|
|
|
|
|
- } else {
|
|
|
+ } else {
|
|
|
|
|
|
- [[NCManageDatabase sharedInstance] addActivityClient:metadataNet.fileName fileID:metadataNet.assetLocalIdentifier action:k_activityDebugActionUpload selector:selectorUploadAutoUploadAll note:@"Internal error image/video not found [0]" type:k_activityTypeFailure verbose:k_activityVerboseHigh activeUrl:app.activeUrl];
|
|
|
+ [[NCManageDatabase sharedInstance] addActivityClient:metadataNet.fileName fileID:metadataNet.assetLocalIdentifier action:k_activityDebugActionUpload selector:selectorUploadAutoUploadAll note:@"Internal error image/video not found [0]" type:k_activityTypeFailure verbose:k_activityVerboseHigh activeUrl:app.activeUrl];
|
|
|
|
|
|
- [[NCManageDatabase sharedInstance] deleteAutoUploadWithAssetLocalIdentifier:metadataNet.assetLocalIdentifier];
|
|
|
+ [[NCManageDatabase sharedInstance] deleteAutoUploadWithAssetLocalIdentifier:metadataNet.assetLocalIdentifier];
|
|
|
+ }
|
|
|
+
|
|
|
+ counterUploadInQueueAndInLock = [app getNumberUploadInQueues] + [app getNumberUploadInQueuesWWan] + [[[NCManageDatabase sharedInstance] getLockAutoUpload] count];
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ // Verify Lock
|
|
|
+ NSInteger counterUploadInQueue = [app getNumberUploadInQueues] + [app getNumberUploadInQueuesWWan];
|
|
|
+ NSArray *tableMetadatasInLock = [[NCManageDatabase sharedInstance] getLockAutoUpload];
|
|
|
+
|
|
|
+ if (counterNewUpload == 0 && counterUploadInQueue == 0 && [tableMetadatasInLock count] > 0) {
|
|
|
|
|
|
- counterUpload = [app getNumberUploadInQueues] + [app getNumberUploadInQueuesWWan] + [[[NCManageDatabase sharedInstance] getLockAutoUpload] count];
|
|
|
+ // Unlock
|
|
|
+ for (tableMetadata *metadata in tableMetadatasInLock) {
|
|
|
+
|
|
|
+ if ([[NCManageDatabase sharedInstance] isTableInvalidated:metadata] == NO)
|
|
|
+ [[NCManageDatabase sharedInstance] unlockAutoUploadWithAssetLocalIdentifier:metadata.assetLocalIdentifier];
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ // Start Timer
|
|
|
+ app.timerProcessAutoUpload = [NSTimer scheduledTimerWithTimeInterval:k_timerProcessAutoUpload target:app selector:@selector(processAutoUpload) userInfo:nil repeats:YES];
|
|
|
}
|
|
|
|
|
|
#pragma --------------------------------------------------------------------------------------------
|