private bool EvaluateFileMembershipInCluster(InternalFile file, ClusterObject cluster, out double result) { var stringComparisonToolsProxy = Facade.RetrieveProxy<StringComparisonToolsProxy>(Globals.StringComparisonToolsProxy); var avg = 0.0; var count = 0; foreach (var f in cluster.Files) { var currentAvg = stringComparisonToolsProxy.CompareSimilarities(file.CleanFileName, f.CleanFileName); if (currentAvg < MagicEarlyTerminationCoefficient) { result = -1; return false; } avg += currentAvg; count++; } result = avg / count; return result <= MagicMembershipThresholdCoefficient; }
/// <summary> /// Encrypts ands saves a file. /// @Requires: PasswordInput.Password != null && !String.Empty().Equals(PasswordInput.Password) /// </summary> private async void EncryptAndSaveAsync(InternalFile source, StorageFile outputFile) { if (outputFile != null) { Task <Stream> outputStreamTask = outputFile.OpenStreamForWriteAsync(); Stream outputStream = await outputStreamTask; if (outputStream != null) { string password = PasswordInput.Password; PdfAssembler pdfAssembler = new PdfAssembler(outputStream); PageRange pageRange = PageRange.EntireDocument(source.Document); ExportTask task = new ExportTask(pageRange); pdfAssembler.AppendTask(task); pdfAssembler.ExportFileEncrypted(password); loadedFilesList.Remove(source); ToolPage.Current.NotifyUser(String.Empty, NotifyType.StatusMessage); } else { ToolPage.Current.NotifyUser("Error occured while while exporting the merged file. Try again.", NotifyType.ErrorMessage); } } else { ToolPage.Current.NotifyUser("No output file has been selected.", NotifyType.ErrorMessage); } }
public void AddFile(InternalFile file) { lock (_files) { _files.Add(file); } }
/// <summary> /// Copies the file to another directory /// </summary> /// <param name="directory">Directory to copy the file to</param> /// <param name="overwrite">Should the file overwrite another file if found</param> /// <returns>The newly created file</returns> public Task <IFile?> CopyToAsync(IDirectory directory, bool overwrite) { if (directory is null || !Exists || InternalFile is null) { return(Task.FromResult <IFile?>(null)); } return(InternalFile.CopyToAsync(directory, overwrite)); }
/// <summary> /// Writes content to the file /// </summary> /// <param name="Content">Content to write</param> /// <param name="Mode">Mode to open the file as</param> /// <param name="Encoding">Encoding to use for the content</param> /// <returns>The result of the write or original content</returns> public string Write(string Content, System.IO.FileMode Mode = FileMode.Create, Encoding Encoding = null) { if (InternalFile == null) { return(Content); } return(InternalFile.Write(Content, Mode, Encoding)); }
/// <summary> /// Writes content to the file /// </summary> /// <param name="Content">Content to write</param> /// <param name="Mode">Mode to open the file as</param> /// <returns>The result of the write or original content</returns> public byte[] Write(byte[] Content, System.IO.FileMode Mode = FileMode.Create) { if (InternalFile == null) { return(Content); } return(InternalFile.Write(Content, Mode)); }
/// <summary> /// Reads a file as binary /// </summary> /// <returns>The file contents as a byte array</returns> public byte[] ReadBinary() { if (InternalFile == null) { return(new byte[0]); } return(InternalFile.ReadBinary()); }
/// <summary> /// Renames the file /// </summary> /// <param name="NewName">New name for the file</param> public void Rename(string NewName) { if (InternalFile == null || string.IsNullOrEmpty(NewName)) { return; } InternalFile.Rename(NewName); }
/// <summary> /// Reads the file in as a string /// </summary> /// <returns>The file contents as a string</returns> public string Read() { if (InternalFile == null) { return(""); } return(InternalFile.Read()); }
/// <summary> /// Moves the file to a new directory /// </summary> /// <param name="Directory">Directory to move to</param> public void MoveTo(IDirectory Directory) { if (InternalFile == null || Directory == null) { return; } InternalFile.MoveTo(Directory); }
/// <summary> /// Deletes the file /// </summary> /// <returns>Any response for deleting the resource (usually FTP, HTTP, etc)</returns> public string Delete() { if (InternalFile == null) { return(""); } return(InternalFile.Delete()); }
/// <summary> /// Copies the file to another directory /// </summary> /// <param name="directory">Directory to copy the file to</param> /// <param name="overwrite">Should the file overwrite another file if found</param> /// <returns>The newly created file</returns> public IFile?CopyTo(IDirectory directory, bool overwrite) { if (directory is null || !Exists) { return(null); } return(InternalFile?.CopyTo(directory, overwrite)); }
/// <summary> /// Deletes the file /// </summary> /// <returns>Any response for deleting the resource (usually FTP, HTTP, etc)</returns> public string Delete() { if (InternalFile is null) { return(string.Empty); } return(InternalFile.Delete()); }
/// <summary> /// Writes content to the file /// </summary> /// <param name="content">Content to write</param> /// <param name="mode">Mode to open the file as</param> /// <returns>The result of the write or original content</returns> public byte[] Write(byte[] content, FileMode mode = FileMode.Create) { if (InternalFile is null) { return(content); } return(InternalFile.Write(content, mode)); }
/// <summary> /// Writes content to the file /// </summary> /// <param name="content">Content to write</param> /// <param name="mode">File mode</param> /// <returns>The result of the write or original content</returns> public Task <byte[]> WriteAsync(byte[] content, FileMode mode = FileMode.Create) { if (InternalFile is null) { return(Task.FromResult(content)); } return(InternalFile.WriteAsync(content, mode)); }
/// <summary> /// Writes content to the file /// </summary> /// <param name="content">Content to write</param> /// <param name="mode">Mode to open the file as</param> /// <param name="encoding">Encoding to use for the content</param> /// <returns>The result of the write or original content</returns> public string Write(string content, FileMode mode = FileMode.Create, Encoding?encoding = null) { if (InternalFile is null) { return(content); } return(InternalFile.Write(content, mode, encoding)); }
/// <summary> /// Reads the file to the end as a byte array /// </summary> /// <returns>A byte array containing the contents of the file</returns> public Task <byte[]> ReadBinaryAsync() { if (InternalFile is null) { return(Task.FromResult(Array.Empty <byte>())); } return(InternalFile.ReadBinaryAsync()); }
/// <summary> /// Reads the file to the end as a string /// </summary> /// <returns>A string containing the contents of the file</returns> public Task <string> ReadAsync() { if (InternalFile is null) { return(Task.FromResult(string.Empty)); } return(InternalFile.ReadAsync()); }
/// <summary> /// Reads a file as binary /// </summary> /// <returns>The file contents as a byte array</returns> public byte[] ReadBinary() { if (InternalFile is null) { return(Array.Empty <byte>()); } return(InternalFile.ReadBinary()); }
/// <summary> /// Reads the file in as a string /// </summary> /// <returns>The file contents as a string</returns> public string Read() { if (InternalFile is null) { return(string.Empty); } return(InternalFile.Read()); }
/// <summary> /// Copies the file to another directory /// </summary> /// <param name="Directory">Directory to copy the file to</param> /// <param name="Overwrite">Should the file overwrite another file if found</param> /// <returns>The newly created file</returns> public IFile CopyTo(IDirectory Directory, bool Overwrite) { if (Directory == null || !Exists) { return(null); } return(InternalFile.CopyTo(Directory, Overwrite)); }
/// <summary> /// Writes content to the file /// </summary> /// <param name="content">Content to write</param> /// <param name="mode">File mode</param> /// <param name="encoding">Encoding that the content should be saved as (default is UTF8)</param> /// <returns>The result of the write or original content</returns> public Task <string> WriteAsync(string content, FileMode mode = FileMode.Create, Encoding?encoding = null) { if (InternalFile is null) { return(Task.FromResult(content)); } return(InternalFile.WriteAsync(content, mode, encoding)); }
/// <summary> /// Moves the file to a new directory /// </summary> /// <param name="directory">Directory to move to</param> public IFile MoveTo(IDirectory directory) { if (InternalFile is null || directory is null) { return(this); } InternalFile.MoveTo(directory); return(this); }
/// <summary> /// Renames the file /// </summary> /// <param name="newName">New name for the file</param> public IFile Rename(string newName) { if (InternalFile is null || string.IsNullOrEmpty(newName)) { return(this); } InternalFile.Rename(newName); return(this); }
/// <summary> /// Reads the file in as a string /// </summary> /// <returns>The file contents as a string</returns> public override string Read() { if (!Exists) { return(string.Empty); } using var Reader = InternalFile.OpenText(); return(Reader.ReadToEnd()); }
public void Delete() { if (!Exists) { return; } InternalFile.Delete(); InternalFile.Refresh(); }
/// <summary> /// Renames the file /// </summary> /// <param name="NewName">New name for the file</param> public override void Rename(string NewName) { if (string.IsNullOrEmpty(NewName) || !Exists) { return; } InternalFile.MoveTo(InternalFile.DirectoryName + "\\" + NewName); InternalFile = new System.IO.FileInfo(InternalFile.DirectoryName + "\\" + NewName); }
/// <summary> /// Renames the file /// </summary> /// <param name="newName">New name for the file</param> public override IFile Rename(string newName) { if (string.IsNullOrEmpty(newName) || !Exists) { return(this); } InternalFile.MoveTo(InternalFile.DirectoryName + "\\" + newName); InternalFile = new System.IO.FileInfo(InternalFile.DirectoryName + "\\" + newName); return(this); }
/// <summary> /// Renames the file /// </summary> /// <param name="newName">New file name</param> /// <returns></returns> public async Task <IFile> RenameAsync(string newName) { if (InternalFile is null || string.IsNullOrEmpty(newName)) { return(this); } await InternalFile.RenameAsync(newName).ConfigureAwait(false); return(this); }
/// <summary> /// Moves the file to another directory /// </summary> /// <param name="directory">Directory to move the file to</param> /// <returns></returns> public async Task <IFile> MoveToAsync(IDirectory directory) { if (InternalFile is null || directory is null) { return(this); } await InternalFile.MoveToAsync(directory).ConfigureAwait(false); return(this); }
/// <summary> /// Moves the file to a new directory /// </summary> /// <param name="Directory">Directory to move to</param> public override void MoveTo(IDirectory Directory) { if (Directory == null || !Exists) { return; } Directory.Create(); InternalFile.MoveTo(Directory.FullName + "\\" + Name); InternalFile = new System.IO.FileInfo(Directory.FullName + "\\" + Name); }
/// <summary> /// Deletes the file /// </summary> /// <returns>Any response for deleting the resource (usually FTP, HTTP, etc)</returns> public override string Delete() { if (!Exists) { return(""); } InternalFile.Delete(); InternalFile.Refresh(); return(""); }
private void HashFileFnv(InternalFile file) { var digest = new FnvMessageDigest(); using (Stream stream = File.OpenRead(file.FilePath)) { digest.Update(stream); } digest.DoFinal(); Facade.RetrieveProxy<FileHashProxy>(Globals.FileHashProxy).AddFileHashEntry(digest, file); }
public QuickSampleMessageDigest(InternalFile file) { _file = file; _lazyHashCode = new Lazy<HashCode>(CalculateHashCode); _fileLength = new Lazy<long>(CalculateFileLength); }
public void AddFile(InternalFile file) { if (_sealed) throw new InvalidOperationException("Cannot add files when Internal File Proxy is sealed"); _internalFiles.Add(file); }