Ejemplo n.º 1
0
        internal static void Start(SchemaBuilder sb)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                SymbolLogic <ChartScriptSymbol> .Start(sb, () => Scripts.Keys);

                ChartRequestModel.GetChartScriptFunc = s => Scripts.GetOrThrow(s);

                RegisterScript(new BarsChartScript());
                RegisterScript(new ColumnsChartScript());
                RegisterScript(new LineChartScript());

                RegisterScript(new MultiBarsChartScript());
                RegisterScript(new MultiColumnsChartScript());
                RegisterScript(new MultiLinesChartScript());

                RegisterScript(new StackedBarsChartScript());
                RegisterScript(new StackedColumnsChartScript());
                RegisterScript(new StackedLinesChartScript());

                RegisterScript(new PieChartScript());
                RegisterScript(new BubblePackChartScript());

                RegisterScript(new ScatterplotChartScript());
                RegisterScript(new BubbleplotChartScript());

                RegisterScript(new ParallelCoordiantesChartScript());
                RegisterScript(new PunchcardChartScript());
                RegisterScript(new CalendarStreamChartScript());
                RegisterScript(new TreeMapChartScript());

                RegisterScript(new HeatmapChartScript());
                RegisterScript(new MarkermapChartScript());
            }
        }
Ejemplo n.º 2
0
        public static Dictionary <string, TypeInfoTS> GetSymbolContainers(IEnumerable <Type> allTypes)
        {
            SymbolLogic.LoadAll();

            var result = (from type in allTypes
                          where type.IsStaticClass() && type.HasAttribute <AutoInitAttribute>()
                          select KVP.Create(GetTypeName(type), OnAddTypeExtension(new TypeInfoTS
            {
                Kind = KindOfType.SymbolContainer,
                FullName = type.FullName,
                Members = type.GetFields(staticFlags)
                          .Select(f => GetSymbolInfo(f))
                          .Where(s =>
                                 s.FieldInfo != null &&  /*Duplicated like in Dynamic*/
                                 s.IdOrNull.HasValue /*Not registered*/)
                          .ToDictionary(s => s.FieldInfo.Name, s => OnAddFieldInfoExtension(new MemberInfoTS
                {
                    NiceName = s.FieldInfo.NiceName(),
                    Id = s.IdOrNull.Value.Object
                }, s.FieldInfo))
            }, type)))
                         .Where(a => a.Value.Members.Any())
                         .ToDictionaryEx("symbols");

            return(result);
        }
Ejemplo n.º 3
0
 public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
 {
     if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
     {
         SymbolLogic <ModelConverterSymbol> .Start(sb, dqm, () => Converters.Keys);
     }
 }
Ejemplo n.º 4
0
        public static void Start(SchemaBuilder sb)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                AuthLogic.AssertStarted(sb);
                OperationLogic.AssertStarted(sb);

                OperationLogic.AllowOperation += OperationLogic_AllowOperation;

                cache = new AuthCache <RuleOperationEntity, OperationAllowedRule, OperationSymbol, OperationSymbol, OperationAllowed>(sb,
                                                                                                                                      s => s,
                                                                                                                                      s => s,
                                                                                                                                      merger: new OperationMerger(),
                                                                                                                                      invalidateWithTypes: true,
                                                                                                                                      coercer:  OperationCoercer.Instance);

                AuthLogic.ExportToXml += exportAll => cache.ExportXml("Operations", "Operation", s => s.Key, b => b.ToString(),
                                                                      exportAll ? OperationLogic.RegisteredOperations.ToList() : null);
                AuthLogic.ImportFromXml += (x, roles, replacements) =>
                {
                    string replacementKey = "AuthRules:" + typeof(OperationSymbol).Name;

                    replacements.AskForReplacements(
                        x.Element("Operations").Elements("Role").SelectMany(r => r.Elements("Operation")).Select(p => p.Attribute("Resource").Value).ToHashSet(),
                        SymbolLogic <OperationSymbol> .AllUniqueKeys(),
                        replacementKey);

                    return(cache.ImportXml(x, "Operations", "Operation", roles,
                                           s => SymbolLogic <OperationSymbol> .TryToSymbol(replacements.Apply(replacementKey, s)), EnumExtensions.ToEnum <OperationAllowed>));
                };
            }
        }
