Пример #1
0
    static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets,
                                       string[] movedFromAssetPaths)
    {
        foreach (string str in importedAssets)
        {
            if (str.IndexOf("/SpawnEnemy.csv") != -1)
            {
                TextAsset         data      = AssetDatabase.LoadAssetAtPath <TextAsset>(str);
                string            assetfile = str.Replace(".csv", ".asset");
                SpawnEnemyExample gm        = AssetDatabase.LoadAssetAtPath <SpawnEnemyExample>(assetfile);
                if (gm == null)
                {
                    gm = ScriptableObject.CreateInstance <SpawnEnemyExample>();
                    AssetDatabase.CreateAsset(gm, assetfile);
                }

                gm.spawnEnemies = CSVSerializer.Deserialize <SpawnEnemyExample.SpawnEnemy>(data.text);

                EditorUtility.SetDirty(gm);
                AssetDatabase.SaveAssets();
#if DEBUG_LOG || UNITY_EDITOR
                Debug.Log("Reimported Asset: " + str);
#endif
            }
        }
    }
        public void PerformanceTest()
        {
            int           fileCount      = 100;
            ClassFormat   dummy          = ClassFormat.Dummy;
            CSVSerializer parser         = new CSVSerializer();
            string        testFolderPath = Path.Combine("./", nameof(PerformanceTest));

            Directory.CreateDirectory(testFolderPath);

            List <string> filePaths = new List <string>();

            for (int i = 0; i < fileCount; i++)
            {
                dummy.className = $"class_{i + 1}";
                string text = parser.Serialize(dummy);
                string path = Path.Combine(testFolderPath, $"{i + 1}.{parser.fileExtension}");
                filePaths.Add(path);
                File.WriteAllText(path, text);
            }

            ToCodeVerb codeCommand = new ToCodeVerb();

            codeCommand.inputPaths       = new string[] { testFolderPath };
            codeCommand.resultFolderPath = testFolderPath;
            codeCommand.fileName         = nameof(PerformanceTest);

            ToCodeVerb.Verb(codeCommand).Result.Should().Be(0);

            Directory.Delete(testFolderPath, true);
        }
Пример #3
0
        public List <Network> aggrigateTransactionsFromCSV(string fileLocation)
        {
            // keeping the raw transactions for future-proofing
            List <Transaction> rawTransactions    = new CSVSerializer().readFromCSV(fileLocation);
            List <Network>     aggrogatedNetworks = new List <Network>();

            Core.Context.log.i("found " + rawTransactions.Count + " transactions.");

            foreach (var transaction in rawTransactions)
            {
                // check if the transaction name exists in the aggrogated network list
                var existingNetwork = aggrogatedNetworks.Find(e => e.Name == transaction.Name);

                if (existingNetwork == null)
                {
                    Network network = new Network(transaction.MSISDN, transaction.Name);
                    network.addLoan(transaction.DateTime, transaction.Product, transaction.Amount);

                    aggrogatedNetworks.Add(network);
                }
                else
                {
                    // add the loan to the existing transaction
                    existingNetwork.addLoan(transaction.DateTime, transaction.Product, transaction.Amount);
                }
            }

            return(aggrogatedNetworks);
        }
Пример #4
0
    static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
    {
        foreach (string str in importedAssets)
        {
            if (str.IndexOf("/orderdata.csv") != -1)
            {
                TextAsset data      = AssetDatabase.LoadAssetAtPath <TextAsset>(str);
                string    assetfile = str.Replace(".csv", ".asset");
                Orderdata gm        = AssetDatabase.LoadAssetAtPath <Orderdata>(assetfile);
                if (gm == null)
                {
                    gm = new Orderdata();
                    AssetDatabase.CreateAsset(gm, assetfile);
                }

                gm.allOrderType = CSVSerializer.Deserialize <Orderdata.OrderDetails>(data.text);

                EditorUtility.SetDirty(gm);
                AssetDatabase.SaveAssets();
#if DEBUG_LOG || UNITY_EDITOR
                Debug.Log("Reimported Asset: " + str);
#endif
            }
        }
    }
