private void AddDocuments(ref Application application, IEnumerable <HttpPostedFileBase> docs) { foreach (var f in docs) { if (f != null) { string mimeType = f.ContentType; string fileName = Path.GetFileName(f.FileName); int fileLength = f.ContentLength; //Note: you could filter for mime types if you only want to allow //certain types of files. I am allowing everything. if (!(fileName == "" || fileLength == 0))//Looks like we have a file!!! { Stream fileStream = f.InputStream; byte[] fileData = new byte[fileLength]; fileStream.Read(fileData, 0, fileLength); ApplicationFiles newFile = new ApplicationFiles { FilesContent = new ApplicationFilesContent { Content = fileData, MimeType = mimeType }, fileName = fileName }; application.Files.Add(newFile); } ; } } }
public FileChangeWatcher(string root, FileSet fileSet, IChangeSetHandler handler) { _files = new ApplicationFiles(root); _fileSet = fileSet; _handler = handler; #if NET46 _timer = new Timer(execute); #else _timer = new Timer(execute, this, 0, PollingIntervalInMilliseconds); #endif Root = root; }
/* Method adds a file to an Application. Note: URI is from Azure BLOB Storage */ public async Task SetFile(string title, Uri uri) { var file = new ApplicationFiles() { Title = title, Created = DateTime.Now, Url = uri.AbsoluteUri, /* use last added application for reference */ Application = _ctx.Applications.Last() }; _ctx.ApplicationFile.Add(file); await _ctx.SaveChangesAsync(); }
/// <summary> /// Initializes a new instance of <see cref="VirtualProcessStartInfo"/> /// based on the <see cref="ApplicationData"/> specified. /// </summary> /// <exception cref="ArgumentNullException"> /// An <see cref="ArgumentNullException"/> is thrown if <paramref name="data"/> of one of its properties is null. /// </exception> /// <exception cref="ArgumentException"> /// An <see cref="ArgumentException"/> is thrown if any of the properties of <paramref name="data"/> is of the wrong type. /// </exception> /// <param name="data">The data to base the process on.</param> /// <param name="workingDirectory">The working directory of the process to start.</param> public VirtualProcessStartInfo(ApplicationData data, ApplicationFile workingDirectory) { if (data == null || data.Files.RegistryDatabase == null || data.Files.Executable == null || data.Files.RootDirectory == null) { throw new ArgumentNullException("data", "The data argument or one of its properties is null."); } if (workingDirectory == null) { throw new ArgumentNullException("workingDirectory", "The workingDirectory argument is null."); } if (data.Files.Executable.Type != FileType.Executable) { throw new ArgumentException("The ApplicationData specified contains an illegal value for the main executable.", "data"); } if (data.Files.RegistryDatabase.Type != FileType.Database) { throw new ArgumentException( "The ApplicationData specified contains an illegal value for the registry database.", "data"); } if (workingDirectory.Type != FileType.Directory) { throw new ArgumentException("The working directory specified is not a directory.", "workingDirectory"); } _files = new ApplicationFiles { RegistryDatabase = new ApplicationFile(Path.Combine(workingDirectory.FileName, data.Files.RegistryDatabase.FileName)), Executable = new ApplicationFile(Path.Combine(workingDirectory.FileName, data.Files.Executable.FileName)), RootDirectory = new ApplicationFile(Path.Combine(workingDirectory.FileName, data.Files.RootDirectory.FileName)) }; _arguments = ""; _workingDirectory = workingDirectory; _fileSystemRuleCollection = data.Settings.FileSystemEngineRuleCollection ?? FileSystemRuleCollection.GetDefaultRuleCollection(); _registryRuleCollection = data.Settings.RegistryEngineRuleCollection ?? RegistryRuleCollection.GetDefaultRuleCollection(); }
private static PGAContext GetContextWithData() { /* Initialize an in-memory Db context, we are not using the context linked to the * SQL server as that falls under integration tests */ var options = new DbContextOptionsBuilder <PGAContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var context = new PGAContext(options); /* Add seed data to in-memory context */ Programme programme1 = new Programme() { Id = 1, ProgrammeName = "Masters by reasearch" }; Programme programme2 = new Programme() { Id = 2, ProgrammeName = "Masters by course work" }; context.Add(programme1); context.Add(programme2); Position position1 = new Position() { Id = 1, PositionName = "Supervisor" }; Position position2 = new Position() { Id = 2, PositionName = "PGO" }; Position position3 = new Position() { Id = 3, PositionName = "PGC" }; context.Add(position1); context.Add(position2); context.Add(position3); Users supervisor = new Users() { Id = 1, FirstName = "Fred", Position = position1 }; context.Add(supervisor); Application application = new Application() { Id = 1, FirstName = "Jon", LastName = "Doe", Programme = programme1, Supervisor = supervisor }; context.Add(application); ApplicationFiles file1 = new ApplicationFiles() { Application = application, Id = 1, Title = "FirstDoc" }; ApplicationFiles file2 = new ApplicationFiles() { Application = application, Id = 2, Title = "SecondDoc" }; context.Add(file1); context.Add(file2); List <ApplicationFiles> docs = new List <ApplicationFiles>(new ApplicationFiles[] { file1, file2 }); application.ApplicationFiles = docs; context.SaveChanges(); return(context); }