Exemplo n.º 1
0
        public static ServerScriptModelRow Execute(
            Context context,
            SiteSettings ss,
            BaseItemModel itemModel,
            View view,
            ServerScript[] scripts)
        {
            if (!(Parameters.Script.ServerScript != false &&
                  context.ContractSettings.Script != false))
            {
                return(null);
            }
            itemModel = itemModel ?? new BaseItemModel();
            ServerScriptModelRow scriptValues = null;

            using (var model = new ServerScriptModel(
                       context: context,
                       ss: ss,
                       data: Values(
                           ss: ss,
                           model: itemModel),
                       columns: Columns(ss),
                       columnFilterHach: view?.ColumnFilterHash,
                       columnSorterHach: view?.ColumnSorterHash))
            {
                using (var engine = context.CreateScriptEngin())
                {
                    engine.AddHostObject("context", model.Context);
                    engine.AddHostObject("model", model.Data);
                    engine.AddHostObject("columns", model.Columns);
                    engine.AddHostObject("siteSettings", model.SiteSettings);
                    engine.AddHostObject("view", model.View);
                    foreach (var script in scripts)
                    {
                        engine.Execute(script.Body);
                    }
                }
                scriptValues = SetValues(
                    context: context,
                    ss: ss,
                    model: itemModel,
                    view: view,
                    data: model);
            }
            return(scriptValues);
        }
