Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public static void Start(OperationManager operationManager)
        {
            if (Navigator.Manager.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                Manager = operationManager;

                Navigator.AddSetting(new EntitySettings <OperationLogEntity>()
                {
                    View = e => new OperationLog()
                });

                Navigator.Manager.GetButtonBarElementGlobal += Manager.ButtonBar_GetButtonBarElement;
                Navigator.Manager.IsCreable += Manager_IsCreable;

                SearchControl.GetContextMenuItems += Manager.SearchControl_GetConstructorFromManyMenuItems;
                SearchControl.GetContextMenuItems += Manager.SearchControl_GetEntityOperationMenuItem;

                Server.SetSymbolIds <OperationSymbol>();

                LinksClient.RegisterEntityLinks <Entity>((entity, control) => new[]
                {
                    entity.GetType() == typeof(OperationLogEntity) ? null :
                    new QuickLinkExplore(new ExploreOptions(typeof(OperationLogEntity), "Target", entity)
                    {
                        OrderOptions = { new OrderOption("Start") }
                    })
                    {
                        IsShy = true
                    }
                });
            }
        }
Exemplo n.º 3
0
        public static void Start()
        {
            if (Navigator.Manager.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                TypeClient.Start();
                QueryClient.Start();
                Navigator.AddSetting(new EntitySettings <UserQueryEntity> {
                    View = _ => new UserQuery(), Icon = ExtensionsImageLoader.GetImageSortName("userQuery.png")
                });
                SearchControl.GetMenuItems += SearchControl_GetCustomMenuItems;
                UserAssetsClient.Start();
                UserAssetsClient.RegisterExportAssertLink <UserQueryEntity>();

                Constructor.Register <UserQueryEntity>(ctx =>
                {
                    MessageBox.Show(Window.GetWindow(ctx.Element),
                                    ChartMessage._0CanOnlyBeCreatedFromTheSearchWindow.NiceToString().FormatWith(typeof(UserQueryEntity).NicePluralName()),
                                    ChartMessage.CreateNew.NiceToString(),
                                    MessageBoxButton.OK, MessageBoxImage.Information);
                    return(null);
                });

                LinksClient.RegisterEntityLinks <Entity>((entity, ctrl) =>
                {
                    if (!UserQueryPermission.ViewUserQuery.IsAuthorized())
                    {
                        return(null);
                    }

                    return(Server.Return((IUserQueryServer us) => us.GetUserQueriesEntity(entity.EntityType))
                           .Select(cp => new UserQueryQuickLink(cp, entity)).ToArray());
                });
            }
        }
Exemplo n.º 4
0
        public static void Start()
        {
            if (Navigator.Manager.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                Navigator.RegisterArea(typeof(IsolationClient));

                WidgetsHelper.GetWidget += ctx => ctx.Entity is Entity && MixinDeclarations.IsDeclared(ctx.Entity.GetType(), typeof(IsolationMixin)) ?
                                           IsolationWidgetHelper.CreateWidget(ctx) : null;

                Navigator.AddSetting(new EntitySettings <IsolationEntity> {
                    PartialViewName = _ => ViewPrefix.FormatWith("Isolation")
                });

                Constructor.ClientManager.GlobalPreConstructors += ctx =>
                                                                   (!MixinDeclarations.IsDeclared(ctx.Type, typeof(IsolationMixin)) || IsolationEntity.Current != null) ? null :
                                                                   Module["getIsolation"](ClientConstructorManager.ExtraJsonParams, ctx.Prefix,
                                                                                          IsolationMessage.SelectAnIsolation.NiceToString(),
                                                                                          GetIsolationChooserOptions(ctx.Type));

                //Unnecessary with the filter
                Constructor.Manager.PreConstructors += ctx =>
                                                       !MixinDeclarations.IsDeclared(ctx.Type, typeof(IsolationMixin)) ? null :
                                                       IsolationEntity.Override(GetIsolation(ctx.Controller.ControllerContext));

                MapClient.GetColorProviders += GetMapColors;
            }
        }
