public async void AutoStart() { try { if (this.UserId != 0) { AutoUpload uploadObj = new AutoUpload(); await uploadObj.InitiateFileUploading(); //string a= uploadObj.currentStatus; AutoDownload downloadObj = new AutoDownload(); downloadObj.InitializeDownload(); } } catch { } }
public async Task InitiateFileUploading() { // patientList = new List<PatientData>(); StartTime = DateTime.Now.ToString(); PatientData PatientDataObj=null; var storage = new Setting<List<PatientData>>(); IReadOnlyList<StorageFile> files = await GetUploadingFileList(); var currentUploadCount = new Setting<int>(); DeletePartiallyUploadedItems(); int count = 0; //var temp = patientList.Select(p => p.Image1.Name).Except(files.Select(x=>x.Name)); IEnumerable<string> filesTemp; if (patientList.Count > 0) filesTemp = files.Select(p => p.Name).Except(patientList.Select(x => x.Image1.Name)); else filesTemp = files.Select(p => p.Name); int newfilecount = 0; foreach (var file in files) { foreach (var newfiles in filesTemp) { if (newfiles == file.Name) { if (newfiles.Contains(app.Username)) { newfilecount = newfilecount + 1; PatientDataObj = new PatientData(); PatientDataObj.ID = count; PatientDataObj.Image1 = new FileUploadCompleted(); PatientDataObj.Image1.Name = file.Name; PatientDataObj.Image1.Status = 0; PatientDataObj.Image1.Url = app.NormalBucketURL + file.Name; PatientDataObj.Age = count + 20; PatientDataObj.Sex = count % 2 == 0 ? DataModel.Gender.Male : DataModel.Gender.Female; var properties = await file.GetBasicPropertiesAsync(); PatientDataObj.Image1.Size = Convert.ToInt32(properties.Size) / 1000000; patientList.Add(PatientDataObj); await Task.WhenAll(Task.Factory.StartNew(() => UploadFile(file.Name, file, PatientDataObj.Image1))); ////await Task.WhenAll(Task.Run(() => UploadFile(file.Name, file, PatientDataObj.Image1))); //using (var semaphore = new SemaphoreSlim(MAX_PARALLEL_UPLOADS)) //{ //} } } } await storage.SaveAsync("UploadStat", patientList); await currentUploadCount.SaveAsync("CurrentUploadCount", newfilecount); count = count + 1; } AutoDownload downloadObj = new AutoDownload(); downloadObj.InitializeDownload(); }