コード例 #1
0
        /// <summary>
        /// Creates a new DynamicData instance
        /// where each element is named as the value of the first column of the row
        /// and the value of that element is another DynamicData instance
        /// populated with name/value pairs corresponding to the columns of the row.
        /// This is useful for summary data needed for a dashboard report.
        /// Note that the first column data should be unique to avoid overwriting previous rows.
        /// The number of rows is limited to 100 to avoid slurping into memory an entire table of People for example.
        /// </summary>
        public DynamicData SqlFirstColumnRowKey(string sql, object declarations)
        {
            var cn         = GetReadonlyConnection();
            var parameters = new DynamicParameters();

            if (declarations != null)
            {
                AddParameters(declarations, parameters);
            }
            var ret = new DynamicData();

            using (var rd = cn.ExecuteReader(sql, parameters))
            {
                var maxn = 100;
                while (rd.Read())
                {
                    var dd = new DynamicData();
                    for (var i = 0; i < rd.FieldCount; i++)
                    {
                        dd.AddValue(rd.GetName(i), rd.GetValue(i));
                    }
                    ret.AddValue(rd.GetString(0), dd);
                    maxn--;
                    if (maxn == 0)
                    {
                        break;
                    }
                }
            }
            return(ret);
        }
コード例 #2
0
        /// <summary>
        /// Creates a new DynamicData instance
        /// where each element is named as the value of the first column of the row
        /// and the value of that element is another DynamicData instance
        /// populated with name/value pairs corresponding to the columns of the row.
        /// This is useful for summary data needed for a dashboard report.
        /// Note that the first column data should be unique to avoid overwriting previous rows.
        /// The number of rows is limited to 100 to avoid slurping into memory an entire table of People for example.
        /// </summary>
        public DynamicData SqlFirstColumnRowKey(string sql, object declarations)
        {
            var cn         = GetReadonlyConnection();
            var parameters = new DynamicParameters();

            if (declarations != null)
            {
                AddParameters(declarations, parameters);
#if DEBUG
                sql = RemoveDeclarations(declarations, sql);
#endif
            }
            var ret = new DynamicData();
            using (var rd = cn.ExecuteReader(sql, parameters, commandTimeout: 600))
            {
                var maxn = 100;
                while (rd.Read())
                {
                    var dd = new DynamicData();
                    for (var i = 0; i < rd.FieldCount; i++)
                    {
                        var t = rd.GetDataTypeName(i);
                        switch (t)
                        {
                        case "datetime":
                            var dt  = rd.GetDateTime(i);
                            var fmt = dt.TimeOfDay.Equals(TimeSpan.Zero) ? "d" : "g";
                            dd.AddValue(rd.GetName(i), dt.ToString(fmt));
                            break;

                        default:
                            dd.AddValue(rd.GetName(i), rd.GetValue(i));
                            break;
                        }
                    }
                    ret.AddValue(rd.GetString(0), dd);
                    maxn--;
                    if (maxn == 0)
                    {
                        break;
                    }
                }
            }
            return(ret);
        }
コード例 #3
0
        private DynamicData ConvertDapperRow(dynamic r, DynamicData metadata)
        {
            var dd   = new DynamicData(r);
            var jkey = dd.Keys().FirstOrDefault(k => k.Contains("Json", ignoreCase: true));

            if (jkey.HasValue())
            {
                dd.AddValue(jkey, DynamicDataFromJson(dd[jkey].ToString(), metadata));
            }
            return(dd);
        }