Exemplo n.º 5
0
        public static void Start(bool toExcel, bool excelReport)
        {
            if (Navigator.Manager.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                if (excelReport)
                {
                    if (toExcel)
                    {
                        SearchControl.GetMenuItems += sc => (sc.QueryName as Type) == typeof(ExcelReportEntity) ? null : ExcelMenuItemConstructor.Construct(sc, PlainExcelMenuItemConstructor.Construct(sc));
                    }
                    else
                    {
                        SearchControl.GetMenuItems += sc => (sc.QueryName as Type) == typeof(ExcelReportEntity) ? null : ExcelMenuItemConstructor.Construct(sc, null);
                    }

                    QueryClient.Start();

                    Navigator.AddSetting(new EntitySettings <ExcelReportEntity> {
                        View = e => new ExcelReport()
                    });
                }
                else
                {
                    if (toExcel)
                    {
                        SearchControl.GetMenuItems += sc => PlainExcelMenuItemConstructor.Construct(sc);
                    }
                }
            }
        }
Exemplo n.º 6
0
        public static void Start(bool package, bool packageOperation)
        {
            if (Navigator.Manager.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                Navigator.AddSetting(new EntitySettings <ProcessAlgorithmSymbol> {
                    View = e => new ProcessAlgorithm(), Icon = Image("processAlgorithm.png")
                });
                Navigator.AddSetting(new EntitySettings <ProcessEntity> {
                    View = e => new ProcessUI(), Icon = Image("process.png")
                });


                Server.SetSymbolIds <ProcessAlgorithmSymbol>();

                OperationClient.AddSettings(new List <OperationSettings>()
                {
                    new EntityOperationSettings <ProcessEntity>(ProcessOperation.Plan)
                    {
                        Icon = Image("plan.png"), Click = ProcessOperation_Plan
                    },
                    new EntityOperationSettings <ProcessEntity>(ProcessOperation.Cancel)
                    {
                        Icon = Image("stop.png")
                    },
                    new EntityOperationSettings <ProcessEntity>(ProcessOperation.Execute)
                    {
                        Icon = Image("play.png")
                    },
                    new EntityOperationSettings <ProcessEntity>(ProcessOperation.Suspend)
                    {
                        Icon = Image("pause.png")
                    },
                });

                if (packageOperation || package)
                {
                    Navigator.AddSetting(new EntitySettings <PackageLineEntity> {
                        View = e => new PackageLine(), Icon = Image("packageLine.png")
                    });
                }

                if (package)
                {
                    Navigator.AddSetting(new EntitySettings <PackageEntity> {
                        View = e => new Package(), Icon = Image("package.png")
                    });
                }

                if (packageOperation)
                {
                    Navigator.AddSetting(new EntitySettings <PackageOperationEntity> {
                        View = e => new PackageOperation(), Icon = Image("package.png")
                    });

                    SearchControl.GetContextMenuItems += SearchControl_GetContextMenuItems;
                }
            }
        }
Exemplo n.º 7
0
 public static void Start()
 {
     if (Navigator.Manager.NotDefined(MethodInfo.GetCurrentMethod()))
     {
         Navigator.AddSetting(new EntitySettings <ExceptionEntity>()
         {
             View = e => new ExceptionCtrl(), Icon = ImageLoader.GetImageSortName("exception.png")
         });
     }
 }
Exemplo n.º 8
0
 public static void Start()
 {
     if (Navigator.Manager.NotDefined(MethodInfo.GetCurrentMethod()))
     {
         Navigator.AddSetting(new EntitySettings <TypeEntity>()
         {
             View = e => new TypeUI()
         });
     }
 }
