|
@@ -1205,136 +1205,10 @@
|
|
|
[[self getDelegate:sessionID] uploadFileSuccessFailure:metadata.fileName fileID:metadata.fileID assetLocalIdentifier:metadata.assetLocalIdentifier serverUrl:serverUrl selector:metadata.sessionSelector selectorPost:metadata.sessionSelectorPost errorMessage:errorMessage errorCode:errorCode];
|
|
|
}
|
|
|
|
|
|
-#pragma --------------------------------------------------------------------------------------------
|
|
|
-#pragma mark ===== Download Verify =====
|
|
|
-#pragma --------------------------------------------------------------------------------------------
|
|
|
-
|
|
|
-- (void)verifyDownloadInProgress
|
|
|
-{
|
|
|
- NSArray *dataSourceDownload = [[NCManageDatabase sharedInstance] getTableMetadataDownload];
|
|
|
- NSArray *dataSourceDownloadWWan = [[NCManageDatabase sharedInstance] getTableMetadataDownloadWWan];
|
|
|
-
|
|
|
- NSMutableArray *dataSource = [NSMutableArray new];
|
|
|
-
|
|
|
- [dataSource addObjectsFromArray:dataSourceDownload];
|
|
|
- [dataSource addObjectsFromArray:dataSourceDownloadWWan];
|
|
|
-
|
|
|
- NSLog(@"[LOG] Verify download file in progress n. %lu", (unsigned long)[dataSource count]);
|
|
|
-
|
|
|
- for (tableMetadata *metadata in dataSource) {
|
|
|
-
|
|
|
- NSURLSession *session = [self getSessionfromSessionDescription:metadata.session];
|
|
|
-
|
|
|
- [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
|
|
|
-
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
-
|
|
|
- BOOL findTask = NO;
|
|
|
- BOOL findTaskPlist = NO;
|
|
|
-
|
|
|
- for (NSURLSessionDownloadTask *downloadTask in downloadTasks) {
|
|
|
-
|
|
|
- NSLog(@"[LOG] Find metadata Tasks [%li] = [%lu] state : %lu", (long)metadata.sessionTaskIdentifier ,(unsigned long)downloadTask.taskIdentifier, (unsigned long)[downloadTask state]);
|
|
|
-
|
|
|
- if (metadata.sessionTaskIdentifier == downloadTask.taskIdentifier) findTask = YES;
|
|
|
-
|
|
|
- if (findTask == YES || findTaskPlist == YES) break; // trovati, download ancora in corso
|
|
|
- }
|
|
|
-
|
|
|
- // DATA
|
|
|
- if (findTask == NO && metadata.sessionTaskIdentifier >= 0) {
|
|
|
-
|
|
|
- NSLog(@"[LOG] NOT Find metadata Task [%li] fileID : %@ - filename : %@", (long)metadata.sessionTaskIdentifier, metadata.fileID, metadata.fileName);
|
|
|
-
|
|
|
- [[NCManageDatabase sharedInstance] setMetadataSession:nil sessionError:@"Serious internal error download Task Not Found]" sessionSelector:nil sessionSelectorPost:nil sessionTaskIdentifier:k_taskIdentifierError predicate:[NSPredicate predicateWithFormat:@"fileID = %@ ", metadata.fileID]];
|
|
|
-
|
|
|
- if ([self.delegate respondsToSelector:@selector(reloadDatasource:)])
|
|
|
- [self.delegate reloadDatasource:[[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID]];
|
|
|
- }
|
|
|
- });
|
|
|
- }];
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-- (void)verifyDownloadInError:(id)delegate
|
|
|
-{
|
|
|
- NSMutableSet *serversUrl = [NSMutableSet new];
|
|
|
-
|
|
|
- NSArray *metadatas = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND session CONTAINS 'download' AND sessionTaskIdentifier = %i", _activeAccount, k_taskIdentifierError] sorted:nil ascending:NO];
|
|
|
-
|
|
|
- NSLog(@"[LOG] Verify re download in error n. %lu", (unsigned long)[metadatas count]);
|
|
|
-
|
|
|
- for (tableMetadata *metadata in metadatas) {
|
|
|
-
|
|
|
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
|
|
|
- if (!serverUrl) continue;
|
|
|
-
|
|
|
- if (metadata.sessionTaskIdentifier == k_taskIdentifierError)
|
|
|
- [self downloadFile:metadata.fileName fileID:metadata.fileID serverUrl:serverUrl selector:metadata.sessionSelector selectorPost:nil session:k_download_session taskStatus: k_taskStatusResume delegate:delegate];
|
|
|
-
|
|
|
- [serversUrl addObject:serverUrl];
|
|
|
-
|
|
|
- NSLog(@"[LOG] Re download file : %@ [%li]", metadata.fileName, (long)metadata.sessionTaskIdentifier);
|
|
|
- }
|
|
|
-
|
|
|
- for (NSString *serverUrl in serversUrl) {
|
|
|
- if ([self.delegate respondsToSelector:@selector(reloadDatasource:)])
|
|
|
- [self.delegate reloadDatasource:serverUrl];
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
#pragma --------------------------------------------------------------------------------------------
|
|
|
#pragma mark ===== Upload Verify =====
|
|
|
#pragma --------------------------------------------------------------------------------------------
|
|
|
|
|
|
-- (void)verifyUploadInProgress
|
|
|
-{
|
|
|
- NSArray *dataSourceUpload = [[NCManageDatabase sharedInstance] getTableMetadataUpload];
|
|
|
- NSArray *dataSourceUploadWWan = [[NCManageDatabase sharedInstance] getTableMetadataUploadWWan];
|
|
|
-
|
|
|
- NSMutableArray *dataSource = [[NSMutableArray alloc] init];
|
|
|
-
|
|
|
- [dataSource addObjectsFromArray:dataSourceUpload];
|
|
|
- [dataSource addObjectsFromArray:dataSourceUploadWWan];
|
|
|
-
|
|
|
- NSLog(@"[LOG] Verify upload file in progress n. %lu", (unsigned long)[dataSource count]);
|
|
|
-
|
|
|
- for (tableMetadata *metadata in dataSource) {
|
|
|
-
|
|
|
- __block NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
|
|
|
- if (!serverUrl) continue;
|
|
|
-
|
|
|
- NSURLSession *session = [self getSessionfromSessionDescription:metadata.session];
|
|
|
-
|
|
|
- [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
|
|
|
-
|
|
|
- BOOL findTask = NO;
|
|
|
-
|
|
|
- // cerchiamo la corrispondenza dei task
|
|
|
- for (NSURLSessionUploadTask *uploadTask in uploadTasks) {
|
|
|
-
|
|
|
- NSLog(@"[LOG] Find metadata Tasks [%li] = [%lu] state : %lu", (long)metadata.sessionTaskIdentifier, (unsigned long)uploadTask.taskIdentifier, (unsigned long)[uploadTask state]);
|
|
|
-
|
|
|
- if (metadata.sessionTaskIdentifier == uploadTask.taskIdentifier) findTask = YES;
|
|
|
-
|
|
|
- if (findTask == YES) break;
|
|
|
- }
|
|
|
-
|
|
|
- // se non c'è il relativo uploadTask.taskIdentifier allora chiediamolo
|
|
|
- if (findTask == NO) {
|
|
|
-
|
|
|
- NSLog(@"[LOG] Call ReadFileVerifyUpload because this file %@ is in progress but there is no task : [%li]", metadata.fileName, (long)metadata.sessionTaskIdentifier);
|
|
|
-
|
|
|
- if (metadata.sessionTaskIdentifier >= 0) [self readFileVerifyUpload:metadata.fileName serverUrl:serverUrl];
|
|
|
- }
|
|
|
- }];
|
|
|
-
|
|
|
- // Notification change session
|
|
|
- NSArray *object = [[NSArray alloc] initWithObjects:session, metadata, nil];
|
|
|
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_networkingSessionNotification object:object];
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
- (void)verifyUploadInErrorOrWait
|
|
|
{
|
|
|
NSMutableSet *directoryIDs = [NSMutableSet new];
|
|
@@ -1359,78 +1233,6 @@
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-- (void)readFileVerifyUpload:(NSString *)fileName serverUrl:(NSString *)serverUrl
|
|
|
-{
|
|
|
-#ifndef EXTENSION
|
|
|
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
|
|
|
-
|
|
|
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:_activeAccount];
|
|
|
-
|
|
|
- metadataNet.action = actionReadFile;
|
|
|
- metadataNet.fileName = fileName;
|
|
|
- metadataNet.serverUrl = serverUrl;
|
|
|
- metadataNet.selector = selectorReadFileVerifyUpload;
|
|
|
-
|
|
|
- [appDelegate addNetworkingOperationQueue:appDelegate.netQueue delegate:self metadataNet:metadataNet];
|
|
|
-#else
|
|
|
- NSLog(@"[LOG] Function not available for extension.");
|
|
|
-#endif
|
|
|
-}
|
|
|
-
|
|
|
-//
|
|
|
-// File exists : selectorReadFileVerifyUpload
|
|
|
-//
|
|
|
-- (void)readFileSuccess:(CCMetadataNet *)metadataNet metadata:(tableMetadata *)metadata
|
|
|
-{
|
|
|
- NSString *fileName = metadataNet.fileName;
|
|
|
-
|
|
|
- NSString *directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:metadataNet.serverUrl];
|
|
|
- if (!directoryID)
|
|
|
- [self uploadFileSuccessFailure:metadata fileName:metadataNet.fileName fileID:metadata.fileID etag:metadata.etag date:metadata.date serverUrl:metadataNet.serverUrl errorCode:k_CCErrorFileUploadNotFound];
|
|
|
-
|
|
|
- tableMetadata *metadataTemp = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileName = %@ AND directoryID = %@ AND account = %@", fileName , directoryID, _activeAccount]];
|
|
|
-
|
|
|
- // is completed ?
|
|
|
- if (metadataTemp.sessionTaskIdentifier == k_taskIdentifierDone) {
|
|
|
-
|
|
|
- [CCGraphics createNewImageFrom:metadata.fileID directoryUser:_directoryUser fileNameTo:metadata.fileID extension:[metadata.fileNameView pathExtension] size:@"m" imageForUpload:NO typeFile:metadata.typeFile writePreview:YES optimizedFileName:[CCUtility getOptimizedPhoto]];
|
|
|
-
|
|
|
- NSLog(@"[LOG] Verify read file success, but files already processed");
|
|
|
-
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
- if ([self.delegate respondsToSelector:@selector(reloadDatasource:)])
|
|
|
- [self.delegate reloadDatasource:[[NCManageDatabase sharedInstance] getServerUrl:directoryID]];
|
|
|
- });
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- [self uploadFileSuccessFailure:metadataTemp fileName:metadataNet.fileName fileID:metadata.fileID etag:metadata.etag date:metadata.date serverUrl:metadataNet.serverUrl errorCode:0];
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-//
|
|
|
-// File do not exists : selectorReadFileVerifyUpload
|
|
|
-//
|
|
|
-- (void)readFileFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
|
|
|
-{
|
|
|
- NSString *fileName = metadataNet.fileName;
|
|
|
-
|
|
|
- NSString *directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:metadataNet.serverUrl];
|
|
|
- if (!directoryID) return;
|
|
|
-
|
|
|
- tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileName = %@ AND directoryID = %@ AND account = %@",fileName , directoryID, _activeAccount]];
|
|
|
-
|
|
|
- NSInteger error;
|
|
|
- if (errorCode == kOCErrorServerPathNotFound)
|
|
|
- error = k_CCErrorFileUploadNotFound;
|
|
|
- else
|
|
|
- error = errorCode;
|
|
|
-
|
|
|
- // fix CCNetworking.m line 1340 2.17.2 (00005)
|
|
|
- if (metadata)
|
|
|
- [self uploadFileSuccessFailure:metadata fileName:metadataNet.fileName fileID:metadata.fileID etag:metadata.etag date:metadata.date serverUrl:metadataNet.serverUrl errorCode:error];
|
|
|
-}
|
|
|
-
|
|
|
#pragma --------------------------------------------------------------------------------------------
|
|
|
#pragma mark ===== Utility =====
|
|
|
#pragma --------------------------------------------------------------------------------------------
|