Ejemplo n.º 5
0
 public static void Start(SchemaBuilder sb)
 {
     if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
     {
         SymbolLogic <TypeConditionSymbol> .Start(sb, () => infos.SelectMany(a => a.Value.Keys).ToHashSet());
     }
 }
Ejemplo n.º 6
0
            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);
            }
Ejemplo n.º 7
0
            public static OperationSymbol ParseOperationAssert(string operationKey)
            {
                var symbol = SymbolLogic <OperationSymbol> .ToSymbol(operationKey);

                OperationLogic.AssertOperationAllowed(symbol, inUserInterface: true);

                return(symbol);
            }
Ejemplo n.º 8
0
        public string[] AvailableDevices(string algorithmKey)
        {
            var key = SymbolLogic <PredictorAlgorithmSymbol> .ToSymbol(algorithmKey);

            var alg = PredictorLogic.Algorithms.GetOrThrow(key);

            return(alg.GetAvailableDevices());
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
 private static MList <RuleTypeConditionEmbedded> Conditions(XElement xr, Replacements replacements)
 {
     return((from xc in xr.Elements("Condition")
             let cn = SymbolLogic <TypeConditionSymbol> .TryToSymbol(replacements.Apply(typeConditionReplacementKey, xc.Attribute("Name").Value))
                      where cn != null
                      select new RuleTypeConditionEmbedded
     {
         Condition = cn,
         Allowed = xc.Attribute("Allowed").Value.ToEnum <TypeAllowed>()
     }).ToMList());
 }
Ejemplo n.º 11
0
        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));
        }
Ejemplo n.º 12
0
        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));
        }
Ejemplo n.º 13
0
        public static void Start(SchemaBuilder sb)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                SymbolLogic <FileTypeSymbol> .Start(sb, () => FileTypes.Keys.ToHashSet());

                sb.Include <FileTypeSymbol>()
                .WithQuery(() => f => new
                {
                    Entity = f,
                    f.Key
                });
            }
        }