Exemplo n.º 9
0
        public static void Start()
        {
            if (Navigator.Manager.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                if (!Navigator.Manager.EntitySettings.ContainsKey(typeof(TypeEntity)))
                {
                    Navigator.AddSetting(new EntitySettings <TypeEntity>());
                }

                Navigator.AddSettings(new List <EntitySettings>
                {
                    new ModelEntitySettings <ChartPaletteModel>
                    {
                        PartialViewName = _ => ChartClient.ViewPrefix.FormatWith("ChartPalette"),
                        MappingDefault  = new EntityMapping <ChartPaletteModel>(true)
                                          .SetProperty(a => a.Colors, new MListDictionaryMapping <ChartColorEntity, Lite <Entity> >(cc => cc.Related,
                                                                                                                                    new EntityMapping <ChartColorEntity>(false)
                                                                                                                                    .CreateProperty(m => m.Color)
                                                                                                                                    .CreateProperty(c => c.Related)))
                    }
                });

                ChartUtils.GetChartColor = ChartColorLogic.ColorFor;

                ButtonBarEntityHelper.RegisterEntityButtons <ChartPaletteModel>((ctx, entity) =>
                {
                    var typeName = Navigator.ResolveWebTypeName(entity.Type.ToType());
                    return(new[]
                    {
                        new ToolBarButton(ctx.Prefix, "savePalette")
                        {
                            Text = ChartMessage.SavePalette.NiceToString(),
                            Style = BootstrapStyle.Primary,
                            OnClick = Module["savePalette"](ctx.Url.Action <ColorChartController>(pc => pc.SavePalette(typeName)))
                        },
                        new ToolBarButton(ctx.Prefix, "newPalette")
                        {
                            Text = ChartMessage.NewPalette.NiceToString(),
                            OnClick = Module["createPalette"](
                                ctx.Url.Action <ColorChartController>(pc => pc.CreateNewPalette(typeName)),
                                ChartColorLogic.Palettes.Keys,
                                ChartMessage.ChooseABasePalette.NiceToString())
                        },
                        new ToolBarButton(ctx.Prefix, "deletePalette")
                        {
                            Text = ChartMessage.DeletePalette.NiceToString(),
                            Style = BootstrapStyle.Danger,
                            OnClick = Module["deletePalette"](
                                ctx.Url.Action <ColorChartController>(pc => pc.DeletePalette(typeName)))
                        }
                    });
                });
            }
        }
Exemplo n.º 10
0
        public static void Start()
        {
            if (Navigator.Manager.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                Navigator.RegisterArea(typeof(DiffLogClient));

                Navigator.AddSetting(new EntitySettings <OperationLogEntity> {
                    PartialViewName = e => ViewPrefix.FormatWith("OperationLog")
                });

                LinksClient.RegisterEntityLinks <Entity>((ident, ctx) => new[] { new QuickLinkExplore(typeof(OperationLogEntity), "Target", ident) });
            }
        }
Exemplo n.º 11
0
 public static void Start()
 {
     if (Navigator.Manager.NotDefined(MethodInfo.GetCurrentMethod()))
     {
         Navigator.AddSetting(new EntitySettings <ExceptionEntity>()
         {
             PartialViewName = e => NavigationManager.ViewPrefix.FormatWith("Exception")
         });
         Navigator.AddSetting(new EmbeddedEntitySettings <DeleteLogParametersEmbedded>()
         {
             PartialViewName = e => NavigationManager.ViewPrefix.FormatWith("DeleteLogParameters")
         });
     }
 }
