コード例 #1
0
ファイル: Service.cs プロジェクト: StevePro7/3DcityLevels
        public void Process(LevelType levelType)
        {
            IList <string> lines = new List <string>();

            Type   dataType = typeof(LevelConfigData);
            string title    = xmlToCsv.GetTitle(dataType);

            lines.Add(title);

            var dict = xmlToCsv.GetHeaders(dataType);

            string[] files = fileMgr.GetFiles(levelType);

            Boolean isValid = true;

            foreach (string file in files)
            {
                LevelConfigData data = xmlToCsv.XmlToObj(file);
                //ErrorType errorType = validate.ValidLevelConfigData(data);
                String error = validate.ValidLevelConfigData(data);
                if (!String.IsNullOrEmpty(error))
                {
                    String msg = String.Format("{0} [{1}] => {2}", file, data.LevelNo.ToString().PadLeft(2, '0'), error);
                    logger.Error(msg);
                    isValid = false;
                }

                string line = xmlToCsv.ObjToCsv(dict, data);
                lines.Add(line);
            }

            if (isValid)
            {
                string[] contents = lines.ToArray();
                fileMgr.WriteCSV(levelType, contents);
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            XmlToCsv        xmlToCsv = new XmlToCsv();
            Type            type     = typeof(LevelConfigData);
            string          title    = xmlToCsv.GetTitle(type);
            var             dict     = xmlToCsv.GetHeaders(type);
            string          file     = "01-MOOT.xml";
            LevelConfigData data     = xmlToCsv.XmlToObj(file);
            string          line     = xmlToCsv.ObjToCsv(dict, data);

            int x = 7;

            /*
             * CsvToXml csvToXml = new CsvToXml();
             * var dict = csvToXml.GetHeaders("LevelNo,LevelName,BonusLevel,GridDelay,BulletMaxim");
             * String line = "01,MOOT,true,250,10";
             * LevelConfigData data = csvToXml.CsvToObj(dict, line);
             * csvToXml.ObjToXml(data);
             */


            //LevelConfigData source = new LevelConfigData { LevelNo = "01" };
            //Object obj = (Object)source;
            ////LevelConfigData dst = new LevelConfigData();

            //// ORIGINALLY code did not set the value
            //// actually did set bu=t LevelConfigData is a value type struct
            //// so makes the copy on the value type struct
            //// Solution is to either make LevelConfigData a class and works first time
            //// OR box LevelConfigData as an object and set all the fields on the object
            //// then when finished unbox back to value type struct LevelConfigData
            //// Reference : https://social.msdn.microsoft.com/Forums/vstudio/en-US/33284e33-d004-4b76-bc0f-50100ec46bf1/fieldinfosetvalue-dont-work-in-struct?forum=csharpgeneral


            //FieldInfo[] fields = source.GetType().GetFields();
            ////fields[0].SetValue(source, (Byte)2);
            //fields[0].SetValue(obj, (Byte)2);

            //source = (LevelConfigData)obj;

            //FieldInfo[] fields = typeof(LevelConfigData).GetFields();
            //foreach (FieldInfo field in fields)
            //{
            //    string name = field.Name;
            //    if ("LevelNo" == name)
            //    {
            //        const Byte levelNo = 5;
            //        var blah = Convert.ChangeType(levelNo, field.FieldType);
            //        field.SetValue(data, blah);
            //    }

            //    Console.WriteLine(name);
            //}

            //char[] DELIM = new char[] { ',' };
            //string[] lines = File.ReadAllLines("Levels.csv");

            //string line = lines[0];
            //string[] headers = line.Split(DELIM);

            //IDictionary<string, int> dictionary = new Dictionary<string, int>();
            //for (int index = 0; index < headers.Length; index++)
            //{
            //    string header = headers[index];
            //    if (!dictionary.ContainsKey(header))
            //    {
            //        dictionary.Add(header, index);
            //    }
            //}


            Console.WriteLine("Hello World!");
        }