public static string Upload(string filename, string path) { if (!Authorised) { MainForm.LogMessageToFile("Authorise google drive in settings"); return(LocRm.GetString("CloudAddSettings")); } if (UploadList.SingleOrDefault(p => p.SourceFilename == filename) != null) { return(LocRm.GetString("FileInQueue")); } if (UploadList.Count >= CloudGateway.MaxUploadQueue) { return(LocRm.GetString("UploadQueueFull")); } UploadList.Add(new UploadEntry { DestinationPath = "iSpy\\" + path.Replace("/", "\\").Trim('\\'), SourceFilename = filename }); if (!_uploading) { _uploading = true; ThreadPool.QueueUserWorkItem(Upload, null); } return(LocRm.GetString("AddedToQueue")); }
public static string Upload(string filename, string path, out bool success) { success = false; //if (!Statics.Subscribed) // return "NotSubscribed"; if (!Authorised) { return("CloudAddSettings"); } if (UploadList.SingleOrDefault(p => p.SourceFilename == filename) != null) { return("FileInQueue"); } if (UploadList.Count >= CloudGateway.MaxUploadQueue) { return("UploadQueueFull"); } UploadList.Add(new UploadEntry { DestinationPath = path, SourceFilename = filename }); if (!_uploading) { _uploading = true; ThreadPool.QueueUserWorkItem(Upload, null); } success = true; return("AddedToQueue"); }
public static string Upload(int objectId, string filename) { if (UploadList.SingleOrDefault(p => p.Filename == filename) != null) { return(LocRm.GetString("FileInQueue")); } if (UploadList.Count >= CloudGateway.MaxUploadQueue) { return(LocRm.GetString("UploadQueueFull")); } if (Uploaded.FirstOrDefault(p => p == filename) != null) { return(LocRm.GetString("AlreadyUploaded")); } var us = new UserState(objectId, filename); UploadList.Add(us); if (!_uploading) { _uploading = true; ThreadPool.QueueUserWorkItem(Upload, null); } return(LocRm.GetString("AddedToQueue")); }
public static string Upload(string filename, string path) { if (!Authorised) { Logger.LogMessageToFile("Authorise dropbox in settings"); return(LocRm.GetString("CloudAddSettings")); } if (UploadList.SingleOrDefault(p => p.SourceFilename == filename) != null) { return(LocRm.GetString("FileInQueue")); } if (UploadList.Count >= CloudGateway.MaxUploadQueue) { return(LocRm.GetString("UploadQueueFull")); } UploadList.Add(new UploadEntry { DestinationPath = path, SourceFilename = filename }); if (!_uploading) { _uploading = true; ThreadPool.QueueUserWorkItem(Upload, null); } return(LocRm.GetString("AddedToQueue")); }
public static string Upload(string filename, string path, out bool success) { success = false; if (!Authorised) { return("CloudAddSettings"); } if (UploadList.SingleOrDefault(p => p.SourceFilename == filename) != null) { return("FileInQueue"); } if (UploadList.Count >= CloudGateway.MaxUploadQueue) { return("UploadQueueFull"); } UploadList.Add(new UploadEntry { DestinationPath = "iSpy" + "\\" + path.Replace("/", "\\").Trim(Path.DirectorySeparatorChar), SourceFilename = filename }); if (!_uploading) { _uploading = true; ThreadPool.QueueUserWorkItem(Upload, null); } success = true; return("AddedToQueue"); }
private async Task HandleNotExistsInCloud(B2Db b2Db, string filePath, ulong xhash, string parentPath, string b2Path) { FileObject existingFileObject = b2Db.GetFileObject(filePath); // fo exists but not uploaded yet if (existingFileObject != null && existingFileObject.B2Files.Count == 0) { UploadList.Add(new UploadObject(existingFileObject, parentPath, b2Path)); } // fo exists and b2file exits but not available on cloud, so clear b2file object else if (existingFileObject != null && existingFileObject.B2Files.Count >= 0) { existingFileObject.B2Files.Clear(); existingFileObject.DateModified = DateTime.Now; await b2Db.UpdateFileObject(existingFileObject); UploadList.Add(new UploadObject(existingFileObject, parentPath, b2Path)); } // no fo, no b2file else { FileObject tempFileObject = new FileObject(filePath, xhash); await b2Db.Add(tempFileObject); UploadList.Add(new UploadObject(tempFileObject, parentPath, b2Path)); } }
private async Task HandleIfExistsInCloud(B2Db b2Db, string filePath, B2File existingB2File, ulong xhash, string parentPath, string b2Path) { // try find local object in db FileObject existingFileObject = b2Db.GetFileObject(filePath); if (existingFileObject != null && existingFileObject.B2Files.ContainsKey(existingB2File.FileId)) { // local object xhash diff from cloud, then mark this for upload if (existingFileObject.Xhash != xhash) { existingFileObject.Xhash = xhash; UploadList.Add(new UploadObject(existingFileObject, parentPath, b2Path)); } } // if existing file object is available but b2file object is not available else if (existingFileObject != null && !existingFileObject.B2Files.ContainsKey(existingB2File.FileId)) { // update b2file object and does not need to reupload if (existingB2File.ContentSHA1.Equals("none") || Utils.FilepathToSha1Hash(filePath).Equals(existingB2File.ContentSHA1.Replace("unverified:", ""), StringComparison.InvariantCultureIgnoreCase)) { existingFileObject.B2Files.Add(existingB2File.FileId, existingB2File); existingFileObject.DateModified = DateTime.Now; await b2Db.UpdateFileObject(existingFileObject); } else // mark this object to upload if diff sha { existingFileObject.Xhash = xhash; UploadList.Add(new UploadObject(existingFileObject, parentPath, b2Path)); } } else { // local not available, so check it's sha1hash when same add to db or mark to upload FileObject tempFileObject = new FileObject(filePath, xhash); if (existingB2File.ContentSHA1.Equals("none") || Utils.FilepathToSha1Hash(filePath).Equals(existingB2File.ContentSHA1.Replace("unverified:", ""), StringComparison.InvariantCultureIgnoreCase)) { tempFileObject.B2Files.Add(existingB2File.FileId, existingB2File); await b2Db.Add(tempFileObject); } else { UploadList.Add(new UploadObject(tempFileObject, parentPath, b2Path)); } } }
public void BuildUploadList() { UploadList.Clear(); if (Directory.Exists(VabPath)) { UploadList.Add(CraftType.Vab, Directory.GetFiles(VabPath).Select(Path.GetFileNameWithoutExtension)); } if (Directory.Exists(SphPath)) { UploadList.Add(CraftType.Sph, Directory.GetFiles(SphPath).Select(Path.GetFileNameWithoutExtension)); } if (Directory.Exists(VabPath)) { UploadList.Add(CraftType.Subassembly, Directory.GetFiles(SubassemblyPath).Select(Path.GetFileNameWithoutExtension)); } }
public static string Upload(string filename, string path, out bool success) { success = false; if (UploadList.SingleOrDefault(p => p.SourceFilename == filename) != null) { return(LocRm.GetString("FileInQueue")); } if (UploadList.Count >= CloudGateway.MaxUploadQueue) { return(LocRm.GetString("UploadQueueFull")); } UploadList.Add(new UploadEntry { DestinationPath = "iSpy\\" + path.Replace("/", "\\").Trim('\\'), SourceFilename = filename }); if (!_uploading) { _uploading = true; ThreadPool.QueueUserWorkItem(Upload, null); } success = true; return(LocRm.GetString("AddedToQueue")); }
private static void Upload(object state) { if (UploadList.Count == 0) { _uploading = false; return; } UploadEntry entry; try { var l = UploadList.ToList(); entry = l[0];//could have been cleared by Authorise l.RemoveAt(0); UploadList = l.ToList(); } catch { _uploading = false; return; } FileInfo fi; byte[] byteArray; try { fi = new FileInfo(entry.SourceFilename); byteArray = System.IO.File.ReadAllBytes(fi.FullName); } catch { //file doesn't exist Upload(null); return; } var mt = MimeTypes.GetMimeType(fi.Extension); var body = new File { Title = fi.Name, Description = "iSpy", MimeType = mt }; string fid = GetOrCreateFolder(entry.DestinationPath); bool retry = fid == ""; if (!retry) { var stream = new MemoryStream(byteArray); body.Parents = new List <ParentReference> { new ParentReference { Id = fid } }; //id of ispy directory var request = Service.Files.Insert(body, stream, mt); request.ProgressChanged += RequestProgressChanged; try { var task = request.UploadAsync(); task.ContinueWith(t => { stream.Dispose(); Upload(null); }); } catch (Exception ex) { MainForm.LogExceptionToFile(ex); //network down? - add it back into the queue and wait for next upload to try again retry = true; } } if (retry) { UploadList.Add(entry); _uploading = false; } }
private static void Upload(object state) { if (UploadList.Count == 0) { _uploading = false; return; } UploadEntry entry; try { var l = UploadList.ToList(); entry = l[0];//could have been cleared by Authorise l.RemoveAt(0); UploadList = l.ToList(); } catch { _uploading = false; return; } FileInfo fi; byte[] byteArray; try { fi = new FileInfo(entry.SourceFilename); byteArray = File.ReadAllBytes(fi.FullName); } catch { //file doesn't exist Upload(null); return; } var retry = false; using (var stream = new MemoryStream(byteArray)) { try { string p = "/" + entry.DestinationPath.Replace("\\", "/").Trim('/') + "/"; var r = Service.UploadFile(p, fi.Name, stream); MainForm.LogMessageToFile("Uploaded to dropbox: /iSpy" + r.Path); } catch (Exception ex) { MainForm.LogExceptionToFile(ex); retry = true; } } if (retry) { UploadList.Add(entry); _uploading = false; } Upload(null); }
private async Task <Boolean> synchronizeAlbum(Album _album, String _pathTrip, TripSummary _summary) { String _pathAlbum = "/" + _pathTrip + "/" + _album.PathAlbum; ResponseContainer _folderDesc = null; ProgressUpdate(Res.GetString("SynchroAlbum") + " \"" + _album.Summary.Name + "\"", 0); //list top-folder String _request = API_METADATA + "/sandbox/" + _pathAlbum + "?access_token=" + Token + "&hash=" + _album.Hash; HttpResponseMessage _response = await SendRequest(_request); if (_response != null) { if (_response.StatusCode == HttpStatusCode.OK) { _folderDesc = await Serialization.DeserializeHttpToJson <ResponseContainer>(_response.Content) as ResponseContainer; } else if (_response.StatusCode == HttpStatusCode.NotFound) { _folderDesc = await CreateFolder(_pathTrip + "/" + _album.PathAlbum); } } if (_folderDesc != null) { Boolean _status = true; if ((_folderDesc.contents != null) && (_folderDesc.contents.Count() != 0)) { //check if all dropbox pictures are synchronized with local pictures, delete if not in local folder foreach (ResponseElement _element in _folderDesc.contents) { if (_element.is_dir) { _status &= await Delete(_element.path); } else { Boolean _found = false; foreach (Picture _picture in _album.Pictures) { if (_pathAlbum + "/" + _picture.Name + _picture.Extension == _element.path) { _found = true; } } if (!_found) { _status &= await Delete(_element.path); } } } if (!_status || CancelInProgress()) { return(false); } } //check if all local pictures are synchronized with dropbox pictures int _countParts = 0; foreach (Picture _picture in _album.Pictures) { Boolean _found = false; if (_folderDesc.contents != null) { foreach (ResponseElement _element in _folderDesc.contents) { if (_pathAlbum + "/" + _picture.Name + _picture.Extension == _element.path) { _found = true; } } } if (!_found) { UploadOperation _newUpload = await synchronizePicture(_picture, _pathAlbum, _countParts ++, _summary); if (_newUpload != null) { UploadList.Add(_newUpload); } } if (CancelInProgress()) { return(false); } } return(true); } return(false); }