private async Task <string> getFileText(FileSystemSession session, string path) { using (var file = await session.GetItemAsync(path) as FileSystemFile) { return(await file.ReadAllTextAsync()); } }
///reads supported configuration file taking file path is absolute private Configuration getConfigFromExistingFile(FileSystemSession session, string path) { try { var file = session[path] as FileSystemFile; if (file == null) { throw new MetabaseException(StringConsts.METABASE_FILE_NOT_FOUND_EXACT_ERROR.Args(path)); } using (file) { var text = file.ReadAllText(); var fmt = chopNameLeaveExt(path); var result = Configuration.ProviderLoadFromString(text, fmt); result.Application = App; return(result); } } catch (Exception error) { throw new MetabaseException(StringConsts.METABASE_CONFIG_LOAD_ERROR.Args(path ?? SysConsts.UNKNOWN_ENTITY, error.ToMessageWithType()), error); } }
protected internal override FileSystemSessionItem DoNavigate(FileSystemSession session, string path) { if (path.IsNullOrEmpty()) { return(null); } var gds = (GoogleDriveSession)session; var client = gds.Client; var handle = client.GetHandle(path); if (handle == null) { return(null); } var parentPath = GoogleDrivePath.GetParentPath(path); if (!handle.IsFolder) { return(new FileSystemFile(gds, parentPath, handle.Name, handle)); } return(new FileSystemDirectory(gds, parentPath, handle.Name, handle)); }
/// <summary> /// Internal method that should not be called by developers /// </summary> public FileSystemFile(FileSystemSession session, string parentPath, string name, IFileSystemHandle handle) : base(session, parentPath, name, handle) { }
//tests and sets FS connection params private FileSystemSession ctorFS(IFileSystem fileSystem, FileSystemSessionConnectParams fsSessionParams, string rootPath) { FileSystemSession session = null; //Test FS connection try { session = fileSystem.StartSession(fsSessionParams); if (fsSessionParams.Version == null) { fsSessionParams.Version = session.LatestVersion; } } catch (Exception error) { throw new MetabaseException(StringConsts.METABASE_FS_CONNECTION_ERROR.Args(fileSystem.GetType().FullName, fileSystem.Name, fsSessionParams.ToString(), error.ToMessageWithType() ), error); } m_FS = fileSystem; m_FSSessionConnectParams = fsSessionParams; m_FSRootPath = rootPath ?? string.Empty; return(session); }
protected override async Task WriteEvents(ToggleID toggleID, params IEvent[] events) { await _fs.WriteFile(FileSystemSession.AggregatePath(Root, typeof(Toggle), toggleID), stream => { using (var writer = new StreamWriter(stream)) events .Select(e => JsonConvert.SerializeObject(e, JsonSettings)) .Each(line => writer.WriteLine(line)); return(Task.CompletedTask); }); }
protected FileSystemSessionItem(FileSystemSession session, string parentPath, string name, IFileSystemHandle handle) { m_FileSystem = session.FileSystem; m_Session = session; m_ParentPath = parentPath; m_Handle = handle; m_Name = name; m_Session.m_Items.Add( this ); }
protected override FileSystemSessionItem DoNavigate(FileSystemSession ses, string path) { var session = ses as FTPFileSystemSession; var fileInfo = session.Connection.GetFileInfo(path); if (fileInfo.IsDirectory) { return(new FileSystemDirectory(session, fileInfo.Name.Length == 0 ? null : fileInfo.FullName.Substring(0, fileInfo.FullName.Length - fileInfo.Name.Length), fileInfo.Name, new Handle(fileInfo))); } return(new FileSystemFile(ses, fileInfo.Name.Length == 0 ? null : fileInfo.FullName.Substring(0, fileInfo.FullName.Length - fileInfo.Name.Length), fileInfo.Name, new Handle(fileInfo))); }
protected override async Task <IEnumerable <Type> > ReadEvents(ToggleID toggleID) { var path = FileSystemSession.AggregatePath(Root, typeof(Toggle), toggleID); if (await _fs.FileExists(path) == false) { return(Enumerable.Empty <Type>()); } var lines = await _fs.ReadFileLines(path); return(lines .Select(line => JsonConvert.DeserializeObject(line, JsonSettings)) .Select(e => e.GetType())); }
protected internal override FileSystemSessionItem DoNavigate(FileSystemSession session, string path) { if (_metadataStore.IsExist(path, 5)) { DropBoxObjectMetadata objectMetadata = _metadataStore.GetObjectMetadata(path, false, 5); if(objectMetadata.IsDir) return new FileSystemDirectory((DropBoxFileSystemSession)session , DropBoxPathUtils.GetParentPathFromPath(path) , DropBoxPathUtils.GetNameFromPath(path) ,new DropBoxObjectHandler(objectMetadata)); return new FileSystemFile((DropBoxFileSystemSession)session , DropBoxPathUtils.GetParentPathFromPath(path) , DropBoxPathUtils.GetNameFromPath(path) ,new DropBoxObjectHandler(objectMetadata)); } return null; }
protected internal override FileSystemSessionItem DoNavigate(FileSystemSession session, string path) { var s3session = (S3V4FileSystemSession)session; S3V4FSH handle = new S3V4FSH(path); if (path != "" && S3V4.FileExists(path, s3session.AccessKey, s3session.SecretKey, s3session.Bucket, s3session.Region, s3session.TimeoutMs)) { return(new FileSystemFile(s3session, handle.Parent, handle.Name, handle)); } if (S3V4.FolderExists(path, s3session.AccessKey, s3session.SecretKey, s3session.Bucket, s3session.Region, s3session.TimeoutMs)) { return(new FileSystemDirectory(s3session, handle.Parent, handle.Name, handle)); } return(null); }
protected internal override FileSystemSessionItem DoNavigate(FileSystemSession session, string path) { if (File.Exists(path)) { var fi = new FileInfo(path); return(new FileSystemFile(session, fi.DirectoryName, fi.Name, new FSH { m_Info = fi })); } if (Directory.Exists(path)) { var di = new DirectoryInfo(path); return(new FileSystemDirectory(session, di.Parent.FullName, di.Name, new FSH { m_Info = di })); } return(null); }
protected internal override FileSystemSessionItem DoNavigate(FileSystemSession session, string path) { SVNFileSystemSession wdSession = session as SVNFileSystemSession; WebDAV.Item item = wdSession.WebDAV.Root.NavigatePath(path); WebDAV.Directory dir = item as WebDAV.Directory; if (dir != null) { return(new FileSystemDirectory(session, dir.Parent != null ? dir.Parent.Path : string.Empty, dir.Name, new SVNFSH(dir))); } WebDAV.File file = item as WebDAV.File; if (file != null) { return(new FileSystemFile(session, file.Parent.Path, file.Name, new SVNFSH(file))); } return(null); }
protected internal override FileSystemSessionItem DoNavigate(FileSystemSession session, string path) { if (File.Exists(path)) { var fi = new FileInfo(path); return(new FileSystemFile(session, fi.DirectoryName, fi.Name, new FSH { m_Info = fi })); } if (Directory.Exists(path)) { var di = new DirectoryInfo(path); //20210209 Fix #424 var parentPath = di.Parent != null ? di.Parent.FullName : null; return(new FileSystemDirectory(session, parentPath == null ? di.Name : parentPath, parentPath == null ? @"\" : di.Name, new FSH { m_Info = di })); } return(null); }
///reads supported configuration file taking file path relative to file system root private Configuration getConfigFromFile(FileSystemSession session, string path, bool require = true) { try { var fnwe = m_FS.CombinePaths(m_FSRootPath, path); foreach (var fmt in Configuration.AllSupportedFormats) { var fn = "{0}.{1}".Args(fnwe, fmt); // filename.<format> var file = session[fn] as FileSystemFile; if (file == null) { continue; } using (file) { var text = file.ReadAllText(); var result = Configuration.ProviderLoadFromString(text, fmt); result.Application = App; return(result); } } if (require) { throw new MetabaseException(StringConsts.METABASE_FILE_NOT_FOUND_ERROR.Args(path)); } else { var result = new MemoryConfiguration(); result.Create(SysConsts.DEFAULT_APP_CONFIG_ROOT); result.Application = App; result.Root.ResetModified(); return(result); } } catch (Exception error) { throw new MetabaseException(StringConsts.METABASE_CONFIG_LOAD_ERROR.Args(path ?? SysConsts.UNKNOWN_ENTITY, error.ToMessageWithType()), error); } }
protected override void DoConfigure(IConfigSectionNode node) { base.DoConfigure(node); if (node == null || !node.Exists) { return; } //Make File System var fsNode = node[CONFIG_CONTENT_FS_SECTION]; DisposeAndNull(ref m_Session); DisposeAndNull(ref m_Fs); m_Fs = FactoryUtils.MakeAndConfigureComponent <FileSystem>(App, fsNode, typeof(IO.FileSystem.Local.LocalFileSystem)); var pnode = fsNode[CONFIG_FS_CONNECT_PARAMS_SECTION]; DisposeIfDisposableAndNull(ref m_FsConnectParams); if (pnode.Exists) { m_FsConnectParams = FileSystemSessionConnectParams.Make <FileSystemSessionConnectParams>(pnode); } else { m_FsConnectParams = new FileSystemSessionConnectParams() { User = Security.User.Fake } }; m_Session = m_Fs.StartSession(m_FsConnectParams); } }
protected override void DoHandleWork(WorkContext work) { var fp = work.MatchedVars[VAR_FILE_PATH].AsString("none"); var attachment = work.MatchedVars[VAR_ATTACHMENT].AsBool(true); var chunked = work.MatchedVars[VAR_CHUNKED].AsBool(true); //Sanitize fp = fp.Replace("..", string.Empty) .Replace(":/", string.Empty) .Replace(@"\\", @"\"); //Cut the surrogate out of path, i.e. '/static/img/@@767868768768/picture.png' -> '/static/img/picture.png' fp = CutVersionSegment(fp, m_VersionSegmentPrefix); string fileName = null; IFileSystem fs = null; FileSystemSession fsSession = null; FileSystemFile fsFile = null; bool exists = false; if (m_UsePortalHub) { var hub = PortalHub.Instance; fs = hub.ContentFileSystem; fileName = m_RootPath != null?fs.CombinePaths(hub.ContentFileSystemRootPath, m_RootPath, fp) : fs.CombinePaths(hub.ContentFileSystemRootPath, fp); fsSession = fs.StartSession(hub.ContentFileSystemConnectParams); fsFile = fsSession[fileName] as FileSystemFile; exists = fsFile != null; } else { fileName = Path.Combine(RootPath, fp); exists = File.Exists(fileName); } try { if (!exists) { var text = StringConsts.FILE_DL_HANDLER_NOT_FOUND_INFO.Args(fileName); if (m_Throw) { throw new HTTPStatusException(WebConsts.STATUS_404, WebConsts.STATUS_404_DESCRIPTION, text); } work.Response.ContentType = ContentType.TEXT; work.Response.Write(text); work.Response.StatusCode = WebConsts.STATUS_404; work.Response.StatusDescription = WebConsts.STATUS_404_DESCRIPTION; return; } if (!work.Response.WasWrittenTo) { work.Response.Buffered = !chunked; } work.Response.SetCacheControlHeaders(CacheControl); if (fsFile == null) { work.Response.WriteFile(fileName, attachment: attachment); } else { var ext = Path.GetExtension(fsFile.Name); work.Response.ContentType = NFX.Web.ContentType.ExtensionToContentType(ext, NFX.Web.ContentType.BINARY); work.Response.WriteStream(fsFile.FileStream, attachmentName: attachment ? Path.GetFileName(fileName) : null); } } finally { DisposableObject.DisposeAndNull(ref fsSession); } }
private GoogleDriveClient GetClient(FileSystemSession session) { return (session as GoogleDriveSession).Client; }
protected internal override FileSystemSessionItem DoNavigate(FileSystemSession session, string path) { if (File.Exists(path)) { var fi = new FileInfo(path); return new FileSystemFile(session, fi.DirectoryName, fi.Name, new FSH{m_Info = fi}); } if (Directory.Exists(path)) { var di = new DirectoryInfo(path); return new FileSystemDirectory(session, di.Parent.FullName, di.Name, new FSH{m_Info=di}); } return null; }
protected override async Task <bool> AggregateExists(ToggleID toggleID) { return(await _fs.FileExists(FileSystemSession.AggregatePath(Root, typeof(Toggle), toggleID))); }
protected internal override FileSystemSessionItem DoNavigate(FileSystemSession session, string path) { var s3session = (S3V4FileSystemSession)session; S3V4FSH handle = new S3V4FSH(path); if (path != "" && S3V4.FileExists(path, s3session.AccessKey, s3session.SecretKey, s3session.Bucket, s3session.Region, s3session.TimeoutMs)) { return new FileSystemFile(s3session, handle.Parent, handle.Name, handle); } if (S3V4.FolderExists(path, s3session.AccessKey, s3session.SecretKey, s3session.Bucket, s3session.Region, s3session.TimeoutMs)) { return new FileSystemDirectory(s3session, handle.Parent, handle.Name, handle); } return null; }
protected SectionWithAnyAppConfig(Catalog catalog, string name, string path, FileSystemSession session) : base(catalog, name, path, session) { m_AnyAppConfig = Metabank.getConfigFromFile(session, Metabank.JoinPaths(path, Metabank.CONFIG_SECTION_LEVEL_ANY_APP_FILE), require: false).Root; }
protected internal override FileSystemSessionItem DoNavigate(FileSystemSession session, string path) { SVNFileSystemSession wdSession = session as SVNFileSystemSession; WebDAV.Item item = wdSession.WebDAV.Root.NavigatePath(path); WebDAV.Directory dir = item as WebDAV.Directory; if (dir != null) return new FileSystemDirectory(session, dir.Parent != null ? dir.Parent.Path : string.Empty, dir.Name, new SVNFSH(dir)); WebDAV.File file = item as WebDAV.File; if (file != null) return new FileSystemFile(session, file.Parent.Path, file.Name, new SVNFSH(file)); return null; }
private async Task<string> getFileText(FileSystemSession session, string path) { using (var file = await session.GetItemAsync(path) as FileSystemFile) { return await file.ReadAllTextAsync(); } }
protected internal override FileSystemSessionItem DoNavigate(FileSystemSession session, string path) { if (path.IsNullOrEmpty()) { return null; } var gds = (GoogleDriveSession)session; var client = gds.Client; var handle = client.GetHandle(path); if (handle == null) { return null; } var parentPath = GoogleDrivePath.GetParentPath(path); if (!handle.IsFolder) { return new FileSystemFile(gds, parentPath, handle.Name, handle); } return new FileSystemDirectory(gds, parentPath, handle.Name, handle); }
private GoogleDriveClient GetClient(FileSystemSession session) { return((session as GoogleDriveSession).Client); }
internal SectionRegionBase(RegCatalog catalog, SectionRegionBase parentSection, string name, string path, FileSystemSession session) : base(catalog, name, path, session) { ParentSection = parentSection; var gc = this.LevelConfig.AttrByName(Metabank.CONFIG_GEO_CENTER_ATTR).Value; if (gc.IsNotNullOrWhiteSpace()) { try { GeoCenter = new LatLng(gc); } catch (Exception error) { throw new MetabaseException(StringConsts.METABASE_REG_GEO_CENTER_ERROR.Args(GetType().Name, name, gc, error.ToMessageWithType())); } } }
internal SectionZone(SectionNOC noc, SectionZone parentZone, string name, string path, FileSystemSession session) : base(noc.Catalog, (SectionRegionBase)parentZone ?? (SectionRegionBase)noc, name, path, session) { m_NOC = noc; m_ParentZone = parentZone; }
protected override void DoHandleWork(WorkContext work) { var fp = work.MatchedVars[VAR_FILE_PATH].AsString("none"); var attachment = work.MatchedVars[VAR_ATTACHMENT].AsBool(true); var chunked = work.MatchedVars[VAR_CHUNKED].AsBool(true); //Sanitize fp = fp.Replace("..", string.Empty) .Replace(":/", string.Empty) .Replace(@"\\", @"\"); string fileName = null; IFileSystem fs = null; FileSystemSession fsSession = null; FileSystemFile fsFile = null; bool exists = false; if (m_UsePortalHub) { var hub = PortalHub.Instance; fs = hub.ContentFileSystem; fileName = m_RootPath != null?fs.CombinePaths(hub.ContentFileSystemRootPath, m_RootPath, fp) : fs.CombinePaths(hub.ContentFileSystemRootPath, fp); fsSession = fs.StartSession(hub.ContentFileSystemConnectParams); fsFile = fsSession[fileName] as FileSystemFile; exists = fsFile != null; } else { fileName = Path.Combine(RootPath, fp); exists = File.Exists(fileName); } try { if (!exists) { var text = StringConsts.FILE_DL_HANDLER_NOT_FOUND_INFO.Args(fileName); if (m_Throw) { throw new HTTPStatusException(SysConsts.STATUS_404, SysConsts.STATUS_404_DESCRIPTION, text); } work.Response.ContentType = ContentType.TEXT; work.Response.Write(text); work.Response.StatusCode = SysConsts.STATUS_404; work.Response.StatusDescription = SysConsts.STATUS_404_DESCRIPTION; return; } if (!work.Response.WasWrittenTo) { work.Response.Buffered = !chunked; } if (m_CacheMaxAgeSec > 0) { work.Response.Headers[HttpResponseHeader.CacheControl] = "private, max-age={0}, must-revalidate".Args(m_CacheMaxAgeSec); } else { work.Response.Headers[HttpResponseHeader.CacheControl] = "no-cache"; } if (fsFile == null) { work.Response.WriteFile(fileName, attachment: attachment); } else { var ext = Path.GetExtension(fsFile.Name); work.Response.ContentType = NFX.Web.ContentType.ExtensionToContentType(ext, NFX.Web.ContentType.BINARY); work.Response.WriteStream(fsFile.FileStream, attachmentName: attachment ? Path.GetFileName(fileName) : null); } } finally { DisposableObject.DisposeAndNull(ref fsSession); } }
internal SectionHost(SectionZone parentZone, string name, string path, FileSystemSession session) : base(parentZone.Catalog, parentZone, name, path, session) { m_ParentZone = parentZone; }
protected SectionWithNamedAppConfigs(Catalog catalog, string name, string path, FileSystemSession session) : base(catalog, name, path, session) { m_AppConfigs = Metabank.fsAccess("SectionWithAppConfig.ctor", path, (fss, dir) => { var result = new Dictionary <string, IConfigSectionNode>(StringComparer.InvariantCultureIgnoreCase); foreach (var fn in dir.FileNames.Where(fn => fn.StartsWith(Metabank.CONFIG_SECTION_LEVEL_APP_FILE_PREFIX))) { var ipr = fn.IndexOf(Metabank.CONFIG_SECTION_LEVEL_APP_FILE_PREFIX); var si = ipr + Metabank.CONFIG_SECTION_LEVEL_APP_FILE_PREFIX.Length; var isfx = fn.IndexOf(Metabank.CONFIG_SECTION_LEVEL_APP_FILE_SUFFIX); if (ipr != 0 || isfx <= si) { continue; } var appName = fn.Substring(si, isfx - si); var app = this.Metabank.CatalogApp.Applications[appName]; if (app == null) { throw new MetabaseException(StringConsts.METABASE_APP_CONFIG_APP_DOESNT_EXIST_ERROR.Args(path, fn, appName)); } var config = Metabank.getConfigFromExistingFile(session, Metabank.JoinPaths(dir.Path, fn)).Root; result.Add(appName, config); } return(result); } ); }
internal SectionNOC(RegCatalog catalog, SectionRegion parentRegion, string name, string path, FileSystemSession session) : base(catalog, parentRegion, name, path, session) { m_ParentRegion = parentRegion; }
internal SectionApplication(AppCatalog catalog, string name, string path, FileSystemSession session) : base(catalog, name, path, session) { }
protected Section(Catalog catalog, string name, string path, FileSystemSession session) { if (name.IsNullOrWhiteSpace() || catalog == null || path.IsNullOrWhiteSpace()) { throw new MetabaseException(StringConsts.ARGUMENT_ERROR + GetType().Name + ".ctor(catalog|name|path==null|empty"); } Catalog = catalog; Metabank = catalog.Metabank; m_Name = name; Path = Metabank.JoinPaths("", path);//ensure root path symbol i.e. m_LevelConfig = Metabank.getConfigFromFile(session, Metabank.JoinPaths(path, Metabank.CONFIG_SECTION_LEVEL_FILE)).Root; if (!m_LevelConfig.IsSameName(RootNodeName)) { throw new MetabaseException(StringConsts.METABASE_METADATA_CTOR_1_ERROR.Args(GetType().Name, RootNodeName, m_LevelConfig.Name)); } var cn = m_LevelConfig.AttrByName(Metabank.CONFIG_NAME_ATTR); if (!cn.Exists || !m_LevelConfig.IsSameNameAttr(name)) { throw new MetabaseException(StringConsts.METABASE_METADATA_CTOR_2_ERROR.Args(GetType().Name, name, cn.ValueAsString(SysConsts.UNKNOWN_ENTITY))); } if (!name.IsValidName()) { throw new MetabaseException(StringConsts.METABASE_METADATA_CTOR_3_ERROR.Args(GetType().Name, name, path)); } Metabank.includeCommonConfig(m_LevelConfig); m_LevelConfig.ResetModified(); }