public FileContents ReadFileContents(string localPath) { if (localPath == null) { throw new ActionException("No file path was provided.", ActionType.File, MemeType.Fuuuuu); } FileIdentity fid = ReadFileMetadata(localPath); string contents = String.Empty; try { StreamReader reader = new StreamReader(localPath); contents = reader.ReadToEnd(); reader.Close(); } catch (Exception ex) { throw new ActionException("Error while reading file data from disk. " + "File path was: '" + localPath + "'.", ActionType.File, ex); } FileContents f = new FileContents(fid, contents); return(f); }
public MapKey(FileContents fileContents) { _fileContents = fileContents; _hashCode = HashCode.Combine( _fileContents.UtcLastModified.GetHashCode(), _fileContents.ByteLength.GetHashCode()); }
public void AddFile(Credentials c, MachineContents m, DirectoryContents d, FileContents f) { GetDirList(c, m); f.Dir = (from o in m.Directories where o.Name == d.Name select o.Id).Single(); if (!CheckFileExistence(c, m, d, f)) { AddFileContent(f); //TypeManipulator.TypeToId(f); File f1 = File.CreateFile(1, f.Dir, 1, f.Content, f.Name, f.Size, f.Hash, f.Uploaded, f.Modified); using (filesyncEntities context = new filesyncEntities()) { context.Files.AddObject(f1); context.SaveChanges(); } } else { GetFileId(c, m, d, f); GetFileContentId(c, m, d, f); UpdateFileContent(f); //TypeManipulator.TypeToId(f); using (filesyncEntities context = new filesyncEntities()) { File f1 = (from o in context.Files where o.file_id == f.Id select o).Single(); f1.file_hash = f.Hash; f1.file_modified = f.Modified; f1.file_size = f.Size; f1.file_uploaded = f.Uploaded; context.SaveChanges(); } } }
// class methods // since the devices are listed within the block, we need to get a list of the for generating the header private List <string> GetIoStatDevices() { int startingLine = FileContents.FindIndex(l => l.StartsWith("Device")) + 1; int deviceColumnNumber = 0; return(new LinuxOutFileHelper().GetDevices(startingLine, FileContents, deviceColumnNumber)); }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { // credit: http://stackoverflow.com/a/263416/677735 unchecked // Overflow is fine, just wrap { int hash = 41; // Suitable nullity checks hash = hash * 59 + Id.GetHashCode(); if (FileName != null) { hash = hash * 59 + FileName.GetHashCode(); } if (FileContents != null) { hash = hash * 59 + FileContents.GetHashCode(); } if (Description != null) { hash = hash * 59 + Description.GetHashCode(); } if (Type != null) { hash = hash * 59 + Type.GetHashCode(); } return(hash); } }
FileReference IFilesCommand.SaveFile(FileType fileType, FileContents fileContents, string fileName) { if (fileContents == null) { throw new ArgumentNullException("fileContents"); } if (string.IsNullOrEmpty(fileName)) { throw new ArgumentException("The file name must be specified.", "fileName"); } // Create the file reference for this file. bool isExistingFile; var fileReference = CreateFileReference(fileType, fileName, fileContents.Type, fileContents.Length, fileContents.Hash, out isExistingFile); // If the file already exists then there is no need to save it. if (!isExistingFile) { _storageRepository.SaveFile(fileContents, fileReference); } return(fileReference); }
private void SaveChanges() { if (_filePath == null) { return; } var fileContents = new FileContents { DefaultEnvironmentName = _defaultEnvironmentName, Environments = _environments, RuleVersions = _ruleVersions, Applications = _applications, Datacenters = _datacenters, DatacenterRules = _datacenterRules }; var content = JsonConvert.SerializeObject(fileContents, Formatting.Indented); try { var fileInfo = new FileInfo(_filePath); using (var stream = fileInfo.Open(FileMode.Create, FileAccess.Write, FileShare.None)) { using (var streamWriter = new StreamWriter(stream)) { streamWriter.Write(content); } } _lastFileTime = fileInfo.LastWriteTimeUtc; } catch { } }
public MyStream(FileContents file, CsvFileSystem fs) { this.file = file; data = file.contents; length = file.contents.Length; this.fs = fs; }
private static int FileComparison(FileContents x, FileContents y) { int nameComparison = x.Name.CompareTo(y.Name); if (nameComparison != 0) { return(nameComparison); } int modifiedComparison = x.Modified.CompareTo(y.Modified); if (modifiedComparison != 0) { return(modifiedComparison); } int sizeComparison = x.Size.CompareTo(y.Size); if (sizeComparison != 0) { return(sizeComparison * (-1)); } int hashComparison = x.Hash.CompareTo(y.Hash); if (hashComparison != 0) { return(hashComparison); } return(0); }
public void As_ascii() { var str = "Test Weird ʣ Character"; var fileContents = new FileContents(Encoding.ASCII.GetBytes(str)); Assert.AreEqual("Test Weird ? Character", fileContents.AsAscii()); Assert.AreEqual("Test Weird ? Character", fileContents.AsUtf8()); }
private void ScrollAndFocus() { //FileContents.Focus(); Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { FileContents.ScrollIntoView(FileContents.SelectedItem); })); }
public bool ValidateFile(string validationType, FileContents fileContents) { Assert.IsNotNullOrWhitespace(validationType, nameof(validationType)); Assert.IsNotNull(fileContents, nameof(fileContents)); var parts = fileContents.Contents.Split(";"); return(parts.Length == 6 && parts[0] == validationType); }
private void AddFile(ClassFile solutionFile, string content) { FileContents fileContents = new FileContents(content); Files.Add(solutionFile, fileContents); Dao.Factory.ClassFileDao .AddFileToSolution(Solution, solutionFile); }
public FileWithContents(FileName fileName, FileContents contents) { if (fileName == null) { throw new ArgumentNullException(nameof(fileName)); } _fileName = fileName; _contents = contents; }
public FileData(FileName fileName, FileContents contents) { if (fileName == null) { throw new ArgumentNullException("fileName"); } _fileName = fileName; _contents = contents; }
private static void UpdateFileContent(FileContents f) { using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { Content c1 = (from o in context.Contents where o.content_id == f.Content select o).Single(); c1.content_data = f.Data; context.SaveChanges(); } }
public FileContents ReadFile(string fileName) { var path = $"{InputFolder}{fileName}"; if (!File.Exists(path)) { throw new FileNotFoundException($"{DateTime.Now}: file \"{fileName}\" is not found in folder \"{InputFolder}\""); } using (var file = File.OpenText(path)) { var inputVariables = new List <string>(); var fileContents = new FileContents(); var rides = new List <Ride>(); var line = file.ReadLine(); var isFirstLine = true; var row = -1; while (line != null) { if (isFirstLine) { inputVariables = line.Split(' ').ToList(); fileContents.Rows = Convert.ToInt32(inputVariables[0]); fileContents.Columns = Convert.ToInt32(inputVariables[1]); fileContents.NumberOfVehicles = Convert.ToInt32(inputVariables[2]); fileContents.NumberOfRides = Convert.ToInt32(inputVariables[3]); fileContents.PerRideBonusForStartingOnTime = Convert.ToInt32(inputVariables[4]); fileContents.NumberOfStepsInSimulation = Convert.ToInt32(inputVariables[5]); } else { var rideParameters = line.Split(' ').ToList(); var ride = new Ride() { StartIntersection = new Tuple <int, int>(Convert.ToInt32(rideParameters[0]), Convert.ToInt32(rideParameters[1])), FinishIntersection = new Tuple <int, int>(Convert.ToInt32(rideParameters[2]), Convert.ToInt32(rideParameters[3])), EarliestStart = Convert.ToInt32(rideParameters[4]), LatestFinish = Convert.ToInt32(rideParameters[5]), RideNumber = row }; rides.Add(ride); } line = file.ReadLine(); isFirstLine = false; row++; } fileContents.Rides = rides; return(fileContents); } }
/// <summary> /// Deletes a key from the INI file /// </summary> /// <param name="Section">Section the key is under</param> /// <param name="Key">Key to remove</param> /// <returns>True if it is removed, false otherwise</returns> public virtual bool DeleteFromINI(string Section, string Key) { bool ReturnValue = false; if (FileContents.ContainsKey(Section) && FileContents[Section].ContainsKey(Key)) { ReturnValue = FileContents[Section].Remove(Key); WriteFile(); } return(ReturnValue); }
private void ApplyFilters() { if (Filters == null) { return; } foreach (string filter in Filters) { FileContents = FileContents.Replace(filter, ""); } }
void WriteIncludes() { string deplist = "CPPDependencies"; WriteIncludes(deplist); string header = "\"" + OutputPath + ".h\""; FileContents.Insert(1, "#include " + header); NewLine(); }
public void GetFileContent(Credentials c, MachineContents m, DirectoryContents d, FileContents f) { f.Id = GetFileContentId(c, m, d, f); using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { Content c1 = (from o in context.Contents where o.content_id == f.Content select o).Single(); f.Data = c1.content_data; } }
/// <summary> /// Deletes a section from the INI file /// </summary> /// <param name="Section">Section to remove</param> /// <returns>True if it is removed, false otherwise</returns> public virtual bool DeleteFromINI(string Section) { bool ReturnValue = false; if (FileContents.ContainsKey(Section)) { ReturnValue = FileContents.Remove(Section); Save(_FileName); } return(ReturnValue); }
public override void UpdateFile(String original, String updated) { foreach (var s in FileContents.Where(itm => itm.Contains(original)).ToList()) { var pos = Array.IndexOf(FileContents, s); if (pos > -1) { FileContents[pos] = FileContents[pos].Replace(original, updated); } } }
public T RunPart <T>(GeneralRunner <T> runner) { var code = FileContents.Split(','); var numbers = new BigInteger[code.Length]; for (int i = 0; i < code.Length; i++) { numbers[i] = BigInteger.Parse(code[i]); } return(runner(numbers)); }
private void AddFileContent(FileContents f) { int AddedContentId; Content f1 = Content.CreateContent(1, f.Data); using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { context.Contents.AddObject(f1); context.SaveChanges(); AddedContentId = (from c in context.Contents select c).ToList().Last().content_id; } f.Content = AddedContentId; }
public void Dispose() { if (!this.isDisposed && FileContents != null) { foreach (var kvp in FileContents.Values) { kvp.Dispose(); } FileContents.Clear(); isDisposed = true; } }
public int RunPart(GeneralRunner runner) { var code = FileContents.Split(','); var numbersOriginal = new int[code.Length]; for (int i = 0; i < code.Length; i++) { numbersOriginal[i] = ToInt32(code[i]); } return(runner(numbersOriginal)); }
private void GetFileId(Credentials c, MachineContents m, DirectoryContents d, FileContents f) { GetDirList(c, m); d.Id = (from o in m.Directories where o.Name == d.Name select o.Id).Single(); using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { int file_id = (from o in context.Files where (o.file_name == f.Name) && (o.dir_id == d.Id) select o.file_id).Single(); f.Id = file_id; } }
private FileContents ReadBannedIpListFile(HttpContext context) { ObjectCache cache = MemoryCache.Default; FileContents fileContents = cache[BLOCKEDIPSKEY] as FileContents; if (fileContents == null) { FileContents tempFileContents = new FileContents(); string cachedFilePath = context.Server.MapPath(FILE_PATH); if (File.Exists(cachedFilePath)) { List <string> filePaths = new List <string>(); filePaths.Add(cachedFilePath); // context.Cache.Insert(BLOCKEDIPSKEY, tempFileContents, new CacheDependency(GetBlockedIPsFilePathFromCurrentContext(context))); CacheItemPolicy policy = new CacheItemPolicy(); policy.AbsoluteExpiration = DateTimeOffset.Now.AddSeconds(Convert.ToDouble(CACHE_EXPIRATION)); policy.ChangeMonitors.Add(new HostFileChangeMonitor(filePaths)); List <string> tempIpv4List = new List <string>(); List <string> tempIpv6List = new List <string>(); // Read the file line by line. using (StreamReader file = new StreamReader(cachedFilePath)) { string line; while ((line = file.ReadLine()) != null) { if (line.Contains(".")) { tempIpv4List.Add(line); } else if (line.Contains(":")) { tempIpv6List.Add(line); } } } tempFileContents.Ipv4Masks = tempIpv4List.ToArray(); tempFileContents.Ipv6Masks = tempIpv6List.ToArray(); cache.Set(BLOCKEDIPSKEY, tempFileContents, policy); } fileContents = tempFileContents; } return(fileContents); }
public void KnowledgePreservesCase() { using (var dir = new TempDirectory()) { var root = dir.Value().FullName; var mem = new FileContents(root, new LocalSyncPipe()); mem.Xml(@"BIG\subdir/file", () => new XDocument(new XElement("root", new XElement("years", new XText("1980's"))))); Assert.Equal( "BIG/subdir/file", new FirstOf <string>(mem.Knowledge()).Value() ); } }
private void SaveChanges() { if (_filePath == null) return; var fileContents = new FileContents { DefaultEnvironmentName = _defaultEnvironmentName, Environments = _environments, RuleVersions = _ruleVersions }; var content = JsonConvert.SerializeObject(fileContents, Formatting.Indented); try { var fileInfo = new FileInfo(_filePath); using (var stream = fileInfo.Open(FileMode.Create, FileAccess.Write, FileShare.None)) { using (var streamWriter = new StreamWriter(stream)) { streamWriter.Write(content); } } _lastFileTime = fileInfo.LastWriteTimeUtc; } catch { } }
public void LoadVimRc3() { // Setup the VimRc contents var contents = new FileContents( "foo", new[] { "set ai" }); _fileSystem.Setup(x => x.GetVimRcDirectories()).Returns(new string[] { "" }).Verifiable(); _fileSystem.Setup(x => x.LoadVimRcContents()).Returns(FSharpOption.Create(contents)).Verifiable(); _vimHost.Setup(x => x.CreateHiddenTextView()).Returns(CreateTextView()); Assert.True(_vim.LoadVimRc()); Assert.True(_vim.VimRcLocalSettings.AutoIndent); _fileSystem.Verify(); }
public void LoadUpdateSettings() { // Setup the VimRc contents var contents = new FileContents( "foo", new[] { "set ai" }); _fileSystem.Setup(x => x.LoadVimRcContents()).Returns(FSharpOption.Create(contents)).Verifiable(); _vimHost.Setup(x => x.CreateHiddenTextView()).Returns(CreateTextView()); Assert.True(_vim.LoadVimRc().IsLoadSucceeded); Assert.True(_vimRaw._vimRcLocalSettings.AutoIndent); _fileSystem.Verify(); }
protected static void SyncGenerateInvoicesToEmail(int[] invoiceIDs, string emailTo, bool isClinicInvoice, bool isBookingInvoice = true) { string originalFile = null; if (isClinicInvoice) originalFile = Letter.GetLettersDirectory() + (isBookingInvoice ? @"InvoiceTemplate.docx" : @"PrivateInvoiceTemplate.docx"); else originalFile = Letter.GetLettersDirectory() + (isBookingInvoice ? @"InvoiceTemplateAC.docx" : @"PrivateInvoiceTemplateAC.docx"); string tmpLettersDirectory = Letter.GetTempLettersDirectory(); Letter.FileContents[] fileContentsList = new Letter.FileContents[invoiceIDs.Length]; for (int i = 0; i < invoiceIDs.Length; i++) { string tmpOutputFile = FileHelper.GetTempFileName(tmpLettersDirectory + "Invoice_" + invoiceIDs[i] + "." + "pdf"); if (isBookingInvoice) GenerateInvoice(invoiceIDs[i], isClinicInvoice, originalFile, tmpOutputFile); else GeneratePrivateInvoice(invoiceIDs[i], isClinicInvoice, originalFile, tmpOutputFile); fileContentsList[i] = new FileContents(System.IO.File.ReadAllBytes(tmpOutputFile), "Invoice_" + invoiceIDs[i] + "." + "pdf"); File.Delete(tmpOutputFile); } Site site = SiteDB.GetSiteByType(!isClinicInvoice ? SiteDB.SiteType.AgedCare : SiteDB.SiteType.Clinic); Email( site.Name, emailTo, "Invoice" + (fileContentsList.Length == 0 ? "" : "s") + " From " + site.Name, "Please find invoice" + (fileContentsList.Length == 0 ? "" : "s") + " attached.<br /><br />Best regards,<br />" + site.Name, true, fileContentsList ); }
public static FileContents Merge(FileContents[] multipleFileContents, string mergedDocName) { if (multipleFileContents.Length == 1) { if (Path.GetExtension(mergedDocName).ToUpper() == ".PDF") { string tmpLettersDirectory = Letter.GetTempLettersDirectory(); if (!System.IO.Directory.Exists(tmpLettersDirectory)) throw new CustomMessageException("Temp letters directory doesn't exist"); string tmpSourceFileName = FileHelper.GetTempFileName(tmpLettersDirectory + multipleFileContents[0].DocName); string tmpDestFileName = FileHelper.GetTempFileName(tmpLettersDirectory + mergedDocName); File.WriteAllBytes(tmpSourceFileName, multipleFileContents[0].Contents); string errorString = string.Empty; OfficeInterop.FormatConverter.WordToPDF(tmpSourceFileName, tmpDestFileName, out errorString); byte[] pdf = File.ReadAllBytes(tmpDestFileName); File.Delete(tmpSourceFileName); File.Delete(tmpDestFileName); return new FileContents(pdf, mergedDocName); } else { return multipleFileContents[0]; } } else if (multipleFileContents.Length > 1) { string tmpLettersDirectory = Letter.GetTempLettersDirectory(); if (!System.IO.Directory.Exists(tmpLettersDirectory)) throw new CustomMessageException("Temp letters directory doesn't exist"); string[] tmpFiles = new string[multipleFileContents.Length]; for (int i = 0; i < multipleFileContents.Length; i++) { string tmpFileName = FileHelper.GetTempFileName(tmpLettersDirectory + multipleFileContents[i].DocName); System.IO.File.WriteAllBytes(tmpFileName, multipleFileContents[i].Contents); tmpFiles[i] = tmpFileName; } string tmpFinalFileName = Letter.MergeMultipleDocuments(tmpFiles, tmpLettersDirectory + System.IO.Path.GetFileName(mergedDocName)); byte[] fileContents = System.IO.File.ReadAllBytes(tmpFinalFileName); foreach (string file in tmpFiles) System.IO.File.Delete(file); System.IO.File.Delete(tmpFinalFileName); return new Letter.FileContents(fileContents, mergedDocName); } else // if (fileContentsList.Length == 0) { return null; } }
/// <summary> /// Show the contents of a cluster-resident object. /// </summary> /// <param name="contents">Contents of the object to display, and error message.</param> /// <param name="cancelled">If true the work was cancelled.</param> private void ShowContents(bool cancelled, FileContents contents) { if (cancelled) return; if (contents.error != null) this.label_title.Text = contents.error; else this.label_title.Text = ""; if (contents.fileContents != null) this.richTextBox_file.Text = contents.fileContents; this.linkCache = contents.links; this.Status("OK", StatusKind.OK); }
private void SetRcContents(params string[] lines) { var contents = new FileContents("foo", lines); _fileSystem.Setup(x => x.LoadVimRcContents()).Returns(FSharpOption.Create(contents)).Verifiable(); }
public static FileContents ConvertContentsToPDF(FileContents fileContents) { string convertedDocName = System.IO.Path.ChangeExtension(fileContents.DocName, ".pdf"); string tmpLettersDirectory = Letter.GetTempLettersDirectory(); if (!System.IO.Directory.Exists(tmpLettersDirectory)) throw new CustomMessageException("Temp letters directory doesn't exist"); string tmpSourceFileName = FileHelper.GetTempFileName(tmpLettersDirectory + fileContents.DocName); string tmpDestFileName = FileHelper.GetTempFileName(tmpLettersDirectory + convertedDocName); File.WriteAllBytes(tmpSourceFileName, fileContents.Contents); string errorString = string.Empty; OfficeInterop.FormatConverter.WordToPDF(tmpSourceFileName, tmpDestFileName, out errorString); byte[] pdf = File.ReadAllBytes(tmpDestFileName); File.Delete(tmpSourceFileName); File.Delete(tmpDestFileName); return new Letter.FileContents(pdf, convertedDocName); }