Ejemplo n.º 1
0
        public int WriteFile(string filename, byte[] buffer, ref uint writtenBytes, long offset, DokanFileInfo info)
        {
            WriteTrace("writefile", filename, offset);

            StartCommunication();

            FileUploader fileUploader = info.Context as FileUploader;

            if (fileUploader == null)
            {
                WriteTrace("writefile", filename, "no uploader found");
                return(-DokanNet.ERROR_ACCESS_DENIED);
            }

            DokanNet.DokanResetTimeout(1000 * 30, info);

            fileUploader.WriteAsync(buffer).Wait();

            writtenBytes = (uint)buffer.Length;

            if (fileUploader.IsFinished())
            {
                OnUploadComplete(fileUploader, filename);
            }

            WriteTrace("writefile", filename, writtenBytes, fileUploader.Id, fileUploader.IsFinished());

            return(DokanNet.DOKAN_SUCCESS);
        }
Ejemplo n.º 2
0
        public int SetEndOfFile(string filename, long length, DokanFileInfo info)
        {
            WriteTrace("setendoffile", filename, length);

            FileUploader fileUploader = info.Context as FileUploader;

            if (fileUploader != null)
            {
                fileUploader.Size = length;
            }

            return(DokanNet.DOKAN_SUCCESS);
        }
Ejemplo n.º 3
0
        public int CloseFile(string filename, DokanFileInfo info)
        {
            WriteTrace("closefile", filename);

            FileUploader fileUploader = info.Context as FileUploader;

            if (fileUploader != null && fileUploader.IsFinished())
            {
                OnUploadComplete(fileUploader, filename);
            }

            return(DokanNet.DOKAN_SUCCESS);
        }
Ejemplo n.º 4
0
        public int SetAllocationSize(string filename, long length, DokanFileInfo info)
        {
            WriteTrace("setallocationsize", filename, length);

            FileUploader fileUploader = info.Context as FileUploader;

            if (fileUploader != null)
            {
                fileUploader.Size = length;
                WriteTrace("setallocationsize", filename, fileUploader.Id, fileUploader.Size);
            }

            return(DokanNet.DOKAN_SUCCESS);
        }
Ejemplo n.º 5
0
        private void OnUploadComplete(FileUploader fileUploader, string filename)
        {
            FileReferences fileReference = files.Value.GetFolderReference(filename);

            if (fileUploader == null || fileReference == null)
            {
                EndCommunication();
                return;
            }

            if (fileReference.Name != fileUploader.FileName && fileReference.IsFolder())
            {
                FileReferences newFileReference = new FileReferences {
                    Name = fileUploader.FileName
                };
                fileReference.Children.Add(newFileReference);

                fileReference = newFileReference;
            }

            fileReference.Size = fileUploader.Size;
            fileReference.Date = DateTime.Now;
            fileReference.Hash = FileReferences.UNKNOWN_FILE_HASH;
            fileReference.Key  = FileReferences.UNKNOWN_FILE_HASH;

            PersistFileReferences();

            Task.Factory.StartNew(() =>
            {
                UploadedFile cloudFile = fileUploader.Close().Result;

                if (cloudFile == null)
                {
                    EndCommunication();
                    return;
                }

                fileReference.Hash = cloudFile.FileHash;
                fileReference.Key  = cloudFile.Key;

                PersistFileReferences();

                EndCommunication();
            });
        }
Ejemplo n.º 6
0
        private void OnUploadComplete(FileUploader fileUploader, string filename)
        {
            FileReferences fileReference = files.Value.GetFolderReference(filename);

            if (fileUploader == null || fileReference == null)
            {
                EndCommunication();
                return;
            }

            if (fileReference.Name != fileUploader.FileName && fileReference.IsFolder())
            {
                FileReferences newFileReference = new FileReferences { Name = fileUploader.FileName };
                fileReference.Children.Add(newFileReference);

                fileReference = newFileReference;
            }

            fileReference.Size = fileUploader.Size;
            fileReference.Date = DateTime.Now;
            fileReference.Hash = FileReferences.UNKNOWN_FILE_HASH;
            fileReference.Key = FileReferences.UNKNOWN_FILE_HASH;

            PersistFileReferences();

            Task.Factory.StartNew(() =>
            {
                UploadedFile cloudFile = fileUploader.Close().Result;

                if (cloudFile == null)
                {
                    EndCommunication();
                    return;
                }

                fileReference.Hash = cloudFile.FileHash;
                fileReference.Key = cloudFile.Key;

                PersistFileReferences();

                EndCommunication();
            });
        }