Ejemplo n.º 14
0
        internal SqlPreCommand?ImportXml(XElement element, Dictionary <string, Lite <RoleEntity> > roles, Replacements replacements)
        {
            var current = Database.RetrieveAll <RuleTypeEntity>().GroupToDictionary(a => a.Role);
            var xRoles  = (element.Element("Types")?.Elements("Role")).EmptyIfNull();
            var should  = xRoles.ToDictionary(x => roles.GetOrThrow(x.Attribute("Name").Value));

            Table table = Schema.Current.Table(typeof(RuleTypeEntity));

            replacements.AskForReplacements(
                xRoles.SelectMany(x => x.Elements("Type")).Select(x => x.Attribute("Resource").Value).ToHashSet(),
                TypeLogic.NameToType.Where(a => !a.Value.IsEnumEntity()).Select(a => a.Key).ToHashSet(), typeReplacementKey);

            replacements.AskForReplacements(
                xRoles.SelectMany(x => x.Elements("Type")).SelectMany(t => t.Elements("Condition")).Select(x => x.Attribute("Name").Value).ToHashSet(),
                SymbolLogic <TypeConditionSymbol> .AllUniqueKeys(),
                typeConditionReplacementKey);

            Func <string, TypeEntity?> getResource = s =>
            {
                Type?type = TypeLogic.NameToType.TryGetC(replacements.Apply(typeReplacementKey, s));

                if (type == null)
                {
                    return(null);
                }

                return(TypeLogic.TypeToEntity.GetOrThrow(type));
            };


            return(Synchronizer.SynchronizeScript(Spacing.Double, should, current,
                                                  createNew: (role, x) =>
            {
                var dic = (from xr in x.Elements("Type")
                           let t = getResource(xr.Attribute("Resource").Value)
                                   where t != null
                                   select KVP.Create(t, new
                {
                    Allowed = xr.Attribute("Allowed").Value.ToEnum <TypeAllowed>(),
                    Condition = Conditions(xr, replacements)
                })).ToDictionaryEx("Type rules for {0}".FormatWith(role));

                SqlPreCommand?restSql = dic.Select(kvp => table.InsertSqlSync(new RuleTypeEntity
                {
                    Resource = kvp.Key,
                    Role = role,
                    Allowed = kvp.Value.Allowed,
                    Conditions = kvp.Value.Condition !    /*CSBUG*/
                }, comment: Comment(role, kvp.Key, kvp.Value.Allowed))).Combine(Spacing.Simple)?.Do(p => p.GoBefore = true);
Ejemplo n.º 15
0
        public static void Start(SchemaBuilder sb)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                AuthLogic.AssertStarted(sb);

                sb.Include <PermissionSymbol>();

                SymbolLogic <PermissionSymbol> .Start(sb, () => RegisteredPermission.ToHashSet());

                sb.Include <RulePermissionEntity>()
                .WithUniqueIndex(rt => new { rt.Resource, rt.Role });

                cache = new AuthCache <RulePermissionEntity, PermissionAllowedRule, PermissionSymbol, PermissionSymbol, bool>(sb,
                                                                                                                              toKey: p => p,
                                                                                                                              toEntity: p => p,
                                                                                                                              isEquals: (p1, p2) => p1 == p2,
                                                                                                                              merger: new PermissionMerger(),
                                                                                                                              invalidateWithTypes: false);

                sb.Schema.EntityEvents <RoleEntity>().PreUnsafeDelete += query =>
                {
                    Database.Query <RulePermissionEntity>().Where(r => query.Contains(r.Role.Entity)).UnsafeDelete();
                    return(null);
                };

                RegisterPermissions(BasicPermission.AdminRules,
                                    BasicPermission.AutomaticUpgradeOfProperties,
                                    BasicPermission.AutomaticUpgradeOfOperations,
                                    BasicPermission.AutomaticUpgradeOfQueries);

                AuthLogic.ExportToXml += exportAll => cache.ExportXml("Permissions", "Permission", a => a.Key, b => b.ToString(),
                                                                      exportAll ? PermissionAuthLogic.RegisteredPermission.ToList() : null);
                AuthLogic.ImportFromXml += (x, roles, replacements) =>
                {
                    string replacementKey = "AuthRules:" + typeof(PermissionSymbol).Name;

                    replacements.AskForReplacements(
                        x.Element("Permissions").Elements("Role").SelectMany(r => r.Elements("Permission")).Select(p => p.Attribute("Resource").Value).ToHashSet(),
                        SymbolLogic <PermissionSymbol> .Symbols.Select(s => s.Key).ToHashSet(),
                        replacementKey);

                    return(cache.ImportXml(x, "Permissions", "Permission", roles,
                                           s => SymbolLogic <PermissionSymbol> .TryToSymbol(replacements.Apply(replacementKey, s)), bool.Parse));
                };

                sb.Schema.Table <PermissionSymbol>().PreDeleteSqlSync += new Func <Entity, SqlPreCommand>(AuthCache_PreDeleteSqlSync);
            }
        }
Ejemplo n.º 16
0
        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);
        }
Ejemplo n.º 17
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                SymbolLogic <FileTypeSymbol> .Start(sb, dqm, () => FileTypes.Keys.ToHashSet());

                sb.Include <FileTypeSymbol>()
                .WithQuery(dqm, () => f => new
                {
                    Entity = f,
                    f.Key
                });

                sb.Schema.SchemaCompleted += Schema_SchemaCompleted;
            }
        }
Ejemplo n.º 18
0
        public static Dictionary <string, TypeInfoTS> GetSymbolContainers(IEnumerable <Type> allTypes)
        {
            SymbolLogic.LoadAll();

            var result = (from type in allTypes
                          where type.IsStaticClass() && type.HasAttribute <AutoInitAttribute>()
                          select KVP.Create(GetTypeName(type), OnAddTypeExtension(new TypeInfoTS
            {
                Kind = KindOfType.SymbolContainer,
                Members = type.GetFields(staticFlags).Where(f => GetSymbol(f).IdOrNull.HasValue).ToDictionary(fi => fi.Name, fi => OnAddFieldInfoExtension(new MemberInfoTS
                {
                    NiceName = fi.NiceName(),
                    Id = GetSymbol(fi).Id.Object
                }, fi))
            }, type))).ToDictionaryEx("symbols");

            return(result);
        }