Пример #5
0
    static void Setup(string path, string fullPath, string[] importedAssets)
    {
        foreach (string str in importedAssets)
        {
            if (str.IndexOf(path) != -1)
            {
                var assetPath = str.Replace(path, fullPath);

                TextAsset data = AssetDatabase.LoadAssetAtPath <TextAsset>(str);

                string assetfile = assetPath.Replace(".csv", ".asset");

                ShopGroupExample gm = AssetDatabase.LoadAssetAtPath <ShopGroupExample>(assetfile);
                if (gm == null)
                {
                    gm = ScriptableObject.CreateInstance <ShopGroupExample>();
                    AssetDatabase.CreateAsset(gm, assetfile);
                }

                gm.shopGroups = CSVSerializer.Deserialize <ShopGroupExample.ShopGroup>(data.text);

                EditorUtility.SetDirty(gm);
                AssetDatabase.SaveAssets();
#if DEBUG_LOG || UNITY_EDITOR
                Debug.Log("Reimported Asset: " + assetPath);
#endif
            }
        }
    }
        public void SerializeTest()
        {
            ClassFormat   dummy  = ClassFormat.Dummy;
            CSVSerializer parser = new CSVSerializer();

            string text = parser.Serialize(dummy);

            if (parser.TryDeserialize(text, out ClassFormat[] formats) == false)
        private void btnSaveCSV_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.FileName = series.Name.Trim();
            sfd.Filter   = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                CSVSerializer.SaveSeria(series, (FileStream)sfd.OpenFile());
            }
        }
Пример #8
0
        public void TestCSVSerializer()
        {
            var serializer = new CSVSerializer();

            var expected = $"1,\"Doe,\tJohn\"{Environment.NewLine}2,\"Doe,\tJane\"";

            var output = serializer.Serialize(data);

            Assert.IsNotNull(output);
            Assert.AreEqual(expected, output);
        }
Пример #9
0
    public static void ImportCardData(string text, string assetfile)
    {
        List <string[]> rows = CSVSerializer.ParseCSV(text);

        if (rows != null)
        {
            CardData cardData = AssetDatabase.LoadAssetAtPath <CardData>(assetfile);
            if (cardData == null)
            {
                cardData = (CardData)ScriptableObject.CreateInstance(typeof(CardData));
                AssetDatabase.CreateAsset(cardData, assetfile);
            }
            cardData.cards = CSVSerializer.Deserialize <Card>(rows);
            EditorUtility.SetDirty(cardData);
            AssetDatabase.SaveAssets();
        }
    }
Пример #10
0
        public ActionResult Attendees()
        {
            var attendeeList = CurrentAttendee.List();
            var serializer   = new CSVSerializer();

            var builder = new StringBuilder();

            builder.AppendLine(serializer.Header(new CurrentAttendee()));
            attendeeList.ForEach(x => builder.AppendLine(serializer.Serialize(x)));

            var result = new FileContentResult(Encoding.ASCII.GetBytes(builder.ToString()), "text/csv")
            {
                FileDownloadName = "Attendees.csv"
            };

            return(new EmptyResult());
        }
Пример #11
0
    static void ImportRankingData(string text, string assetfile)
    {
        List <string[]> rows = CSVSerializer.ParseCSV(text);

        if (rows != null)
        {
            RankingData gm = AssetDatabase.LoadAssetAtPath <RankingData>(assetfile);
            if (gm == null)
            {
                gm = new RankingData();
                AssetDatabase.CreateAsset(gm, assetfile);
            }
            gm.m_Items = CSVSerializer.Deserialize <RankingData.Item>(rows);

            EditorUtility.SetDirty(gm);
            AssetDatabase.SaveAssets();
        }
    }
        public void WorkingTest()
        {
            ClassFormat   dummy  = ClassFormat.Dummy;
            CSVSerializer parser = new CSVSerializer();

            string text = parser.Serialize(dummy);
            string path = $"{nameof(WorkingTest)}.{parser.fileExtension}";

            File.WriteAllText(path, text);

            ToCodeVerb codeCommand = new ToCodeVerb();

            codeCommand.inputPaths = new string[] { path };
            codeCommand.fileName   = nameof(WorkingTest);

            ToCodeVerb.Verb(codeCommand).Result.Should().Be(0);

            File.Delete(Path.Combine(Directory.GetCurrentDirectory(), path));
            File.Delete(codeCommand.OutputFilePath());
        }
