Example #1
0
        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;
            }
        }
Example #2
0
        public static bool DownloadFile(string guid, string downloadLocation)
        {
            indexEntities db = new indexEntities();
            file dbFile = (from f in db.files
                         where f.guid == guid
                         select f).First();

            string serviceStr = dbFile.service;

            bool result = true;
            StorageServices service = (StorageServices)Enum.Parse(typeof(StorageServices), serviceStr);
            if (guid != "" && service != StorageServices.Empty)
            {
                try
                {
                    switch (service)
                    {
                        case StorageServices.Dropbox:
                            var file = DropboxApi.Api.DownloadFile("sandbox", guid);
                            file.Save(dbFile.origFileName);
                            break;
                        case StorageServices.GoogleDrive:
                            throw new NotImplementedException();
                        case StorageServices.SkyDrive:
                            SkyDrive.Api.DownloadFile(guid);
                            break;
                        case StorageServices.UbuntuOne:
                            throw new NotImplementedException();
                        case StorageServices.Box:
                            throw new NotImplementedException();
                        default:
                            throw new Exception("how'd you manage that one?");
                    }
                }
                catch (Exception)
                {
                    result = false;
                }
            }
            else
            {
                MessageBox.Show("GUID does not exist!");
                return false;
            }

            return result;
        }
        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");
        }
Example #4
0
        public static bool UpdateFile(string filePath)
        {
            if (!System.IO.File.Exists(filePath))
                return false;

            string[] paths = filePath.Split('\\');
            string filename = paths.Last();

            indexEntities db = new indexEntities();
            file uploadFile = (from f in db.files
                               where (f.rootFolder + f.relativeFilePath) == filePath
                               select f).First();

            return UpdateFile(uploadFile);
        }
Example #5
0
        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;
            }
        }
Example #6
0
        private static void DownloadFileHelper(object sender, LiveOperationCompletedEventArgs e)
        {
            string clientDirectory = "C:\\UltiDrive\\";

            indexEntities db = new indexEntities();
            string guidToDownload = (string)guidToDownloadQueue.Dequeue();
            var request = from f in db.files
                          where f.guid == guidToDownload
                          select f.origFileName;

            string originalPath = request.First().ToString();

            string originalFileName = originalPath.Split('\\').Last();

            try
            {
                JavaScriptSerializer ser = new JavaScriptSerializer();
                Files.RootObject data = ser.Deserialize<Files.RootObject>(e.RawResult);

                foreach (Files.Datum listItem in data.data)
                {
                    if (listItem.name == guidToDownload)
                    {
                        LiveConnectClient client = new LiveConnectClient(Properties.session);

                        client.DownloadCompleted += UltiDrive.SkyDrive.Utilities.ConnectClient_DownloadCompleted;
                        string path = clientDirectory + originalFileName;
                        client.DownloadAsync(listItem.id + "/content", path);
                    }
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine("SkyDriveApi.DownloadFile() failed. --> " + ex.ToString());
            }
        }