コード例 #1
0
ファイル: FDOperationQueue.cs プロジェクト: fardog/snowpack
 public void Add(FDQueueItem item)
 {
     if(item.status == FDItemStatus.QueuedUpload)
         uploadQueue.Enqueue(item);
     else if(item.status == FDItemStatus.QueuedDownload)
         downloadQueue.Enqueue(item);
     else
         throw new System.NotImplementedException("Queue doesn't yet support this item status");
 }
コード例 #2
0
ファイル: FDDataStore.cs プロジェクト: fardog/snowpack
 public int StoreQueue(FDQueueItem item)
 {
     return 0;
 }
コード例 #3
0
ファイル: FDOperationQueue.cs プロジェクト: fardog/snowpack
        public void ProcessFileUpload(string fileName)
        {
            FileAttributes attr = File.GetAttributes(fileName);
            //TODO handle non-file items (like devices)
            if ((attr & FileAttributes.Directory) == FileAttributes.Directory) { //we're on a directory, process it recursively
                foreach ( string f in Directory.GetFiles(fileName) ) //handle files first
                    this.ProcessFileUpload (f);
                foreach ( string d in Directory.GetDirectories(fileName) ) //then directories
                    this.ProcessFileUpload (d);
                return; //if we're done processing all contents, return
            }

            //Build our temporary item for upload
            FDQueueItem item = new FDQueueItem(fileName, FileAttributes.Normal, FDItemStatus.Uploading);
            try
            {
                item.info = new System.IO.FileInfo(item.path);
            }
            catch (Exception e)
            {
                log.Store (this.ToString(),
                           "Failed to get file info on " + item.path,
                           "Exception info was: " + e.Message,
                           FDLogVerbosity.Error);
            }

            //our file is zero bytes, Glacier won't accept it but we still want to remember that it existed
            if (item.info.Length == 0)
            {
                DataStore.InsertFile(item.path,
                                     "0",
                                     item.info.Length,
                                     item.info.LastWriteTimeUtc,
                                     "0");
                return;
            }

            //set the current file name for communication with the frontend
            UploadFile = Path.GetFileName(item.path);

            //Calculate the file's checksum before upload, so we can check if it's uploaded before
            FDChecksum fileChecksum = new FDChecksum(item.path);
            try
            {
                fileChecksum.CalculateChecksum();
            }
            catch (Exception e)
            {
                log.Store (this.ToString(),
                           "Failed to checksum on " + item.path,
                           "Exception info was: " + e.Message,
                           FDLogVerbosity.Error);
                return;
            }
            item.checksum = fileChecksum.checksum;

            //Verfiy we haven't uploaded previously by comparing checksum + filesize to db
            string archiveId = DataStore.CheckExists(item.checksum, item.info.Length);

            //if we got a response, re-insert the file to db to be remembered and advance queue
            if (!String.IsNullOrEmpty(archiveId))
            {
                DataStore.InsertFile(item.path,
                                     item.checksum,
                                     item.info.Length,
                                     item.info.LastWriteTimeUtc,
                                     archiveId);
                return;
            }

            //If we've made it this far, we're ready to upload the file
            item.glacier = new FDGlacier(settings, log, "upload");
            item.glacier.archiveDescription = System.IO.Path.GetFileName (item.path);
            item.glacier.setCallback(this._uploadProgress);
            try
            {
                item.glacier.uploadFile(item.path);
            }
            catch (Exception e)
            {
                log.Store(this.ToString(),
                          "Failed to upload on " + item.path,
                          "Exception info was: " + e.Message,
                          FDLogVerbosity.Error);
                return;
            }

            //Store the result to db
            DataStore.InsertFile(item.path,
                                 item.checksum,
                                 item.info.Length,
                                 item.info.LastWriteTimeUtc,
                                 item.glacier.result.ArchiveId);
        }
コード例 #4
0
ファイル: FDOperationQueue.cs プロジェクト: fardog/snowpack
 public void ProcessFileDownload(FDQueueItem item)
 {
     if(item.kind != System.IO.FileAttributes.Normal)
     {
         throw new Exception("Recursive downloads aren't supported yet.");
         return;
     }
     Console.WriteLine("Archive ID was: " + item.archiveID);
     item.glacier = new FDGlacier(settings, log, "download");
     item.glacier.archiveID = item.archiveID;
     item.glacier.setCallback(this._downloadProgress);
     item.glacier.RequestArchive(item.downloadPath);
 }
コード例 #5
0
ファイル: FDQueueView.cs プロジェクト: fardog/snowpack
    protected void enqueueUpload(string filePath)
    {
        FileAttributes attr = File.GetAttributes(filePath);

        //Add to the OperationQueue
        FDQueueItem addItem = new FDQueueItem(filePath, attr, FDItemStatus.QueuedUpload);
        operationQueue.Add (addItem);

        //Add to the queue view
        TreeIter iter = uploadQueue.AppendValues(new Gdk.Pixbuf(null, "snowpack.assets.upload.png"), filePath, "", addItem.guid);
        ListItem item = new ListItem(filePath, addItem.progress, addItem.guid, iter);
        this.items.Add (item);
    }
コード例 #6
0
ファイル: FDQueueView.cs プロジェクト: fardog/snowpack
    protected void enqueueDownload(string filePath, FileAttributes fileType, string restoreTo, string archiveID = null)
    {
        //add to the operationqueue
        FDQueueItem addItem = new FDQueueItem(filePath, fileType, FDItemStatus.QueuedDownload);
        addItem.archiveID = archiveID;
        addItem.downloadPath = restoreTo;
        operationQueue.Add (addItem);

        //add to the queue view
        TreeIter iter = uploadQueue.AppendValues(new Gdk.Pixbuf(null, "snowpack.assets.download.png"), filePath, "", addItem.guid);
        ListItem item = new ListItem(filePath, addItem.progress, addItem.guid, iter);
        this.items.Add (item);
    }