예제 #1
0
 async Task Render(String pathInfo, RequestUrlKind kind)
 {
     //  Ajax
     if (IsNotAjax())
     {
         return;
     }
     try
     {
         Response.ContentType = "text/html";
         ExpandoObject loadPrms = new ExpandoObject();
         loadPrms.Append(_baseController.CheckPeriod(Request.QueryString), toPascalCase: true);
         if (pathInfo.StartsWith("app/"))
         {
             SetUserTenantToParams(loadPrms);                     // without claims
             await _baseController.RenderApplicationKind(kind, pathInfo, loadPrms, Response.Output);
         }
         else
         {
             SetSqlQueryParams(loadPrms);
             await _baseController.RenderElementKind(kind, pathInfo, loadPrms, Response.Output);
         }
     }
     catch (Exception ex)
     {
         _baseController.WriteHtmlException(ex, Response.Output);
     }
 }
예제 #2
0
        public static async Task <RequestModel> CreateFromUrl(IApplicationHost host, RequestUrlKind kind, String normalizedUrl)
        {
            var    mi          = GetModelInfo(kind, normalizedUrl);
            String pathForLoad = _redirect.Value.Redirect(mi.path);
            String jsonText    = await host.ApplicationReader.ReadTextFileAsync(pathForLoad, "model.json");

            if (jsonText == null)
            {
                throw new FileNotFoundException($"File not found '{pathForLoad}/model.json'");
            }

            var rm = JsonConvert.DeserializeObject <RequestModel>(jsonText);

            rm._host = host;
            rm.EndInit();
            rm._action    = mi.action;
            rm._dialog    = mi.dialog;
            rm._popup     = mi.popup;
            rm._command   = mi.command;
            rm._report    = mi.report;
            rm._file      = mi.file;
            rm._data      = mi.data;
            rm._modelPath = pathForLoad;
            rm._kind      = kind;
            rm._id        = ((mi.id == "0") || (mi.id == "new")) ? null : mi.id;
            return(rm);
        }
예제 #3
0
        async Task <ViewInfo> LoadViewKind(String pathInfo, RequestUrlKind kind)
        {
            var host = _baseController.Host;
            var rm   = await RequestModel.CreateFromUrl(host, false, kind, NormalizeUrl(pathInfo));

            var rw     = rm.GetCurrentAction();
            var pageId = $"el{Guid.NewGuid()}";
            var dmrw   = await _baseController.GetDataModelForView(rw, CreateParams());

            rw = dmrw.RequestView;
            var viewInfo = new ViewInfo()
            {
                PageId    = pageId,
                View      = host.MakeRelativePath(rw.Path, $"{rw.GetView()}.cshtml"),
                Path      = rw.Path,
                BaseUrl   = rw.ParentModel.BasePath,
                DataModel = dmrw.Model,
                Id        = rw.Id
            };

            var msi = new ModelScriptInfo()
            {
                DataModel = viewInfo.DataModel,
                RootId    = pageId,
                IsDialog  = rw.IsDialog,
                Template  = rw.template,
                Path      = rw.Path,
                BaseUrl   = rw.ParentModel.BasePath
            };

            viewInfo.Scripts = await _baseController.Scripter.GetModelScript(msi);

            return(viewInfo);
        }
예제 #4
0
        public async Task RenderElementKind(RequestUrlKind kind, String pathInfo, ExpandoObject loadPrms, TextWriter writer)
        {
            RequestModel rm = await RequestModel.CreateFromUrl(_host, Admin, kind, pathInfo);

            RequestView rw = rm.GetCurrentAction(kind);

            await Render(rw, writer, loadPrms);
        }
예제 #5
0
        static void Render(BaseController ctrl, RequestUrlKind kind, String path, String search, TextWriter writer)
        {
            ExpandoObject loadPrms = new ExpandoObject();

            loadPrms.Append(HttpUtility.ParseQueryString(search), toPascalCase: true);
            // TODO: current user ID;
            //loadPrms.Set("UserId", 100);
            ctrl.RenderElementKind(kind, path, loadPrms, writer).Wait();
        }
예제 #6
0
        public async Task RenderElementKind(RequestUrlKind kind, String pathInfo, ExpandoObject loadPrms, TextWriter writer)
        {
            RequestModel rm = await RequestModel.CreateFromUrl(_host, kind, pathInfo);

            RequestView rw = rm.GetCurrentAction(kind);

            rw.CheckPermissions(_userStateManager?.GetUserPermissions(), Host.IsDebugConfiguration);
            await Render(rw, writer, loadPrms);
        }
예제 #7
0
        void Render(RequestUrlKind kind, String path, String search, TextWriter writer)
        {
            ExpandoObject loadPrms = new ExpandoObject();

            loadPrms.Append(HttpUtility.ParseQueryString(search), toPascalCase: true);
            SetSqlParams(loadPrms);
            if (path.StartsWith("app/"))
            {
                _controller.RenderApplicationKind(kind, path, loadPrms, writer).Wait();
            }
            else
            {
                _controller.RenderElementKind(kind, path, loadPrms, writer).Wait();
            }
        }
예제 #8
0
 public RequestView GetCurrentAction(RequestUrlKind kind)
 {
     if (kind == RequestUrlKind.Page)
     {
         return(CurrentAction);
     }
     else if (kind == RequestUrlKind.Dialog)
     {
         return(CurrentDialog);
     }
     else if (kind == RequestUrlKind.Popup)
     {
         return(CurrentPopup);
     }
     throw new RequestModelException($"Invalid kind ({kind}) for GetCurrentAction");
 }