コード例 #4
0
ファイル: PythonScriptModel.cs プロジェクト: lightyeare/bvcms
        private void UnpackZipIntoDynamicData(string key, HttpPostedFileBase file)
        {
            var dd = new DynamicData();

            pythonModel.DictionaryAdd(key, dd);
            // The name of the zip file will be the Special Content keyword filter for all the files
            dd.AddValue("keyword", Path.GetFileNameWithoutExtension(file.FileName));

            var data = new byte[4096];

            using (var zs = new ZipInputStream(file.InputStream))
            {
                ZipEntry ze;
                while ((ze = zs.GetNextEntry()) != null)
                {
                    if (!ze.IsFile)
                    {
                        continue;
                    }
                    if (ze.Name.Contains("/."))
                    {
                        continue;
                    }
                    if (ze.Name.Contains(@"\\."))
                    {
                        continue;
                    }
                    var sb   = new StringBuilder();
                    var size = zs.Read(data, 0, data.Length);
                    while (size > 0)
                    {
                        sb.Append(Encoding.ASCII.GetString(data, 0, size));
                        size = zs.Read(data, 0, data.Length);
                    }

                    var filename = Path.GetFileName(ze.Name);
                    dd.AddValue(filename, sb.ToString());
                }
            }
        }
コード例 #5
0
ファイル: DynamicData.cs プロジェクト: crownemmanuel/bvcms
        private void AddDropDownOptions(PythonModel pe)
        {
            if (pe.DataHas("DropdownOption"))
            {
                return;
            }
            if (option == null)
            {
                return;
            }
            var options = new DynamicData();

            pe.DictionaryAdd("DropdownOption", options);
            foreach (var o in option)
            {
                options.AddValue(o, true);
            }
        }
コード例 #6
0
ファイル: DynamicData.cs プロジェクト: crownemmanuel/bvcms
        private void AddCheckboxes(PythonModel pe)
        {
            if (pe.DataHas("Checkbox"))
            {
                return;
            }
            if (Checkbox == null)
            {
                return;
            }
            var checkboxes = new DynamicData();

            pe.DictionaryAdd("Checkbox", checkboxes);
            foreach (var c in Checkbox)
            {
                checkboxes.AddValue(c, true);
            }
        }
コード例 #7
0
ファイル: DynamicData.cs プロジェクト: crownemmanuel/bvcms
        private void AddYesNo(PythonModel pe)
        {
            if (pe.DataHas("YesNoQuestion"))
            {
                return;
            }
            if (YesNoQuestion == null || YesNoQuestion.Count == 0)
            {
                return;
            }
            var yesnoquestions = new DynamicData();

            pe.DictionaryAdd("YesNoQuestion", yesnoquestions);
            foreach (var dict in YesNoQuestion)
            {
                yesnoquestions.AddValue(dict.Key, dict.Value ?? false);
            }
        }
コード例 #8
0
ファイル: DynamicData.cs プロジェクト: crownemmanuel/bvcms
        private void AddQuestions(PythonModel pe)
        {
            if (pe.DataHas("ExtraQuestion"))
            {
                return;
            }
            if (ExtraQuestion == null || ExtraQuestion.Count == 0)
            {
                return;
            }
            var questions = new DynamicData();

            pe.DictionaryAdd("ExtraQuestion", questions);
            foreach (var dict in ExtraQuestion)
            {
                foreach (var q in dict)
                {
                    questions.AddValue(q.Key, q.Value);
                }
            }
        }
コード例 #9
0
ファイル: DynamicData.cs プロジェクト: crownemmanuel/bvcms
        private void AddMenuItems(PythonModel pe)
        {
            if (pe.DataHas("MenuItem"))
            {
                return;
            }
            if (MenuItem == null)
            {
                return;
            }
            var menuitems = new DynamicData();

            pe.DictionaryAdd("MenuItem", menuitems);
            foreach (var dict in MenuItem)
            {
                foreach (var q in dict)
                {
                    menuitems.AddValue(q.Key, q.Value ?? 0);
                }
            }
        }
コード例 #10
0
ファイル: DynamicData.cs プロジェクト: crownemmanuel/bvcms
        private void AddText(PythonModel pe)
        {
            if (pe.DataHas("TextQuestion"))
            {
                return;
            }
            if (Text == null || Text.Count == 0)
            {
                return;
            }
            var textquestions = new DynamicData();

            pe.DictionaryAdd("TextQuestion", textquestions);
            foreach (var dict in Text)
            {
                foreach (var q in dict)
                {
                    textquestions.AddValue(q.Key, q.Value);
                }
            }
        }