|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace Versioner
{
public class Versioner
{
public Dictionary<string, string> Versions;
public static Versioner Create(string filename)
{
return new Versioner()
{
Versions = !File.Exists (filename) ? new Dictionary<string, string>() :
File.ReadAllLines(filename).Select(l => l.Split(',')).Where(v=>v.Length==2).ToDictionary(k => k[0], v => v[1])
};
}
public Versioner Save(string filename)
{
var dir = Path.GetDirectoryName(filename);
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
File.WriteAllLines(filename,
Versions.Select(v=>string.Format("{0},{1}", v.Key, v.Value)).ToArray());
return this;
}
public static string Increment(string response, int incIndex)
{
var ints = response.Split('.').Select(i => int.Parse(i)).ToArray();
int pos = ints.Length - incIndex;
if (pos < 0)
return response;
ints[pos] = ints[pos]+1;
while (++pos < ints.Length)
ints[pos] = 0;
return string.Join(".", ints.Select(i => i.ToString()));
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
My professional career began as a developer fixing bugs on Microsoft Word97 and I've been fixing bad habits ever since. Now I do R&D work writing v1 line of business applications mostly in C#/.Net.
I've been an avid pilot/instructor for 13+ years, I've built two airplanes and mostly fly gliders now for fun. I commute in an all-electric 1986 BMW 325 conversion.
I'd like to get back to my academic roots of programming 3D analysis applications to organize complex systems.