public static bool DeleteFile(string fileName) { try { indexEntities db = new indexEntities(); var request = (from f in db.files where f.origFileName == fileName select f); file theFile = request.First(); string service = theFile.service; string guid = theFile.guid; db.files.Remove(theFile); db.SaveChanges(); if (service == StorageServices.Dropbox.ToString()) { throw new NotImplementedException(); } else if (service == StorageServices.GoogleDrive.ToString()) { //Google Drive Upload code throw new NotImplementedException(); } else if (service == StorageServices.SkyDrive.ToString()) { SkyDrive.Api.DeleteFile(guid); } else if (service == StorageServices.UbuntuOne.ToString()) { //UbuntuOne Upload code throw new NotImplementedException(); } else if (service == StorageServices.Box.ToString()) { throw new NotImplementedException(); } else { Console.WriteLine("WTF did you do..?!"); return false; } return true; } catch (Exception e) { Console.WriteLine(e.ToString()); return false; } }
public static bool RenameFile(string oldFileName, string newFileName) { try { indexEntities db = new indexEntities(); DateTime newLastModified = System.IO.File.GetLastWriteTime(newFileName); var request = (from f in db.files where f.rootFolder + f.relativeFilePath == oldFileName select f); file theFile = request.First(); theFile.lastModified = newLastModified; theFile.origFileName = newFileName.Split('\\').Last(); theFile.relativeFilePath = newFileName.Replace(theFile.rootFolder, ""); db.SaveChanges(); return true; } catch (Exception e) { Console.WriteLine(e.ToString()); return false; } }
void fileCreated(object sender, FileSystemEventArgs e) { indexEntities db = new indexEntities(); FileInfo info = new FileInfo(e.FullPath); file newFile = new file() { lastModified = info.LastWriteTime, origFileName = info.Name }; foreach (RootFolder folder in FileStructure.Index.IndexRoots) { if (e.FullPath.Contains(folder.RootFolderName)) { newFile.rootFolder = folder.RootFolderName; newFile.relativeFilePath = info.FullName.Replace(folder.RootFolderName, ""); newFile.service = Enum.GetName(typeof(StorageServices), FileStructure.Index.algo.SortingHat(info)); break; } } Exception error; do { error = null; newFile.guid = Guid.NewGuid().ToString(); try { newFile = db.files.Add(newFile); db.SaveChanges(); } catch (Exception ex) { error = ex; } } while (error != null); newFile.serviceFileId = Unity.UploadFile(newFile); db.SaveChanges(); System.Windows.Forms.MessageBox.Show("A file has been uploaded"); }