Example #1
0
        private void AddLineToFile(string filename, Dictionary <string, string> fileRow)
        {
            lock (this) {
                StringBuilder outData = StringBuilderPool.Get();
                lock (fileColumnNames)
                    foreach (string columnHeader in fileColumnNames)
                    {
                        outData.AppendFormat("{0}, ", columnHeader);
                    }
                if (!File.Exists(filename))
                {
                    outData.AppendLine();
                    File.AppendAllText(filename, outData.ToString());
                }
                else
                {
                    string tempFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".trsimtmp");
                    bool   RowHeaderChanged;
                    using (StreamReader reader = new StreamReader(filename)) {
                        string firstRow = reader.ReadLine();
                        RowHeaderChanged = !firstRow.Equals(outData.ToString());
                        if (RowHeaderChanged)
                        {
                            using (StreamWriter writer = new StreamWriter(tempFilename)) {
                                writer.WriteLine(outData.ToString());
                                string line;
                                while ((line = reader.ReadLine()) != null)
                                {
                                    writer.WriteLine(line);
                                }
                            }
                        }
                    }
                    if (RowHeaderChanged)
                    {
                        File.Copy(tempFilename, filename, true);
                        File.Delete(tempFilename);
                    }
                }

                outData.Clear();
                lock (fileColumnNames) {
                    foreach (string column in fileColumnNames)
                    {
                        if (fileRow.ContainsKey(column))
                        {
                            outData.AppendFormat("{0}, ", fileRow[column]);
                        }
                        else
                        {
                            outData.Append("0, ");
                        }
                    }
                    outData.AppendLine();
                }
                File.AppendAllText(filename, outData.Release());
            }
        }
Example #2
0
            public string Data()
            {
                var sb = StringBuilderPool.Get();

                sb.Append(memeId);
                sb.Append(',').Append(affectedFeature.GetAcronym());
                sb.Append(',').Append(efficiency.ToString(CultureInfo.InvariantCulture));
                sb.Append(',').Append(price.ToString(CultureInfo.InvariantCulture));
                sb.Append(',').Append(complexityCoefficient.ToString(CultureInfo.InvariantCulture));
                sb.Append(',').Append(yearInvented);
                sb.Append(',').Append(currentPopulation);
                sb.Append(',').Append(maxPopulation);
                sb.Append(',').Append(maxPopulationYear);
                sb.Append(',').Append(totalPopulation);
                sb.Append(',').Append(goesAwayYear);
                sb.Append('\n');
                return(sb.Release());
            }
Example #3
0
            public string Header()
            {
                var sb = StringBuilderPool.Get();

                sb.Append(nameof(memeId));
                sb.Append(',').Append(nameof(affectedFeature));
                sb.Append(',').Append(nameof(efficiency));
                sb.Append(',').Append(nameof(price));
                sb.Append(',').Append(nameof(complexityCoefficient));
                sb.Append(',').Append(nameof(yearInvented));
                sb.Append(',').Append(nameof(currentPopulation));
                sb.Append(',').Append(nameof(maxPopulation));
                sb.Append(',').Append(nameof(maxPopulationYear));
                sb.Append(',').Append(nameof(totalPopulation));
                sb.Append(',').Append(nameof(goesAwayYear));
                sb.Append('\n');
                return(sb.Release());
            }