protected void SaveTextFile(ref string FileName, string title, Entry entry, ManagedArray data) { TextSaver.Title = title; TextSaver.SelectFilename(FileName); string directory; // Add most recent directory if (!string.IsNullOrEmpty(TextSaver.Filename)) { directory = System.IO.Path.GetDirectoryName(TextSaver.Filename); if (Directory.Exists(directory)) { TextSaver.SetCurrentFolder(directory); } } if (TextSaver.Run() == (int)ResponseType.Accept) { if (!string.IsNullOrEmpty(TextSaver.Filename)) { FileName = TextSaver.Filename; directory = GetDirectory(FileName); var ext = TextSaver.Filter.Name; FileName = String.Format("{0}.{1}", GetBaseFileName(FileName), ext); if (data != null) { var current = DelimiterBox.Active; var delimiter = current >= 0 && current < Delimiters.Count ? Delimiters[current].Character : '\t'; var fullpath = String.Format("{0}/{1}", directory, FileName); try { ManagedFile.Save2D(fullpath, data, delimiter); FileName = fullpath; entry.Text = FileName; } catch (Exception ex) { Console.WriteLine("Error saving {0}: {1}", FileName, ex.Message); } } } } TextSaver.Hide(); }
/// <summary> /// Read palette for specified record. /// </summary> /// <param name="Index">Index of palette.</param> private void ReadPalette(int Index) { // Read palette data if not already stored if (null == Palettes[Index]) { BinaryReader Reader = ManagedFile.GetReader(PaletteDataPosition + (776 * Index) + 8); Palettes[Index] = new DFPalette(); Palettes[Index].Read(ref Reader); } }
public static void ResetTasksForFile(ManagedFile file, CatalogRecord record, ApplicationDbContext db) { var tasks = db.TaskStatuses.Where(x => x.File.Id == file.Id).ToList(); foreach (var task in tasks) { task.IsComplete = false; task.CompletedBy = null; task.CompletedDate = null; } }
public void Run(CatalogRecord record, ManagedFile file, ApplicationUser user, ApplicationDbContext db, string processingDirectory, string agencyId) { if (string.IsNullOrWhiteSpace(agencyId)) { agencyId = "int.example"; } VersionableBase.DefaultAgencyId = agencyId; // Set SPSS path. string spssPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory); SpssRaw.Instance.Initialize(spssPath); var existingPhysicalInstance = GetExistingPhysicalInstance(file, agencyId); string path = Path.Combine(processingDirectory, file.Name); string errorMessage = string.Empty; // Create the PhysicalInstance // Calculate the summary statistics. if (file.Name.EndsWith(".dta")) { errorMessage = CreateOrUpdatePhysicalInstanceForFile <StataImporter>(file.Id, path, agencyId, existingPhysicalInstance); } if (file.Name.EndsWith(".sav")) { errorMessage = CreateOrUpdatePhysicalInstanceForFile <SpssImporter>(file.Id, path, agencyId, existingPhysicalInstance); } if (file.Name.EndsWith(".csv")) { errorMessage = CreateOrUpdatePhysicalInstanceForFile <CsvImporter>(file.Id, path, agencyId, existingPhysicalInstance); } if (file.Name.EndsWith(".rdata") || file.Name.EndsWith(".rda")) { errorMessage = CreateOrUpdatePhysicalInstanceForFile <RDataImporter>(file.Id, path, agencyId, existingPhysicalInstance); } // Log any errors. if (!string.IsNullOrWhiteSpace(errorMessage)) { var note = new Data.Note() { CatalogRecord = file.CatalogRecord, File = file, Timestamp = DateTime.UtcNow, User = user, Text = errorMessage }; db.Notes.Add(note); db.SaveChanges(); } }
public VideoFileOperationCoroutine(ManagedFile baseFile, VideoArchiveAction fileAction = VideoArchiveAction.NoAction) { if (baseFile == null) { throw new ArgumentNullException("baseFile"); } BaseFile = baseFile; desiredFileAction = fileAction; acceptedFileAction = VideoArchiveAction.NoAction; IoC.BuildUp(this); }
public void Map(ManagedFile file, OtherMaterial material) { if (file == null) { throw new ArgumentNullException("file"); } if (material == null) { throw new ArgumentNullException("material"); } material.Identifier = file.Id; material.SetUserId("FileNumber", file.Number?.ToString()); material.DublinCoreMetadata.Title.Current = file.Title; material.DublinCoreMetadata.AlternateTitle.Current = file.PublicName; Uri uri = null; bool gotUri = Uri.TryCreate(file.PersistentLink, UriKind.RelativeOrAbsolute, out uri); if (gotUri) { material.UrlReference = uri; } material.SetUserId("PersistentLinkDate", file.PersistentLinkDate?.ToString()); material.SetUserId("Version", file.Version.ToString()); material.SetUserId("Type", file.Type); material.SetUserId("FormatName", file.FormatName); material.SetUserId("FormatId", file.FormatId); material.SetUserId("Size", file.Size.ToString()); material.SetUserId("CreationDate", file.CreationDate?.ToString()); material.SetUserId("KindOfData", file.KindOfData); material.DublinCoreMetadata.Source.Current = file.Source; material.SetUserId("SourceInformation", file.SourceInformation); material.DublinCoreMetadata.Rights.Current = file.Rights; material.SetUserId("IsPublicAccess", file.IsPublicAccess.ToString()); material.SetUserId("UploadedDate", file.UploadedDate?.ToString()); material.SetUserId("ExternalDatabase", file.ExternalDatabase); material.SetUserId("Software", file.Software); material.SetUserId("SoftwareVersion", file.SoftwareVersion); material.SetUserId("Hardware", file.Hardware); material.SetUserId("Checksum", file.Checksum); material.SetUserId("ChecksumMethod", file.ChecksumMethod); material.SetUserId("ChecksumDate", file.ChecksumDate?.ToString()); material.SetUserId("VirusCheckOutcome", file.VirusCheckOutcome); material.SetUserId("VirusCheckMethod", file.VirusCheckMethod); material.SetUserId("VirusCheckDate", file.VirusCheckDate?.ToString()); material.SetUserId("AcceptedDate", file.AcceptedDate?.ToString()); material.SetUserId("CertifiedDate", file.CertifiedDate?.ToString()); }
public override void SaveAs(object param) { var oldName = string.Empty; if (_file != null) { oldName = _file.FileName; } _file = DialogManager.SaveFileAs(_document.Text); SystemLog.Instance.LogInfo($"Saving file as...From {oldName} to {_file.FileName}"); }
/// <summary> /// Loads a texture file. /// </summary> /// <param name="FilePath">Absolute path to TEXTURE.* file</param> /// <param name="Usage">Specify if file will be accessed from disk, or loaded into RAM.</param> /// <param name="ReadOnly">File will be read-only if true, read-write if false.</param> /// <returns>True if successful, otherwise false.</returns> public override bool Load(string FilePath, FileUsage Usage, bool ReadOnly) { // Exit if this file already loaded if (ManagedFile.FilePath == FilePath) { return(true); } // Validate filename FilePath = FilePath.ToUpper(); string fn = Path.GetFileName(FilePath); if (!fn.StartsWith("TEXTURE.")) { return(false); } // Handle unsupported files if (!IsFilenameSupported(fn)) { Console.WriteLine(string.Format("{0} is unsupported.", fn)); return(false); } // Handle solid types if (fn == "TEXTURE.000") { SolidType = SolidTypes.SolidColoursA; } else if (fn == "TEXTURE.001") { SolidType = SolidTypes.SolidColoursB; } else { SolidType = SolidTypes.None; } // Load file if (!ManagedFile.Load(FilePath, Usage, ReadOnly)) { return(false); } // Read file if (!Read()) { return(false); } return(true); }
public async Task UpdateManagedFile(ManagedFile managedFile, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); var entity = await _managedFileRepository.GetById(managedFile.Id, cancellationToken); if (entity != null) { entity.FileName = managedFile.FileName; entity.File = managedFile.File; await _managedFileRepository.Update(entity, cancellationToken); } }
private Settings LoadSettings() { _file = ManagedFile.Create(_settingsPath); if (_file.Load().Length > 0) { return(_file.Load <Settings>()); } else { var settings = new Settings(); _file.Save <Settings>(Settings); return(settings); } }
public static PhysicalInstance GetPhysicalInstance(ManagedFile file, string agencyID) { var client = RepositoryHelper.GetClient(); var pi = client.GetLatestItem(file.Id, agencyID) as PhysicalInstance; var populator = new GraphPopulator(client); populator.ChildProcessing = ChildReferenceProcessing.PopulateLatest; pi.Accept(populator); return(pi); }
public ManagedFile GetManagedFile(string fichierFullPath) { Func <string, string> supressExtension = delegate(string fileName) { var rep = Path.GetDirectoryName(fileName); var fil1 = Path.GetFileNameWithoutExtension(fileName); var ret1 = Path.Combine(rep, fil1); LogManager.Current.Debug($"NbzPut.GetManagerFile.supressExtension - FileName: {ret1}"); return(ret1); }; Func <string, ManagedFile> getSecondExtension = delegate(string fileName) { var ret1 = Path.GetExtension(supressExtension(fichierFullPath)); var ret2 = ManagedFile.Other; if (ret1.StartsWith(".ZIP", StringComparison.OrdinalIgnoreCase)) { ret2 = ManagedFile.Zip; } else if (ret1.StartsWith(".NZB", StringComparison.OrdinalIgnoreCase)) { ret2 = ManagedFile.Nzb; } LogManager.Current.Debug($"NbzPut.GetManagerFile.getSecondExtension - Extension: {ret1} - {ret2}"); return(ret2); }; ManagedFile retour = ManagedFile.Other; var extension = Path.GetExtension(fichierFullPath).ToUpperInvariant(); LogManager.Current.Debug($"NbzPut.GetManagerFile - Extension: {extension}"); switch (extension) { case ".NZB": retour = ManagedFile.Nzb; break; case ".ZIP": retour = ManagedFile.Zip; break; case ".TXT": retour = getSecondExtension(fichierFullPath); break; } return(retour); }
public static void AddProcessingTasksForFile(ManagedFile file, CatalogRecord record, ApplicationDbContext db, bool addAllDataTasks = false, bool addAllCodeTasks = false) { // Don't add tasks for the auto-generated CSV file. if (file.Source == "Curation System") { return; } foreach (var task in MefConfig.AddinManager.AllTasks) { bool goAhead = false; if (addAllDataTasks && task.IsForDataFiles) { goAhead = true; } else if (addAllCodeTasks && task.IsForCodeFiles) { goAhead = true; } else if (task.AppliesToFile(file)) { goAhead = true; } if (!goAhead) { continue; } // If the task already exists, don't add it again. if (db.TaskStatuses.Any(x => x.TaskId == task.Id && x.CatalogRecord.Id == record.Id && x.File.Id == file.Id)) { continue; } var status = new TaskStatus() { Id = Guid.NewGuid(), TaskId = task.Id, CatalogRecord = record, File = file, Name = task.Name, Weight = task.Weight, StageName = "Processing" }; db.TaskStatuses.Add(status); } }
/// <summary> /// Reads image data. /// </summary> /// <param name="Index">Index of image.</param> private bool ReadImageData(int Index) { // Read image if not already stored if (null == Bitmaps[Index].Data) { BinaryReader Reader = ManagedFile.GetReader(ImageDataPosition + (FrameDataLength * Index)); Bitmaps[Index].Width = FrameWidth; Bitmaps[Index].Height = FrameHeight; Bitmaps[Index].Stride = FrameWidth; Bitmaps[Index].Format = DFBitmap.Formats.Indexed; Bitmaps[Index].Data = Reader.ReadBytes(FrameDataLength); } return(true); }
private void WriteCache(string path, string text) { if (_cache.ContainsKey(path)) { var file = _cache[path].Item1; _cache[path] = Tuple.Create(file, text); file.Save(text); } else { var file = ManagedFile.Create(path); _cache.Add(path, Tuple.Create(file, text)); file.Save(text); } }
/////////////////////// /// private methods /// /////////////////// private string ReadCache(string path) { if (_cache.ContainsKey(path)) { return(_cache[path].Item2); } else { var file = ManagedFile.Create(path); var contents = file.Load(); file.Changed += File_Changed; _cache[path] = Tuple.Create(file, contents); return(contents); } }
public void CompareFiles() { foreach (ManagedFile patchFile in PatchFiles) { string fullpath = CurrentProfile.ClientFolder + patchFile.Basepath + patchFile.Filename; FileScanned(this, new ScanEventArgs(patchFile.Filename)); //Tells the form to update the progress bar var localFile = new ManagedFile(fullpath); localFile.ComputeHash(); if (patchFile.MyHash != localFile.MyHash) { downloadFiles.Add(localFile); localFile.Length = patchFile.Length; } } }
public static bool FileHasAllCodeTasks(ManagedFile file, CatalogRecord record, ApplicationDbContext db) { foreach (var task in MefConfig.AddinManager.AllTasks) { if (task.IsForCodeFiles) { if (!db.TaskStatuses.Any(x => x.TaskId == task.Id && x.CatalogRecord.Id == record.Id && x.File.Id == file.Id)) { return(false); } } } return(true); }
public static bool IsStataDataFile(this ManagedFile file) { if (string.IsNullOrWhiteSpace(file.Name)) { return(false); } string lower = file.Name.ToLower(); if (lower.EndsWith(".dta")) { return(true); } return(false); }
/// <summary> /// Read file. /// </summary> /// <returns>True if succeeded, otherwise false.</returns> private bool Read() { try { // Step through file BinaryReader reader = ManagedFile.GetReader(); ReadRecords(ref reader); } catch (Exception e) { Console.WriteLine(e.Message); return(false); } return(true); }
public CodeEditorViewModel(ManagedFile file) { SystemLog.Instance.LogInfo($"Opening file...{file.FileName}"); _file = file; if (_file != null) { Document.Text = _file.Load(); Title = _file.FileName; ContentId = $"file://{_file.FullPath}"; SyntaxHighlighting = HighlightingManager.Instance.GetDefinitionByExtension( _file.Extension ); Title = _file.FileName + $" - ({SyntaxHighlighting.Name})"; initialLoad = true; } }
ActionResult Download(Guid id, bool inline) { using (var db = ApplicationDbContext.Create()) { ManagedFile file = db.Files.Where(x => x.Id == id) .Include(x => x.CatalogRecord) .Include(x => x.CatalogRecord.Organization).FirstOrDefault(); if (file == null) { //TODO error page? return(RedirectToAction("Index")); } // For non-public files, or unpublished files, verify that the user should have access. // For public files, anybody can download. if (!file.IsPublicAccess || file.CatalogRecord.Status != CatalogRecordStatus.Published) { EnsureUserIsAllowed(file.CatalogRecord, db); EnsureUserCanDownload(file.CatalogRecord.Organization); } string processingDirectory = SettingsHelper.GetProcessingDirectory(file.CatalogRecord.Organization, db); string path = Path.Combine(processingDirectory, file.CatalogRecord.Id.ToString()); path = Path.Combine(path, file.Name); // Use the PublicName as the downloaded file name. string fileDownloadName = file.Name; var cd = new System.Net.Mime.ContentDisposition { FileName = fileDownloadName, Inline = inline, }; Response.AppendHeader("Content-Disposition", cd.ToString()); // Set the MIME type. string ext = Path.GetExtension(cd.FileName).ToLower(); string mimeType = MediaTypeNames.Application.Octet; if (ext == ".pdf") { mimeType = MediaTypeNames.Application.Pdf; } return(File(path, mimeType)); } }
public bool ApplyMetadataUpdates(CatalogRecord record, ManagedFile file, ApplicationUser user, string userId, ApplicationDbContext db, string processingDirectory) { try { string agencyId = record.Organization.AgencyID; string fullProcessingDirectory = System.IO.Path.Combine(processingDirectory, record.Id.ToString()); var piUpdater = new CreatePhysicalInstances(); piUpdater.Run(record, file, user, db, fullProcessingDirectory, agencyId); } catch (Exception ex) { logger.Error("Error while recalculating summary statistics", ex); return(false); } return(true); }
public static string GetChangeSummary(ManagedFile file, FileViewModel model) { var builder = new StringBuilder(); CheckProperty("Public Name", file.PublicName, model.PublicName, builder); CheckProperty("Type", file.Type, model.Type, builder); CheckProperty("Data Type", file.KindOfData, model.KindOfData, builder); CheckProperty("Software", file.Software, model.Software, builder); CheckProperty("Software Version", file.SoftwareVersion, model.SoftwareVersion, builder); CheckProperty("Hardware", file.Hardware, model.Hardware, builder); CheckProperty("Source", file.Source, model.Source, builder); CheckProperty("Source Information", file.SourceInformation, model.SourceInformation, builder); CheckProperty("Rights", file.Rights, model.Rights, builder); CheckProperty("Public Access", file.IsPublicAccess ? "Yes" : "No", model.IsPublicAccess.ToString(), builder); return(builder.ToString()); }
public static bool IsStatisticalCommandFile(this ManagedFile file) { if (string.IsNullOrWhiteSpace(file.Name)) { return(false); } string lower = file.Name.ToLower(); if (lower.EndsWith(".do") || lower.EndsWith(".r") || lower.EndsWith(".sps")) { return(true); } return(false); }
/// <summary> /// Read uncompressed record. /// </summary> /// <param name="Record">Record index.</param> /// <param name="Frame">Frame index.</param> /// <returns>True if succeeded, otherwise false.</returns> private bool ReadImage(int Record, int Frame) { // Setup frame to hold extracted image Records[Record].Frames[Frame].Width = Records[Record].Header.Width; Records[Record].Frames[Frame].Height = Records[Record].Header.Height; Records[Record].Frames[Frame].Stride = Records[Record].Header.Width; Records[Record].Frames[Frame].Format = DFBitmap.Formats.Indexed; Records[Record].Frames[Frame].Data = new byte[Records[Record].Header.PixelDataLength]; // Read image bytes long position = Records[Record].Header.DataPosition; BinaryReader reader = ManagedFile.GetReader(position); BinaryWriter writer = new BinaryWriter(new MemoryStream(Records[Record].Frames[Frame].Data)); writer.Write(reader.ReadBytes(Records[Record].Header.PixelDataLength)); return(true); }
public void CompareCache() { foreach (ManagedFile patchFile in PatchFiles) { FileScanned(this, new ScanEventArgs(patchFile.Filename)); //Tells the form to update the progress bar ManagedFile currentFile = cacheFiles.FirstOrDefault(x => x.Basepath + x.Filename == patchFile.Basepath + patchFile.Filename); if (currentFile == null) //file not in cache, download it. { downloadFiles.Add(patchFile); } else if (patchFile.MyHash != currentFile.MyHash) { currentFile.Length = patchFile.Length; downloadFiles.Add(currentFile); } } }
/// <summary> /// Manages the file. /// </summary> /// <param name = "crawlRequest">The crawl request.</param> public override void ManageFile(CrawlRequest <TArachnodeDAO> crawlRequest) { //we want to prevent files and images from being created by bugs when we haven't explicitly allowed file and image crawling, //but want to allow specific requests for file and image AbsoluteUris... if (ApplicationSettings.AssignFileAndImageDiscoveries || crawlRequest.Discovery.Uri.AbsoluteUri == crawlRequest.Parent.Uri.AbsoluteUri) { if (ApplicationSettings.InsertFiles && crawlRequest.IsStorable) { crawlRequest.Discovery.ID = _arachnodeDAO.InsertFile(crawlRequest.Parent.Uri.AbsoluteUri, crawlRequest.Discovery.Uri.AbsoluteUri, ApplicationSettings.InsertFileResponseHeaders ? crawlRequest.WebClient.HttpWebResponse.Headers.ToString() : null, ApplicationSettings.InsertFileSource ? crawlRequest.Data : new byte[] { }, crawlRequest.DataType.FullTextIndexType, ApplicationSettings.ClassifyAbsoluteUris); } if (crawlRequest.Discovery.ID.HasValue) { ManagedFile managedFile = ManageFile(crawlRequest, crawlRequest.Discovery.ID.Value, crawlRequest.Discovery.Uri.AbsoluteUri, crawlRequest.Data, crawlRequest.DataType.FullTextIndexType, ApplicationSettings.ExtractFileMetaData, ApplicationSettings.InsertFileMetaData, ApplicationSettings.SaveDiscoveredFilesToDisk); crawlRequest.ManagedDiscovery = managedFile; } } }
private void EnsureUserHasPermission(ManagedFile file, ApplicationDbContext db) { var user = db.Users .Where(x => x.UserName == User.Identity.Name) .FirstOrDefault(); var permissions = db.Permissions .Where(x => x.User.Id == user.Id && x.Organization.Id == file.CatalogRecord.Organization.Id); bool userCanViewAll = permissions.Any(x => x.Right == Right.CanViewAllCatalogRecords); string createdByUserName = file.CatalogRecord.CreatedBy != null ? file.CatalogRecord.CreatedBy.UserName : string.Empty; if (createdByUserName != User.Identity.Name && !file.CatalogRecord.Curators.Any(x => x.UserName == User.Identity.Name) && !file.CatalogRecord.Approvers.Any(x => x.UserName == User.Identity.Name) && !OrganizationHelper.DoesUserHaveRight(db, User, file.CatalogRecord.Organization.Id, Right.CanApprove) && !userCanViewAll) { throw new HttpException(403, "Only curators may perform this task."); } }
/// <summary> /// Read a RLE record. /// </summary> /// <param name="Record">Record index.</param> /// <param name="Frame">Frame index.</param> /// <returns>True if succeeded, otherwise false.</returns> private bool ReadRleImage(int Record, int Frame) { // Setup frame to hold extracted image int length = Records[Record].Header.Width * Records[Record].Header.Height; Records[Record].Frames[Frame].Width = Records[Record].Header.Width; Records[Record].Frames[Frame].Height = Records[Record].Header.Height; Records[Record].Frames[Frame].Stride = Records[Record].Header.Width; Records[Record].Frames[Frame].Format = DFBitmap.Formats.Indexed; Records[Record].Frames[Frame].Data = new byte[length]; // Extract image data from RLE long position = Records[Record].Header.DataPosition; BinaryReader reader = ManagedFile.GetReader(position); BinaryWriter writer = new BinaryWriter(new MemoryStream(Records[Record].Frames[Frame].Data)); ReadRleData(ref reader, length, ref writer); return(true); }