Ejemplo n.º 1
0
        public void Map()
        {
            var sut   = new CSVMapper();
            var lines = new List <string> {
                "a,12,06", "bc,06,01"
            };
            var columnConfigs = new List <ColumnLayout>
            {
                new ColumnLayout {
                    FieldName = "name", ColumnPosition = 0, FieldLength = 1
                },
                new ColumnLayout {
                    FieldName = "age", ColumnPosition = 1, FieldLength = 2
                },
                new ColumnLayout {
                    FieldName = "grade", ColumnPosition = 3, FieldLength = 2
                },
            };

            var config = new Configuration {
                ColumnLayouts = columnConfigs, Delimiter = ','
            };

            DataTable actualTable = sut.Map(lines, config);

            Assert.Equal(2, actualTable.Rows.Count);
            Assert.Equal("a", actualTable.Rows[0]["name"]);
            Assert.Equal("12", actualTable.Rows[0]["age"]);
            Assert.Equal("06", actualTable.Rows[0]["grade"]);
            Assert.Equal("bc", actualTable.Rows[1]["name"]);
            Assert.Equal("06", actualTable.Rows[1]["age"]);
            Assert.Equal("01", actualTable.Rows[1]["grade"]);
        }
Ejemplo n.º 2
0
        public void Map()
        {
            var table  = new DataTable();
            var config = new Configuration();

            DataColumn[] cols =
            {
                new DataColumn("name",  typeof(string)),
                new DataColumn("day",   typeof(string)),
                new DataColumn("month", typeof(string)),
            };
            table.Columns.AddRange(cols);
            object[] rows =
            {
                new object[] { "tra\"n,g ", "29", "09" },
                new object[] { "phuong",    "10", "10" },
            };
            foreach (object[] row in rows)
            {
                table.Rows.Add(row);
            }
            var sut = new CSVMapper();

            List <string> lines = sut.Map(table, config);

            Assert.Equal("\"tra\"\"n,g\",29,09", lines[0]);
            Assert.Equal("phuong,10,10", lines[1]);
        }
Ejemplo n.º 3
0
        public static void upload(string filepath)
        {
            var data = Helpers.LoadCSV(filepath);

            // Map columns
            var mapper = new CSVMapper {
                DataTable = data
            };

            if (mapper.map("name", new[] { "NAME", "ID", "DISPLAYNAME", "SKILL" }) == -1)
            {
                throw new ArgumentException("Name column not found", "name");
            }
            mapper.map("workgroups", new[] { "WORKGROUP", "WORKGROUPS", "GROUP", "GROUPS" });
            mapper.map("users", new[] { "USER", "USERS", "AGENT", "AGENTS" });

            var configurations = new SkillConfigurationList(ConfigurationManager.GetInstance(Application.ICSession));

            foreach (DataRow row in data.Rows)
            {
                SkillConfiguration skill = null;
                var name = row.Field <string>(mapper["name"]);

                if (string.IsNullOrWhiteSpace(name))
                {
                    continue;
                }
                if (!SkillConfigurations.Any(item => item.ConfigurationId.DisplayName == name))
                {
                    skill = configurations.CreateObject();
                    skill.SetConfigurationId(name);
                    skill.SetDisplayName(name);
                }
                else
                {
                    skill = SkillConfigurations.First(item => item.ConfigurationId.DisplayName == name);
                    skill.PrepareForEdit();
                }
                if (mapper["workgroups"] > -1)
                {
                    skill.WorkgroupAssignments.Value.Clear();
                    Helpers.ParseManySkillSettings(row.Field <string>(mapper["workgroups"])).ForEach(x => skill.WorkgroupAssignments.Value.Add(x));
                }
                if (mapper["users"] > -1)
                {
                    skill.UserAssignments.Value.Clear();
                    Helpers.ParseManySkillSettings(row.Field <string>(mapper["users"])).ForEach(x => skill.UserAssignments.Value.Add(x));
                }
                skill.Commit();
            }
            _SkillConfigurations = null; // So the list is fetched again
        }
Ejemplo n.º 4
0
        public void エクスポートできる()
        {
            var users  = getUsers();
            var actual = new CSVMapper <User>().ConvertToCsv(users);

            var expected = "Name,Sex,Age,Weight,Birthday,LastAccessDate,Dummy" + Environment.NewLine +
                           "mikami,Man,30,70.5,1970/05/27 0:00:00,," + Environment.NewLine +
                           "\"ta\"\"na" + "\n" +
                           "ka\",Woman,60,100,1970/12/31 0:00:00,2019/11/11 0:00:00," + Environment.NewLine;


            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 5
0
        public static void upload(string filepath)
        {
            var data = Helpers.LoadCSV(filepath);

            // Map columns
            var mapper = new CSVMapper { DataTable = data };

            if (mapper.map("name", new[] { "NAME", "ID", "DISPLAYNAME", "SKILL" }) == -1) throw new ArgumentException("Name column not found", "name");
            mapper.map("workgroups", new[] { "WORKGROUP", "WORKGROUPS", "GROUP", "GROUPS" });
            mapper.map("users", new[] { "USER", "USERS", "AGENT", "AGENTS" });

            var configurations = new SkillConfigurationList(ConfigurationManager.GetInstance(Application.ICSession));

            foreach (DataRow row in data.Rows)
            {
                SkillConfiguration skill = null;
                var                name  = row.Field<string>(mapper["name"]);

                if (string.IsNullOrWhiteSpace(name)) continue;
                if (! SkillConfigurations.Any(item => item.ConfigurationId.DisplayName == name))
                {
                    skill = configurations.CreateObject();
                    skill.SetConfigurationId(name);
                    skill.SetDisplayName(name);
                }
                else
                {
                    skill = SkillConfigurations.First(item => item.ConfigurationId.DisplayName == name);
                    skill.PrepareForEdit();
                }
                if (mapper["workgroups"] > -1)
                {
                    skill.WorkgroupAssignments.Value.Clear();
                    Helpers.ParseManySkillSettings(row.Field<string>(mapper["workgroups"])).ForEach(x => skill.WorkgroupAssignments.Value.Add(x));
                }
                if (mapper["users"] > -1)
                {
                    skill.UserAssignments.Value.Clear();
                    Helpers.ParseManySkillSettings(row.Field<string>(mapper["users"])).ForEach(x => skill.UserAssignments.Value.Add(x));
                }
                skill.Commit();
            }
            _SkillConfigurations = null; // So the list is fetched again
        }
Ejemplo n.º 6
0
        public void インポートできる()
        {
            var actual = new CSVMapper <User>().Read($@"{_directory}\User.csv");

            check(getUsers(), actual);
        }