Ejemplo n.º 19
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include <OperationLogEntity>();

                SymbolLogic <OperationSymbol> .Start(sb, () => RegisteredOperations);

                dqm.RegisterQuery(typeof(OperationSymbol), () =>
                                  from os in Database.Query <OperationSymbol>()
                                  select new
                {
                    Entity = os,
                    os.Id,
                    os.Key
                });

                dqm.RegisterQuery(typeof(OperationLogEntity), () =>
                                  from lo in Database.Query <OperationLogEntity>()
                                  select new
                {
                    Entity = lo,
                    lo.Id,
                    lo.Target,
                    lo.Operation,
                    lo.User,
                    lo.Start,
                    lo.End,
                    lo.Exception
                });

                dqm.RegisterExpression((OperationSymbol o) => o.Logs(), () => OperationMessage.Logs.NiceToString());
                dqm.RegisterExpression((Entity o) => o.OperationLogs(), () => typeof(OperationLogEntity).NicePluralName());

                sb.Schema.EntityEventsGlobal.Saving += EntityEventsGlobal_Saving;

                sb.Schema.Table <OperationSymbol>().PreDeleteSqlSync += new Func <Entity, SqlPreCommand>(Operation_PreDeleteSqlSync);
                sb.Schema.Table <TypeEntity>().PreDeleteSqlSync      += new Func <Entity, SqlPreCommand>(Type_PreDeleteSqlSync);

                sb.Schema.SchemaCompleted += OperationLogic_Initializing;

                ExceptionLogic.DeleteLogs += ExceptionLogic_DeleteLogs;
            }
        }
Ejemplo n.º 20
0
        public static void Start(SchemaBuilder sb)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include <OperationLogEntity>()
                .WithQuery(() => lo => new
                {
                    Entity = lo,
                    lo.Id,
                    lo.Target,
                    lo.Operation,
                    lo.User,
                    lo.Start,
                    lo.End,
                    lo.Exception
                });

                SymbolLogic <OperationSymbol> .Start(sb, () => RegisteredOperations);

                sb.Include <OperationSymbol>()
                .WithQuery(() => os => new
                {
                    Entity = os,
                    os.Id,
                    os.Key
                });

                QueryLogic.Expressions.Register((OperationSymbol o) => o.Logs(), () => OperationMessage.Logs.NiceToString());
                QueryLogic.Expressions.Register((Entity o) => o.OperationLogs(), () => typeof(OperationLogEntity).NicePluralName());


                sb.Schema.EntityEventsGlobal.Saving += EntityEventsGlobal_Saving;

                sb.Schema.Table <OperationSymbol>().PreDeleteSqlSync += new Func <Entity, SqlPreCommand>(Operation_PreDeleteSqlSync);
                sb.Schema.Table <TypeEntity>().PreDeleteSqlSync      += new Func <Entity, SqlPreCommand>(Type_PreDeleteSqlSync);

                sb.Schema.SchemaCompleted += OperationLogic_Initializing;
                sb.Schema.SchemaCompleted += () => RegisterCurrentLogs(sb.Schema);

                ExceptionLogic.DeleteLogs += ExceptionLogic_DeleteLogs;
            }
        }
Ejemplo n.º 21
0
        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);
        }
Ejemplo n.º 22
0
        internal static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                SymbolLogic <SimpleTaskSymbol> .Start(sb, dqm, () => tasks.Keys.ToHashSet());

                SchedulerLogic.ExecuteTask.Register((SimpleTaskSymbol st, ScheduledTaskContext ctx) =>
                {
                    Func <ScheduledTaskContext, Lite <IEntity> > func = tasks.GetOrThrow(st);
                    return(func(ctx));
                });

                sb.Include <SimpleTaskSymbol>()
                .WithQuery(dqm, () => ct => new
                {
                    Entity = ct,
                    ct.Id,
                    ct.Key,
                });
            }
        }
