public static char ToChar(this AvailableDelimiters delimiter)
        {
            switch (delimiter)
            {
            case AvailableDelimiters.Comma:
                return(',');

            case AvailableDelimiters.Tab:
                return('\t');

            case AvailableDelimiters.Pipe:
                return('|');
            }
            throw new ArgumentException();
        }
Example #2
0
        private static void DeserializeToRcr(AvailableDelimiters delimiter, string fileName, out RuntimeCsvRepresentation rcr, out bool succeeded)
        {
            rcr = null;

            succeeded = true;

            try
            {
                // Let's load this bad boy and get info about the class we need to make
                rcr = CsvFileManager.CsvDeserializeToRuntime(fileName);
            }
            catch (Exception e)
            {
                GlueGui.ShowMessageBox("Error parsing CSV\n\n" + fileName + "\nAttempted to use " + delimiter + " as the delimiter.  If this is not the delimiter of the file, try changing the delimiter in Glue after the file is added");

                FlatRedBall.Glue.Plugins.PluginManager.ReceiveError(e.ToString());

                succeeded = false;
            }
        }
Example #3
0
        private static void DeserializeToRcr(AvailableDelimiters delimiter, string fileName, out RuntimeCsvRepresentation rcr, out bool succeeded)
        {
            rcr = null;

            succeeded = true;

            try
            {
                // Let's load this bad boy and get info about the class we need to make
                rcr = CsvFileManager.CsvDeserializeToRuntime(fileName);
            }
            catch (Exception e)
            {
                GlueGui.ShowMessageBox("Error parsing CSV\n\n" + fileName + "\nAttempted to use " + delimiter + " as the delimiter.  If this is not the delimiter of the file, try changing the delimiter in Glue after the file is added");

                FlatRedBall.Glue.Plugins.PluginManager.ReceiveError(e.ToString());

                succeeded = false;
            }
        }
Example #4
0
        public static void GenerateAndSaveDataClass(ReferencedFileSave rfs, AvailableDelimiters delimiter)
        {
            string fileName = rfs.Name;

            fileName = ProjectManager.MakeAbsolute(fileName);

            #region See if the CSV file doesn't exist and warn the user if not
            if (!System.IO.File.Exists(fileName))
            {
                MessageBox.Show("Could not find the CSV file " + fileName +
                                " when trying to generate a data file");
            }
            #endregion

            else // CSV exists
            {
                #region Save off the old delimiter and switch to using the new one - we need the old one so we can switch back after this function finishes

                char oldDelimiter = CsvFileManager.Delimiter;
                CsvFileManager.Delimiter = delimiter.ToChar();
                #endregion

                if (!string.IsNullOrEmpty(rfs.UniformRowType))
                {
                    // This simply
                    // checks to make
                    // sure the CSV is
                    // set up right - it
                    // doesn't actually generate
                    // any code because the CSV will
                    // deserialize to an array of primitives.
                    CheckUniformTypeValidity(rfs, fileName, oldDelimiter);
                }
                else
                {
                    RuntimeCsvRepresentation rcr;
                    bool succeeded;
                    DeserializeToRcr(delimiter, fileName, out rcr, out succeeded);

                    if (succeeded)
                    {
                        CsvFileManager.Delimiter = oldDelimiter;


                        string whyIsCsvWrong = GetWhyCsvIsWrong(rcr, rfs.CreatesDictionary, fileName);

                        if (!string.IsNullOrEmpty(whyIsCsvWrong))
                        {
                            GlueGui.ShowMessageBox(whyIsCsvWrong);
                            succeeded = false;
                        }
                        else
                        {
                            string className;
                            List <TypedMemberBase>      members;
                            Dictionary <string, string> untypedMembers;

                            CustomClassSave customClass = GetCustomClassForCsv(rfs.Name);

                            if (customClass == null || customClass.GenerateCode)
                            {
                                fileName = GetClassInfoFromCsvs(rfs, fileName, rcr, out className, out members, out untypedMembers);


                                succeeded = GenerateClassFromMembers(rfs, succeeded, className, members, untypedMembers);
                            }
                        }
                    }
                }
            }
        }
Example #5
0
        public static void GenerateAndSaveDataClass(ReferencedFileSave rfs, AvailableDelimiters delimiter)
        {
            string fileName = rfs.Name;
            fileName = ProjectManager.MakeAbsolute(fileName);

            #region See if the CSV file doesn't exist and warn the user if not
            if (!System.IO.File.Exists(fileName))
            {
                MessageBox.Show("Could not find the CSV file " + fileName + 
                    " when trying to generate a data file");
            }
            #endregion

            else // CSV exists
            {
                #region Save off the old delimiter and switch to using the new one - we need the old one so we can switch back after this function finishes

                char oldDelimiter = CsvFileManager.Delimiter;
                CsvFileManager.Delimiter = delimiter.ToChar();
                #endregion

                if (!string.IsNullOrEmpty(rfs.UniformRowType))
                {
                    // This simply
                    // checks to make
                    // sure the CSV is
                    // set up right - it
                    // doesn't actually generate
                    // any code because the CSV will
                    // deserialize to an array of primitives.
                    CheckUniformTypeValidity(rfs, fileName, oldDelimiter);
                }
                else
                {
                    RuntimeCsvRepresentation rcr;
                    bool succeeded;
                    DeserializeToRcr(delimiter, fileName, out rcr, out succeeded);
                    
                    if(succeeded)
                    {
                        CsvFileManager.Delimiter = oldDelimiter;
                    

                        string whyIsCsvWrong = GetWhyCsvIsWrong(rcr, rfs.CreatesDictionary, fileName);

                        if (!string.IsNullOrEmpty(whyIsCsvWrong))
                        {
                            GlueGui.ShowMessageBox(whyIsCsvWrong);
                            succeeded = false;
                        }
                        else
                        {
                            string className;
                            List<TypedMemberBase> members;
                            Dictionary<string, string> untypedMembers;

                            CustomClassSave customClass = GetCustomClassForCsv(rfs.Name);

                            if (customClass == null || customClass.GenerateCode)
                            {
                                fileName = GetClassInfoFromCsvs(rfs, fileName, rcr, out className, out members, out untypedMembers);


                                succeeded = GenerateClassFromMembers(rfs, succeeded, className, members, untypedMembers);
                            }
                        }
                    }
                }

            }
        }