Пример #13
0
        public static void Main(string[] args)
        {
            TransactionImporter transactionImporter   = new TransactionImporter();
            List <Network>      aggregatedNetworkList = transactionImporter.aggrigateTransactionsFromCSV("../../../../loans.csv");

            if (aggregatedNetworkList.Count > 0)
            {
                CSVSerializer csvSerializer = new CSVSerializer();
                csvSerializer.exportAggrigatedList(aggregatedNetworkList, "../../../../output.csv");
            }
            else
            {
                Core.Context.log.i("no aggrigated transactions, file not being written.");
            }

            Console.ReadLine();

            while (true)
            {
                Thread.Sleep(1000);
            }
        }
Пример #14
0
        static void Main(string[] args)
        {
            if (File.Exists("export.csv"))
            {
                File.Delete("export.csv");
            }


            string connectionString = "Data Source=localhost;Database=tutorial_db;userid=xxxx;password=xxxxx";

            MinimalDataContext dataContext = new MinimalDataContext(connectionString);
            var           mydataList       = dataContext.GetUserData();
            CSVSerializer serializer       = new CSVSerializer();


            using (StreamWriter file = new StreamWriter("export.csv"))
            {
                foreach (var item in mydataList)
                {
                    file.WriteLine(serializer.Serialize(item));
                }
            }


            dataContext.DeleteAll();


            using (StreamReader reader = new StreamReader("export.csv"))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    var model = serializer.Deserialize(line);
                    dataContext.Insert(model);
                }
            }
        }
Пример #15
0
    private void Awake()
    {
        ItemBase[] items = CSVSerializer.Deserialize <ItemBase>(csvItems.text);
        foreach (var item in items)
        {
            this.items.Add(item.id, item);
        }

        ItemBaseLocal[] locals = CSVSerializer.Deserialize <ItemBaseLocal>(csvItemsLocals.text);
        foreach (var item in locals)
        {
            if (this.items.ContainsKey(item.id))
            {
                try
                {
                    this.items[item.id].local = item;
                }
                catch (Exception ex)
                {
                    Debug.Log("Couldnt load local for: " + item.id + " " + ex.ToString());
                }
            }
        }
    }
