public object SerializeAndDeserialize <T>(T data)
        {
            var csv = CsvSerializer.SerializeToString(data);

            csv.Print();

            var dto = CsvSerializer.DeserializeFromString <T>(csv);

            AssertEqual(dto, data);

            using (var reader = new StringReader(csv))
            {
                dto = CsvSerializer.DeserializeFromReader <T>(reader);
                AssertEqual(dto, data);
            }

            using (var ms = new MemoryStream(csv.ToUtf8Bytes()))
            {
                dto = CsvSerializer.DeserializeFromStream <T>(ms);
                AssertEqual(dto, data);
            }

            using (var ms = new MemoryStream(csv.ToUtf8Bytes()))
            {
                dto = (T)CsvSerializer.DeserializeFromStream(typeof(T), ms);
                AssertEqual(dto, data);
            }

            return(dto);
        }
Exemplo n.º 2
0
        public PortDescriptionService()
        {
            var fileReader = new StreamReader(PortDescriptionFilePath);
            var internalPortDescriptions = CsvSerializer.DeserializeFromReader <List <InternalPortDescription> >(fileReader);

            foreach (var internalPortDescription in internalPortDescriptions)
            {
                var port        = internalPortDescription.Port;
                var description = internalPortDescription.Description;

                if (port.Contains("-"))
                {
                    var ports     = port.Split('-');
                    var startPort = Convert.ToUInt16(ports[0]);
                    var endPort   = Convert.ToUInt16(ports[1]);

                    for (var portNumber = startPort; portNumber < endPort; portNumber++)
                    {
                        var portDescription = new PortDescription(portNumber, description);
                        this.AddPortDescription(portDescription);
                    }
                }
                else
                {
                    var portDescription = new PortDescription(Convert.ToUInt16(port), description);
                    this.AddPortDescription(portDescription);
                }
            }
        }
        public override List <Person> Reader()
        {
            StreamReader reader = new StreamReader(ConnectionString);

            var result = CsvSerializer.DeserializeFromReader <List <Person> >(reader);

            reader.Close();
            reader.Dispose();
            return(result);
        }
Exemplo n.º 4
0
        static void InsertCSV_in_Itop()
        {
            TextReader         reader          = File.OpenText(_objectDataPath);
            List <ContactType> ListContactType = CsvSerializer.DeserializeFromReader <List <ContactType> >(reader);

            foreach (ContactType s in ListContactType)
            {
                // ContactType _ContactType = new ContactType();
                Response QueryResult = new Response();
                s.Create(s.name, out QueryResult);
                Console.WriteLine("{0} - add : {1}", className, s.name);
            }
        }
Exemplo n.º 5
0
        public override List <RequestLogEntry> GetLatestLogs(int?take)
        {
            var logFile = files.GetFile(GetLogFilePath(this.requestLogsPattern, DateTime.UtcNow));

            if (logFile.Exists())
            {
                using (var reader = logFile.OpenText())
                {
                    var results = CsvSerializer.DeserializeFromReader <List <RequestLogEntry> >(reader);
                    return(take.HasValue
                        ? results.Take(take.Value).ToList()
                        : results);
                }
            }

            return(base.GetLatestLogs(take));
        }
Exemplo n.º 6
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Initializing Importer");


            TextReader readFile   = new StreamReader("planetInfo.csv");
            var        planetInfo = CsvSerializer.DeserializeFromReader <List <PlanetInfoCsv> >(readFile);

            await UpdateOrCreatePlanetResources(planetInfo);

            //Console.WriteLine("Importing Regions");
            //await CreateOrUpdateRegions(planetInfo);
            //Console.WriteLine("Importing Constellations");
            //await CreateOrUpdateConstellations(planetInfo);
            //Console.WriteLine("Importing Solar systems");
            //await CreateOrUpdateSystems(planetInfo);

            //await CreateOrUpdatePlanets(planetInfo);

            Console.WriteLine("Import Complete");
        }