Ejemplo n.º 23
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                AuthLogic.AssertStarted(sb);

                sb.Include <PermissionSymbol>();

                SymbolLogic <PermissionSymbol> .Start(sb, dqm, () => RegisteredPermission.ToHashSet());

                cache = new AuthCache <RulePermissionEntity, PermissionAllowedRule, PermissionSymbol, PermissionSymbol, bool>(sb,
                                                                                                                              s => s,
                                                                                                                              s => s,
                                                                                                                              merger: new PermissionMerger(),
                                                                                                                              invalidateWithTypes: false);

                RegisterPermissions(BasicPermission.AdminRules,
                                    BasicPermission.AutomaticUpgradeOfProperties,
                                    BasicPermission.AutomaticUpgradeOfOperations,
                                    BasicPermission.AutomaticUpgradeOfQueries);

                AuthLogic.ExportToXml += exportAll => cache.ExportXml("Permissions", "Permission", a => a.Key, b => b.ToString(),
                                                                      exportAll ? PermissionAuthLogic.RegisteredPermission.ToList() : null);
                AuthLogic.ImportFromXml += (x, roles, replacements) =>
                {
                    string replacementKey = "AuthRules:" + typeof(PermissionSymbol).Name;

                    replacements.AskForReplacements(
                        x.Element("Permissions").Elements("Role").SelectMany(r => r.Elements("Permission")).Select(p => p.Attribute("Resource").Value).ToHashSet(),
                        SymbolLogic <PermissionSymbol> .Symbols.Select(s => s.Key).ToHashSet(),
                        replacementKey);

                    return(cache.ImportXml(x, "Permissions", "Permission", roles,
                                           s => SymbolLogic <PermissionSymbol> .TryToSymbol(replacements.Apply(replacementKey, s)), bool.Parse));
                };
            }
        }
Ejemplo n.º 24
0
 public PermissionSymbol?TryPermission(string permissionKey)
 {
     return(SymbolLogic <PermissionSymbol> .TryToSymbol(permissionKey));
 }
Ejemplo n.º 25
0
        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);
        }
Ejemplo n.º 26
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include <WordTemplateEntity>()
                .WithSave(WordTemplateOperation.Save)
                .WithDelete(WordTemplateOperation.Delete)
                .WithQuery(dqm, () => e => new
                {
                    Entity = e,
                    e.Id,
                    e.Name,
                    e.Query,
                    e.Culture,
                    e.Template.Entity.FileName
                });

                PermissionAuthLogic.RegisterPermissions(WordTemplatePermission.GenerateReport);

                SystemWordTemplateLogic.Start(sb, dqm);

                SymbolLogic <WordTransformerSymbol> .Start(sb, dqm, () => Transformers.Keys.ToHashSet());

                SymbolLogic <WordConverterSymbol> .Start(sb, dqm, () => Converters.Keys.ToHashSet());

                sb.Include <WordTransformerSymbol>()
                .WithQuery(dqm, () => f => new
                {
                    Entity = f,
                    f.Key
                });

                sb.Include <WordConverterSymbol>()
                .WithQuery(dqm, () => f => new
                {
                    Entity = f,
                    f.Key
                });


                ToDataTableProviders.Add("Model", new ModelDataTableProvider());
                ToDataTableProviders.Add("UserQuery", new UserQueryDataTableProvider());
                ToDataTableProviders.Add("UserChart", new UserChartDataTableProvider());

                dqm.RegisterExpression((SystemWordTemplateEntity e) => e.WordTemplates(), () => typeof(WordTemplateEntity).NiceName());


                new Graph <WordTemplateEntity> .Execute(WordTemplateOperation.CreateWordReport)
                {
                    CanExecute = et =>
                    {
                        if (et.SystemWordTemplate != null && SystemWordTemplateLogic.RequiresExtraParameters(et.SystemWordTemplate))
                        {
                            return(WordTemplateMessage._01RequiresExtraParameters.NiceToString(typeof(SystemWordTemplateEntity).NiceName(), et.SystemWordTemplate));
                        }

                        return(null);
                    },
                    Execute = (et, args) =>
                    {
                        throw new InvalidOperationException("UI-only operation");
                    }
                }

                .Register();

                WordTemplatesLazy = sb.GlobalLazy(() => Database.Query <WordTemplateEntity>()
                                                  .ToDictionary(et => et.ToLite()), new InvalidateWith(typeof(WordTemplateEntity)));

                TemplatesByQueryName = sb.GlobalLazy(() =>
                {
                    return(WordTemplatesLazy.Value.Values.GroupToDictionary(a => a.Query.ToQueryName()));
                }, new InvalidateWith(typeof(WordTemplateEntity)));

                TemplatesByEntityType = sb.GlobalLazy(() =>
                {
                    return((from wr in WordTemplatesLazy.Value.Values
                            let imp = DynamicQueryManager.Current.GetEntityImplementations(wr.Query.ToQueryName())
                                      where !imp.IsByAll
                                      from t in imp.Types
                                      select KVP.Create(t, wr))
                           .GroupToDictionary(a => a.Key, a => a.Value));
                }, new InvalidateWith(typeof(WordTemplateEntity)));

                Schema.Current.Synchronizing += Schema_Synchronize_Tokens;

                Validator.PropertyValidator((WordTemplateEntity e) => e.Template).StaticPropertyValidation += ValidateTemplate;
            }
        }
