public static OperationSymbol ParseOperationAssert(string operationKey, Type entityType, object[]?args = null) { var symbol = SymbolLogic <OperationSymbol> .ToSymbol(operationKey); OperationLogic.AssertOperationAllowed(symbol, entityType, inUserInterface: true); return(symbol); }
public static OperationSymbol ParseOperationAssert(string operationKey) { var symbol = SymbolLogic <OperationSymbol> .ToSymbol(operationKey); OperationLogic.AssertOperationAllowed(symbol, inUserInterface: true); return(symbol); }
public string[] AvailableDevices(string algorithmKey) { var key = SymbolLogic <PredictorAlgorithmSymbol> .ToSymbol(algorithmKey); var alg = PredictorLogic.Algorithms.GetOrThrow(key); return(alg.GetAvailableDevices()); }
public static OperationSymbol GetOperationKeyAssert(this ControllerBase controller, Type entityType) { var operationFullKey = controller.ControllerContext.RequestContext.HttpContext.Request["operationFullKey"]; var operationSymbol = SymbolLogic <OperationSymbol> .ToSymbol(operationFullKey); OperationLogic.AssertOperationAllowed(operationSymbol, entityType, inUserInterface: true); return(operationSymbol); }
public HttpResponseMessage DownloadFilePathEmbedded(string fileTypeKey, string suffix, string fileName) { var fileType = SymbolLogic <FileTypeSymbol> .ToSymbol(fileTypeKey); var virtualFile = new FilePathEmbedded(fileType) { Suffix = suffix, FileName = fileName, }; return(GetHttpReponseMessage(virtualFile.OpenRead(), virtualFile.FileName)); }
public FileStreamResult DownloadFilePathEmbedded(string fileTypeKey, string suffix, string fileName) { var fileType = SymbolLogic <FileTypeSymbol> .ToSymbol(fileTypeKey); var virtualFile = new FilePathEmbedded(fileType) { Suffix = suffix, FileName = fileName, }; return(GetFileStreamResult(virtualFile.OpenRead(), virtualFile.FileName)); }
public static OperationSymbol TryGetOperationKeyAsset(this ControllerBase controller) { var operationFullKey = controller.ControllerContext.RequestContext.HttpContext.Request["operationFullKey"]; if (operationFullKey == null) { return(null); } var operationSymbol = SymbolLogic <OperationSymbol> .ToSymbol(operationFullKey); OperationLogic.AssertOperationAllowed(operationSymbol, inUserInterface: true); return(operationSymbol); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var request = (OperationController.BaseOperationRequest)Activator.CreateInstance(objectType); serializer.Populate(reader, request); var operationSymbol = SymbolLogic <OperationSymbol> .ToSymbol(request.operationKey); if (request.args != null) { for (int i = 0; i < request.args.Length; i++) { if (request.args[i] is JToken jtoken) { request.args[i] = ConvertObject(jtoken, serializer, operationSymbol); } } } return(request); }
public static void Start(bool file, bool embeddedFile, bool filePath, bool embeddedFilePath) { if (Navigator.Manager.NotDefined(MethodInfo.GetCurrentMethod())) { Navigator.RegisterArea(typeof(FilesClient)); UrlsRepository.DefaultSFUrls.AddRange(new Dictionary <string, Func <UrlHelper, string> > { { "uploadFile", url => url.Action <FileController>(fc => fc.Upload()) }, { "uploadDroppedFile", url => url.Action <FileController>(fc => fc.UploadDropped()) }, }); if (file) { RegisterFileConstructor <FileEntity>(data => { return(new FileEntity { FileName = data.FileName, BinaryFile = data.Content }.Save()); }); RegisterDownloadUrlConstructor <FileEntity>(fp => { return(RouteHelper.New().Action((FileController fc) => fc.Download(new RuntimeInfo(fp).ToString()))); }); RegisterFileDownloadResult <FileEntity>(ri => { FileEntity f = (FileEntity)ri.ToLite().Retrieve(); return(new StaticContentResult(f.BinaryFile, f.FileName)); }); var es = new EntitySettings <FileEntity>(); Navigator.AddSetting(es); var baseMapping = (Mapping <FileEntity>)es.MappingLine.AsEntityMapping().RemoveProperty(fp => fp.BinaryFile); es.MappingLine = ctx => { RuntimeInfo runtimeInfo = ctx.GetRuntimeInfo(); if (runtimeInfo == null) { return(null); } else { if (runtimeInfo.IsNew) { HttpPostedFileBase hpf = GetHttpRequestFile(ctx); if (hpf != null) { return(new FileEntity { FileName = Path.GetFileName(hpf.FileName), BinaryFile = hpf.InputStream.ReadAllBytes() }); } else { throw new InvalidOperationException("Impossible to create new FileEntity {0}".FormatWith(ctx.Prefix)); } } else { return(baseMapping(ctx)); } } }; FileLogic.DownloadFileUrl = DownloadFileUrl; var lm = new LiteMapping <FileEntity>(); lm.EntityHasChanges = ctx => ctx.GetRuntimeInfo().IsNew; Mapping.RegisterValue <Lite <FileEntity> >(lm.GetValue); } if (embeddedFile) { RegisterFileConstructor <FileEmbedded>(data => { return(new FileEmbedded { FileName = data.FileName, BinaryFile = data.Content }); }); var es = new EmbeddedEntitySettings <FileEmbedded>(); Navigator.AddSetting(es); var baseMapping = (Mapping <FileEmbedded>)es.MappingDefault.AsEntityMapping().RemoveProperty(fp => fp.BinaryFile); es.MappingDefault = ctx => { RuntimeInfo runtimeInfo = ctx.GetRuntimeInfo(); if (runtimeInfo == null) { return(null); } else { HttpPostedFileBase hpf = GetHttpRequestFile(ctx); if (hpf != null && hpf.ContentLength != 0) { return(new FileEmbedded() { FileName = Path.GetFileName(hpf.FileName), BinaryFile = hpf.InputStream.ReadAllBytes() }); } else if (ctx.Inputs.ContainsKey(EntityBaseKeys.EntityState)) { return((FileEmbedded)Navigator.Manager.DeserializeEntity(ctx.Inputs[EntityBaseKeys.EntityState])); } else { return(baseMapping(ctx)); } } }; } if (filePath) { RegisterFileConstructor <FilePathEntity>(data => { if (!data.FileType.HasText()) { throw new InvalidOperationException("Couldn't create FilePath with unknown FileType for file '{0}'".FormatWith(data.FileName)); } return(new FilePathEntity(SymbolLogic <FileTypeSymbol> .ToSymbol(data.FileType)) { FileName = data.FileName, BinaryFile = data.Content, CalculatedDirectory = data.CalculatedDirectory }.Save()); }); RegisterDownloadUrlConstructor <FilePathEntity>(fp => { return(RouteHelper.New().Action((FileController fc) => fc.Download(new RuntimeInfo(fp).ToString()))); }); RegisterFileDownloadResult <FilePathEntity>(ri => { FilePathEntity fp = (FilePathEntity)ri.ToLite().Retrieve(); return(new FilePathResult(fp.FullPhysicalPath(), MimeMapping.GetMimeMapping(fp.FullPhysicalPath())) { FileDownloadName = fp.FileName }); }); Navigator.AddSettings(new List <EntitySettings> { new EntitySettings <FilePathEntity> { PartialViewName = e => ViewPrefix.FormatWith("FilePath") }, }); var es = Navigator.EntitySettings <FilePathEntity>(); var baseMapping = (Mapping <FilePathEntity>)es.MappingLine.AsEntityMapping().RemoveProperty(fp => fp.BinaryFile); es.MappingLine = ctx => { RuntimeInfo runtimeInfo = ctx.GetRuntimeInfo(); if (runtimeInfo == null) { return(null); } else { if (runtimeInfo.IsNew) { HttpPostedFileBase hpf = GetHttpRequestFile(ctx); if (hpf != null) { string fileType = ctx.Inputs[FileLineKeys.FileType]; return(new FilePathEntity(SymbolLogic <FileTypeSymbol> .ToSymbol(fileType)) { FileName = Path.GetFileName(hpf.FileName), BinaryFile = hpf.InputStream.ReadAllBytes(), }); } else { throw new InvalidOperationException("Impossible to create new FilePath {0}".FormatWith(ctx.Prefix)); } } else { return(baseMapping(ctx)); } } }; es.MappingMain = es.MappingLine; var lm = new LiteMapping <FilePathEntity>(); lm.EntityHasChanges = ctx => ctx.GetRuntimeInfo().IsNew; Mapping.RegisterValue <Lite <FilePathEntity> >(lm.GetValue); } if (embeddedFilePath) { RegisterFileConstructor <FilePathEmbedded>(data => { if (!data.FileType.HasText()) { throw new InvalidOperationException("Couldn't create FilePath with unknown FileType for file '{0}'".FormatWith(data.FileName)); } return(new FilePathEmbedded(SymbolLogic <FileTypeSymbol> .ToSymbol(data.FileType)) { FileName = data.FileName, BinaryFile = data.Content, CalculatedDirectory = data.CalculatedDirectory }.SaveFile()); }); RegisterDownloadUrlConstructor <FilePathEmbedded>(fp => { return(RouteHelper.New().Action((FileController fc) => fc.DownloadEmbedded(fp.FileType.ToLite(), fp.Suffix, fp.FileName))); }); Navigator.AddSettings(new List <EntitySettings> { new EmbeddedEntitySettings <FilePathEmbedded> { PartialViewName = e => ViewPrefix.FormatWith("EmbeddedFilePath") }, }); var es = Navigator.EmbeddedEntitySettings <FilePathEmbedded>(); var baseMapping = (Mapping <FilePathEmbedded>)es.MappingDefault.AsEntityMapping().RemoveProperty(fp => fp.BinaryFile); es.MappingDefault = ctx => { RuntimeInfo runtimeInfo = ctx.GetRuntimeInfo(); if (runtimeInfo == null) { return(null); } else { HttpPostedFileBase hpf = GetHttpRequestFile(ctx); if (hpf != null) { string fileType = ctx.Inputs[FileLineKeys.FileType]; return(new FilePathEmbedded(SymbolLogic <FileTypeSymbol> .ToSymbol(fileType)) { FileName = Path.GetFileName(hpf.FileName), BinaryFile = hpf.InputStream.ReadAllBytes(), }); } else if (ctx.Inputs.ContainsKey(EntityBaseKeys.EntityState)) { return((FilePathEmbedded)Navigator.Manager.DeserializeEntity(ctx.Inputs[EntityBaseKeys.EntityState])); } else { return(baseMapping(ctx)); } } }; } if (filePath || embeddedFilePath) { Navigator.AddSetting(new EntitySettings <FileTypeSymbol>()); } var dqm = DynamicQueryManager.Current; QuerySettings.FormatRules.Add(new FormatterRule("WebImage", col => col.Type == typeof(WebImage), col => new CellFormatter((help, obj) => (obj == null || ((WebImage)obj)?.FullWebPath.HasText() == false) ? null : new HtmlTag("img") .Attr("src", RouteHelper.New().Content(((WebImage)obj).FullWebPath)) .Attr("alt", typeof(WebImage).NiceName()) .Attr("style", "width:80px").ToHtmlSelf()) { TextAlign = "center" } )); QuerySettings.FormatRules.Add(new FormatterRule("WebDownload", col => col.Type == typeof(WebDownload), col => new CellFormatter((help, obj) => ((WebDownload)obj)?.FullWebPath.HasText() == false ? null : new MvcHtmlString("<a href='{0}'>{1}</a>".FormatWith(RouteHelper.New().Content(((WebDownload)obj).FullWebPath), ((WebDownload)obj).FileName ?? typeof(WebDownload).NiceName()))) { TextAlign = "center" } )); } }
static void RegisterTypes() { Navigator.AddSetting(new EmbeddedEntitySettings <TypeConditionRuleEmbedded>()); string viewPrefix = "~/authAdmin/Views/{0}.cshtml"; Navigator.AddSetting(new ModelEntitySettings <TypeRulePack> { PartialViewName = e => viewPrefix.FormatWith("types"), MappingDefault = new EntityMapping <TypeRulePack>(false) .SetProperty(m => m.Rules, new MListDictionaryMapping <TypeAllowedRule, TypeEntity>(a => a.Resource, new EntityMapping <TypeAllowedRule>(false) .SetProperty(p => p.Allowed, ctx => new TypeAllowedAndConditions( ParseTypeAllowed(ctx.Inputs.SubDictionary("Fallback")), ctx.Inputs.SubDictionary("Conditions").IndexSubDictionaries().Select(d => new TypeConditionRuleEmbedded( SymbolLogic <TypeConditionSymbol> .ToSymbol(d["ConditionName"]), ParseTypeAllowed(d.SubDictionary("Allowed"))) ).ToMList())) )) }); RegisterSaveButton <TypeRulePack>("types", false); }