public ImagesUploadViewModel(FileContext context, string path, IEnumerable<FileInfo> files, Action finished) { _context = context; _path = path; _finished = finished; _items = new ObservableCollection<ImageUploadModel>(files.Select(file => new ImageUploadModel(file))); _totalSize = files.Sum(file => file.Length); _removeCommand = new DelegateCommand<ImageUploadModel>(Remove); _window = new ImagesUploadWindow(); _window.DataContext = this; _window.Loaded += ImagesUploadWindow_Loaded; _window.Closed += Window_Closed; _window.Closing += Window_Closing; _window.Show(); }
internal HeaderedFileWriter([NotNull] HeaderedFile file) { _file = file; _file.CurrentWriter = this; _context = file.Context; _description = _context.Description; }
public void Setup() { var layout = SimpleSerializer.Xml<Layout>() .DeserializeTypedFromString(SampleLayouts.test_b_layout); using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(SampleLayouts.test_b))) file = layout.Read(stream).CompleteInitialize(); }
public void Initialize() { context = new FileContext("test", new MemoryStream()); fieldMock = new Mock<IField<FileContext, int>>(); map = new PropertyMap<Target, int, FileContext, int>(t => t.Id, fieldMock.Object, i => i); target = new Target(); }
public void Dispose() { if (_context != null) { _context.Dispose(); _context = null; } }
internal SectionGroup(FileContext core) { _core = core; SectionGroups = new SectionGroupCollection(core, this); Sections = new SectionDefinitionCollection(core); ConfigurationSections = new List<ConfigurationSection>(); Name = string.Empty; Type = string.Empty; Path = string.Empty; }
/// <summary> /// Creates a new instance of <see cref="FileResponseMessage"/> /// </summary> /// <param name="fileContext">The file context</param> public FileResponseMessage(FileContext fileContext) { var mediaType = MimeMapping.GetMimeMapping(fileContext.FileExtension); this.Content = new StreamContent(fileContext.FileStream); this.Content.Headers.ContentType = new MediaTypeHeaderValue(mediaType); this.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = fileContext.FileName }; }
public CTO<List<GetActiveFilesVIEW>> GetFilesForClient(List<int> clientFiles) { try { using (var fileContext = new FileContext()) { return new CTO<List<GetActiveFilesVIEW>>( fileContext.ActiveFilesDS.Where(a => !clientFiles.Contains(a.ID)).ToList()); } } catch (Exception ex) { return new CTO<List<GetActiveFilesVIEW>>(null, ex); } }
public void AddFile(string content, ASSET_TYPES assetType) { using (var fileContext = new FileContext()) { var file = new Files { AssetTypeID = (int)assetType, Content = content }; fileContext.FilesDS.Add(file); fileContext.SaveChanges(); } }
public void Initialize() { context = new FileContext("test", new MemoryStream()); sectionContextStub = new SectionContextStub(context); childTargetMapMock = new Mock<IClassMap<ChildTarget,FileContext>>(); childTargetMapMock.Setup(m => m.ExtractAsync(It.IsAny<FileContext>(), It.IsAny<ChildTarget>())) .Returns(Task.Delay(0)); parentTarget = new ParentTarget(); childTargets = new[] { new ChildTarget(), new ChildTarget() }; endOfSectionPredicate = c => false; map = new ComponentMap<ParentTarget, ChildTarget, FileContext>(p => p.Children, c => sectionContextStub, () => childTargets[childIndex++], childTargetMapMock.Object, c => endOfSectionPredicate(c)); }
public void GetAllObjectsOfCertainTypeFromRepositoryTest() { const string connectionString = @"C:\Temp\CrateStorage"; var dc = new FileContext(connectionString, "Test"); var p = new Person { Name = "John Doe", Age = 24, Email = "*****@*****.**" }; var repository = new Repository("ConsoleApp"); repository.Add(p); dc.SubmitChanges(repository); var repositories = dc.GetObjects("ConsoleApp"); Assert.AreNotEqual(0, repositories.Count()); }
private static IDataContext CreateDataContext(Connection currentConnection) { IDataContext dc = null; switch (currentConnection.SourceType) { case SourceType.File: dc = new FileContext(currentConnection.ConnectionString, "Test"); break; case SourceType.SqlServer: dc = new SqlServerContext(currentConnection.ConnectionString, "Test"); break; case SourceType.MySql: dc = new MySqlContext(currentConnection.ConnectionString, "Test"); break; } return dc; }
public void Run() { var portList = new List<PortListingItem> { new PortListingItem("FTP", 21), new PortListingItem("SSH", 22), new PortListingItem("SMTP", 25), new PortListingItem("HTTP", 80) }; using (var fileCT = new FileContext()) { var file = new Files { AssetTypeID = (int) ASSET_TYPES.PORT_DEFINITIONS, Content = BasePA.GetJSONStringFromT(new PortDefinitionsResponseItem {Ports = portList}) }; fileCT.FilesDS.Add(file); fileCT.SaveChanges(); } }
public void AddANewEntryToTheRepositoryTest() { const string filePath = @"C:\Temp\CrateStorage"; var dc = new FileContext(filePath, "Test"); var p = new Person { Name = "John Doe", Age = 24, Email = "*****@*****.**" }; var repository = new Repository("ConsoleApp"); dc.Clear<Person>(repository); repository.Add(p); dc.SubmitChanges(repository); var people = dc.Select<Person>(repository); Assert.AreEqual(1, people.Count()); }
public virtual void SetUp() { fc = FileContext.GetLocalFSFileContext(); fc.Mkdir(fileContextTestHelper.GetTestRootPath(fc, "test"), FileContext.DefaultPerm , true); }
public Path GetDefaultWorkingDirectory(FileContext fc) { return(GetTestRootPath(fc, "/user/" + Runtime.GetProperty("user.name")).MakeQualified (fc.GetDefaultFileSystem().GetUri(), fc.GetWorkingDirectory())); }
public Path GetTestRootPath(FileContext fc, string pathString) { return(fc.MakeQualified(new Path(testRootDir, pathString))); }
public FamilyService(FileContext file) { this.file = file; }
private ConfigurationSection DetectSection(string sectionPath, string locationPath, FileContext core) { var index = sectionPath.IndexOf(Path, StringComparison.Ordinal); if (index != 0) { return null; } if (this.Path.Length != 0) { if (sectionPath.Length != this.Path.Length && sectionPath[this.Path.Length] != '/') { return null; } } foreach (ConfigurationSection section in ConfigurationSections) { if (section.ElementTagName == sectionPath && section.Location == locationPath && !section.IsLocked) { return section; } } foreach (SectionGroup group in SectionGroups) { var found = group.DetectSection(sectionPath, locationPath, core); if (found != null) { return found; } } var definition = Sections.FirstOrDefault(item => item.Path == sectionPath); if (definition?.Schema == null) { var sectionInParent = core.Parent?.RootSectionGroup.DetectSection(sectionPath, locationPath, core.Parent); return sectionInParent; } return null; }
public void UpdateEntryTest() { const string filePath = @"C:\Temp\CrateStorage"; var dc = new FileContext(filePath, "Test"); var p = new Person { Name = "John Doe", Age = 24, Email = "*****@*****.**" }; var repository = new Repository("ConsoleApp"); dc.Clear<Person>(repository); repository.Add(p); dc.SubmitChanges(repository); var man = dc.Select<Person>(repository).First(c => c.Age == 24); man.Age = 35; repository.Update(man); dc.SubmitChanges(repository); var actual = dc.Select<Person>(repository).First(c => c.Age == 35); Assert.AreEqual(35, actual.Age); }
public void ClearAllPairTest() { const string filePath = @"C:\Temp\CrateStorage"; var dc = new FileContext(filePath, "Test"); const string expectedValue = "Hello Pair!"; const string pairName = "TestKey"; dc.Pairs.Add(pairName, expectedValue); dc.Pairs.ClearAll(); var actual = dc.Pairs.Get(pairName); Assert.AreEqual(false, actual.Contains(expectedValue)); }
public HomeController(FileContext context) { _context = context; Files = new List <FileInfo>(); Directories = new List <DirectoryInfo>(); }
public FamilyService() { fileContext = new FileContext(); dbContext = new Assignment4DBContext(); }
public Task <IReadOnlyList <IFileContextAction> > GetActionsAsync(string filePath, FileContext fileContext, CancellationToken cancellationToken) { return(Task.FromResult <IReadOnlyList <IFileContextAction> >(new IFileContextAction[] { // Word count command: new MyContextAction( fileContext, new Tuple <Guid, uint>(ProviderCommandGroup, PackageIds.WordCountCmdId), "My Action" + fileContext.DisplayName, async(fCtxt, progress, ct) => { WordCountSettings settings = WordCountSettings.GetSettings(workspaceContext); string action = settings.CountType == WordCountSettings.WordCountType.WordCount ? "Word Count" : "Line Count"; await OutputWindowPaneAsync(action + " " + fCtxt.Context.ToString()); }), // Toggle word count type command: new MyContextAction( fileContext, new Tuple <Guid, uint>(ProviderCommandGroup, PackageIds.ToggleWordCountCmdId), "My Action" + fileContext.DisplayName, async(fCtxt, progress, ct) => { WordCountSettings settings = WordCountSettings.GetSettings(workspaceContext); settings.CountType = settings.CountType == WordCountSettings.WordCountType.LineCount ? WordCountSettings.WordCountType.WordCount : WordCountSettings.WordCountType.LineCount; WordCountSettings.StoreSettings(workspaceContext, settings); await OutputWindowPaneAsync( settings.CountType == WordCountSettings.WordCountType.WordCount ? "Counting Words\n" : "Counting Lines\n"); }), })); }
public HomeController(FileContext fileContext) { _fileContext = fileContext; }
public AuthService() { var filePath = FileContext.FindFilePath(); _fileContext = new FileContext(filePath); }
public FamilyManager() { familyFileHandler = new FileContext(); adults = familyFileHandler.Adults; }
public virtual void Setup() { localFS = FileContext.GetLocalFSFileContext(); }
internal Configuration(FileContext fileContext) { this.FileContext = fileContext; }
public FileRepository(FileContext context) { _context = context; }
internal ConfigurationElement GetElementAtParentLocationInFileContext(FileContext core) { if (Section == null) { return null; } if (Section.Location == null) { if (core != null && core.Parent == null && Schema.Path == "configProtectedData/providers") { // IMPORTANT: to load providers from machine.config. return core.GetSection(Section.SectionPath).GetChildElement("providers"); } return null; } string parentLocation = Section.Location.GetParentPath(); while (true) { var parentSection = core.GetSection(Section.SectionPath, parentLocation); // IMPORTANT: allow null section as web.config does not have the sections. var parentElement = parentSection?.GetElementByPath(Schema.Path); if (parentElement != null) { return parentElement; } if (parentLocation == null) { return null; } parentLocation = parentLocation.GetParentPath(); } }
public InMemoryUserService(FileContext fileContext) { this.fileContext = fileContext; }
public async Task CanGetExistingFile() { const string FileName = "Foo.pdf"; const string FileExtension = "pdf"; var fileStream = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); var fileContext = new FileContext(FileName, FileExtension, fileStream); A.CallTo(() => this.fileReader.ReadAsync(A<string>.Ignored, Identifier, FileName)) .Returns(fileContext); var response = await this.testee.Get(Identifier, FileName); var responseStream = await response.Content.ReadAsStreamAsync(); var fileStreamLength = fileStream.Length; var responseStreamLength = responseStream.Length; responseStreamLength.Should().Be(fileStreamLength); }
public FileRepository() { _context = new FileContext(); }
internal ConfigurationSection FindSection(string sectionPath, string locationPath, FileContext core) { var temp = DetectSection(sectionPath, locationPath, core); if (temp != null) { return temp; } return CreateSection(sectionPath, locationPath, core, core); }
public HeaderedFile([NotNull] FileDescription description) { Context = new FileContext(description); }
public Path GetTestRootPath(FileContext fc) { return(fc.MakeQualified(new Path(testRootDir))); }
public DownloadController(FileContext context) { _context = context; }
public Path GetAbsoluteTestRootPath(FileContext fc) { return(fc.MakeQualified(new Path(GetAbsoluteTestRootDir(fc)))); }
public UploadFileHandler(MinioClient client, IMapper mapper, FileContext context) { _client = client; _mapper = mapper; _context = context; }
public AdultService(FileContext file) { this.file = file; }
public PersonData(FileContext file) { this.file = file; }
public FileController(IHostingEnvironment hostingEnvironment, FileContext context) { this.hostingEnvironment = hostingEnvironment; this.context = context; }
// Matches anything containing <, >, :, ", |, ?, *, or anything that ends with // space or dot. //Helper method to make path qualified protected internal virtual Path QualifiedPath(string path, FileContext fc) { return(fc.MakeQualified(new Path(Base, path))); }
public AdultService() { fileContext = new FileContext(); }
public void SelectDataInKeyValueFormatTest() { const string filePath = @"C:\Temp\CrateStorage"; var dc = new FileContext(filePath, "Test"); var p = new Person { Name = "John Doe", Age = 24, Email = "*****@*****.**" }; var repository = new Repository("ConsoleApp"); dc.Clear<Person>(repository); repository.Add(p); dc.SubmitChanges(repository); var people = dc.Select(repository.Name, "Person").ToList(); Assert.AreEqual(4, people[0].Count()); }
public void Initialize() { context = new FileContext("test.txt", new MemoryStream()); fieldMock = new Mock<IField<FileContext, string>>(); map = new ClassMap<Target, FileContext, string>(); }
public override NT_STATUS Write(UserContext UserContext, FileContext FileObject, long Offset, ref int Count, ref byte[] Buffer, int Start) { // All locking issies are handled in the calling class, expect if other application access the files from outside // WinFUSE // It's possible to write all data to a cache and write it through to the final media after a flush or close. But this // write through should not last longer than 20 secounds NT_STATUS error = NT_STATUS.OK; MyFileContext HE = (MyFileContext)FileObject; if (HE.IsDirectory || HE.FS == null) { Debug.WriteLine("Warning->Cannot write to Directory."); Count = 0; return NT_STATUS.INVALID_HANDLE; // ERROR_INVALID_HANDLE } if (!HE.FS.CanWrite && !HE.FS.CanSeek) { Debug.WriteLine("Warning->The file can not be written."); Count = 0; return NT_STATUS.INVALID_PARAMETER; // ERROR_INVALID_PARAMETER; } if (Count > 0x0FFFFFFF) { Debug.WriteLine("Warning->Number of bytes to write is too large."); Count = 0; return NT_STATUS.INVALID_PARAMETER; //ERROR_INVALID_PARAMETER } long NewOffset; try { NewOffset = HE.FS.Seek(Offset, System.IO.SeekOrigin.Begin); if (NewOffset != Offset) { Debug.WriteLine("Warning->The indicated position can not be written."); Count = 0; return NT_STATUS.INVALID_PARAMETER; //132 ERROR_SEEK_ON_DEVICE } BinaryWriter Writer = new BinaryWriter(HE.FS); Writer.Write(Buffer, Start, Count); } catch (Exception ex) { Trace.WriteLine("Warning->Exception in Write: " + ex.Message); Count = 0; //error = 29; // ERROR_WRITE_FAULT error = (NT_STATUS)Marshal.GetHRForException(ex); } return error; }
internal ConfigurationElement(ConfigurationElement element, string name, ConfigurationElementSchema schema, ConfigurationElement parent, XElement entity, FileContext core) { Methods = new ConfigurationMethodCollection(); this.FileContext = parent?.FileContext ?? element?.FileContext ?? core; Section = parent?.Section; this.InnerEntity = entity ?? element?.InnerEntity; if (element == null) { if (name == null) { throw new ArgumentException("empty name"); } ElementTagName = name; Attributes = new ConfigurationAttributeCollection(this); ChildElements = new ConfigurationChildElementCollection(this); Collections = new List<ConfigurationElementCollection>(); RawAttributes = new Dictionary<string, string>(); ParentElement = parent; if (parent == null) { if (schema == null) { throw new ArgumentException(); } Schema = schema; IsLocallyStored = true; } else { IsLocallyStored = !parent.Section.IsLocked; var collection = parent.Schema.CollectionSchema; if (collection == null) { Schema = parent.Schema.ChildElementSchemas[name]; } else { Schema = parent.Schema.CollectionSchema.GetElementSchema(name) ?? parent.Schema.ChildElementSchemas[name]; } if (Schema == null) { throw new ArgumentException("empty schema"); } } ParseAttributes(); } else { IsLocallyStored = element.IsLocallyStored; ElementTagName = element.ElementTagName; Attributes = element.Attributes; ChildElements = element.ChildElements; Collections = element.Collections; RawAttributes = element.RawAttributes; Schema = element.Schema; ParentElement = parent ?? element.ParentElement; if (schema != null) { // TODO: here we ignore second schema //throw new ArgumentException(); } } }
/// <exception cref="System.IO.IOException"/> public static long CreateFile(FileContext fc, Path path, int numBlocks, int blockSize ) { return(CreateFile(fc, path, numBlocks, Options.CreateOpts.BlockSize(blockSize), Options.CreateOpts .CreateParent())); }
public void AddNewPairTest() { const string filePath = @"C:\Temp\CrateStorage"; var dc = new FileContext(filePath, "Test"); const string expectedValue = "Hello Pair!"; dc.Pairs.Add("TestKey", expectedValue); var actual = dc.Pairs.Get("TestKey"); Assert.AreEqual(true, actual.Contains(expectedValue)); }
/// <exception cref="System.IO.IOException"/> public long CreateFileNonRecursive(FileContext fc, string name) { Path path = GetTestRootPath(fc, name); return(CreateFileNonRecursive(fc, path)); }
internal ConfigurationSection(string path, ConfigurationElementSchema schema, string location, FileContext core, XElement entity) : base(null, path, schema, null, entity, core) { Location = location; Section = this; }
/// <exception cref="System.IO.IOException"/> public static long CreateFileNonRecursive(FileContext fc, Path path) { return(CreateFile(fc, path, DefaultNumBlocks, Options.CreateOpts.DonotCreateParent ())); }
private ConfigurationSection CreateSection(string sectionPath, string locationPath, FileContext core, FileContext top) { var index = sectionPath.IndexOf(Path, StringComparison.Ordinal); if (index != 0) { return null; } if (this.Path.Length != 0) { if (sectionPath.Length != this.Path.Length && sectionPath[this.Path.Length] != '/') { return null; } } var definition = Sections.FirstOrDefault(item => item.Path == sectionPath); if (definition?.Schema != null) { var section = new ConfigurationSection(sectionPath, definition.Schema.Root, locationPath, top, null); section.OverrideMode = OverrideMode.Inherit; section.OverrideModeEffective = (OverrideMode)Enum.Parse(typeof(OverrideMode), definition.OverrideModeDefault); section.IsLocked = section.FileContext.FileName != definition.FileContext.FileName && section.OverrideModeEffective != OverrideMode.Allow; section.IsLocallyStored = section.FileContext.FileName == definition.FileContext.FileName; ConfigurationSections.Add(section); return section; } foreach (SectionGroup group in SectionGroups) { var created = group.CreateSection(sectionPath, locationPath, core, top); if (created != null) { return created; } } var sectionBasedOnParent = core.Parent?.RootSectionGroup.CreateSection(sectionPath, locationPath, core.Parent, top); return sectionBasedOnParent; }
/// <exception cref="System.IO.IOException"/> public static bool Exists(FileContext fc, Path p) { return(fc.Util().Exists(p)); }
public FileStatus ContainsPath(FileContext fc, Path path, FileStatus[] dirList) { return(ContainsPath(GetTestRootPath(fc, path.ToString()), dirList)); }
public FileStatus ContainsPath(FileContext fc, string path, FileStatus[] dirList) { return(ContainsPath(fc, new Path(path), dirList)); }
public abstract void Drawing(FileContext context);
/// <summary> /// Execute the response result. /// </summary> /// <param name="context">HTTP controller context</param> /// <remarks>Invoked by <see cref="ControllerFactory"/> to process the response.</remarks> public override void ExecuteResult(IControllerContext context) { //Logger.WriteDebug(this, "Pipeline => ExecuteResult"); if (context == null) { throw new ArgumentNullException("context"); } // only handle GET and HEAD if (!context.HttpContext.Request.HttpMethod.ToUpper().Equals("GET") && !context.HttpContext.Request.HttpMethod.ToUpper().Equals("HEAD")) { return; } var header = context.HttpContext.Request.Headers["If-Modified-Since"]; // TODO: Build reliable date parser var time = DateTime.MinValue; //var time = header != null // ? ParseUtility.TryParseDateTime(header) // : DateTime.MinValue; var fileContext = new FileContext(context.HttpContext.Request, time); _fileService.GetFile(fileContext, _fullFilePath); if (!fileContext.IsFound) { return; } if (!fileContext.IsModified) { context.HttpContext.Response.StatusCode = (int)HttpStatusCode.NotModified; context.HttpContext.Response.StatusDescription = "Was last modified " + fileContext.LastModifiedAtUtc.ToString("R"); return; } var mimeType = MimeTypeProvider.Instance.Get(fileContext.Filename); if (mimeType == null) { context.HttpContext.Response.StatusCode = (int)HttpStatusCode.UnsupportedMediaType; context.HttpContext.Response.StatusDescription = string.Concat("File type '", Path.GetExtension(fileContext.Filename), "' is not supported."); return; } context.HttpContext.Response.AddHeader("Last-Modified", fileContext.LastModifiedAtUtc.ToString("R")); context.HttpContext.Response.AddHeader("Accept-Ranges", "bytes"); context.HttpContext.Response.AddHeader("Content-Disposition", "inline;filename=\"" + Path.GetFileName(fileContext.Filename) + "\""); context.HttpContext.Response.ContentType = mimeType; context.HttpContext.Response.ContentLength = (int)fileContext.FileStream.Length; context.HttpContext.Response.Body = fileContext.FileStream; // Do not include a body when the client only want's to get content information. if (context.HttpContext.Request.HttpMethod.ToUpper().Equals("HEAD") && context.HttpContext.Response.Body != null) { context.HttpContext.Response.Body.Dispose(); context.HttpContext.Response.Body = null; } }