/// <summary>
        /// Load applets in <paramref name="appletDirectories"/>
        /// </summary>
        private static void LoadApplets(IEnumerable <String> appletDirectories, IAppletManagerService appService)
        {
            foreach (var appletDir in appletDirectories)// Directory.GetFiles(this.m_configuration.GetSection<AppletConfigurationSection>().AppletDirectory)) {
            {
                try
                {
                    if (!Directory.Exists(appletDir) || !File.Exists(Path.Combine(appletDir, "manifest.xml")))
                    {
                        throw new DirectoryNotFoundException($"Applet {appletDir} not found");
                    }

                    String appletPath = Path.Combine(appletDir, "manifest.xml");
                    using (var fs = File.OpenRead(appletPath))
                    {
                        AppletManifest manifest = AppletManifest.Load(fs);
                        (appService as MiniAppletManagerService).m_appletBaseDir.Add(manifest, appletDir);
                        // Is this applet in the allowed applets

                        // public key token match?
                        appService.LoadApplet(manifest);
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
示例#2
0
        public byte[] GetRoutes()
        {
            // Ensure response makes sense
            MiniHdsiServer.CurrentContext.Response.ContentType = "text/javascript";

            IAppletManagerService appletService = ApplicationContext.Current.GetService <IAppletManagerService>();

            // Calculate routes
#if !DEBUG
            if (this.m_routes == null)
#endif
            using (MemoryStream ms = new MemoryStream())
            {
                using (StreamWriter sw = new StreamWriter(ms))
                {
                    sw.WriteLine("SanteDB = SanteDB || {}");
                    sw.WriteLine("SanteDB.UserInterface = SanteDB.UserInterface || {}");
                    sw.WriteLine("SanteDB.UserInterface.states = [");
                    // Collect routes
                    foreach (var itm in appletService.Applets.ViewStateAssets)
                    {
                        var htmlContent = (itm.Content ?? appletService.Applets.Resolver?.Invoke(itm)) as AppletAssetHtml;
                        var viewState   = htmlContent.ViewState;
                        sw.WriteLine($"{{ name: '{viewState.Name}', url: '{viewState.Route}', abstract: {viewState.IsAbstract.ToString().ToLower()}");
                        if (viewState.View.Count > 0)
                        {
                            sw.Write(", views: {");
                            foreach (var view in viewState.View)
                            {
                                sw.Write($"'{view.Name}' : {{ controller: '{view.Controller}', templateUrl: '{view.Route ?? itm.ToString() }'");
                                var dynScripts = appletService.Applets.GetLazyScripts(itm);
                                if (dynScripts.Any())
                                {
                                    int i = 0;
                                    sw.Write($", lazy: [ {String.Join(",", dynScripts.Select(o => $"'{appletService.Applets.ResolveAsset(o.Reference, itm)}'"))}  ]");
                                }
                                sw.WriteLine(" }, ");
                            }
                            sw.WriteLine("}");
                        }
                        sw.WriteLine("} ,");
                    }
                    sw.Write("];");
                }
                this.m_routes = ms.ToArray();
            }
            return(this.m_routes);
        }
示例#3
0
        /// <summary>
        /// DI applet BI repository
        /// </summary>
        public AppletBiRepository(IAppletManagerService appletManager, IServiceManager serviceManager, IPolicyEnforcementService policyEnforcementService, IAppletSolutionManagerService solutionManagerService = null, IBiDataSource defaultDataSource = null)
        {
            this.m_appletManager            = appletManager;
            this.m_policyEnforcementService = policyEnforcementService;
            this.m_solutionManagerService   = solutionManagerService;
            this.m_serviceManager           = serviceManager;
            this.m_defaultDataSource        = defaultDataSource;

            // Re-scans the loaded applets for definitions when the collection has changed
            this.m_appletManager.Applets.CollectionChanged += (oa, ea) =>
            {
                this.LoadAllDefinitions();
            };

            if (this.m_solutionManagerService.Solutions is INotifyCollectionChanged notify)
            {
                notify.CollectionChanged += (oa, eo) =>
                {
                    this.LoadAllDefinitions();
                };
            }
            //this.LoadAllDefinitions();
        }
        /// <summary>
        /// Load a solution file and all referneced applets
        /// </summary>
        private static void LoadSolution(String solutionFile, IAppletManagerService appService)
        {
            using (var fs = File.OpenRead(solutionFile))
            {
                var solution = AppletManifest.Load(fs);

                // Load include elements
                var solnDir = Path.GetDirectoryName(solutionFile);

                // Preload any manifests
                var refManifests = new Dictionary <String, AppletManifest>();
                // Load reference manifests
                foreach (var mfstFile in Directory.GetFiles(solnDir, "manifest.xml", SearchOption.AllDirectories))
                {
                    using (var manifestStream = File.OpenRead(mfstFile))
                    {
                        refManifests.Add(Path.GetDirectoryName(mfstFile), AppletManifest.Load(manifestStream));
                    }
                }

                // Load dependencies
                foreach (var dep in solution.Info.Dependencies)
                {
                    // Attempt to load the appropriate manifest file
                    var cand = refManifests.FirstOrDefault(o => o.Value.Info.Id == dep.Id);
                    if (cand.Value != null)
                    {
                        (appService as MiniAppletManagerService).m_appletBaseDir.Add(cand.Value, cand.Key);
                        // Is this applet in the allowed applets

                        // public key token match?
                        appService.LoadApplet(cand.Value);
                    }
                }
            }
        }
示例#5
0
 /// <summary>
 /// Dependency injection header for localization service
 /// </summary>
 public AppletLocalizationService(IAppletManagerService appletManager, IAppletSolutionManagerService solutionManagerService = null)
 {
     this.m_appletManager   = appletManager;
     this.m_solutionManager = solutionManagerService;
 }
示例#6
0
        /// <summary>
        /// Get the routes for the Angular Application
        /// </summary>
        public Stream GetRoutes()
        {
            // Ensure response makes sense
            RestOperationContext.Current.OutgoingResponse.ContentType = "text/javascript";
            IAppletManagerService appletService = ApplicationContext.Current.GetService <IAppletManagerService>();

            appletService.Changed += (o, e) => this.m_routes = null;

            if (this.m_routes == null)
            {
                // Calculate routes
                using (MemoryStream ms = new MemoryStream())
                {
                    using (StreamWriter sw = new StreamWriter(ms))
                    {
                        IEnumerable <AppletAsset> viewStates = appletService.Applets.ViewStateAssets.Select(o => new { Asset = o, Html = (o.Content ?? appletService.Applets.Resolver?.Invoke(o)) as AppletAssetHtml }).GroupBy(o => o.Html.ViewState.Name).Select(g => g.OrderByDescending(o => o.Html.ViewState.Priority).First().Asset);

                        sw.WriteLine("// Generated Routes ");
                        sw.WriteLine("// Loaded Applets");
                        foreach (var apl in appletService.Applets)
                        {
                            sw.WriteLine("// \t {0}", apl.Info.Id);
                            foreach (var ast in apl.Assets)
                            {
                                var cont = ast.Content ?? appletService.Applets.Resolver?.Invoke(ast);
                                if (cont is AppletAssetHtml html && html.ViewState != null)
                                {
                                    sw.WriteLine("// \t\t {0}", html.ViewState?.Name);
                                }
                            }
                        }
                        sw.WriteLine("// Include States: ");
                        foreach (var vs in viewStates)
                        {
                            sw.WriteLine("// \t{0}", vs.Name);
                        }

                        sw.WriteLine("SanteDB = SanteDB || {}");
                        sw.WriteLine("SanteDB.UserInterface = SanteDB.UserInterface || {}");
                        sw.WriteLine("SanteDB.UserInterface.states = [");

                        // Collect routes
                        foreach (var itm in viewStates)
                        {
                            var htmlContent = (itm.Content ?? appletService.Applets.Resolver?.Invoke(itm)) as AppletAssetHtml;
                            var viewState   = htmlContent.ViewState;
                            sw.WriteLine($"{{ name: '{viewState.Name}', url: '{viewState.Route}', abstract: {viewState.IsAbstract.ToString().ToLower()}");
                            var displayName = htmlContent.GetTitle(AuthenticationContext.Current.Principal.GetClaimValue(SanteDBClaimTypes.Language) ?? CultureInfo.CurrentUICulture.TwoLetterISOLanguageName);
                            if (!String.IsNullOrEmpty(displayName))
                            {
                                sw.Write($", displayName: '{displayName }'");
                            }
                            if (itm.Policies.Count > 0)
                            {
                                sw.Write($", demand: [{String.Join(",", itm.Policies.Select(o => $"'{o}'"))}] ");
                            }
                            if (viewState.View.Count > 0)
                            {
                                sw.Write(", views: {");
                                foreach (var view in viewState.View)
                                {
                                    sw.Write($"'{view.Name}' : {{ controller: '{view.Controller}', templateUrl: '{view.Route ?? itm.ToString() }'");
                                    var dynScripts = appletService.Applets.GetLazyScripts(itm);
                                    if (dynScripts.Any())
                                    {
                                        sw.Write($", lazy: [ {String.Join(",", dynScripts.Select(o => $"'{appletService.Applets.ResolveAsset(o.Reference, relativeAsset: itm)}'"))}  ]");
                                    }
                                    sw.WriteLine(" }, ");
                                }
                                sw.WriteLine("}");
                            }
                            sw.WriteLine("} ,");
                        }
                        sw.Write("];");
                    }
                    this.m_routes = ms.ToArray();
                }
            }
            return(new MemoryStream(this.m_routes));
        }