Пример #16
0
        private ISerializable GetSerializer(string path)
        {
            string        ext        = Path.GetExtension(path);
            ISerializable serializer = null;

            if (ext.Equals(".json"))
            {
                serializer = new JSONSerializer();
            }
            else if (ext.Equals(".xml"))
            {
                serializer = new XMLSerializer();
            }
            else if (ext.Equals(".csv"))
            {
                serializer = new CSVSerializer();
            }
            else if (ext.Equals(".bin"))
            {
                serializer = new BinarySerializer();
            }

            return(serializer);
        }
    static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
    {
        foreach (string str in importedAssets)
        {
            if (str.IndexOf("/sample.csv") != -1)
            {
                TextAsset        data      = AssetDatabase.LoadAssetAtPath <TextAsset>(str);
                string           assetfile = str.Replace(".csv", ".asset");
                CSVImportExample gm        = AssetDatabase.LoadAssetAtPath <CSVImportExample>(assetfile);
                if (gm == null)
                {
                    gm = new CSVImportExample();
                    AssetDatabase.CreateAsset(gm, assetfile);
                }

                gm.m_Sample = CSVSerializer.Deserialize <CSVImportExample.Sample>(data.text);

                EditorUtility.SetDirty(gm);
                AssetDatabase.SaveAssets();
#if DEBUG_LOG || UNITY_EDITOR
                Debug.Log("Reimported Asset: " + str);
#endif
            }
            if (str.IndexOf("/f1ranking2018.csv") != -1)
            {
                TextAsset   data      = AssetDatabase.LoadAssetAtPath <TextAsset>(str);
                string      assetfile = str.Replace(".csv", ".asset");
                RankingData gm        = AssetDatabase.LoadAssetAtPath <RankingData>(assetfile);
                if (gm == null)
                {
                    gm = new RankingData();
                    AssetDatabase.CreateAsset(gm, assetfile);
                }

                gm.m_Items = CSVSerializer.Deserialize <RankingData.Item>(data.text);

                EditorUtility.SetDirty(gm);
                AssetDatabase.SaveAssets();
#if DEBUG_LOG || UNITY_EDITOR
                Debug.Log("Reimported Asset: " + str);
#endif
            }
            if (str.IndexOf("/lan.csv") != -1)
            {
                TextAsset          data      = AssetDatabase.LoadAssetAtPath <TextAsset>(str);
                string             assetfile = str.Replace(".csv", ".asset");
                LanguageStringData gm        = AssetDatabase.LoadAssetAtPath <LanguageStringData>(assetfile);
                if (gm == null)
                {
                    gm = new LanguageStringData();
                    AssetDatabase.CreateAsset(gm, assetfile);
                }

                gm.m_Items = CSVSerializer.Deserialize <LanguageStringData.Item>(data.text);

                EditorUtility.SetDirty(gm);
                AssetDatabase.SaveAssets();
#if DEBUG_LOG || UNITY_EDITOR
                Debug.Log("Reimported Asset: " + str);
#endif
            }
            if (str.IndexOf("/const.csv") != -1)
            {
                TextAsset data      = AssetDatabase.LoadAssetAtPath <TextAsset>(str);
                string    assetfile = str.Replace(".csv", ".asset");
                ConstData gm        = AssetDatabase.LoadAssetAtPath <ConstData>(assetfile);
                if (gm == null)
                {
                    gm = new ConstData();
                    AssetDatabase.CreateAsset(gm, assetfile);
                }

                ConstData readdata = CSVSerializer.DeserializeIdValue <ConstData>(data.text);
                EditorUtility.CopySerialized(readdata, gm);

                EditorUtility.SetDirty(gm);
                AssetDatabase.SaveAssets();
#if DEBUG_LOG || UNITY_EDITOR
                Debug.Log("Reimported Asset: " + str);
#endif
            }
        }
    }