Exemplo n.º 2
0
        public static ServerScriptModelRow SetValues(
            Context context,
            SiteSettings ss,
            BaseItemModel model,
            View view,
            ServerScriptModel data)
        {
            var valueColumns = FilterCanUpdateColumns(
                ss: ss,
                columnNames: data.GetChangeItemNames());
            var valueColumnDictionary = valueColumns
                                        .ToDictionary(
                column => column.ColumnName,
                column => column);
            var scriptValues = SetRow(
                ss: ss,
                model: data.Data,
                columns: data.Columns);

            SetExtendedColumnValues(
                context: context,
                model: model,
                data: data.Data,
                columns: valueColumns);
            SetColumnFilterHachValues(
                context: context,
                view: view,
                columnFilterHach: data.View.Filters);
            SetColumnSorterHachValues(
                context: context,
                view: view,
                columnSorterHach: data.View.Sorters);
            switch (ss?.ReferenceType)
            {
            case "Issues":
                if (model is IssueModel issueModel)
                {
                    SetIssueModelValues(
                        context: context,
                        issueModel: issueModel,
                        data: data.Data,
                        columns: valueColumnDictionary);
                }
                break;

            case "Results":
                if (model is ResultModel resultModel)
                {
                    SetResultModelValues(
                        context: context,
                        resultModel: resultModel,
                        data: data.Data,
                        columns: valueColumnDictionary);
                }
                break;
            }
            SetViewValues(
                ss: ss,
                data: data.SiteSettings);
            return(scriptValues);
        }
        public static ServerScriptModelRow SetValues(
            Context context,
            SiteSettings ss,
            BaseItemModel model,
            View view,
            ServerScriptModel data)
        {
            var valueColumns = FilterCanUpdateColumns(
                context: context,
                ss: ss,
                model: model,
                columnNames: data.GetChangeItemNames());
            var valueColumnDictionary = valueColumns
                                        .ToDictionary(
                column => column.ColumnName,
                column => column);
            var scriptValues = SetRow(
                context: context,
                ss: ss,
                model: data.Model,
                columns: data.Columns,
                hidden: data.Hidden,
                elements: data.Elements,
                itemModel: model);

            SetExtendedColumnValues(
                context: context,
                model: model,
                data: data.Model,
                columns: valueColumns);
            if (view != null)
            {
                view.AlwaysGetColumns   = data.View.AlwaysGetColumns;
                view.OnSelectingWhere   = data.View.OnSelectingWhere;
                view.OnSelectingOrderBy = data.View.OnSelectingOrderBy;
                view.ColumnPlaceholders = data.View.ColumnPlaceholders;
            }
            SetColumnFilterHashValues(
                context: context,
                view: view,
                columnFilterHash: data.View.Filters);
            SetColumnSorterHashValues(
                context: context,
                view: view,
                columnSorterHash: data.View.Sorters);
            model.ReadOnly = Bool(
                data: data.Model,
                name: "ReadOnly");
            switch (ss?.ReferenceType)
            {
            case "Issues":
                if (model is IssueModel issueModel)
                {
                    SetIssueModelValues(
                        context: context,
                        ss: ss,
                        issueModel: issueModel,
                        data: data.Model,
                        columns: valueColumnDictionary);
                }
                break;

            case "Results":
                if (model is ResultModel resultModel)
                {
                    SetResultModelValues(
                        context: context,
                        ss: ss,
                        resultModel: resultModel,
                        data: data.Model,
                        columns: valueColumnDictionary);
                }
                break;
            }
            SetViewValues(
                ss: ss,
                data: data.SiteSettings);
            return(scriptValues);
        }
        public static ServerScriptModelRow Execute(
            Context context,
            SiteSettings ss,
            BaseItemModel itemModel,
            View view,
            ServerScript[] scripts,
            string condition,
            bool debug,
            bool onTesting = false)
        {
            if (!(Parameters.Script.ServerScript != false &&
                  context.ContractSettings.ServerScript != false &&
                  context.ServerScriptDisabled == false))
            {
                return(null);
            }
            if (!(context?.ServerScriptDepth < 10))
            {
                return(null);
            }
            itemModel = itemModel ?? new BaseItemModel();
            ServerScriptModelRow scriptValues = null;

            using (var model = new ServerScriptModel(
                       context: context,
                       ss: ss,
                       data: Values(
                           context: context,
                           ss: ss,
                           model: itemModel),
                       columns: Columns(
                           context: context,
                           ss: ss,
                           model: itemModel),
                       view: view,
                       condition: condition,
                       debug: debug,
                       onTesting: onTesting))
            {
                using (var engine = new ScriptEngine(debug: debug))
                {
                    try
                    {
                        engine.ContinuationCallback = model.ContinuationCallback;
                        engine.AddHostObject("context", model.Context);
                        engine.AddHostObject("model", model.Model);
                        engine.AddHostObject("depts", model.Depts);
                        engine.AddHostObject("groups", model.Groups);
                        engine.AddHostObject("users", model.Users);
                        engine.AddHostObject("columns", model.Columns);
                        engine.AddHostObject("siteSettings", model.SiteSettings);
                        engine.AddHostObject("view", model.View);
                        engine.AddHostObject("items", model.Items);
                        engine.AddHostObject("hidden", model.Hidden);
                        engine.AddHostObject("elements", model.Elements);
                        engine.AddHostObject("extendedSql", model.ExtendedSql);
                        engine.AddHostObject("notifications", model.Notification);
                        if (!Parameters.Script.DisableServerScriptHttpClient)
                        {
                            engine.AddHostObject("httpClient", model.HttpClient);
                        }
                        engine.AddHostObject("utilities", model.Utilities);
                        engine.Execute(scripts.Select(o => o.Body).Join("\n"));
                    }
                    finally
                    {
                        engine.ContinuationCallback = null;
                    }
                }
                scriptValues = SetValues(
                    context: context,
                    ss: ss,
                    model: itemModel,
                    view: view,
                    data: model);
            }
            return(scriptValues);
        }
        public static ServerScriptModelRow Execute(
            Context context,
            SiteSettings ss,
            BaseItemModel itemModel,
            View view,
            ServerScript[] scripts,
            bool onTesting = false)
        {
            if (!(Parameters.Script.ServerScript != false &&
                  context.ContractSettings.NewFeatures() &&
                  context.ContractSettings.Script != false))
            {
                return(null);
            }
            if (!(context?.ServerScriptDepth < 10))
            {
                return(null);
            }
            itemModel = itemModel ?? new BaseItemModel();
            ServerScriptModelRow scriptValues = null;

            using (var model = new ServerScriptModel(
                       context: context,
                       ss: ss,
                       data: Values(
                           context: context,
                           ss: ss,
                           model: itemModel),
                       columns: Columns(
                           context: context,
                           ss: ss),
                       columnFilterHash: view?.ColumnFilterHash,
                       columnSorterHash: view?.ColumnSorterHash,
                       onTesting: onTesting))
            {
                using (var engine = new Microsoft.ClearScript.V8.V8ScriptEngine(
                           Microsoft.ClearScript.V8.V8ScriptEngineFlags.EnableDateTimeConversion))
                {
                    try
                    {
                        engine.ContinuationCallback = model.ContinuationCallback;
                        engine.AddHostObject("context", model.Context);
                        engine.AddHostObject("model", model.Model);
                        engine.AddHostObject("depts", model.Depts);
                        engine.AddHostObject("groups", model.Groups);
                        engine.AddHostObject("users", model.Users);
                        engine.AddHostObject("columns", model.Columns);
                        engine.AddHostObject("siteSettings", model.SiteSettings);
                        engine.AddHostObject("view", model.View);
                        engine.AddHostObject("items", model.Items);
                        engine.AddHostObject("hidden", model.Hidden);
                        engine.AddHostObject("extendedSql", model.ExtendedSql);
                        engine.AddHostObject("notifications", model.Notification);
                        foreach (var script in scripts)
                        {
                            engine.Execute(script.Body);
                        }
                    }
                    finally
                    {
                        engine.ContinuationCallback = null;
                    }
                }
                scriptValues = SetValues(
                    context: context,
                    ss: ss,
                    model: itemModel,
                    view: view,
                    data: model);
            }
            return(scriptValues);
        }