Exemplo n.º 12
0
        public static void Start(bool packages, bool packageOperations)
        {
            if (Navigator.Manager.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                Navigator.RegisterArea(typeof(ProcessClient), "Processes");

                UrlsRepository.DefaultSFUrls.Add("processFromMany", url => url.Action((ProcessController pc) => pc.ProcessFromMany()));

                Navigator.AddSettings(new List <EntitySettings>
                {
                    new EntitySettings <ProcessEntity> {
                        PartialViewName = e => ViewPrefix.FormatWith("Process"),
                    },
                    new EntitySettings <ProcessAlgorithmSymbol> {
                        PartialViewName = e => ViewPrefix.FormatWith("ProcessAlgorithm")
                    },
                });

                if (packages || packageOperations)
                {
                    Navigator.AddSetting(new EntitySettings <PackageLineEntity> {
                        PartialViewName = e => ViewPrefix.FormatWith("PackageLine")
                    });
                }

                if (packages)
                {
                    Navigator.AddSetting(new EntitySettings <PackageEntity> {
                        PartialViewName = e => ViewPrefix.FormatWith("Package")
                    });
                }

                if (packageOperations)
                {
                    Navigator.AddSetting(new EntitySettings <PackageOperationEntity> {
                        PartialViewName = e => ViewPrefix.FormatWith("PackageOperation")
                    });

                    OperationClient.Manager.CustomizeMenuItem += CustomizeMenuItemForProcess;
                }

                SpecialOmniboxProvider.Register(new SpecialOmniboxAction("ProcessPanel",
                                                                         () => ProcessPermission.ViewProcessPanel.IsAuthorized(),
                                                                         uh => uh.Action((ProcessController pc) => pc.View())));
            }
        }
Exemplo n.º 13
0
        public static void Start(bool smtp, bool pop3)
        {
            if (Navigator.Manager.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                Navigator.AddSettings(new List <EntitySettings>
                {
                    new EntitySettings <EmailMessageEntity> {
                        View = e => new EmailMessage()
                    },
                    new EmbeddedEntitySettings <EmailAttachmentEmbedded> {
                        View = e => new EmailAttachment()
                    },
                    new EmbeddedEntitySettings <EmailAddressEmbedded> {
                        View = e => new EmailAddress()
                    },
                    new EmbeddedEntitySettings <EmailRecipientEntity> {
                        View = e => new EmailRecipient()
                    }
                });

                if (smtp || pop3)
                {
                    Navigator.AddSetting(new EmbeddedEntitySettings <ClientCertificationFileEmbedded> {
                        View = e => new ClientCertificationFile()
                    });
                }

                if (smtp)
                {
                    Navigator.AddSettings(new List <EntitySettings>
                    {
                        new EntitySettings <SmtpConfigurationEntity> {
                            View = e => new SmtpConfiguration()
                        },
                    });
                }

                if (pop3)
                {
                    Navigator.AddSetting(new EntitySettings <Pop3ConfigurationEntity> {
                        View = e => new Pop3Configuration()
                    });
                }
            }
        }
Exemplo n.º 14
0
        public static void Start(bool toExcelPlain, bool excelReport, bool excelAttachment)
        {
            if (Navigator.Manager.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                ToExcelPlain = toExcelPlain;
                ExcelReport  = excelReport;

                Navigator.RegisterArea(typeof(ExcelClient));

                if (excelReport)
                {
                    if (!Navigator.Manager.EntitySettings.ContainsKey(typeof(FileEmbedded)))
                    {
                        throw new InvalidOperationException("Call FileEmbedded first");
                    }

                    if (!Navigator.Manager.EntitySettings.ContainsKey(typeof(QueryEntity)))
                    {
                        Navigator.Manager.EntitySettings.Add(typeof(QueryEntity), new EntitySettings <QueryEntity>());
                    }


                    Navigator.AddSetting(new EntitySettings <ExcelReportEntity> {
                        PartialViewName = _ => ViewPrefix.FormatWith("ExcelReport")
                    });
                }

                if (toExcelPlain || excelReport)
                {
                    ButtonBarQueryHelper.RegisterGlobalButtons(ButtonBarQueryHelper_GetButtonBarForQueryName);
                }

                if (excelAttachment)
                {
                    Navigator.AddSetting(new EntitySettings <ExcelAttachmentEntity> {
                        PartialViewName = _ => ViewPrefix.FormatWith("ExcelAttachment")
                    });
                }
            }
        }
