Пример #1
0
        private string GetCsvContents(EntitySave entity, RacingEntityViewModel viewModel)
        {
            List <RacingEntityValues> values = new List <RacingEntityValues>();

            var defaultValues = new RacingEntityValues();

            defaultValues.Name = "DefaultValues";
            // leave the defaults from the class

            values.Add(defaultValues);

            RuntimeCsvRepresentation rcr = RuntimeCsvRepresentation.FromList(values);

            var nameHeader = rcr.Headers[0];

            // Setting it to IsRequired is not sufficient, need to
            // modify the "Original Text" prop
            // chop off the closing quote, and add ", required)"
            nameHeader.OriginalText = nameHeader.OriginalText.Substring(0, nameHeader.OriginalText.Length - 1) + ", required)";

            rcr.Headers[0] = nameHeader;

            // if we want more defaults here...
            rcr.Records.Add(new string[0]);

            var toReturn = rcr.GenerateCsvString();

            return(toReturn);
        }
Пример #2
0
        private string GetCsvContents(EntitySave entity, PlatformerEntityViewModel viewModel)
        {
            List <PlatformerValues> values = new List <PlatformerValues>();

            foreach (var valuesViewModel in viewModel.PlatformerValues)
            {
                values.Add(valuesViewModel.ToValues());
            }

            RuntimeCsvRepresentation rcr = RuntimeCsvRepresentation.FromList(values);

            var nameHeader = rcr.Headers[0];

            nameHeader.IsRequired = true;
            // Setting it to IsRequired is not sufficient, need to
            // modify the "Original Text" prop
            // chop off the closing quote, and add ", required)"
            nameHeader.OriginalText = nameHeader.OriginalText.Substring(0, nameHeader.OriginalText.Length - 1) + ", required)";

            rcr.Headers[0] = nameHeader;

            var toReturn = rcr.GenerateCsvString();

            return(toReturn);
        }
        public void TestSerialization()
        {
            RuntimeCsvRepresentation rcr = new RuntimeCsvRepresentation();

            rcr.Headers = new CsvHeader[4];
            rcr.Headers[0] = new CsvHeader("Header1");
            rcr.Headers[1] = new CsvHeader("Header2");
            rcr.Headers[2] = new CsvHeader("Newline Test1");
            rcr.Headers[3] = new CsvHeader("Something");
            rcr.Headers[3].IsRequired = true;

            rcr.Records = new List<string[]>();
            rcr.Records.Add(new string[4]);
            rcr.Records[0][0] = "NoQuotes \"Quotes\" NoQuotes";
            rcr.Records[0][1] = "Value = \"Something\"";
            rcr.Records[0][2] = string.Concat("Line 1", Environment.NewLine, "Line 2");
            rcr.Records[0][3] = "";

            string result = rcr.GenerateCsvString();
            if (!result.Contains("NoQuotes \"\"Quotes\"\" NoQuotes"))
            {
                throw new Exception("rcr.GenerateCsvString is not properly adding double quotes for quotes");
            }

            if (!result.Contains("\"Value = \"\"Something\"\"\""))
            {
                throw new Exception("rcr.GenerateCsvString is not properly wrapping text in quotes when it should");
            }
            
            if (!result.Contains(string.Concat("\"", rcr.Records[0][2], "\"")))
            {
                throw new Exception("rcr.GenerateCsvString is not properly wrapping newlined text in quotes");
            }

            FileManager.SaveText(result, "SavedCsv.csv");

            RuntimeCsvRepresentation loaded = CsvFileManager.CsvDeserializeToRuntime("SavedCsv.csv");

            for (int i = 0; i < loaded.Records.Count; i++)
            {
                for (int j = 0; j < loaded.Records[i].Length; j++)
                {
                    var loadedAtIandJ = loaded.Records[i][j];
                    var rcrAtIandJ = rcr.Records[i][j];
                    if (loadedAtIandJ != rcrAtIandJ)
                    {
                        throw new Exception("Loaded RCR doesn't equal what was saved");
                    }
                }
            }

        }
        public void TestSerialization()
        {
            RuntimeCsvRepresentation rcr = new RuntimeCsvRepresentation();

            rcr.Headers               = new CsvHeader[4];
            rcr.Headers[0]            = new CsvHeader("Header1");
            rcr.Headers[1]            = new CsvHeader("Header2");
            rcr.Headers[2]            = new CsvHeader("Newline Test1");
            rcr.Headers[3]            = new CsvHeader("Something");
            rcr.Headers[3].IsRequired = true;

            rcr.Records = new List <string[]>();
            rcr.Records.Add(new string[4]);
            rcr.Records[0][0] = "NoQuotes \"Quotes\" NoQuotes";
            rcr.Records[0][1] = "Value = \"Something\"";
            rcr.Records[0][2] = string.Concat("Line 1", Environment.NewLine, "Line 2");
            rcr.Records[0][3] = "";

            string result = rcr.GenerateCsvString();

            if (!result.Contains("NoQuotes \"\"Quotes\"\" NoQuotes"))
            {
                throw new Exception("rcr.GenerateCsvString is not properly adding double quotes for quotes");
            }

            if (!result.Contains("\"Value = \"\"Something\"\"\""))
            {
                throw new Exception("rcr.GenerateCsvString is not properly wrapping text in quotes when it should");
            }

            if (!result.Contains(string.Concat("\"", rcr.Records[0][2], "\"")))
            {
                throw new Exception("rcr.GenerateCsvString is not properly wrapping newlined text in quotes");
            }

            FileManager.SaveText(result, "SavedCsv.csv");

            RuntimeCsvRepresentation loaded = CsvFileManager.CsvDeserializeToRuntime("SavedCsv.csv");

            for (int i = 0; i < loaded.Records.Count; i++)
            {
                for (int j = 0; j < loaded.Records[i].Length; j++)
                {
                    var loadedAtIandJ = loaded.Records[i][j];
                    var rcrAtIandJ    = rcr.Records[i][j];
                    if (loadedAtIandJ != rcrAtIandJ)
                    {
                        throw new Exception("Loaded RCR doesn't equal what was saved");
                    }
                }
            }
        }
        public void UpdateLocalizationDb(string[][] localizationDbEntries, bool isGlsnChange = false)
        {
            if (LocalizationDb != null)
            {
                //Make sure we are getting the most recent version of the localizationDb.
                //This prevents us from erasing entries not added by this plugin.
                ResetLocalizationDb();

                if (isGlsnChange)
                {
                    var firstKey = localizationDbEntries[0][0];
                    var currentStringIdPrefix = firstKey.Substring(0, firstKey.IndexOf("Passage"));

                    //We want to remove all entries for this DT because we could be removing a key.
                    LocalizationDb.Records.RemoveAll(item => item[0].StartsWith(currentStringIdPrefix));
                }

                foreach (var entry in localizationDbEntries)
                {
                    var dbRecord = LocalizationDb.Records.FirstOrDefault(item => item[0] == entry[0]);

                    if (dbRecord != null)
                    {
                        for (int i = 0; i < entry.Length; i++)
                        {
                            dbRecord[i] = entry[i];
                        }
                    }
                    else
                    {
                        LocalizationDb.Records.Add(entry);
                    }
                }
                TaskManager.Self.AddAsyncTask(
                    () =>
                {
                    string fileName = GlueCommands.Self.GetAbsoluteFileName(RelativeToGlobalContentLocalizationDbCsvFile, false);

                    CsvGenerator.Self.GenerateFor(fileName, LocalizationDb.GenerateCsvString());
                },
                    "Dialog Tree Manager: Regenerating LocalizationDatabase."
                    );
            }
        }
Пример #6
0
        private string GetCsvContents(EntitySave entity, TopDownEntityViewModel viewModel)
        {
            List <TopDownValues> values = new List <TopDownValues>();

            // create a default entry:
            var defaultValue = new TopDownValues();

            defaultValue.Name                        = "DefaultValues";
            defaultValue.MaxSpeed                    = 250;
            defaultValue.AccelerationTime            = 1;
            defaultValue.DecelerationTime            = .5f;
            defaultValue.UpdateDirectionFromVelocity = true;

            values.Add(defaultValue);

            RuntimeCsvRepresentation rcr = RuntimeCsvRepresentation.FromList(values);

            var nameHeader = rcr.Headers[0];

            nameHeader.IsRequired = true;
            // Setting it to IsRequired is not sufficient, need to
            // modify the "Original Text" prop
            // chop off the closing quote, and add ", required)"
            nameHeader.OriginalText = nameHeader.OriginalText.Substring(0, nameHeader.OriginalText.Length - 1) + ", required)";

            rcr.Headers[0] = nameHeader;

            var movementDefaults = new string[]
            {
            };

            rcr.Records.Add(movementDefaults);

            var toReturn = rcr.GenerateCsvString();

            return(toReturn);
        }