示例#1
0
        public DataFeedResult GetDataFeedResult(string alias, string key, IDictionary <object, object> parameters = null)
        {
            var feed = Session.Query <DataFeed>().FirstOrDefault(x => x.FeedAlias == alias);

            DataFeedResult result = null;

            if (feed != null)
            {
                result = new DataFeedResult
                {
                    ID          = feed.FeedID,
                    GUID        = feed.FeedGUID,
                    Alias       = feed.FeedAlias,
                    Name        = feed.FeedName,
                    Description = feed.FeedDescription,
                    Private     = feed.Private,
                    Active      = feed.Active,
                    Deleted     = feed.Deleted,
                    Data        = null
                };

                if (result.Deleted)
                {
                    return(result);
                }

                if (parameters == null)
                {
                    parameters = new Dictionary <object, object>();
                }

                feed.ApplyDefaultParameters(parameters);

                DataSet ds = ExecuteQuery(feed, ScriptParameters.Create(parameters));
                result.Name = ds.DataSetName;
                result.Data = new DataFeedResultSet();

                IList <DataTable> tables = GetTables(ds, key);

                foreach (DataTable dt in tables)
                {
                    var items = new DataFeedResultItemCollection();
                    foreach (DataRow dr in dt.Rows)
                    {
                        var item = new DataFeedResultItem();
                        foreach (DataColumn dc in dt.Columns)
                        {
                            item[dc.ColumnName] = dr[dc.ColumnName].ToString();
                        }
                        items.Add(item);
                    }

                    result.Data[dt.TableName] = items;
                }
            }

            return(result);
        }
示例#2
0
        private ScriptParameters GetParameters(DataFeed feed)
        {
            var dict = new Dictionary <object, object>();

            Merge(dict, Request.QueryString);
            Merge(dict, Request.Form);
            feed.ApplyDefaultParameters(dict);

            var result = ScriptParameters.Create(dict);

            return(result);
        }
示例#3
0
        public DataSet ExecuteQuery(DataFeed feed, HttpRequestBase request)
        {
            var parameters = new Dictionary <object, object>();

            foreach (var key in request.QueryString.AllKeys)
            {
                parameters.Add(key, request.QueryString[key]);
            }

            var util = new DataFeedUtility(Provider);

            feed.ApplyDefaultParameters(parameters);
            return(util.ExecuteQuery(feed, ScriptParameters.Create(parameters)));
        }
示例#4
0
        public ActionResult Ajax(FeedModel model)
        {
            model.Provider = Provider;

            if (model.Command == "run-script")
            {
                string    query  = string.Empty;
                string    error  = string.Empty;
                string    buffer = string.Empty;
                string    html   = string.Empty;
                Hashtable data   = new Hashtable();

                if (model.FeedType == DataFeedType.Python)
                {
                    query = model.Query;
                }
                else
                {
                    query = string.Format("data(sqlquery(\"{0}\"))", model.Query.Replace("\n", " ").Replace("\"", @"\""").Trim());
                }

                var dict = new Dictionary <object, object>();
                DataFeedItem.ApplyDefaultParameters(model.DefaultParameters, dict);

                var parameters = ScriptParameters.Create(dict);

                var result = _engine.Run(query, parameters);

                if (result.Exception != null)
                {
                    error = result.Exception.Message;
                }

                buffer = result.Buffer.ToString();
                html   = result.Html.ToString();
                if (result.DataSet.Count > 0)
                {
                    foreach (KeyValuePair <string, ScriptData> kvp in result.DataSet)
                    {
                        data.Add(kvp.Key, new { Headers = kvp.Value.GetHeaders().Select(x => x.DisplayText).ToArray(), Items = kvp.Value.GetItems() });
                    }
                }

                return(Json(new { Success = true, Message = "", Error = error, Buffer = buffer, Html = html, Data = data, Parameters = parameters.ToString() }));
            }
            else
            {
                return(Json(new { Success = false, Message = "Invalid command" }));
            }
        }