Exemplo n.º 15
0
        public static void Start(params Type[] types)
        {
            if (Navigator.Manager.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                if (types == null)
                {
                    throw new ArgumentNullException("types");
                }

                WidgetPanel.GetWidgets += (obj, mainControl) =>
                {
                    if (obj is Entity && types.Contains(obj.GetType()) && !((Entity)obj).IsNew && Finder.IsFindable(typeof(NoteEntity)))
                    {
                        return(new NotesWidget());
                    }

                    return(null);
                };

                Server.SetSemiSymbolIds <NoteTypeEntity>();

                OperationClient.AddSettings(new List <OperationSettings>
                {
                    new EntityOperationSettings <Entity>(NoteOperation.CreateNoteFromEntity)
                    {
                        IsVisible = _ => false
                    }
                });

                Navigator.AddSetting(new EntitySettings <NoteTypeEntity> {
                    View = e => new NoteType()
                });
                Navigator.AddSetting(new EntitySettings <NoteEntity>
                {
                    View      = e => new Note(),
                    IsCreable = EntityWhen.Never,
                    Icon      = ExtensionsImageLoader.GetImageSortName("note2.png")
                });
            }
        }
Exemplo n.º 16
0
        static void Register <T, AR, R, A, K>(string partialViewName, Expression <Func <AR, K> > getKey, Mapping <A> allowedMapping, bool embedded)
            where T : BaseRulePack <AR>
            where AR : AllowedRule <R, A>, new()
            where R : Entity
        {
            if (!Navigator.Manager.EntitySettings.ContainsKey(typeof(R)))
            {
                Navigator.AddSetting(new EntitySettings <R>());
            }

            string viewPrefix = "~/authAdmin/Views/{0}.cshtml";

            Navigator.AddSetting(new ModelEntitySettings <T>
            {
                PartialViewName = e => viewPrefix.FormatWith(partialViewName),
                MappingDefault  = new EntityMapping <T>(false)
                                  .SetProperty(m => m.Rules,
                                               new MListDictionaryMapping <AR, K>(getKey,
                                                                                  new EntityMapping <AR>(false).SetProperty(p => p.Allowed, allowedMapping)))
            });

            RegisterSaveButton <T>(partialViewName, embedded);
        }
Exemplo n.º 17
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"
                }
                                                                ));
            }
        }
Exemplo n.º 18
0
        public static void Start(bool types, bool property, bool queries, bool permissions, bool operations, bool defaultPasswordExpiresLogic)
        {
            if (Navigator.Manager.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                Server.Connecting += UpdateCache;

                if (types)
                {
                    TypeAuthClient.Start();
                }
                if (property)
                {
                    PropertyAuthClient.Start();
                }
                if (queries)
                {
                    QueryAuthClient.Start();
                }
                if (permissions)
                {
                    PermissionAuthClient.Start();
                }
                if (operations)
                {
                    OperationAuthClient.Start();
                }

                UpdateCache();

                Navigator.AddSetting(new EntitySettings <UserEntity> {
                    View = e => new User(), Icon = ImageLoader.GetImageSortName("user.png")
                });
                Navigator.AddSetting(new EntitySettings <RoleEntity> {
                    View = e => new Role(), Icon = ImageLoader.GetImageSortName("role.png")
                });

                if (defaultPasswordExpiresLogic)
                {
                    Navigator.AddSetting(new EntitySettings <PasswordExpiresIntervalEntity> {
                        View = e => new PasswordExpiresInterval()
                    });
                }

                OperationClient.AddSettings(new List <OperationSettings>()
                {
                    new EntityOperationSettings <UserEntity>(UserOperation.SetPassword)
                    {
                        IsVisible = e => false
                    },
                    new EntityOperationSettings <UserEntity>(UserOperation.SaveNew)
                    {
                        IsVisible = e => e.Entity.IsNew
                    },
                    new EntityOperationSettings <UserEntity>(UserOperation.Save)
                    {
                        IsVisible = e => !e.Entity.IsNew
                    }
                });

                SpecialOmniboxProvider.Register(new SpecialOmniboxAction("UpdateAuthCache",
                                                                         () => true,
                                                                         win =>
                {
                    UpdateCache();

                    MessageBox.Show(AuthMessage.AuthorizationCacheSuccessfullyUpdated.NiceToString());
                }));

                SpecialOmniboxProvider.Register(new SpecialOmniboxAction("DownloadAuthRules",
                                                                         () => BasicPermission.AdminRules.IsAuthorized(),
                                                                         win =>
                {
                    SaveFileDialog sfc = new SaveFileDialog()
                    {
                        FileName = "AuthRules.xml"
                    };
                    if (sfc.ShowDialog() == true)
                    {
                        var bytes = Server.Return((ILoginServer ls) => ls.DownloadAuthRules());

                        File.WriteAllBytes(sfc.FileName, bytes);
                    }
                }));
            }
        }