Ejemplo n.º 27
0
        public static WikiLink LinkParser(string content)
        {
            Match m = HelpLogic.HelpLinkRegex.Match(content);

            if (m.Success)
            {
                string letter = m.Groups["letter"].ToString();
                string link   = m.Groups["link"].ToString();
                string text   = m.Groups["text"].ToString();

                switch (letter)
                {
                case WikiFormat.EntityLink:
                    Type t = TypeLogic.TryGetType(link);
                    return(new WikiLink(
                               HelpUrls.EntityUrl(t),
                               text.HasText() ? text : t.NiceName()));

                case WikiFormat.Hyperlink:
                    return(new WikiLink(link, text));

                case WikiFormat.OperationLink:
                    OperationSymbol operation = SymbolLogic <OperationSymbol> .TryToSymbol(link);

                    List <Type> types = OperationLogic.FindTypes(operation).Where(TypeLogic.TypeToEntity.ContainsKey).ToList();
                    if (types.Count == 1)
                    {
                        return(new WikiLink(
                                   HelpUrls.OperationUrl(types[0], operation),
                                   text.HasText() ? text : operation.NiceToString()));
                    }
                    else
                    {
                        return(new MultiWikiLink(operation.NiceToString())
                        {
                            Links = types.Select(currentType =>
                                                 new WikiLink(
                                                     HelpUrls.OperationUrl(currentType, operation),
                                                     currentType.NiceName(), operation.NiceToString())).ToList()
                        });
                    }

                case WikiFormat.PropertyLink:
                    PropertyRoute route = PropertyRoute.Parse(TypeLogic.TryGetType(link.Before('.')), link.After('.'));

                    while (route.PropertyRouteType == PropertyRouteType.LiteEntity ||
                           route.PropertyRouteType == PropertyRouteType.Mixin ||
                           route.PropertyRouteType == PropertyRouteType.MListItems)
                    {
                        route = route.Parent;
                    }

                    return(new WikiLink(HelpUrls.PropertyUrl(route), route.PropertyInfo.NiceName()));

                case WikiFormat.QueryLink:
                    object o = QueryLogic.TryToQueryName(link);
                    if (o as Enum != null)
                    {
                        Enum query = (Enum)o;
                        return(new WikiLink(
                                   HelpUrls.QueryUrl(query),
                                   text.HasText() ? text : QueryUtils.GetNiceName(query)));
                    }
                    else
                    {
                        Type query = (Type)o;
                        return(new WikiLink(
                                   HelpUrls.QueryUrl(query),
                                   text.HasText() ? text : QueryUtils.GetNiceName(query)));
                    }

                case WikiFormat.NamespaceLink:
                    NamespaceHelp nameSpace = HelpLogic.GetNamespaceHelp(link);
                    return(new WikiLink(
                               HelpUrls.NamespaceUrl(link),
                               text.HasText() ? text : link,
                               nameSpace != null ? "" : "unavailable"));

                case WikiFormat.AppendixLink:
                    AppendixHelp appendix = HelpLogic.GetAppendixHelp(link);
                    return(new WikiLink(
                               HelpUrls.AppendixUrl(link),
                               text.HasText() ? text : link,
                               appendix != null ? "" : "unavailable"));
                }
            }
            return(null);
        }
