示例#1
0
        private void CreateJson(List <IDataSource> dataPool)
        {
            string destPath = @"C:\Users\fhjun\Desktop\html\data\";
            string JS_PATH  = destPath + "tree.js";

            List <ExportTree> tree = new List <ExportTree>();

            foreach (IDataSource ds in dataPool)
            {
                if (ds == null)
                {
                    continue;
                }

                ExportTree t = new ExportTree()
                {
                    text = ds.PluginInfo.Name, location = "", icon = ds.PluginInfo.Icon ?? "", tags = new string[] { "0" }
                };

                if (ds is TreeDataSource td)
                {
                    CreateJson(td.TreeNodes, destPath, t);
                }
                else if (ds is SimpleDataSource sd)
                {
                    CreateItemJson(sd.Items, destPath, t, typeof(Call));
                }
                tree.Add(t);
            }
            System.IO.File.WriteAllText(JS_PATH, $"var __data = {Serializer.JsonFastSerilize(tree)};");
        }
示例#2
0
        private void CreateItemJson(IDataItems items, string dir, ExportTree t, Type itemType = null)
        {
            if (items == null)
            {
                return;
            }
            t.location = items.Key;
            string path = $"{dir}{items.Key}.js";

            using (StreamWriter sw = new StreamWriter(path, false, Encoding.UTF8))
            {
                sw.Write("var __data = [");
                int r = 0;
                items.Filter();
                foreach (var c in items.View)
                {
                    if (r != 0)
                    {
                        sw.Write(",");
                    }
                    sw.Write(Serializer.JsonSerilize(c));
                    r++;
                }
                sw.Write("];");

                sw.Write("var __columns = ");
                List <ExportColumn> cols = new List <ExportColumn>();
                foreach (var c in DisplayAttributeHelper.FindDisplayAttributes(itemType))
                {
                    if (c.Visibility != EnumDisplayVisibility.ShowInDatabase)
                    {
                        cols.Add(new ExportColumn()
                        {
                            field = c.Key, title = c.Text
                        });
                    }
                }
                sw.Write(Serializer.JsonFastSerilize(cols));
                sw.Write(";");
            }
        }
示例#3
0
 private void CreateJson(List <TreeNode> nodes, string path, ExportTree t)
 {
     if (nodes == null)
     {
         return;
     }
     if (nodes.Count > 0 && t.nodes == null)
     {
         t.nodes = new List <ExportTree>();
     }
     foreach (TreeNode n in nodes)
     {
         ExportTree t0 = (new ExportTree()
         {
             text = n.Text, location = "", icon = t.icon, tags = new string[] { "0" }
         });
         CreateItemJson(n.Items, path, t0, (Type)n.Type);
         CreateJson(n.TreeNodes, path, t0);
         t.nodes.Add(t0);
     }
 }