Exemplo n.º 19
0
        public static void Start(bool types, bool properties, bool queries, bool operations, bool permissions)
        {
            if (Navigator.Manager.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                Navigator.RegisterArea(typeof(AuthAdminClient));
                if (Navigator.Manager.EntitySettings.ContainsKey(typeof(UserEntity)))
                {
                    Navigator.EntitySettings <UserEntity>().PartialViewName = _ => ViewPrefix.FormatWith("User");
                }
                else
                {
                    Navigator.AddSetting(new EntitySettings <UserEntity> {
                        PartialViewName = _ => ViewPrefix.FormatWith("User")
                    });
                }

                Navigator.EntitySettings <UserEntity>().MappingMain.AsEntityMapping().RemoveProperty(a => a.PasswordHash);

                if (Navigator.Manager.EntitySettings.ContainsKey(typeof(RoleEntity)))
                {
                    Navigator.EntitySettings <RoleEntity>().PartialViewName = _ => ViewPrefix.FormatWith("Role");
                }
                else
                {
                    Navigator.AddSetting(new EntitySettings <RoleEntity> {
                        PartialViewName = _ => ViewPrefix.FormatWith("Role")
                    });
                }

                if (types)
                {
                    RegisterTypes();
                }

                if (properties)
                {
                    Register <PropertyRulePack, PropertyAllowedRule, PropertyRouteEntity, PropertyAllowed, string>("properties", a => a.Resource.Path,
                                                                                                                   Mapping.New <PropertyAllowed>(), true);
                }

                if (queries)
                {
                    QueryClient.Start();

                    Register <QueryRulePack, QueryAllowedRule, QueryEntity, QueryAllowed, string>("queries", a => a.Resource.Key,
                                                                                                  Mapping.New <QueryAllowed>(), true);
                }

                if (operations)
                {
                    Register <OperationRulePack, OperationAllowedRule, OperationSymbol, OperationAllowed, OperationSymbol>("operations", a => a.Resource,
                                                                                                                           Mapping.New <OperationAllowed>(), true);
                }

                if (permissions)
                {
                    Register <PermissionRulePack, PermissionAllowedRule, PermissionSymbol, bool, PermissionSymbol>("permissions", a => a.Resource,
                                                                                                                   Mapping.New <bool>(), false);
                }

                LinksClient.RegisterEntityLinks <RoleEntity>((role, ctx) =>
                                                             !BasicPermission.AdminRules.IsAuthorized() ? null :
                                                             new[]
                {
                    types ? new QuickLinkAction(AuthAdminMessage.TypeRules, RouteHelper.New().Action((AuthAdminController c) => c.Types(role))): null,
                    permissions ? new QuickLinkAction(AuthAdminMessage.PermissionRules, RouteHelper.New().Action((AuthAdminController c) => c.Permissions(role))): null,
                });

                SpecialOmniboxProvider.Register(new SpecialOmniboxAction("DownloadAuthRules",
                                                                         () => BasicPermission.AdminRules.IsAuthorized(),
                                                                         uh => uh.Action((AuthAdminController aac) => aac.Export())));

                MapClient.GetColorProviders += GetMapColors;
            }
        }
