main
1using System;
2using System.IO;
3using gorilla.migrations.utility;
4
5namespace gorilla.migrations.data
6{
7 public class SqlFile : IEquatable<SqlFile>, IComparable<SqlFile>
8 {
9 public virtual string path { get; set; }
10
11 public virtual bool is_greater_than(int version)
12 {
13 return this.version() > version;
14 }
15
16 int version()
17 {
18 return version_number(file_name()).convert_to<int>();
19 }
20
21 string version_number(string name)
22 {
23 return name.Substring(0, name.IndexOf("_"));
24 }
25
26 string file_name()
27 {
28 return new FileInfo(path).Name;
29 }
30
31 public virtual int CompareTo(SqlFile other)
32 {
33 return version().CompareTo(other.version());
34 }
35
36 public virtual string raw_sql()
37 {
38 return File.ReadAllText(path);
39 }
40
41 static public implicit operator SqlFile(string file_path)
42 {
43 return new SqlFile {path = file_path.ToLower()};
44 }
45
46 public bool Equals(SqlFile other)
47 {
48 if (ReferenceEquals(null, other)) return false;
49 if (ReferenceEquals(this, other)) return true;
50 return Equals(other.path, path);
51 }
52
53 public override bool Equals(object obj)
54 {
55 if (ReferenceEquals(null, obj)) return false;
56 if (ReferenceEquals(this, obj)) return true;
57 if (obj.GetType() != typeof (SqlFile)) return false;
58 return Equals((SqlFile) obj);
59 }
60
61 public override int GetHashCode()
62 {
63 return (path != null ? path.GetHashCode() : 0);
64 }
65
66 public override string ToString()
67 {
68 return path;
69 }
70 }
71}