Пример #18
0
    static void Setup(string path, string[] importedAssets)
    {
        Action <string, TextAsset, Type, Type> genAsset =
            delegate(string assetfile, TextAsset data, Type classCollection, Type classData)
        {
            var gm = AssetDatabase.LoadAssetAtPath(assetfile, classCollection);

            if (gm == null)
            {
                gm = ScriptableObject.CreateInstance(classCollection);
                AssetDatabase.CreateAsset(gm, assetfile);
            }

            Type type   = classData;
            var  field  = gm.GetType().GetField("dataGroups", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
            var  method = gm.GetType().GetMethod("Convert");

            field.SetValue(gm, CSVSerializer.Deserialize(data.text, type));

            method?.Invoke(gm, null);

            if (field.IsPrivate)
            {
                field.SetValue(gm, null);
            }

            EditorUtility.SetDirty(gm);
            AssetDatabase.SaveAssets();
        };

        foreach (string str in importedAssets)
        {
            if (str.IndexOf(path) != -1)
            {
                Debug.Log("str: " + str);
                TextAsset data = AssetDatabase.LoadAssetAtPath <TextAsset>(str);

                var isDefineCollection = path.Equals("define_collection.csv");

                var  assetfile = "";
                Type classCollection;
                Type classData;

                if (isDefineCollection)
                {
                    assetfile       = "Assets/Resources/Collection/define_collection.asset";
                    classCollection = Type.GetType("DefineCollection");
                    classData       = Type.GetType("DefineData");
                    genAsset(assetfile, data, classCollection, classData);
                }
                else
                {
                    var defineCollection = LoadResourceController.GetDefineCollection();

                    if (defineCollection == null)
                    {
                        TextAsset textAsset =
                            AssetDatabase.LoadAssetAtPath <TextAsset>(
                                "Assets/Csv/Collection/define_collection.csv");

                        Debug.Log("textAsset:" + textAsset);
                        assetfile       = "Assets/Resources/Collection/define_collection.asset";
                        classCollection = Type.GetType("DefineCollection");
                        classData       = Type.GetType("DefineData");
                        genAsset(assetfile, textAsset, classCollection, classData);
                    }

                    defineCollection = LoadResourceController.GetDefineCollection();
                    var defineData = defineCollection.GetDefineCollectionData(path);
                    if (defineData == null)
                    {
                        return;
                    }

                    assetfile       = "Assets/Resources/" + defineData.assetPath + ".asset";
                    classCollection = Type.GetType(defineData.classCollection);
                    classData       = Type.GetType(defineData.classData);
                    genAsset(assetfile, data, classCollection, classData);
                }

#if DEBUG_LOG || UNITY_EDITOR
                Debug.Log("Reimported Asset: " + assetfile);
#endif
            }
        }
    }
Пример #19
0
    static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
    {
        foreach (string str in importedAssets)
        {
            if (str.IndexOf("/character.csv") != -1)
            {
                TextAsset     data      = AssetDatabase.LoadAssetAtPath <TextAsset>(str);
                string        assetfile = str.Replace(".csv", ".asset");
                CharacterText gm        = AssetDatabase.LoadAssetAtPath <CharacterText>(assetfile);
                if (gm == null)
                {
                    gm = new CharacterText();
                    AssetDatabase.CreateAsset(gm, assetfile);
                }

                gm.characters = CSVSerializer.Deserialize <CharacterText.Character>(data.text);

                EditorUtility.SetDirty(gm);
                AssetDatabase.SaveAssets();
#if DEBUG_LOG || UNITY_EDITOR
                Debug.Log("Reimported Asset: " + str);
#endif
            }
            if (Regex.IsMatch(str, "L[0-9a-zA-Z]*[.]csv$"))
            {
                TextAsset       data      = AssetDatabase.LoadAssetAtPath <TextAsset>(str);
                string          assetfile = str.Replace(".csv", ".asset");
                LocalizableData gm        = AssetDatabase.LoadAssetAtPath <LocalizableData>(assetfile);
                if (gm == null)
                {
                    gm = new LocalizableData();
                    AssetDatabase.CreateAsset(gm, assetfile);
                }

                gm.datas = CSVSerializer.Deserialize <LocalizableData.Data>(data.text);

                EditorUtility.SetDirty(gm);
                AssetDatabase.SaveAssets();
#if DEBUG_LOG || UNITY_EDITOR
                Debug.Log("Reimported Asset: " + str);
#endif
            }

            if (str.IndexOf("/CardData.csv") != -1)
            {
                TextAsset data      = AssetDatabase.LoadAssetAtPath <TextAsset>(str);
                string    assetfile = str.Replace(".csv", ".asset");
                CardData  gm        = AssetDatabase.LoadAssetAtPath <CardData>(assetfile);
                if (gm == null)
                {
                    gm = new CardData();
                    AssetDatabase.CreateAsset(gm, assetfile);
                }

                gm.Cards = CSVSerializer.Deserialize <CardData.Data>(data.text);
                var tempList = new List <CardSource>();

                foreach (var card in gm.Cards)
                {
                    var cardSource = CheckAndGetCard(card);
                    ApplyData(card, cardSource);
                    tempList.Add(cardSource);
                }

                foreach (var card in gm.Cards)
                {
                    ApplyUpgradeList(card, tempList[0]);
                    tempList.RemoveAt(0);
                }

                EditorUtility.SetDirty(gm);
                AssetDatabase.SaveAssets();
#if DEBUG_LOG || UNITY_EDITOR
                Debug.Log("Reimported Asset: " + str);
#endif
            }
        }
    }
Пример #20
0
        static void Main(string[] args)
        {
            var data = CSVSerializer.Deserialize <Data>("postcodes.csv");

            Console.ReadLine();
        }