Ejemplo n.º 28
0
        static string SynchronizeContent(string content, Replacements r, SyncData data)
        {
            if (content == null)
            {
                return(null);
            }

            return(WikiMarkup.WikiParserExtensions.TokenRegex.Replace(content, m =>
            {
                var m2 = HelpLinkRegex.Match(m.Groups["content"].Value);

                if (!m2.Success)
                {
                    return m.Value;
                }

                string letter = m2.Groups["letter"].Value;
                string link = m2.Groups["link"].Value;
                string text = m2.Groups["text"].Value;

                switch (letter)
                {
                case WikiFormat.EntityLink:
                    {
                        string type = r.SelectInteractive(link, TypeLogic.NameToType.Keys, "Type", data.StringDistance);

                        if (type == null)
                        {
                            return Link(letter + "-error", link, text);
                        }

                        return Link(letter, type, text);
                    }

                case WikiFormat.PropertyLink:
                    {
                        string type = r.SelectInteractive(link.Before("."), TypeLogic.NameToType.Keys, "Type", data.StringDistance);

                        if (type == null)
                        {
                            return Link(letter + "-error", link, text);
                        }

                        var routes = PropertyRoute.GenerateRoutes(TypeLogic.GetType(type)).Select(a => a.PropertyString()).ToList();

                        string pr = r.SelectInteractive(link.After('.'), routes, "PropertyRoutes-" + type, data.StringDistance);

                        if (pr == null)
                        {
                            return Link(letter + "-error", link, text);
                        }

                        return Link(letter, type + "." + pr, text);
                    }

                case WikiFormat.QueryLink:
                    {
                        string query = r.SelectInteractive(link, QueryLogic.QueryNames.Keys, "Query", data.StringDistance);

                        if (query == null)
                        {
                            return Link(letter + "-error", link, text);
                        }

                        return Link(letter, query, text);
                    }

                case WikiFormat.OperationLink:
                    {
                        string operation = r.SelectInteractive(link, SymbolLogic <OperationSymbol> .AllUniqueKeys(), "Operation", data.StringDistance);

                        if (operation == null)
                        {
                            return Link(letter + "-error", link, text);
                        }

                        return Link(letter, operation, text);
                    }

                case WikiFormat.Hyperlink: return m.Value;

                case WikiFormat.NamespaceLink:
                    {
                        string @namespace = r.SelectInteractive(link, data.Namespaces, "Namespace", data.StringDistance);

                        if (@namespace == null)
                        {
                            return Link(letter + "-error", link, text);
                        }

                        return Link(letter, @namespace, text);
                    }

                case WikiFormat.AppendixLink:
                    {
                        string appendix = r.SelectInteractive(link, data.Appendices, "Appendices", data.StringDistance);

                        if (appendix == null)
                        {
                            return Link(letter + "-error", link, text);
                        }

                        return Link(letter, appendix, text);
                    }

                default:
                    break;
                }

                return m.Value;
            }));
        }
Ejemplo n.º 29
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include <ProcessAlgorithmSymbol>()
                .WithQuery(dqm, () => pa => new
                {
                    Entity = pa,
                    pa.Id,
                    pa.Key
                });

                sb.Include <ProcessEntity>()
                .WithQuery(dqm, () => p => new
                {
                    Entity = p,
                    p.Id,
                    p.Algorithm,
                    p.Data,
                    p.State,
                    p.MachineName,
                    p.ApplicationName,
                    p.CreationDate,
                    p.PlannedDate,
                    p.CancelationDate,
                    p.QueuedDate,
                    p.ExecutionStart,
                    p.ExecutionEnd,
                    p.SuspendDate,
                    p.ExceptionDate,
                });

                sb.Include <ProcessExceptionLineEntity>()
                .WithQuery(dqm, () => p => new
                {
                    Entity = p,
                    p.Line,
                    p.Process,
                    p.Exception,
                });

                PermissionAuthLogic.RegisterPermissions(ProcessPermission.ViewProcessPanel);

                SymbolLogic <ProcessAlgorithmSymbol> .Start(sb, dqm, () => registeredProcesses.Keys.ToHashSet());

                OperationLogic.AssertStarted(sb);

                ProcessGraph.Register();

                dqm.RegisterExpression((ProcessAlgorithmSymbol p) => p.Processes(), () => typeof(ProcessEntity).NicePluralName());
                dqm.RegisterExpression((ProcessAlgorithmSymbol p) => p.LastProcess(), () => ProcessMessage.LastProcess.NiceToString());

                dqm.RegisterExpression((IProcessDataEntity p) => p.Processes(), () => typeof(ProcessEntity).NicePluralName());
                dqm.RegisterExpression((IProcessDataEntity p) => p.LastProcess(), () => ProcessMessage.LastProcess.NiceToString());

                dqm.RegisterExpression((IProcessLineDataEntity p) => p.ExceptionLines(), () => ProcessMessage.ExceptionLines.NiceToString());

                PropertyAuthLogic.AvoidAutomaticUpgradeCollection.Add(PropertyRoute.Construct((ProcessEntity p) => p.User));

                ExceptionLogic.DeleteLogs += ExceptionLogic_DeleteLogs;
            }
        }
Ejemplo n.º 30
0
        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"
                }
                                                                ));
            }
        }