Example #1
0
        public bool ExportData(string filePath, UserTrainingInfo userTrainingInfo)
        {
            var json = JsonConvert.SerializeObject(userTrainingInfo);

            try
            {
                File.WriteAllText(filePath, json);
                return(true);
            }
            catch
            {
                // Ignore
                return(false);
            }
        }
Example #2
0
        public bool ExportData(string fileName, UserTrainingInfo userTrainingInfo)
        {
            try
            {
                var formatter = new XmlSerializer(typeof(UserTrainingInfo));

                using (var fs = new FileStream(fileName, FileMode.OpenOrCreate))
                {
                    formatter.Serialize(fs, userTrainingInfo);
                }

                return(true);
            }
            catch
            {
                // Ignore
                return(false);
            }
        }
        public bool ExportData(string fileName, UserTrainingInfo userTrainingInfo)
        {
            var generalInfo = $"User,{userTrainingInfo.Name}\n" +
                              $"Average Steps,{userTrainingInfo.AverageSteps}\n" +
                              $"Best Step Result,{userTrainingInfo.BestStepResult}\n" +
                              $"Worth Step Result,{userTrainingInfo.WorstStepResult}\n";

            var trainingHeader = $"Day,Rang,Status,Steps\n";

            var dayToDayInfo = string.Join("\n", userTrainingInfo.Trainings
                                           .OrderBy(training => training.Number)
                                           .Select(training => $"Day{training.Number},{training.Rank},{training.Status},{training.Steps}"));

            try
            {
                File.WriteAllText(fileName, generalInfo + trainingHeader + dayToDayInfo);
                return(true);
            }
            catch
            {
                // Ignore
                return(false);
            }
        }