コード例 #1
0
        async Task <RequestView> LoadIndirect(RequestView rw, IDataModel innerModel, ExpandoObject loadPrms)
        {
            if (!rw.indirect)
            {
                return(rw);
            }
            if (!String.IsNullOrEmpty(rw.target))
            {
                String targetUrl = innerModel.Root.Resolve(rw.target);
                if (String.IsNullOrEmpty(rw.targetId))
                {
                    throw new RequestModelException("targetId must be specified for indirect action");
                }
                targetUrl += "/" + innerModel.Root.Resolve(rw.targetId);
                var rm = await RequestModel.CreateFromUrl(_host, Admin, rw.CurrentKind, targetUrl);

                rw = rm.GetCurrentAction();
                String loadProc = rw.LoadProcedure;
                if (loadProc != null)
                {
                    loadPrms.Set("Id", rw.Id);
                    var newModel = await _dbContext.LoadModelAsync(rw.CurrentSource, loadProc, loadPrms);

                    innerModel.Merge(newModel);
                    innerModel.System.Set("__indirectUrl__", rm.BaseUrl);
                }
            }
            else
            {
                // simple view/model redirect
                if (rw.targetModel == null)
                {
                    throw new RequestModelException("'targetModel' must be specified for indirect action without 'target' property");
                }
                rw.model      = innerModel.Root.Resolve(rw.targetModel.model);
                rw.view       = innerModel.Root.Resolve(rw.targetModel.view);
                rw.viewMobile = innerModel.Root.Resolve(rw.targetModel.viewMobile);
                rw.schema     = innerModel.Root.Resolve(rw.targetModel.schema);
                if (String.IsNullOrEmpty(rw.schema))
                {
                    rw.schema = null;
                }
                rw.template = innerModel.Root.Resolve(rw.targetModel.template);
                if (String.IsNullOrEmpty(rw.template))
                {
                    rw.template = null;
                }
                String loadProc = rw.LoadProcedure;
                if (loadProc != null)
                {
                    loadPrms.Set("Id", rw.Id);
                    var newModel = await _dbContext.LoadModelAsync(rw.CurrentSource, loadProc, loadPrms);

                    innerModel.Merge(newModel);
                }
            }
            return(rw);
        }
コード例 #2
0
ファイル: BaseController.Data.cs プロジェクト: dmitrkov/A2v10
        internal async Task ReloadData(Action <ExpandoObject> setParams, String json, TextWriter writer)
        {
            ExpandoObject dataToSave = JsonConvert.DeserializeObject <ExpandoObject>(json, new ExpandoObjectConverter());
            String        baseUrl    = dataToSave.Get <String>("baseUrl");

            ExpandoObject loadPrms = new ExpandoObject();

            if (baseUrl.Contains("?"))
            {
                var parts = baseUrl.Split('?');
                baseUrl = parts[0];
                // parts[1] contains query parameters
                var qryParams = HttpUtility.ParseQueryString(parts[1]);
                loadPrms.Append(CheckPeriod(qryParams), toPascalCase: true);
            }

            if (NormalizeBaseUrl != null)
            {
                baseUrl = NormalizeBaseUrl(baseUrl);
            }

            if (baseUrl == null)
            {
                throw new RequestModelException("There are not base url for command 'reload'");
            }

            var rm = await RequestModel.CreateFromBaseUrl(_host, Admin, baseUrl);

            RequestView rw       = rm.GetCurrentAction();
            String      loadProc = rw.LoadProcedure;

            if (loadProc == null)
            {
                throw new RequestModelException("The data model is empty");
            }
            setParams?.Invoke(loadPrms);
            loadPrms.Set("Id", rw.Id);
            loadPrms.Append(rw.parameters);
            ExpandoObject prms2 = loadPrms;

            if (rw.indirect)
            {
                // for indirect action - @UserId and @Id only
                prms2 = new ExpandoObject();
                setParams?.Invoke(prms2);
                prms2.Set("Id", rw.Id);
            }
            IDataModel model = await _dbContext.LoadModelAsync(rw.CurrentSource, loadProc, prms2);

            if (rw.HasMerge)
            {
                var mergeModel = await _dbContext.LoadModelAsync(rw.MergeSource, rw.MergeLoadProcedure, prms2);

                model.Merge(mergeModel);
            }
            rw = await LoadIndirect(rw, model, loadPrms);

            WriteDataModel(model, writer);
        }
コード例 #3
0
        internal async Task <DataModelAndView> GetDataModelForView(RequestView rw, ExpandoObject loadPrms)
        {
            var dmv = new DataModelAndView()
            {
                RequestView = rw
            };
            String     loadProc = rw.LoadProcedure;
            IDataModel model    = null;

            if (rw.parameters != null && loadPrms == null)
            {
                loadPrms = rw.parameters;
            }
            if (loadPrms != null)
            {
                loadPrms.AppendIfNotExists(rw.parameters);
                if (rw.Id != null)
                {
                    loadPrms.Set("Id", rw.Id);
                }
            }
            if (loadProc != null)
            {
                ExpandoObject prms2 = loadPrms;
                if (rw.indirect)
                {
                    // for indirect - @TenantId, @UserId and @Id only
                    prms2 = new ExpandoObject();
                    prms2.Set("Id", rw.Id);
                    if (loadPrms != null)
                    {
                        prms2.Set("UserId", loadPrms.Get <Int64>("UserId"));
                        prms2.Set("TenantId", loadPrms.Get <Int32>("TenantId"));
                    }
                }
                model = await _dbContext.LoadModelAsync(rw.CurrentSource, loadProc, prms2);

                if (rw.HasMerge)
                {
                    var mergeModel = await _dbContext.LoadModelAsync(rw.MergeSource, rw.MergeLoadProcedure, prms2);

                    model.Merge(mergeModel);
                }
                if (rw.copy)
                {
                    model.MakeCopy();
                }
                if (!String.IsNullOrEmpty(rw.Id) && !rw.copy)
                {
                    var me = model.MainElement;
                    if (me.Metadata != null)
                    {
                        var modelId = me.Id ?? String.Empty;
                        if (rw.Id != modelId.ToString())
                        {
                            throw new RequestModelException($"Element not found. Id={rw.Id}");
                        }
                    }
                }
            }
            if (rw.indirect)
            {
                rw = await LoadIndirect(rw, model, loadPrms);
            }
            if (model?.Root != null)
            {
                // side effect!
                rw.view       = model.Root.Resolve(rw.view);
                rw.viewMobile = model.Root.Resolve(rw.viewMobile);
                rw.template   = model.Root.Resolve(rw.template);
            }

            if (_userStateManager != null && model != null)
            {
                Int64 userId = loadPrms.Get <Int64>("UserId");
                if (_userStateManager.IsReadOnly(userId))
                {
                    model.SetReadOnly();
                }
            }
            dmv.Model       = model;
            dmv.RequestView = rw;
            return(dmv);
        }