Ejemplo n.º 1
0
        public static CCPDataSet Read(string importFilePath)
        {
            CCPDataSet set = new CCPDataSet();

            if (File.Exists(importFilePath))
            {
                //Read out our json into a new set for interrogation
                var entries = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(File.ReadAllText(importFilePath));

                foreach (var entry in entries)
                {
                    CCPDataRow row = new CCPDataRow();

                    foreach (var field in entry)
                    {
                        if (field.Value.ToString().StartsWith("{") && field.Value.ToString().EndsWith("}"))
                        {
                            //We're looking at a collection here
                            var nest = JsonConvert.DeserializeObject <Dictionary <string, string> >(field.Value.ToString());

                            foreach (var n in nest)
                            {
                                CCPDataItem item = new CCPDataItem();
                                item.Name  = $"{field.Key}_{n.Key}";
                                item.Value = n.Value.ToString();
                                row.Items.Add(item);
                            }
                        }
                        else
                        {
                            //Basic item, nothing fancy
                            CCPDataItem item = new CCPDataItem();
                            item.Name  = field.Key;
                            item.Value = field.Value.ToString();
                            row.Items.Add(item);
                        }
                    }

                    set.Rows.Add(row);
                }
            }

            return(set);
        }
Ejemplo n.º 2
0
        public static CCPDataSet Read(string importFilePath)
        {
            CCPDataSet set = new CCPDataSet();

            if (File.Exists(importFilePath))
            {
                //Load xml into memory
                XmlDocument doc = new XmlDocument();
                doc.Load(importFilePath);

                foreach (XmlNode n in doc.DocumentElement)
                {
                    CCPDataRow row = new CCPDataRow();
                    foreach (XmlNode r in n.ChildNodes)
                    {
                        //If we have child nodes, and those child nodes are actually xml elements, that means we want to dig deeper
                        if (r.HasChildNodes && r.ChildNodes.OfType <XmlElement>().Any())
                        {
                            foreach (XmlNode cc in r.ChildNodes)
                            {
                                CCPDataItem item = new CCPDataItem();
                                item.Name  = $"{r.Name}_{cc.Name}";
                                item.Value = cc.InnerText;
                                row.Items.Add(item);
                            }
                        }
                        else
                        {
                            //Otherwise, we're as deep as we want to be
                            CCPDataItem item = new CCPDataItem();
                            item.Name  = r.Name;
                            item.Value = r.InnerText;
                            row.Items.Add(item);
                        }
                    }

                    set.Rows.Add(row);
                }
            }

            return(set);
        }
Ejemplo n.º 3
0
        public static CCPDataSet Read(string importFilePath)
        {
            CCPDataSet set = new CCPDataSet();

            if (File.Exists(importFilePath))
            {
                using (TextFieldParser parser = new TextFieldParser(importFilePath))
                {
                    parser.SetDelimiters(new string[] { "," });

                    string[] headers = parser.ReadFields();

                    while (!parser.EndOfData)
                    {
                        var      row        = new CCPDataRow();
                        string[] properties = parser.ReadFields();
                        int      index      = 0;
                        foreach (var p in properties)
                        {
                            var headerName = headers[index];


                            var header = new CCPDataItem();
                            header.Name       = headers[index];
                            header.Value      = p;
                            header.OrderIndex = index;
                            row.Items.Add(header);
                            index++;
                        }
                        set.Rows.Add(row);
                    }
                }
            }

            return(set);
        }