public virtual async Task SaveDataApp(string entLookup, string host, Application app)
        {
            if (app.ID.IsEmpty())
            {
                app.ID = randomizeGuid();
            }

            var appToSave = State.Applications.FirstOrDefault(a => a.ID == app.ID);

            if (appToSave != null)
            {
                State.Applications.Remove(appToSave);
            }

            State.Applications.Add(app);

            var newDafApp = new DAFApplication()
            {
                ApplicationID = app.ID.ToString(),
                ID            = Guid.NewGuid(),
                Lookup        = null,
                Priority      = 500,
                Details       = new DAFViewApplicationDetails()
                {
                    NPMPackage     = "@lowcodeunit/lcu-charts-demo",
                    BaseHref       = "/charts/",
                    PackageVersion = null
                }
            };

            await SetActiveApp(entLookup, app);

            await SaveDAFApp(entLookup, newDafApp);

            State.AddingApp = false;
        }
예제 #2
0
        protected virtual MetadataModel loadDafConfig(DAFApplication dafApp, out DataDAFAppTypes?dafAppType)
        {
            if (dafApp.Details.Metadata.ContainsKey("APIRoot"))
            {
                dafAppType = DataDAFAppTypes.API;

                return(new Dictionary <string, JToken>()
                {
                    { "APIRoot", dafApp.Details.Metadata["APIRoot"] },
                    { "InboundPath", dafApp.Details.Metadata["InboundPath"] },
                    { "Lookup", dafApp.Details.Metadata.ContainsKey("Lookup") ? dafApp.Details.Metadata["Lookup"].ToString().Trim() : "" },
                    { "Methods", dafApp.Details.Metadata["Methods"] },
                    { "Security", dafApp.Details.Metadata["Security"] }
                }.JSONConvert <MetadataModel>());
            }
            else if (dafApp.Details.Metadata.ContainsKey("Redirect"))
            {
                dafAppType = DataDAFAppTypes.Redirect;

                return(new Dictionary <string, JToken>()
                {
                    { "Redirect", dafApp.Details.Metadata["Redirect"] }
                }.JSONConvert <MetadataModel>());
            }
            else if (dafApp.Details.Metadata.ContainsKey("BaseHref"))
            {
                var view = dafApp.Details.JSONConvert <DAFLCUApplicationDetails>();

                var package = new Dictionary <string, JToken>()
                {
                    { "BaseHref", view.BaseHref },
                    { "Package", view.Package.JSONConvert <JToken>() },
                    { "PackageType", view.PackageType.ToString() },
                    { "RegScripts", view.RegScripts },
                    { "StateConfig", view.StateConfig?.JSONConvert <JToken>() }
                };

                if (dafApp.Details.Metadata["BaseHref"].ToString().StartsWith("/_lcu/"))
                {
                    dafAppType = DataDAFAppTypes.LCU;

                    package.Add("Lookup", view.Lookup);
                }
                else
                {
                    dafAppType = DataDAFAppTypes.View;
                }

                return(package.JSONConvert <MetadataModel>());
            }
            else if (dafApp.Details.Metadata.ContainsKey("DAFApplicationID"))
            {
                dafAppType = DataDAFAppTypes.DAFAppPointer;

                return(new Dictionary <string, JToken>()
                {
                    { "DAFApplicationID", dafApp.Details.Metadata["DAFApplicationID"] },
                    { "DAFApplicationRoot", dafApp.Details.Metadata["DAFApplicationRoot"] }
                }.JSONConvert <MetadataModel>());
            }
            else
            {
                dafAppType = null;

                return(null);
            }
        }
        public virtual async Task SaveDAFApp(ApplicationDeveloperClient appDev, ApplicationManagerClient appMgr, string entLookup,
                                             DAFApplication dafApp)
        {
            if (State.ActiveApp != null)
            {
                if (State.AppType != DAFAppTypes.API)
                {
                    if (dafApp.Details.Metadata.ContainsKey("APIRoot"))
                    {
                        dafApp.Details.Metadata.Remove("APIRoot");
                    }

                    if (dafApp.Details.Metadata.ContainsKey("InboundPath"))
                    {
                        dafApp.Details.Metadata.Remove("InboundPath");
                    }

                    if (dafApp.Details.Metadata.ContainsKey("Methods"))
                    {
                        dafApp.Details.Metadata.Remove("Methods");
                    }

                    if (dafApp.Details.Metadata.ContainsKey("Security"))
                    {
                        dafApp.Details.Metadata.Remove("Security");
                    }
                }

                if (State.AppType != DAFAppTypes.Redirect)
                {
                    if (dafApp.Details.Metadata.ContainsKey("Redirect"))
                    {
                        dafApp.Details.Metadata.Remove("Redirect");
                    }
                }

                if (State.AppType != DAFAppTypes.View)
                {
                    if (dafApp.Details.Metadata.ContainsKey("BaseHref"))
                    {
                        dafApp.Details.Metadata.Remove("BaseHref");
                    }

                    if (dafApp.Details.Metadata.ContainsKey("NPMPackage"))
                    {
                        dafApp.Details.Metadata.Remove("NPMPackage");
                    }

                    if (dafApp.Details.Metadata.ContainsKey("PackageVersion"))
                    {
                        dafApp.Details.Metadata.Remove("PackageVersion");
                    }
                }

                if (State.AppType != DAFAppTypes.DAFApp)
                {
                    if (dafApp.Details.Metadata.ContainsKey("DAFApplicationID"))
                    {
                        dafApp.Details.Metadata.Remove("DAFApplicationID");
                    }

                    if (dafApp.Details.Metadata.ContainsKey("DAFApplicationRoot"))
                    {
                        dafApp.Details.Metadata.Remove("DAFApplicationRoot");
                    }
                }

                var dafAppResp = await appDev.SaveDAFApps(new[] { dafApp }.ToList(), State.ActiveApp.ID, entLookup);

                State.ActiveDAFApp = dafAppResp.Model?.FirstOrDefault();
            }

            await SetActiveApp(appMgr, entLookup, State.ActiveApp);
        }
        public virtual async Task SaveDAFApp(string entLookup, DAFApplication dafApp)
        {
            if (State.ActiveApp != null)
            {
                if (State.AppType != DAFAppTypes.API)
                {
                    if (dafApp.Details.Metadata.ContainsKey("APIRoot"))
                    {
                        dafApp.Details.Metadata.Remove("APIRoot");
                    }

                    if (dafApp.Details.Metadata.ContainsKey("InboundPath"))
                    {
                        dafApp.Details.Metadata.Remove("InboundPath");
                    }

                    if (dafApp.Details.Metadata.ContainsKey("Methods"))
                    {
                        dafApp.Details.Metadata.Remove("Methods");
                    }

                    if (dafApp.Details.Metadata.ContainsKey("Security"))
                    {
                        dafApp.Details.Metadata.Remove("Security");
                    }
                }

                if (State.AppType != DAFAppTypes.Redirect)
                {
                    if (dafApp.Details.Metadata.ContainsKey("Redirect"))
                    {
                        dafApp.Details.Metadata.Remove("Redirect");
                    }
                }

                if (State.AppType != DAFAppTypes.View)
                {
                    if (dafApp.Details.Metadata.ContainsKey("BaseHref"))
                    {
                        dafApp.Details.Metadata.Remove("BaseHref");
                    }

                    if (dafApp.Details.Metadata.ContainsKey("NPMPackage"))
                    {
                        dafApp.Details.Metadata.Remove("NPMPackage");
                    }

                    if (dafApp.Details.Metadata.ContainsKey("PackageVersion"))
                    {
                        dafApp.Details.Metadata.Remove("PackageVersion");
                    }
                }

                if (dafApp.Details.Metadata.ContainsKey("PackageVersion") && dafApp.Details.Metadata["PackageVersion"].ToString() == "latest")
                {
                    dafApp.Details.Metadata["PackageVersion"] = State.VersionLookups[dafApp.Details.Metadata["NPMPackage"].ToString()].ElementAt(1);
                }

                if (dafApp.ApplicationID.IsNullOrEmpty())
                {
                    dafApp.ApplicationID = randomizeGuid().ToString();
                }

                var dafAppToSave = State.DAFApps.FirstOrDefault(da => da.ApplicationID == dafApp.ApplicationID);

                if (dafAppToSave != null)
                {
                    State.DAFApps.Remove(dafAppToSave);
                }

                State.DAFApps.Add(dafApp);

                State.ActiveDAFApp = dafApp;
            }

            await SetActiveApp(entLookup, State.ActiveApp);
        }