Exemplo n.º 20
0
        public static void Start(bool types, bool property, bool queries, bool resetPassword, bool passwordExpiration, bool singleSignOnMessage)
        {
            if (Navigator.Manager.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                ResetPasswordStarted = resetPassword;
                SingleSignOnMessage  = singleSignOnMessage;

                Navigator.RegisterArea(typeof(AuthClient));

                if (!Navigator.Manager.EntitySettings.ContainsKey(typeof(UserEntity)))
                {
                    Navigator.AddSetting(new EntitySettings <UserEntity>());
                }

                if (!Navigator.Manager.EntitySettings.ContainsKey(typeof(RoleEntity)))
                {
                    Navigator.AddSetting(new EntitySettings <RoleEntity>());
                }

                if (resetPassword)
                {
                    Navigator.AddSetting(new EntitySettings <ResetPasswordRequestEntity>());
                }

                if (passwordExpiration)
                {
                    Navigator.AddSetting(new EntitySettings <PasswordExpiresIntervalEntity> {
                        PartialViewName = _ => ViewPrefix.FormatWith("PasswordValidInterval")
                    });
                }

                Navigator.AddSetting(new ModelEntitySettings <SetPasswordModel>
                {
                    PartialViewName = _ => ViewPrefix.FormatWith("SetPassword"),
                    MappingDefault  = new EntityMapping <SetPasswordModel>(false)
                                      .SetProperty(a => a.PasswordHash, ctx => UserMapping.GetNewPassword(ctx, UserMapping.NewPasswordKey, UserMapping.NewPasswordBisKey))
                });

                if (property)
                {
                    Common.CommonTask += TaskAuthorizeProperties;
                    Mapping.CanChange += Mapping_CanChange;
                }


                var manager = Navigator.Manager;
                if (types)
                {
                    manager.IsCreable  += manager_IsCreable;
                    manager.IsReadOnly += manager_IsReadOnly;
                    manager.IsViewable += manager_IsViewable;
                }

                if (queries)
                {
                    Finder.Manager.IsFindable += q => QueryAuthLogic.GetQueryAllowed(q) != QueryAllowed.None;
                }

                AuthenticationRequiredAttribute.Authenticate = context =>
                {
                    if (UserEntity.Current == null)
                    {
                        string returnUrl = context.HttpContext.Request.SuggestedReturnUrl().PathAndQuery;

                        //send them off to the login page
                        string loginUrl = PublicLoginUrl(returnUrl);
                        context.Result = context.Controller.RedirectHttpOrAjax(loginUrl);
                    }
                };

                Schema.Current.EntityEvents <UserEntity>().Saving += AuthClient_Saving;

                var defaultException = SignumExceptionHandlerAttribute.OnControllerException;
                SignumExceptionHandlerAttribute.OnControllerException = ctx =>
                {
                    if (ctx.Exception is UnauthorizedAccessException && (UserEntity.Current == null || UserEntity.Current.Is(AuthLogic.AnonymousUser)))
                    {
                        string returnUrl = ctx.HttpContext.Request.SuggestedReturnUrl().PathAndQuery;
                        string loginUrl  = PublicLoginUrl(returnUrl);

                        DefaultOnControllerUnauthorizedAccessException(ctx, loginUrl);
                    }
                    else
                    {
                        defaultException(ctx);
                    }
                };

                OperationClient.AddSettings(new List <OperationSettings>
                {
                    new EntityOperationSettings <UserEntity>(UserOperation.SetPassword)
                    {
                        Click = ctx => Module["setPassword"](ctx.Options(),
                                                             ctx.Url.Action((AuthController c) => c.SetPasswordModel()),
                                                             ctx.Url.Action((AuthController c) => c.SetPasswordOnOk()))
                    },

                    new EntityOperationSettings <UserEntity>(UserOperation.SaveNew)
                    {
                        Click = ctx => Module["saveNew"](ctx.Options(),
                                                         ctx.Url.Action((AuthController c) => c.SaveNewUser()))
                    }
                });
            }
        }