예제 #9
0
        void Render(RequestUrlKind kind, String path, TextWriter writer)
        {
            ExpandoObject loadPrms = new ExpandoObject();

            path = path.ToLowerInvariant();
            loadPrms.Append(_controller.CheckPeriod(HttpUtility.ParseQueryString(Search)), toPascalCase: true);
            SetSqlQueryParams(loadPrms);
            if (path.StartsWith("app/"))
            {
                _controller.RenderApplicationKind(kind, path, loadPrms, writer, false).Wait();
            }
            else
            {
                _controller.RenderElementKind(kind, path, loadPrms, writer).Wait();
            }
        }
예제 #10
0
        public async Task RenderApplicationKind(RequestUrlKind kind, String pathInfo, ExpandoObject loadPrms, TextWriter writer, Boolean isUserOpenId)
        {
            var segs = pathInfo.ToLowerInvariant().Split('/');

            if (segs.Length < 2)
            {
                throw new RequestModelException($"Invalid application Url: {pathInfo}");
            }
            if (segs[0] != "app")
            {
                throw new RequestModelException($"Invalid application Url: {pathInfo}");
            }
            switch (segs[1])
            {
            case "about":
                if (kind != RequestUrlKind.Page)
                {
                    throw new RequestModelException($"Invalid application Url: {pathInfo}");
                }
                await RenderAbout(writer);

                break;

            case "changepassword":
                if (isUserOpenId)
                {
                    throw new RequestModelException($"Unable to change password");
                }
                if (kind != RequestUrlKind.Dialog)
                {
                    throw new RequestModelException($"Invalid application Url: {pathInfo}");
                }
                await RenderChangePassword(writer, loadPrms);

                break;

            default:
                // find page
                if (kind != RequestUrlKind.Page)
                {
                    throw new RequestModelException($"Invalid application Url: {pathInfo}");
                }
                await RenderAppPage(writer, segs[1]);

                break;
            }
        }
예제 #11
0
 async Task Render(String pathInfo, RequestUrlKind kind)
 {
     /*
      * PARAMS:
      * 1. initial = [queryString, controller]
      * 2. real = [model.json, id, initial]
      */
     //  Ajax
     if (IsNotAjax())
     {
         return;
     }
     try
     {
         Response.ContentType = "text/html";
         ExpandoObject loadPrms = new ExpandoObject();
         // query string
         loadPrms.Append(_baseController.CheckPeriod(Request.QueryString), toPascalCase: true);
         if (pathInfo.StartsWith("app/"))
         {
             // controller after query string
             SetUserTenantToParams(loadPrms);                     // without claims
             await _baseController.RenderApplicationKind(kind, pathInfo, loadPrms, Response.Output);
         }
         else
         {
             // controller after query string
             SetSqlQueryParams(loadPrms);
             await _baseController.RenderElementKind(kind, pathInfo, loadPrms, Response.Output);
         }
     }
     catch (Exception ex)
     {
         if (ex.Message.StartsWith("UI:", StringComparison.OrdinalIgnoreCase))
         {
             var error = _baseController.Localize(ex.Message.Substring(3));
             _baseController.WriteExceptionStatus(ex, Response);
         }
         else
         {
             _baseController.WriteHtmlException(ex, Response.Output);
         }
     }
 }
예제 #12
0
        public static RequestModelInfo GetModelInfo(RequestUrlKind kind, String normalizedUrl)
        {
            // {pathInfo}/action/id - ACTION
            // {pathInfo}/dialog/id - DIALOG
            // {pathInfo}/command/id - COMMAND
            // {pathInfo}/image/id - IMAGE
            // {pathInfo}/action/ - api

            var mi = new RequestModelInfo();

            String[] urlParts = normalizedUrl.Split('/');
            Int32    len      = urlParts.Length;

            if (len < 3)
            {
                // min: {path}/{act}/id
                throw new RequestModelException($"invalid url ({normalizedUrl})");
            }
            mi.id = urlParts[len - 1];
            String action = urlParts[len - 2];

            switch (kind)
            {
            case RequestUrlKind.Page:
                mi.action = action;
                break;

            case RequestUrlKind.Dialog:
                mi.dialog = action;
                break;

            case RequestUrlKind.Popup:
                mi.popup = action;
                break;

            case RequestUrlKind.Command:
                mi.command = action;
                break;

            case RequestUrlKind.Data:
                mi.data = action;
                break;

            case RequestUrlKind.Image:
                mi.action = action;
                break;

            case RequestUrlKind.Attachment:
                mi.action = action;
                break;

            case RequestUrlKind.File:
                mi.file = action;
                break;

            case RequestUrlKind.Report:
                mi.report = action;
                break;

            case RequestUrlKind.Export:
                mi.action = action;
                break;

            case RequestUrlKind.Api:
                mi.command = action;
                break;

            default:
                throw new RequestModelException($"Invalid action kind ({kind})");
            }
            var pathArr = new ArraySegment <String>(urlParts, 0, len - 2);

            mi.path = String.Join("/", pathArr);
            return(mi);
        }
예제 #13
0
        public static async Task <RequestModel> CreateFromUrl(IApplicationHost host, Boolean bAdmin, RequestUrlKind kind, String normalizedUrl)
        {
            var    mi          = GetModelInfo(kind, normalizedUrl);
            String pathForLoad = await Redirect(host, bAdmin, mi.path);

            String jsonText = await host.ReadTextFile(bAdmin, pathForLoad, "model.json");

            var rm = JsonConvert.DeserializeObject <RequestModel>(jsonText);

            rm.EndInit();
            rm._action    = mi.action;
            rm._dialog    = mi.dialog;
            rm._popup     = mi.popup;
            rm._command   = mi.command;
            rm._report    = mi.report;
            rm._upload    = mi.upload;
            rm._data      = mi.data;
            rm._modelPath = pathForLoad;
            rm._id        = ((mi.id == "0") || (mi.id == "new")) ? null : mi.id;
            return(rm);
        }